Skip to content

[moe training] fix uncoalesced global accesses in per group rowwise scaling kernel #2761

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

Draft
wants to merge 1 commit into
base: danielvegamyhre/stack/36
Choose a base branch
from

Conversation

danielvegamyhre
Copy link
Contributor

@danielvegamyhre danielvegamyhre commented Aug 13, 2025

Stacked PRs:


[moe training] fix uncoalesced global accesses in per group rowwise scaling kernel

Summary

  • NCU analysis showed uncoalesced global accesses in per-group rowwise scaling kernel, that occur when writing the output data. This is because the output tensor was in row major memory layout, as required for the LHS operator of the scaled grouped gemm kernel.
  • I did some testing and it turns out that when number of experts/groups is >= 64, it is actually faster to write to column major, then transform the output to row major afterwards. For smaller number of experts/groups, it's best to just write to row major and accept the uncoalesced writes.

Performance

Before:

input_shape      n_groups  high_precision_dtype      torch_time_us    triton_time_us  triton_speedup
-------------  ----------  ----------------------  ---------------  ----------------  ----------------
(16640, 5120)          16  torch.bfloat16                  5157.71           574.464  8.98x
(16640, 5120)          32  torch.bfloat16                 10792.7            757.536  14.25x
(16640, 5120)          64  torch.bfloat16                 20967.1           1356.64   15.46x
(16640, 5120)         128  torch.bfloat16                 42147.9           2467.57   17.08x

After:

input_shape      n_groups  high_precision_dtype      torch_time_us    triton_time_us  triton_speedup
-------------  ----------  ----------------------  ---------------  ----------------  ----------------
(16640, 5120)          16  torch.bfloat16                  5207.62           599.744  8.68x
(16640, 5120)          32  torch.bfloat16                 10647.6            670.416  15.88x
(16640, 5120)          64  torch.bfloat16                 21124             1355.79   15.58x
(16640, 5120)         128  torch.bfloat16                 42005.6           1408.99   29.81x

Copy link

pytorch-bot bot commented Aug 13, 2025

🔗 Helpful Links

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

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

✅ No Failures

As of commit b2b9b2f with merge base 317179e (image):
💚 Looks good so far! There are no failures yet. 💚

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

…caling kernel

stack-info: PR: #2761, branch: danielvegamyhre/stack/37
@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 Aug 13, 2025
@danielvegamyhre danielvegamyhre force-pushed the danielvegamyhre/stack/37 branch from ac93c84 to b2b9b2f Compare August 13, 2025 20:46
@danielvegamyhre danielvegamyhre added the topic: not user facing Use this tag if you don't want this PR to show up in release notes label Aug 13, 2025
@danielvegamyhre danielvegamyhre marked this pull request as draft August 13, 2025 21:18
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. topic: 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.

1 participant