Skip to content

[Attention] DCP sparse MLA output-merge optimizations - #48196

Draft
LucasWilkinson wants to merge 1 commit into
vllm-project:mainfrom
LucasWilkinson:codex/dcp-sparse-mla-merge
Draft

[Attention] DCP sparse MLA output-merge optimizations#48196
LucasWilkinson wants to merge 1 commit into
vllm-project:mainfrom
LucasWilkinson:codex/dcp-sparse-mla-merge

Conversation

@LucasWilkinson

Copy link
Copy Markdown
Collaborator

Summary

Optimizes the DCP decode attention-output merge for sparse MLA. This is one of two PRs split out of #47355 (which is now scoped to just the indexer side-stream overlap). The two are independent and target main directly — they touch disjoint regions of forward_impl, so they can merge in either order.

  • Project-before-merge: project the attention output through an all-gathered W_UV before the DCP merge, shrinking the exchanged payload from kv_lora_rank to v_head_dim per head. Exact — the LSE-weighted merge and the linear W_UV projection commute. Encapsulated in _dcp_merge_and_v_up_proj / _dcp_lse_merge.
  • FlashInfer helix A2A: default the DCP A2A merge transport to FlashInfer's fused decode-CP all-to-all when available (measured ~15.5µs vs 45–74µs for NCCL all_to_all_single at the decode merge payload), with a Triton/NCCL fallback.
  • Valid counts: propagate per-row valid counts into the merge so empty sparse rows are handled in the pack without extra zero-fill passes.
  • Workspace sizing: auto-size the TRTLLM sparse-MLA workspace for the DCP head-gathered decode shape.

Relationship to #47355

Split from #47355. This PR is the DCP-specific half; #47355 is the indexer side-stream overlap (which applies to all sparse-MLA decode, not just DCP). Independent; either can land first.

Not a duplicate

Extends the existing DCP a2a merge already in main (dcp_a2a_lse_reduce, cp_lse_ag_out_rs) with the helix transport, project-before-merge, and valid-count handling. No open PR covers this.

Testing

  • tests/distributed/test_dcp_a2a.py — 4-rank pack/combine vs reference incl. valid-count handling and CUDA graph capture.
  • GSM8K-64 on GLM-5.1-NVFP4 TP4/DCP4 — accuracy parity (0.98, matching the DCP=1 reference).
  • imports, ruff, and manual-stage mypy on all touched files.

AI assistance

AI assistance (Claude) was used to author this change; the submitter has reviewed every line and run the tests above.

Optimize the DCP decode attention-output merge for sparse MLA:

- Project the attention output through an all-gathered W_UV before the DCP
  merge, shrinking the merge payload from kv_lora_rank to v_head_dim per
  head. Exact: the LSE-weighted merge and the linear W_UV projection
  commute. Encapsulated in _dcp_merge_and_v_up_proj / _dcp_lse_merge.
- Default the DCP A2A merge transport to FlashInfer's fused decode-CP
  all-to-all (helix) when available (measured 15.5us vs 45-74us for NCCL
  all_to_all_single at the decode merge payload), falling back to the
  Triton/NCCL path otherwise.
- Propagate per-row valid counts into the merge so empty sparse rows are
  handled in the pack without extra zero-fill passes.
- Auto-size the TRTLLM sparse-MLA workspace for the DCP head-gathered
  decode shape.

AI assistance (Claude) was used to author this change; the submitter has
reviewed every line and run the tests below.

Tests: tests/distributed/test_dcp_a2a.py (4-rank pack/combine vs reference,
incl. valid-count handling and CUDA graph capture); GSM8K-64 on
GLM-5.1-NVFP4 TP4/DCP4 (accuracy parity); imports, ruff, manual-stage mypy.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Lucas Wilkinson <lwilkins@redhat.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify

mergify Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @LucasWilkinson.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Jul 14, 2026
Leoyzen added a commit to Leoyzen/vllm that referenced this pull request Aug 14, 2026
…ap long lines

- mla_attention.py: add get_current_vllm_config_or_none, cp_lse_ag_out_rs,
  dcp_a2a_lse_reduce imports for _dcp_merge_and_v_up_proj (vllm-project#48196); drop
  unused finalize_mla_pcp_decode import
- test_mtp.py: add missing torch import for prefix-cache test (vllm-project#50897)
- cli_args.py: wrap >88-col lines (vllm-project#50668)
- flashmla_sparse.py: wrap long comment (vllm-project#49357)
- flashinfer_mla_sparse.py: drop unused np_to_pinned_tensor import (vllm-project#48196)
- kv_cache_coordinator.py: fix factory-function param indentation (vllm-project#50897)

Co-authored-by: Sisyphus <sisyphus@openci.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant