Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 814
Increase number of FP8 tensors per GEMM#22
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
95910d8
Increase number of FP8 tensors per GEMM
vasunvidia fcbce36
Enable FP8 output tensor for fp8_gemm
vasunvidia 8a336ab
[BERT FP8] Initial TE review comments
vasunvidia 320182a
Temporary fix for cuda graph non convergence
vasunvidia ffe4852
Address review comments-2
vasunvidia 075e287
Review comments-3
vasunvidia 784fb47
Cleanup
vasunvidia 0ccb2e5
Change for New API
vasunvidia 397a1e4
Remove unnecessary clone for D_scale, D_amax
vasunvidia a575b5e
Avoid Roll for AMAX history size = 1
vasunvidia 2dad360
Update onnx_te_gemm API
vasunvidia 66b98e3
Fix Lint errors
vasunvidia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -22,14 +22,19 @@ def fp8_gemm( | ||
| workspace: torch.Tensor, | ||
| accumulate: bool = False, | ||
| out: Optional[torch.Tensor] = None, | ||
| out_index = None, | ||
| fp8_meta_tensor: tex.FP8TensorMeta = None, | ||
| bias: Optional[torch.Tensor] = None, | ||
| use_bias: bool = False, | ||
| fp32_output: bool = False, | ||
| use_split_accumulator: bool = False, | ||
| D_dtype: tex.DType = None, | ||
| ) -> torch.Tensor: | ||
| """TN layout GEMM with fp8 inputs.""" | ||
| empty_tensor = torch.Tensor() | ||
| if D_dtype is not None and D_dtype in [tex.DType.kFloat8E4M3, tex.DType.kFloat8E5M2]: | ||
| assert fp8_meta_tensor is not None and out_index is not None | ||
| return_output = False | ||
| if out is None: | ||
| @@ -42,6 +47,9 @@ def fp8_gemm( | ||
| return_output = True | ||
| out_dtype = tex.DType.kFloat32 if fp32_output else TE_DType[out_dtype] | ||
vasunvidia marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| # Use bfloat16 as default bias_dtype | ||
| bias_dtype = tex.DType.kBFloat16 if bias is None else TE_DType[bias.dtype] | ||
| out_dtype = D_dtype if D_dtype is not None else out_dtype | ||
| _ = torch.ops.tex_ts.te_gemm_ts( | ||
| A, | ||
| @@ -55,8 +63,11 @@ def fp8_gemm( | ||
| B_dtype, | ||
| False, # transb | ||
| out, | ||
| empty_tensor if out_index is None else fp8_meta_tensor.scale[out_index], | ||
| out_dtype, | ||
| empty_tensor if out_index is None else fp8_meta_tensor.amax_history[0][out_index], | ||
| bias if use_bias else empty_tensor, | ||
| bias_dtype, | ||
| empty_tensor, # this is pre_gelu_out | ||
| False, # grad | ||
| workspace, | ||
| @@ -95,6 +106,7 @@ def gemm( | ||
| input_dtype = TE_DType[dtype] | ||
| output_dtype = tex.DType.kFloat32 if fp32_output else input_dtype | ||
| bias_dtype = output_dtype if bias is None else TE_DType[bias.dtype] | ||
| return_output = False | ||
| if out is None: | ||
| @@ -132,8 +144,11 @@ def gemm( | ||
| input_dtype, | ||
| transb, | ||
| out, | ||
| empty_tensor, # out_scale | ||
| output_dtype, | ||
| empty_tensor, # out_amax | ||
| grad_bias if grad else bias, | ||
| bias_dtype, | ||
| gelu_input, | ||
| grad, | ||
| workspace, | ||
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
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 |
|---|---|---|
| @@ -158,8 +158,10 @@ def __init__(self) -> None: | ||
| def set_meta_tensor(self, fwd: bool) -> None: | ||
| """Init scales and amaxes for fwd | bwd.""" | ||
| fp8_meta_tensor_key = "scaling_fwd" if fwd else "scaling_bwd" | ||
| # Max. number of fp8 tensors per GEMM = 3 (input, weight, output) for fwd and | ||
| # 2 (grad_output and grad_input) for bwd | ||
| num_fp8_tensors = ( | ||
| self.fp8_meta["num_gemms"] * 2 if fwd else self.fp8_meta["num_gemms"] | ||
| self.fp8_meta["num_gemms"] * 3 if fwd else self.fp8_meta["num_gemms"] * 2 | ||
vasunvidia marked this conversation as resolved.
Outdated
Uh oh!There was an error while loading. Please reload this page. | ||
| ) | ||
| self.fp8_meta[fp8_meta_tensor_key] = tex.FP8TensorMeta() | ||
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.
Uh oh!
There was an error while loading. Please reload this page.