[Feat]: Add NPU ModelRunnerV2 DBO with Eager and FULL_DECODE_ONLY ACL Graph Support - #275
[Feat]: Add NPU ModelRunnerV2 DBO with Eager and FULL_DECODE_ONLY ACL Graph Support#275lirx-pd wants to merge 5 commits into
Conversation
Signed-off-by: lirx-pd <616517220@qq.com>
Signed-off-by: lirx-pd <616517220@qq.com>
Signed-off-by: lirx-pd <616517220@qq.com>
7552e07 to
616d97b
Compare
jiangkuaixue123
left a comment
There was a problem hiding this comment.
Thanks for the detailed design and test coverage. I found two blockers before this can merge:
- The temporary backport copies/adapts upstream execution code but does not follow this repository's patch-marking requirements; see the inline comment.
- The current head fails the
pre-commitworkflow. The failing job reports mypy errors in the changed source/test files and the SPDX hook modifies four touched test files. Please run the full pre-commit checks and make the workflow green.
| ) | ||
|
|
||
|
|
||
| def execute_model_v026_eager_dbo( |
There was a problem hiding this comment.
This function is a copied/adapted upstream execution path, but the AFD-specific differences are not marked. The repository guidelines require copied or wrapped upstream functions to have the patch reason/functionality/signature comments immediately above them and to surround only the AFD-specific deltas with # ### PATCH START: ... / # ### PATCH END: .... Please re-copy from the exact pinned source and mark the adaptations so future vLLM upgrades can mechanically compare and reapply this backport. The same applies to the copied helpers in runtime.py.
There was a problem hiding this comment.
All the related files have been refactored
jiangkuaixue123
left a comment
There was a problem hiding this comment.
A follow-up pass focused specifically on abstraction and defensive programming. Most of the larger boundaries (AFDAscendUBatchRunnerV2, graph-entry state, and the scoped graph-manager context managers) are justified because they isolate substantial lifecycle/state. The overengineering is concentrated in compatibility sentries and optional attribute probing. assert_backport_required() is also a single-use helper that duplicates the module ABI sentry; I suggest removing both and relying on the pinned ABI plus direct accesses/tests.
|
|
||
|
|
||
| _EXPECTED_RUNTIME_ABI = 3 | ||
| _loaded_runtime_abi = getattr(dbo_runtime, "AFD_MRV2_DBO_RUNTIME_ABI", 1) |
There was a problem hiding this comment.
This module-to-module ABI handshake looks over-defensive. These modules are shipped from the same package/checkout, and there is already a second proactive guard in assert_backport_required(). The getattr(..., 1) fallback also masks the actual missing-symbol failure. Please remove this private ABI protocol (and the single-use descriptor-field sentry) and let the pinned vLLM contract plus normal import/static-test failures expose drift.
| num_ubatches=ubatches, | ||
| ) | ||
|
|
||
| dispatch_ubatches = getattr(cudagraph_manager, "dispatch_ubatches", None) |
There was a problem hiding this comment.
Please avoid probing this contract with getattr and replacing the original failure with a custom RuntimeError. The DBO initialization path installs AFDModelAclGraphManagerV2, which defines dispatch_ubatches; call cudagraph_manager.dispatch_ubatches(...) directly (and preferably give the manager a concrete protocol/type). If that contract changes, the original attribute/type failure should remain visible, per the repository's upstream-compatibility guidance.
| for groups in attn_groups: | ||
| for group in groups: | ||
| for builder in group.metadata_builders: | ||
| if workspace is None and hasattr(builder, "_get_workspace_buffer"): |
There was a problem hiding this comment.
These hasattr branches silently turn an ABI mismatch into partially initialized graph state. Because this backport targets pinned vLLM/vLLM-Ascend versions, access _get_workspace_buffer() / set_workspace_buffer() directly with the expected builder type and let an upstream incompatibility fail at its source. This removes defensive branching and makes static checking useful.
…rived code with patch markers and remove redundant defensive logic. Signed-off-by: lirx-pd <616517220@qq.com>
Signed-off-by: lirx-pd <616517220@qq.com>
Purpose
This change adds temporary Dual Batch Overlap (DBO) support for the AFD NPU
ModelRunnerV2 path while the pinned vLLM
v0.26.0ABI does not provide therequired ModelRunnerV2 DBO implementation.
The implementation adapts the ModelRunnerV2 DBO behavior from
specture724/vllmbranchfeat/v2/dbo-fullcgat commit626fee7831to thecurrent vLLM ABI at
568afb3a13, and keeps all missing upstream behavior underan isolated compatibility backport. This allows the backport to be removed once
the pinned vLLM version contains native ModelRunnerV2 DBO support.
The supported AFD NPU ModelRunnerV2 paths are:
FULLorFULL_DECODE_ONLY;FULL_DECODE_ONLY.The vLLM and vLLM-Ascend source trees are not modified. Existing NPU
ModelRunnerV1 behavior remains on its original execution path.
Architecture Diagram
flowchart TB Config["AFD NPU V2 configuration"] Validation["Scoped v0.26 validation shim"] Runner["AFDNPUAttentionModelRunnerV2"] Dispatch["DP synchronization and DBO dispatch"] Single["Native single-batch V2 path"] Split["Two request-boundary uBatches"] Eager["AFDAscendUBatchRunnerV2<br/>eager execution"] Graph["AFDModelAclGraphManagerV2<br/>DBO graph capture/replay"] Yield["Per-layer DBO handoff"] Connector["CAMP2pAFDConnector"] FFN["Existing AFD NPU FFN runner"] Output["Merged model output"] Guard["Upstream capability guard<br/>remove backport when native DBO lands"] Config --> Validation --> Runner Runner --> Dispatch Dispatch -->|threshold not met| Single --> Connector Dispatch -->|eager DBO| Split --> Eager --> Yield Dispatch -->|captured DBO shape| Split --> Graph --> Yield Yield --> Connector --> FFN --> Connector --> Output Guard -.-> Validation classDef new fill:#fff7ed,stroke:#f59e0b,color:#92400e,stroke-width:2px; classDef reused fill:#ecfdf5,stroke:#16a34a,color:#166534,stroke-width:2px; classDef upstream fill:#eff6ff,stroke:#3b82f6,color:#1e40af,stroke-width:2px; class Validation,Dispatch,Split,Eager,Graph,Guard new; class Runner,Yield,Connector,FFN,Output reused; class Single upstream;Issue
Scope
In scope
v0.26.0ABI intoafd-plugin.FULL_DECODE_ONLYACL graph capture and replay.across DP ranks before execution.
token count across DP ranks.
single batch when graph padding would leave the second microbatch empty.
input, attention, block-table, slot-mapping, and forward-context state for
each microbatch.
tensor, auxiliary-hidden-state, and intermediate outputs in request order.
graphs and publish matching AFD metadata for warmup, capture, and replay.
parameters and updating the captured task-group handles during replay.
during repeated Attention-side capture events.
NPU ModelRunnerV2 configuration.
not met.
Out of scope
FULL_DECODE_ONLY.NPU ModelRunnerV2 DBO.
parallel MoE, or other topologies already unsupported by AFD NPU
ModelRunnerV2.
Implementation Notes
Temporary vLLM v0.26 backport
The compatibility package
afd_plugin/compat/backports/vllm_v026_mrv2_dbocontains the copied/adaptedexecution behavior that is absent from the pinned upstream ABI:
num_ubatches;The backport checks the upstream
BatchExecutionDescriptorshape at startup. Ifupstream already provides
num_ubatches, initialization fails with an explicitinstruction to remove this compatibility layer instead of silently shadowing
the new native implementation.
Eager DBO execution
AFDNPUAttentionModelRunnerV2.execute_model()delegates to the backportedexecute path only when vLLM reports
use_ubatching. Otherwise it continues todelegate to the native vLLM-Ascend runner.
For a selected DBO batch, the implementation:
and forward contexts for both stages;
The stage-specific Ascend state is stored in
ForwardContext.additional_kwargsfor ModelRunnerV2. ModelRunnerV1 continues to use its existing attributes, so
the V2 adaptation does not remove or redirect V1 state.
DP dispatch and fallback
All DP ranks participate in one CPU-group reduction containing their token
count, uniform-token state, local DBO eligibility, and requested graph mode.
The result ensures that every rank makes the same eager/graph and
single-/dual-batch decision.
DBO is selected only when all ranks allow it, the configured threshold is met,
and both microbatches contain real work after final graph padding. Otherwise the
step uses the native single-batch descriptor. If any DP rank cannot use a graph,
all ranks execute the two microbatches eagerly for that step.
Full ACL graph DBO
During ModelRunnerV2 initialization, a scoped wrapper replaces only the graph
manager factory used by the current AFD runner. The original vLLM and
vLLM-Ascend symbols are restored in
finallyblocks.AFDModelAclGraphManagerV2retains the native single-batch graph descriptorsand owns separate two-microbatch twins only for eligible, evenly divisible
capture shapes. Each DBO graph has:
An uncaptured DBO shape falls back to eager DBO. A captured single-batch shape
continues through the native graph manager.
Compatibility and isolation
configurations and restores the original config values after upstream
validation.
is always restored.
after each execution scope.
graph ownership.
Configuration Boundary
NPU ModelRunnerV2 DBO requires:
v0.26.0without native ModelRunnerV2 DBO descriptors;CAMP2pAFDConnector;compute_gate_on_attention=false;DP * TP;FULL_DECODE_ONLY.Unsupported combinations fail during validation before model execution.
Test Plan
Unit and compatibility coverage
selection, and structured output merging.
values.
non-AFD/native-runner isolation.
Ascend E2E coverage
The hardware E2E matrix covers:
FULL_DECODE_ONLYDBO off versus on;Test Result
including eager and
FULL_DECODE_ONLYgraph execution.implementation path.
Limitations and Follow-up
ModelRunnerV2 DBO behavior.
topology above.
dispatch, slicing, and execution, remove the compatibility package and the
scoped validation/graph-manager patches, then adapt only the NPU-specific
execution and ACL graph seams that remain necessary.
Essential PR Checklist
FULL_DECODE_ONLYDBO behavior is documented.