-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[Feat] Add RMSNorm NvFp4 Quant Operator (#32612) #32957
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
Open
sparkecho
wants to merge
14
commits into
vllm-project:main
Choose a base branch
from
sparkecho:feature/rmsnorm-fp4quant
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
106e7c7
[Feat] Add RMSNorm NvFp4 Quant Operator (#32612)
sparkecho 82200fe
fix wrong QuantKey usage
sparkecho 43cebd7
fix hardcoded bf16 dtype (cursor cr)
sparkecho 3dffb27
refact file org of rms cuda kernel and utils
sparkecho 97af2ba
fix redefinition error
sparkecho bd9254b
fix precision loss in bfloat16
sparkecho e3cb02f
add rmsnorm fp4 quant fusion unit test
sparkecho aa96900
fix code format
sparkecho 50b23a5
add FusedAddRMSNormNvfp4QuantPattern to optimize perf
sparkecho 25f8231
fix pattern match
sparkecho 31541e3
add fusion test for fused add rmsnorm nvfp4 quant
sparkecho 8b5501f
refact code to reduce duplication
sparkecho d3fa2f8
fix cr and optimize perf on small batch
sparkecho fe28ddd
add micro benchmarks for rmsnorm fp4
sparkecho 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| #pragma once | ||
|
|
||
| #include <cuda_fp16.h> | ||
| #include <cuda_bf16.h> | ||
| #include <cuda_fp8.h> | ||
| #include <ATen/cuda/CUDAContext.h> | ||
|
|
||
| // Conditional compilation for FP4 element packing size | ||
| #if (defined(NVFP4_ENABLE_ELTS16) && (CUDART_VERSION >= 12090) && \ | ||
| defined(ENABLE_NVFP4_SM100) && ENABLE_NVFP4_SM100) | ||
| #define ELTS_PER_THREAD 16 | ||
| constexpr int CVT_FP4_ELTS_PER_THREAD = 16; | ||
| constexpr bool CVT_FP4_PACK16 = true; | ||
| #else | ||
| #define ELTS_PER_THREAD 8 | ||
| constexpr int CVT_FP4_ELTS_PER_THREAD = 8; | ||
| constexpr bool CVT_FP4_PACK16 = false; | ||
| #endif | ||
|
|
||
| constexpr int CVT_FP4_SF_VEC_SIZE = 16; | ||
|
|
||
| namespace vllm { | ||
|
|
||
| // Convert PyTorch cpp type to CUDA type | ||
| template <typename T> | ||
| struct CUDATypeConverter { | ||
| using Type = T; | ||
| }; | ||
|
|
||
| template <> | ||
| struct CUDATypeConverter<at::Half> { | ||
| using Type = half; | ||
| }; | ||
|
|
||
| template <> | ||
| struct CUDATypeConverter<at::BFloat16> { | ||
| using Type = __nv_bfloat16; | ||
| }; | ||
|
|
||
| // Get type2 from type or vice versa (half <-> half2, bfloat16 <-> bfloat162) | ||
| template <typename T> | ||
| struct TypeConverter { | ||
| using Type = half2; | ||
| }; | ||
|
|
||
| template <> | ||
| struct TypeConverter<half2> { | ||
| using Type = half; | ||
| }; | ||
|
|
||
| template <> | ||
| struct TypeConverter<half> { | ||
| using Type = half2; | ||
| }; | ||
|
|
||
| template <> | ||
| struct TypeConverter<__nv_bfloat162> { | ||
| using Type = __nv_bfloat16; | ||
| }; | ||
|
|
||
| template <> | ||
| struct TypeConverter<__nv_bfloat16> { | ||
| using Type = __nv_bfloat162; | ||
| }; | ||
|
|
||
| #if (defined(NVFP4_ENABLE_ELTS16) && (CUDART_VERSION >= 12090) && \ | ||
| defined(ENABLE_NVFP4_SM100) && ENABLE_NVFP4_SM100) | ||
| // Define a 32 bytes packed data type. | ||
| template <class Type> | ||
| struct alignas(32) PackedVec { | ||
| typename TypeConverter<Type>::Type elts[8]; | ||
| }; | ||
| #else | ||
| // Define a 16 bytes packed data type. | ||
| template <class Type> | ||
| struct alignas(16) PackedVec { | ||
| typename TypeConverter<Type>::Type elts[4]; | ||
| }; | ||
| #endif | ||
|
|
||
| template <> | ||
| struct PackedVec<__nv_fp8_e4m3> { | ||
| __nv_fp8x2_e4m3 elts[8]; | ||
| }; | ||
|
|
||
| } // namespace vllm | ||
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.