Skip to content

[BUG] Kernels/dispatch: AWQ GEMV_FAST drops K-tiles when K/128 odd (Qwen2.5-0.5B), AWQ GEMV OOB read -> NaN, CPU AUTO TorchFused crash for g-1/g16, torch.compile addmm failure, device_map CPU entries crash #4054

Closed

Description

@Qubitium

Backend-dispatch and inference audit on sm_89 (plus 2-GPU runs). Test model: a 4-layer truncated real Qwen2.5-0.5B-Instruct (K = 896 / 4864) quantized in 19 variants (GPTQ 2/3/4/8-bit, gs −1/16/32/64/128, sym/asym, desc_act, v1/v2, bf16, mixed dynamic; AWQ gemm/gemv/gemv_fast), plus the real Qwen2.5-0.5B-Instruct-GPTQ-Int4 / -AWQ. Found at e6b19c5 and re-checked on main @ 39cd57a.

Checked and working:

  • AUTO picks a valid kernel for every GPU config, including per-module kernels for mixed dynamic bits.
  • Every explicit backend either agrees with TorchLinear (rel ≤ 2e-3) or rejects cleanly.
  • Greedy generate matches the token-by-token argmax with cache on, cache off and static cache.
  • Batched left-pad and assisted generation work.
  • device_map="auto" / "balanced" / manual 2-GPU maps give identical logits.
  • .half() / .bfloat16() / .train() errors are clean.

1. AWQ GEMV_FAST prefill drops K-tiles when K/128 is odd: wrong output for M = 2..32 and batch ≥ 8 decode (high, silent)

gptqmodel_ext/awq/quantization_new/gemm/gemm_cuda.cu:957 takes the M ≤ 32 branch with SPLITK = 2, CTA_K = 128:

  • :341 sets cta_offset_k = z * (K / SPLITK).
  • :351 sets gemm_iters = ceil(K / CTA_K) / SPLITK using integer division.

For K = 896 that is 7 tiles, so each split runs 3 of them and K-ranges [384, 448) and [832, 896) are never computed. AwqGEMVFastLinear declares SUPPORTS_IN_FEATURES_DIVISIBLE_BY=[64], so validation accepts the shape. gemv_fast_awq.py sends every prompt of ≤ 32 tokens, and any decode step with batch ≥ 8, to this kernel.

Relative error vs an exact-dequant reference (negative M = batch-of-|M| decode):

K 896 : M=1 4e-4  M=7 0.579  M=32 0.690  M=33 4e-4  M=100 4e-4  M=-8 0.564  M=-16 0.623
K 1024: 4e-4 everywhere          (K 1152 / 1408: ~0.55 for M=7/32;  K 4864: 4e-4)
model: logits vs dense 1.02 for gemv_fast vs 0.27 for gemm/gemv from the same AWQ search; batched-vs-single 0.8-0.9 with different argmax

Real Qwen2.5-0.5B (hidden 896) is affected. Fix: use SPLITK=2 only when (K / CTA_K) % 2 == 0 (otherwise the SPLITK=1 config), give the last split the remainder tiles, or reject odd K/128 in validate. No test exercises GEMV_FAST prefill numerically; the existing tests monkeypatch the kernel.

2. AWQ GEMV CUDA (gemmv2, M > 8) reads past the end of the row when (IC/32) % split_k ≠ 0, giving NaN rows (high)

gptqmodel_ext/awq/quantization/gemm_cuda_gen.cu:628:

int k_bound = make_divisible(IC / 32, split_k_iters);
if ((k_bound - 1) * 32 + blockIdx_z >= IC) k_bound -= 1;   // compares a tile index with a column count

For IC = 896 and split_k = 8, splits z = 4..7 process k-tiles 28..31, reading past the row (into the next row) and past the end of the activation buffer for the last row. The padded scales are zero, so results are usually right by accident. But when the memory after the input holds a non-finite value, 0·NaN poisons the row:

real model, AwqGEMVLinear: NONFINITE at decode step 4, len 9, model.layers.0.self_attn.q_proj (input max 1.78); greedy generate diverges
same model, AwqGEMVTritonLinear: no non-finite values;   K = 4864: clean

Fix: if ((k_bound - 1) * split_k_iters + blockIdx_z >= IC / 32) k_bound -= 1;, or skip k_0_0 >= IC/32 inside the loop.

3. CPU AUTO picks TorchFusedLinear for group_size −1 or 16, then the first forward crashes (medium-high)

nn_modules/qlinear/torch_fused.py:72 declares SUPPORTS_GROUP_SIZE = [-1, 16, 32, 64, 128], but the CPU op _weight_int4pack_mm_for_cpu only accepts 32/64/128/256. TorchAtenLinear correctly rejects these sizes, so AUTO (which prefers trainable kernels on CPU) falls through to TorchFused. The load succeeds, and then:

RuntimeError: _weight_int4pack_mm_cpu: expect qGroupSize to be 32, 64, 128 or 256, got 896   (or "got 16")

This hits every per-channel or g16 4-bit GPTQ checkpoint loaded on CPU with default settings. TorchFusedAwq inherits the same list. Fix: on CPU, validate the resolved group size against {32, 64, 128, 256} (XPU can keep −1), or fall back to dequant + matmul.

4. torch.compile fails for TorchLinear / AwqTorchLinear with a bias, so 3-bit GPTQ on CUDA crashes with cache_implementation="static" (medium)

nn_modules/qlinear/_numerics.py:146 calls torch.addmm(bias.float(), x, w, out_dtype=torch.float32), which Inductor (torch 2.15) can't lower:

LoweringException: TypeError: tuned_addmm() takes 3 positional arguments but 4 were given

A pure-torch repro reproduces it. The line came in with #3649 (bias before output rounding). AUTO selects TorchLinear for 3-bit on CUDA, and Qwen q/k/v have a bias, so generate(cache_implementation="static") crashes for 3-bit and for mixed-dynamic models. Fix: use torch.mm(..., out_dtype=torch.float32) + bias.float(), or branch on torch.compiler.is_compiling().

5. W4AFP8Linear (explicit gptq_w4afp8, accepted on sm_89) crashes under torch.compile / static cache (low-medium)

InductorError: NameError: name 'gl' is not defined: Inductor codegens the Gluon kernel without the gl namespace. Fix: wrap the launch in a torch.library.custom_op, or mark it torch.compiler.disable.

6. A device_map with CPU-offload entries makes AUTO pick a CUDA-only kernel, so the load crashes (medium)

utils/importer.py:1088-1095 ignores CPU map entries when selecting the kernel, and the loader then runs post_init on modules that are on CPU:

device_map with model.layers.2/3: "cpu" -> AUTO picks Marlin / ExLlamaV2 / AwqMarlin
-> ValueError: GPTQ Marlin requires CUDA tensors, got cpu   (ExLlamaV2: make_q_matrix ... CPU backend)
explicit gptq_triton / gptq_torch with the same map: works (rel 0.0, generate OK)

Fix: when the map has CPU entries, also validate candidates for CPU-resident post_init (or prefer offload-capable kernels), or run post_init on the execution device.

7. max_memory is silently ignored by GPTQModel.load (low-medium)

build_layerwise_device_map (models/loader.py) is a fixed round-robin, and the max_memory kwarg is swallowed:

  • device_map="auto", max_memory={1: "4GiB"} still puts half the layers on cuda:0.
  • {0: "350MiB", "cpu": "8GiB"} still uses GPU 1 and offloads nothing.

Fix: honour it via infer_auto_device_map, or warn or raise.

Plausible, unverified:

  • A failed .train() leaves 6/59 modules with training=True, because the error is raised midway.
  • The explicit-backend branch of select_quant_linear (importer.py ~1488) doesn't pass adapter to validate.
  • The error text at nn_modules/qlinear/__init__.py:951, 976 reads "only supports [False] bits: actual desc_act".

🤖 Generated with Claude Code

Activity

  1. added
    bug
    on Nov 14, 2026
  2. Qubitium commented on Nov 14, 2026

    @Qubitium
    CollaboratorAuthor

    Resolved by #4058 (items 1-2: gemm_w4a16_T1 split-K now partitions whole CTA_K tiles so odd K/128 counts no longer drop tail tiles, and gemmv2 k-tile bounds are computed in tile units so the out-of-bounds read that produced NaN rows is gone) and #4062 (items 3-7: CPU int4pack group-size gate for g-1/g16, torch.compile bias epilogue + W4AFP8, CPU-offload-aware kernel selection, and max_memory honoured by greedy layer placement).

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions