-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
[NVIDIA] Support Cutlass w8a8 FP8 for Blackwell Geforce GPUs (sm120) #17280
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
4 commits
Select commit
Hold shift + click to select a range
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,24 @@ | ||
#include "scaled_mm_kernels.hpp" | ||
#include "scaled_mm_sm120_fp8_dispatch.cuh" | ||
#include "cutlass_extensions/epilogue/scaled_mm_epilogues_c3x.hpp" | ||
|
||
namespace vllm { | ||
|
||
void cutlass_scaled_mm_sm120_fp8(torch::Tensor& out, torch::Tensor const& a, | ||
torch::Tensor const& b, | ||
torch::Tensor const& a_scales, | ||
torch::Tensor const& b_scales, | ||
std::optional<torch::Tensor> const& bias) { | ||
TORCH_CHECK(a_scales.is_contiguous() && b_scales.is_contiguous()); | ||
if (bias) { | ||
TORCH_CHECK(bias->dtype() == out.dtype(), | ||
"currently bias dtype must match output dtype ", out.dtype()); | ||
return cutlass_scaled_mm_sm120_fp8_epilogue<c3x::ScaledEpilogueBias>( | ||
out, a, b, a_scales, b_scales, *bias); | ||
} else { | ||
return cutlass_scaled_mm_sm120_fp8_epilogue<c3x::ScaledEpilogue>( | ||
out, a, b, a_scales, b_scales); | ||
} | ||
} | ||
|
||
} // namespace vllm |
67 changes: 67 additions & 0 deletions
67
csrc/quantization/cutlass_w8a8/c3x/scaled_mm_sm120_fp8_dispatch.cuh
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,67 @@ | ||
#pragma once | ||
|
||
#include "scaled_mm.cuh" | ||
#include "cutlass_gemm_caller.cuh" | ||
|
||
/** | ||
* This file defines Gemm kernel configurations for SM120 (fp8) based on the | ||
* Gemm shape. | ||
*/ | ||
|
||
namespace vllm { | ||
|
||
using c3x::cutlass_gemm_caller; | ||
|
||
template <typename InType, typename OutType, | ||
template <typename, typename, typename> typename Epilogue> | ||
struct sm120_fp8_config_default { | ||
static_assert(std::is_same<InType, cutlass::float_e4m3_t>()); | ||
using KernelSchedule = cutlass::gemm::collective::KernelScheduleAuto; | ||
using EpilogueSchedule = cutlass::epilogue::collective::EpilogueScheduleAuto; | ||
using TileShape = Shape<_128, _128, _128>; | ||
using ClusterShape = Shape<_1, _1, _1>; // Only work with Shape<_1, _1, _1> | ||
using Cutlass3xGemm = | ||
cutlass_3x_gemm_sm120<InType, OutType, Epilogue, TileShape, ClusterShape, | ||
KernelSchedule, EpilogueSchedule>; | ||
}; | ||
|
||
template <typename InType, typename OutType, | ||
template <typename, typename, typename> typename Epilogue, | ||
typename... EpilogueArgs> | ||
inline void cutlass_gemm_sm120_fp8_dispatch(torch::Tensor& out, | ||
torch::Tensor const& a, | ||
torch::Tensor const& b, | ||
EpilogueArgs&&... args) { | ||
static_assert(std::is_same<InType, cutlass::float_e4m3_t>()); | ||
TORCH_CHECK(a.dtype() == torch::kFloat8_e4m3fn); | ||
TORCH_CHECK(b.dtype() == torch::kFloat8_e4m3fn); | ||
|
||
using Cutlass3xGemmDefault = | ||
typename sm120_fp8_config_default<InType, OutType, | ||
Epilogue>::Cutlass3xGemm; | ||
return cutlass_gemm_caller<Cutlass3xGemmDefault>( | ||
out, a, b, std::forward<EpilogueArgs>(args)...); | ||
} | ||
|
||
template <template <typename, typename, typename> typename Epilogue, | ||
typename... EpilogueArgs> | ||
void cutlass_scaled_mm_sm120_fp8_epilogue(torch::Tensor& out, | ||
torch::Tensor const& a, | ||
torch::Tensor const& b, | ||
EpilogueArgs&&... epilogue_args) { | ||
TORCH_CHECK(a.dtype() == torch::kFloat8_e4m3fn); | ||
TORCH_CHECK(b.dtype() == torch::kFloat8_e4m3fn); | ||
|
||
if (out.dtype() == torch::kBFloat16) { | ||
return cutlass_gemm_sm120_fp8_dispatch<cutlass::float_e4m3_t, | ||
cutlass::bfloat16_t, Epilogue>( | ||
out, a, b, std::forward<EpilogueArgs>(epilogue_args)...); | ||
} else { | ||
TORCH_CHECK(out.dtype() == torch::kFloat16); | ||
return cutlass_gemm_sm120_fp8_dispatch<cutlass::float_e4m3_t, | ||
cutlass::half_t, Epilogue>( | ||
out, a, b, std::forward<EpilogueArgs>(epilogue_args)...); | ||
} | ||
} | ||
|
||
} // namespace vllm |
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,34 @@ | ||
#include <cudaTypedefs.h> | ||
#include "c3x/scaled_mm_kernels.hpp" | ||
|
||
#include "cuda_utils.h" | ||
|
||
/* | ||
This file defines quantized GEMM operations using the CUTLASS 3.x API, for | ||
NVIDIA GPUs with sm120 (Blackwell Geforce). | ||
*/ | ||
|
||
#if defined ENABLE_SCALED_MM_SM120 && ENABLE_SCALED_MM_SM120 | ||
|
||
void cutlass_scaled_mm_sm120(torch::Tensor& c, torch::Tensor const& a, | ||
torch::Tensor const& b, | ||
torch::Tensor const& a_scales, | ||
torch::Tensor const& b_scales, | ||
std::optional<torch::Tensor> const& bias) { | ||
TORCH_CHECK(a_scales.dtype() == torch::kFloat32); | ||
TORCH_CHECK(b_scales.dtype() == torch::kFloat32); | ||
|
||
int M = a.size(0), N = b.size(1), K = a.size(1); | ||
TORCH_CHECK( | ||
(a_scales.numel() == 1 || a_scales.numel() == a.size(0)) && | ||
(b_scales.numel() == 1 || b_scales.numel() == b.size(1)), | ||
"Currently, block scaled fp8 gemm is not implemented for Blackwell"); | ||
|
||
// Standard per-tensor/per-token/per-channel scaling | ||
TORCH_CHECK(a_scales.is_contiguous() && b_scales.is_contiguous()); | ||
TORCH_CHECK(a.dtype() == torch::kFloat8_e4m3fn, | ||
"Currently, only fp8 gemm is implemented for Blackwell"); | ||
vllm::cutlass_scaled_mm_sm120_fp8(c, a, b, a_scales, b_scales, bias); | ||
} | ||
|
||
#endif |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copy from the top one. If you think that's incorrect you can delete it.