Repository navigation
[rl] Validation samples at temperature 1; optional n samples per prompt with best_of_n - #6266
Conversation
…pt with best_of_n
ValidationConfig gains temperature (default 1.0) and num_samples_per_prompt (default 1). Each
validation prompt runs as one group of n rollouts. validation_reward keeps its meaning (the mean
over all scored rollouts). With n > 1, validation_reward/best_of_{n} logs each prompt's best scored
reward (pass@n for 0/1 rewards); a prompt with no scored rollout is left out. Config checks reject
temperature < 0, num_samples_per_prompt < 1, and greedy with n > 1.
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 2m 36s —— View job Approve -- please address the items before merging (missing human summary, stale "greedy" docstring in |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The change is small, fits how validation already works (one rollout group per prompt, fresh negative group ids, release_groups), and the new metric is correct. What's left: a missing human summary and docs that still say validation is greedy. A maintainer still needs to review, because this touches the RL controller.
What this PR does. Validation used to decode greedily with 1 rollout per prompt. Now it samples at ValidationConfig.temperature (default 1.0) and runs num_samples_per_prompt rollouts per prompt (default 1). With n > 1 it also logs validation_reward/best_of_{n}: each prompt's best scored reward, averaged over prompts.
Example. 2 prompts, ValidationConfig(num_samples_per_prompt=2), training sampling T=0.8, seed=7:
main: run_group_rollouts(group_size=1, sampling=T=0.0) -> validation_reward/_mean over 2 rollouts
PR: run_group_rollouts(group_size=2, sampling=T=1.0, seed=7)
rewards [[1, 0], [0, 0]] -> validation_reward/_mean 0.25, validation_reward/best_of_2/mean 0.5
rewards [[None, 1], [None, None]] -> _mean 1.0, best_of_2 1.0 (the second prompt is left out)
The rollouter seeds siblings with seed + rollout_id (rollouter.py:456, verifiers/rollouter.py:268), so n > 1 gives n distinct samples when debug.seed is set.
Must fix
- PR description: the "Summary (human-written)" section is empty. The author needs to fill it in (see "AI-assisted contributions" in
CONTRIBUTING.md). torchtitan_recipes/rl/slake.py:112: the docstring still says "Validation: greedy answers on the English test questions". After this PR, the slake recipe samples at T=1.0. Either setValidationConfig(..., temperature=0.0)there, if exact-match short answers should stay greedy, or update the docstring.
Should consider
torchtitan/rl/controller/controller.py:903-905: passnum_samples_per_promptinto_collect_validation_rolloutsas an argument, likesampling. Then the existing test doesn't need a stubbedcontroller.config(details inline).torchtitan/rl/examples/search_r1/README.md:81: the results say the curves are "greedy decoding". That is still true of those snapshots, but new runs will validate at T=1.0 and won't be comparable with them. Add one clause saying so, or pin the search_r1 recipe totemperature=0.0.
Questions
- Item 3 of the description cites libraries that validate "at the training temperature". The PR instead fixes validation at 1.0, which is the training temperature for every recipe except alphabet_sort (0.8). The "You may ask" answer (comparability across runs) is a reasonable call. A maintainer should confirm they prefer a fixed default over inheriting
generator.sampling.temperature.
Details
top_p=1.0is no longer forced. That's fine:SamplingConfig.__post_init__already rejectstop_p < 1.0(generator/types.py:44).- Unscored rollouts:
best_of_nfiltersreward is Nonethe same waycompute_rollout_metricsdoes forvalidation_reward(metrics.py:262), so the two metrics count the same rollouts. - Every in-repo
ValidationConfig(...)caller (recipes,torchtitan_recipes/tests/rl,tests/rl) uses defaults for the new fields. The loss-guard configs usesteps=0, so no golden file depends on validation numerics. - The extra load with n > 1 runs at vLLM priority -1, as the description says (
generator/types.py:60). The existing TODO atcontroller.py:991about reading every prompt up front already covers the case where prompts x n gets large (e.g.steps=-1on slake or geometry3k).
Not verified: the GPU smoke results in the description.
| num_samples_per_prompt = ( | ||
| self.config.async_loop.validation.num_samples_per_prompt | ||
| ) |
There was a problem hiding this comment.
Should consider: validate() works out the validation sampling and passes it in as sampling=, but _collect_validation_rollouts reads num_samples_per_prompt from self.config itself. That split is the only reason test_validation_renames_turn_metrics_and_uses_fresh_group_ids now has to stub controller.config with a ValidationConfig(). Pass it in as a keyword argument next to sampling (num_samples_per_prompt=validation.num_samples_per_prompt in validate()). Then the helper gets everything from its caller, and the existing test needs no change.
There was a problem hiding this comment.
Reply from claude: applied in 7df4fb8. validate() reads the ValidationConfig once and passes num_samples_per_prompt next to sampling; the old test passes num_samples_per_prompt=1 and no longer stubs controller.config.
…ollouts; docs no longer say greedy validate() reads the ValidationConfig once and passes the sampling and the sample count, so the helper takes everything from its caller. The SLAKE recipe docstring and the search_r1 README say validation now samples at temperature 1.0.
|
Reply from claude: 7df4fb8 addresses the review: num_samples_per_prompt is passed into _collect_validation_rollouts; the SLAKE docstring and the search_r1 README no longer call validation greedy (the README says its curves are greedy snapshots). Fixed vs inherited temperature is a maintainer call; the description's "You may ask" gives the reason for a fixed 1.0. @claude please review |
|
Claude finished @felipemello1's task in 37s —— View job Approve -- please address the item below before merging (the human-written summary is still empty; all earlier code and doc items are fixed): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. 7df4fb8 fixes the code and doc items from the last review. The new commit adds no new problems. The one open item is the empty human-written summary. A maintainer still needs to review, because this touches the RL controller.
What this PR does. Validation used to decode greedily, with 1 rollout per prompt. Now it samples at ValidationConfig.temperature (default 1.0) and runs num_samples_per_prompt rollouts per prompt (default 1). With n > 1 it also logs validation_reward/best_of_{n}.
Example.
ValidationConfig(num_samples_per_prompt=2), 2 prompts, training sampling T=0.8 seed=7
main: run_group_rollouts(group_size=1, sampling=T=0.0)
PR: run_group_rollouts(group_size=2, sampling=T=1.0, seed=7)
rewards [[1, 0], [0, 0]] -> validation_reward/_mean 0.25, validation_reward/best_of_2/mean 0.5
Status of earlier items
- Resolved:
torchtitan_recipes/rl/slake.py:112. The docstring now says one sampled answer at T=1.0. - Resolved:
controller.py.validate()passesnum_samples_per_promptnext tosampling, so the old test no longer stubscontroller.config. - Resolved:
search_r1/README.md:83-85. It says the curves are greedy snapshots and newer runs aren't comparable. Theterminal_benchREADME is updated too. No other in-repo doc still calls validation greedy.
Must fix
- PR description: "Summary (human-written)" is still empty. The author has to fill it in (see "AI-assisted contributions" in
CONTRIBUTING.md).
Questions
- Still open for a maintainer: should validation use a fixed default of 1.0, or inherit
generator.sampling.temperature? The "You may ask" section explains why the PR picks a fixed value (runs stay comparable). Today the only recipe where the two differ is alphabet_sort, which trains at 0.8.
Not verified: the GPU smoke results in the description.
…e the sampling settings
|
Claude finished @felipemello1's task in 36s —— View job Approve. Please fill in the empty human-written summary before merging. The doc trims in 83c22ea add no new problems: review |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. 83c22ea only trims docs, and none of it is wrong. The one open item is still the empty human-written summary. A maintainer still needs to review, because this touches the RL controller.
What this PR does. Validation used to decode greedily, with 1 rollout per prompt. Now it samples at ValidationConfig.temperature (default 1.0) and runs num_samples_per_prompt rollouts per prompt (default 1). With n > 1 it also logs validation_reward/best_of_{n}.
Example.
ValidationConfig(num_samples_per_prompt=2), 2 prompts, training sampling T=0.8 seed=7
main: run_group_rollouts(group_size=1, sampling=T=0.0)
PR: run_group_rollouts(group_size=2, sampling=T=1.0, seed=7)
rewards [[1, 0], [0, 0]] -> validation_reward/_mean 0.25, validation_reward/best_of_2/mean 0.5
Status of the new commit
controller.py:168-173: the docstrings are shorter now. The greedy-needs-n=1 rule used to be in the docstring and is now enforced only by the__post_init__error (controller.py:207-211). The error message is clear enough on its own.slake.py:112and theterminal_benchREADME no longer describe the validation sampling. They still say nothing incorrect.search_r1/README.mdis back to main's text. Its "greedy decoding" describes the linked snapshot curves, and those really were greedy, so it stays accurate. No in-repo doc still says current validation is greedy.
Must fix
- PR description: "Summary (human-written)" is still empty. The author has to fill it in (see "AI-assisted contributions" in
CONTRIBUTING.md).
Questions
- Still open for a maintainer: should validation use a fixed default of 1.0, or inherit
generator.sampling.temperature? Today the only recipe where the two differ is alphabet_sort, which trains at 0.8.
Not verified: the GPU smoke results in the description.
## 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.
Summary (human-written)
changes validation temperate default to 1
exposes the arg
enables best-of-n
Agent details
TLDR: Validation now samples at temperature 1.0 instead of greedily, still with 1 rollout per prompt by default. 6 of the 8 RL training libraries we surveyed validate by sampling by default.
num_samples_per_promptruns more rollouts per prompt. With n > 1,validation_reward/best_of_nlogs the best reward per prompt, which is pass@n when rewards are 0/1.Problem
Controller.validateruns each held-out prompt once, greedily (temperature=0.0).Solution
ValidationConfiggainstemperature: float = 1.0andnum_samples_per_prompt: int = 1.release_groupsdon't change, and the best-of-1 TODO goes away.validation_rewardkeeps its name and meaning: the mean over all scored rollouts.validation_reward/best_of_{n}logs each prompt's best scored reward, averaged over prompts; unscored rollouts (reward None) are skipped, as invalidation_reward, and a prompt with none scored is left out. It needs no pass threshold (alphabet_sort's reward is graded), and it equals pass@n for 0/1 rewards.max_num_seqsis unchanged: main sizes it from training rollouts only. With n > 1, a validation sends prompts x n requests, and the generators serve validation requests first (vLLM priority -1).ValueErrorontemperature < 0, onnum_samples_per_prompt < 1, and on greedy with n > 1, which would run n identical rollouts.SamplingConfigrequires it), and validation keeps main's schedule (ValidationConfig.freq, beside training).Recipes
No recipe sets validation sampling, so they all move from greedy to temperature 1.0 with the same number of rollouts. One sampled rollout per prompt is noisier than greedy, and
validation_rewardcurves are not comparable with earlier greedy runs.Results
2-GPU smoke, H100: Qwen3-0.6B on alphabet_sort, 2 training steps, 8 validation prompts x 4 rollouts. It exercises the n > 1 path.
You may ask:
ValidationConfig(temperature=0.0).NOTE: The H100 smoke above ran on an earlier revision that defaulted to n=4. The GB300 smoke in the test plan ran on 7c4c678, this commit before a clean rebase onto main.
Test plan
pytest tests/rl/unit_tests/cpu/test_async_controller.py -k validat: 15 passed.pytest tests/rl/unit_tests/cpu: 689 passed, 7 skipped (mainb1c259cd3: 685 passed, 7 skipped).test_validate_rolls_out_each_prompt_n_times(n=1, n=2, and n=2 with unscored rollouts) andtest_validation_config_rejects_bad_sampling.test_validation_renames_turn_metrics_and_uses_fresh_group_idspassesnum_samples_per_prompt=1:validate()now hands it to_collect_validation_rolloutsnext tosampling.ValidationConfig(steps=8, num_samples_per_prompt=4, validate_after_training=True). rc=0,validation/group_failures0, 32 rollouts per validation.validation_reward/best_of_4/mean0.24 vsvalidation_reward/_mean0.12 at step 0, and 0.23 vs 0.14 after training.pre-commit runon the changed files.