-
Notifications
You must be signed in to change notification settings - Fork 641
[PyTorch] Add dtype information to QuantizedTensorStorage class #2676
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
ptrendx
wants to merge
4
commits into
NVIDIA:main
Choose a base branch
from
ptrendx:pr_dtype_in_storage
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.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -75,14 +75,16 @@ def __new__( | |||||
| data: Optional[torch.Tensor], | ||||||
| fp8_scale_inv: torch.Tensor, | ||||||
| fp8_dtype: TE_DType, | ||||||
| fake_dtype: Optional[torch.dtype] = 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. I'd prefer to just name it
Suggested change
|
||||||
| data_transpose: Optional[torch.Tensor] = None, | ||||||
| quantizer: Optional[Quantizer] = None, | ||||||
| **kwargs, | ||||||
| ): | ||||||
| if cls is Float8TensorStorage: | ||||||
| instance = object.__new__(cls) | ||||||
| instance._dtype = fake_dtype if fake_dtype is not None else torch.float32 | ||||||
| else: | ||||||
| instance = super().__new__(cls, *args, **kwargs) | ||||||
| instance = super().__new__(cls, *args, fake_dtype=fake_dtype, **kwargs) | ||||||
| instance._data = data | ||||||
| instance._quantizer = quantizer.copy() if quantizer is not None else None | ||||||
| instance._fp8_dtype = fp8_dtype | ||||||
|
|
@@ -112,6 +114,7 @@ def get_metadata(self) -> Dict[str, Any]: | |||||
| "fp8_dtype": self._fp8_dtype, | ||||||
| "data_transpose": self._transpose, | ||||||
| "quantizer": self._quantizer, | ||||||
| "fake_dtype": self._dtype, | ||||||
| } | ||||||
|
|
||||||
| def prepare_for_saving(self) -> Tuple[list[Optional[torch.Tensor]], QuantizedTensorStorage]: | ||||||
|
|
@@ -141,8 +144,10 @@ def get_data_tensors(self, rowwise_data: bool = True, columnwise_data: bool = Tr | |||||
| return self._transpose | ||||||
| raise ValueError("No data to get, both rowwise_data and columnwise_data are False") | ||||||
|
|
||||||
| def dequantize(self, *, dtype: torch.dtype = torch.float32) -> torch.Tensor: | ||||||
| def dequantize(self, *, dtype: Optional[torch.dtype] = None) -> torch.Tensor: | ||||||
| """Dequantize to a higher precision.""" | ||||||
| if dtype is None: | ||||||
| dtype = self._dtype | ||||||
| return _FromFloat8Func.forward(None, self, dtype) | ||||||
|
|
||||||
| def size(self, *args, **kwargs): | ||||||
|
|
@@ -165,6 +170,7 @@ def view(self, shape: torch.Size): | |||||
| data=out_data, | ||||||
| fp8_scale_inv=self._scale_inv, | ||||||
| fp8_dtype=self._fp8_dtype, | ||||||
| fake_dtype=self._dtype, | ||||||
| data_transpose=out_transpose, | ||||||
| quantizer=self._quantizer, | ||||||
| ) | ||||||
|
|
||||||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this redundant with the
dtypekwarg?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is mostly to avoid issues with MRO and still have fairly straightforward constructors for the Storage classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also just noticed that the make_like call would be problematic there otherwise - we want to include the fake_dtype in get_metadata call, but if it was named dtype it would clash with the dtype that we pass directly in make_like.