Skip to content

perf(auto): stop ranking ExLlamaV2 first for bf16/fp32 GPTQ (#4213) - #4277

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4213-exllamav2-bf16-dense
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4213-exllamav2-bf16-dense

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4213

Problem

AUTO ranked ExllamaV2Linear first for asym 4-bit GPTQ even when the model
dtype is bf16 (or fp32). The extension only has a native quantized GEMM for
FP16 activations; every other dtype falls into ext_gptq.cpp:144, which
reconstructs the full FP16 weight and an FP32 copy on every forward:

auto weights = torch::empty({qm->height, qm->width}, a.options().dtype(at::kHalf));
qm->reconstruct(...);
c.copy_(at::matmul(a.to(at::kFloat), weights.to(at::kFloat)));

That is a per-token 266 MiB scratch allocation and ~3.8x slower than a native
bf16 kernel on the same layer.

Fix

Make the AUTO rank dtype-aware instead of changing SUPPORTS_DTYPES (which
would also reject an explicit backend=GPTQ_EXLLAMA_V2 request):

  • BaseQuantLinear.auto_select_priority(fmt, dtype) returns the declared
    SUPPORTS_FORMATS rank by default.
  • ExllamaV2Linear lowers its rank for any activation dtype other than FP16
    (AUTO_NON_FP16_PRIORITY = 1, below TritonV2=40 and TorchLinear=20). It never
    raises the declared rank.
  • select_quant_linear stable-sorts the AUTO candidates with that rank for the
    requested dtype. Equal ranks keep the declared order, and dtype=None is
    unchanged.

SUPPORTS_DTYPES still advertises FP16/BF16/FP32, so explicit backend
selection and fp32 (where ExLlamaV2 is the only GPTQ kernel) are unchanged.

AUTO order for bits=4, group_size=128, sym=False, desc_act=False:

dtype before after
fp16 ExllamaV2, TritonV2, Torch ExllamaV2, TritonV2, Torch
bf16 ExllamaV2, TritonV2, Torch TritonV2, Torch, ExllamaV2
fp32 ExllamaV2 ExllamaV2

Measurements

Host: idle RTX 4090 (index 3, UUID GPU-d458708b-c760-bbf1-08fb-8b8803a2157d),
CUDA 13.0, torch 2.16.0.dev20261102+cu130, Triton 3.9.0. Layer shape
4096 x 11008, 4-bit, group 128, asym, no bias, no act-order. Median of 5
rounds, 300 calls/round, OMP/MKL/OPENBLAS/NUMEXPR=4, torch.set_num_threads(4).

M path median peak transient
1 before: ExllamaV2 bf16 640.3 us 266.2 MiB
1 after: TritonV2 bf16 168.1 us (3.8x) 94.2 MiB (-172.0)
8 before: ExllamaV2 bf16 613.5 us 266.8 MiB
8 after: TritonV2 bf16 199.5 us (3.1x) 94.5 MiB (-172.3)
64 before: ExllamaV2 bf16 635.7 us 271.2 MiB
64 after: TritonV2 bf16 209.5 us (3.0x) 96.8 MiB (-174.4)
1 reference: ExllamaV2 fp16 23.4 us 1.4 MiB

peak transient is torch.cuda.max_memory_allocated() - memory_allocated()
after reset_peak_memory_stats(), per the reproduction in the issue.

Numerics

Independent FP64 oracle: unpack the int32 nibbles explicitly, compute
W = (q - z[g]) * s[g] in float64, then x @ W in float64. Random 1024x1024
asym 4-bit layer, max relative error vs oracle over the output tensor:

path max abs max rel
ExllamaV2 bf16 2.97e-02 2.80e-03
TritonV2 bf16 (new AUTO pick) 5.03e-02 4.75e-03
ExllamaV2 fp16 3.47e-03 3.28e-04
TritonV2 fp16 5.88e-03 5.55e-04

Both bf16 paths stay inside bf16 precision (eps ~ 7.8e-3); the faster path did
not change numerics beyond the requested dtype.

Tests

  • tests/kernels/test_selection.py::test_exllamav2_auto_priority_demotes_dense_non_fp16_fallback
    (rank + explicit-backend support)
  • tests/kernels/test_selection.py::test_auto_reranks_candidates_for_the_requested_dtype
    (importer re-ranks, keeps all candidates, dtype=None unchanged)
  • tests/kernels/test_selection.py::test_auto_bf16_prefers_a_native_kernel_over_exllamav2_dense_fallback
    (real AUTO order on CUDA; skipped without the ExLlamaV2 runtime)

tests/kernels/test_selection.py: 142 passed, 42 skipped.
tests/test_auto_module_decoder.py: 39 passed, 2 skipped.
tests/test_kernel_audit_regressions.py: 21 pre-existing failures, identical
set on origin/main (CPU layout/state-dict tests, unrelated).
ruff check gptqmodel docs/eora tests setup.py: all checks passed.

Residual risk

  • Explicit backend=GPTQ_EXLLAMA_V2 with bf16/fp32 still uses the dense
    fallback. That is intentional (the user asked for this kernel), but it remains
    slow until the extension grows a bf16 quantized GEMM.
  • AwqExllamaV2Linear has the same dense fallback in ext_awq.cpp, but AUTO
    already prefers AwqMarlinLinear for bf16 on this host, so it was left
    unchanged rather than re-ranking an unmeasured path.
  • The demotion is by rank only; if no native non-fp16 kernel is valid (for
    example fp32 GPTQ), ExLlamaV2 is still selected.

)

AUTO ranked ExLlamaV2 first for asym 4-bit GPTQ even when the requested
activation dtype is bf16 or fp32. The extension only has a native
quantized GEMM for fp16; every other dtype reconstructs the full fp16
weight and an fp32 copy on every forward (266 MiB / ~640 us for a
4096x11008 layer).

Make the AUTO rank dtype-aware: BaseQuantLinear.auto_select_priority()
defaults to SUPPORTS_FORMATS, and ExllamaV2Linear demotes itself below
kernels with a native non-fp16 path. Explicit backend selection is
unchanged, and fp32 still resolves to ExLlamaV2 when it is the only
kernel that supports the dtype.

Measured on an idle RTX 4090 (M=1, 4096x11008, sym=False):
  before (ExllamaV2 bf16): 640.3 us, 266.2 MiB peak
  after  (TritonV2 bf16):  168.1 us,  94.2 MiB peak
fp16 keeps ExllamaV2 first (23.4 us, 1.4 MiB).

Fixes #4213
@Qubitium
Qubitium merged commit f7ef43e into main Nov 16, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/issue-4213-exllamav2-bf16-dense branch November 16, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant