Repository navigation
Wire MoE and MXFP8Linear training paths to CuTeDSL by default - #4705
alexsamardzic wants to merge 8 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4705
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 71bdb6c with merge base 39d5874 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
| @@ -0,0 +1,212 @@ | |||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | |||
There was a problem hiding this comment.
split between test and benchmarks
| reason="MXFP8 grouped GEMM requires SM100", | ||
| ) | ||
| @pytest.mark.parametrize("backend", ("legacy", "cutedsl")) | ||
| def test_mxfp8_grouped_gemm_backend_fwd_bwd(backend): |
There was a problem hiding this comment.
is there an existing test we can extend?
| reason="MXFP8 grouped GEMM requires SM100", | ||
| ) | ||
| @pytest.mark.parametrize("backend", ("legacy", "cutedsl")) | ||
| def test_mxfp8_grouped_gemm_padded_backend_fwd_bwd(backend): |
There was a problem hiding this comment.
is there an existing test we can extend
| reason="MXFP8 grouped GEMM requires SM100", | ||
| ) | ||
| @pytest.mark.parametrize("backend", ("legacy", "cutedsl")) | ||
| def test_mxfp8_grouped_gemm_mxtensor_backend_forward(backend): |
| _MXFP8_GROUPED_MM_BACKEND = "cutedsl" | ||
|
|
||
|
|
||
| def set_mxfp8_grouped_mm_backend(backend: str) -> None: |
There was a problem hiding this comment.
let's remove the global, instead a user should be able to select this when they create a config. You can use kernel_preference or create a new similar flag.
| elem_dtype=torch.float8_e4m3fn, | ||
| hp_dtype=grad_output.dtype, | ||
| kernel_preference=KernelPreference.AUTO, | ||
| cast_kernel_choice=MXFP8Dim1CastKernelChoice.CUDA, |
There was a problem hiding this comment.
can we wire it with things like MXFP8Dim1CastKernelChoice.CUTEDSL, etc instead of creating a new backend concept
| from torchao.prototype.mx_formats.utils import _to_mxfp8_dim1_kernel_wrapper | ||
| from torchao.quantization.quantize_.common.kernel_preference import KernelPreference | ||
|
|
||
| _MXFP8_LINEAR_BACKEND = "cutedsl" |
| block_size: int, | ||
| scale_calculation_mode: ScaleCalculationMode, | ||
| kernel_preference: KernelPreference, | ||
| mxfp8_dim0_cast_kernel_choice: MXFP8Dim0CastKernelChoice, |
There was a problem hiding this comment.
i think we want MXFP8Dim0CastKernelChoice.CUTEDSL
|
@claude review |
|
Claude finished @vkuzo's task in 4m 38s —— View job Claude PR Review
I reviewed the diff against 1. The
|
|
All comments addressed. Two of the three near-duplicate tests merged into existing ones; the padded-groups test stayed separate since it's the only one exercising |
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
(Replaces #4620 due to incorrect ghstack base branch targeting.)
This PR wires the MXFP8 MoE grouped-mm and MXFP8Linear training paths to use the CuTeDSL backend by default, while keeping the legacy CUDA/Triton backend selectable for validation and benchmarking. It adds end-to-end correctness tests for grouped-mm, padded grouped-mm, prequantized MXTensor grouped-mm, and MXFP8Linear fwd/bwd, plus benchmark support for comparing CuTeDSL against the legacy backend. This prepares the next PR to delete torchao._C_mxfp8 and the now-obsolete legacy CUDA/Triton paths.
To run tests:
pytest -q \ test/prototype/moe_training/test_mxfp8_grouped_mm.py::test_mxfp8_grouped_gemm_with_dq_fwd_bwd \ test/prototype/moe_training/test_mxfp8_grouped_mm.py::test_mxfp8_grouped_gemm_padded_fwd_bwd \ test/prototype/moe_training/test_mxfp8_grouped_mm.py::test_mxfp8_grouped_gemm_from_qdata_and_scales_forward \ test/prototype/moe_training/test_mxfp8_linear.py::test_mxfp8_linear_fwd_bwd_sqnrTo run MoE grouped-mm fwd/bwd recipe benchmark:
python benchmarks/prototype/moe_training/mxfp8/roofline_unified.py \ --backend=both --K=4096 --N=4096 --G=8 --breakdown_M=16384 \ --outfile_speedup=roofline_speedup_K4096_N4096.csv \ --outfile_quant_2d=roofline_quant_2d_K4096_N4096.csv \ --outfile_quant_3d=roofline_quant_3d_K4096_N4096.csv \ --plot_file=roofline_K4096_N4096.pngResults of benchmark above:

To run MXFP8Linear fwd/bwd recipe benchmark:
python benchmarks/prototype/moe_training/mxfp8/bench_mxfp8_linear.py \ 4096x4096x2048 \ --cuda-graph-bench --graph-iters 100Would be good to run on multi-GPU machine:
torchrun --nproc-per-node=2 --local-ranks-filter=0 \ benchmarks/prototype/moe_training/mxfp8/bench_ep_pipeline.py --backend=legacy torchrun --nproc-per-node=2 --local-ranks-filter=0 \ benchmarks/prototype/moe_training/mxfp8/bench_ep_pipeline.py --backend=cutedsl