Repository navigation
Conversation
|
👋 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 introduces a performance optimization for Mixture of Experts (MoE) inference on Ascend 910B2. It replaces the slow AICPU-based prefix-sum operation for small INT64 token counts with a specialized AscendC AIV scalar kernel. This change achieves up to a 93.5% latency reduction for the cumsum operation without altering the user-facing API or compromising model accuracy. 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:
[Ops][Feature] Add specialized moe_counts_cumsum custom operator for Ascend NPUSuggested PR Summary:
### What this PR does / why we need it?
This pull request introduces a specialized custom operator `moe_counts_cumsum` for Ascend NPU to optimize the cumulative sum of MoE expert counts. It implements an Ascend C kernel (`moe_counts_cumsum_kernel`), registers it as a PyTorch custom operator, and integrates it into `cumsum_group_list` to avoid unnecessary narrowing and keep the scan operation in the NPU stream.
Feedback:
- In `moe_counts_cumsum.cpp`, `DataCopy` should be used instead of `DataCopyPad` when copying from Local Tensor to Global Tensor (UB -> GM).
- When copying from GM to UB with `DataCopyPad`, `isPad` should be set to `true` to handle unaligned memory access safely.
- A safety check should be added to limit the maximum number of elements (e.g., up to 4096) to prevent Unified Buffer (UB) capacity overflow and potential memory corruption.
### Does this PR introduce _any_ user-facing change?
No, this is an internal performance optimization for MoE operations on Ascend NPUs.
### How was this patch tested?
Added end-to-end tests in `test_moe_counts_cumsum.py` and unit tests in `test_moe_counts_cumsum_dispatch.py` to verify correctness, graph replay behavior, and input validation.|
@zzzzwwjj Could you take a look and help trigger CI? Thanks! |
|
I also tested a specialized custom AICPU implementation on Ascend 910B2 with CANN 9.2.1. It performs the full INT64 prefix sum through a direct entry taking input/output pointers and the element count, bypassing the generic NodeDef/Tensor/Context processing.
These are NPU Event measurements without an active profiling session: the span of 64 captured nodes divided by 64, including inter-node gaps. Values are the median of six trial medians, with 40 measurements per trial after warmup and interleaved route orders. The AIV implementation tested was |
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
|
Updated the dispatch to enable moe_counts_cumsum only for the Ascend 910B hardware profile. Other device families retain the existing cumsum path |
97e4546 to
93e0c5f
Compare
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
Signed-off-by: lumen183 <2024311525@stu.hit.edu.cn>
Signed-off-by: lumen183 <2024311525@stu.hit.edu.cn>
Signed-off-by: lumen183 <2024311525@stu.hit.edu.cn>
Enable the specialized kernel through the 910B hardware profile and retain the existing conversion on other device families. Signed-off-by: lumen183 <2024311525@stu.hit.edu.cn>
ed5b542 to
6a9712f
Compare
|
This pull request has conflicts, please resolve those before we can evaluate the pull request. |
What this PR does / why we need it?
This pull request introduces a specialized custom operator
moe_counts_cumsumfor Ascend NPU to optimize the cumulative sum of MoE expert counts. It implements an Ascend C kernel (moe_counts_cumsum_kernel), registers it as a PyTorch custom operator, and integrates it intocumsum_group_listto avoid unnecessary narrowing and keep the scan operation in the NPU stream.Motivation
Profiling MoE inference on Ascend 910B2 shows that
cumsum_group_listlaunches an AICPU task when converting INT64 per-expert token counts to cumulative group boundaries. These arrays are small: DeepSeek-V4-Flash uses 256 entries with EP disabled and 32 entries per rank with EP8.In the tested CANN/torch_npu stack, the generic AI Core/vector Cumsum path does not support this INT64 input, so the native operation runs on AICPU. This is a limitation of the available Cumsum path, rather than a lack of INT64 scalar arithmetic on AI Core.
The workload is dominated by task and framework overhead. A device-side instrumentation experiment of TP8 workload measured:
Implementation
Add an AscendC kernel specialized for small MoE counts-to-prefix conversion:
cumsum_group_listonly for counts-to-prefix conversion with a one-dimensional NPU INT64 input. This specialized path assumes the small MoE counts array fits in UB. Retain the original path for other conversions and when the custom operator is unavailable or disabled.Does this PR introduce any user-facing change?
Yes. This is a performance improvement for the eligible INT64 MoE counts-to-prefix path on Ascend 910B2, with no changes to the existing API.
How was this patch tested?
Validation environment
8 × Ascend 910B2; driver 25.2.1; CANN 9.2.0; torch 2.10.0+cpu; torch_npu 2.10.0.post7; Triton Ascend 3.6.0; Python 3.12.13. All measured tensors execute on NPU.
vllm-ascend base:
e07bf18b76ce8543baffafa9ba868e86305d15b2; core vLLM:db9527a46873454610df6dbedf79a36d6bf1a7f6(0.31.0+empty). Model: DeepSeek-V4-Flash W8A8, 43 layers, 256 experts, top-k 6; MTP disabled.Operator performance
Latency was measured with NPU Events during graph replay, without profiling. Results report median latency per operation across repeated trials, measured over 64 operations per replay.
Correctness and model accuracy
Model-level validation used a fixed 256-question GSM8K subset with real prefill and normal greedy generation: seed 42, temperature 0, maximum 2048 generated tokens.
The two runs agree on 255/256 final answers. An earlier native run scored 248/256, demonstrating same-route model-run variability. These result suggests that AIV cumsum implementation preserves model-level accuracy.
Model decode performance
The completed TP8 / EP-disabled experiment uses real model weights, synthetic initial KV. It measures client-observed token delivery within the inference engine, excluding HTTP transport and detokenization. Mean TPOT is
(last_token_time - first_token_time) / 1023, excluding the first-token interval. Each configuration has native-pre → AIV → native-post stages, with three 1024-token runs per stage. The native result averages the pre/post means.Reproduction
After applying the patch and building the custom extension in a matching Ascend environment, run from the vllm-ascend repository root:
Scope and remaining validation
This PR specializes the small INT64 MoE counts-to-prefix workload. Performance and device validation reported here cover Ascend 910B2.
Checklist
Testing
Boundary / edge-case coverage: I reviewed whether this change involves
boundary conditions (e.g. empty input, single/zero element, min/max values,
off-by-one, sequence-length limits, integer overflow). Where applicable, I
added unit tests covering these edge cases in
tests/ut/ortests/e2e/.Regression test: If this PR fixes a bug, I added a regression test
that would fail without the fix.
Error / failure path coverage: I covered abnormal paths (exceptions,
timeouts, out-of-range, division by zero) in addition to the happy path.
Meaningful & reliable tests: New tests assert real behavior and are
not written merely to satisfy CI.
Performance impact: If this PR touches a performance-sensitive path,
I attached benchmark results and added performance regression tests.
vLLM main: vllm-project/vllm@24420b7