Repository navigation
[None][perf] Add a small-M MXFP8 quantization kernel for swizzled scale factors - #21444
Draft
greg-kwasniewski1 wants to merge 1 commit into
Draft
greg-kwasniewski1 wants to merge 1 commit into
greg-kwasniewski1 wants to merge 1 commit into
Conversation
…le factors For 1 to 32 rows, more than 2048 columns (a multiple of 128) and the swizzled 128x4 scale-factor layout on SM100/SM103, invokeMxFP8Quantization now launches quantize_mxfp8_small_m_swizzled. Each CTA converts 1024 columns of one row instead of one padded row, and the scale-factor atoms are written with 16-byte stores instead of one byte per padding scale. Values and scale factors come from cvt_warp_fp16_to_mxfp8, as in quantize_with_block_size, so the output is bitwise identical. The PDL contract does not change: the dependency wait comes before the first global access, and the trigger comes after a fence and a CTA barrier. Other shapes, layouts and architectures keep quantize_with_block_size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: greg-kwasniewski1 <213329731+greg-kwasniewski1@users.noreply.github.com>
Collaborator
Author
|
/bot run |
Collaborator
|
PR_Github #82237 [ run ] triggered by Bot. Commit: |
Collaborator
|
PR_Github #82237 [ run ] completed with state
|
This branch has not been deployed
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.
@coderabbitai summary
Description
invokeMxFP8Quantizationgives each CTA one padded row. With the swizzled 128x4 scale-factor layout, a few rowstherefore launch
PadUp(m, 128) = 128CTAs of up to 512 threads. At M = 6, K = 5120, six CTAs convert data (two passesover the row each) and 122 CTAs only write zero padding scale factors, one byte per store.
This PR adds
quantize_mxfp8_small_m_swizzled<T>inquantization.cuand dispatches to it when all of these hold:SF_VEC_SIZE == SF_OUTPUT_VEC_SIZE == 32, swizzled layout,b == 1;1 <= m <= 32,n == padded_n,n % 128 == 0,n > 2048;Every other shape, layout, scale-vector size and architecture keeps
quantize_with_block_size. SM107 is not touched,so the SM107 path that #20623 adds in the same function is not affected; the two changes merge without conflicts.
How the kernel works:
(ceil(n / 1024), m), 128 threads per CTA; each thread converts one 8-element vector.cvt_warp_fp16_to_mxfp8, the function thatquantize_with_block_sizecalls, sothe output is bitwise identical, including the
exp2f_rcphandling of tiny blocks.r + 64 and r + 96. With m <= 32, slot r < m is [four scales of row r, 12 zero bytes] and every other slot is zero.
The kernel writes each atom with 16-byte stores and covers every byte of the scale-factor buffer.
cudaGridDependencySynchronize()comes before the first global access, and__threadfence(); __syncthreads();come beforecudaTriggerProgrammaticLaunchCompletion().Up to 2048 columns both kernels run at the launch latency on B200 and the existing kernel is not slower, so the guard
starts above 2048 columns.
Performance (B200)
Per-launch time in µs, main → this PR, bf16, PDL on. Each value is the median of 9 rounds of a CUDA graph with 50
back-to-back launches. Main's and this PR's
quantization.cuare compiled with the same nvcc and release flags(
-O3 -DNDEBUG,sm_100f) into one binary, and the rounds alternate between them.Summary over all measured shapes:
The not-dispatched shapes (M ∈ {33, 64, 128, 1024}, N ≤ 2048, N = 2880) run the same code as main; their spread is the
run-to-run noise.
Kernel duration from nsys (bf16, PDL off, median over all launches):
Setup: one B200 (148 SMs), driver 615.71.10, nvcc 13.2, default clocks (not locked; maximum SM clock 1965 MHz).
Test Coverage
New tests in
tests/unittest/_torch/kernels/parallel/test_fp8_quantize.py. The existingunittest/_torch/kernels/parallelentries ofl0_b200.ymlandl0_gb300.ymlrun them.test_mxfp8_quantize_swizzled_matches_linear_layout: for m ∈ {1, 2, 6, 12, 31, 32, 33, 128},k ∈ {1024, 2048, 2176, 2880, 5120, 7168, 16384}, fp16 and bf16, the swizzled output equals the linear output with
block_scale_interleaveapplied, byte for byte over the full value and scale-factor buffers, padding included. Theinputs contain zero blocks, a block below the smallest UE8M0 scale, the dtype maximum, subnormals and negative zeros.
Before the call, blocks filled with 0xFF are released to the caching allocator, so that an unwritten byte is likely
to show.
test_mxfp8_quantize_swizzled_cuda_graph_replays: CUDA-graph replays with new inputs give the bytes of eager calls,for dispatched and fallback shapes.
Existing tests on the same paths:
test_mxfp8_quantize_torch_device,test_mxfp8_quantize_alignment_torch_device,test_mxfp8_quantize_zero_rows,test_mxfp8_quantize_tiny_block_is_finite, andtest_mxfp8_mxfp8_gemm.pyfor theconsumer GEMM.
Local validation on B200:
quantization.cucompared every byte of the value andscale-factor buffers for M ∈ {1, 2, 4, 6, 8, 12, 16, 24, 31, 32, 33, 64, 128, 1024} ×
N ∈ {1024, 1152, 1536, 2048, 2880, 3584, 4096, 5120, 6144, 7168, 8192, 16384} × {fp16, bf16} × 3 seeds, with the
outputs pre-filled with 0xFF and with 0x00: 3528 comparisons, 0 differing bytes.
compute-sanitizermemcheck, racecheck and synccheck on the same binary: 0 errors.quantization.cucompiles for sm_80, sm_90a, sm_100f, sm_103f and sm_120f with the same warnings as main.ptxasreports 30 registers, no stack frame and no spills for the new kernel.
PR Checklist
Please review the following before submitting your PR:
PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.
PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.
Test cases are provided for new code paths (see test instructions)
If PR introduces API changes, an appropriate PR label is added - either
api-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin the PR title.Any new dependencies have been scanned for license and vulnerabilities
CODEOWNERS updated if ownership changes
Documentation updated as needed
Update tava architecture diagram if there is a significant design change in PR.
The reviewers assigned automatically/manually are appropriate for the PR.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see a list of available CI bot commands, please comment
/bot help.🤖 Generated with Claude Code