Skip to content

fix(mxfp8): support triton cast with swizzled scales for mxfp8 training - #4961

Open
devtyagi3909 wants to merge 2 commits into
pytorch:mainfrom
devtyagi3909:fix-mxfp8-training-swizzle
Open

devtyagi3909 wants to merge 2 commits into
pytorch:mainfrom
devtyagi3909:fix-mxfp8-training-swizzle

Conversation

@devtyagi3909

Copy link
Copy Markdown

Fixes #4929

Description

The MXFP8 training path (torchao.prototype.moe_training) was breaking with torch >= 2.12 because its AUTO gemm produces unswizzled (row-major) scales, but torch's F.scaled_mm v2 MXFP8 path unconditionally requires SWIZZLE_32_4_4 scales on CUDA.

This implements the compositional fix suggested in the issue:

  1. Supports swizzled scale output in to_mx's TRITON branch by applying the triton_mx_block_rearrange swizzle kernel directly to the Triton cast output if is_swizzled_scales=True.
  2. Has moe_training request is_swizzled_scales=True in MXFP8Linear when calling MXTensor.to_mx.

This avoids the slow TORCH cast fallback by leveraging the fast Triton cast and then rearranging the scales for the required SWIZZLE_32_4_4 format.

@pytorch-bot

pytorch-bot Bot commented Sep 30, 2026

Copy link
Copy Markdown

🔗 Helpful Links

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

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.

@meta-cla

meta-cla Bot commented Sep 30, 2026

Copy link
Copy Markdown

Hi @devtyagi3909!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla meta-cla 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 Oct 1, 2026
@meta-cla

meta-cla Bot commented Oct 1, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

This branch has not been deployed

No deployments
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.

[mxfp8 training] mx_mm AUTO gemm broken with torch>=2.12: F.scaled_mm v2 requires SWIZZLE_32_4_4 scales

1 participant