-
Notifications
You must be signed in to change notification settings - Fork 434
[PyTorch] Add save_original_input in Linear/GroupedLinear to save memory #1865
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
Open
hxbai
wants to merge
5
commits into
NVIDIA:main
Choose a base branch
from
hxbai:save_bf16_in_fp8_gemm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com>
for more information, see https://pre-commit.ci
Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com>
Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com>
BestJuly
added a commit
to BestJuly/TransformerEngine
that referenced
this pull request
Jun 16, 2025
… memory NVIDIA#1865 Squashed commit of the following: commit 218046d Author: Hongxiao Bai <hongxiaob@nvidia.com> Date: Wed Jun 11 01:25:48 2025 -0700 refine the docstring Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com> commit 097d900 Author: Hongxiao Bai <hongxiaob@nvidia.com> Date: Wed Jun 11 00:43:35 2025 -0700 minor fix Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com> commit 90ade56 Author: Hongxiao Bai <hongxiaob@nvidia.com> Date: Wed Jun 11 00:37:09 2025 -0700 fix input_quantizer usage in Linear bwd Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com> commit aa4a01f Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed Jun 11 03:06:44 2025 +0000 [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci commit 406356f Author: Hongxiao Bai <hongxiaob@nvidia.com> Date: Tue Jun 10 18:58:01 2025 -0700 save original input Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com>
hxbai
added a commit
to hxbai/TransformerEngine
that referenced
this pull request
Jun 18, 2025
… memory NVIDIA#1865 Squashed commit of the following: commit 218046d Author: Hongxiao Bai <hongxiaob@nvidia.com> Date: Wed Jun 11 01:25:48 2025 -0700 refine the docstring Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com> commit 097d900 Author: Hongxiao Bai <hongxiaob@nvidia.com> Date: Wed Jun 11 00:43:35 2025 -0700 minor fix Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com> commit 90ade56 Author: Hongxiao Bai <hongxiaob@nvidia.com> Date: Wed Jun 11 00:37:09 2025 -0700 fix input_quantizer usage in Linear bwd Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com> commit aa4a01f Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed Jun 11 03:06:44 2025 +0000 [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci commit 406356f Author: Hongxiao Bai <hongxiaob@nvidia.com> Date: Tue Jun 10 18:58:01 2025 -0700 save original input Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com>
hxbai
added a commit
to BestJuly/TransformerEngine
that referenced
this pull request
Jun 18, 2025
… memory NVIDIA#1865 Squashed commit of the following: commit 218046d Author: Hongxiao Bai <hongxiaob@nvidia.com> Date: Wed Jun 11 01:25:48 2025 -0700 refine the docstring Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com> commit 097d900 Author: Hongxiao Bai <hongxiaob@nvidia.com> Date: Wed Jun 11 00:43:35 2025 -0700 minor fix Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com> commit 90ade56 Author: Hongxiao Bai <hongxiaob@nvidia.com> Date: Wed Jun 11 00:37:09 2025 -0700 fix input_quantizer usage in Linear bwd Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com> commit aa4a01f Author: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed Jun 11 03:06:44 2025 +0000 [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci commit 406356f Author: Hongxiao Bai <hongxiaob@nvidia.com> Date: Tue Jun 10 18:58:01 2025 -0700 save original input Signed-off-by: Hongxiao Bai <hongxiaob@nvidia.com>
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.
Description
Add save_original_input in Linear/GroupedLinear. If it is on, the modules save the original inputs and only do rowwise quant in forward and colwise quant in backward (for blockwise and mxfp8 recipe). With this, in some scenarios, we can save memory usage at the expense of separated quantizations.
In the current implementation, the Linear/GroupedLinear always saves the cast input tensors for backward.
But this may increase the memory usage if this input tensor is used by multiple modules, such as:
Besides, in Megatron-LM, we added an output-discarding recomputation that trickily releases some saved tensors and restores them by recomputation. This relies on that the saved tensor is the original output tensor.
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: