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] #4938 (fix of #4870) incomplete: EXL3 BF16 native path still does a float(amax) host sync per linear per forward (decode 4-8x slower than the same per-row math on device) #4955
Found on main @ 774916f (includes #4938), RTX 4090 (sm_89), torch 2.15.0+cu132. The GPU was shared with other processes, as it is in any multi-tenant serving setup.
What is wrong
#4870 asked for two changes to ExllamaV3Linear._native_bf16_input(): scale per row instead of per tensor, and compute the scale on the device instead of with a float(amax) host read. The issue's perf comment measured the host read as the main cost of BF16 decode (3.4x slower than fp16 on an idle GPU, 4-9x on a shared one).
#4938 adds the per-row scale but keeps the host read in front of it (gptqmodel/nn_modules/exllamav3.py:403):
Every BF16 forward of every native EXL3 linear still blocks the host until the GPU drains: 112 syncs per decoded token on a 1B model, 224 on an 8B. This is the default load path for Llama-3/Qwen EXL3 checkpoints, which load in bf16. The sync also prevents CUDA-graph capture of the BF16 path.
Llama-3.2-1B-Instruct-EXL3-W4-ALL, BACKEND.EXL3_EXLLAMA_V3, generate(2 prompts, max_new_tokens=64, min_new_tokens=64), dynamic cache, 3 runs each, all in one process. nosync is the same per-row math done fully on the device: no float(amax), scale = where(row_amax > 64, ldexp(1, frexp(row_amax).exponent), 1), and the existing rescale.
variant
generate s
one ExllamaV3Linear, M=1, ms/call
fp16 (native, no pre-scale)
0.85 / 0.86 / 0.86
-
bf16 main
8.95 / 10.71 / 5.66
1.53
bf16 nosync
1.31 / 1.30 / 1.31
0.091
Greedy tokens from main and nosync are identical. The per-row result is the same; only the host read differs. The sync costs 17x per linear and 4-8x per generate call, and makes bf16 timing erratic under load.
Suggested fix
Drop the float(amax) read and keep the decision on the device:
compute row_amax once (it is already computed on the wide path) and derive output_scale = where(row_amax > 64, 2**exponent, 1) unconditionally; the rows that need no scale get 1.0, which is exact;
route non-finite rows without a host decision, for example by computing the FP32 fallback for those rows with torch.where, or by checking isfinite only once at load/warmup. A nan_to_num-free design keeps the current "non-finite goes to the FP32 path" contract without reading back each call.
Test that should have caught it
tests/test_exl3_wide_input.py checks only numerics. A test that runs the BF16 native forward under torch.cuda.graph capture, or with torch.cuda.set_sync_debug_mode("error"), would fail on the host read.
Severity: medium perf. BF16 is the default dtype for EXL3 checkpoints, and decode is 4-8x slower than the same math without the sync on a shared GPU (3.4x on an idle one per #4870's measurements).
Agent claim released:agent-root-4955 opened and squash-merged #4989 (merge commit 450774e7a). The BF16 pre-scale decision now stays on the device: no float(amax) host read per forward, 0/20 syncs vs 20/20 on main, 2.2-2.5x per-call latency in a deep-queue A/B.
Activity
Qubitium commentedon Nov 17, 2026
Agent claim:
agent-root-4955is working on this issue now.Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83is no longer working on this issue.The issue is free to claim.
PR #4989 already covers this; releasing so the claim does not block it.
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-root-4955opened and squash-merged #4989 (merge commit450774e7a). The BF16 pre-scale decision now stays on the device: nofloat(amax)host read per forward, 0/20 syncs vs 20/20 on main, 2.2-2.5x per-call latency in a deep-queue A/B.perf(exl3): keep the bf16 pre-scale decision on the device (ModelClou…