Skip to content

[Test][Triton] Add RMS norm kernel unit tests - #14700

Open
GDzhu01 wants to merge 1 commit into
vllm-project:mainfrom
GDzhu01:test/triton-rms-kernel-ut
Open

[Test][Triton] Add RMS norm kernel unit tests#14700
GDzhu01 wants to merge 1 commit into
vllm-project:mainfrom
GDzhu01:test/triton-rms-kernel-ut

Conversation

@GDzhu01

@GDzhu01 GDzhu01 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

What this PR does / why we need it?

Adds unit test coverage for triton_q_rms, the Python wrapper around triton_rms_kernel.

The new tests verify:

  • launch grid uses the detected vectorcore count
  • total_batch, hidden dimension, row stride, epsilon, and output tensor shape are passed correctly
  • BLOCK_M selection covers representative batch-per-core cases
  • hidden dimensions greater than 2048 are rejected before launching the kernel

triton_q_rms is used by the DSA Q RMS norm paths through DeviceOperator.apply_dsa_q_rms, and is also warmed up by rms_triton_warmup.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

  • Added unit test: tests/ut/ops/test_triton_rms_norm.py
  • Ran syntax check locally:
    python -m py_compile tests/ut/ops/test_triton_rms_norm.py

Could not run pytest locally because this Windows PC Python environment does not have pytest installed, and this workspace targets Ascend/NPU execution for hardware-specific tests.

@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 introduces unit test coverage for the triton_q_rms operator wrapper. By utilizing a mock kernel approach, the changes validate that the operator correctly interfaces with the underlying Triton kernel, properly calculates launch grids based on hardware properties, and enforces necessary constraints on input dimensions.

Highlights

  • Unit Test Coverage: Added comprehensive unit tests for the triton_q_rms Python wrapper to ensure kernel launch parameters and input validation are handled correctly.
  • Kernel Mocking: Implemented a RecordingKernel helper to capture and verify kernel launch arguments and grid configurations without requiring actual hardware execution.
  • Validation Logic: Verified that the implementation correctly rejects hidden dimensions exceeding 2048, ensuring robust input handling.
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.

@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:

[Ops][Test][Feature] Add unit tests for Triton RMS Norm operator

Suggested PR Summary:

### What this PR does / why we need it?
This pull request adds unit tests for the Triton RMS Norm operator (`triton_q_rms`) in `tests/ut/ops/test_triton_rms_norm.py`. It verifies that the kernel is launched with the expected arguments across various shapes and device configurations, and checks that unsupported dimensions (greater than 2048) are correctly rejected.

Feedback:
- An issue was identified where directly monkeypatching `rms_norm.triton.runtime.driver.active.utils` can raise an `AttributeError` in environments where Triton's active driver is not initialized (such as CPU-only test environments). It is recommended to mock the `active` attribute on `triton.runtime.driver` instead.

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

### How was this patch tested?
This PR introduces new unit tests (`test_triton_q_rms_launches_kernel_with_expected_args` and `test_triton_q_rms_rejects_unsupported_dim`) to verify the correctness of the Triton RMS Norm operator.

Comment on lines +60 to +64
monkeypatch.setattr(
rms_norm.triton.runtime.driver.active.utils,
"get_device_properties",
lambda device: {"num_vectorcore": num_vectorcore},
)

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.

high

Attempting to monkeypatch rms_norm.triton.runtime.driver.active.utils directly will raise an AttributeError on environments where Triton's active driver is not initialized (such as CPU-only test environments or local development machines), because triton.runtime.driver.active is None. To make the unit tests robust and runnable on CPU-only environments, mock the active attribute itself on triton.runtime.driver instead.

Suggested change
monkeypatch.setattr(
rms_norm.triton.runtime.driver.active.utils,
"get_device_properties",
lambda device: {"num_vectorcore": num_vectorcore},
)
class MockActive:
class utils:
@staticmethod
def get_device_properties(device):
return {"num_vectorcore": num_vectorcore}
monkeypatch.setattr(rms_norm.triton.runtime.driver, "active", MockActive)

@github-actions

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.

Add unit coverage for triton_q_rms wrapper launch behavior, block size selection, output shape preservation, and unsupported hidden dimension handling.

Signed-off-by: GDzhu01 <116337067+GDzhu01@users.noreply.github.com>
@GDzhu01
GDzhu01 force-pushed the test/triton-rms-kernel-ut branch from f2a09a1 to 63d82fd Compare August 21, 2026 03:22
@GDzhu01

GDzhu01 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

CI gate is blocked because selected tests require a readiness label. Could a maintainer please add
eady-precise\ to run the selected test set? The code checks currently pass: DCO, PR create action, main, pre-commit, Recommend tests from coverage, and select-tests.

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.

1 participant