feat(rollout): non-greedy sampling on hybrid engine graph decode path #8939
All Vouch review confidence checks passed
Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 622 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.385
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #8939"
general
weight: 0.35
delock
Closes #8934.
Summary
HybridEngineRolloutdecodes greedily on its fast paths. Graph capture applies only whentemperature <= 0, and sampling silently falls back to Hugging Facegenerate(). Continuous batching (#8368), with or without its CUDA graph (#8732), rejectstemperature > 0outright. RL rollouts sample at temperature 1, so they get neither path.Only the decode forward is captured; the next token is picked on the host from the output logits. So sampling needs no change to any captured graph. This PR changes token selection and dispatch only:
HybridEngineRollout._token_selector(sampling), picks the first token and every decoded token on all three paths: graph decode, continuous batching, and continuous batching with graphs.- At
temperature <= 0it takes the argmax, as before.- Otherwise it applies Hugging Face's
TemperatureLogitsWarper,TopKLogitsWarperandTopPLogitsWarper, ingenerate()'s order on float32 logits, then callstorch.multinomial. So every path samples from the same distribution asgenerate().generate()no longer checksis_greedyfor it.- The greedy-only check is removed.
- The model's repetition penalty is applied before the selector, which is
generate()'s order._hf_sampling_kwargs(sampling): thegenerate()sampling arguments, now shared by the maingenerate()call and the continuous-batching prefill of models without cache-class support. That prefill previously hard-codeddo_sample=False.inference-engine.rstnow describes sampling on the graph decode path, and "greedy decoding" is dropped from the continuous batching requirements.Known issues outside this PR
On master, two cache and mask gaps stop some paths from running on a Hugging Face model with SDPA attention, greedy included. This PR doesn't touch either; #8602 fixes both.
_generate_graph), Transformers 4.57.x: capture fails with "operation not permitted when stream is capturing". The decode step's 2-D attention mask makes Transformers callpadding_mask.all()on the host (reported by 0z5a on #8197). #8602 passes a pre-built 4-D decode mask.DeepSpeedStaticCachehas noget_query_offset(also #8852). #8602 adds it.Until #8602 lands, the end-to-end GPU tests of these paths fail with those errors (results below).
Tests
The tests cover correct dispatch and correct sampling.
tests/unit/runtime/rollout/test_hybrid_engine_rollout.py(CPU):generate()is not called.test_token_selector_samples_the_configured_distribution: 20,000 draws from fixed logits for temperature, top-k, top-p and their combination. They are compared against a reference distribution computed independently of the rollout. No token outside the top-k / top-p support may appear, and every token's frequency must lie within 4 standard errors.test_token_selector_is_argmax_without_temperature.test_continuous_generation_samples_when_temperature_is_set:- setup: continuous batching on a fake model whose logits tie tokens 7 and 8, with top-k 2;
- check: the output must contain both tokens and nothing else (greedy would always pick 7);
- this replaces the assertion that continuous batching rejects
temperature > 0.test_continuous_sampling_applies_repetition_penalty_before_warpers: with penalty 1.5 and top-k 1, the token the penalty favors must win.tests/unit/v1/test_hybrid_engine_rollout_v1.py(CUDA):test_decode_sampling_matches_hf_generatesamples end to end on a tiny random Llama, with a scaled output head so next-token distributions are peaked.generate()'s exactly. Every prompt gets its own continuous batching slot, so each path draws all rows' tokens in one call per step, asgenerate()does, and both consume the same random numbers.Results on this branch (master
322283b25+ this PR), 1× NVIDIA A40 (driver 595.71.05), torch 2.14.1+cu130:| Transformers | Result | Failures |
|---|---|---|
| 4.57.1 | 91 passed, 3 failed, 1 skipped | the 3 plain graph-path cases: capture error (
padding_mask.all()) || 5.19.0 | 88 passed, 6 failed, 1 skipped | the 3 plain graph-path and 3 continuous-batching-without-graphs cases: no
get_query_offset|All failures are the master issues above, which #8602 fixes. Every CPU test passes on both versions, and so does continuous batching with graphs end to end. The skipped test is the optional pretrained-model test
(
DEEPSPEED_PRETRAINED_ROLLOUT_MODEL).