[JIT Kernel]Support fused_add_rmsnorm in JIT Kernel#17677
[JIT Kernel]Support fused_add_rmsnorm in JIT Kernel#17677BBuf merged 9 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello @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 Highlights
🧠 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 AssistThe 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
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 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
|
|
@BBuf @DarkSharpness WIP for now, I will add benchmarks within a few days. |
There was a problem hiding this comment.
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.
python/sglang/jit_kernel/csrc/elementwise/fused_add_rmsnorm.cuh
Outdated
Show resolved
Hide resolved
python/sglang/jit_kernel/csrc/elementwise/fused_add_rmsnorm.cuh
Outdated
Show resolved
Hide resolved
python/sglang/jit_kernel/csrc/elementwise/fused_add_rmsnorm.cuh
Outdated
Show resolved
Hide resolved
python/sglang/jit_kernel/csrc/elementwise/fused_add_rmsnorm.cuh
Outdated
Show resolved
Hide resolved
python/sglang/jit_kernel/csrc/elementwise/fused_add_rmsnorm.cuh
Outdated
Show resolved
Hide resolved
python/sglang/jit_kernel/csrc/elementwise/fused_add_rmsnorm.cuh
Outdated
Show resolved
Hide resolved
|
@DarkSharpness @BBuf Ready for review. |
|
/tag-and-rerun-ci |
|
/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"); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Motivation
There are two differences from the Flashinfer implementation:
Modifications
Accuracy Tests
H20(with CUDA 12.9):


B200(witch CUDA 13.1):
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
/tag-run-ci-label,/rerun-failed-ci,/tag-and-rerun-ci