Companion illustration for
NVIDIA-NeMo/RL #4171.
Permalinks pin the PR head ae5a6d9; the removed code is linked at the base
commit 612d527, since it no longer exists at head.
Two pages on this PR, one question each β this one: a fix to the filter that was already on.
NaN or Β±Inf logprob sitting in a padded slot β a position the filter is supposed to ignore β poisoned the score for the whole sequence and got it thrown away.seq_logprob_error_threshold is set β you do not need the PR's new opt-in mode to get it.Sequences in a batch have different lengths, so short ones are padded out to a common width.
A token_mask marks which slots are real response tokens. The filter scores a sequence
by averaging exp(|generation_logprob β policy_logprob|) over the real tokens only, and
drops the sequence if that average is above the threshold. The padded slots hold whatever happened
to be in memory β often -inf, because that is what masked-out logits become. The old
code multiplied by the mask inside the exponent to skip them, and that is where it went
wrong: in IEEE floating point, inf Γ 0 is not 0. It is NaN.
Running the numbers from the figure: exp(0.5) + exp(0.2) + exp(0.9) is
1.6487 + 1.2214 + 2.4596 = 5.3297, divided by the 3 real tokens gives
1.7766, which is under the threshold of 2.0. Under the old formula the fourth slot
turned that sum into NaN, and because every comparison against NaN is
false, the sequence failed the threshold test and was dropped.
A bad number on a real token still rejects the sequence, which is the behaviour you
want. exp(inf) is inf and exp(NaN) is NaN, and
neither is ever below a finite threshold. The fix only stops slots the filter was already told to
ignore from having a say.
Why this matters more than it looks. This filter is not the PR's new opt-in
mode β it runs on any config that sets seq_logprob_error_threshold, and four shipped
recipes set it to 2. So the old behaviour was quietly throwing away training data whenever a padded slot
held a non-finite logprob, and the sequence itself was perfectly fine. Nothing logged a warning;
the sequence just counted as filtered. If you have been watching
num_masked_seqs_by_logprob_error and wondering why it was higher than you expected,
this is a candidate explanation.