Reuse the static rollout decode graph across calls #9077
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 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.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #9077"
general
weight: 0.35
jinyouzhi
Summary
The default graph path (
use_graph_capture=Truewithoutcontinuous_batch_size) builds a newDeepSpeedStaticCache, runs three warmup forwards and captures a new graph on everygenerate()call. In an RL loop that is a fixed cost per rollout round, although the decode graph depends only on the decode shape.This PR keeps the static path's graph and cache across calls, as #8732 / #9009 do for the continuous path. Rebased onto master after #9127 merged, so the #9126 correctness fixes are inherited rather than duplicated. The remaining patch is focused on static graph reuse and segment-KI lifecycle.
| | Before | After |
| --- | --- | --- |
| Per
generate()call | Allocate cache, 3 warmups, capture | Eager prefill; replay the retained graph || Recapture trigger | Every call | Graph signature changes: batch size, prompt width +
max_new_tokens, device, dtype, parameter layout, training mode, autocast, b=1 step-kernel use, or asegki_refresh()|| In-place weight updates | n/a | Without segKI: replayed without recapture. With segKI:
sync_weights()/refresh_weights()/segki_refresh()force a recapture, because the injected kernels cache tensors derived from the weights || Tensor parallelism | n/a | Ranks of each group whose collectives the decode forward runs (AutoTP, the HybridEngine inference group, segKI's lm_head group) agree on recapture with an all-reduce, so no rank captures while its peers replay. They also agree on a capture failure, so all of them raise rather than one replaying a graph its peer lacks. Data-parallel replicas decide on their own |
|
shutdown()| Releases the continuous state | Releases both states |segKI (#8602)
segki_refresh()bumps a counter in the graph signature, so a graph that captured the freed derived tensors is never replayed.refresh_weights()additionally releases it right away.LinearAllreducelayers) instead of the world. Under pure data parallelism the lm_head previously mixed other replicas' logits into each rank's and all-gathered over the world outside the recapture agreement; now it keeps the whole head and gathers nothing.VocabParallelLinearhead (tensor_parallel.vocab_parallel_lm_head=True) is no longer patched by the segKI lm_head install: it already holds a vocab/tp shard, so a patch would halve the shard and all-gather, silently decoding a subset of the vocabulary. It keeps its own forward, and the rollout's gather_output flag turns its rank-local logits into full-vocabulary ones for sampling (a pre-existing master bug, fixed by this PR).Relationship to #9127
#9127 independently fixed the post-#8602 local-KV, additive-mask, and repetition-penalty regressions. This PR is rebased on top of that merged fix and drops duplicate correctness hunks. The following checks remain part of the graph-reuse validation:
test_static_graph_uses_prefill_kv_shape: the decode cache is sized from the prefill's local KV tensors again (#9008), not from the config divided by world size.test_static_graph_matches_native_llama_generation[eager]: eager attention adds the mask to the scores, so it gets an additive mask built inside the graph from the boolean one.test_decode_repetition_penalty_matches_hf_generate: the repetition penalty is applied on the graph prefill and Python decode paths again; the b=1 step kernel is used only without a penalty.Tests
test_static_graph_is_reused_across_rollouts_with_the_same_decode_shape(Llama): capture once per decode shape, in-place update changes the tokens without recapture, train mode and autocast force recapture,shutdown()frees the cache.TestAutoTPGraphRecapture(2 GPUs): ranks recapture together.test_static_graph_is_recaptured_after_a_peer_capture_failure: a rank whose own capture succeeded while a peer's failed captures again on the next call instead of replaying.TestSegKIDataParallelRollout(2 ranks, segKI + static graph, a different prompt per rank): each rank matches its own un-injected HFgenerate(). Fails on master, passes here (2x L20).test_capture_failure_on_any_rank_fails_capture_on_every_rank,test_recapture_is_agreed_over_the_segki_lm_head_tp_group(CPU, mocked collectives).TestLmHeadSplitsOverTheTensorParallelGroup(2 CPU ranks): a data-parallel lm_head is not split; a tensor-parallel one gathers over the model's group.test_graph_reused_until_refresh[1, 2](Qwen3.5-0.8B, segKI): one capture across two rollouts with the same tokens;segki_refresh()andrefresh_weights()each force one recapture with the same tokens.4× NVIDIA L20, torch 2.14.1+cu130, Transformers 5.17.0,
test_segment_ki_kernels.py,test_graph_position_regression.py,runtime/rollout/test_hybrid_engine_rollout.py,v1/test_hybrid_engine_rollout_v1.py: 220 passed, 3 skipped, 3 failed. The 3 failures fail the same way on master on this machine (Qwen3RMSNormhas noepsin Transformers 5.17;torch.get_acceleratormissing in this torch). Master on the same files: 6 more failures (listed above).Qwen3.5-0.8B, segKI + graph, prompt 128, 128 new tokens, greedy: tokens identical to master at b=1 and b=4; per-call time 0.63 → 0.53 s (b=1) and 0.76 → 0.65 s (b=4) from skipping the recapture.
Multi-rank checks on H20 (torch 2.13.0+cu130, Transformers 5.17.0), static and continuous paths:
| Scenario | Before | After |
| --- | --- | --- |
| Pure DP, only rank 1's signature changes | n/a | captures [1, 2], no hang |
| TP=2 × DP=2, only rank 1's signature changes | n/a | captures [2, 2, 1, 1], tokens match HF on all ranks |
| AutoTP=2, rank 1's capture raises, then both retry | rank 0 hangs in replay (NCCL timeout) | both raise; the retry captures [2, 2], tokens match HF |
On 2× L20, segKI without AutoTP with only rank 1's signature changing: before, captures [1, 2], wrong tokens and then a hang; the TP-group fix is covered by the CPU tests above (L20 was unavailable for a rerun).
H20, with this PR:
v1/test_hybrid_engine_rollout_v1.py63 passed, 1 skipped;runtime/rollout/test_hybrid_engine_rollout.py183 passed, 4 skipped (TestZero3SynchronizedEarlyStopdeselected:transformer_inferencecannot be built on this host, cusparse.h is missing).Not covered
LinearLayerforward (cuBLAS + the TP gather), which is correct but does not use the segKI kernel. Wiring the per-shardgrouped_linearinto that training-shared forward is a follow-up.This PR was prepared with AI assistance (GitHub Copilot); I reviewed and tested the changes.