Repository navigation
FP8 block dequant: ragged / rectangular e4m3fn blocks take the byte decoder on every NVIDIA GPU (4-16x) - #14450
Merged
Merged
Conversation
…ecoder on every NVIDIA arch
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. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! 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". |
danielhanchen
added a commit
to danielhanchen/unsloth-staging-2
that referenced
this pull request
Oct 23, 2026
…ake the byte decoder (unslothai#14936) On ROCm, block-FP8 weights whose tiles are ragged, or whose blocks are rectangular, still went through the chunked torch loop. unslothai#14450 moved these cases to the e4m3fn byte decoder on NVIDIA only. On gfx1151 (RDNA 3.5) that loop is 7.5x slower than the byte decoder, which is bit-identical to it for bf16 / fp32 output. ### Change - **gfx11 (RDNA3 / 3.5):** the cases the torch loop took run `_e4m3fn_bytes_dequant` for bf16 / fp32 output. Those cases are ragged blocks, rectangular blocks, and even tiles when Triton has no fp8e4nv. - **fp16 output** keeps the torch loop. On gfx1151 both Triton kernels round fp16 differently from it. - **Even tiles** keep the fp8e4nv kernel. - **CDNA, RDNA2, gfx12, gfx950 and unknown archs** keep their current routes. - **Kill switch:** `UNSLOTH_FP8_HIP_BYTES_DEQUANT=0` restores the old routes. - **NVIDIA:** routing is unchanged. ### Results gfx1151 (Radeon 8060S, torch 2.11 ROCm 7.13, Triton 3.6), main and this branch in the same job on the same runner: | shape | main | this PR | |---|---|---| | ragged 14336 x 4096, bf16 | 7.64 ms (torch loop) | 1.02 ms (byte decoder) | | q / up / down (even tiles) | fp8e4nv kernel | unchanged | - **Correctness:** output is bit-equal to the torch loop. - **Kill switch:** restores main's routes. A/A on the unchanged `up` shape is within 0.6%. - **FP8 tests on gfx1151:** main has 121 passed / 15 failed, this branch 155 passed / 15 failed. The same 15 fail on main: fp16 parity on gfx1151. - **NVIDIA, all FP8 test files (B200):** | torch | main | this PR | |---|---|---| | 2.10 | 707 passed | 733 passed | | 2.14 | 659 passed | 685 passed | The same 3 tests fail on main and here: `test_explicit_and_automatic_dequantize_reload[False]` and `test_ragged_rows_match_block_reference[glm5_3|ling3]`. ### Tests - `test_rocm_routes` / `test_rocm_kill_switch_restores_old_routes`: the routing table per gfx arch and Triton version. - `test_real_rocm_device_takes_bytes_kernel_bit_exact`: runs on real ROCm hardware. - The NVIDIA routing assertions are kept. ### Not covered - **AMD architectures:** CDNA, RDNA2, gfx12 and gfx950 were not run. They keep their current route by construction. - **Real checkpoint on AMD:** none was run; the evidence is kernel-level plus tests. - **Windows ROCm** was not run. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.
Block-FP8 weights whose shape does not tile into whole blocks (2880 x 2880 for gpt-oss-sized layers, 14400 x 4160, ...) or that use rectangular blocks are dequantized by the chunked torch loop
_torch_blockwise_dequanton sm89+ GPUs (L4, H100, B200, RTX PRO 6000). That is 4 to 16x slower than one pass over the weight. #14408 added a bit-identical e4m3fn byte decoder (_e4m3fn_bytes_dequant), but routed only pre-sm89 GPUs to it.Change
_blockwise_weight_dequant_any_shape, every case that took the torch loop on NVIDIA now takes the byte decoder for e4m3fn weights with a 2-D scale: ragged shapes and rectangular blocks on any arch, plus pre-sm89 as before.The byte decoder's output is bit-identical to the torch loop: same arithmetic, one rounding, every byte value incl. subnormals, -0.0 and NaN, as tested in #14408.
Validation
tests/test_fp8_pre_sm89_byte_dequant.py:test_triton_fp_fusion.pyon B200, 330 passed, 25 skipped; on Colab L4 (torch 2.11, Triton 3.6) the two pre-sm89 FP8 files gave 140 passed._blockwise_weight_dequant_any_shapeper call, bf16 output, ms. Main and this PR in fresh processes; main's route is the torch loop (main / torch loop = 1.00 in every row):L4 rows: two rounds each, main within 0.1% of itself; the 2880 x 2880 row gave 0.080 and 0.059 ms on this PR.
Not covered: