-
-
Notifications
You must be signed in to change notification settings - Fork 20.4k
[Kernel] Switch fp8 layers to use the CUTLASS kernels #5183
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
Changes from 1 commit
b6809fa
2e93b71
33085d9
43e5bd1
81f5372
1fe0468
2d77ca5
a1ffa09
e894b21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,27 +233,43 @@ def apply(self, | |
| layer: torch.nn.Module, | ||
| x: torch.Tensor, | ||
| bias: Optional[torch.Tensor] = None) -> torch.Tensor: | ||
|
|
||
| # ops.scaled_fp8_quant supports both dynamic and static quant. | ||
| # If dynamic, layer.act_scale is None and x_scale computed from x. | ||
| # If static, layer.act_scale is scalar and x_scale set to act_scale. | ||
| qinput, x_scale = ops.scaled_fp8_quant(x, | ||
| layer.act_scale, | ||
| batch_dim_padding=17) | ||
|
|
||
| # Fused GEMM_DQ -- note we padded the input above because | ||
| # torch._scaled_mm is more performant for matrices with | ||
| # batch dimension > 16. Note that this could change | ||
| # in the future. | ||
| output, _ = torch._scaled_mm( | ||
| qinput, | ||
| layer.weight, | ||
| out_dtype=x.dtype, | ||
| scale_a=x_scale, | ||
| scale_b=layer.weight_scale, | ||
| bias=bias, | ||
| ) | ||
|
|
||
| return torch.narrow(output, 0, 0, x.shape[0]) | ||
|
|
||
| # We use the CUTLASS kernels by default but they don't support bias yet | ||
| if bias is None: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we also do a branch if we are on ada lovelace and CUDA 12.1?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will need to if on CUDA < 12.4. We also need a branch if on CUDA 11.8. @comaniac do you know if
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only know that it only supports SM89+. We can try to call this op with torch+cu118 to test out.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cutlass kernels need at least SM89 as well, for the record.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah that makes sense. Older architectures don't have native FP8 so we can't get speedup from them, which seems not necessary to be covered.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: we already have a mechanism for determining if a |
||
| qinput, x_scale = ops.scaled_fp8_quant(x, layer.act_scale) | ||
|
|
||
| # Fused GEMM_DQ | ||
| output = ops.cutlass_scaled_mm_dq( | ||
| qinput, | ||
| layer.weight, | ||
| out_dtype=x.dtype, | ||
| scale_a=x_scale, | ||
| scale_b=layer.weight_scale, | ||
| ) | ||
|
|
||
| else: | ||
| qinput, x_scale = ops.scaled_fp8_quant(x, | ||
| layer.act_scale, | ||
| batch_dim_padding=17) | ||
|
|
||
| # Fused GEMM_DQ -- note we padded the input above because | ||
| # torch._scaled_mm is more performant for matrices with | ||
| # batch dimension > 16. Note that this could change | ||
| # in the future. | ||
| output, _ = torch._scaled_mm( | ||
| qinput, | ||
| layer.weight, | ||
| out_dtype=x.dtype, | ||
| scale_a=x_scale, | ||
| scale_b=layer.weight_scale, | ||
| bias=bias, | ||
| ) | ||
|
|
||
| return output | ||
|
tlrmchlsmth marked this conversation as resolved.
Outdated
|
||
|
|
||
|
|
||
| class Fp8KVCacheMethod(QuantizeMethodBase): | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.