Skip to content

[JIT Kernel]Support fused_add_rmsnorm in JIT Kernel#17677

Merged
BBuf merged 9 commits intosgl-project:mainfrom
HydraQYH:dev_jit_fused_add_rmsnorm
Jan 29, 2026
Merged

[JIT Kernel]Support fused_add_rmsnorm in JIT Kernel#17677
BBuf merged 9 commits intosgl-project:mainfrom
HydraQYH:dev_jit_fused_add_rmsnorm

Conversation

@HydraQYH
Copy link
Collaborator

@HydraQYH HydraQYH commented Jan 24, 2026

Motivation

There are two differences from the Flashinfer implementation:

  1. Avoid storing/loading inp+res in shared memory
  2. Using 256-bit LDG on B200

Modifications

  • python/sglang/jit_kernel/norm.py
  • python/sglang/jit_kernel/csrc/elementwise/fused_add_rmsnorm.cuh
  • python/sglang/jit_kernel/tests/test_fused_add_rmsnorm.py
  • python/sglang/jit_kernel/include/sgl_kernel/vec.cuh

Accuracy Tests

H20(with CUDA 12.9):
image
B200(witch CUDA 13.1):
image

Benchmarking and Profiling

H20(with CUDA 12.9):
h20_fused_add_rmsnorm.txt
B200(witch CUDA 13.1):
b200_fused_add_rmsnorm.txt

Checklist

Review Process

  1. Ping Merge Oncalls to start the PR flow. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • /tag-run-ci-label, /rerun-failed-ci, /tag-and-rerun-ci
  4. After green CI and required approvals, ask Merge Oncalls to merge.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @HydraQYH, 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 highly optimized JIT kernel for the fused_add_rmsnorm operation, crucial for efficient deep learning model execution. The primary goal is to boost performance by refining memory access patterns and utilizing advanced GPU features like 256-bit global loads, especially beneficial for NVIDIA B200 architectures. The new kernel is seamlessly integrated into the SGLang JIT framework and its correctness is verified through extensive testing against a known performant library.

Highlights

  • New Fused Kernel: Implemented a new CUDA kernel (fused_add_rmsnorm.cuh) for a fused add and RMS normalization operation.
  • Performance Optimizations: The new kernel is optimized to avoid storing intermediate inp+res results in shared memory and leverages 256-bit global memory loads (LDG) for enhanced performance on B200 GPUs.
  • Python Integration: Integrated the new CUDA kernel into the Python JIT kernel system, making it accessible via a new fused_add_rmsnorm function in sglang.jit_kernel.norm.
  • Unit Testing: Added comprehensive unit tests (test_fused_add_rmsnorm.py) to verify the numerical accuracy of the new fused operation by comparing its output against the flashinfer library across various input sizes.

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

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.

@HydraQYH
Copy link
Collaborator Author

@BBuf @DarkSharpness WIP for now, I will add benchmarks within a few days.

Copy link
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 a new fused add and RMSNorm JIT kernel, which is a valuable performance optimization. The implementation is generally solid, with corresponding Python bindings and tests. My review identifies a few areas for improvement. There is a high-priority issue in the CUDA kernel regarding an unused and misused kernel parameter that should be addressed. I've also included several medium-severity suggestions to enhance code quality, maintainability, and test coverage. Specifically, I recommend improving const-correctness, reducing code duplication in the CUDA kernel, and expanding the test suite to cover all supported data types and simplify test data generation. Addressing these points will improve the robustness and maintainability of this new feature.

@HydraQYH HydraQYH changed the title [WIP][JIT Kernel]Support fused_add_rmsnorm in JIT Kernel [JIT Kernel]Support fused_add_rmsnorm in JIT Kernel Jan 26, 2026
@HydraQYH
Copy link
Collaborator Author

@DarkSharpness @BBuf Ready for review.

@HydraQYH
Copy link
Collaborator Author

/tag-and-rerun-ci

@HydraQYH
Copy link
Collaborator Author

/rerun-failed-ci

private:
/// NOTE: 1. must be pow of two 2. 16 * 8 = 128 byte, which is the max vector size supported by most devices
static_assert((N > 0 && (N & (N - 1)) == 0) && sizeof(T) * N <= 16, "CUDA only support at most 128B vector op");
static_assert((N > 0 && (N & (N - 1)) == 0) && sizeof(T) * N <= 32, "CUDA only support at most 256B vector op");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is actually very tricky. Before B200, the max load/store size is 128bit. On and after B200, the max size is 256bit. On H200, developers may misuse this API and lead to poor performance.

It's okay to keep this behavior. But in the future we need to forbid using 256bit load/store on H200.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah. I think we could use __CUDA_ARCH__ for conditional compilation. However, this macro only works on device code, which might not meet our requirements.

@BBuf BBuf merged commit 0368ddf into sgl-project:main Jan 29, 2026
237 of 266 checks passed
charlesHsuGG pushed a commit to charlesHsuGG/sglang that referenced this pull request Jan 30, 2026
Chen-0210 pushed a commit to Chen-0210/sglang that referenced this pull request Jan 30, 2026
sfiisf pushed a commit to sfiisf/sglang that referenced this pull request Feb 5, 2026
Johnsonms pushed a commit to Johnsonms/sglang that referenced this pull request Feb 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants