You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[PERF] #4989 (fix of #4955) incomplete: EXL3 BF16 native path is launch-bound - ~12 eager ops per linear for the per-row pre-scale make bf16 decode 2x slower than fp16 (8.7 vs 4.4 ms/step, 96 vs 33 us per linear on sm_120) #5148
Found on main @ 7b8f127, RTX 5090 (sm_120), torch 2.15 + CUDA 13.2. GPU otherwise idle.
What is wrong
#4989 (fix of #4955) removed the host sync from the EXL3 BF16 path. Decode in BF16 (the default load dtype for Llama-3/Qwen EXL3 checkpoints) is still 2x slower than the same checkpoint in fp16, and 2.4x slower than the dense bf16 model. The cause is now CPU launch overhead. ExllamaV3Linear._native_bf16_input + _rescale_native_output (gptqmodel/nn_modules/exllamav3.py:411-449) run about 10 eager tensor ops per linear per forward: vector_norm(inf), .float(), div, frexp, ones_like x2, ldexp, where, x / scale, .to(fp16), then result.to(fp32), * scale, .to(bf16).
At decode (M=1) each of these is a microsecond-scale kernel, but each costs a full dispatch + launch on the host. torch.profiler over 20 calls of one gate_proj (4096 -> 14336): GPU time is 46 us/call (EXL3 GEMM 30 us + elementwise ~16 us), while host time is 209 us/call. The per-call wall clock is GPU-starved.
Numbers
Llama-3.1-8B-Instruct truncated to 8 decoder layers, EXL3Config(bits=4) quantized with GPTQModel, AUTO -> ExllamaV3Linear. Batch 1, manual DynamicCache decode loop, CUDA-event medians:
decode step bs1
decode step bs8
prefill 2048
generate() 128 tok
dense HF bf16
3.60 ms
4.10 ms
39.3 ms
242 tok/s
EXL3 fp16
4.38 ms
4.40 ms
35.7 ms
209 tok/s
EXL3 bf16
8.67 ms
8.55 ms
46.4 ms
111 tok/s
Single mlp.gate_proj, M=1, wall clock per call (200 calls, synchronized at the end): bf16 96.2 us, fp16 33.0 us. Wrapping the two helpers in torch.compile only reaches 86 us (still dispatch-bound) and is bit-identical to the current output. CUDA-event per-module times: q/o/gate/down at M=1 are 112/106/115/119 us in bf16 vs 42/42/57/59 us in fp16 (dense bf16: 23/23/80/83 us).
Do the pre-scale in one launch: a small fused CUDA/Triton op computing the row amax, the power-of-two scale and the fp16 cast, writing x_fp16 and scale. Do the rescale in one more fused op, or fold it into the EXL3 GEMM epilogue (it is a per-row multiply). That brings bf16 down to two extra launches per linear instead of about 12. The math stays bit-identical: power-of-two scaling, then one rounding.
Test that should have caught it
#4989's test asserts there is no host sync. Nothing compares bf16 vs fp16 EXL3 decode latency. An M=1 bound such as "bf16 <= 1.3x fp16 per linear" would catch the launch overhead.
Severity
Medium [PERF]: the default dtype of EXL3 Llama/Qwen checkpoints decodes at half the speed of fp16.
Agent claim:agent-4e3a0639ecaf is working on this issue now.
Started 2026-11-18T07:37:41Z. The claim expires 4.0h after this comment was last edited (heartbeat). Other agents: do not start this issue while the claim is live.
EXL3 bf16 native path is launch-bound: ~12 eager ops per linear for the per-row pre-scale make bf16 decode 2x slower than fp16
Activity
Qubitium commentedon Nov 18, 2026
Agent claim:
agent-4e3a0639ecafis working on this issue now.Started 2026-11-18T07:37:41Z. The claim expires 4.0h after this comment was last edited (heartbeat). Other agents: do not start this issue while the claim is live.
EXL3 bf16 native path is launch-bound: ~12 eager ops per linear for the per-row pre-scale make bf16 decode 2x slower than fp16
fix(exl3): map the scalar bf16 conversion in the HIP shim (#5208) (#5227
perf(exl3): fuse the bf16 pre-scale and re-scale into one launch each (…