-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[None][feat] Minimax RMS norm optimization #12163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
syuoni
merged 20 commits into
NVIDIA:main
from
jmydurant:user/mingyangj/minimax_opt_rebase
Apr 20, 2026
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
af779cc
draft: use all reduce for rms norm in attention module
jmydurant 24f495a
chore: use nccl as all reduce backend
jmydurant f9ef536
draft: add new reduce kernel file
jmydurant 462f882
chore: add pytorch wrapper
jmydurant 83c3503
test: add unit test case
jmydurant 5a32a80
fix: bug fix for unit test
jmydurant 49dec20
chore: support bf16 or fp16 as input tensor
jmydurant e934b06
chore: use origin dtype for input, just use fp32 acc in kernel
jmydurant 9e9d357
draft: add float4 kernel, add benchmark script
jmydurant 2eaa0e7
test: add benchmark code, fix clean lamport buffer bug
jmydurant 05885e7
feature: fuse q and k rms norm kernel
jmydurant 78e38cf
feature: q and k use different thread idx
jmydurant a610f72
test: add test case for qk norm, add range reduce func
jmydurant 55739c2
feature: modify float4 kernel, split q, k to different warp, enable pdl
jmydurant 212c46a
chore: modify rms norm weight loading method
jmydurant 76db2c3
fix: fix split tensor contiguous bug
jmydurant 5049a8e
chore: add more torch check for input shape
jmydurant 87020f2
fix: fix for code rabbit review comments
jmydurant 76be688
fix: add fake op impl
jmydurant d912d1c
fix: clean code by hyukn comments
jmydurant File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
885 changes: 885 additions & 0 deletions
885
cpp/tensorrt_llm/kernels/communicationKernels/MiniMaxReduceRMSKernel.cu
Large diffs are not rendered by default.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
cpp/tensorrt_llm/kernels/communicationKernels/MiniMaxReduceRMSKernel.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Copyright (c) 2026, NVIDIA CORPORATION. All rights reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| #pragma once | ||
| #include "tensorrt_llm/common/assert.h" | ||
| #include <NvInferRuntime.h> | ||
| #include <cuda_bf16.h> | ||
| #include <cuda_fp16.h> | ||
|
|
||
| #include "tensorrt_llm/common/config.h" | ||
| #include "tensorrt_llm/common/cudaUtils.h" | ||
| #include "tensorrt_llm/kernels/quantization.h" | ||
| #include "tensorrt_llm/runtime/ipcUtils.h" | ||
|
|
||
| TRTLLM_NAMESPACE_BEGIN | ||
|
|
||
| namespace kernels::minimax_ar | ||
| { | ||
| template <typename DType> | ||
| struct ElemsPerAccess; | ||
|
|
||
| template <> | ||
| struct ElemsPerAccess<half> | ||
| { | ||
| static constexpr int value = 8; | ||
| using norm_weight_type = common::__nv_bfloat168; | ||
| }; | ||
|
|
||
| template <> | ||
| struct ElemsPerAccess<nv_bfloat16> | ||
| { | ||
| static constexpr int value = 8; | ||
| using norm_weight_type = common::__nv_bfloat168; | ||
| }; | ||
|
|
||
| template <> | ||
| struct ElemsPerAccess<float> | ||
| { | ||
| static constexpr int value = 4; | ||
| using norm_weight_type = common::__nv_bfloat164; | ||
| }; | ||
|
|
||
| template <typename DType> | ||
| static constexpr int kElemsPerAccess = ElemsPerAccess<DType>::value; | ||
|
|
||
| struct MiniMaxReduceRMSParams | ||
| { | ||
| int nranks{}; | ||
| int rank{}; | ||
| nvinfer1::DataType dtype; | ||
| int size_q{}; // numel of Q (num_token * head_dim_q) | ||
| int hidden_dim{}; // head_dim_q | ||
| int size_k{}; // numel of K (num_token * head_dim_k) | ||
| int hidden_dim_k{}; // head_dim_k; must have head_dim_q >= head_dim_k | ||
| void** workspace{}; | ||
| void* allreduce_in{}; // Q input | ||
| void* rms_norm_out{}; // Q output | ||
| void* rms_gamma{}; // Q norm weight | ||
| void* allreduce_in_k{}; // K input (nullptr for single-matrix path) | ||
| void* rms_norm_out_k{}; // K output | ||
| void* rms_gamma_k{}; // K norm weight | ||
| float rms_eps{}; | ||
| cudaStream_t stream{}; | ||
| bool trigger_completion_at_end = true; | ||
| }; | ||
|
|
||
| void minimax_reduce_rms_op(MiniMaxReduceRMSParams const& params); | ||
|
|
||
| } // namespace kernels::minimax_ar | ||
|
|
||
| TRTLLM_NAMESPACE_END | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.