add a_1_128_w_128_128 (DeepSeek) float8 scaling for inference#3257
Merged
Conversation
Contributor
Author
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/3257
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New FailuresAs of commit c4769a6 with merge base 1e473ed ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
vkuzo
added a commit
that referenced
this pull request
Oct 29, 2025
Summary: Basic enablement of the a_1_128_w_128_128 float8 scaling recipe in torchao inference. In detail: 1. bring the 128x128 gemm triton kernel we have out of prototype and wrap it with a custom op for `torch.compile` compatibility 2. enable the new granularity in various utility functions 3. wire the new granularity through the float8 inference configs 4. add a test which tests for e2e numerical correctness via SQNR comparison vs high precision baseline For now I added a fallback which only requires triton and is numerically correct but may not reach optimal performance. Performance optimization is left for future PRs: 1. we should map the gemm to `torch._scaled_mm` for CUDA 12.9+ 2. we should enable an fbgemm_gpu_genai path, if available in user env 3. we should map to a triton kernel for quantizing the weights, as `torch.compile` is currently known slow for 128x128 block quantization Test Plan: Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: db464e1 ghstack-comment-id: 3460951962 Pull-Request: #3257
This was referenced Oct 29, 2025
vkuzo
added a commit
that referenced
this pull request
Oct 29, 2025
Summary: Basic enablement of the a_1_128_w_128_128 float8 scaling recipe in torchao inference. In detail: 1. bring the 128x128 gemm triton kernel we have out of prototype and wrap it with a custom op for `torch.compile` compatibility 2. enable the new granularity in various utility functions 3. wire the new granularity through the float8 inference configs 4. add a test which tests for e2e numerical correctness via SQNR comparison vs high precision baseline For now I added a fallback which only requires triton and is numerically correct but may not reach optimal performance. Performance optimization is left for future PRs: 1. we should map the gemm to `torch._scaled_mm` for CUDA 12.9+ 2. we should enable an fbgemm_gpu_genai path, if available in user env 3. we should map to a triton kernel for quantizing the weights, as `torch.compile` is currently known slow for 128x128 block quantization Test Plan: Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: c9e22bd ghstack-comment-id: 3460951962 Pull-Request: #3257
vkuzo
added a commit
that referenced
this pull request
Oct 29, 2025
Summary: Basic enablement of the a_1_128_w_128_128 float8 scaling recipe in torchao inference. In detail: 1. bring the 128x128 gemm triton kernel we have out of prototype and wrap it with a custom op for `torch.compile` compatibility 2. enable the new granularity in various utility functions 3. wire the new granularity through the float8 inference configs 4. add a test which tests for e2e numerical correctness via SQNR comparison vs high precision baseline For now I added a fallback which only requires triton and is numerically correct but may not reach optimal performance. Performance optimization is left for future PRs: 1. we should map the gemm to `torch._scaled_mm` for CUDA 12.9+ 2. we should enable an fbgemm_gpu_genai path, if available in user env 3. we should map to a triton kernel for quantizing the weights, as `torch.compile` is currently known slow for 128x128 block quantization Test Plan: Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 802d26f ghstack-comment-id: 3460951962 Pull-Request: #3257
vkuzo
added a commit
that referenced
this pull request
Oct 29, 2025
Summary: Basic enablement of the a_1_128_w_128_128 float8 scaling recipe in torchao inference. In detail: 1. bring the 128x128 gemm triton kernel we have out of prototype and wrap it with a custom op for `torch.compile` compatibility 2. enable the new granularity in various utility functions 3. wire the new granularity through the float8 inference configs 4. add a test which tests for e2e numerical correctness via SQNR comparison vs high precision baseline For now I added a fallback which only requires triton and is numerically correct but may not reach optimal performance. Performance optimization is left for future PRs: 1. we should map the gemm to `torch._scaled_mm` for CUDA 12.9+ 2. we should enable an fbgemm_gpu_genai path, if available in user env 3. we should map to a triton kernel for quantizing the weights, as `torch.compile` is currently known slow for 128x128 block quantization Test Plan: Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 81e336e ghstack-comment-id: 3460951962 Pull-Request: #3257
vkuzo
commented
Oct 29, 2025
vkuzo
commented
Oct 29, 2025
| triton.cdiv(N, meta["BLOCK_SIZE"]), | ||
| from torch.utils._triton import has_triton | ||
|
|
||
| if has_triton(): |
Contributor
Author
There was a problem hiding this comment.
most of the changes in this file is just indent from adding the if has_triton() statement
vkuzo
commented
Oct 29, 2025
| mask = (offs_m[:, None] < M) & (offs_n[None, :] < N) | ||
| tl.store(c_ptrs, c, mask=mask) | ||
|
|
||
| @torch.library.custom_op("ao::blockwise_fp8_gemm", mutates_args=()) |
vkuzo
commented
Oct 29, 2025
| ) | ||
| return c | ||
|
|
||
| @blockwise_fp8_gemm.register_fake |
vkuzo
commented
Oct 29, 2025
| fp8_blockwise_weight_dequant_kernel[grid](x, s, y, M, N, BLOCK_SIZE=block_size) | ||
| return y | ||
|
|
||
| else: |
jerryzh168
reviewed
Oct 30, 2025
jerryzh168
reviewed
Oct 30, 2025
jerryzh168
reviewed
Oct 30, 2025
vkuzo
added a commit
that referenced
this pull request
Oct 30, 2025
Summary: Basic enablement of the a_1_128_w_128_128 float8 scaling recipe in torchao inference. In detail: 1. bring the 128x128 gemm triton kernel we have out of prototype and wrap it with a custom op for `torch.compile` compatibility 2. enable the new granularity in various utility functions 3. wire the new granularity through the float8 inference configs 4. add a test which tests for e2e numerical correctness via SQNR comparison vs high precision baseline For now I added a fallback which only requires triton and is numerically correct but may not reach optimal performance. Performance optimization is left for future PRs: 1. we should map the gemm to `torch._scaled_mm` for CUDA 12.9+ 2. we should enable an fbgemm_gpu_genai path, if available in user env 3. we should map to a triton kernel for quantizing the weights, as `torch.compile` is currently known slow for 128x128 block quantization Test Plan: Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 8d58dfe ghstack-comment-id: 3460951962 Pull-Request: #3257
jerryzh168
approved these changes
Oct 30, 2025
jerryzh168
left a comment
Contributor
There was a problem hiding this comment.
looks good, I think we can also keep the 1x128 block to align with what deepseek is calling it now
jerryzh168
reviewed
Oct 30, 2025
jerryzh168
left a comment
Contributor
There was a problem hiding this comment.
oh since we are changing the meaning of PerBlock, please update the doc a bit as well:
ao/torchao/quantization/granularity.py
Line 107 in 1e473ed
Contributor
Author
|
CI failures exist on main branch, landing |
namgyu-youn
pushed a commit
to namgyu-youn/ao
that referenced
this pull request
Nov 21, 2025
…h#3257) * Update [ghstack-poisoned] * Update [ghstack-poisoned] * Update [ghstack-poisoned] * Update [ghstack-poisoned] * Update [ghstack-poisoned] * Update [ghstack-poisoned] * Update [ghstack-poisoned] * Update [ghstack-poisoned] * Update [ghstack-poisoned] * Update [ghstack-poisoned]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
Basic enablement of the a_1_128_w_128_128 float8 scaling recipe in
torchao inference. In detail:
comparison vs high precision baseline
For now we only have fallback kernels which requires triton and are numerically
correct but may not reach optimal performance. Performance optimization is
left for future PRs:
torch._scaled_mmfor CUDA 12.9+torch.compileis currently known slow for 128x128 blockquantization
Further accuracy testing and enablement of more features is left for future PRs, to keep PR size small.
Test Plan:
Reviewers:
Subscribers:
Tasks:
Tags: