Repository navigation
[Sampling Replay] Bounded sampling-support replay #3354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
guapisolo
merged 15 commits into
radixark:main
from
nanjiangwill:feat/top-p-sampling-mask-actor-logprobs
Sep 23, 2026
+1,239
−102
Merged
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
eda6b27
feat(rl): replay sampling support in actor scoring
nanjiangwill 483d9d2
feat(rollout): capture native sampling support
nanjiangwill 49de5a0
feat(session): preserve rollout sampling support
nanjiangwill 561d81c
fix(rl): validate bounded sampling replay contracts
nanjiangwill b9b824f
test(e2e): validate sampling-support replay
nanjiangwill ad27242
docs(rl): document sampling-support replay
nanjiangwill d1216cd
fix(rl): tighten sampling replay contracts
nanjiangwill 232279f
docs(rl): clarify sampling replay guarantees
nanjiangwill 20e4b3d
test(e2e): name sampling replay coverage precisely
nanjiangwill 5ba2872
fix(rl): allow sampling replay through SGLang router
nanjiangwill fd87bf3
style(rl): format sampling replay e2e arguments
nanjiangwill f20c909
test(rl): model derived sampling replay default
nanjiangwill d7e28bd
test(session): model sampling replay default in parity runs
nanjiangwill d00746e
test(e2e): check sampling-support replay exactly under true-on-policy…
guapisolo f345ebb
docs(rl): remove stale sampling replay router requirement
nanjiangwill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| --- | ||
| title: Sampling-Support Replay | ||
| description: Train against the same bounded sampling distribution used during rollout. | ||
| --- | ||
|
|
||
| Top-p and top-k change the distribution that generates a rollout token. They | ||
| remove tokens from the vocabulary and renormalize the remaining probability | ||
| mass. Recomputing a token's log probability over the full vocabulary therefore | ||
| does not reproduce its behavior-policy probability, even when the rollout and | ||
| trainer weights are identical. | ||
|
|
||
| Sampling-support replay preserves that distribution. For every generated token, | ||
| SGLang returns the realized set of token IDs that remained after sampling | ||
| filters. Miles transports this ragged support with the sample and applies it to | ||
| the actor logits before the softmax: | ||
|
|
||
| $$ | ||
| q_\theta(a_t \mid S_t) = | ||
| \frac{\exp(z_\theta(a_t) / T)} | ||
| {\sum_{j \in S_t} \exp(z_\theta(j) / T)}. | ||
| $$ | ||
|
|
||
| The support `S_t` is fixed rollout data; `z_θ` comes from the actor being | ||
| trained. This gives PPO/GRPO a denominator and numerator in the same sampled | ||
| probability space while retaining gradients through the current actor logits. | ||
|
|
||
| ## Enable replay | ||
|
|
||
| ```bash | ||
| ROLLOUT_ARGS+=( | ||
| --rollout-temperature 1.0 | ||
| --rollout-top-p 0.95 | ||
| --rollout-top-k 64 | ||
| ) | ||
| ``` | ||
|
|
||
| Replay is enabled whenever `--rollout-top-p` is below `1` or | ||
| `--rollout-top-k` is positive. A finite top-p run must also set a positive | ||
| top-k so that the captured support is bounded. Miles asks SGLang to capture its | ||
| native sampling support with `return_sampling_mask` and uses the returned | ||
| support-normalized log probability as the rollout log probability. | ||
|
|
||
| `--rollout-top-k` is the default for rollout requests, not a global upper bound | ||
| on request-specific top-k values. SGLang owns support capacity through | ||
| `--sglang-sampling-mask-max-tokens` (or the matching server-group override) and | ||
| rejects requests whose realized support cannot be represented. | ||
|
|
||
| ## Correctness requirements | ||
|
|
||
| Miles rejects configurations that it cannot replay faithfully: | ||
|
|
||
| - Every resolved training request must have top-p, top-k, and temperature. Agentic | ||
| sessions fill omitted values from the sampling defaults registered when the | ||
| session is created. | ||
| - Request temperature must match the registered training temperature | ||
| (`--rollout-temperature` for the standard rollout paths). | ||
| - Frequency, presence, and repetition penalties, `logit_bias`, and custom logit | ||
| processors are not supported because the trainer does not replay those logit | ||
| transformations. | ||
| - `--recompute-logprobs-via-prefill` is incompatible because that path does not | ||
| preserve the per-token support. | ||
| - The selected router must preserve `return_sampling_mask`. The Miles router | ||
| forwards raw request bodies. The native SGLang router requires typed chat and | ||
| generate request schemas that declare the field. | ||
|
|
||
| The SGLang backend must return one complete support and its normalized log | ||
| probability for every sampled token. Miles validates that response contract but | ||
| does not add separate restrictions for speculative decoding. | ||
|
|
||
| Tool and environment tokens are recorded with singleton support. Evaluation | ||
| requests do not capture this training-only metadata. | ||
|
|
||
| ## Current objective limitation | ||
|
|
||
| Replay currently exposes only the support-normalized actor score to the loss. | ||
| Reference KL and on-policy distillation also need a full-vocabulary actor score, | ||
| so Miles rejects `--use-kl-loss`, nonzero `--kl-coef`, and `--use-opd` with | ||
| replay until the loss interface carries both scores. | ||
|
|
||
| ## Monitor replay | ||
|
|
||
| On the first update from identical weights, | ||
| `train/train_rollout_logprob_abs_diff` should be near numerical tolerance. | ||
| Afterward, interpret it with version-lag and clipping metrics because it also | ||
| reflects policy updates and staleness. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.