[PyTorch] Inference mode disables initializing quantized weights with column-wise usage#1847
Merged
ksivaman merged 4 commits intoNVIDIA:mainfrom Jun 13, 2025
Merged
Conversation
…ce mode Signed-off-by: Tim Moon <tmoon@nvidia.com>
Signed-off-by: Tim Moon <tmoon@nvidia.com>
Collaborator
Author
|
/te-ci pytorch |
ksivaman
reviewed
Jun 9, 2025
| import pytest | ||
| import os | ||
|
|
||
| import transformer_engine.pytorch |
Collaborator
Author
There was a problem hiding this comment.
I find it convenient to be able to access a class without explicitly doing from ... import ...:
TransformerEngine/tests/pytorch/test_sanity.py
Line 1393 in 649b04c
It's just a matter of style though. Within the package we explicitly list the imports to order to guarantee only relative imports, but this isn't relevant for tests since we always do absolute imports. Also, Google's style guide recommends against it.
Co-authored-by: Kirthi Shankar Sivamani <ksivamani@nvidia.com> Signed-off-by: Tim Moon <4406448+timmoon10@users.noreply.github.com>
Collaborator
Author
|
/te-ci pytorch |
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.
Description
When initializing a model with quantized weights, the required data is different for training and inference (training requires row-wise data for forward GEMM and column-wise data for dgrad GEMM, inference only requires column-wise). This PR adds logic so the model will only initialize quantized weights with the data required for inference when initialized within no-grad mode or inference mode. It is also less aggressive about deallocating weight data in order to handle cases where we were alternating between training and validation modes.
This is an alternative to #1827. The heuristic API in that PR are somewhat redundant with these plain PyTorch APIs, but it is also more general.
Type of change
Changes
Checklist: