[PyTorch] Float8Tensor uses cached transpose if available#524
Closed
timmoon10 wants to merge 5 commits intoNVIDIA:mainfrom
Closed
[PyTorch] Float8Tensor uses cached transpose if available#524timmoon10 wants to merge 5 commits intoNVIDIA:mainfrom
timmoon10 wants to merge 5 commits intoNVIDIA:mainfrom
Conversation
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Collaborator
Author
|
/te-ci pytorch |
8 tasks
ptrendx
reviewed
Nov 20, 2023
| transpose_dims: Tuple[int, int], | ||
| fp8_dtype: tex.DType = tex.DType.kFloat8E4M3, | ||
| scale: float = 1, | ||
| scale: float = 0.5, |
Collaborator
Author
There was a problem hiding this comment.
I thought there was a correctness issue that was hidden by scale=1, but I don't think it's actually an issue. Making this non-one does a better job stress-testing this in any case though.
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Collaborator
Author
|
/te-ci pytorch |
Collaborator
Author
|
Test failures are ONNX-related. This is ready to go. |
Collaborator
|
@timmoon10 |
Collaborator
Author
|
The work in this PR was merged in #529. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR changes the transpose behavior of
Float8Tensor:update_cache == True, it will compute the transpose and update the cacheupdate_cache == Falseand the cache is empty, it will compute the transposeupdate_cache == Falseand the cache is populated, it will return the cached transposeThis is somewhat of a kludge to support transpose caching with Megatron GPT (see NVIDIA-NeMo/NeMo#7909). Its
forwardfunction doesn't keep track of gradient accumulation steps, so it doesn't passis_first_microbatchtoLayerNormLinearorLinear. E.g.:https://github.com/NVIDIA/Megatron-LM/blob/9290c730d04b482be8fae92a4186fe4ff0c95270/megatron/core/transformer/attention.py#L271C31-L271C31
Compare to NeMo GPT, which contains TE-specific logic like
is_first_microbatch:https://github.com/NVIDIA/NeMo/blob/d81beac52423dbd04b48e4e04567b17df2428e3a/nemo/collections/nlp/modules/common/megatron/transformer.py#L1556
Discussion would be appreciated. This design ping-ponged a few times in #452, e.g. 00b9c31. This approach is convenient with an FP8-aware optimizer since the optimizer doesn't need any access to the TE modules, just the FP8 params. There are also some alternative approaches:
is_first_microbatch, to keep the current API