Skip to content

[NPU] Port DSV4 CAM fixes to main - #311

Merged
jiangkuaixue123 merged 3 commits into
vllm-project:mainfrom
jiangkuaixue123:main
Sep 4, 2026
Merged

[NPU] Port DSV4 CAM fixes to main#311
jiangkuaixue123 merged 3 commits into
vllm-project:mainfrom
jiangkuaixue123:main

Conversation

@jiangkuaixue123

Copy link
Copy Markdown
Collaborator

Summary

Port the following merged changes from v0.26.0_camasync_dsv4 to main:

Changes

  • Align and validate TP-local input IDs for DSV4 NPU Hash routing.
  • Fuse CAM shared expert activation through W13, dequant-SwiGLU-quant, and W2.
  • Add focused contract and unit-test coverage.

Validation

  • python3 -m compileall -q on the four changed Python files
  • git diff --check upstream/main..HEAD
  • Focused pytest was attempted, but the system Python does not have pytest installed (No module named pytest).

Signed-off-by: jiangkuaixue123 jiangxiaozhou111@163.com

…-project#301)

## Purpose

Fix DeepSeek V4 Hash routing on NPU Attention ranks when FlashComm v1
sequence parallelism is enabled.

After FlashComm splits hidden states across tensor-parallel ranks,
router logits contain only rank-local tokens, while
forward_context.input_ids can still contain the unsplit global token
list. The previous alignment check therefore raised:

DSV4 Hash routing input_ids/token count mismatch on Attention

This change pads input_ids with the existing forward-context pad size,
splits them with the same contiguous tensor-parallel layout, and selects
the current TP rank before invoking the CANN Hash routing operator.

## Issue

- Related issue(s): None
- Closing keyword, only if fully resolved: N/A

## Scope

- In scope:
- DSV4 NPU Async CAM Hash routing on Attention ranks with FlashComm v1
enabled.
- Validation that the Hash-routing token IDs follow the local TP token
layout.
- Out of scope:
  - Non-Hash routing.
  - Native vLLM-Ascend MoE communication.
  - GPU behavior and unrelated DSV4 execution paths.

## Implementation Notes

- The adjustment is only applied when FlashComm v1 is enabled and the
input ID count differs from the local router-logit token count.
- Existing forward_context.pad_size is applied before splitting so the
token layout is divisible across TP ranks.
- vLLM-Ascend split_tensor_along_first_dim is used with contiguous
chunks, and the current TP rank selects its local input IDs.
- The existing post-split count validation remains in place, so
unexpected layouts still fail explicitly.
- No vLLM source checkout or monkey patch is modified.

## Test Plan

- Run the focused CPU-safe unit test.
- Run Ruff lint and formatting checks on both changed files.
- NPU multi-rank validation is hardware-gated and was not available
locally.

## Test Result

- python3 -m pytest -q
tests/unit/model_executor/models/test_deepseek_v4_attention_gate.py
  - 2 passed
- python3 -m ruff check
afd_plugin/model_executor/models/npu/deepseek_v4_attention_gate.py
tests/unit/model_executor/models/test_deepseek_v4_attention_gate.py
  - All checks passed
- python3 -m ruff format --check
afd_plugin/model_executor/models/npu/deepseek_v4_attention_gate.py
tests/unit/model_executor/models/test_deepseek_v4_attention_gate.py
  - 2 files already formatted
- git diff --check
  - Passed
- NPU multi-rank E2E: not run because no NPU environment was available
locally.

## Docs Impact

- Files updated: None
- If none, reason: This is an internal runtime correctness fix with no
user-facing API or configuration change.

---

<details>
<summary>Essential PR Checklist</summary>

- [x] Purpose is clear and linked to public context when possible.
- [x] Scope is bounded.
- [x] Compatibility with vLLM v0.26.0 is considered.
- [x] No changes are made to the vLLM source checkout.
- [x] Plugin-owned classes or explicit dotted class paths are preferred
over monkey patches.
- [x] Any compat shim or monkey patch is isolated, idempotent,
version-guarded, documented, and tested. Not applicable; no shim or
monkey patch is changed.
- [x] Imports remain CPU-safe; NPU-specific imports stay deferred inside
the runtime-only branch.
- [x] Validation evidence is included, including skipped NPU tests.
- [x] Documentation impact is stated.

</details>

Signed-off-by: jiangkuaixue123 <jiangxiaozhou111@163.com>
Keeps CAM dynamicQuant shared inputs in the INT8 path through W13, fused
dequant-SwiGLU-quant, and W2. Adds contract coverage for the fused scale
handoff.\n\nValidation: python3 -m compileall and git diff --check.
Pytest could not run because the local .venv pytest launcher points to a
missing interpreter.

---------

Signed-off-by: jiangkuaixue123 <jiangxiaozhou111@163.com>
Signed-off-by: jiangkuaixue123 <jiangxiaozhou111@163.com>
@jiangkuaixue123
jiangkuaixue123 merged commit 0e20834 into vllm-project:main Sep 4, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant