[Performance][Attention] Fuse local SFA LSE formation into DCP pack - #15568
[Performance][Attention] Fuse local SFA LSE formation into DCP pack#15568Ruiqiu-Zheng wants to merge 2 commits into
Conversation
Pass native PA_BSND softmax max/sum statistics to the existing DCP payload packer and form FP32 LSE inside the Triton pack kernel. Preserve the legacy materialized-LSE entry point, All2All transport, and stable combine implementation. Add focused host routing/fake-op coverage and NPU pack/combine coverage for BF16/FP16, token/head scatter, non-contiguous strides, and invalid statistics. Signed-off-by: OpenAI Codex <codex@openai.com>
Exercise the repository-registered max/sum DCP custom op under eager execution and two-rank HCCL NPUGraph capture/replay for both scatter dimensions. Verify changed-input replay while preserving static input and output addresses. Use the spawn multiprocessing start method so child processes initialize independent NPU contexts on current torch_npu runtimes. Signed-off-by: OpenAI Codex <codex@openai.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:
If CI fails, you can run linting and testing checks locally according Contributing and Testing. |
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request optimizes the SparseFlashAttention (SFA) DCP post-processing pipeline by integrating LSE formation directly into the DCP pack kernel. By avoiding the materialization of a standalone FP32 LSE tensor, the change reduces memory overhead and improves latency in local composition and producer-to-pack intervals. The implementation maintains existing communication patterns and ABI compatibility while introducing robust handling for non-finite or invalid statistics. Highlights
New Features🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
There was a problem hiding this comment.
Code Review
Suggested PR Title:
[Attention][Feature] Support fused All2All with max/sum statistics in SFA CPSuggested PR Summary:
### What this PR does / why we need it?
This PR introduces a new custom operator `sfa_dcp_a2a_fused_max_sum` to support context-parallel All2All communication directly using `softmax_max` and `softmax_sum` statistics. Previously, LSE was materialized in Python before the All2All operation. By computing LSE on-the-fly within the Triton kernel (`_pack_sfa_dcp_output_lse_kernel`), we avoid extra memory allocation and overhead.
Key changes:
- Updated Triton kernel `_pack_sfa_dcp_output_lse_kernel` to support `INPUT_MAX_SUM` mode.
- Added `pack_sfa_dcp_output_max_sum` and registered the `sfa_dcp_a2a_fused_max_sum` custom op.
- Integrated the new op into `vllm_ascend/attention/context_parallel/sfa_cp.py`.
- Added comprehensive unit and end-to-end tests.
### Does this PR introduce _any_ user-facing change?
No. This is an internal optimization for context-parallel attention.
### How was this patch tested?
- Added unit tests in `tests/ut/ops/test_sfa_cp_max_sum.py` and `tests/ut/attention/test_sfa_cp_precision.py`.
- Added Triton-level tests in `tests/e2e/nightly/single_node/ops/singlecard_ops/triton/test_sfa_cp_a2a.py`.
- Added multi-rank integration tests in `tests/e2e/nightly/single_node/ops/multicard_ops_a3/test_sfa_cp_a2a.py`.I have no feedback to provide as there are no review comments.
|
CI triage: Could a maintainer please add |
What this PR does / why we need it?
This PR removes a local SparseFlashAttention DCP post-processing boundary by forming LSE inside the existing pack kernel instead of materializing a standalone FP32 LSE tensor before packing.
Before:
softmax_max/softmax_sumLSE = softmax_max + log(softmax_sum)After:
softmax_max/softmax_sumThe change preserves the existing row/head/token mapping, packed payload semantics, HCCL communication pattern, and downstream stable-combine ABI.
The legacy materialized-LSE custom-op path is kept for compatibility and regression coverage.
Invalid local statistics are handled explicitly. Non-finite
softmax_max, non-finitesoftmax_sum, orsoftmax_sum <= 0produce an invalid (-inf) LSE contribution, which is then handled by the existing combine semantics. Focused tests cover these cases.Performance evidence
The performance experiment used a preregistered paired/interleaved A/B protocol with fixed inputs and ordering:
202609162026091320260914The positive decision rule was fixed before measurement:
at least 75% of paired blocks favor candidate AND paired median improvement > max(1%, 2 * relative_noise_floor)Matched measurements on the recorded Ascend test environment were:
For the two-rank lane, the standalone arm medians and paired median point in slightly different directions, and both effects are far below the 8.819% decision threshold. It is therefore classified as neutral, not as either a speedup or a regression.
These numbers are scoped to the measured local/laboratory intervals. They are not end-to-end model, serving-throughput, or production-performance claims.
A sanitized reproducibility packet is available on an auxiliary branch of the fork. It is not part of this production PR and is not a CI dependency:
protocol, seeds, fixture, raw paired/null-control measurements, and correctness sentinels:
https://github.com/Ruiqiu-Zheng/vllm-ascend/tree/repro/sfa-local-lse-r016-20260902/repro/sfa-local-lse-r016
README and reproduction instructions:
https://github.com/Ruiqiu-Zheng/vllm-ascend/blob/repro/sfa-local-lse-r016-20260902/repro/sfa-local-lse-r016/README.md
independent reducer that recomputes the table above from raw JSON:
https://github.com/Ruiqiu-Zheng/vllm-ascend/blob/repro/sfa-local-lse-r016-20260902/repro/sfa-local-lse-r016/reduce_results.py
The exact binary fixture is:
SHA256 63785fa8f4592b7f8f9e06d345a20cf29a4ac8d19adc1e89dc8f90e60eb7db19The packet also contains the exact candidate reconstruction patch and source/runtime lineage.
Absolute latency is not expected to reproduce bit-for-bit on a different hardware/runtime state. The intended reproduction target is the paired effect relative to a freshly observed null-control noise floor under matched lineage and the same protocol.
Does this PR introduce any user-facing change?
No.
This is an internal DCP post-processing optimization. It does not add or change a public API, user configuration, environment variable, or user-visible model behavior.
How was this patch tested?
Focused post-rebase regression on the PR branch:
py_compile: passedgit diff --check: passedNPU correctness coverage includes:
scatter_dim = 0andscatter_dim = 1The two-rank graph regression covers eager execution, graph capture, first replay, and changed-input replay while keeping input/output storage addresses fixed. This checks that replay consumes updated tensor contents rather than returning stale captured results.
The PR was rebased as upstream
mainadvanced. Before each rebase, the decision-relevant Local-SFA callsite/pack seam was checked for upstream drift. No relevant source drift was observed, and the focused post-rebase regressions remained passing.