-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
[feat]: add SM100 support for cutlass FP8 groupGEMM #20447
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
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
1eacd3d
[feat]: add SM100 support for cutlass groupGEMM
djmmoss 32a7d21
remove redundant checks
djmmoss f0d819b
separate sm90 and sm100 _is_fp8_w8a8
djmmoss 3ae294b
further updates
djmmoss a7ac882
nit buster
djmmoss 271fbad
add version_num check to cutlass_moe_mm function
djmmoss af06e98
add cutlass tuning
jiahanc d221ffd
update swap AB
jiahanc 7bdae95
update shape
jiahanc b9a5763
fix swapAB
jiahanc c403a57
fall back logic
jiahanc 2de546c
rebase and fix
jiahanc de8ac9e
fix
jiahanc d789068
lint
jiahanc 457ddf9
add comemnt and fix logic
jiahanc 9c7e286
fix
jiahanc f2f12c8
Merge branch 'main' into dmoss/group_gemm_sm100
mgoin 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
140 changes: 140 additions & 0 deletions
140
csrc/quantization/cutlass_w8a8/moe/grouped_mm_c3x_sm100.cu
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,140 @@ | ||
| #include <cudaTypedefs.h> | ||
|
|
||
| #include <c10/cuda/CUDAGuard.h> | ||
| #include <torch/all.h> | ||
|
|
||
| #include "cutlass/cutlass.h" | ||
| #include "grouped_mm_c3x.cuh" | ||
|
|
||
| using namespace cute; | ||
|
|
||
| namespace { | ||
|
|
||
| template <typename InType, typename OutType, | ||
| template <typename, typename, typename> typename Epilogue> | ||
| struct sm100_fp8_config_default { | ||
| static_assert(std::is_same<InType, cutlass::float_e4m3_t>()); | ||
| using KernelSchedule = | ||
| cutlass::gemm::KernelPtrArrayTmaWarpSpecialized1SmSm100; | ||
| using EpilogueSchedule = cutlass::epilogue::PtrArrayTmaWarpSpecialized1Sm; | ||
| using TileShape = cute::Shape<cute::_128, cute::_256, cute::_128>; | ||
| using ClusterShape = cute::Shape<cute::_1, cute::_1, cute::_1>; | ||
| using ArchTag = cutlass::arch::Sm100; | ||
|
|
||
| using Cutlass3xGemm = | ||
| cutlass_3x_group_gemm<InType, OutType, ArchTag, Epilogue, TileShape, | ||
| ClusterShape, KernelSchedule, EpilogueSchedule>; | ||
| }; | ||
|
|
||
| template <typename InType, typename OutType, | ||
| template <typename, typename, typename> typename Epilogue> | ||
| struct sm100_fp8_config_M64 { | ||
| // M in [1,64] | ||
| static_assert(std::is_same<InType, cutlass::float_e4m3_t>()); | ||
| using KernelSchedule = | ||
| cutlass::gemm::KernelPtrArrayTmaWarpSpecialized1SmSm100; | ||
| using EpilogueSchedule = cutlass::epilogue::PtrArrayTmaWarpSpecialized1Sm; | ||
| using TileShape = cute::Shape<cute::_128, cute::_16, cute::_128>; | ||
| using ClusterShape = cute::Shape<cute::_1, cute::_1, cute::_1>; | ||
| using ArchTag = cutlass::arch::Sm100; | ||
|
|
||
| using Cutlass3xGemm = | ||
| cutlass_3x_group_gemm<InType, OutType, ArchTag, Epilogue, TileShape, | ||
| ClusterShape, KernelSchedule, EpilogueSchedule, | ||
| true>; | ||
| }; | ||
|
|
||
| template <typename InType, typename OutType, | ||
| template <typename, typename, typename> typename Epilogue> | ||
| struct sm100_fp8_config_N8192 { | ||
| // N in [8192, inf) | ||
| static_assert(std::is_same<InType, cutlass::float_e4m3_t>()); | ||
| using KernelSchedule = | ||
| cutlass::gemm::KernelPtrArrayTmaWarpSpecialized2SmSm100; | ||
| using EpilogueSchedule = cutlass::epilogue::PtrArrayTmaWarpSpecialized2Sm; | ||
| using TileShape = cute::Shape<cute::_128, cute::_256, cute::_128>; | ||
| using ClusterShape = cute::Shape<cute::_2, cute::_1, cute::_1>; | ||
| using ArchTag = cutlass::arch::Sm100; | ||
|
|
||
| using Cutlass3xGemm = | ||
| cutlass_3x_group_gemm<InType, OutType, ArchTag, Epilogue, TileShape, | ||
| ClusterShape, KernelSchedule, EpilogueSchedule>; | ||
| }; | ||
|
|
||
| template <typename InType, typename OutType> | ||
| void run_cutlass_moe_mm_sm100( | ||
| torch::Tensor& out_tensors, torch::Tensor const& a_tensors, | ||
| torch::Tensor const& b_tensors, torch::Tensor const& a_scales, | ||
| torch::Tensor const& b_scales, torch::Tensor const& expert_offsets, | ||
| torch::Tensor const& problem_sizes, torch::Tensor const& a_strides, | ||
| torch::Tensor const& b_strides, torch::Tensor const& c_strides, | ||
| bool per_act_token, bool per_out_ch) { | ||
| TORCH_CHECK(a_tensors.size(0) > 0, "No input A tensors provided."); | ||
| TORCH_CHECK(b_tensors.size(0) > 0, "No input B tensors provided."); | ||
| TORCH_CHECK(out_tensors.size(0) > 0, "No output tensors provided."); | ||
|
|
||
| TORCH_CHECK(a_tensors.dtype() == torch::kFloat8_e4m3fn, | ||
| "A tensors must be of type float8_e4m3fn."); | ||
| TORCH_CHECK(b_tensors.dtype() == torch::kFloat8_e4m3fn, | ||
| "B tensors must be of type float8_e4m3fn."); | ||
|
|
||
| using Cutlass3xGemmDefault = typename sm100_fp8_config_default< | ||
| InType, OutType, vllm::c3x::ScaledEpilogueArray>::Cutlass3xGemm; | ||
| using Cutlass3xGemmN8192 = typename sm100_fp8_config_N8192< | ||
| InType, OutType, vllm::c3x::ScaledEpilogueArray>::Cutlass3xGemm; | ||
| using Cutlass3xGemmM64 = typename sm100_fp8_config_M64< | ||
| InType, OutType, vllm::c3x::ScaledEpilogueArray>::Cutlass3xGemm; | ||
|
|
||
| uint32_t const m = a_tensors.size(0); | ||
| uint32_t const n = out_tensors.size(1); | ||
|
|
||
| if (m <= 64) { | ||
| cutlass_group_gemm_caller<Cutlass3xGemmM64>( | ||
| out_tensors, a_tensors, b_tensors, a_scales, b_scales, expert_offsets, | ||
| problem_sizes, a_strides, b_strides, c_strides, per_act_token, | ||
| per_out_ch); | ||
| } else if (n >= 8192) { | ||
| cutlass_group_gemm_caller<Cutlass3xGemmN8192>( | ||
| out_tensors, a_tensors, b_tensors, a_scales, b_scales, expert_offsets, | ||
| problem_sizes, a_strides, b_strides, c_strides, per_act_token, | ||
| per_out_ch); | ||
| } else { | ||
| cutlass_group_gemm_caller<Cutlass3xGemmDefault>( | ||
| out_tensors, a_tensors, b_tensors, a_scales, b_scales, expert_offsets, | ||
| problem_sizes, a_strides, b_strides, c_strides, per_act_token, | ||
| per_out_ch); | ||
| } | ||
| } | ||
| } // namespace | ||
|
|
||
| void dispatch_moe_mm_sm100( | ||
| torch::Tensor& out_tensors, torch::Tensor const& a_tensors, | ||
| torch::Tensor const& b_tensors, torch::Tensor const& a_scales, | ||
| torch::Tensor const& b_scales, torch::Tensor const& expert_offsets, | ||
| torch::Tensor const& problem_sizes, torch::Tensor const& a_strides, | ||
| torch::Tensor const& b_strides, torch::Tensor const& c_strides, | ||
| bool per_act_token, bool per_out_ch) { | ||
| if (out_tensors.dtype() == torch::kBFloat16) { | ||
| run_cutlass_moe_mm_sm100<cutlass::float_e4m3_t, cutlass::bfloat16_t>( | ||
| out_tensors, a_tensors, b_tensors, a_scales, b_scales, expert_offsets, | ||
| problem_sizes, a_strides, b_strides, c_strides, per_act_token, | ||
| per_out_ch); | ||
| } else { | ||
| run_cutlass_moe_mm_sm100<cutlass::float_e4m3_t, cutlass::half_t>( | ||
| out_tensors, a_tensors, b_tensors, a_scales, b_scales, expert_offsets, | ||
| problem_sizes, a_strides, b_strides, c_strides, per_act_token, | ||
| per_out_ch); | ||
| } | ||
| } | ||
|
|
||
| void cutlass_moe_mm_sm100( | ||
| torch::Tensor& out_tensors, torch::Tensor const& a_tensors, | ||
| torch::Tensor const& b_tensors, torch::Tensor const& a_scales, | ||
| torch::Tensor const& b_scales, torch::Tensor const& expert_offsets, | ||
| torch::Tensor const& problem_sizes, torch::Tensor const& a_strides, | ||
| torch::Tensor const& b_strides, torch::Tensor const& c_strides, | ||
| bool per_act_token, bool per_out_ch) { | ||
| dispatch_moe_mm_sm100(out_tensors, a_tensors, b_tensors, a_scales, b_scales, | ||
| expert_offsets, problem_sizes, a_strides, b_strides, | ||
| c_strides, per_act_token, per_out_ch); | ||
| } |
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.
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.