Skip to content

[BUG] Follow-up on #4060/#4062: model.optimize() TypeError on all CPU AUTO kernels, torch.compile int4pack LoweringException for fp16+bias (regression) and bf16, max_memory still ignored with device="cuda:0" #4068

Closed

Description

@Qubitium

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

Plausible, not verified

🤖 Generated with Claude Code

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