Skip to content

[Fix] [NPU] dspark: Fix attn_tp > 1 draft wo_b all_reduce group - #40399

Merged
iforgetmyname merged 6 commits into
sgl-project:mainfrom
unclezhou486:fix-dspark-attn-tp-wo-b-reduce
Oct 21, 2026
Merged

iforgetmyname merged 6 commits into
sgl-project:mainfrom
unclezhou486:fix-dspark-attn-tp-wo-b-reduce

Conversation

@unclezhou486

@unclezhou486 unclezhou486 commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

DSpark speculative decoding with a DeepSeek-V4 (MoE) draft supports DP attention
(attn_tp_size < tp_size) on Ascend NPU, but the draft attention's output
projection wo_b reduced its partial results over the wrong process group,
which corrupted the draft output and collapsed the accept rate to ~0.

DSparkAttention (python/sglang/srt/models/deepseek_v4_dspark.py) subclasses
MqaAttentionBase and hard-codes wo_b_reduce_results=True, overriding the
base's default reduce_results = (attn_tp_size == tp_size and attn_tp_size > 1).
As a result, under DP attention (attn_tp_size < tp_size) wo_b still performed
a row-parallel all-reduce, but over the full DP × TP group, while its weight
is sharded over the attn-TP group only. That summed partial outputs that
belong to different DP ranks' different batches, so the draft attention output
was garbage and the accept rate collapsed to ~0.

A guard in DSparkWorkerV2 rejected this whole configuration
(attn_tp > 1 + DP attention + MoE draft), which blocked the feature on NPU.

(Note: the guard's error string referred to the "MoE-under-DP all-reduce", but
the actual corruption was the draft attention's wo_b reduce group; the draft
MoE path itself handles attn_tp > 1 via _dp_gather_via_all_gather.)

Modifications

  1. python/sglang/srt/models/deepseek_v4.py

    • MqaAttentionBase.wo_b now passes
      use_dp_attention_reduce=is_dp_attention_enabled(), so its row-parallel
      all-reduce runs over the attn-TP group (get_parallel().attn_tp_group)
      when DP attention is enabled, matching the weight sharding.
    • DSparkAttention.forward calls self.wo_b(...) directly (it does not use
      _project_wo_b), so this single flag fixes the draft reduce with no
      double-reduce.
  2. python/sglang/srt/speculative/dspark_components/dspark_worker_v2.py

    • Allow the attn_tp > 1 MoE-draft + DP-attention configuration on NPU by
      adding and not _is_npu to the guard. CUDA/ROCm still reject it.
  3. python/sglang/srt/hardware_backend/npu/attention/ascend_dsv4_backend.py

    • Pad the draft ori_sparse_indices tail with -1 ("skip") up to the
      attn-TP-padded token count, matching out_cache_loc
      (prepare_mlp_sync_batch pads the query to an attn_tp multiple, but
      seq_lens is not).

Accuracy Tests

Model Dataset Metric Subset Num Score
DeepSeek-V4-Pro-0813-w4a8 GPQA-Diamond Accuracy ↑ gpqa_diamond 198 88.9%

Speed Tests and Profiling

Model Dataset Num Avg Lat Avg TTFT Avg TPOT Avg Thpt Avg In Avg Out
DeepSeek-V4-Pro-0813-w4a8 GPQA-Diamond 198 227.141 s 8876.8 ms 44.7 ms 25.74 tok/s 252 5847

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ✅ Run #39185582451
Latest PR Test (Extra): ❌ Run #39185582349
Latest PR Test (AMD ROCm 10): ❌ Run #39185582366

@sglang-npu-bot

Copy link
Copy Markdown
Collaborator

/tag-run-ci-label

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Oct 8, 2026
@unclezhou486

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci

@unclezhou486

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci try again

@unclezhou486

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci try again again

@unclezhou486

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci try again again again

@unclezhou486

unclezhou486 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci try again again again again again again again again again again again again again
again again

DSparkAttention hard-coded wo_b_reduce_results=True, so its row-parallel
wo_b all-reduced over get_tp_group() (the full DP x TP group) while its
weight is sharded by attn_tp_size only. Under DP attention (attn_tp_size <
tp_size) this summed the partial outputs of different DP ranks' different
batches, corrupting the draft attention output and collapsing the accept
rate to ~0.

Mirror MqaAttentionBase: drop the override so reduce_results defaults to
(attn_tp_size == tp_size), and add the explicit attn_tp_all_reduce after
wo_b. Drop the attn_tp == 1 guard this configuration was hiding behind.
@unclezhou486
unclezhou486 force-pushed the fix-dspark-attn-tp-wo-b-reduce branch from f54b813 to 9308451 Compare October 15, 2026 08:20
@unclezhou486

unclezhou486 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci again again again again again again again again

@unclezhou486 unclezhou486 changed the title [DSpark][NPU] Fix attn_tp > 1 draft wo_b all_reduce group [Fix][NPU] Fix attn_tp > 1 draft wo_b all_reduce group Oct 16, 2026
@unclezhou486

unclezhou486 commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci again again again again

@unclezhou486 unclezhou486 changed the title [Fix][NPU] Fix attn_tp > 1 draft wo_b all_reduce group [Fix] [NPU] dspark: Fix attn_tp > 1 draft wo_b all_reduce group Oct 16, 2026
@iforgetmyname iforgetmyname added the bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) label Oct 19, 2026
@unclezhou486

unclezhou486 commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor Author

/rerun-failed-ci again
again again again again again again again again

@iforgetmyname
iforgetmyname merged commit c0d18c0 into sgl-project:main Oct 21, 2026
704 of 811 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bypass-fail-fast CI: a failing job no longer aborts its siblings (lint still gates) deepseek npu run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants