Skip to content

fix(dp-attn): DP-attention buffer sizing + EAGLE padding for require_attn_tp_gather=True - #26016

Open
ashutoshuiuc wants to merge 52 commits into
sgl-project:sglang-milesfrom
ashutoshuiuc:fix/dp-attn-extend-padding
Open

ashutoshuiuc wants to merge 52 commits into
sgl-project:sglang-milesfrom
ashutoshuiuc:fix/dp-attn-extend-padding

Conversation

@ashutoshuiuc

@ashutoshuiuc ashutoshuiuc commented May 21, 2026

Copy link
Copy Markdown

Summary

Fixes 7 bugs triggered when running DP-attention with require_mlp_tp_gather=False and require_attn_tp_gather=True (e.g. moe_dense_tp_size=1, ep_size=32, dp_size=4, attn_tp_size=8). Discovered while running GLM-4.5-355B-A32B training with EAGLE speculative decoding on 32 nodes (128 GPUs).

Fixes

1. global_num_tokens_gpu buffer sizing (scheduler_dp_attn_mixin.py, cuda_graph_runner.py, eagle_draft_cuda_graph_runner.py, eagle_draft_extend_cuda_graph_runner.py, model_runner.py, forward_batch_info.py)

Buffer allocation and _update_gather_batch only checked require_mlp_tp_gather to decide between dp_size vs 1 element. With our config (mlp=False, attn=True), get_dp_local_info() indexed out-of-bounds by dp_rank, producing garbage that crashed flashinfer with q.shape[0] does not match qo_indptr[-1].

Fix: change all guards to if require_mlp_tp_gather or require_attn_tp_gather.

2. EAGLE draft extend padding for DP-attention (flashinfer_backend.py, eagle_info.py)

EAGLE draft extend has num_tokens = batch_size * num_draft_tokens, not necessarily divisible by attn_tp_size. The DP-attention all-gather requires alignment but flashinfer metadata (qo_indptr, kv_indptr, kv_indices) wasn't padded to match.

Fix: append dummy padding request to flashinfer metadata covering the extra positions, same pattern the non-speculative extend path already uses for piecewise CUDA graph padding.

3. Truncate padded logits in EAGLE verify (eagle_info.py)

After DP-attention-padded forward, logits have ceil_align(n, attn_tp_size) rows but verify expects exactly bs * draft_token_num.

Fix: truncate next_token_logits before verification.

4. Reset heartbeat before declaring server ready (http_server.py)

CUDA graph capture takes ~53s for 355B. TokenizerManager.last_receive_tstamp was set at object creation, so /health_generate returned 503 immediately after startup. With DP-attention, one "unhealthy" shard causes NCCL hangs on all others.

Fix: reset last_receive_tstamp right before "fired up and ready to roll" log.

Config that triggers these bugs

--sglang-tp-size 32
--sglang-dp-size 4
--sglang-ep-size 32
--sglang-moe-dense-tp-size 1
--sglang-enable-dp-attention
--sglang-enable-dp-lm-head
--sglang-speculative-algorithm EAGLE

This gives attn_tp_size = tp_size / dp_size = 8, require_mlp_tp_gather = False (because moe_dense_tp_size == 1), require_attn_tp_gather = True.

Test plan

  • Tested with GLM-4.5-355B-A32B on 32x4-GPU nodes (128 GPUs total)
  • Without these fixes: crashes immediately on first decode batch (fixes 1-2) or first EAGLE draft extend (fixes 3-6)
  • With these fixes: rollout generation runs successfully through full batch generation
  • Fix 7 tested by observing /health_generate returning 200 immediately after server ready instead of 503

CI States

Latest PR Test (Base): ❌ Missing run-ci label -- add it to run CI tests.
Latest PR Test (Extra): ❌ Blocked -- run-ci is required first.
Latest PR Test (AMD ROCm 10): ➖ No AMD PR run found for this commit.

mickqian and others added 30 commits April 4, 2026 23:37
…alistic perf and auto-discover ut (sgl-project#22086)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Baizhou Zhang <sobereddiezhang@gmail.com>
…gl-project#21649)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Baizhou Zhang <sobereddiezhang@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Letian Ruan <ruanlt420@gmail.com>
…ng (sgl-project#22754)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Byron Hsu <byron+per@periodiclabs.ai>
Co-authored-by: Kurt Shuster <kurt@thinkingmachines.ai>
Co-authored-by: satyamk7054 <43010011+satyamk7054@users.noreply.github.com>
Co-authored-by: Satyam Kumar <satyamk@linkedin.com>
…y arch name

DeepseekV3ForCausalLM models on sm100 (B200) were unconditionally defaulted
to fp8 quantization. This breaks BF16 models that share the same architecture
(e.g. Moonlight-16B-A3B) because they lack FP8 scale tensors, causing
AssertionError in the flashinfer_trtllm MoE runner.

Instead of assuming FP8 by architecture name, read the safetensors file header
to check if expert weights are actually stored as F8_E4M3. This correctly
distinguishes DeepSeek V3/R1 (native FP8 experts) from Moonlight (BF16).

Made-with: Cursor
…follow-up to sgl-project#23731) (sgl-project#23734)

Co-authored-by: Byron Hsu <byron@periodiclabs.ai>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
ehuaa added a commit to ehuaa/sglang that referenced this pull request Jul 11, 2026
…kend

Fixes two crash sites when running MLA models (e.g. DeepSeek-R1) with
--enable-dp-attention + NEXTN/EAGLE speculative decoding on the flashinfer
backend, verified on 4-node tp32/dp4/ep32 DeepSeek-R1-0528-bf16:

1. Multi-step draft backend: grow the shared kv_indptr / q_indptr_decode
   buffers to the capture bound in init_cuda_graph_state and rebind them
   into the child backends (and their decode indices updaters, which cache
   references at construction). With dp-attention the max capture bs is
   rounded up to a multiple of attn_tp_size and can exceed the
   req_to_token_pool.size bound used in __init__, so the [: bs + 1] slices
   silently truncated and crashed flashinfer's plan with a size mismatch.

2. Prefill indices updater: with dp-attention the batch is padded before
   attention (extend_num_tokens / input_ids include padding rows) but the
   per-request seq_lens do not, so the qo_indptr built from
   cumsum(seq_lens - prefix_lens) falls short of q.shape[0] and flashinfer
   ragged prefill rejects the extra rows. Append a dummy padding request
   to the flashinfer metadata covering the padding tokens (same pattern as
   the piecewise-cuda-graph padding in flashinfer_backend.py, see sgl-project#26016).
ehuaa added a commit to ehuaa/sglang that referenced this pull request Jul 12, 2026
…kend

Fixes two crash sites when running MLA models (e.g. DeepSeek-R1) with
--enable-dp-attention + NEXTN/EAGLE speculative decoding on the flashinfer
backend, verified on 4-node tp32/dp4/ep32 DeepSeek-R1-0528-bf16:

1. Multi-step draft backend: grow the shared kv_indptr / q_indptr_decode
   buffers to the capture bound in init_cuda_graph_state and rebind them
   into the child backends (and their decode indices updaters, which cache
   references at construction). With dp-attention the max capture bs is
   rounded up to a multiple of attn_tp_size and can exceed the
   req_to_token_pool.size bound used in __init__, so the [: bs + 1] slices
   silently truncated and crashed flashinfer's plan with a size mismatch.

2. Prefill indices updater: with dp-attention the batch is padded before
   attention (extend_num_tokens / input_ids include padding rows) but the
   per-request seq_lens do not, so the qo_indptr built from
   cumsum(seq_lens - prefix_lens) falls short of q.shape[0] and flashinfer
   ragged prefill rejects the extra rows. Append a dummy padding request
   to the flashinfer metadata covering the padding tokens (same pattern as
   the piecewise-cuda-graph padding in flashinfer_backend.py, see sgl-project#26016).
@Jiminator
Jiminator deleted the branch sgl-project:sglang-miles September 14, 2026 04:44
@Jiminator Jiminator closed this Sep 14, 2026
@hnyls2002 hnyls2002 reopened this Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blackwell SM100/SM120 deepseek dependencies Pull requests that update a dependency file diffusion SGLang Diffusion jit-kernel lora memory-pool model-gateway Multi-modal multi-modal language model quant LLM Quantization

Projects

None yet

Development

Successfully merging this pull request may close these issues.