Repository navigation
[Fix] [NVIDIA] deepseek-v4.1: Fix the breakable prefill CUDA graph in the late-layer tail on SM90 - #45407
Conversation
… the late-layer tail on SM90 Without the in-graph low-ratio path (SM90), the late-layer tail of decoder SWA bounded replay broke the breakable prefill graph twice: the tail's eager low-ratio break rebuilt its rows from the whole extend's extend_seq_lens (repeat_interleave assert during warmup), and the source-layer KV write at the start of the tail was captured with the capture-time row count (assert on replay). Take the live prefix of the hoisted rows in that break, and run the source-layer KV write as an eager break over the live rows. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Cover deepseek_v4_write_tail_source_kv: it writes only the extend's live rows, and with no live rows it skips the write but still marks the source layer, as write_tail_source_kv does, so the layer's own pass inside the tail skips its compressor. Comment the zero-row branch accordingly. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
8edbe4b to
09c246d
Compare
|
/rerun-test test_deepseek_v4.py test_dsv41_late_layer_tail_readers.py test_encoder_swa_replay.py test_megakernel_binding.py test_deepseek_v41_flash_gb300_tp2ep2.py test_deepseek_v41_flash_gb300_dp2ep2.py test_deepseek_v41_flash_gb300_encoder_bcg.py test_deepseek_v41_flash_gb300_trtllm_bounded_bcg.py test_dsv41_prefill_sparse_indexer.py test_dsv41_candidate_blocks.py test_dsv4_nonpaged_indexer.py test_dsv41_candidate_graph_variants.py test_prefill_cuda_graph_runner.py |
|
/tag-and-rerun-ci |
|
🚀 🚀 🚀 🚀 |
|
🚀 🚀 🚀 🚀 |
…rows; the break only slices them
|
🚀 🚀 🚀 🚀 |
…io_sources sgl-project#45407 slices q_lora with [:n] on the hoisted-rows path of forward_low_ratio_sources. On gfx950 the indexer's wq_b operand is an Mxfp8Activation or Fp8GridActivation, which refuses slicing, so a DeepSeek-V4.1 DSpark server crashes while capturing the target-verify CUDA graph. Move _first_rows from the HIP backend into the shared backend and take the rows through it.
…rows Simpler form of the fix: forward_low_ratio_sources cuts x and q_lora only when the step has rows past the hoisted ones (DP attention padding an eager extend), as before sgl-project#45407; in every other case they already have n rows. That cut keeps HIP's quantized activations whole, field by field. write_tail_source_kv's input is a bf16 tensor (fused_boundary_attn_input), so it keeps sgl-project#45407's check. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… rows The all-rows-live pass-through (the crash sgl-project#45407 caused) and the DP-padding cut are separate cases, each with the failure it prevents in its docstring. The hoisted req / pos assertions go: test_tail_break_uses_live_prefix_of_hoisted_rows pins them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Motivation
On H200 (SM90), DeepSeek-V4.1-Flash with decoder SWA bounded replay (on by default; the cookbook lists breakable prefill as supported with it) cannot serve with
--cuda-graph-backend-prefill breakable. The late-layer tail fails in two places, both on paths that SM100 does not take: SM90 has no in-graph low-ratio path (low_ratio_prefill_graphis false), so the ratio-1/2 sources run as eager breaks or, in one place, get captured.torch.repeat_interleave(Repeat.cu:20: result_size == cumsum_ptr[size - 1]); the CUDA 719 and DeepGEMM errors that follow are knock-on errors. Call chain:bcg_deepseek_v4_low_ratio_sources→forward_low_ratio_sources→token_req_indices→repeat_interleave(req, extend_seq_lens, output_size=positions.shape[0]). Inside the tail, the eager break sees only the tail's live rows, whileforward_batch.extend_seq_lensstill spans the whole extend. The hoistedlow_ratio_req_indices/low_ratio_pos_i64already hold the tail's rows (live rows first, bucket-sized), but they are only used when their length equals the break's row count, which it does not inside an eager break.the output_size argument (8) must be the same as the sum of the elements in the repeats tensor (6). The source-layer KV write at the start of the tail (write_tail_source_kv) is called directly from the model, not through an eager break, so on SM90 itstoken_req_indicesand the host-side compressor are captured with the capture-time row count.This still reproduces on
main@c1c287a4: without this change, the breakable launch below crashes while capturing the prefill graph with the sameRepeat.cu:20assert.#45381 fixes a different capture failure of the same low-ratio prefill-graph path on SM12x.
Modifications
deepseek_v4_backend.py(forward_low_ratio_sources): when the hoisted rows are longer than the break's rows in an extend, take their live prefix instead of rebuilding the rows fromextend_seq_lens. Bucket-sized calls (the in-graph path) and calls without hoisted rows are unchanged.token_req_indicescomputes; inside the tail it is the only correct value. The prefill-graph full top-k break (_prefill_graph_full_topk_break) already takeslow_ratio_req_indices[:real]the same way. If a narrower condition is preferred, it can check the tail metadata explicitly; happy to switch.deepseek_v4.py: a new eager break,bcg_deepseek_v4_write_tail_source_kv, slices the source-layer input to the live rows likedeepseek_v4_low_ratio_sources, with the same capture-stub contract as_low_ratio_sources_capture_stub. The tail's source-KV write uses it inside a breakable prefill graph when the backend has no in-graph low-ratio path; every other configuration keeps the direct call. The condition readslow_ratio_prefill_graphthe same way as the existing low-ratio call site in_forward_prepare. With no live rows it skips the write but still setstail_source_kv_layer_id, aswrite_tail_source_kvdoes, so the source layer's own pass inside the tail keeps skipping its compressor. Rebased ontomain@c1c287a4, where [Perf] [AMD] dsv41: Skip unneeded layer 20 computation under decoder-bounded-replay #45339 computessource_xat the same call site with a HIP branch; that computation is kept and only the call after it is dispatched.main@c1c287a4):TestDSV4LateLayerTailLowRatioRowschecks that a tail-sized eager break gets the live prefix of the hoisted rows for both the compressor and the indexer. It fails before this change (RuntimeError: allocated size does not match required sizefromrepeat_interleave, the rows rebuilt fromextend_seq_lensnot matching the break's row count) and passes after.TestDSV4WriteTailSourceKvBreakchecks that the source-KV break passes only the firstglobal_num_token_non_padded_cpurows ofxandpositionstowrite_tail_source_kv, and that with zero live rows it does not call it but still marks the source layer. It covers a function this PR adds, so it has no before/after comparison; it passes.Accuracy Tests
Setup: DeepSeek-V4.1-Flash on 8×H200, image
lmsysorg/sglang:nightly-dev-cu13-20261021-c1c287a4(main@c1c287a4), with this PR's commits applied to the image's source tree for the "this change" column.Launch flags:
--tp 8 --attention-backend dsv4 --moe-runner-backend marlin --mem-fraction-static 0.70 --chunked-prefill-size 16384 --prefill-decode-interval 16 --enable-decoder-swa-bounded-replay --swa-prefix-tails 1024 --speculative-algorithm DSPARK --speculative-dspark-block-size 5 --speculative-num-steps 1 --speculative-eagle-topk 1 --speculative-num-draft-tokens 6 --enable-hierarchical-cache --hicache-ratio 2 --language-model-only, plus--cuda-graph-backend-prefill breakable --cuda-graph-max-bs-prefill 4096for the graph runs. "Eager" is the same launch without the two prefill-graph flags.Repeat.cu:20assert, item 1)max_total_num_tokensSWA_WINDOW), unless it asks for prompt logprobs or every hidden state; speculative verify extends do not run the tail. (--swa-prefix-tails 1024is unrelated: it sizes how many radix-cached prefix tails the SWA KV pool keeps room for.) In a separate run of this change with a counting log added (not part of this PR), sgl-eval GSM8K (200 questions) and the smoke ran 40 prefill forwards through the tail after startup: 31 were graph replays (up to 3,447 tail rows), which run the two eager breaks changed here, and 9 ran eager (batches over the 4,096-token capture cap, or chunks whose context exceeds the 16K replay limit).nightly-dev-cu13-20261018-b234b5c3, before the rebase: GSM8K (InferenceX setup) 0.9727 / 0.9735 with this change and eager, a second pair with--max-running-requests 64at 0.9742 / 0.9742, long-context retrieval 6/6, smoke 15/15./generatewithreturn_logprobandlogprob_start_len 0, T=0): the graph-vs-eager difference (mean |Δlogprob| 0.158 / 0.160) is the same as the run-to-run difference of each configuration (0.159 eager, 0.157 graph). Requests for prompt logprobs run the late layers over the whole prompt rather than the bounded tail, so this check covers the graph's numerics but not the tail path changed here; the tail path is covered by the accuracy rows and the smoke above.--cuda-graph-max-bs-prefill 4096: with the default capture sizes the graph pool takes about 29.6 GB at--mem-fraction-static 0.70, and the first eager chunk of a 128K cold prefill (chunks past the 16K replay limit run eager) ran out of memory in the eager torch indexer scoring (measured on b234b5c). Capping the capture at 4,096 tokens keeps the pool at 8.75 GB with the same KV pool size. That is a memory-headroom setting for this configuration, not part of the fix: with the default capture sizes the fix also captures, starts and serves the same smoke prefills without errors, with the same KV pool size, long-context retrieval 6/6 and GSM8K 0.9697 (within the ±0.0047 standard error); only the 128K cold prefill ran out of memory.Speed Tests and Profiling
On
main@c1c287a4(single requests, same server as the accuracy rows):Measured earlier on b234b5c:
Cold-prefill TTFT (random-word prompts, no cache hit,
max_tokens1, median of 3; the nominal sizes are estimated at 2.3 words per token, so actual token counts are somewhat larger):Short prefills lose a fixed ~0.2 s of eager launch overhead. Prefill chunks whose context exceeds 16K still run eager on SM90 (#43733 lifts that limit only on SM100), so long prefills are unchanged.
Load test, 900 s per point after a 600 s warmup, InferenceX agentic traces (SLO lines TTFT p90 ≤ 5,750 ms, TPOT p90 ≤ 34.5 ms), same flags as above with
--max-running-requests 64:Checklist
This PR was prepared with AI assistance (Claude Code). The submitter reviewed every changed line and the validation above.
🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ⏳ Run #39880852240
Latest PR Test (Extra): ❌ Run #39880852054
Latest PR Test (AMD ROCm 10): ⏳ Run #39880852335