Skip to content

Support MX4 E3M0 format and add stochastic rounding #477

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

Closed
wants to merge 19 commits into from

Conversation

NicoleMayer
Copy link

No description provided.

Copy link

pytorch-bot bot commented Jul 4, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/477

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 4, 2024
@msaroufim msaroufim requested a review from vkuzo July 4, 2024 17:36
@@ -21,6 +21,8 @@

from torchao.prototype.mx_formats.constants import (
DTYPE_FP4,
DTYPE_FP4_E2M1,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all the changes in this file, can you rebase past #363 ?

and in the code after that PR, perhaps we can add stochastic rounding option to _f32_to_fpx_unpacked?

for rounding mode, how about something like this instead of a boolean?

class RoundingMode(enum.Enum):
    TIE_TO_EVEN = auto()  # default
    STOCHASTIC = auto()  # added in this PR

def foo(..., rounding_mode=RoundingMode.TIE_TO_EVEN, ...): ...

@pytest.mark.parametrize("device", ["cuda", "cpu"])
@pytest.mark.parametrize("sign", [1, -1])
@pytest.mark.parametrize("use_stochastic_rounding", [False, True])
def test_overflow_cast(hp_dtype, device, sign, use_stochastic_rounding):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add these tests to test/prototype/mx_formats/test_custom_cast.py to keep the testing of MX numerics in one place?

@vkuzo
Copy link
Contributor

vkuzo commented Jul 5, 2024

thanks for adding this! left some comments, mostly on rebasing past https://github.com/pytorch/ao/pull/363/files and code style

Copy link

@summerdengfb summerdengfb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The E3M0 numerics implementation looks good to me.

denormal_x = denormal_x.view(torch.float)

# adjust the denormal values back
denormal_x -= min_normal

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SR code up to this line looks good to me.

@NicoleMayer NicoleMayer force-pushed the hanmei-e3m0-impl branch 3 times, most recently from 57165ff to 60fe4c3 Compare July 10, 2024 00:03
@NicoleMayer NicoleMayer deleted the hanmei-e3m0-impl branch July 17, 2024 06:16
@NicoleMayer NicoleMayer restored the hanmei-e3m0-impl branch July 17, 2024 06:16
yanbing-j pushed a commit to yanbing-j/ao that referenced this pull request Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants