-
Notifications
You must be signed in to change notification settings - Fork 217
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
MX: move block_size and elem_dtype into MXLinearConfig #1689
Merged
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c834520
Update
vkuzo 85da297
Update
vkuzo 0d3d6f9
Update
vkuzo 82b543d
Update
vkuzo 0220b19
Update
vkuzo e4b5ded
Update
vkuzo 7c1166e
Update
vkuzo 8819b28
Update
vkuzo 1064e83
Update
vkuzo e596007
Update
vkuzo d49b604
Update
vkuzo 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 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 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 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 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 |
---|---|---|
@@ -1,2 +1,44 @@ | ||
# If True, uses a custom triton kernel for fp4 dequantize | ||
use_fp4_custom_triton_dequant_kernel = False | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
|
||
# This source code is licensed under the license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from dataclasses import dataclass | ||
from typing import Any, Optional | ||
|
||
import torch | ||
|
||
from torchao.prototype.mx_formats.constants import SUPPORTED_ELEM_DTYPES | ||
|
||
|
||
@dataclass | ||
class MXLinearConfig: | ||
# block size for scaling, default is 32 to match | ||
# https://www.opencompute.org/documents/ocp-microscaling-formats-mx-v1-0-spec-final-pdf, | ||
# section 5.2 | ||
block_size: int = 32 | ||
|
||
# element dtype, used for activations, weights and gradients | ||
elem_dtype: Any = torch.float8_e4m3fn | ||
|
||
# overrides for element dtype for weights and gradients | ||
# TODO(future PR): refactor to make this cleaner | ||
elem_dtype_weight_override: Optional[Any] = None | ||
elem_dtype_grad_output_override: Optional[Any] = None | ||
|
||
# If True, uses a custom triton kernel for fp4 dequantize | ||
use_fp4_custom_triton_dequant_kernel: bool = False | ||
|
||
def __post_init__(self): | ||
assert ( | ||
self.elem_dtype in SUPPORTED_ELEM_DTYPES | ||
), f"elem_dtype: expected one of {SUPPORTED_ELEM_DTYPES}, got {self.elem_dtype}" | ||
if self.elem_dtype_weight_override is not None: | ||
assert ( | ||
self.elem_dtype_weight_override in SUPPORTED_ELEM_DTYPES | ||
), f"elem_dtype_weight_override: expected one of {SUPPORTED_ELEM_DTYPES}, got {self.elem_dtype}" | ||
if self.elem_dtype_grad_output_override is not None: | ||
assert ( | ||
self.elem_dtype_grad_output_override in SUPPORTED_ELEM_DTYPES | ||
), f"elem_dtype_grad_output_override: expected one of {SUPPORTED_ELEM_DTYPES}, got {self.elem_dtype}" |
Oops, something went wrong.
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.
you think that we will want to keep this public?
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.
unlikely, but IMO we can punt that until later