Skip to content

[scaled grouped mm] add triton kernels for float8 rowwise quantization with per-group/jagged scales #2064

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

Merged
merged 11 commits into from
Apr 21, 2025

Conversation

danielvegamyhre
Copy link
Contributor

@danielvegamyhre danielvegamyhre commented Apr 16, 2025

Next PR in stack: #2077

Motivation

  • In the first iteration of the differentiable scaled grouped mm prototype, to perform float8 quantization with per-group/"jagged" scales, we naively iterate through the offsets on the CPU in for loop, launching separate scaling kernels for each subtensor (see here). This approach requires host-device sync, to loop over the values via offs.tolist() on the CPU, which negatively impacts performance.
  • Solution: do all of this in a single triton kernel to avoid host-device sync and improve performance.

Summary

This PR adds 2 Triton kernels:

  • _triton_fp8_row_major_jagged_rowwise_scales: performs dynamic float8 quantization with row-wise scales for each group (as determined by the offsets), and writes the output in row-major memory layout. This kernel is to be used for quantizing left operand of the scaled grouped mm in the backward pass of the differentiable scaled grouped mm, to compute grad_weight (see here).
  • _triton_fp8_col_major_jagged_colwise_scales: performs dynamic float8 quantization with row-wise scales computed over logical columns for each group (as determined by the offsets), and writes the output in col-major memory layout. This kernel is to be used for quantization of the right operand of the scaled grouped mm in the backward pass of the differentiable scaled grouped mm, to compute grad_weight (see here).

Test plan

  • Added unit tests confirming triton kernels produce same outputs as corresponding pure pytorch implementations.

Next steps

  • Measure e2e differentiable scaled grouped mm perf with vs without these changes
  • Integrate the triton kernels into the autograd func
  • Do any additional perf improvements as necessary
  • Add JaggedFloat8Tensor subclass w/ override for torch._grouped_mm (bf16 op)
  • Add user-facing prototype API for converting MoE layers to use float8 training

Copy link

pytorch-bot bot commented Apr 16, 2025

🔗 Helpful Links

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

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:

❌ 4 New Failures, 4 Pending

As of commit d818d51 with merge base f788897 (image):

NEW FAILURES - The following jobs have failed:

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 Apr 16, 2025
@danielvegamyhre danielvegamyhre marked this pull request as draft April 16, 2025 17:12
@danielvegamyhre danielvegamyhre force-pushed the kernel branch 3 times, most recently from db30377 to 1d5b2c9 Compare April 16, 2025 19:10
@danielvegamyhre danielvegamyhre changed the title [WIP] [scaled grouped mm] add triton kernels for float8 rowwise quantization with jagged scales [scaled grouped mm] add triton kernels for float8 rowwise quantization with jagged scales Apr 16, 2025
@danielvegamyhre danielvegamyhre added topic: improvement Use this tag if this PR is an improvement (doesn't fit into any of the other categories) topic: performance Use this tag if this PR improves the performance of a feature labels Apr 16, 2025
@danielvegamyhre danielvegamyhre marked this pull request as ready for review April 16, 2025 19:33
@danielvegamyhre danielvegamyhre changed the title [scaled grouped mm] add triton kernels for float8 rowwise quantization with jagged scales [scaled grouped mm] add triton kernels for float8 rowwise quantization with per-group/jagged scales Apr 16, 2025
@danielvegamyhre
Copy link
Contributor Author

cc @drisspg @ngimel I'd appreciate your thoughts/reviews on this when you have time

@danielvegamyhre danielvegamyhre requested a review from drisspg April 18, 2025 16:20
@danielvegamyhre
Copy link
Contributor Author

also cc @vkuzo for visibility upon return from recharge

@danielvegamyhre
Copy link
Contributor Author

confirmed test failures are unrelated to this change

@danielvegamyhre danielvegamyhre merged commit 7b05105 into main Apr 21, 2025
11 of 18 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. topic: improvement Use this tag if this PR is an improvement (doesn't fit into any of the other categories) topic: performance Use this tag if this PR improves the performance of a feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants