Skip to content

make NVFP4Tensor handle per-expert outer scale#4315

Merged
vkuzo merged 27 commits intomainfrom
gh/vkuzo/253/head
Apr 23, 2026
Merged

make NVFP4Tensor handle per-expert outer scale#4315
vkuzo merged 27 commits intomainfrom
gh/vkuzo/253/head

Conversation

@vkuzo
Copy link
Copy Markdown
Contributor

@vkuzo vkuzo commented Apr 22, 2026

Summary:

NVFP4 MoE kernels usually do per-expert outer scale.
This PR extends NVFP4Tensor to support this.

Test Plan:

pytest test/prototype/mx_formats/test_nvfp4_tensor.py -s

vkuzo added 20 commits April 20, 2026 20:52
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@vkuzo
Copy link
Copy Markdown
Contributor Author

vkuzo commented Apr 22, 2026

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 22, 2026

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 New Failure

As of commit be9dc1b with merge base 0c8f44b (image):

NEW FAILURE - The following job has failed:

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

@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 Apr 22, 2026
@vkuzo vkuzo added the module: not user facing Use this tag if you don't want this PR to show up in release notes label Apr 22, 2026

def get_hp_scales(self) -> torch.Tensor:
"""Get the scales of the NVFP4Tensor in original dtype.
"""Get the scales of the NVFP4Tensor in float32.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not for this PR: I just checked the usage of self._orig_dtype seems it's duplicated with self.dtype now

Copy link
Copy Markdown
Contributor

@jerryzh168 jerryzh168 left a comment

Choose a reason for hiding this comment

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

would be good to add a comment for attribute per_tensor_scale for NVFP4Tensor I think, also probably try to restrict this to weight only since it doesn't apply to activations?

vkuzo added 6 commits April 23, 2026 09:23
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@vkuzo vkuzo changed the base branch from gh/vkuzo/252/head to main April 23, 2026 09:25
[ghstack-poisoned]
@vkuzo
Copy link
Copy Markdown
Contributor Author

vkuzo commented Apr 23, 2026

would be good to add a comment for attribute per_tensor_scale for NVFP4Tensor I think

sure, fixed!

also probably try to restrict this to weight only since it doesn't apply to activations?

it could apply to activations (per-token-group)

@vkuzo vkuzo merged commit bfa7a94 into main Apr 23, 2026
54 of 57 checks passed
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. module: not user facing Use this tag if you don't want this PR to show up in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants