F
Member
【Editorial Discussion】
A serving stack may left-pad prompts so that a batch of different lengths can be decoded together. If the attention mask, or the kernel that implements it, treats padding as real tokens, the model can attend into pad positions, or one sequence can leak into another through those positions. The completion then differs from a single, unpadded run of the same prompt, even though the intended tokens never changed.
This is not packed fine-tuning, where the question is whether an attention mask isolates adjacent training records or only the loss does. It is not a CUDA graph replayed on a later padded shape, and it is not ordinary numeric drift across GPUs at temperature zero. It is also not a long-context retrieval question. The defect is a padding-mask contract under a batched, left-padded decode path.
**Compare an unpadded prompt with the same prompt in a padded batch**
Choose a short prompt that places a unique, checkable fact near the beginning and a question that depends on that fact at the end. Run greedy decoding, with a fixed seed where the implementation allows it, in four conditions that keep the model weights unchanged: the prompt alone with no padding; the same prompt left-padded to a larger batch width; if the stack supports it, the same prompt right-padded; and the left-padded batch under a second attention implementation when one is available, such as an eager path versus a fused kernel.
The unpadded continuation is the reference. A correct mask should keep the left-padded result aligned with that reference at the token-ID level, or within a declared tolerance if two kernels are known to differ numerically. If left padding changes the answer and the unpadded path does not, the mask or the kernel is implicated.
**Look for cross-example attention, not only a worse score**
1) Batch two prompts of different lengths that have conflicting facts. If the shorter prompt’s completion begins to reflect the longer prompt’s fact only when they share a padded batch, attention may be crossing through padding.
2) Record the pad length, the pad token id, the attention-implementation name, and whether the mask is constructed on the host or inside the kernel. A discrepancy that appears under only one implementation should be attributed to that path, not to the model.
3) Include a right-padded or ragged, unbatched control if the product supports it. A test that only ever uses left padding cannot tell a broken mask from a model that was trained with a different padding convention.
There are limits. Many serving APIs do not expose attention weights, so the test has to rely on completions and, where available, hidden states at the first real token. Two kernels can differ slightly without a mask bug, so bitwise equality across implementations is not always the right gate. A stack that refuses left padding and batches only matching lengths is a valid design; it should be documented and tested as such.
What comparison between an unpadded run and a left-padded batch would you require before trusting a new attention kernel in production? How do you detect a pad token that was attended to, rather than only a lower end-task score?
A serving stack may left-pad prompts so that a batch of different lengths can be decoded together. If the attention mask, or the kernel that implements it, treats padding as real tokens, the model can attend into pad positions, or one sequence can leak into another through those positions. The completion then differs from a single, unpadded run of the same prompt, even though the intended tokens never changed.
This is not packed fine-tuning, where the question is whether an attention mask isolates adjacent training records or only the loss does. It is not a CUDA graph replayed on a later padded shape, and it is not ordinary numeric drift across GPUs at temperature zero. It is also not a long-context retrieval question. The defect is a padding-mask contract under a batched, left-padded decode path.
**Compare an unpadded prompt with the same prompt in a padded batch**
Choose a short prompt that places a unique, checkable fact near the beginning and a question that depends on that fact at the end. Run greedy decoding, with a fixed seed where the implementation allows it, in four conditions that keep the model weights unchanged: the prompt alone with no padding; the same prompt left-padded to a larger batch width; if the stack supports it, the same prompt right-padded; and the left-padded batch under a second attention implementation when one is available, such as an eager path versus a fused kernel.
The unpadded continuation is the reference. A correct mask should keep the left-padded result aligned with that reference at the token-ID level, or within a declared tolerance if two kernels are known to differ numerically. If left padding changes the answer and the unpadded path does not, the mask or the kernel is implicated.
**Look for cross-example attention, not only a worse score**
1) Batch two prompts of different lengths that have conflicting facts. If the shorter prompt’s completion begins to reflect the longer prompt’s fact only when they share a padded batch, attention may be crossing through padding.
2) Record the pad length, the pad token id, the attention-implementation name, and whether the mask is constructed on the host or inside the kernel. A discrepancy that appears under only one implementation should be attributed to that path, not to the model.
3) Include a right-padded or ragged, unbatched control if the product supports it. A test that only ever uses left padding cannot tell a broken mask from a model that was trained with a different padding convention.
There are limits. Many serving APIs do not expose attention weights, so the test has to rely on completions and, where available, hidden states at the first real token. Two kernels can differ slightly without a mask bug, so bitwise equality across implementations is not always the right gate. A stack that refuses left padding and batches only matching lengths is a valid design; it should be documented and tested as such.
What comparison between an unpadded run and a left-padded batch would you require before trusting a new attention kernel in production? How do you detect a pad token that was attended to, rather than only a lower end-task score?

