Skip to content

[rl] Bitwise parity test: trainer vs vLLM decode, greedy and at temperature 0.8 - #5928

Draft
felipemello1 wants to merge 4 commits into
mainfrom
felipemello1/rl/bitwise-temperature
Draft

felipemello1 wants to merge 4 commits into
mainfrom
felipemello1/rl/bitwise-temperature

Conversation

@felipemello1

@felipemello1 felipemello1 commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

Agent details

TLDR: A GPU parity test that runs the real vLLM engine, samples tokens greedy and at T=0.8, and checks that the trainer's logprobs for those generated tokens are bitwise equal to vLLM's. It found two gaps: the test engine returned logprobs before the temperature divide, and Kimi K3's trainer and vLLM differ past the first generated tokens.

vLLM:     logits -> fp32 -> / 0.8 (V1 sampler, per-request fp32 tensor) -> log_softmax -> sampled token's logprob
trainer:  logits -> compute_logprobs(..., temperature=<per-token fp32 tensor>)
check:    bitwise equal at every generated position, greedy and T=0.8

Problem

  1. tests/rl/unit_tests/cpu/test_losses.py:24 checks DAPOLoss against a copy of vLLM's op on CPU. Nothing runs the real vLLM engine at a temperature.
  2. The GPU parity tests compare the trainer with vLLM on the prompt only, and decode greedily.
  3. The test engine used vLLM's default raw_logprobs, unlike the Generator. At T=0.8 it returned logprobs from before the divide: max delta 0.98 on CI.

Solution

  1. test_trainer_vs_vllm_decode: vLLM generates greedy and at T=0.8 (seed 0). The trainer prefills prompt + generated tokens and passes a per-token fp32 temperature to compute_logprobs, as the batcher does. Every rank runs both temperatures, then rank 0 asserts, so a failure can't strand a rank in a TP collective.
  2. The test engine sets logprobs_mode="processed_logprobs", as the Generator does.
  3. No generator change. torchtitan runs vLLM's V1 model runner, whose sampler divides fp32 logits by an fp32 temperature tensor: the same op as compute_logprobs.
  4. Kimi K3 skips the new test, with a TODO: its trainer and vLLM differ there, greedy too.

Results

CI, the new test per class, at the head dc391edb0 (RL GPU Unit Tests 42443945063; H100 green):
TestBitwiseParityVarlen (Qwen3-0.6B, TP=2)       PASS, greedy and T=0.8
TestBitwiseParityFlex                            PASS, greedy and T=0.8
TestBitwiseParityQwen35DebugVarlen               FAIL at the head, T=0.8 only (seq 0: 1 of 16 tokens, max delta 1.3e-5;
                                                 greedy bitwise). FAIL at 9382daa9d (greedy: 2.5e-3, 16 of 16 tokens) and
                                                 0e7f4ba3e (T=0.8: 6.9e-4, 8 of 16 tokens); PASS at d5b6c3c20
TestBitwiseParityKimiK3DebugVarlen (H100)        SKIPPED; before the skip it failed greedy too (seq 0: 33 of 128 tokens match,
                                                 the first 5 included; max delta 3.2e-2)
MoEEP, GptOssVarlen, Qwen35Varlen                inherit the test; no CI job runs these classes

Qwen35Debug is flaky in this job. The class's existing prompt-only test_trainer_vs_vllm_prefill also fails on some
PR runs that include #5941 (3 of 6 since 11-08, max delta 9e-4 to 1.8e-3); main passed 7 of 7. At 9382daa and
0e7f4ba the new test failed in the same run as the prompt-only test. At the head it failed alone, so the new test
adds a way for the job to fail.

Test plan

  • CI (label ciflow/rl): RL GPU Unit Tests runs Varlen, Flex and Qwen35DebugVarlen; RL H100 Integration Tests runs KimiK3DebugVarlen.
  • A CPU gloo probe of the new loop (2 ranks, pytest 7.3.2): rank 0's failure ends the test on both ranks, and the next test runs.

@pytorch-bot pytorch-bot Bot added the ciflow/rl label Nov 7, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 7, 2026
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude review

@claude

claude Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 47s —— View job


Approve, with two items to address before merging: fill in the human-written summary, and confirm the multi-GPU CI run at 04eb450 passes. Review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the items below before merging. This is a test-only change. It closes a real gap: until now no test checked that the trainer's temperature-scaled logprobs match the generator's at T>0, and that is the ratio RL trains on.

What this PR does. It adds a parity test. vLLM samples 50 tokens at T=0.8, and the trainer prefills prompt + those tokens, divides the logits by a per-token fp32 tensor as DAPOLoss does (dapo.py:102), and must match the vLLM decode logprobs bitwise. It also switches the test engine to logprobs_mode="processed_logprobs", which the production engine already uses (engine.py:272). And vllm_generate now reads each logprob by the sampled token id instead of taking the first dict entry.

Example.

before: test engine on raw_logprobs, greedy only
  vLLM decode logprob = log_softmax(logits)[tok]          (no /T)
  trainer             = log_softmax(logits / T)[tok]      (DAPOLoss)
  -> no test compares the two; at T=0.8 they differ by up to 0.98
after:  test engine on processed_logprobs, T=0.8, seed=0
  vLLM decode logprob = log_softmax(fp32(logits).div_(T_fp32))[tok]
  trainer             = compute_logprobs(logits / full((T,), 0.8))[tok]
  -> asserted bitwise equal at every generated position

Must fix

  1. The PR description's "Summary (human-written)" section is empty. Please fill it in.
  2. The Results table lists the run at 04eb450 (the commit that includes the processed_logprobs fix) as pending. Please confirm RL Multi-GPU Unit Tests passes there and update the table. The test is meant to pass only because of that fix.

Should consider

  • tests/rl/unit_tests/gpu/test_bitwise_parity.py:338 -- pin the per-token divisor to dtype=torch.float32 (inline).
  • tests/rl/unit_tests/gpu/test_bitwise_parity.py:11-23 -- the module docstring still says "Three tests" and argues "trainer == vLLM decode" by transitivity. The new test checks that directly, at T=0.8, so please add it to the list.
Details
  • Necessity: the problem is real. The test engine reimplements engine construction (see the TODO at line 175) and had drifted from the production logprobs_mode. The CI run at 3143c24 shows the gap (50/50 tokens differ).
  • Cost: the new test runs one sampled generate and one trainer prefill per class. Putting it on the base class extends existing coverage to every backend and model class (Flex, Qwen3.5 TP=2, MoE EP, Kimi K3, GPT-OSS) rather than adding a new suite, which follows rules/tests.md.
  • d[token] is safe: with logprobs=1, vLLM always includes the sampled token in each step's dict. Adding seed=0 changes nothing for the existing greedy callers.
  • The "Python float divisor multiplies by its reciprocal" comment matches PyTorch's CUDA div_true kernel for a CPU scalar operand.
  • Under TP (Qwen3.5 TP=2), logits.shape[0] is still the token dim, so the per-token broadcast is correct for vocab-sharded logits.

Not verified: bitwise equality at T=0.8 for the 04eb450 run (GPU CI pending). Also the V1-vs-V2 runner note in the description; this test is what would catch a change there.

divisor would multiply by its reciprocal). ``temperature=None`` returns them unchanged."""
if temperature is None:
return logits
per_token = torch.full((logits.shape[0],), temperature, device=logits.device)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docstring says the divisor is fp32, and bitwise parity depends on that: vLLM's V1 sampler divides fp32 logits by an fp32 temperature tensor. But this tensor's dtype comes from torch.get_default_dtype(). Production sets it explicitly (torch.full_like(generator_logprobs, ...) in batcher.py:903). Pin it here too, so a default-dtype context left active by setup can't change what the test checks:

Suggested change
per_token = torch.full((logits.shape[0],), temperature, device=logits.device)
per_token = torch.full(
(logits.shape[0],), temperature, dtype=torch.float32, device=logits.device
)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reply from claude: Done in 0e7f4ba: the divisor is pinned to dtype=torch.float32. The module docstring now lists the new test (4 tests) and says the transitivity argument covers greedy tokens.

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: CI at 0e7f4ba: the new test passes bitwise on Varlen and Flex. It fails on Qwen35DebugVarlen, where the greedy trainer-vs-vLLM prefill test already fails on main (same class, max_delta 3.15e-4). Results table updated. @claude review

@claude

claude Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 34s —— View job


Request changes: at 0e7f4ba the new test also fails on Kimi K3 in RL H100 Integration Tests (max_delta 4.3e-2, 95/128 tokens differ), and the human-written summary is still empty. Review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Request changes -- at 0e7f4ba the new test also fails on Kimi K3 in RL H100 Integration Tests. Kimi K3's greedy parity tests pass there, so this failure is new, and the description doesn't mention it.

Re-review since the last automated review.

  • Resolved: the per-token divisor is now pinned to fp32 (test_bitwise_parity.py:341), and the module docstring lists the new test and limits the transitivity claim to greedy tokens.
  • Resolved: the RL Multi-GPU Unit Tests result at the processed_logprobs fix is now in the description. Varlen and Flex pass bitwise.
  • Still open: the "Summary (human-written)" section is empty.

Example (from the CI log, job 128352331978).

TestBitwiseParityKimiK3DebugVarlen (H100, TP=1, 128 tokens, T=0.8)
  test_trainer_vs_vllm_prefill                PASSED   (greedy)
  test_vllm_decode_vs_prefill                 PASSED   (greedy)
  test_trainer_vs_vllm_decode_at_temperature  FAILED   max_delta 4.33e-02, 95/128 differ
    first 5 positions bitwise equal (-7.4213, -7.3997, -6.3708, -5.9912, -9.1480),
    later positions drift (e.g. -6.6056 vs -6.5822)

Must fix

  1. tests/rl/unit_tests/gpu/test_bitwise_parity.py:871 -- KimiK3BitwiseParityTestBase inherits the new test, and it fails on H100. rl-kimi-k3 runs this test before the other tests in its script, so merging turns that job red and the later tests there stop running. Kimi K3's greedy trainer-vs-vLLM tests pass, so this is not the pre-existing Qwen3.5 mismatch. The early positions match and the later ones drift, so the cause could be in the decode state on sampled tokens, not in the divide (unverified). Please find the root cause. Then either fix it, or skip the test for Kimi K3 with a TODO that links an issue and states the cause. Either way, add the Kimi K3 row to the Results table.
  2. The PR description's "Summary (human-written)" section is still empty.

Should consider

  • TestBitwiseParityQwen35DebugVarlen: the new test fails there (max_delta 6.9e-4, 8/16), on top of the greedy prefill failure already on main. Please link the issue tracking that mismatch in the Results table. Then a maintainer can see that the failure is expected, and when the fix lands, this test confirms it.
Details
  • The Kimi K3 failure is in the H100 log at 08:54:09. RL Multi-GPU Unit Tests (job 128352280060) shows Varlen and Flex PASSED for the new test. Qwen35DebugVarlen failed both the new test and test_trainer_vs_vllm_prefill.
  • Kimi K3 runs the trainer in train() mode (KimiK3BitwiseParityTestBase.setUpClass) and generates 128 tokens, longer than any other class. With sampling, the generated tokens differ from the greedy run's, so the KDA recurrent state and the decode positions get coverage the greedy tests never gave them. The drift starts after the first few positions, which points at decode-state accumulation rather than a rounding difference in logits / T. That is a hypothesis; I can't run it.
  • The rest of the diff is unchanged since the last review. I have nothing new on it.

Not verified: the root cause of the Kimi K3 mismatch (needs an H100 run).

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: Kimi K3 root cause, as far as CI shows: the greedy case fails too (max_delta 3.2e-2, 95/128 tokens), so the temperature is not involved. Past the 64-token prompt the trainer's prefill differs from vLLM's decode, while the prompt-only parity test passes. Skipped for Kimi K3 in d6cb77f with a TODO that states the gap; an upstream issue needs the author's OK, so no link yet. At d6cb77f both RL GPU jobs are green, and Qwen35DebugVarlen passed the new test and its flaky prefill test. Results table updated. @claude review

@claude

claude Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 26s —— View job


Approve, with two items to fix before merging: fill in the human-written summary, and reword the Kimi K3 TODO. The gap there is trainer prefill vs vLLM prefill past 64 tokens, not decode, and the TODO needs an issue link. Review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the items below before merging. At d6cb77f both RL GPU jobs are green. The Kimi K3 failure turned out to be a trainer-vs-vLLM gap that also shows up greedy, so it is unrelated to the temperature. It is skipped with a TODO, which was one of the outcomes the last review accepted.

Re-review since the last automated review (0e7f4ba -> d6cb77f).

  • Resolved: Kimi K3 no longer turns RL H100 Integration Tests red. test_trainer_vs_vllm_decode now also runs greedy, which separates the temperature from the sequence length. The Kimi K3 override skips it (test_bitwise_parity.py:1105), and the Results table has the Kimi K3 row.
  • Resolved: Qwen35DebugVarlen. Its prefill failure is flaky on main (runs on 89dd0b8 and f548851), and both tests pass at d6cb77f.
  • Still open: the "Summary (human-written)" section is empty.

Example (Kimi K3, H100, greedy, what the four checks tell us).

trainer prefill(prompt, <=64 tok)       == vLLM prefill(prompt)          PASS
vLLM decode(gen)                        == vLLM prefill(prompt + gen)    PASS
trainer prefill(prompt + gen, <=192 tok) vs vLLM decode(gen)             FAIL 3.2e-2, 95/128
=> trainer prefill != vLLM prefill once the sequence goes past 64 tokens; decode is not involved

Must fix

  1. The PR description's "Summary (human-written)" section is still empty.
  2. tests/rl/unit_tests/gpu/test_bitwise_parity.py:1101-1104 -- the TODO points at the wrong side of the gap (see the inline comment). Also, add the issue link once you approve opening the issue. This is a real logprob mismatch between the Kimi K3 trainer and generator on any rollout longer than 64 tokens, which RL training hits, so it needs a tracked issue, not only a test skip.
Details
  • The skip is a method override on TestBitwiseParityKimiK3DebugVarlen only. Every other class still runs the new test, greedy and at T=0.8.
  • The greedy subtest is not redundant with tests 2 and 3. Test 2 only covers prompt-length sequences (64 tokens for Kimi K3 and Qwen3.5 debug). The greedy case of test 4 is the only check on trainer prefill over prompt + generated length. It is what found the Kimi K3 gap.
  • temperature=None if temperature == 0.0 else temperature matches production, where greedy means no divide. Cost: the test now runs two generates and two trainer prefills per class, which is still small next to setUpClass.
  • No changes outside the Kimi K3 override and the greedy loop since the last review.

Not verified: which kernel causes the Kimi K3 gap past 64 tokens (needs an H100 run).

Comment on lines +1101 to +1104
# TODO: past the 64-token prompt, the trainer's prefill differs from vLLM's decode, greedy
# too: max_delta 3.2e-2 on 95 of 128 generated tokens (H100 CI). The prompt-only
# test_trainer_vs_vllm_prefill passes, so the gap starts after the prompt. Find the
# kernel that differs there (KDA's chunked prefill is a candidate), then drop this skip.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TODO says the trainer differs from "vLLM's decode", but for this class test_vllm_decode_vs_prefill passes on H100: vLLM decode == vLLM prefill of prompt + generated tokens. So the gap is trainer prefill vs vLLM prefill once a sequence runs past the prompt (up to 64 + 128 = 192 tokens). Decode is not involved. That moves the search from the decode KV/recurrent state to the prefill kernels, and it explains why the prompt-only test passes: it never goes past 64 tokens. Please reword it so whoever picks this up starts in the right place, and add the issue link once you open the issue:

Suggested change
# TODO: past the 64-token prompt, the trainer's prefill differs from vLLM's decode, greedy
# too: max_delta 3.2e-2 on 95 of 128 generated tokens (H100 CI). The prompt-only
# test_trainer_vs_vllm_prefill passes, so the gap starts after the prompt. Find the
# kernel that differs there (KDA's chunked prefill is a candidate), then drop this skip.
# TODO: on sequences longer than the prompt (up to 64 + 128 tokens), the trainer's prefill
# differs from vLLM's, greedy too: max_delta 3.2e-2 on 95 of 128 generated tokens (H100
# CI). vLLM decode == vLLM prefill here (test_vllm_decode_vs_prefill passes), and the
# prompt-only test_trainer_vs_vllm_prefill (<= 64 tokens) passes, so the gap is trainer vs
# vLLM prefill past 64 tokens. Find the kernel that differs there (KDA's chunked prefill
# is a candidate), then drop this skip.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reply from claude: Done in e2aaf2e, with your wording. The issue link waits for the author's OK to open the issue.

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude review

@claude

claude Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 38s —— View job


Approve, with two items to fix before merging: the Kimi K3 TODO wording is now fixed, but the human-written summary is still empty, and the TODO still needs an issue link. Review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the items below before merging. The only change since d6cb77f is a comment: the Kimi K3 TODO now points at the right side of the gap. Both RL GPU jobs were green at d6cb77f, and a comment-only edit can't change that.

Re-review since the last automated review (d6cb77f -> e2aaf2e).

  • Resolved: the TODO at tests/rl/unit_tests/gpu/test_bitwise_parity.py:1101-1106 now says the gap is trainer prefill vs vLLM prefill past 64 tokens, and that decode is not involved.
  • Still open: the "Summary (human-written)" section is empty.
  • Still open: the TODO has no issue link.

Example (Kimi K3, H100, greedy; what the TODO now records).

trainer prefill(prompt, <=64 tok)        == vLLM prefill(prompt)          PASS
vLLM decode(gen)                         == vLLM prefill(prompt + gen)    PASS
trainer prefill(prompt + gen, <=192 tok) vs vLLM decode(gen)              FAIL 3.2e-2, 95/128
=> trainer prefill != vLLM prefill past 64 tokens

Must fix

  1. Fill in the "Summary (human-written)" section of the PR description.
  2. tests/rl/unit_tests/gpu/test_bitwise_parity.py:1101 -- file the Kimi K3 issue (the author has to approve the draft) and put its link in the TODO. Any Kimi K3 rollout longer than 64 tokens has a trainer-vs-generator logprob mismatch, and RL training hits that. A test skip alone won't keep it tracked.

Not verified: which kernel causes the Kimi K3 gap past 64 tokens (needs an H100 run).

…rature 0.8

The GPU parity tests compared the trainer with vLLM only on the prompt, and decoded
greedily. The new test_trainer_vs_vllm_decode prefills prompt + generated tokens with the
trainer and compares them with vLLM's decode logprobs, greedy and sampled at T=0.8. The
trainer passes a per-token fp32 temperature to compute_logprobs, as the batcher does.
Every rank runs both temperatures before rank 0 asserts, so a failure can't strand a rank
in a TP collective.

The test engine now sets logprobs_mode="processed_logprobs", as the production Generator
does; with vLLM's default raw_logprobs, the T=0.8 logprobs came before the divide.
Kimi K3 skips the new test: its trainer and vLLM prefill differ past the first generated
tokens, greedy too (TODO at the skip).
@felipemello1
felipemello1 force-pushed the felipemello1/rl/bitwise-temperature branch from e2aaf2e to d5b6c3c Compare November 7, 2026 10:09
@felipemello1 felipemello1 changed the title [rl] Bitwise parity test for tokens sampled at a temperature [rl] Bitwise parity test: trainer vs vLLM decode, greedy and at temperature 0.8 Nov 7, 2026
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: Round of fixes in d5b6c3c (one commit on main): both temperatures run on every rank before rank 0 asserts (no subTest, so a failure can't strand a rank in a TP collective); the trainer passes a per-token fp32 temperature to compute_logprobs, as main does since #5921; comment and TODO fixes; body rewritten with results per class. @claude review

@claude

claude Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 39s —— View job


Approve, with three items to address before merging: fill in the human-written summary, add the issue link and the decode == prefill evidence to the Kimi K3 TODO, and confirm the RL GPU and H100 jobs pass at d5b6c3c. Review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the items below before merging. d5b6c3c drops the test-local divide helper. The test now goes through compute_logprobs(..., temperature=<per-token fp32>), the same path the batcher feeds (batcher.py:903). That makes the T=0.8 check cover the production op, not a copy of it. Every remaining item is a description or comment edit.

Re-review since the last automated review (e2aaf2e -> d5b6c3c).

  • Resolved: the trainer side uses compute_logprobs's temperature argument (test_bitwise_parity.py:385-387, 429-431). full_like(labels, T, dtype=float32) has shape [T], which matches the logits rows on both the varlen and the padded flex paths. Under TP, the divide is elementwise on each vocab shard before the gather, so the result is unchanged.
  • Resolved: both temperatures run on every rank before rank 0 asserts (:870-903). This follows the pattern already used in test_reload_after_generate.
  • Still open: the "Summary (human-written)" section is empty.
  • Still open: the Kimi K3 TODO has no issue link.

Example (what the new test now checks against main's loss path).

vLLM (V1 sampler, processed_logprobs): log_softmax(fp32(logits) / T_fp32[req])[tok]
trainer: compute_logprobs(logits, labels, temperature=full_like(labels, 0.8, fp32))
         -> logits / temperature.unsqueeze(-1).expand_as(logits)   (loss.py:530)
check:   bitwise equal at every generated position, T in {0.0, 0.8}

Must fix

  1. The PR description's "Summary (human-written)" section is empty.
  2. tests/rl/unit_tests/gpu/test_bitwise_parity.py:1097 -- add the issue link once you approve filing it. The rewritten TODO also dropped the "vLLM decode == vLLM prefill" evidence, and it now names only the generator's KDA as the candidate (see the inline comment).
  3. CI at d5b6c3c is still running (RL GPU Unit Tests, RL H100 Integration Tests). The trainer side now goes through a different code path than at d6cb77f, so please confirm both jobs are green and fill in the "pending" row of the Results table.
Details
  • The VLLM_USE_V2_MODEL_RUNNER comment rewrite (:202) fixes a comment that contradicted the code next to it ("v2 runner is required" next to = "0"). It matches engine.py:212, so it is in scope.
  • Removing the By transitivity line is correct. Test 4 now checks trainer == vLLM decode directly.
  • seed=0 doesn't change the greedy callers (test_vllm_decode_vs_prefill, batch invariance, reload).
  • Prompt length 64 equals the generator's KDA _CHUNK_SIZE (kda.py:48). That is why the Kimi K3 gap shows up only once a sequence goes past the prompt.

Not verified: bitwise equality at d5b6c3c (GPU CI pending); which side's KDA chunk handling causes the Kimi K3 gap.

Comment on lines +1097 to +1099
# TODO: trainer and vLLM prefill differ on prompt + generated tokens, greedy too (seq 0 on H100:
# the first 5 generated tokens match, 33 of 128 match, max_delta 3.2e-2). The prompt-only test
# passes. The generator's chunked KDA prefill (paged_chunk_kda) is a candidate.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This rewrite lost two things from the version at e2aaf2e.

  1. The evidence that decode is not involved: test_vllm_decode_vs_prefill passes for this class.
  2. The candidate now points only at the generator side. The evidence fits either side's KDA prefill equally well. The generator's paged_chunk_kda uses _CHUNK_SIZE = 64 (torchtitan/rl/generator/vllm/attention/kda.py:48), and the prompt is exactly 64 tokens. So the prompt-only test never crosses a chunk boundary, and this test is the first one that does. Whoever picks this up should compare how the trainer's and the generator's KDA carry state across chunks, not only look at paged_chunk_kda.
Suggested change
# TODO: trainer and vLLM prefill differ on prompt + generated tokens, greedy too (seq 0 on H100:
# the first 5 generated tokens match, 33 of 128 match, max_delta 3.2e-2). The prompt-only test
# passes. The generator's chunked KDA prefill (paged_chunk_kda) is a candidate.
# TODO: trainer and vLLM prefill differ on prompt + generated tokens, greedy too (seq 0 on H100:
# the first 5 generated tokens match, 33 of 128 match, max_delta 3.2e-2). vLLM decode == vLLM
# prefill here (test_vllm_decode_vs_prefill passes), and the prompt-only test (64 tokens, one
# 64-token KDA chunk) passes, so compare how the trainer's and the generator's (paged_chunk_kda)
# chunked KDA prefill carry state across chunk boundaries.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reply from claude: done in d64ed6c. The TODO keeps both pieces of evidence in 3 lines: the 64-token prompt (one KDA chunk) matches, and vLLM decode matches its prefill (H100 run 42361174677 at e2aaf2e: test_vllm_decode_vs_prefill and test_trainer_vs_vllm_prefill passed). So the next step is to compare how the trainer and paged_chunk_kda carry KDA state across chunks. The first-5-tokens count and max delta stay in the body and the issue draft.

The trainer vs vLLM gap past the prompt is not in vLLM decode (it matches
vLLM prefill) and not in a single KDA chunk (the 64-token prompt matches).
Point the TODO at how the trainer and paged_chunk_kda carry KDA state
across chunks.
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude review

@claude

claude Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 43s —— View job


Approve, with two items to address before merging: fill in the human-written summary, and add the issue link to the Kimi K3 TODO. Review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the items below before merging. The only change since d5b6c3c is a comment. Both RL GPU jobs pass at d5b6c3c (RL GPU Unit Tests 42362733852: 1-GPU and multi-GPU jobs pass; RL H100 42362733871: rl-kimi-k3 passes).

Re-review since the last automated review (d5b6c3c -> d64ed6c).

  • Resolved: the Kimi K3 TODO (tests/rl/unit_tests/gpu/test_bitwise_parity.py:1097-1099) again records that vLLM decode == vLLM prefill and that the 64-token prompt (PROMPT_LENGTH = 64 at :1090, one KDA chunk) matches. It now points at both sides: how the trainer and paged_chunk_kda carry KDA state across chunks.
  • Resolved: CI at d5b6c3c is green, and the Results table has the numbers.
  • Still open: the "Summary (human-written)" section is empty.
  • Still open: the Kimi K3 TODO has no issue link.

Example (Kimi K3, H100, greedy; what the TODO now records).

trainer prefill(prompt, 64 tok = 1 KDA chunk)   == vLLM prefill(prompt)          PASS
vLLM decode(gen)                                == vLLM prefill(prompt + gen)    PASS
trainer prefill(prompt + gen, > 1 chunk)        vs vLLM decode(gen)              FAIL, 33/128 match
=> the gap opens at the KDA chunk boundary, trainer vs generator prefill

Must fix

  1. Fill in the "Summary (human-written)" section of the PR description.
  2. tests/rl/unit_tests/gpu/test_bitwise_parity.py:1097 -- add the issue link to the TODO once you approve filing the drafted issue. Every Kimi K3 rollout longer than 64 tokens has a trainer-vs-generator logprob mismatch, so the gap needs an issue to track it, not only a skipped test. The same goes for the Qwen35DebugVarlen flake mentioned in the Results section.

Not verified: CI at d64ed6c is still queued. It is a comment-only change, so I expect the same results as d5b6c3c.

felipemello1 pushed a commit that referenced this pull request Nov 25, 2026
## Summary (human-written)
Reject non-positive training sampling temperatures
(`generator.sampling.temperature <= 0`) at config time in
`Controller.Config.__post_init__`. Previously, setting `0.0` (greedy)
built without error and produced `NaN` logprobs, loss, and gradients
when `compute_logprobs` divided logits by temperature, while also
repeating identical rollouts with all-zero group-relative advantages.
Keeping the check in `Controller.Config` rather than `SamplingConfig`
leaves greedy validation (`async_loop.validation.temperature=0`)
unaffected, and `test_greedy_training_sampling_raises` guards against
regressions.

## Why
`SamplingConfig.temperature` documents `0.0 = greedy`, and
`Controller.Config` accepts it as the training sampling temperature. The
controller hands `generator.sampling.temperature` to the `Batcher`,
which fills every microbatch's `temperature[T]` with it, and
`compute_logprobs` scores tokens under `softmax(logits / temperature)`.
At 0 the trainer's logprobs, loss and gradients become NaN. A greedy
group also repeats one rollout, so its group-relative advantages are all
0.

Validation already rejects greedy sampling with more than one sample per
prompt (#6266), and the trainer-vs-vLLM parity test in #5928 scores
greedy tokens with `temperature=None` rather than 0. Training has no
such check.

**Example.** `rl_grpo_qwen3_5_debug_varlen(seq_len=128)` with
`generator.sampling.temperature=0.0`:

```
main:     the config builds; DAPOLoss with temperature[T] = 0 gives loss=nan,
          non-finite logits gradients and entropy nan (T = 0.8: loss 0.0964, finite)
this PR:  ValueError: generator.sampling.temperature must be positive, got 0.0: the
          trainer divides the logits by it. For greedy validation, set
          async_loop.validation.temperature=0.
```

## What changed
- `Controller.Config.__post_init__` raises `ValueError` when
`generator.sampling.temperature <= 0`.
- `test_greedy_training_sampling_raises` builds the CI recipe with
temperature 0 and expects the error. It catches the check being dropped,
which would let a greedy training config train on NaN again.

## Alternatives considered
- Check in `SamplingConfig.__post_init__`: validation reuses it through
`dataclasses.replace(self._sampling,
temperature=validation.temperature)`, so greedy validation would break.
- Score greedy tokens without the divide, as #5928's test does: removes
the NaN, but a greedy group still trains on all-zero advantages.

## User-facing changes
| Before | After |
| --- | --- |
| `generator.sampling.temperature=0.0` builds and trains on NaN loss |
`ValueError` at config time |
| `async_loop.validation.temperature=0` (greedy validation) | unchanged
|

## Testing
WSL2 Ubuntu 24.04, Python 3.12, torch `2.16.0.dev20261123+cpu`, vLLM
`1.0.0.dev20261107+cu132` with `VLLM_TARGET_DEVICE=cpu`, base `3f09e7b`
and this branch.

- `pytest tests/rl/unit_tests/cpu/test_async_controller.py -k
greedy_training_sampling`: fails on `main` with `DID NOT RAISE <class
'ValueError'>`, passes on this branch.
- `pytest tests/rl/unit_tests/cpu
--ignore=tests/rl/unit_tests/cpu/test_dapo_math.py
--ignore=tests/rl/unit_tests/cpu/test_geometry3k.py`: `main` 702 passed,
1 failed, 10 skipped; this branch 703 passed, 1 failed, 10 skipped. The
failure on both is
`test_controller_requires_a_vision_processor_exactly_for_multimodal_models`
(`No module named 'math_verify'` in my environment). The two ignored
modules need their example dependencies to collect.
- Every zero-argument recipe in `torchtitan_recipes/rl` and
`torchtitan_recipes/tests/rl` that imports without optional packages
(43, at temperature 0.8 or 1.0) builds on both `main` and this branch.
Training temperatures 1.0, 0.8 and 1e-3, and greedy validation with a
training temperature of 0.8, still build.
- On this branch merged with current `main` (`8919259`):
`test_async_controller.py` 55 passed. With `main`'s `controller.py`, the
new test fails with `DID NOT RAISE`.
- `pre-commit run --files` on the two changed files: flake8, ufmt,
pydoclint and codespell pass. Pyrefly reports the same diagnostics on
these files on `main` and this branch (RL packages missing on my Windows
checkout).

**AI assistance disclosure:** AI-assisted development tools were used
during investigation, implementation, and regression testing. I
personally reviewed the final diff, verified the correctness of the
changes and validation results, and take full responsibility for the
contribution.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant