feat(npu): support token-balanced Async CAM MoE ubatching - #180
Conversation
- add two-stage token-balanced splitting for non-PCP DP+TP/SP - rebuild stage-local Attention metadata and preserve token ordering - keep CAM dispatch and combine state paired across microbatches - preserve PCP request-boundary behavior and reject unsupported configs - cover token/request, SP/no-SP, and ubatched/non-ubatched paths - document the supported topology and validation matrix Refs vllm-project#149 Signed-off-by: ShwStone <haowenshi@outlook.com>
Signed-off-by: ShwStone <haowenshi@outlook.com>
Signed-off-by: ShwStone <haowenshi@outlook.com>
Signed-off-by: ShwStone <haowenshi@outlook.com>
Signed-off-by: ShwStone <haowenshi@outlook.com>
There was a problem hiding this comment.
Pull request overview
Adds plugin-owned, token-balanced two-stage Async CAM MoE microbatching for Ascend NPU, enabling non-PCP DP+TP/SP Attention topologies while preserving stage-local metadata and CAM dispatch/combine pairing.
Changes:
- Introduces a CPU-safe two-stage planner supporting
async_moe_split="token"(token-balanced) and"request"(request-boundary) for Async CAM. - Rebuilds stage-local Attention metadata and forward-context state, including distinct handling for real tokens vs parent DP padding vs stage-local TP/SP padding.
- Adds SP/plain-TP CAM-boundary layout conversions, expands validation rules, and extends unit + opt-in GSM8K E2E coverage with updated documentation.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
afd_plugin/async_moe.py |
Defines backend-independent Async CAM stage contracts/constants. |
afd_plugin/v1/worker/npu/async_moe_ubatch.py |
Adds the two-stage planner for request/token split policies. |
afd_plugin/v1/worker/npu/attention_model_runner.py |
Integrates stage planning, stage metadata building, and isolates metadata builders for Async CAM. |
afd_plugin/v1/worker/npu/ubatch_utils.py |
Adds Async CAM-specific attention-metadata slicing that distinguishes real vs stage-physical tokens. |
afd_plugin/model_executor/models/forward_context.py |
Replaces TypedDict with an immutable Async MoE execution-plan dataclass. |
afd_plugin/model_executor/models/npu/async_moe_sp.py |
Implements SP/plain-TP stage tensor layout conversion and CAM dispatch/restore layout handling. |
afd_plugin/model_executor/models/npu/deepseek_v2_async_cam_forward.py |
Updates Async CAM forward orchestration to use stage inputs + CAM dispatch layouts and restores outputs. |
afd_plugin/connectors/npu/async_cam.py |
Documents/exports token vs request split constants and updates connector extra-info defaults. |
afd_plugin/compat/npu/feature_validation.py |
Tightens feature validation (native DBO/ubatching rejected; token split constraints enforced on Attention). |
tests/unit/v1/worker/test_async_moe_ubatch_planner.py |
Adds unit tests for the stage planner split policies and edge cases. |
tests/unit/v1/worker/test_npu_runtime.py |
Extends runtime validation + metadata tests; adds module reimport helper for isolation. |
tests/unit/model_executor/models/test_forward_context.py |
Adds tests for execution-plan validation and stage-context behavior/order/layout conversion. |
tests/e2e/conftest.py |
Enhances E2E launcher to support connector overrides, per-role TP sizing, async mode, and per-role env vars. |
tests/e2e/accuracy/test_gsm8k_npu_async_cam.py |
Adds opt-in GSM8K accuracy matrix for DP3TP2 Attention + DP2TP1/EP2 FFN Async CAM modes. |
docs/npu/CAM_ASYNC_CONNECTOR_USER_GUIDE.md |
Updates user guide for token-balanced ubatching, env var guidance, and E2E matrix description. |
docs/design/module/attention_runtime.md |
Documents token-balanced stages and topology semantics (Attention-local SP, FFN independence). |
docs/design/module/connector_contracts.md |
Updates CAMAsync connector contract text to reflect request/token stage pipeline. |
docs/design/module/execution_platforms.md |
Updates platform matrix + behavior notes for token-balanced Async CAM pipeline. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Follow-up validation: repeatable token-SP vs request-SP score differenceAdditional GSM8K
This qualifies the single I do not yet consider this evidence of a confirmed token-split correctness regression:
Static inspection so far:
Next checks:
Please treat this as an open validation finding, not yet a pass/fail conclusion. The per-sample lm-eval artifacts are needed to distinguish a strategy bug from batch/DP scheduling and low-precision execution variability. |
|
Important refinement from the code and the previously captured runtime shapes: when an Attention DP has only one scheduled long prefill, |
Follow-up: batch-size-1 accuracy resultWith lm-eval batch size set to 1, both SP configurations produced the same GSM8K
This controlled single-request result does not reproduce the earlier token-SP versus request-SP score difference. In particular, it provides no evidence that splitting a single request with the token policy causes an accuracy loss relative to the request-policy fallback in this run. We will therefore stop investigating batch-size effects for now. The earlier batch-size-8 aggregate difference remains documented above, but it is not currently treated as a confirmed split-policy correctness regression. No code change is proposed from these accuracy observations. |
| ] | ||
|
|
||
|
|
||
| # Patch reason: native DBO stages do not distinguish real tokens from |
There was a problem hiding this comment.
Why is this a patch function?
There was a problem hiding this comment.
It is not a runtime patch and it does not replace or wrap an upstream function. This ubatch_utils.py module is a plugin-owned copy of the pinned vLLM-Ascend implementation, so the PATCH START/END markers were intended only to delimit the AFD-specific delta inside copied upstream code, as required by the repository guidelines. The helper itself is imported and called explicitly by the AFD NPU runner.
I agree that the Patch reason/functionality/signature wording is misleading for a plugin-owned helper. It would be clearer to describe this as an AFD-specific extension while retaining only the copied-upstream delta markers.
Summary
Add token-balanced, AFD-managed asynchronous MoE ubatching for
CAMAsyncAFDConnectoron non-PCP DP+TP/SP Attention topologies.The new token policy divides the real flattened token workload into exactly two
approximately balanced stages while preserving token order, stage-local
Attention metadata, and CAM dispatch/combine pairing. Request-boundary splitting
remains available and continues to be used by the existing PCP-oriented policy.
Native vLLM DBO remains unsupported for Ascend Async CAM.
Closes #149.
This PR supersedes #152 and #154 and combines their feature and E2E work on the
latest
main. Both earlier PRs were developed while the model-configurationidentity regression described in #172 was present. That unrelated regression
caused TP2 FlashComm1 MLA/RoPE failures and materially distorted the debugging
and validation of those changes. #172 was fixed by #174; this replacement was
rebuilt and revalidated on the corrected baseline.
What changed
Async CAM MoE ubatching.
padding.
including sequence lengths, positions, slot mappings, and routing state.
the parent layout after the MoE pipeline.
FFN output before the next Attention layer.
deployment uses Attention DP3TP2 and FFN DP2TP1 with EP2.
native DBO, decode context parallel, and token splitting on unsupported
Attention topologies.
AFD_ASYNC_MOE_LAYOUT_LOG=1; the diagnostics do not inspect tensor values orintroduce device synchronization.
No vLLM or vLLM-Ascend source-tree changes or model monkey patches are added.
Supported and validated configurations
The Ascend DP3TP2 Attention + DP2TP1/EP2 FFN GSM8K E2E matrix passed in all six
distinct configurations:
When async MoE ubatching is disabled, token and request split settings are
operationally equivalent because no stage split is performed; the matrix uses
requestas the representative no-ubatch configuration.Validation
Unit tests passed, including the planner, stage metadata reconstruction,
forward-context/state-machine behavior, SP/plain-TP layout conversion, and
startup validation coverage.
Focused unit command:
Six-configuration Ascend E2E matrix:
Because of the available test time, the accuracy run was limited to one
representative configuration:
token-ubatch-spThe remaining five configurations completed their E2E runs successfully, but
were not all repeated with the 100-sample accuracy limit.
Scope and compatibility
In scope:
CAMAsyncAFDConnectorprefill execution.Out of scope:
Review request
Even excluding tests and documentation, this PR changes a substantial amount of
runtime code (9 production files, approximately
+1306/-186). Review isrequested, with particular attention to:
async_moe_sp.py: SP/plain-TP token layout conversion and padding rules.deepseek_v2_async_cam_forward.py: two-stage dispatch/receive ordering andpending state pairing.
attention_model_runner.pyandubatch_utils.py: stage metadata rebuildingand real-versus-physical token counts.
feature_validation.py: Attention/FFN topology constraints and preservationof the existing request-boundary PCP policy.
Documentation
docs/npu/CAM_ASYNC_CONNECTOR_USER_GUIDE.mddocs/design/module/attention_runtime.mddocs/design/module/connector_contracts.mddocs/design/module/execution_platforms.md