Skip to content

[Feature] Add docs of batch invariance and make some extra operators patch#6910

Merged
wangxiyuan merged 18 commits intovllm-project:mainfrom
Ronald1995:add_rms_norm
Mar 5, 2026
Merged

[Feature] Add docs of batch invariance and make some extra operators patch#6910
wangxiyuan merged 18 commits intovllm-project:mainfrom
Ronald1995:add_rms_norm

Conversation

@Ronald1995
Copy link
Copy Markdown
Contributor

@Ronald1995 Ronald1995 commented Mar 2, 2026

What this PR does / why we need it?

This PR add docs of batch invariance and make some extra operators according to validation result.
please see #5487 to track progress.

Does this PR introduce any user-facing change?

No

How was this patch tested?

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>
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>
@github-actions github-actions bot added documentation Improvements or additions to documentation module:tests module:core labels Mar 2, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 2, 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, 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 significantly enhances the batch invariance feature within vLLM-Ascend by providing detailed user documentation and implementing crucial operator-level changes. The primary goal is to ensure deterministic model outputs, irrespective of batch size or request order, which is vital for debugging, reproducibility in RL, and consistent large-scale inference. The changes involve new documentation, the introduction of batch-invariant operator implementations, and strategic disabling of certain fused or custom operations that could introduce non-determinism.

Highlights

  • Batch Invariance Documentation: Introduced comprehensive documentation for batch invariance in vLLM-Ascend, detailing its motivation, hardware requirements, enabling steps for online and offline inference, and a list of tested models.
  • Batch-Invariant Operator Implementations: Implemented and integrated batch-invariant versions of add_rms_norm and reduce_sum operators to ensure deterministic behavior, addressing limitations of existing fused operations.
  • Operator Patching for Determinism: Patched core PyTorch and NPU operations, specifically torch_npu.npu_add_rms_norm and torch.sum, to utilize the newly implemented batch-invariant operators when the feature is enabled.
  • Environment and Custom Operator Configuration: Configured environment variables to disable specific optimizations (VLLM_ASCEND_ENABLE_NZ, VLLM_ASCEND_ENABLE_MATMUL_ALLREDUCE) and custom operators when batch invariance is active, preventing non-deterministic behavior.
  • Unit Tests for New Operators: Added unit tests to verify the correctness and consistency of the add_rms_norm implementation, ensuring it produces expected deterministic outputs.

🧠 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
  • docs/source/user_guide/feature_guide/batch_invariance.md
    • Added new documentation file detailing batch invariance, its motivation, hardware requirements, usage examples, and tested models.
  • docs/source/user_guide/feature_guide/index.md
    • Updated the feature guide index to include the new batch invariance documentation.
  • tests/ut/batch_invariant/test_batch_invariant.py
    • Added torch import and mocking for torch_npu to facilitate testing.
    • Added unit tests for the add_rms_norm function, including a consistency check against npu_add_rms_norm.
  • vllm_ascend/batch_invariant.py
    • Added torch_sum alias to prevent recursive calls during patching.
    • Imported softmax_batch_invariant for Triton-based batch invariance.
    • Implemented add_rms_norm to split AclnnAddRmsNorm into separate add and RMS norm operations for determinism.
    • Implemented reduce_sum to use npu_reduce_sum_batch_invariant for NPU tensors.
    • Disabled VLLM_ASCEND_ENABLE_MATMUL_ALLREDUCE environment variable when batch invariance is enabled.
    • Registered aten::softmax and aten::_softmax with softmax_batch_invariant for Triton.
    • Patched torch_npu.npu_add_rms_norm to use the custom add_rms_norm function.
    • Patched torch.sum to use the custom reduce_sum function.
  • vllm_ascend/utils.py
    • Modified enable_custom_op to disable custom operators when batch invariance is active, as some custom operators may not be batch-invariant.
Activity
  • No specific activity (comments, reviews, or progress updates) 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 introduces documentation and necessary code changes to support batch invariance for vLLM on Ascend NPUs. The core changes involve patching several PyTorch operations like softmax, add_rms_norm, and sum with deterministic implementations when batch invariance is enabled. It also correctly disables other optimizations and custom operators that are not batch-invariant.

My main concern is a critical bug in the implementation of the reduce_sum wrapper, which incorrectly changes the default behavior of torch.sum when no dimension is specified. This could lead to silent errors and incorrect model outputs. I've provided a detailed comment and a suggested fix for this issue.

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>
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
@@ -0,0 +1,129 @@
# Batch Invariance

!!! note
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

Signed-off-by: Ronald1995 <ronaldautomobile@163.com>
@weijinqian0 weijinqian0 added the ready read for review label Mar 4, 2026
@yiz-liu yiz-liu added the ready-for-test start test by label for PR label Mar 4, 2026
@wangxiyuan wangxiyuan merged commit 77e009d into vllm-project:main Mar 5, 2026
64 checks passed
845473182 pushed a commit to 845473182/vllm-ascend that referenced this pull request Mar 5, 2026
…to qwen3next_graph

* 'main' of https://github.com/vllm-project/vllm-ascend: (40 commits)
  [Feature] Add docs of batch invariance and make some extra operators patch (vllm-project#6910)
  [bugfix]Qwen2.5VL accurate question (vllm-project#6975)
  [CI] Add DeepSeek-V3.2 large EP nightly ci (vllm-project#6378)
  [Ops][BugFix] Fix RoPE shape mismatch for mtp models with flashcomm v1 enabled (vllm-project#6939)
  [bugfix]fix file not found error in nightly of single-node (vllm-project#6976)
  [Bugfix] Fix the acceptance rates dorp issue when applying eagle3 to QuaRot model (vllm-project#6914)
  [CI] Enable auto upgrade e2e estimated time for auto-partition suites (vllm-project#6840)
  [Doc][Misc] Fix msprobe_guide.md documentation issues (vllm-project#6965)
  [Nightly][Refactor]Migrate nightly single-node model tests from `.py` to `.yaml` (vllm-project#6503)
  [BugFix] Improve GDN layer detection for multimodal models (vllm-project#6941)
  [feat]ds3.2 pcp support mtp and chunkprefill (vllm-project#6917)
  [CPU binding] Implement global CPU slicing and improve IRQ binding for Ascend NPUs (vllm-project#6945)
  [Triton] Centralize Ascend extension op dispatch in triton_utils (vllm-project#6937)
  [csrc][bugfix] Add compile-time Ascend950/910_95 compatibility for custom ops between CANN8.5 and 9.0 (vllm-project#6936)
  [300I][Bugfix] fix unquant model weight nd2nz error (vllm-project#6851)
  [doc] fix supported_models (vllm-project#6930)
  [CI] nightly test timeout (vllm-project#6912)
  [CI] Upgrade CANN to 8.5.1 (vllm-project#6897)
  [Model]Add Qwen3-Omni quantization Ascend NPU adaptation and optimization (vllm-project#6828)
  [P/D][v0.16.0]Adapt to RecomputeScheduler in vLLM 0.16.0 (vllm-project#6898)
  ...
LCAIZJ pushed a commit to LCAIZJ/vllm-ascend that referenced this pull request Mar 7, 2026
…patch (vllm-project#6910)

### What this PR does / why we need it?

This PR add docs of batch invariance and make some extra operators
according to validation result.
please see vllm-project#5487 to
track progress.

### Does this PR introduce _any_ user-facing change?
No

### How was this patch tested?

- vLLM version: v0.16.0
- vLLM main:
vllm-project/vllm@15d76f7

---------

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

Labels

documentation Improvements or additions to documentation module:core module:tests ready read for review ready-for-test start test by label for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants