Repository navigation
perf(auto): stop ranking ExLlamaV2 first for bf16/fp32 GPTQ (#4213) - #4277
Merged
Merged
Conversation
) 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4213
Problem
AUTO ranked
ExllamaV2Linearfirst for asym 4-bit GPTQ even when the modeldtype is
bf16(orfp32). The extension only has a native quantized GEMM forFP16 activations; every other dtype falls into
ext_gptq.cpp:144, whichreconstructs the full FP16 weight and an FP32 copy on every forward:
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(whichwould also reject an explicit
backend=GPTQ_EXLLAMA_V2request):BaseQuantLinear.auto_select_priority(fmt, dtype)returns the declaredSUPPORTS_FORMATSrank by default.ExllamaV2Linearlowers its rank for any activation dtype other than FP16(
AUTO_NON_FP16_PRIORITY = 1, below TritonV2=40 and TorchLinear=20). It neverraises the declared rank.
select_quant_linearstable-sorts the AUTO candidates with that rank for therequested dtype. Equal ranks keep the declared order, and
dtype=Noneisunchanged.
SUPPORTS_DTYPESstill advertises FP16/BF16/FP32, so explicit backendselection and
fp32(where ExLlamaV2 is the only GPTQ kernel) are unchanged.AUTO order for
bits=4, group_size=128, sym=False, desc_act=False: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 5rounds, 300 calls/round,
OMP/MKL/OPENBLAS/NUMEXPR=4,torch.set_num_threads(4).peak transientistorch.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, thenx @ Win float64. Random 1024x1024asym 4-bit layer, max relative error vs oracle over the output tensor:
Both bf16 paths stay inside bf16 precision (
eps ~ 7.8e-3); the faster path didnot 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=Noneunchanged)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, identicalset on
origin/main(CPU layout/state-dict tests, unrelated).ruff check gptqmodel docs/eora tests setup.py: all checks passed.Residual risk
backend=GPTQ_EXLLAMA_V2with bf16/fp32 still uses the densefallback. That is intentional (the user asked for this kernel), but it remains
slow until the extension grows a bf16 quantized GEMM.
AwqExllamaV2Linearhas the same dense fallback inext_awq.cpp, but AUTOalready prefers
AwqMarlinLinearfor bf16 on this host, so it was leftunchanged rather than re-ranking an unmeasured path.
example
fp32GPTQ), ExLlamaV2 is still selected.