NVIDIA-NeMo/RL #5006, head 77d3b094.
Raised first by a reviewer in this thread.
ฯ = sampler tail รท trainer tail, with the trainer tail clamped at 1e-6.ฯ = 0 whenever the trainer tail is at most 1e-6 (score_centering.py L74-L81), for every caller, replay or not.compute_score_centering_term now takes sampler_replay and zeroes ฯ only under replay; the PR's tests now cover the small-tail case. This page shows what the bug was.Three pages on this PR, one question each. This one: what the new ฯ = 0 rule does outside replay.
ฯ ยท p: the trainer's own tail probabilities, scaled so the total
matches vLLM's missing mass. Under replay the list holds every token vLLM could sample, so there is no tail. There, any ฯ
gives the same gradient; only the logged loss value changes (with #4818's formula it can jump from โ1.42 to +140), which is why the
author set it to 0.The reviewer's example, replay off: the trainer gives p = 0.6, 0.4 โ t, t to three tokens; vLLM gives q = 0.5, 0.3, 0.2 and captured only the first two (K = 2). The tail token holds 0.2 of vLLM's mass. Values computed on CPU with the base and head versions of the function.
Where the fix landed: RL only. compute_score_centering_term takes a new sampler_replay argument. ClippedPGLossFn sets it when the batch has a top-k/top-p support mask, which only filtered sampling produces; setup already requires replay for score centering under filters, so the two always agree.
@@ nemo_rl/algorithms/loss/score_centering.py ยท compute_score_centering_term (af11112532) - trainer_tail = 1.0 - p.sum(-1) - rho = torch.where( - trainer_tail > 1e-6, - (1.0 - head_mass).clamp(min=0.0) / trainer_tail.clamp(min=1e-6), - 0.0, - ) + if sampler_replay: + rho = torch.zeros_like(head_mass) + else: + rho = (1.0 - head_mass).clamp(min=0.0) / (1.0 - p.sum(-1)).clamp(min=1e-6)
The else branch is #4818\'s line, unchanged. The PR\'s replay no-tail test now uses a replay-shaped input, and a new test checks the reviewer\'s example (trainer tail 9e-7) without replay.