Repository navigation
FP8 rowwise decode: one multi-row GEMV launch for 2 to 16 tokens - #14791
Merged
Merged
Conversation
…ing the weight Per-channel FP8 weights with 2..16 decode rows (batched generate, GRPO HF rollouts) went to fbgemm_fp8_linear, whose scaled_mm backend dequantizes the whole weight to 16 bits for every call below 64 rows. A multi-row variant of the GEMV reads each fp8 weight tile once for all rows (exact upcast, fp32 dot accumulate, per-channel scale after the sum), with split K only where K is long or N narrow (deterministic two-pass reduce, no atomics). One row keeps the existing kernel; 17+ rows keep the GEMM paths; UNSLOTH_FP8_GEMV_ROWS=0 restores the previous routing.
…usion M (2..16 decode rows) is do_not_specialize, so one compiled kernel serves every batch size; tl.dot input_precision / out_dtype and enable_fp_fusion are passed explicitly.
[skip ci]
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. Breezy! 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
that referenced
this pull request
Oct 22, 2026
pre-commit.ci fails `ruff-format-with-kwargs` on every open PR (#14806, #14805, #14803, #14790, #14785, #14781, #14780, #14777, #14776, #14775, #14774, #14773, #14772, #14770, #14769, #14768, and others): "files were modified by this hook". pre-commit.ci runs the hooks on all files, and 20 files on main (26 by the time this lands) are not in the formatter's output, so every PR is reformatted outside its own diff. Where pre-commit.ci can push, its autofix commit drags those unrelated files into the PR (for example #14790's touches `tests/test_block_compile.py`, `tests/test_bnb_integration_compile.py` and `unsloth/models/_utils.py`). The drift came in with PRs merged today, among them #14702, #14751, #14759, #14784, #14786, #14787, #14788, #14791 and the FP8 block decode, GRPO routing replay, 4-bit decode, compiled blocks and MoE LoRA target changes. ### Change `python scripts/run_ruff_format.py` (the hook's own entry point, `ruff==0.6.9` as pinned in `.pre-commit-config.yaml`) applied to those 20 files, plus 6 more from #14739, #14779 and #14806, which merged while this was open. Formatting only. ### Verification - Every changed file parses to an identical AST before and after. - A second run of the hook over the same files changes nothing (fixed point), and over all tracked Python files on this branch it changes nothing. - `ruff check` passes on the changed files; `tests/test_formatter_fixed_point.py` passes (16). Open PRs pick this up on their next pre-commit.ci run after merging main.
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
Per-channel (rowwise) FP8 weights with 2 to 16 decode rows (batched
generate, GRPO HF rollouts) went tofbgemm_fp8_linear, whosescaled_mmbackend dequantizes the whole weight to 16 bits on every call below 64 rows. This adds a multi-row variant of the existing rowwise GEMV that reads each fp8 weight tile once for all rows: exact upcast, fp32 dot accumulate, per-channel scale applied after the sum, split K only where K is long or N narrow (deterministic two-pass reduce, no atomics).Misdo_not_specialize, so one compiled kernel serves every batch size from 2 to 16.UNSLOTH_COMPRESSED_TENSORS_FP8_KERNELS=1) andfast_linear_forward.UNSLOTH_FP8_GEMV_ROWS=0restores the previous routing.End to end decode
RedHatAI/Qwen3-1.7B-FP8-dynamic,UNSLOTH_COMPRESSED_TENSORS_FP8_KERNELS=1, greedy, 64 new tokens, torch 2.14.1. Main and this branch run from separate checkouts in separate processes, interleaved main, branch, main, 3 rounds; tok/s is the median, A/A is the largest main vs main gap within a round.The new kernel ran 12348 times per 64-token batch-4 / batch-8 generate and 0 times at batch 1. Greedy tokens differ from main at batch 4 / 8 (78 to 89% identical), since main dequantizes or quantizes the activation while this keeps the activation exact; against an fp64 oracle on B200 (84 cases, 60 of them routed to the new kernel), its mean abs error is at or below main's in all 60.
Kernel timing
Same per-channel quantized weights in both arms, bf16, decode rows
M, called the way the compressed-tensors forward calls it. Device time with L2 flushed (median of 30), microseconds, main / this PR:Across 20 shapes (Qwen3 0.6B to 8B, Llama 8B) at M = 2, 4, 8, 16:
M = 1 and M = 17 are within the A/A band of main on every shape (same code path).
Tests
Main and this PR from separate checkouts,
-m "not server and not native_mxc":test_fp8_rowwise_gemv_rows.pyThe 4 failures on both sides are in
test_modelopt_fp8_loading.pyand are pre-existing on main.torch.compile
HF
generateat batch 1, 2, 4, 8, 16 (each batch 8 new tokens), counted after the last batch:The rows kernel's variant count is the same after batch 2 as after batch 16. Fewer Dynamo graphs because the 2 to 16 row calls no longer go through the compiled
fbgemm_fp8_linearpath.Not proven
031a117757; main's onlyfp8.pychange in between (FP8 dequant: multiply per-tensor and rowwise scales in fp32 for fp16 output #14677) is in the fp16 per-tensor / per-rowweight_dequant, off the decode paths timed here. Tests and the compile census above were re-run on the merged branch.