mx: small speedup with dim0 cast#1980
Merged
Merged
Conversation
vkuzo
added a commit
that referenced
this pull request
Mar 28, 2025
Summary: Removes the unnecessary cast to bfloat16 in the MX dim0 casting code. This is a 2.6% speedup on 16k by 16k shape: https://www.internalfb.com/phabricator/paste/view/P1769373804 Note: this PR also includes a couple of cleanups around e8m0 dtype and NaN handling, I found them while coding this PR. Leaving them together instead of separate PR since they are all safe. Test Plan: ```bash (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 152.90741052631583 mem_bw_gbps 5321.488168553876 (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 149.03950980392162 mem_bw_gbps 5459.5924065404415 ``` Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 47fb1df ghstack-comment-id: 2762318741 Pull Request resolved: #1980
vkuzo
added a commit
that referenced
this pull request
Mar 28, 2025
Summary: Removes the unnecessary cast to bfloat16 in the MX dim0 casting code. This is a 2.6% speedup on 16k by 16k shape: https://www.internalfb.com/phabricator/paste/view/P1769373804 Note: this PR also includes a couple of cleanups around e8m0 dtype and NaN handling, I found them while coding this PR. Leaving them together instead of separate PR since they are all safe. Test Plan: ```bash (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 152.90741052631583 mem_bw_gbps 5321.488168553876 (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 149.03950980392162 mem_bw_gbps 5459.5924065404415 ``` Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 47fb1df ghstack-comment-id: 2762318741 Pull Request resolved: #1980
vkuzo
added a commit
that referenced
this pull request
Mar 28, 2025
Summary: Removes the unnecessary cast to bfloat16 in the MX dim0 casting code. This is a 2.6% speedup on 16k by 16k shape: https://www.internalfb.com/phabricator/paste/view/P1769373804 Note: this PR also includes a couple of cleanups around e8m0 dtype and NaN handling, I found them while coding this PR. Leaving them together instead of separate PR since they are all safe. Test Plan: ```bash (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 152.90741052631583 mem_bw_gbps 5321.488168553876 (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 149.03950980392162 mem_bw_gbps 5459.5924065404415 ``` Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 47fb1df ghstack-comment-id: 2762318741 Pull Request resolved: #1980
vkuzo
added a commit
that referenced
this pull request
Mar 28, 2025
Summary: Removes the unnecessary cast to bfloat16 in the MX dim0 casting code. This is a 2.6% speedup on 16k by 16k shape: https://www.internalfb.com/phabricator/paste/view/P1769373804 Note: this PR also includes a couple of cleanups around e8m0 dtype and NaN handling, I found them while coding this PR. Leaving them together instead of separate PR since they are all safe. Test Plan: ```bash (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 152.90741052631583 mem_bw_gbps 5321.488168553876 (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 149.03950980392162 mem_bw_gbps 5459.5924065404415 ``` Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 47fb1df ghstack-comment-id: 2762318741 Pull Request resolved: #1980
HDCharles
approved these changes
Mar 28, 2025
vkuzo
added a commit
that referenced
this pull request
Apr 1, 2025
Summary: Removes the unnecessary cast to bfloat16 in the MX dim0 casting code. This is a 2.6% speedup on 16k by 16k shape: https://www.internalfb.com/phabricator/paste/view/P1769373804 Note: this PR also includes a couple of cleanups around e8m0 dtype and NaN handling, I found them while coding this PR. Leaving them together instead of separate PR since they are all safe. Test Plan: ```bash (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 152.90741052631583 mem_bw_gbps 5321.488168553876 (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 149.03950980392162 mem_bw_gbps 5459.5924065404415 ``` Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 47fb1df ghstack-comment-id: 2762318741 Pull Request resolved: #1980
vkuzo
added a commit
that referenced
this pull request
Apr 1, 2025
Summary: Removes the unnecessary cast to bfloat16 in the MX dim0 casting code. This is a 2.6% speedup on 16k by 16k shape: https://www.internalfb.com/phabricator/paste/view/P1769373804 Note: this PR also includes a couple of cleanups around e8m0 dtype and NaN handling, I found them while coding this PR. Leaving them together instead of separate PR since they are all safe. Test Plan: ```bash (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 152.90741052631583 mem_bw_gbps 5321.488168553876 (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 149.03950980392162 mem_bw_gbps 5459.5924065404415 ``` Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 47fb1df ghstack-comment-id: 2762318741 Pull Request resolved: #1980
vkuzo
added a commit
that referenced
this pull request
Apr 1, 2025
Summary: Removes the unnecessary cast to bfloat16 in the MX dim0 casting code. This is a 2.6% speedup on 16k by 16k shape: https://www.internalfb.com/phabricator/paste/view/P1769373804 Note: this PR also includes a couple of cleanups around e8m0 dtype and NaN handling, I found them while coding this PR. Leaving them together instead of separate PR since they are all safe. Test Plan: ```bash (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 152.90741052631583 mem_bw_gbps 5321.488168553876 (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ (pytorch) [vasiliy@devgpu023.atn1 ~/local/ao (20250321_mx_dim1_triton_kernel)]$ python benchmarks/mx_formats/cast_bench.py --mode dim0_mx --M 16384 --K 16384 M 16384 K 16384 BLOCK_SIZE 32 GPU: NVIDIA B200 torch version: 2.8.0a0+git25309a1 triton version: 3.3.0 mode: dim0_mx time_us 149.03950980392162 mem_bw_gbps 5459.5924065404415 ``` Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 47fb1df ghstack-comment-id: 2762318741 Pull Request resolved: #1980
liangel-02
pushed a commit
that referenced
this pull request
Aug 25, 2025
* 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] * 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] * 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:
Removes the unnecessary cast to bfloat16 in the MX dim0 casting code.
This is a 2.6% speedup on 16k by 16k shape:
https://www.internalfb.com/phabricator/paste/view/P1769373804
Note: this PR also includes a couple of cleanups around e8m0 dtype and
NaN handling, I found them while coding this PR. Leaving them together
instead of
separate PR since they are all safe.
Test Plan:
Reviewers:
Subscribers:
Tasks:
Tags: