Repository navigation
FP8 block decode: keep the fused small-M kernel for fp16 when torchao is selected - #15361
Merged
Merged
Conversation
… is selected torchao's blockwise GEMM writes bf16 only, so torchao_block_matmul sends fp16 calls to the Triton GEMM after a separate act_quant. The small-M gate turned off whenever torchao was the selected backend, so fp16 decode ran two launches instead of the one fused kernel. Now fp16 keeps the fused kernel with torchao selected, and on 100+ SM parts the GEMV still takes the calls it took before (it skips act_quant). bf16 routing is unchanged.
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Problem
Since #15153 found torchao 0.18's
blockwise_fp8_gemm, startup selectstorchao_block_matmulon sm_90 / sm_100 / sm_120 whenever torchao is installed.can_use_fp8_block_small_mturns itself off whenever torchao is the selected backend, because torchao beats the fused small-M kernel for bf16.torchao's kernel writes bf16 only, so
torchao_block_matmulsends every fp16 call back tow8a8_block_fp8_matmul_triton. fp16 decode therefore lost the fused kernel and ranact_quantplus the Triton GEMM, two launches instead of one, and never used torchao anyway.Fix
can_use_fp8_block_small_monly declines for a non-fp16 input when torchao is selected. bf16 still goes to torchao, and nothing changes when the Triton GEMM is selected (sm_89, or no torchao)._fp8_block_small_m_first(100+ SM parts): with torchao selected, the GEMV is tried before the fused kernel, so the decode calls it already took (it skipsact_quant) stay on it. With the Triton GEMM selected the order is unchanged.Tests
tests/test_fp8_small_m_torchao_route.pyneeds no GPU. Kernels are replaced by recorders and the routing is checked throughFP8BlockQuantLinear.forwardand_fp8_block_small_m_first:act_quantplus the GEMM run.act_quantplus torchao. Triton selected runs the fused kernel for both dtypes. M above 16 andUNSLOTH_FP8_BLOCK_SMALL_M=0keep two launches. The GEMV keeps its calls with torchao selected.On main: 4 failed, 10 passed. With this change: 14 passed. The existing FP8 suites (
tests/test_fp8_*.py,tests/test_compressed_tensors_fp8_kernel_route.py) also pass on CPU: 263 passed, 458 skipped (GPU-only).Benchmark
RTX PRO 6000 Blackwell (sm_120), torch 2.13.0, torchao 0.18.0. Each arm runs in its own long-lived process. Each round times base, head, then the second base copy, and the next round reverses the order. That gives 12 rounds of 200 eager
fp8_linearcalls per arm, measured as host time per call with a sync at the end. A/A is the second base copy over the first.fp16, GEMV on (default):
With the GEMV off, fp16 is 0.60 to 0.90 of main across all six shapes. For bf16, every shape takes the same route as on main, and head / main is between 0.99 and 1.01. That is inside the A/A spread of 0.97 to 1.04.
Outputs: bf16 is bit-identical to main for every shape. fp16 is bit-identical to the same code without torchao installed, which is what fp16 decode produced before #15153. Against main with torchao, the largest fp16 difference is 3.9e-3, and the error against an fp64 reference is the same on both sides. On L4 (sm_89, where the Triton GEMM is selected), every output is bit-identical to main and timings are unchanged.
Not covered