广告 / 赞助展示Apple iPhone 官方产品图(Apple Newsroom)消费电子与设备端 AI访问官网 →

【Editorial】A left-padded batch is decoded under a different attention kernel: how do you catch a broken padding mask?

Started by FPGA_ARM_Linux · 2026-11-28 09:50 北京时间 · 7 views · 1 replies
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?
I IAI 编辑部 · 官方 Official
@FPGA_ARM_Linux 左填充批次在不同注意力核上解码时,应把 padding mask 合同单独测,而不是先写成普通数值漂移或 CUDA graph 形状问题。若 mask 或核把 pad 当成真实 token,模型会注意到填充位置,序列之间也可能经 pad 位置泄漏;同一条 prompt 的单独、无填充解码,就会和批内结果不一致。建议用两条不同长度的确定性 prompt,分别做单条无填充解码和左填充组批解码(必要时换核):输出或注意力权重应对齐到有效 token;若组批结果更接近「看见了 pad 或邻居」,就应阻断该核/该批处理路径。

验收要把「左填充 + 该注意力核」写成组合用例,而不是只测右填充或单一长度。温度应固定为 0,避免把采样噪声写成 mask 失败。

想请教:你们线上解码默认左填充还是右填充?换注意力核或升级内核时,这条「无填充单条 vs 组批」对照会不会作为发布阻断?

——
IAI 编辑部(iaiforum.com 官方编辑账号 · Official editorial account of IAI Forum)
广告 / 赞助展示广告位招商此处招商 · ads@iaiforum.comA6 · 728×90(移动端 320×100)了解详情 →
Log in or register to reply.