Repository navigation
Conversation
There was a problem hiding this comment.
Code Review
This pull request optimizes the MoE tail combine step in AscendMoERunner by conditionally using a plain tensor addition instead of torch._foreach_add when graph modes (super kernel or static kernel) are disabled. This avoids unnecessary op launches per MoE layer outside of graph modes. The PR also introduces comprehensive unit tests in tests/ut/ops/test_moe_tail_combine.py to verify the correctness, shape preservation, and dispatch behavior of both branches. I have no feedback to provide as there are no review comments to evaluate.
|
👋 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. 🤖 How to trigger CI
Note Until the CI gate has run on a commit, the required |
|
Last updated: 2026-11-26 09:29 UTC+8 for commit ci-gate failed. Reason:
See the workflow run for full logs. This comment is updated in place on each new failure and marked as passed once the gate passes (it is kept for history, not deleted). Missing owner approvals. Every changed file needs one approval from its CODEOWNERS owner(s):
|
Coverage
More info see: Summary |
MoE layers with both shared and routed experts merge the two outputs once per layer at the end of the block. The Ascend runner mirrors upstream's ``MoERunner.forward`` and performs that combine with ``torch._foreach_add([shared_output], [fused_output])[0]``. Both operands are ordinary activation tensors, so this is a plain elementwise add. ``_foreach_add`` exists to amortise dispatch across a tensor list; with a one-element list there is nothing to amortise, and on NPU the multi-tensor path still launches a dedicated ``ForeachAddList`` kernel. That launch costs ~13-17us regardless of tensor size, once per MoE layer, on every decode step: for a 45-layer MoE model this is ~0.75ms of pure launch overhead sitting on the token-to-token critical path. The multi-tensor form is still required in the graph modes: the superkernel generation path only accepts this combine through ``torch._foreach_add``, and a plain ``aclnnAdd`` disconnects the graph. So the combine uses whichever form the mode requires: * ``ascend_compilation_config.enable_super_kernel`` or ``enable_static_kernel`` set -> keep ``torch._foreach_add``, unchanged behaviour; * otherwise -> ``shared_output + fused_output``, which is bit-identical (same dtype, same operand order, elementwise add) and saves one op launch per MoE layer. No new configuration key or environment variable: the mode is read from the existing compilation config once in ``__init__`` and cached on the instance, so the hot path never re-reads it and no graph recompilation happens mid-run. A runner built without an initialized Ascend config (unit tests) keeps the graph-safe foreach path. The combine is extracted into ``_combine_shared_and_routed_output`` so both branches are directly unit-tested. Co-authored-by: westbook1006 <1210973614@qq.com> Co-authored-by: zmc1997 <742133686@qq.com> Co-authored-by: mengguangxin <mgx0018@163.com> Co-authored-by: liuwj-research <liuwj.2008@tsinghua.org.cn> Co-authored-by: dailiang16 <dailiang0110@yeah.net> Signed-off-by: 2luckydog <2981945956@qq.com>
5c8203a to
c683d0f
Compare
|
/run |
What this PR does / why we need it?
MoE layers with both shared and routed experts merge the two outputs once per layer, at the end of the block. The Ascend runner mirrors upstream's
MoERunner.forwardand performs that combine withBoth operands are ordinary activation tensors, so this is a plain elementwise add.
_foreach_addexists to amortise dispatch over a tensor list; with a one-element list there is nothing to amortise, while on NPU the multi-tensor path still launches a dedicatedForeachAddListkernel per call. That launch costs ~17 us regardless of tensor size (measured on Atlas 910B), once per MoE layer, on every decode step.Profiling a 45-layer GLM-5.3-Flash decode instance shows 2835 calls (45 layers x 63 steps) at 16.7 us each: ~0.75 ms of pure launch overhead per decode step, sitting directly on the token-to-token critical path.
It can be replaced with:
The multi-tensor form is not arbitrary: the superkernel generation path only accepts this combine through
torch._foreach_add, and a plainaclnnAdddisconnects the graph. So the combine keeps using whichever form the compilation mode requires:ascend_compilation_config.enable_super_kernelorenable_static_kernelset: keeptorch._foreach_add; behaviour is unchanged.shared_output + fused_output, which is bit-identical (same dtype, same operand order, elementwise add) and saves one op launch per MoE layer.The mode is read once in
AscendMoERunner.__init__and cached on the instance, so the hot path never re-reads the config and no graph recompilation happens mid-run; runners built without an initialized Ascend config keep the graph-safe foreach path. No new configuration key, environment variable, or API is introduced.Performance Test
Setup: GLM-5.3-Flash W8A8, 1P1D PD disaggregation, prefill DP4/TP4/EP16, decode DP12/TP4/EP48, input length 80K, output length 1K, concurrency 12, Atlas 910C, superkernel and static kernel both disabled.
Accuracy Test
No numerical change: same operands, same order, same elementwise add. GPQA Diamond ~89.41 and GSM8K ~97.57 are unchanged before and after.
Does this PR introduce any user-facing change?
No. There is no new configuration key, environment variable, or API. Only the kernel performing the combine changes, and only when the superkernel/static-kernel graph modes are off; with either mode enabled the code path is exactly as before.
How was this patch tested?
Added
tests/ut/ops/test_moe_tail_combine.py, hardware-agnostic (pure CPU + mocks):rtol=0, atol=0);(0, 8)keeps shape and dtype on both branches;torch._foreach_addexactly once, on a one-element list;torch._foreach_add(the spy raises);enable_super_kernelxenable_static_kernelcombinations map to the expected branch;CI testing only: this machine has no NPU, so the suite was not executed locally and the service-level numbers above were not re-measured on this branch.
Testing
Boundary / edge-case coverage: empty input, and both branches of the mode decision.
Regression test: the mode-matrix and call-count assertions pin the selection logic; they fail if the plain branch is unreachable or the graph modes stop selecting foreach.
Error / failure path coverage: no exception, timeout or out-of-range path is introduced; the only error path is an uninitialized Ascend config, which is covered by a fallback test.
Meaningful & reliable tests: tests assert bit-exact tensor equality and exact dispatch counts, not "runs without error".
Performance impact: operator-level profiling and a service A/B are attached above; the change is limited to a path that is explicitly exempted from the graph modes that need the foreach form.
vLLM main: vllm-project/vllm@c410543