Repository navigation
ROCm: eager batch-1 NF4 decode takes the Triton GEMV (1.8x decode on gfx1151) - #14440
Conversation
…on 3.6 On gfx1151 with Triton 3.6 the words kernel ran Llama 8B decode shapes 1.5x to 3.4x faster per call than bitsandbytes' ctypes GEMV, which HIP kept since the gate predates the words kernel. UNSLOTH_TRITON_GEMV_EAGER=0 keeps bitsandbytes' GEMV, =1 takes the Triton GEMV on any GPU and Triton. CUDA routing is unchanged.
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 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 |
|
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". |
On ROCm, eager batch-1 NF4 decode (
fast_gemvinunsloth/kernels/utils.py) still calls bitsandbytes' ctypes GEMV, which on gfx1151 is about 3x slower per call than Unsloth's own Triton NF4 GEMV on the large projections.The cause is the gate
triton_gemv_eager()inunsloth/kernels/nf4_gemv.py:torch.version.hip is None or triton >= 3.7. It came in with Fused Triton NF4 dequant and GEMV: bit-exact, stream-safe, torch.compile traceable #12113 ("keep bitsandbytes' GEMV for eager decode before Triton 3.7") for every device.Change
UNSLOTH_TRITON_GEMV_EAGER:0keeps bitsandbytes' GEMV,1takes the Triton GEMV on any GPU and Triton. Unset, CUDA routing is unchanged.test_planned_rows_are_reused_without_an_outwas previously skipped on HIP and now runs there. It skips when the direct launcher (triton_launch, CUDA only) is off: plans are only kept with it, and the multi-row path it forces is not taken on HIP.Validation
tests/test_nf4_triton_gemv.pyadds 38 cases; the 14 gate and routing cases fail on main:fast_gemvtakes vs dequantize + fp32 matmul on Llama-8B / Qwen shapes, fp16 / bf16, nested and flat absmax.On B200,
test_nf4_triton_gemv.py+test_bnb_integration_compile.py+test_triton_fp_fusion.py: 403 passed.AMD gfx1151 (Strix Halo, ROCm, torch 2.11, Triton 3.6), main vs this branch on the same runner, each also with
UNSLOTH_TRITON_GEMV_EAGER=0. Every call took the Triton route on the branch and ctypes on main and with the switch off; parity vs fp64 is within the existing test tolerance.Decode loop over real layer shapes, ms per token (host time included):
Per call, ms (CUDA events, first of the two AMD runs):
Not covered:
bnb.matmul_4bitmeasured at or slightly below the Triton GEMV per call on gfx1151 (0.073 to 0.089 ms on the large shapes) but is not used here; routing HIP to it would be a separate change.