Repository navigation
[Fix] [NPU] dspark: Fix attn_tp > 1 draft wo_b all_reduce group - #40399
Merged
iforgetmyname merged 6 commits intoOct 21, 2026
Merged
Conversation
unclezhou486
requested review from
Qiaolin-Yu,
Ying1123,
hnyls2002 and
merrymercy
as code owners
September 20, 2026 02:25
AndyLi429
reviewed
Sep 20, 2026
AndyLi429
reviewed
Sep 20, 2026
unclezhou486
requested review from
iforgetmyname,
ping1jing2 and
whybeyoung
as code owners
September 21, 2026 07:15
Collaborator
|
/tag-run-ci-label |
Contributor
Author
|
/rerun-failed-ci |
Contributor
Author
|
/rerun-failed-ci try again |
Contributor
Author
|
/rerun-failed-ci try again again |
Contributor
Author
|
/rerun-failed-ci try again again again |
Contributor
Author
|
/rerun-failed-ci try 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
force-pushed
the
fix-dspark-attn-tp-wo-b-reduce
branch
from
October 15, 2026 08:20
f54b813 to
9308451
Compare
Contributor
Author
|
/rerun-failed-ci again again again again again again again again |
Contributor
Author
|
/rerun-failed-ci again again again again |
iforgetmyname
approved these changes
Oct 19, 2026
Contributor
Author
|
/rerun-failed-ci again |
Open
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 outputprojection
wo_breduced 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) subclassesMqaAttentionBaseand hard-codeswo_b_reduce_results=True, overriding thebase'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_bstill performeda 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
DSparkWorkerV2rejected 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_breduce group; the draftMoE path itself handles
attn_tp > 1via_dp_gather_via_all_gather.)Modifications
python/sglang/srt/models/deepseek_v4.pyMqaAttentionBase.wo_bnow passesuse_dp_attention_reduce=is_dp_attention_enabled(), so its row-parallelall-reduce runs over the attn-TP group (
get_parallel().attn_tp_group)when DP attention is enabled, matching the weight sharding.
DSparkAttention.forwardcallsself.wo_b(...)directly (it does not use_project_wo_b), so this single flag fixes the draft reduce with nodouble-reduce.
python/sglang/srt/speculative/dspark_components/dspark_worker_v2.pyattn_tp > 1MoE-draft + DP-attention configuration on NPU byadding
and not _is_nputo the guard. CUDA/ROCm still reject it.python/sglang/srt/hardware_backend/npu/attention/ascend_dsv4_backend.pyori_sparse_indicestail with-1("skip") up to theattn-TP-padded token count, matching
out_cache_loc(
prepare_mlp_sync_batchpads the query to an attn_tp multiple, butseq_lensis not).Accuracy Tests
Speed Tests and Profiling
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ✅ Run #39185582451
Latest PR Test (Extra): ❌ Run #39185582349
Latest PR Test (AMD ROCm 10): ❌ Run #39185582366