← Back to Pull requests

feat(rollout): non-greedy sampling on hybrid engine graph decode path #8939

Closed
unknown closed this pull request without merging on Nov 08, 2026 09:05 UTC
View on GitHub
unknown unknown commented on Oct 28, 2026 21:41 UTC
Author

Closes #8934.

Summary

HybridEngineRollout decodes greedily on its fast paths. Graph capture applies only when temperature <= 0, and sampling silently falls back to Hugging Face generate(). Continuous batching (#8368), with or without its CUDA graph (#8732), rejects temperature > 0 outright. 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:

  • One token selector, 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 <= 0 it takes the argmax, as before.
    - Otherwise it applies Hugging Face's TemperatureLogitsWarper, TopKLogitsWarper and TopPLogitsWarper, in generate()'s order on float32 logits, then calls torch.multinomial. So every path samples from the same distribution as generate().
  • Graph dispatch: sampled requests go to the graph path; generate() no longer checks is_greedy for it.

  • Continuous batching:

  • - 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): the generate() sampling arguments, now shared by the main generate() call and the continuous-batching prefill of models without cache-class support. That prefill previously hard-coded do_sample=False.

  • Docs: inference-engine.rst now 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.

  • Plain graph path (_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 call padding_mask.all() on the host (reported by 0z5a on #8197). #8602 passes a pre-built 4-D decode mask.

  • Plain graph path and continuous batching without graphs, Transformers 5.x: DeepSpeedStaticCache has no get_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):

  • The graph dispatch test also runs at temperature 0.7 and checks that 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_generate samples end to end on a tiny random Llama, with a scaled output head so next-token distributions are peaked.

  • Paths: graph decode, continuous batching, and continuous batching with graphs.

  • Settings: (temperature 1), (temperature 0.7, top-k 5) and (temperature 1, top-p 0.8).

  • Check: under the same seed, the generated tokens must equal Hugging Face generate()'s exactly. Every prompt gets its own continuous batching slot, so each path draws all rows' tokens in one call per step, as generate() 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).

    Diff: 622 lines (+466 / -156) across 7 files Reviewer: delock Review duration: 15083m
    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
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50.3% (MEDIUM) · Higher = larger blast radius
    50.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.9% · Safe to merge
    19.9%