Skip to content

[PERF] AUTO picks ExllamaV2 for bf16 asym 4-bit GPTQ; its bf16 path rebuilds a dense fp16 weight + fp32 copy on every forward (~10–20× slower, ~266 MiB scratch per 4096×11008 layer) #4213

Closed

Description

@Qubitium

Severity: medium (output is correct)
Version: 7.11.0 @ 9dad249

Summary

  • gptqmodel_ext/exllamav2/ext_gptq.cpp:144-161: for any input that isn't kHalf, it reconstructs the full fp16 weight and runs at::matmul(a.to(kFloat), weights.to(kFloat)). ext_awq.cpp:~122 does the same.
  • nn_modules/qlinear/exllamav2.py:76 declares SUPPORTS_DTYPES = [fp16, bf16, fp32].
  • ExllamaV2 has priority 80, ahead of TritonV2 (40), and Marlin is sym-only. So for asym bf16 checkpoints, AUTO puts ExllamaV2 first.

In practice, a real asym Qwen2.5-0.5B GPTQ checkpoint loaded with dtype=bf16 selected ExllamaV2Linear for 168/168 layers.

Reproduce (RTX 4090)

import time, torch
from gptqmodel.nn_modules.qlinear.exllamav2 import ExllamaV2Linear
from gptqmodel.utils.exllamav2 import ScratchSpace
from gptqmodel.utils.importer import select_quant_linear
from gptqmodel.utils.backend import BACKEND
from gptqmodel.quantization import FORMAT, METHOD
dev = torch.device("cuda:0")
print([c.__name__ for c in select_quant_linear(bits=4, group_size=128, desc_act=False, sym=False, device=dev,
      backend=BACKEND.AUTO, format=FORMAT.GPTQ, quant_method=METHOD.GPTQ, pack_dtype=torch.int32,
      dtype=torch.bfloat16, multi_select=True)])
K, N = 4096, 11008
for dt in (torch.float16, torch.bfloat16):
    m = ExllamaV2Linear(bits=4, group_size=128, sym=False, desc_act=False, in_features=K, out_features=N, bias=False,
                        pack_dtype=torch.int32, register_buffers=True, dtype=dt)
    g = torch.Generator().manual_seed(0)
    m.qweight.copy_(torch.randint(-2**31, 2**31-1, m.qweight.shape, generator=g, dtype=torch.int64).to(torch.int32))
    m.qzeros.copy_(torch.randint(-2**31, 2**31-1, m.qzeros.shape, generator=g, dtype=torch.int64).to(torch.int32))
    m.scales.copy_(torch.rand(m.scales.shape, generator=g) * 0.01 + 1e-3)
    m = m.to(dev); m.post_init(scratch_space=ScratchSpace(1 << 22, dev)); m.eval()
    x = torch.randn(1, K, device=dev, dtype=dt)
    with torch.inference_mode():
        for _ in range(5): m(x)
        torch.cuda.synchronize(); torch.cuda.reset_peak_memory_stats(); base = torch.cuda.memory_allocated()
        t = time.perf_counter()
        for _ in range(50): m(x)
        torch.cuda.synchronize()
    print(dt, f"{(time.perf_counter()-t)/50*1e6:.0f} us", f"{(torch.cuda.max_memory_allocated()-base)/2**20:.1f} MiB")

AUTO order: ['ExllamaV2Linear', 'TritonV2Linear', 'TorchLinear']. Decode at M=1:

Kernel / dtype Time Transient memory
ExllamaV2 fp16 ~30 µs 1.4 MiB
ExllamaV2 bf16 ~650–680 µs 266 MiB
TritonV2 bf16 ~60–175 µs 0 MiB

Expected

Don't rank ExllamaV2 first for non-fp16 activations: restrict SUPPORTS_DTYPES to fp16 for AUTO, or demote it for bf16.

Minor: with a bias, bf16 output is rounded twice (kernel → bf16, then + fp32 bias → cast) because wide_bias applies only to fp16 (exllamav2.py:~312). That is within one ulp.


Found during an AI-assisted review (Claude Code) of 9dad249; repros were run on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions