Skip to content

[Bugfix][MRV2] Isolate sleep-mode KV allocations - #53508

Merged
njhill merged 6 commits into
vllm-project:mainfrom
Ronald1995:codex/sleep-mrv2-kv-scope
Aug 27, 2026
Merged

njhill merged 6 commits into
vllm-project:mainfrom
Ronald1995:codex/sleep-mrv2-kv-scope

Conversation

@Ronald1995

@Ronald1995 Ronald1995 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Purpose

Part of #53343. Split from #53344.

The Model Runner V2 KV-cache memory-pool context currently covers initialization work beyond the discardable cache backing allocation. Persistent metadata created in that scope can inherit the kv_cache tag and lose its contents during level-1 sleep while retaining the same virtual address.

This PR is intentionally MRV2-only. It passes the allocation context through the MRV2 model runner and enters it only around allocate_kv_cache. MRV1 keeps its existing behavior.

Changes

  • restrict the MRV2 kv_cache pool to backing allocations;
  • keep cache sharing, binding, and runtime setup outside the pool;
  • add an MRV2 allocation-boundary test;
  • add deterministic poisoned-remap allocator and CUDA Graph reproducers.

Dependency

Independent. Can merge directly into main.

Test Plan

pytest -q tests/v1/worker/test_kv_cache_allocation_scope.py
pytest -q tests/basic_correctness/test_mem.py -k "tagged_ordinary_tensor or cudagraph_replays"

test result:

===================================================================================== warnings summary =====================================================================================
.venv/lib/python3.12/site-packages/torch/jit/_script.py:365: 14 warnings
  /home/liurong/vllm/.venv/lib/python3.12/site-packages/torch/jit/_script.py:365: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
1 passed, 14 warnings in 1.00s
..                                                                                                                                                                                   [100%]
===================================================================================== warnings summary =====================================================================================
.venv/lib/python3.12/site-packages/torch/jit/_script.py:365: 14 warnings
  /home/liurong/vllm/.venv/lib/python3.12/site-packages/torch/jit/_script.py:365: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
    warnings.warn(

tests/basic_correctness/test_mem.py::test_tagged_ordinary_tensor_is_discarded_with_kv_cache
tests/basic_correctness/test_mem.py::test_cudagraph_replays_with_corrupted_tagged_constant
  /home/liurong/vllm/tests/utils.py:1759: DeprecationWarning: This process (pid=4125262) is multi-threaded, use of fork() may lead to deadlocks in the child.
    pid = os.fork()

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
2 passed, 11 deselected, 16 warnings in 34.01s

Changed files pass Ruff, git diff --check, and Python compilation. CUDA tests require a supported Linux CUDA runtime and were not executed on the Windows development host.

Follow-up: reevaluate post_kv_cache_wake_up

A follow-up PR will evaluate removing the MRV2 post_kv_cache_wake_up() implementation that rebuilds the BlockTable layout tensors.

That hook currently compensates for the previous broad allocation scope: BlockTables and its pointer, stride, and block-size metadata were created while the kv_cache pool was active, so level-1 sleep discarded their contents and wake-up had to reconstruct them.

After this PR, those metadata tensors are created outside the discardable kv_cache pool. They should therefore remain resident and no longer require wake-time reconstruction. Removing the workaround would also avoid replacing tensor objects after wake-up, which is preferable for consumers that rely on stable storage addresses.

The cleanup is intentionally deferred until a follow-up verifies pointer/value stability across sleep and wake-up and confirms behavior across supported platforms and sleep-mode backends.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added mrv2 Model Runner V2 specific bug Something isn't working labels Aug 24, 2026
@mergify

mergify Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @Ronald1995.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@aoshen02

Copy link
Copy Markdown
Collaborator

I reproduced the sleep/wake failure and tested the follow-up in Ronald1995#9.

Environment

  • Node: 1x H200 node, 4 GPUs used
  • Image: vllm/vllm-openai:nightly@sha256:3578c1fa6a9676e1de068b9d75c777cc865d251fadfbe6175ae82278739c6674
  • Image vLLM commit: a9a17e7095a66ef6c6685a1c7ddd657781a78d3c
  • PR patch rebased onto vllm-project/vllm@5e379a361e3ea8bb82b7efd768c36f39a0cf32fd
  • Model: Qwen/Qwen3.5-35B-A3B
  • Model snapshot: 59d61f3ce65a6d9863b86d2e96597125219dc754
  • No source bind mount: the modified Python files were copied into the container.

Engine configuration

os.environ["VLLM_USE_V2_MODEL_RUNNER"] = "1"

llm = LLM(
    model="Qwen/Qwen3.5-35B-A3B",
    tensor_parallel_size=4,
    speculative_config={"method": "mtp", "num_speculative_tokens": 3},
    compilation_config=CompilationConfig(cudagraph_mode=CUDAGraphMode.FULL),
    enable_sleep_mode=True,
    enable_prefix_caching=False,
    max_model_len=256,
    max_num_seqs=1,
    limit_mm_per_prompt={"image": 0, "video": 0},
    trust_remote_code=True,
)

Additional environment:

HF_HUB_OFFLINE=1
TRANSFORMERS_OFFLINE=1
VLLM_ALLOW_INSECURE_SERIALIZATION=1

Reproduction sequence

  1. Verify all four workers use fused MTP decode.
  2. Record the five block-table layout tensor data_ptr() values on every worker.
  3. Generate four tokens for The capital of France is.
  4. llm.sleep(level=2).
  5. llm.wake_up(tags=["weights"]).
  6. llm.collective_rpc("reload_weights").
  7. llm.wake_up(tags=["kv_cache"]).
  8. Record layout pointers again and repeat the same deterministic decode.

Results

PR #53508 as-is

  • sleep: 0.503149 s
  • wake weights: 0.407355 s
  • wake KV: 1.497417 s
  • first post-wake decode: failed on all TP workers with CUDA error: an illegal memory access was encountered

The remaining problem is GPUModelRunner.post_kv_cache_wake_up() calling init_block_table_layout_tensors(): it replaces tensors referenced by the fused multi-step CUDA graph even though #53508 already moved this metadata outside the sleepable KV allocation scope.

#53508 + remove MRV2 post-wake reconstruction

  • layout_ptrs_stable=true
  • tokens_equal=true
  • sleep: 0.507078 s
  • wake weights: 0.454879 s
  • wake KV: 1.132419 s
  • first post-wake decode: 0.120755 s
  • no CUDA error

The legacy Model Runner callback is retained because it still restores FP8 KV state; only MRV2 skips the callback. Pre-commit, mypy, and DCO checks pass.

@aoshen02 aoshen02 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strict review: the allocation-scope direction is correct, but this revision is not merge-ready.

  1. Blocking runtime failure: MRV2 still calls post_kv_cache_wake_up(), which recreates the block-table layout tensors. Those tensors are now intentionally resident outside the sleepable KV pool, so rebuilding them is unnecessary and changes addresses captured by fused multi-step CUDA graphs. In the 4x H200 / Qwen3.5-35B-A3B / TP4 / fused-MTP / full-CUDA-Graph reproducer, PR #53508 as-is fails on the first post-wake decode on every TP worker with CUDA error: an illegal memory access was encountered. Removing the MRV2 reconstruction makes layout pointers stable and preserves identical output. The minimal follow-up is Ronald1995#9.

  2. Blocking type-check failure: Worker.model_runner is typed as the legacy GPUModelRunner, so the new kv_cache_allocation_context= argument at vllm/v1/worker/gpu_worker.py:691 fails mypy with Unexpected keyword argument ... [call-arg]. The changed files must pass pre-commit after rebasing.

  3. Regression coverage is insufficient: test_kv_cache_allocation_scope.py calls attn_utils.init_kv_cache() directly and the allocator tests only demonstrate generic corruption. Neither test exercises Worker.initialize_from_config() followed by the real MRV2 sleep/wake callback. Consequently all proposed tests pass while the production fused-MTP path still crashes. Add a regression that asserts MRV2 does not rebuild graph-visible block-table metadata and that pointer identity survives KV wake-up.

  4. The PR currently conflicts with main; rebase and rerun the complete changed-file checks.

Once the MRV2 wake reconstruction is removed, the type boundary is fixed, and the regression covers the lifecycle path, the core design is preferable to an in-place refresh workaround.

@aoshen02

Copy link
Copy Markdown
Collaborator

Correction to item 4 in my strict review: GitHub currently reports this commit as mergeable, so the earlier Mergify conflict notice is stale. The accurate validation blocker is that is failed and is skipped; the revision still needs a green required-check run after the three substantive fixes. The runtime failure, mypy failure, and regression-coverage findings are unchanged.

@aoshen02
aoshen02 force-pushed the codex/sleep-mrv2-kv-scope branch from b0aa9f4 to 0dcece3 Compare August 25, 2026 09:56
@aoshen02 aoshen02 added the ready ONLY add when PR is ready to merge/full CI is needed label Aug 25, 2026
@github-actions

Copy link
Copy Markdown

@Ronald1995, CI is now available for this PR.

  • /ci run starts upstream CI; /amd-ci run starts AMD CI only.
  • /ci retry retries failed jobs in the CI build for the current PR head. If the current head has no CI build, it starts a new CI build for the current head containing only jobs that failed in the latest earlier CI build for this PR.
  • /amd-ci retry retries failed jobs in AMD CI for the current PR head. Use /amd-ci run when the current head has no AMD CI build.
  • /ci cancel cancels scheduled or running CI builds for this PR branch; /amd-ci cancel does the same for AMD CI only.

@aoshen02 aoshen02 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed after the follow-up fix was merged and the branch was rebased onto latest main. The sleep/wakeup allocation scope and stable block-table refresh are now integrated; changed-file pre-commit passes locally and the remote pre-run-check/pre-commit workflow is green. The H200 MRV2 fused-MTP sleep/wakeup regression also passed with stable metadata pointers and identical tokens.

@aoshen02
aoshen02 force-pushed the codex/sleep-mrv2-kv-scope branch from 6e454b1 to 9d2d787 Compare August 25, 2026 10:20
@aoshen02

Copy link
Copy Markdown
Collaborator

MRV1 support is now included in commit 9d2d78745. Both model runners pass the memory-pool context down to the backing KV allocation only; MRV1 keeps its FP8 KV-cache wake-up recovery. Validation: tests/v1/worker/test_kv_cache_allocation_scope.py passes for MRV1 and MRV2 (2 passed), full mypy 3.13 passes, changed-file pre-commit passes, and the updated remote pre-commit is green. The PR title should now be [Bugfix][MRV1][MRV2] Isolate sleep-mode KV allocations.

@aoshen02 aoshen02 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed after extending the allocation boundary to Model Runner V1. The shared worker path now scopes only the actual KV backing allocation for both runners, while MRV1 retains its FP8 wake recovery. MRV1/MRV2 unit tests, full mypy 3.13, local pre-commit, and remote pre-commit all pass.

@mergify mergify Bot added the cpu Related to CPU backends label Aug 25, 2026
@Ronald1995

Copy link
Copy Markdown
Contributor Author

Why MRV1 no longer needs post_kv_cache_wake_up

Commit c84879845c removes the MRV1 post-KV wake-up hook, along with the now-unreachable post_kv_cache_wake_up() / init_fp8_kv_scales() implementation.

init_fp8_kv_scales() bundled two operations:

  1. zeroing the remapped FP8 KV-cache backing tensors;
  2. resetting _k_scale and _v_scale to 1.0.

Neither operation is required by the current sleep/wake lifecycle:

  • _k_scale and _v_scale are now registered model buffers. Before level-2 sleep, Worker.sleep() saves model.named_buffers() to CPU, and Worker.wake_up(tags=["weights"]) restores those buffers. The host-side scale values are not part of the discarded KV allocation either. Therefore FP8 scales no longer depend on a KV-cache wake-up callback.
  • KV-cache contents discarded by level-2 sleep are no longer logically valid. After wake-up, cache slots used by new requests are written before they are read. Their initial byte contents therefore do not need to be zero. This invariant is dtype-independent, which is also why BF16 KV cache has never required an equivalent zeroing step.
  • The zeroing added in [Bugfix][sleepmode][fp8 kv cache]: Fix FP8 KV cache + sleep(level=2) gibberish output #28783 was coupled with the scale-reset workaround. The correctness issue was the lost FP8 scale state, rather than FP8 requiring an all-zero cache allocation.

A regression test now explicitly sets VLLM_USE_V2_MODEL_RUNNER=0, performs FP8 generation, level-2 sleep, weights/KV wake-up, and deterministic generation again, then verifies that the pre/post-wake outputs are identical. This directly covers the #28783 failure mode without relying on post_kv_cache_wake_up().

Ruff and changed-file static checks pass locally. The FP8 CUDA regression requires a supported GPU and is left to GPU CI.

@Ronald1995

Copy link
Copy Markdown
Contributor Author

test result for test_deep_sleep_fp8_kvcache_mrv1 merged by #28783

===================================================================================== warnings summary =====================================================================================
.venv/lib/python3.12/site-packages/torch/jit/_script.py:365: 14 warnings
  /home/liurong/vllm/.venv/lib/python3.12/site-packages/torch/jit/_script.py:365: DeprecationWarning: `torch.jit.script_method` is deprecated. Please switch to `torch.compile` or `torch.export`.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================================================= 1 passed, 14 warnings in 31.23s ==============================================================================

@Ronald1995
Ronald1995 force-pushed the codex/sleep-mrv2-kv-scope branch from 61300ed to f25b827 Compare August 26, 2026 02:38
@aoshen02
aoshen02 force-pushed the codex/sleep-mrv2-kv-scope branch 2 times, most recently from b0cf781 to 4081433 Compare August 27, 2026 00:55
Ronald1995 and others added 6 commits August 27, 2026 01:24
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: aoshen02 <aoshen@inferact.ai>
Signed-off-by: aoshen02 <aoshen@inferact.ai>
FP8 KV scales are model buffers restored with weights after level-2 sleep, while discarded KV cache contents do not need initialization. Remove the obsolete wake-up hook and cover the behavior with an MRV1 FP8 sleep regression test.

Signed-off-by: aoshen02 <aoshen@inferact.ai>
Run the existing regression directly under pytest and use monkeypatch to select Model Runner V1 without leaking the environment setting.

Signed-off-by: aoshen02 <aoshen@inferact.ai>
Signed-off-by: aoshen02 <aoshen@inferact.ai>
@aoshen02
aoshen02 force-pushed the codex/sleep-mrv2-kv-scope branch from 4081433 to 093ae6c Compare August 27, 2026 01:25
@aoshen02

Copy link
Copy Markdown
Collaborator

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #85729 for commit 093ae6c23453.

@aoshen02

Copy link
Copy Markdown
Collaborator

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #85735 for commit 093ae6c23453.

@njhill njhill left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Ronald1995

@njhill
njhill merged commit 479eeb3 into vllm-project:main Aug 27, 2026
103 checks passed
@aoshen02
aoshen02 deleted the codex/sleep-mrv2-kv-scope branch August 28, 2026 00:05
khushali9 pushed a commit to khushali9/vllm that referenced this pull request Aug 29, 2026
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: aoshen02 <aoshen@inferact.ai>
Co-authored-by: aoshen02 <aoshen@inferact.ai>
Signed-off-by: khushali9 <khushali.desai9@gmail.com>
askliar pushed a commit to askliar/vllm that referenced this pull request Aug 30, 2026
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: aoshen02 <aoshen@inferact.ai>
Co-authored-by: aoshen02 <aoshen@inferact.ai>
am-cohere pushed a commit to am-cohere/vllm that referenced this pull request Sep 1, 2026
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: aoshen02 <aoshen@inferact.ai>
Co-authored-by: aoshen02 <aoshen@inferact.ai>
mylibrar pushed a commit to tanyuqian/vllm that referenced this pull request Sep 3, 2026
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: aoshen02 <aoshen@inferact.ai>
Co-authored-by: aoshen02 <aoshen@inferact.ai>
Tflowers-0129 pushed a commit to vllm-project/vllm-ascend that referenced this pull request Sep 7, 2026
### What this PR does / why we need it

This PR upgrades the verified vLLM main anchor from
[`ba07e4a48fc951300d97eb506217dd530583dea3`](vllm-project/vllm@ba07e4a)
to
[`e6bfe03ad73a3330cb427885aa90d97a12e1c704`](vllm-project/vllm@e6bfe03).
The exact upstream range is
[ba07e4a48...e6bfe03ad](vllm-project/vllm@ba07e4a...e6bfe03).

The branch is rebased onto the latest vllm-ascend `origin/main`. The
current revision adds two follow-ups on top of the reviewed source
mapping:

- **`e67948b9c` - drop the local `pr_test.yaml` tweak.** The earlier
"raise e2e timeout for `ready-all` partitions" change is reverted, so
this PR no longer modifies `.github/workflows/pr_test.yaml`.
- **`fe7f550b7` - drop the vLLM `v0.27.1` release lane from the tests.**
Every `vllm_version_is("0.27.1")` gate in the unit/e2e suite is removed
and each site resolves to the vLLM-main behavior: dual-lane
if/else/ternary branches collapse to the main path, the v0.27.1-only
skip and the
`test_kimi_k3_gqa_mixed_groups_use_expected_physical_layout` test are
deleted, the profiling-time and `prepare_inputs` AST contract tests are
reshaped to the single main-lane implementation, dead `vllm_version_is`
mocks/imports are dropped, the e2e `hunyuan-vl` case always skips, the
obsolete `VLLM_VERSION=0.27.1` hack in `test_num_nans` is removed, and
the orphaned legacy `_get_kv_cache_config_deepseek_v4` planner is
deleted. `vllm_version_is()` stays in `vllm_ascend/utils.py` with its
unit test.

#### Review conclusion

- **Latest revision (`fe7f550b7`):** clean rebase onto current
`origin/main`; the two follow-ups above are committed and pushed.
Local-only, non-PR working-tree sources are not part of this branch.
- **Source review (earlier revisions):** the main2main adaptations for
the pinned upstream range were reviewed and are documented below; no
PR-introduced source-level blocker was found.
- **CI:** the run triggered on the rebased head (`fe7f550b7`) supersedes
the earlier run and is the authoritative gate for this revision.

#### Upstream changes covered

| Upstream PR | Exact commit | Contract adopted here |
|---|---|---|
| [#50465](vllm-project/vllm#50465) |
[`d154d90d6c`](vllm-project/vllm@d154d90)
| Batch-sharded sampling and `skip_gather` |
| [#51718](vllm-project/vllm#51718) |
[`8bdc70ec7b`](vllm-project/vllm@8bdc70e)
| Standardized KV-cache layout |
| [#52209](vllm-project/vllm#52209) |
[`b26039b09f`](vllm-project/vllm@b26039b)
| Custom routed-expert weight loading |
| [#52560](vllm-project/vllm#52560) |
[`2f55ef254c`](vllm-project/vllm@2f55ef2)
| Qwen3-Omni DSpark support |
| [#52816](vllm-project/vllm#52816) |
[`b389ac2946`](vllm-project/vllm@b389ac2)
| DFlash2 and DFlash class factories |
| [#53183](vllm-project/vllm#53183) |
[`4aab2b0ebe`](vllm-project/vllm@4aab2b0)
| MRV2 becomes the default runner |
| [#53435](vllm-project/vllm#53435) |
[`a9a17e7095`](vllm-project/vllm@a9a17e7)
| DFlash2 subclass loading fix |
| [#53508](vllm-project/vllm#53508) |
[`479eeb32d2`](vllm-project/vllm@479eeb3)
| Isolated sleep-mode KV allocations |
| [#53515](vllm-project/vllm#53515) |
[`b1fbbc2ade`](vllm-project/vllm@b1fbbc2)
| Persistent PCP graph input buffers |
| [#53694](vllm-project/vllm#53694) |
[`5acc1c4e4b`](vllm-project/vllm@5acc1c4)
| Spec-decode `dp_sync` contract |
| [#53869](vllm-project/vllm#53869) |
[`b3af042abd`](vllm-project/vllm@b3af042)
| PCP slot mappings for PIECEWISE capture |

### Changes by file

> Note: the per-file notes below document the reviewed source mapping
for the pinned upstream range. Where they describe code as keeping a
v0.27.1 lane, the latest revision (`fe7f550b7`) removes the
`vllm_version_is("0.27.1")` gates from the unit/e2e tests listed below
and deletes the 0.27.1-only coverage; see "What this PR does".

#### Repository metadata and CI

##### `.github/vllm-main-verified.commit`

1. Updates the verified vLLM main SHA to
`e6bfe03ad73a3330cb427885aa90d97a12e1c704`.
- Upstream: [exact compare
range](vllm-project/vllm@ba07e4a...e6bfe03).
- Review: correct; this is the exact new anchor used by the source and
CI review.

##### `.github/workflows/pr_test.yaml`

This revision reverts the earlier local e2e-timeout tweak; this PR no
longer modifies `.github/workflows/pr_test.yaml`.

#### Runtime source

##### `vllm_ascend/_310p/model_runner_310p.py`

1. Adds a version-aware `KVCacheTensor` layer-name accessor and keeps
v0.27.1 aliasing while allocating main-lane attention/Mamba buffers per
layer.
2. Marks the 310P runner as not supporting the standardized shared
backing and derives cache sizes from each layer spec.
- Upstream: [#51718](vllm-project/vllm#51718) /
[`8bdc70ec7b`](vllm-project/vllm@8bdc70e).
- Review: correct; it avoids treating an all-layer descriptor size as
one layer's allocation.

##### `vllm_ascend/_310p/worker/v2/model_runner.py`

1. Reads `shared_by` on v0.27.1 and `layers` on main when binding 310P
V2 KV tensors.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; the active descriptor field is selected without
changing the release-lane behavior.

##### `vllm_ascend/_310p/worker_310p.py`

1. Applies the multi-group KV-memory scaling helper when the runner
cannot consume standardized shared backing.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; this prevents per-layer materialization from
exceeding the planner's shared-allocation budget.

##### `vllm_ascend/attention/context_parallel/dsa_cp.py`

1. Reads the DeepSeek V4 compression ratio from `compress_ratio` on
v0.27.1 or `tokens_per_state` on main.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; both fields encode the same logical ratio in their
respective lanes.

##### `vllm_ascend/attention/dsa_v1.py`

1. Applies the same `compress_ratio` / `tokens_per_state` compatibility
when building DSA metadata.
2. Retains `AscendDSABackend.get_kv_cache_shape` intentionally: main
removed the generic base declaration, but Ascend allocation code still
calls the concrete backend helper.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; deleting the concrete helper would break Ascend's own
allocator.

##### `vllm_ascend/core/kv_cache_interface.py`

1. Makes `AscendMLAAttentionSpec.storage_block_size` and `merge()`
lane-aware for `compress_ratio` versus `tokens_per_state`.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; layout compatibility is compared using the field that
exists in each lane.

##### `vllm_ascend/distributed/kv_transfer/kv_p2p/mooncake_connector.py`

1. Replaces direct `shared_by` reads with the version-aware helper.
2. Registers each real per-layer storage when one standardized
descriptor represents multiple private Ascend buffers.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; registration uses actual aligned storage addresses
instead of assuming descriptor-level aliasing.

#####
`vllm_ascend/distributed/kv_transfer/kv_p2p/mooncake_hybrid_connector.py`

1. Uses the version-aware tensor-layer accessor for hybrid Mooncake
transfers.
- Upstream: [#51718](vllm-project/vllm#51718).
   - Review: correct.

#####
`vllm_ascend/distributed/kv_transfer/kv_p2p/mooncake_layerwise_connector.py`

1. Uses the version-aware tensor-layer accessor for layerwise Mooncake
transfers.
- Upstream: [#51718](vllm-project/vllm#51718).
   - Review: correct.

#####
`vllm_ascend/distributed/kv_transfer/kv_pool/ascend_store/layerwise_cache_layout.py`

1. Reads layer names through the compatibility helper.
2. Constructs v0.27.1 tensors with `shared_by` and main tensors with
`layers`, `layer_stride`, `block_stride`, and `offset`.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; the produced descriptor is valid in both dataclass
versions.

#####
`vllm_ascend/distributed/kv_transfer/kv_pool/kv_offload/native/offloading_connector.py`

1. Removes the deleted `is_kv_cache_tensor_packed` import/call and uses
`bool(block_stride)` on main.
2. Replaces `shared_by` with the version-aware layer accessor.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; this resolves both introduced P1 import/call findings
while preserving the old packed-layout meaning.

#####
`vllm_ascend/distributed/kv_transfer/kv_pool/recompute_cpu_offload/manager.py`

1. Uses the version-aware layer accessor when building recompute offload
metadata.
- Upstream: [#51718](vllm-project/vllm#51718).
   - Review: correct.

#####
`vllm_ascend/distributed/kv_transfer/kv_pool/recompute_cpu_offload/worker.py`

1. Preserves new descriptor geometry (`layers`, strides, offset) on main
and old `shared_by` construction on v0.27.1.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; reconstructed tensors retain the layout information
required by main.

##### `vllm_ascend/models/deepseek_v4/indexer.py`

1. Constructs `AscendMLAAttentionSpec` with `compress_ratio` on v0.27.1
and `tokens_per_state` on main.
- Upstream: [#51718](vllm-project/vllm#51718).
   - Review: correct.

##### `vllm_ascend/models/layer/attention/layer.py`

1. Applies the same lane-specific MLA spec field when attention layers
publish their KV-cache specs.
- Upstream: [#51718](vllm-project/vllm#51718).
   - Review: correct.

##### `vllm_ascend/models/qwen3_dflash2.py`

1. Declares `decoder_layer_cls` and `model_cls` for the new upstream
factory-based construction path.
2. Retains the module-global swap only for v0.27.1, where the factories
do not exist.
- Upstream: [#52816](vllm-project/vllm#52816) /
[`b389ac2946`](vllm-project/vllm@b389ac2),
finalized by [#53435](vllm-project/vllm#53435) /
[`a9a17e7095`](vllm-project/vllm@a9a17e7).
- Review: correct; each lane instantiates `DFlash2Qwen3DecoderLayer` and
`DFlash2Qwen3Model` through its native mechanism.

##### `vllm_ascend/ops/vocab_parallel_embedding.py`

1. Adds the new `skip_gather` argument and mirrors the upstream early
return before tensor-parallel gather.
- Upstream: [#50465](vllm-project/vllm#50465) /
[`d154d90d6c`](vllm-project/vllm@d154d90).
- Review: correct; the trailing default keeps the old call contract
valid.

##### `vllm_ascend/patch/platform/patch_fused_moe.py`

1. Composes an upstream custom `RoutedExperts` subclass with
`AscendRoutedExperts` instead of replacing the class by name.
2. Preserves the upstream subclass's custom loader while retaining
Ascend routing/EPLB behavior.
- Upstream: [#52209](vllm-project/vllm#52209) /
[`b26039b09f`](vllm-project/vllm@b26039b).
- Review: correct; it adapts the actual factory return type and avoids
bypassing new upstream loading behavior.

##### `vllm_ascend/patch/platform/patch_kv_cache_utils.py`

1. Constructs lane-correct `KVCacheTensor` descriptors and inlines
page-size calculation removed from the old patch target.
2. Replaces the removed `_get_kv_cache_config_packed` hook on main with
patches for `get_kv_cache_config_from_groups`,
`_max_memory_usage_bytes_from_groups`, and `_pool_bytes_per_block`.
3. Preserves DeepSeek V4 shared tuples and rank-consistent KV block
planning.
- Upstream: [#51718](vllm-project/vllm#51718) /
[`8bdc70ec7b`](vllm-project/vllm@8bdc70e).
- Review: correct; this resolves the introduced P0 removed-target
finding against the live main entry points.

##### `vllm_ascend/patch/platform/patch_use_v2_model_runner.py`

1. Removes DSpark and DFlash2 from Ascend's V1-only unsupported-feature
result when the upstream helper exists.
- Upstream: MRV2 default switch
[#53183](vllm-project/vllm#53183), with DSpark
from [#52560](vllm-project/vllm#52560) and
DFlash2 from [#52816](vllm-project/vllm#52816).
- Review: correct; the filter is narrow and does not change other
unsupported features.

##### `vllm_ascend/patch/worker/patch_v2/patch_attn_utils.py`

1. Keeps the legacy `_allocate_kv_cache` / `_reshape_kv_cache` patches
only on v0.27.1.
2. Patches main's live `allocate_kv_cache` entry point with
`allocate_kv_cache_main` and retains Ascend reshape binding.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; this resolves the removed-import and
removed-monkey-patch-target P0/P1 findings.

##### `vllm_ascend/utils.py`

1. Adds `get_kv_cache_tensor_layers()` to normalize `shared_by` and
`layers` reads.
- Upstream: [#51718](vllm-project/vllm#51718).
2. Strips a PEP 440 local suffix (for example `+empty`) before
`vllm_version_is()` comparison.
- Upstream: no direct upstream patch; downstream compatibility hardening
needed for release-lane version strings.
- Review: correct; the comparison changes only local build metadata
handling.

##### `vllm_ascend/worker/model_runner_v1.py`

1. Implements lane-correct KV descriptor reads and advertises support
for standardized shared backing.
2. On main, overlays compatible attention/Mamba groups in one backing
store and exposes descriptor-offset views; otherwise materializes
correctly sized private per-layer buffers.
3. Preserves v0.27.1 aliasing, SFA/indexer layouts, sparse/offload
paths, cache-only caches, and page-padding geometry.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; the allocation follows the new descriptor geometry
without changing the release-lane memory model.

##### `vllm_ascend/worker/v2/aclgraph_utils.py`

1. Keeps old-lane dummy-batch repartitioning but consumes already-local
persistent buffers on main.
2. Uses PCP dummy block tables and slot mappings and forwards
`pcp_manager` through graph capture.
- Upstream: persistent buffers
[#53515](vllm-project/vllm#53515) and capture
slot mappings [#53869](vllm-project/vllm#53869).
- Review: correct; main no longer repartitions an already rank-local
capture batch.

##### `vllm_ascend/worker/v2/attn_utils.py`

1. Removes main-lane dependence on the deleted
`indexes_kv_by_block_stride` marker and uses standardized page geometry.
2. Allocates one hybrid backing on main, then creates per-layer views
from `offset`, `layer_stride`, and `block_stride`; private SFA/attention
allocations are retained where sharing is invalid.
3. Adds `allocate_kv_cache_main`, reconstructs Ascend attention groups,
and binds the live upstream allocation entry point.
4. Retains calls to concrete Ascend `get_kv_cache_shape` helpers because
Ascend still needs backend-specific views after the generic base method
was removed.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; the three machine-reported calls are intentional
concrete-backend calls, not calls to the removed base implementation.

##### `vllm_ascend/worker/v2/model_runner.py`

1. Advertises standardized shared KV backing and keeps separate
`prepare_inputs` implementations for the two upstream signatures.
2. Preserves the larger of real PCP tokens and graph-descriptor padding;
main forwards `padded_num_tokens` to the PCP manager.
- Upstream: KV layout
[#51718](vllm-project/vllm#51718), persistent
PCP buffers [#53515](vllm-project/vllm#53515),
and capture mappings
[#53869](vllm-project/vllm#53869).
- Review: correct; runtime PCP tokens are not truncated to the graph
descriptor.

##### `vllm_ascend/worker/v2/pcp_manager.py`

1. Matches the optional constructor/partition keywords exposed by each
lane.
2. Uses persistent `AscendInputBuffers`, including the `max_num_reqs +
1` query-offset view required by prefix sums.
3. Preserves explicit graph padding in the main-lane local batch.
- Upstream: [#53515](vllm-project/vllm#53515)
and [#53869](vllm-project/vllm#53869).
- Review: correct; buffer lifetime, shape, and padding match the new PCP
capture contract.

##### `vllm_ascend/worker/v2/spec_decode/autoregressive/speculator.py`

1. Accepts `dp_sync`, forwards `num_tokens_across_dp` on v0.27.1, and
forwards `dp_sync` on main.
- Upstream: [#53694](vllm-project/vllm#53694) /
[`5acc1c4e4b`](vllm-project/vllm@5acc1c4).
   - Review: correct.

##### `vllm_ascend/worker/v2/spec_decode/dflash/speculator.py`

1. Applies the same lane-specific `num_tokens_across_dp` / `dp_sync`
forwarding in DFlash.
- Upstream: [#53694](vllm-project/vllm#53694).
   - Review: correct.

##### `vllm_ascend/worker/v2/spec_decode/dspark/speculator.py`

1. Applies the same lane-specific `num_tokens_across_dp` / `dp_sync`
forwarding in DSpark.
- Upstream: [#53694](vllm-project/vllm#53694).
   - Review: correct.

##### `vllm_ascend/worker/worker.py`

1. Guards the removed `post_kv_cache_wake_up` hook with `hasattr`.
- Upstream: [#53508](vllm-project/vllm#53508) /
[`479eeb32d2`](vllm-project/vllm@479eeb3).
2. Scales multi-group KV memory only when Ascend must materialize
private buffers; skips DeepSeek V4 custom planning and compatible
standardized hybrid sharing.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; it prevents OOM without reducing capacity for runners
that can consume the shared layout.

#### Unit tests

##### `tests/ut/_310p/test_model_runner_310p.py`

1. Verifies that the 310P runner does not advertise standardized shared
KV backing.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/_310p/test_model_runner_v2_310p.py`

1. Makes the descriptor fixture valid with `shared_by` on v0.27.1 and
`layers` on main.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/attention/test_dsa_v1.py`

1. Covers both `compress_ratio` and `tokens_per_state` metadata inputs.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/core/test_recompute_scheduler.py`

1. Constructs base MLA specs with the ratio field available in the
active lane.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/distributed/ascend_store/test_layerwise_cache_layout.py`

1. Adds a lane-aware `KVCacheTensor` fixture and validates layout reads
through the compatibility helper.
2. Covers main descriptor strides/offsets and packed-descriptor
rejection.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/kv_offload/test_mooncake_connector.py`

1. Adapts fixtures/assertions to standardized descriptors and main
group-allocation sizes.
2. Adds coverage for registering multiple private per-layer storages
represented by one descriptor.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/patch/platform/test_patch_fused_moe.py`

1. Verifies composition of a custom upstream routed-expert subclass with
the Ascend contract and loader preservation.
- Upstream coverage:
[#52209](vllm-project/vllm#52209).

##### `tests/ut/patch/platform/test_patch_use_v2_model_runner.py`

1. Verifies that only DSpark and DFlash2 are removed from the V1-only
unsupported list.
- Upstream coverage:
[#53183](vllm-project/vllm#53183),
[#52560](vllm-project/vllm#52560), and
[#52816](vllm-project/vllm#52816).

##### `tests/ut/patch/platform/test_prefix_cache_cp_patches.py`

1. Adapts standardized KV descriptor fixtures.
2. Covers DeepSeek V4 shared-tuple capacity and rank-consistent
replanning.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/spec_decode/test_dflash2_proposer.py`

1. Verifies DFlash2's `decoder_layer_cls` and `model_cls` declarations.
- Upstream coverage:
[#52816](vllm-project/vllm#52816) and
[#53435](vllm-project/vllm#53435).

##### `tests/ut/test_compressed_prefix_cache.py`

1. Constructs compressed-prefix MLA specs with the lane-specific ratio
field.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/tools/bisect/test_version_compat.py`

1. Isolates `VLLM_VERSION` environment state so one compatibility test
cannot leak its lane into another.
- Upstream coverage: no direct source patch; downstream test isolation
for the two-lane compatibility logic.

##### `tests/ut/worker/a2/test_model_runner_v1.py`

1. Covers standardized descriptor allocation, per-layer views, shared
capacity, and cache-only behavior.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/worker/a2/test_model_runner_v1_with_device.py`

1. Adapts device-backed V1 fixtures to `shared_by` / `layers` and
validates main-lane geometry.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/worker/a2/test_worker_v1.py`

1. Covers shared-layout capacity versus private-buffer budget scaling.
2. Covers the optional wake hook after sleep-mode KV allocation changes.
- Upstream coverage:
[#51718](vllm-project/vllm#51718) and
[#53508](vllm-project/vllm#53508).

##### `tests/ut/worker/test_attn_utils_v2.py`

1. Covers the main `allocate_kv_cache` entry point, new descriptor
geometry, MLA ratio field, and flat attention-group reshape contract.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/worker/test_model_runner_v2.py`

1. Verifies both prepare-input implementations preserve real PCP tokens
and only main forwards graph padding.
- Upstream coverage:
[#53515](vllm-project/vllm#53515) and
[#53869](vllm-project/vllm#53869).

##### `tests/ut/worker/test_model_runner_v2_finegrained_tp.py`

1. Adds `batch_sharder` and request-count fields to the bare fixture to
match the new sampling contract.
- Upstream coverage:
[#50465](vllm-project/vllm#50465).

##### `tests/ut/worker/test_model_runner_v2_mamba.py`

1. Adds lane-aware descriptors and validates one main-lane hybrid
backing with per-layer offsets.
2. Covers the removal of `indexes_kv_by_block_stride` through observable
page-padding geometry.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/worker/test_pcp_manager_v2.py`

1. Covers persistent Ascend input buffers, prefix-sum offset shape,
padded local batches, main capture slot mappings, and old/new keyword
signatures.
2. Verifies `dp_sync` on all three Ascend speculators and `pcp_manager`
on graph capture.
- Upstream coverage:
[#53515](vllm-project/vllm#53515),
[#53694](vllm-project/vllm#53694), and
[#53869](vllm-project/vllm#53869).

### Does this PR introduce any user-facing change?

No. This is an internal compatibility update; it does not add an
Ascend-specific public API.

### How was this patch tested?

- Exact-contract main2main validation and range prediction for vLLM
[`ba07e4a48...e6bfe03ad`](vllm-project/vllm@ba07e4a...e6bfe03).
- GitHub Actions: [run
33229439657](https://github.com/vllm-project/vllm-ascend/actions/runs/33229439657).
- Successful in that run: pre-commit, both 310P jobs, all A3 jobs, and
the passing A2 shards on both `e6bfe03ad...` and `v0.27.1`.
- Pending rerun: ModelScope HTTP 500 failures on A2; two unchanged EPLB
CPU tests fail identically on both lanes.

- vLLM main:
vllm-project/vllm@ba07e4a

---------

Signed-off-by: liaoqidan <1107297340@qq.com>
Signed-off-by: shenzhao <shenzhao9@huawei.com>
Signed-off-by: LQDLove <LQDLove@users.noreply.github.com>
Co-authored-by: shenzhao <shenzhao9@huawei.com>
Co-authored-by: LQDLove <LQDLove@users.noreply.github.com>
sheralskumar pushed a commit to sheralskumar/vllm that referenced this pull request Sep 8, 2026
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: aoshen02 <aoshen@inferact.ai>
Co-authored-by: aoshen02 <aoshen@inferact.ai>
sunny-rain-63 pushed a commit to sunny-rain-63/vllm-ascend that referenced this pull request Sep 12, 2026
### What this PR does / why we need it

This PR upgrades the verified vLLM main anchor from
[`ba07e4a48fc951300d97eb506217dd530583dea3`](vllm-project/vllm@ba07e4a)
to
[`e6bfe03ad73a3330cb427885aa90d97a12e1c704`](vllm-project/vllm@e6bfe03).
The exact upstream range is
[ba07e4a48...e6bfe03ad](vllm-project/vllm@ba07e4a...e6bfe03).

The branch is rebased onto the latest vllm-ascend `origin/main`. The
current revision adds two follow-ups on top of the reviewed source
mapping:

- **`e67948b9c` - drop the local `pr_test.yaml` tweak.** The earlier
"raise e2e timeout for `ready-all` partitions" change is reverted, so
this PR no longer modifies `.github/workflows/pr_test.yaml`.
- **`fe7f550b7` - drop the vLLM `v0.27.1` release lane from the tests.**
Every `vllm_version_is("0.27.1")` gate in the unit/e2e suite is removed
and each site resolves to the vLLM-main behavior: dual-lane
if/else/ternary branches collapse to the main path, the v0.27.1-only
skip and the
`test_kimi_k3_gqa_mixed_groups_use_expected_physical_layout` test are
deleted, the profiling-time and `prepare_inputs` AST contract tests are
reshaped to the single main-lane implementation, dead `vllm_version_is`
mocks/imports are dropped, the e2e `hunyuan-vl` case always skips, the
obsolete `VLLM_VERSION=0.27.1` hack in `test_num_nans` is removed, and
the orphaned legacy `_get_kv_cache_config_deepseek_v4` planner is
deleted. `vllm_version_is()` stays in `vllm_ascend/utils.py` with its
unit test.

#### Review conclusion

- **Latest revision (`fe7f550b7`):** clean rebase onto current
`origin/main`; the two follow-ups above are committed and pushed.
Local-only, non-PR working-tree sources are not part of this branch.
- **Source review (earlier revisions):** the main2main adaptations for
the pinned upstream range were reviewed and are documented below; no
PR-introduced source-level blocker was found.
- **CI:** the run triggered on the rebased head (`fe7f550b7`) supersedes
the earlier run and is the authoritative gate for this revision.

#### Upstream changes covered

| Upstream PR | Exact commit | Contract adopted here |
|---|---|---|
| [#50465](vllm-project/vllm#50465) |
[`d154d90d6c`](vllm-project/vllm@d154d90)
| Batch-sharded sampling and `skip_gather` |
| [#51718](vllm-project/vllm#51718) |
[`8bdc70ec7b`](vllm-project/vllm@8bdc70e)
| Standardized KV-cache layout |
| [#52209](vllm-project/vllm#52209) |
[`b26039b09f`](vllm-project/vllm@b26039b)
| Custom routed-expert weight loading |
| [#52560](vllm-project/vllm#52560) |
[`2f55ef254c`](vllm-project/vllm@2f55ef2)
| Qwen3-Omni DSpark support |
| [#52816](vllm-project/vllm#52816) |
[`b389ac2946`](vllm-project/vllm@b389ac2)
| DFlash2 and DFlash class factories |
| [#53183](vllm-project/vllm#53183) |
[`4aab2b0ebe`](vllm-project/vllm@4aab2b0)
| MRV2 becomes the default runner |
| [#53435](vllm-project/vllm#53435) |
[`a9a17e7095`](vllm-project/vllm@a9a17e7)
| DFlash2 subclass loading fix |
| [#53508](vllm-project/vllm#53508) |
[`479eeb32d2`](vllm-project/vllm@479eeb3)
| Isolated sleep-mode KV allocations |
| [#53515](vllm-project/vllm#53515) |
[`b1fbbc2ade`](vllm-project/vllm@b1fbbc2)
| Persistent PCP graph input buffers |
| [#53694](vllm-project/vllm#53694) |
[`5acc1c4e4b`](vllm-project/vllm@5acc1c4)
| Spec-decode `dp_sync` contract |
| [#53869](vllm-project/vllm#53869) |
[`b3af042abd`](vllm-project/vllm@b3af042)
| PCP slot mappings for PIECEWISE capture |

### Changes by file

> Note: the per-file notes below document the reviewed source mapping
for the pinned upstream range. Where they describe code as keeping a
v0.27.1 lane, the latest revision (`fe7f550b7`) removes the
`vllm_version_is("0.27.1")` gates from the unit/e2e tests listed below
and deletes the 0.27.1-only coverage; see "What this PR does".

#### Repository metadata and CI

##### `.github/vllm-main-verified.commit`

1. Updates the verified vLLM main SHA to
`e6bfe03ad73a3330cb427885aa90d97a12e1c704`.
- Upstream: [exact compare
range](vllm-project/vllm@ba07e4a...e6bfe03).
- Review: correct; this is the exact new anchor used by the source and
CI review.

##### `.github/workflows/pr_test.yaml`

This revision reverts the earlier local e2e-timeout tweak; this PR no
longer modifies `.github/workflows/pr_test.yaml`.

#### Runtime source

##### `vllm_ascend/_310p/model_runner_310p.py`

1. Adds a version-aware `KVCacheTensor` layer-name accessor and keeps
v0.27.1 aliasing while allocating main-lane attention/Mamba buffers per
layer.
2. Marks the 310P runner as not supporting the standardized shared
backing and derives cache sizes from each layer spec.
- Upstream: [#51718](vllm-project/vllm#51718) /
[`8bdc70ec7b`](vllm-project/vllm@8bdc70e).
- Review: correct; it avoids treating an all-layer descriptor size as
one layer's allocation.

##### `vllm_ascend/_310p/worker/v2/model_runner.py`

1. Reads `shared_by` on v0.27.1 and `layers` on main when binding 310P
V2 KV tensors.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; the active descriptor field is selected without
changing the release-lane behavior.

##### `vllm_ascend/_310p/worker_310p.py`

1. Applies the multi-group KV-memory scaling helper when the runner
cannot consume standardized shared backing.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; this prevents per-layer materialization from
exceeding the planner's shared-allocation budget.

##### `vllm_ascend/attention/context_parallel/dsa_cp.py`

1. Reads the DeepSeek V4 compression ratio from `compress_ratio` on
v0.27.1 or `tokens_per_state` on main.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; both fields encode the same logical ratio in their
respective lanes.

##### `vllm_ascend/attention/dsa_v1.py`

1. Applies the same `compress_ratio` / `tokens_per_state` compatibility
when building DSA metadata.
2. Retains `AscendDSABackend.get_kv_cache_shape` intentionally: main
removed the generic base declaration, but Ascend allocation code still
calls the concrete backend helper.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; deleting the concrete helper would break Ascend's own
allocator.

##### `vllm_ascend/core/kv_cache_interface.py`

1. Makes `AscendMLAAttentionSpec.storage_block_size` and `merge()`
lane-aware for `compress_ratio` versus `tokens_per_state`.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; layout compatibility is compared using the field that
exists in each lane.

##### `vllm_ascend/distributed/kv_transfer/kv_p2p/mooncake_connector.py`

1. Replaces direct `shared_by` reads with the version-aware helper.
2. Registers each real per-layer storage when one standardized
descriptor represents multiple private Ascend buffers.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; registration uses actual aligned storage addresses
instead of assuming descriptor-level aliasing.

#####
`vllm_ascend/distributed/kv_transfer/kv_p2p/mooncake_hybrid_connector.py`

1. Uses the version-aware tensor-layer accessor for hybrid Mooncake
transfers.
- Upstream: [#51718](vllm-project/vllm#51718).
   - Review: correct.

#####
`vllm_ascend/distributed/kv_transfer/kv_p2p/mooncake_layerwise_connector.py`

1. Uses the version-aware tensor-layer accessor for layerwise Mooncake
transfers.
- Upstream: [#51718](vllm-project/vllm#51718).
   - Review: correct.

#####
`vllm_ascend/distributed/kv_transfer/kv_pool/ascend_store/layerwise_cache_layout.py`

1. Reads layer names through the compatibility helper.
2. Constructs v0.27.1 tensors with `shared_by` and main tensors with
`layers`, `layer_stride`, `block_stride`, and `offset`.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; the produced descriptor is valid in both dataclass
versions.

#####
`vllm_ascend/distributed/kv_transfer/kv_pool/kv_offload/native/offloading_connector.py`

1. Removes the deleted `is_kv_cache_tensor_packed` import/call and uses
`bool(block_stride)` on main.
2. Replaces `shared_by` with the version-aware layer accessor.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; this resolves both introduced P1 import/call findings
while preserving the old packed-layout meaning.

#####
`vllm_ascend/distributed/kv_transfer/kv_pool/recompute_cpu_offload/manager.py`

1. Uses the version-aware layer accessor when building recompute offload
metadata.
- Upstream: [#51718](vllm-project/vllm#51718).
   - Review: correct.

#####
`vllm_ascend/distributed/kv_transfer/kv_pool/recompute_cpu_offload/worker.py`

1. Preserves new descriptor geometry (`layers`, strides, offset) on main
and old `shared_by` construction on v0.27.1.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; reconstructed tensors retain the layout information
required by main.

##### `vllm_ascend/models/deepseek_v4/indexer.py`

1. Constructs `AscendMLAAttentionSpec` with `compress_ratio` on v0.27.1
and `tokens_per_state` on main.
- Upstream: [#51718](vllm-project/vllm#51718).
   - Review: correct.

##### `vllm_ascend/models/layer/attention/layer.py`

1. Applies the same lane-specific MLA spec field when attention layers
publish their KV-cache specs.
- Upstream: [#51718](vllm-project/vllm#51718).
   - Review: correct.

##### `vllm_ascend/models/qwen3_dflash2.py`

1. Declares `decoder_layer_cls` and `model_cls` for the new upstream
factory-based construction path.
2. Retains the module-global swap only for v0.27.1, where the factories
do not exist.
- Upstream: [#52816](vllm-project/vllm#52816) /
[`b389ac2946`](vllm-project/vllm@b389ac2),
finalized by [#53435](vllm-project/vllm#53435) /
[`a9a17e7095`](vllm-project/vllm@a9a17e7).
- Review: correct; each lane instantiates `DFlash2Qwen3DecoderLayer` and
`DFlash2Qwen3Model` through its native mechanism.

##### `vllm_ascend/ops/vocab_parallel_embedding.py`

1. Adds the new `skip_gather` argument and mirrors the upstream early
return before tensor-parallel gather.
- Upstream: [#50465](vllm-project/vllm#50465) /
[`d154d90d6c`](vllm-project/vllm@d154d90).
- Review: correct; the trailing default keeps the old call contract
valid.

##### `vllm_ascend/patch/platform/patch_fused_moe.py`

1. Composes an upstream custom `RoutedExperts` subclass with
`AscendRoutedExperts` instead of replacing the class by name.
2. Preserves the upstream subclass's custom loader while retaining
Ascend routing/EPLB behavior.
- Upstream: [#52209](vllm-project/vllm#52209) /
[`b26039b09f`](vllm-project/vllm@b26039b).
- Review: correct; it adapts the actual factory return type and avoids
bypassing new upstream loading behavior.

##### `vllm_ascend/patch/platform/patch_kv_cache_utils.py`

1. Constructs lane-correct `KVCacheTensor` descriptors and inlines
page-size calculation removed from the old patch target.
2. Replaces the removed `_get_kv_cache_config_packed` hook on main with
patches for `get_kv_cache_config_from_groups`,
`_max_memory_usage_bytes_from_groups`, and `_pool_bytes_per_block`.
3. Preserves DeepSeek V4 shared tuples and rank-consistent KV block
planning.
- Upstream: [#51718](vllm-project/vllm#51718) /
[`8bdc70ec7b`](vllm-project/vllm@8bdc70e).
- Review: correct; this resolves the introduced P0 removed-target
finding against the live main entry points.

##### `vllm_ascend/patch/platform/patch_use_v2_model_runner.py`

1. Removes DSpark and DFlash2 from Ascend's V1-only unsupported-feature
result when the upstream helper exists.
- Upstream: MRV2 default switch
[#53183](vllm-project/vllm#53183), with DSpark
from [#52560](vllm-project/vllm#52560) and
DFlash2 from [#52816](vllm-project/vllm#52816).
- Review: correct; the filter is narrow and does not change other
unsupported features.

##### `vllm_ascend/patch/worker/patch_v2/patch_attn_utils.py`

1. Keeps the legacy `_allocate_kv_cache` / `_reshape_kv_cache` patches
only on v0.27.1.
2. Patches main's live `allocate_kv_cache` entry point with
`allocate_kv_cache_main` and retains Ascend reshape binding.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; this resolves the removed-import and
removed-monkey-patch-target P0/P1 findings.

##### `vllm_ascend/utils.py`

1. Adds `get_kv_cache_tensor_layers()` to normalize `shared_by` and
`layers` reads.
- Upstream: [#51718](vllm-project/vllm#51718).
2. Strips a PEP 440 local suffix (for example `+empty`) before
`vllm_version_is()` comparison.
- Upstream: no direct upstream patch; downstream compatibility hardening
needed for release-lane version strings.
- Review: correct; the comparison changes only local build metadata
handling.

##### `vllm_ascend/worker/model_runner_v1.py`

1. Implements lane-correct KV descriptor reads and advertises support
for standardized shared backing.
2. On main, overlays compatible attention/Mamba groups in one backing
store and exposes descriptor-offset views; otherwise materializes
correctly sized private per-layer buffers.
3. Preserves v0.27.1 aliasing, SFA/indexer layouts, sparse/offload
paths, cache-only caches, and page-padding geometry.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; the allocation follows the new descriptor geometry
without changing the release-lane memory model.

##### `vllm_ascend/worker/v2/aclgraph_utils.py`

1. Keeps old-lane dummy-batch repartitioning but consumes already-local
persistent buffers on main.
2. Uses PCP dummy block tables and slot mappings and forwards
`pcp_manager` through graph capture.
- Upstream: persistent buffers
[#53515](vllm-project/vllm#53515) and capture
slot mappings [#53869](vllm-project/vllm#53869).
- Review: correct; main no longer repartitions an already rank-local
capture batch.

##### `vllm_ascend/worker/v2/attn_utils.py`

1. Removes main-lane dependence on the deleted
`indexes_kv_by_block_stride` marker and uses standardized page geometry.
2. Allocates one hybrid backing on main, then creates per-layer views
from `offset`, `layer_stride`, and `block_stride`; private SFA/attention
allocations are retained where sharing is invalid.
3. Adds `allocate_kv_cache_main`, reconstructs Ascend attention groups,
and binds the live upstream allocation entry point.
4. Retains calls to concrete Ascend `get_kv_cache_shape` helpers because
Ascend still needs backend-specific views after the generic base method
was removed.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; the three machine-reported calls are intentional
concrete-backend calls, not calls to the removed base implementation.

##### `vllm_ascend/worker/v2/model_runner.py`

1. Advertises standardized shared KV backing and keeps separate
`prepare_inputs` implementations for the two upstream signatures.
2. Preserves the larger of real PCP tokens and graph-descriptor padding;
main forwards `padded_num_tokens` to the PCP manager.
- Upstream: KV layout
[#51718](vllm-project/vllm#51718), persistent
PCP buffers [#53515](vllm-project/vllm#53515),
and capture mappings
[#53869](vllm-project/vllm#53869).
- Review: correct; runtime PCP tokens are not truncated to the graph
descriptor.

##### `vllm_ascend/worker/v2/pcp_manager.py`

1. Matches the optional constructor/partition keywords exposed by each
lane.
2. Uses persistent `AscendInputBuffers`, including the `max_num_reqs +
1` query-offset view required by prefix sums.
3. Preserves explicit graph padding in the main-lane local batch.
- Upstream: [#53515](vllm-project/vllm#53515)
and [#53869](vllm-project/vllm#53869).
- Review: correct; buffer lifetime, shape, and padding match the new PCP
capture contract.

##### `vllm_ascend/worker/v2/spec_decode/autoregressive/speculator.py`

1. Accepts `dp_sync`, forwards `num_tokens_across_dp` on v0.27.1, and
forwards `dp_sync` on main.
- Upstream: [#53694](vllm-project/vllm#53694) /
[`5acc1c4e4b`](vllm-project/vllm@5acc1c4).
   - Review: correct.

##### `vllm_ascend/worker/v2/spec_decode/dflash/speculator.py`

1. Applies the same lane-specific `num_tokens_across_dp` / `dp_sync`
forwarding in DFlash.
- Upstream: [#53694](vllm-project/vllm#53694).
   - Review: correct.

##### `vllm_ascend/worker/v2/spec_decode/dspark/speculator.py`

1. Applies the same lane-specific `num_tokens_across_dp` / `dp_sync`
forwarding in DSpark.
- Upstream: [#53694](vllm-project/vllm#53694).
   - Review: correct.

##### `vllm_ascend/worker/worker.py`

1. Guards the removed `post_kv_cache_wake_up` hook with `hasattr`.
- Upstream: [#53508](vllm-project/vllm#53508) /
[`479eeb32d2`](vllm-project/vllm@479eeb3).
2. Scales multi-group KV memory only when Ascend must materialize
private buffers; skips DeepSeek V4 custom planning and compatible
standardized hybrid sharing.
- Upstream: [#51718](vllm-project/vllm#51718).
- Review: correct; it prevents OOM without reducing capacity for runners
that can consume the shared layout.

#### Unit tests

##### `tests/ut/_310p/test_model_runner_310p.py`

1. Verifies that the 310P runner does not advertise standardized shared
KV backing.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/_310p/test_model_runner_v2_310p.py`

1. Makes the descriptor fixture valid with `shared_by` on v0.27.1 and
`layers` on main.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/attention/test_dsa_v1.py`

1. Covers both `compress_ratio` and `tokens_per_state` metadata inputs.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/core/test_recompute_scheduler.py`

1. Constructs base MLA specs with the ratio field available in the
active lane.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/distributed/ascend_store/test_layerwise_cache_layout.py`

1. Adds a lane-aware `KVCacheTensor` fixture and validates layout reads
through the compatibility helper.
2. Covers main descriptor strides/offsets and packed-descriptor
rejection.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/kv_offload/test_mooncake_connector.py`

1. Adapts fixtures/assertions to standardized descriptors and main
group-allocation sizes.
2. Adds coverage for registering multiple private per-layer storages
represented by one descriptor.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/patch/platform/test_patch_fused_moe.py`

1. Verifies composition of a custom upstream routed-expert subclass with
the Ascend contract and loader preservation.
- Upstream coverage:
[#52209](vllm-project/vllm#52209).

##### `tests/ut/patch/platform/test_patch_use_v2_model_runner.py`

1. Verifies that only DSpark and DFlash2 are removed from the V1-only
unsupported list.
- Upstream coverage:
[#53183](vllm-project/vllm#53183),
[#52560](vllm-project/vllm#52560), and
[#52816](vllm-project/vllm#52816).

##### `tests/ut/patch/platform/test_prefix_cache_cp_patches.py`

1. Adapts standardized KV descriptor fixtures.
2. Covers DeepSeek V4 shared-tuple capacity and rank-consistent
replanning.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/spec_decode/test_dflash2_proposer.py`

1. Verifies DFlash2's `decoder_layer_cls` and `model_cls` declarations.
- Upstream coverage:
[#52816](vllm-project/vllm#52816) and
[#53435](vllm-project/vllm#53435).

##### `tests/ut/test_compressed_prefix_cache.py`

1. Constructs compressed-prefix MLA specs with the lane-specific ratio
field.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/tools/bisect/test_version_compat.py`

1. Isolates `VLLM_VERSION` environment state so one compatibility test
cannot leak its lane into another.
- Upstream coverage: no direct source patch; downstream test isolation
for the two-lane compatibility logic.

##### `tests/ut/worker/a2/test_model_runner_v1.py`

1. Covers standardized descriptor allocation, per-layer views, shared
capacity, and cache-only behavior.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/worker/a2/test_model_runner_v1_with_device.py`

1. Adapts device-backed V1 fixtures to `shared_by` / `layers` and
validates main-lane geometry.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/worker/a2/test_worker_v1.py`

1. Covers shared-layout capacity versus private-buffer budget scaling.
2. Covers the optional wake hook after sleep-mode KV allocation changes.
- Upstream coverage:
[#51718](vllm-project/vllm#51718) and
[#53508](vllm-project/vllm#53508).

##### `tests/ut/worker/test_attn_utils_v2.py`

1. Covers the main `allocate_kv_cache` entry point, new descriptor
geometry, MLA ratio field, and flat attention-group reshape contract.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/worker/test_model_runner_v2.py`

1. Verifies both prepare-input implementations preserve real PCP tokens
and only main forwards graph padding.
- Upstream coverage:
[#53515](vllm-project/vllm#53515) and
[#53869](vllm-project/vllm#53869).

##### `tests/ut/worker/test_model_runner_v2_finegrained_tp.py`

1. Adds `batch_sharder` and request-count fields to the bare fixture to
match the new sampling contract.
- Upstream coverage:
[#50465](vllm-project/vllm#50465).

##### `tests/ut/worker/test_model_runner_v2_mamba.py`

1. Adds lane-aware descriptors and validates one main-lane hybrid
backing with per-layer offsets.
2. Covers the removal of `indexes_kv_by_block_stride` through observable
page-padding geometry.
- Upstream coverage:
[#51718](vllm-project/vllm#51718).

##### `tests/ut/worker/test_pcp_manager_v2.py`

1. Covers persistent Ascend input buffers, prefix-sum offset shape,
padded local batches, main capture slot mappings, and old/new keyword
signatures.
2. Verifies `dp_sync` on all three Ascend speculators and `pcp_manager`
on graph capture.
- Upstream coverage:
[#53515](vllm-project/vllm#53515),
[#53694](vllm-project/vllm#53694), and
[#53869](vllm-project/vllm#53869).

### Does this PR introduce any user-facing change?

No. This is an internal compatibility update; it does not add an
Ascend-specific public API.

### How was this patch tested?

- Exact-contract main2main validation and range prediction for vLLM
[`ba07e4a48...e6bfe03ad`](vllm-project/vllm@ba07e4a...e6bfe03).
- GitHub Actions: [run
33229439657](https://github.com/vllm-project/vllm-ascend/actions/runs/33229439657).
- Successful in that run: pre-commit, both 310P jobs, all A3 jobs, and
the passing A2 shards on both `e6bfe03ad...` and `v0.27.1`.
- Pending rerun: ModelScope HTTP 500 failures on A2; two unchanged EPLB
CPU tests fail identically on both lanes.

- vLLM main:
vllm-project/vllm@ba07e4a

---------

Signed-off-by: liaoqidan <1107297340@qq.com>
Signed-off-by: shenzhao <shenzhao9@huawei.com>
Signed-off-by: LQDLove <LQDLove@users.noreply.github.com>
Co-authored-by: shenzhao <shenzhao9@huawei.com>
Co-authored-by: LQDLove <LQDLove@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cpu Related to CPU backends mrv2 Model Runner V2 specific ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants