Skip to content

[Feature][Ops] Support original sparse indices in SCFA - #15751

Open
QwertyJack wants to merge 1 commit into
vllm-project:mainfrom
QwertyJack:codex/dsv4-vision-scfa-operator
Open

QwertyJack wants to merge 1 commit into
vllm-project:mainfrom
QwertyJack:codex/dsv4-vision-scfa-operator

Conversation

@QwertyJack

@QwertyJack QwertyJack commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

What this PR does / why we need it?

This operator follow-up is stacked directly on #15457. DeepSeek V4 Vision builds ori_sparse_indices for bidirectional attention inside image spans, but the arch32 SCFA kernel currently reads original K/V through the contiguous paged-attention window. As a result, passing the indices alone does not make compressed SCFA layers consume the selected physical PA slots.

With #15457 plus this PR, the core DeepSeek-V4-Flash-Vision-Exp multimodal SCFA path is available.

Related roadmap: #15462.

What changed

  • Detect the valid original sparse-index length from the first negative sentinel in each query row.
  • Gather original K for MM1 and V for MM2 through the same physical PA slots with DataCopyPABySlots.
  • Use the TND cumulative query-token offset when selecting each sparse-index row.
  • Preserve the existing contiguous causal/SWA path when ori_sparse_indices is absent.
  • Fall back to two PA copies when compressed paged blocks descend physically, preserving their logical order.
  • Add dense-reference NPU coverage for FP16/BF16, compression ratios 1/4/128, non-contiguous PA blocks, K/V gather, and the production block-32 image geometry.

Does this PR introduce any user-facing change?

Yes. On arch32 with layout_q=TND and layout_kv=PA_ND, SCFA now applies the per-query original-KV physical slots supplied by the runtime. Image tokens can therefore attend bidirectionally within their image span while surrounding text retains causal sliding-window attention.

How was this patch tested?

The rebased PR contains one operator commit whose parent is the current #15457 head a0f4947bb.

Current branch checks:

python -m py_compile tests/e2e/nightly/single_node/ops/singlecard_ops/test_sparse_attn_sharedkv_scfa_indices.py
ruff format --check tests/e2e/nightly/single_node/ops/singlecard_ops/test_sparse_attn_sharedkv_scfa_indices.py
ruff check tests/e2e/nightly/single_node/ops/singlecard_ops/test_sparse_attn_sharedkv_scfa_indices.py
git diff --check a0f4947bb..HEAD
# passed

The three modified SCFA kernel sources are byte-identical to the sources used to build the retained Ascend 910B OPP package. That package passed the new dense-reference suite:

9 passed, 15 warnings in 8.40s

The covered operator configurations are:

  • query layout: TND;
  • KV layout: PA_ND;
  • KV heads: 1;
  • index width: 512;
  • PA block sizes: 16 and the service geometry 32;
  • dtype: FP16 and BF16;
  • compression ratio: 1, 4, and 128;
  • absent-index compatibility path;
  • non-contiguous and descending physical PA blocks.

The same operator sources were also used in the full W8A8 integration stack that aligned the fixed official-API teacher sequences and content-token top-1 results. That service evidence included additional runtime hardening from #15740, so it is integration evidence rather than an isolated #15457-plus-operator comparison.

Scope boundaries

  • This PR intentionally targets the DeepSeek V4 production combination TND + PA_ND on arch32.

  • The existing host tiling restriction kv_head_num == 1 remains unchanged.

  • DSA context parallel is not changed.

  • No Python runtime, frontend, RNG, or performance changes are included.

  • vLLM main: vllm-project/vllm@ba07e4a

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enables the DeepSeek-V4-Flash-Vision-Exp multimodal path on the Ascend architecture. It introduces a specialized SCFA kernel that supports per-query original-KV physical slots, integrates the vision tower and aligner components, and updates the MoE router to handle vision-specific expert selection. Additionally, it includes infrastructure to manage multimodal document ranges and ensures speculative decoding remains stable when using vision-enabled checkpoints.

Highlights

  • SCFA Operator Enhancement: Updated the SCFA kernel to consume original sparse indices, enabling bidirectional attention within image spans while maintaining causal sliding-window attention for text.
  • Vision Model Integration: Added the DeepSeek-V4 vision tower (ViT + aligner) and multimodal processor, enabling support for the DeepSeek-V4-Flash-Vision-Exp architecture.
  • MoE Router Update: Implemented vision-specific expert routing bias (bias_vl) in the MoE router to handle sentinel tokens correctly while preserving deterministic text routing.
  • Speculative Decoding Fix: Added normalization logic to restore the DSpark draft architecture after multimodal config conversion, preventing duplicate attention layer registrations.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions

github-actions Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.


Tip

💡 Consider Linking a Related Issue or RFC

Your PR title contains the [BugFix] tag, indicating a bug fix or new feature.

Linking a related issue or RFC in the PR description is strongly encouraged — it gives reviewers helpful context and speeds up the review. You can use any of these keywords:

  • Fixes #<issue_number>
  • Closes #<issue_number>
  • Resolves #<issue_number>
  • Refs #<rfc_or_issue_number> (for RFCs)

🙏 Thanks for helping us keep the project well-organized!

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

Suggested PR Title:\n\nmarkdown\n[Ops][Feature] Support DeepSeek-V4 Vision model on Ascend\n\n\nSuggested PR Summary:\n\nmarkdown\n### What this PR does / why we need it?\nThis PR adds support for the DeepSeek-V4 vision model (DeepSeek-V4-Flash-Vision-Exp) on the Ascend backend. It implements multimodal preprocessing, the vision tower (ViT and aligner), and the main conditional generation model wrapper. It also integrates vision-specific expert routing bias (`bias_vl`) into the fused MoE router, updates speculative decoding configurations, and adapts quantization prefix mappings.\n\nFeedback:\n- Remove `strict=True` in `zip()` within `vl_model.py` to maintain compatibility with Python 3.9.\n- Guard the weight loading check in `vl_model.py` to prevent a `KeyError` when `image_enabled` is `False`.\n- Specify `device=original_mask.device` when creating the padding mask in `mm_preprocess.py` to avoid device mismatch errors.\n\n### Does this PR introduce _any_ user-facing change?\nYes, it adds support for serving the DeepSeek-V4 vision model on Ascend.\n\n### How was this patch tested?\nTested with newly added unit and integration tests under `tests/e2e/nightly/single_node/ops/singlecard_ops/test_sparse_attn_sharedkv_scfa_indices.py`, `tests/ut/attention/test_dsa_v1.py`, `tests/ut/models/test_deepseek_v4_moe.py`, `tests/ut/models/test_deepseek_v4_vision.py`, and `tests/ut/models/test_deepseek_v4_vision_preprocess.py`.\n

Comment thread vllm_ascend/models/deepseek_v4/vl_model.py
Comment thread vllm_ascend/models/deepseek_v4/vl_model.py
Comment thread vllm_ascend/models/deepseek_v4/mm_preprocess.py
@QwertyJack QwertyJack changed the title [BugFix][Ops] Consume original sparse indices in SCFA [Feature][Ops] Support original sparse indices in SCFA Sep 4, 2026
@QwertyJack QwertyJack added the ready-precise run selected e2e test for pr label Sep 4, 2026
@QwertyJack
QwertyJack force-pushed the codex/dsv4-vision-scfa-operator branch from 331abdd to 1895dd9 Compare September 4, 2026 08:22
@QwertyJack

QwertyJack commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

/rerun
[Bot]: rerun completed.

Rerun (failed jobs only):

  • E2E

1 similar comment
@QwertyJack

QwertyJack commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator Author

/rerun
[Bot]: rerun completed.

Rerun (failed jobs only):

  • E2E

Derive original KV lengths from padded physical-slot rows and gather both K and V through ori_sparse_indices. Preserve the existing contiguous path when the optional indices are absent.

Signed-off-by: QwertyJack <7554089+QwertyJack@users.noreply.github.com>
@QwertyJack
QwertyJack force-pushed the codex/dsv4-vision-scfa-operator branch from 1895dd9 to c1dfeea Compare September 5, 2026 02:14
@QwertyJack

QwertyJack commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator Author

/rerun
[Bot]: rerun completed.

Rerun (failed jobs only):

  • E2E

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation module:tests ready-precise run selected e2e test for pr

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants