Skip to content

implement batch invariant with ascendc#6590

Merged
wangxiyuan merged 8 commits intovllm-project:mainfrom
Ronald1995:batch_invariant_v3
Feb 10, 2026
Merged

implement batch invariant with ascendc#6590
wangxiyuan merged 8 commits intovllm-project:mainfrom
Ronald1995:batch_invariant_v3

Conversation

@Ronald1995
Copy link
Copy Markdown
Contributor

@Ronald1995 Ronald1995 commented Feb 6, 2026

What this PR does / why we need it?

there are batch invariant ops implemented by triton and ascendc, this pr aims to choose which kind of ops to be used to enable batch invariant. #5487

Does this PR introduce any user-facing change?

no

How was this patch tested?

Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 6, 2026

👋 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.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Ronald1995, 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 introduces a flexible system for handling batch-invariant operations within the vllm-ascend project. It allows for dynamic selection between Triton-based and AscendC-based implementations, prioritizing the latter for key matrix operations to leverage potential performance benefits on Ascend NPUs. This change aims to optimize the execution of these operations while maintaining determinism.

Highlights

  • Flexible Batch Invariant Operator Selection: Implemented a mechanism to dynamically choose between Triton and AscendC implementations for batch-invariant operations, prioritizing AscendC when available for potentially better performance on Ascend NPUs.
  • AscendC Prioritization: Configured mm, matmul, and npu_fused_infer_attention_score operations to use AscendC custom operators if custom_ops are detected, otherwise falling back to Triton implementations for mm and matmul.
  • Triton-only Operator Registration: Ensured that addmm and bmm operations are registered using their Triton implementations when Triton is available, regardless of AscendC availability.
  • Enhanced Determinism Settings: Updated the HCCL_DETERMINISTIC environment variable to 'strict' to improve communication determinism.

🧠 New Feature in Public Preview: You can now enable Memory 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.

Changelog
  • vllm_ascend/batch_invariant.py
    • Added importlib and torch_npu imports.
    • Introduced HAS_ASCENDC_BATCH_INVARIANT flag to detect the presence of AscendC custom operations.
    • Modified override_envs_for_invariance to set HCCL_DETERMINISTIC to "strict".
    • Refactored enable_batch_invariant_mode to conditionally register aten operators:
      • addmm and bmm are registered using Triton implementations if HAS_TRITON is true.
      • mm and matmul are registered using AscendC custom ops (torch.ops.myops) if HAS_ASCENDC_BATCH_INVARIANT is true.
      • torch_npu.npu_fused_infer_attention_score is directly patched with its AscendC batch-invariant counterpart if HAS_ASCENDC_BATCH_INVARIANT is true.
      • If HAS_ASCENDC_BATCH_INVARIANT is false, mm, matmul, and linear are registered using Triton implementations if HAS_TRITON is true.
    • Updated the init_batch_invariance function to check for both HAS_TRITON and HAS_ASCENDC_BATCH_INVARIANT before logging the enablement of batch-invariant mode.
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request yet.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the batch invariance mechanism to support AscendC custom operators as a preferred alternative to Triton kernels. The changes correctly prioritize AscendC implementations when available and fall back to Triton.

My main concern is a critical issue where batch invariance for addmm and bmm operations is silently lost if Triton is not available, even when AscendC is. This could lead to hard-to-diagnose determinism problems. I've added a specific comment with a suggested fix to address this by adding a warning.

Overall, the direction is good, but this potential for silent partial failure needs to be addressed to ensure the feature is robust.

Comment thread vllm_ascend/batch_invariant.py Outdated
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
@Ronald1995 Ronald1995 force-pushed the batch_invariant_v3 branch 2 times, most recently from 7e40903 to 96be758 Compare February 9, 2026 06:26
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
@wangxiyuan wangxiyuan merged commit 77305df into vllm-project:main Feb 10, 2026
25 checks passed
845473182 pushed a commit to 845473182/vllm-ascend that referenced this pull request Feb 11, 2026
…to qwen3next_rebase

* 'main' of https://github.com/vllm-project/vllm-ascend:
  [Feat] 310p support MoE W8A8 quantizaition (vllm-project#6641)
  [TEST]add a qwen3-30b acc case with mooncake mempool (vllm-project#6244)
  [MOE Refactor] Remove QuantType in prepare_finalize.py (vllm-project#6534)
  [EPLB] Avoiding eplb's dependency on a specified model (vllm-project#6528)
  [Doc][Misc] Restructure tutorial documentation (vllm-project#6501)
  implement batch invariant with ascendc (vllm-project#6590)
  [Refact]Refact MLA/SFA weight prefetch to consist with moe weight prefetch (vllm-project#6629)
  [Misc] upgrade to vllm main (vllm-project#6646)
  [main][Docs] Fix spelling errors across documentation (vllm-project#6649)
  [bugfix]Fix no attribute 'data' when MLAPO is enable  (vllm-project#6601)
  [DOC]Add Memcache Usage Guide (vllm-project#6476)
  [main][bugfix] Fix spec acceptance rate problem in vllm_0.15.0 (vllm-project#6606)
  [Test][LoRA] Add e2e test for base model inference (vllm-project#6624)
  [refactor]Optimized the kvcache usage of Deepseek v3.2 (vllm-project#6610)
  [Feat](sfa,dcp) support dcp for sfa (vllm-project#6563)
  [BugFix] Add support for rotary_dim parameter when using partial rope in rotary_embedding (vllm-project#6581)
  [fix bug] fix tensor mismatch bug in sigmoid operate test case (vllm-project#6619)
  [Kernel]: Optimize DispatchFFNCombine performance (vllm-project#6468)
  [MISC] Clean up useless env USE_OPTIMIZED_MODEL (vllm-project#6618)
chenchuw886 pushed a commit to chenchuw886/vllm-ascend that referenced this pull request Feb 12, 2026
### What this PR does / why we need it?
there are batch invariant ops implemented by triton and ascendc, this pr
aims to choose which kind of ops to be used to enable batch invariant.
vllm-project#5487

### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@d7e17aa

---------

Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: momochenchuw <chenchuw@huawei.com>
@wangxiyuan wangxiyuan mentioned this pull request Feb 24, 2026
banxiaduhuo pushed a commit to banxiaduhuo/vllm-ascend that referenced this pull request Feb 26, 2026
### What this PR does / why we need it?
there are batch invariant ops implemented by triton and ascendc, this pr
aims to choose which kind of ops to be used to enable batch invariant.
vllm-project#5487

### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@d7e17aa

---------

Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
ZRJ026 pushed a commit to ZRJ026/vllm-ascend that referenced this pull request Feb 28, 2026
### What this PR does / why we need it?
there are batch invariant ops implemented by triton and ascendc, this pr
aims to choose which kind of ops to be used to enable batch invariant.
vllm-project#5487

### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@d7e17aa

---------

Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: zrj026 <zhangrunjiang026@gmail.com>
maoxx241 pushed a commit to maoxx241/vllm-ascend that referenced this pull request Mar 2, 2026
### What this PR does / why we need it?
there are batch invariant ops implemented by triton and ascendc, this pr
aims to choose which kind of ops to be used to enable batch invariant.
vllm-project#5487

### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@d7e17aa

---------

Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
ZRJ026 pushed a commit to ZRJ026/vllm-ascend that referenced this pull request Mar 4, 2026
### What this PR does / why we need it?
there are batch invariant ops implemented by triton and ascendc, this pr
aims to choose which kind of ops to be used to enable batch invariant.
vllm-project#5487

### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@d7e17aa

---------

Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: zrj026 <zhangrunjiang026@gmail.com>
LCAIZJ pushed a commit to LCAIZJ/vllm-ascend that referenced this pull request Mar 7, 2026
### What this PR does / why we need it?
there are batch invariant ops implemented by triton and ascendc, this pr
aims to choose which kind of ops to be used to enable batch invariant.
vllm-project#5487

### Does this PR introduce _any_ user-facing change?
no
### How was this patch tested?

- vLLM version: v0.15.0
- vLLM main:
vllm-project/vllm@d7e17aa

---------

Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants