Skip to content

[BUG] GGUFConfig(bits=4) default q4_0 (and q5_0) quantize crashes with backend=AUTO (CUDA+ROCm: GGUFTritonKernel selected, no fallback); [ROCm] AWQ format=gemv AUTO quantize picks CUDA-only AWQ_GEMV #4107

Closed

Description

@Qubitium

Audit of main @ a15e6bf. The affected files are unchanged through 110136f. Platforms: RTX 4090 (CUDA) and R9700 gfx1201 (ROCm 10.1). Found during an end-to-end ROCm method/kernel matrix (quantize → save → reload → wikitext-2 PPL).

1. GGUFConfig(bits=4) (default q_0 → Q4_0) and q5_0 crash in quantize() with backend=AUTO, on CUDA and ROCm (medium)

GGUFConfig(bits=4) resolves to format="q_0", i.e. Q4_0. When packing, AUTO selection (models/base.py:1989/2030, select_quant_linear) looks only at the bit width. So Q4_0 and Q5_0 select GGUFTritonKernel (SUPPORTS_BITS [1,4,5,6]), whose constructor (nn_modules/qlinear/gguf_triton.py:1786-1791) only accepts Q1_0/Q4_K/Q5_K/Q6_K. The load path (create_quant_layer, utils/model.py:884) catches that NotImplementedError and falls back to GGUFTorchLinear. The weight-only finalize path (looper/weight_only_processor.py:212-229 → create_quant_module, utils/model.py:808) passes a single class and has no fallback, so quantization aborts on the first module:

GPTQModel.load(Qwen2.5-0.5B-Instruct, GGUFConfig(bits=4)).quantize(None, backend=BACKEND.AUTO)
  RTX 4090 -> NotImplementedError: GGUFTritonKernel only supports fused GGUF Triton formats (Q1_0, Q4_K, Q5_K, Q6_K). Actual GGUF qtype: Q4_0.
  R9700    -> same;  format="q_0", bits=5 -> same with Q5_0
AUTO pack selection: q4_0 -> GGUFTritonKernel, q5_0 -> GGUFTritonKernel, q4_k_m -> GGUFTritonKernel (ok), q8_0 -> GGUFTorchLinear (ok)
backend=BACKEND.GGUF_TORCH, q4_0 -> OK, PPL 21.135 (fp16 base 18.549)

Fix: make GGUFTritonKernel.validate / select_quant_linear aware of the GGUF qtype so non-fused qtypes are rejected during selection, or reuse create_quant_layer's NotImplementedError candidate fallback in create_quant_module. tests/test_weight_only.py::test_baseqmodel_quantize_allows_direct_gguf_export parametrizes only K formats; add q_0 4/5 (the default for bits=4).

2. [ROCm] AWQ format=gemv quantize with backend=AUTO fails before calibration, although AWQ_GEMV_TRITON packs the same layout (low)

models/base.py:1927-1928 hardcodes preferred_backend = BACKEND.AWQ_GEMV, which is the CUDA-only AwqGEMVLinear. GEMM switches to a portable packer through awq_gemm_pack_backend(is_rocm=...), and QQQ has a ROCm branch, but GEMV has neither:

ROCm, AWQConfig(bits=4, group_size=128, format=FORMAT.GEMV).quantize(..., backend=AUTO)
  -> ValueError: AwqGEMVLinear does not support device: DEVICE.ROCM (AwqGEMVLinear is CUDA-only ...; select a portable `*Torch` or `*Triton` backend ...)
backend=BACKEND.AWQ_GEMV_TRITON -> OK; reload -> AwqGEMVTritonLinear, "The capital of France is Paris…",
  PPL(40 win) 23.66 vs GEMM-format AWQ 23.69; decode M=1/2/5/16 vs prefill OK

The error message suggests a *Torch backend, but AWQ_TORCH does not accept GEMV. Fix: BACKEND.AWQ_GEMV_TRITON if IS_ROCM else BACKEND.AWQ_GEMV. tests/test_rocm_awq_gemv_gating.py only covers loading; add a quantize case.

Minor: the TorchFusedLinear / TorchFusedAwqLinear rejection message on ROCm says "CUDA-only", but these classes are CPU/XPU kernels.

Checked on ROCm (R9700), matches CUDA

Qwen2.5-0.5B and Llama-3.2-1B, 80×512 wikitext-2:

Open lead, not filed as a bug: VPTQ PPL on ROCm is 18–23% above the CUDA numbers from older commits (Qwen 70.5–73.3 vs 59.5, Llama 82.4 vs 69.7). Per-module quantization losses match CUDA within ±3%. ROCm inference matches CPU fp32, and the old source gives the same PPL on ROCm. We could not determine the cause without a CUDA run at HEAD cross-evaluated on ROCm.

🤖 Generated with Claude Code

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