Repository navigation
Description
Audit of main @ ad0525c, RTX 4090 + CPU. These follow up on #4060 (for #4051) and #4062 (for #4054). A differential fuzz of every GPTQ/AWQ kernel, CUDA and CPU, against an fp64 dequant reference came back clean (details at the end). The three remaining defects are all on dispatch, compile or placement paths.
1. GPTQModel.optimize() / .compile() raises TypeError on every model that uses the CPU AUTO kernels (medium)
models/base.py:3210 calls modules[name].optimize(fullgraph=False, backend=backend, mode=mode). Five kernels override optimize(self) with no parameters:
TorchAtenLinear(torch_aten_kernel.py:150)TorchFusedLinear(torch_fused.py:225)TorchFusedAwqLinear(torch_fused_awq.py:165)TorchAtenAwqLinear(torch_aten_kernel_awq.py:139)TorchInt8Linear(torch_int8.py:392)
Qwen2.5-0.5B-Instruct-gptq-4bit on CPU (168 x TorchAtenLinear), model.optimize()
TypeError: TorchAtenLinear.optimize() got an unexpected keyword argument 'fullgraph'
Fix: give the overrides the base signature (backend="inductor", mode=None, fullgraph=False) and forward it to super(). Add a CPU model.optimize() test. After this fix, item 2 is the next failure.
2. torch.compile of the CPU int4pack path fails for fp16+bias (regression from #4060) and for all bf16
torch_fused.py _cpu_int4pack_mm (~L47-64) does x.to(float32) and then calls aten._weight_int4pack_mm_for_cpu. Inductor fuses the cast into a Pointwise node and then can't lower the int4pack op on it. Since #4060, biased fp16 layers also take this fp32 path (fused_bias_safe); before #4060 they took the dense path, which compiled.
fp16 no-bias fp16 + bias bf16 (+/- bias)
main @ ad0525c OK 3.1e-4 COMPILEFAIL COMPILEFAIL
tree before #4060 OK OK (3.6e-4) COMPILEFAIL
InductorError: LoweringException: AssertionError: <class 'torch._inductor.ir.Pointwise'>
pure torch: x.to(fp32) -> _weight_int4pack_mm_for_cpu under torch.compile -> same LoweringException; without the cast -> OK
TorchAten is the CPU AUTO kernel for fp16, and Qwen's q/k/v have a bias, so optimize() / static-cache compile on CPU breaks for common models. The AWQ variants compile fine. Fix: put torch.compiler.disable on _cpu_int4pack_mm, or register it as a torch.library.custom_op.
3. max_memory is still silently ignored when an indexed device is passed (gap in #4062)
In models/loader.py, the "either device_map or max_memory" check runs at ~L1915. Only afterwards (~L1931-1939) does device="cuda:0" / torch.device become explicit_device_map = {"": device}. So build_layerwise_device_map(max_memory=...) is never called, and the cap is dropped without a warning:
Llama-3.2-1B GPTQ, max_memory={0: "300MiB", "cpu": "20GiB"}
device=None / "auto": {'cpu': 705, 'cuda:0': 3} (cap honoured)
device="cuda:0": {'cuda:0': 708} (all 985 MiB on the GPU)
Fix: convert the indexed device before running the conflict check, so the two options are rejected together, or use that device as the accelerator for the budgeted layer-wise map.
Checked, clean
- GPTQ on CUDA (TorchLinear, TritonV2, Marlin, ExLlamaV2):
- bits 2/3/4/8, group sizes -1/32/64/128, sym/asym, desc_act with g_idx;
- fp16/bf16, M in {0…1024}, 3-D and strided inputs;
- shapes up to 5632×1536.
- AWQ on CUDA: Torch, GEMM, GEMM-Triton, Marlin, ExLlamaV2, GEMV and GEMV-Fast, including K=896/4864/5632/96/160 (the fix(awq): cover every split-K tile and bound gemmv2 k-tiles (#4054) #4058 split-K and gemmv2 bounds).
- CPU kernels: TorchFused, TorchAten, Avx512 and Int8 (GPTQ and AWQ variants).
- Across all of the above: no NaN/inf, nothing worse than the TorchLinear peer, and unsupported configs are rejected by
validate_quant_linear. - fp16 pre-bias overflow that the bias cancels (|pre-bias| up to 1.08e5): every kernel stays finite in eager mode, so fix(moe,awq,kernels,server): keep padding out of expert Hessians and restore live paths (#4051) #4060's fp32 product works.
- torch.compile on CUDA (GPTQ torch/tritonv2/marlin/exllamav2, AWQ torch/gemm/triton/marlin) matches eager, so fix(dispatch): CPU group-size gate, CPU-offload kernel choice, max_memory, compile paths (#4054) #4062's addmm path is fine.
- fix(models): honor third-party checkpoint interop in save, Marlin, and export (#4053) #4059 / fix(models): honor third-party checkpoint filters and layouts (#4053) #4061 re-save: an asym v1 Llama-1B re-saves bitwise identical (336/336 tensors) with identical reloaded logits.
- fix(dispatch): CPU group-size gate, CPU-offload kernel choice, max_memory, compile paths (#4054) #4062 CPU group-size gate: behaves as intended.
Plausible, not verified
- XPU: fix(moe,awq,kernels,server): keep padding out of expert Hessians and restore live paths (#4051) #4060 sets
fused_bias_safefor fp16 on every device, but on XPU_weight_int4pack_mm_with_scales_and_zerosstill returns an fp16 product before the bias add, so the overflow fix(moe,awq,kernels,server): keep padding out of expert Hessians and restore live paths (#4051) #4060 fixed on CPU may still occur there. - fix(config): normalize EXL3 serialization and reject silent kwarg drops (#4052) #4057:
_validate_bool_fieldsnow raises on 0/1 forsym/desc_act, where they used to be coerced. Legacy hub configs that store ints would stop loading. None of the 325 local checkpoints do this.
🤖 Generated with Claude Code
Activity
fix(dispatch): repair CPU optimize/compile, max_memory and HIP/autogr…
perf(cpu): make quantized CPU kernels torch-compilable and graph-safe (…
perf(cpu): make NF12, Paro and QQQ inductor-ready on CPU (#5075)
fix(compile): make the int4pack cast path a traceable custom op (#5110)…
fix(paro): trace the biased CPU int4pack path after an eager warmup (#…