Skip to content

[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

Closed

Description

@Qubitium

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).

Repro

m = GPTQModel.load("<EXL3 4-bit Llama-3.1-8B ckpt>", backend=BACKEND.AUTO, dtype=torch.bfloat16)
lin = m.model.model.layers[0].mlp.gate_proj            # ExllamaV3Linear
x = torch.randn(1, 1, 4096, device="cuda", dtype=torch.bfloat16)
import time
with torch.inference_mode():
    for xx in (x, x.half()):
        for _ in range(10): lin(xx)
        torch.cuda.synchronize(); t = time.perf_counter()
        for _ in range(200): lin(xx)
        torch.cuda.synchronize(); print(xx.dtype, (time.perf_counter() - t) / 200 * 1e6, "us")
# torch.bfloat16 96.2 us / torch.float16 33.0 us

Suggested fix

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.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions