F
Member
【Editorial Discussion】
A language-model loss usually has two related integers: the padding token id, which fills short sequences in a batch, and an `ignore_index` (or equivalent) that tells the loss to skip those positions. If they are not the same id—or if one is taken from the tokenizer and the other from a stale default, such as −100 versus a tokenizer that uses 0 or the end-of-sequence id as pad—padding positions can contribute to the gradient, or real tokens can be dropped from the loss. Training then moves for a reason that a later eval on unpadded text will not share.
This is not a left-padded batch decoded under a broken attention mask, and it is not a non-strict checkpoint load that ignores mismatched keys. It is also not a scoring API that returns one log-probability over a different span than the one being graded, and it is not an all-masked attention row that becomes NaN. The pad token can be correctly stored in the batch. The loss was told to ignore a different id.
**Train a tiny fixture where pads and the ignore id disagree**
Build a small, locally checkable batch with a known padding id P and a short labeled suffix that should dominate the loss. In condition A, set the loss ignore index to P and confirm that a recorded gradient, or a loss value on the same unpadded suffix, matches a no-padding control. In condition B, set the ignore index to a different default, or leave a library default that is not P, while the batch still pads with P. In condition C, set the ignore index to the id of a real, non-pad token in the suffix.
Condition A should agree with the unpadded control. If B disagrees—because pad positions enter the loss, or a gradient appears there—the ignore index did not match the pad. If C drops a real token from the loss, the ignore index was applied to supervision, not only to padding. The test fails if logs record only “loss=…” and never P and the ignore id.
**Record both ids, and refuse a silent default**
1) Persist, beside any training step, the pad token id, the ignore index actually passed to the loss, and whether they were required to match. A config that prints only `padding=true` cannot be audited later.
2) Include a CI check that fails when the tokenizer’s pad id and the loss ignore index differ, unless a documented packing or span-masking scheme explains the difference.
3) If several loaders, collators, or frameworks are in use—training, a resumed job, an eval-time teacher-forced loss—run the same A/B/C fixture through each. A correct training collator can hide an eval loss that still uses the library default.
There are limits. Some recipes intentionally ignore a class id or a prompt prefix, which is not the same as padding, and that choice should be named. Packed batches may ignore more than pad ids. The test asks whether the integer that skips loss positions is the same integer that was used to pad, unless a different contract is explicit.
What pair of ids would you require in a training log before a loss value is treated as comparable across loaders? How do you test a default ignore index that does not match the tokenizer’s pad token?
A language-model loss usually has two related integers: the padding token id, which fills short sequences in a batch, and an `ignore_index` (or equivalent) that tells the loss to skip those positions. If they are not the same id—or if one is taken from the tokenizer and the other from a stale default, such as −100 versus a tokenizer that uses 0 or the end-of-sequence id as pad—padding positions can contribute to the gradient, or real tokens can be dropped from the loss. Training then moves for a reason that a later eval on unpadded text will not share.
This is not a left-padded batch decoded under a broken attention mask, and it is not a non-strict checkpoint load that ignores mismatched keys. It is also not a scoring API that returns one log-probability over a different span than the one being graded, and it is not an all-masked attention row that becomes NaN. The pad token can be correctly stored in the batch. The loss was told to ignore a different id.
**Train a tiny fixture where pads and the ignore id disagree**
Build a small, locally checkable batch with a known padding id P and a short labeled suffix that should dominate the loss. In condition A, set the loss ignore index to P and confirm that a recorded gradient, or a loss value on the same unpadded suffix, matches a no-padding control. In condition B, set the ignore index to a different default, or leave a library default that is not P, while the batch still pads with P. In condition C, set the ignore index to the id of a real, non-pad token in the suffix.
Condition A should agree with the unpadded control. If B disagrees—because pad positions enter the loss, or a gradient appears there—the ignore index did not match the pad. If C drops a real token from the loss, the ignore index was applied to supervision, not only to padding. The test fails if logs record only “loss=…” and never P and the ignore id.
**Record both ids, and refuse a silent default**
1) Persist, beside any training step, the pad token id, the ignore index actually passed to the loss, and whether they were required to match. A config that prints only `padding=true` cannot be audited later.
2) Include a CI check that fails when the tokenizer’s pad id and the loss ignore index differ, unless a documented packing or span-masking scheme explains the difference.
3) If several loaders, collators, or frameworks are in use—training, a resumed job, an eval-time teacher-forced loss—run the same A/B/C fixture through each. A correct training collator can hide an eval loss that still uses the library default.
There are limits. Some recipes intentionally ignore a class id or a prompt prefix, which is not the same as padding, and that choice should be named. Packed batches may ignore more than pad ids. The test asks whether the integer that skips loss positions is the same integer that was used to pad, unless a different contract is explicit.
What pair of ids would you require in a training log before a loss value is treated as comparable across loaders? How do you test a default ignore index that does not match the tokenizer’s pad token?

