You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] #5277 (fix of #5262) incomplete: without a prior import gptqmodel, plain transformers from_pretrained(device_map="auto", max_memory=<CPU/disk spill>) of a third-party AWQ checkpoint still raises 'AWQ Marlin requires CUDA tensors' #5395
Found on main @ 1405751, RTX 5090 (single visible GPU), torch 2.15 + CUDA 13.2, transformers 5.23.0.
What is wrong
#5277 (fix of #5262) rebuilds offload-safe kernels for third-party AWQ/GPTQ checkpoints after transformers resolves device_map="auto" + max_memory. The rebuild runs from the validate_environment wrapper that import gptqmodel installs on AwqQuantizer (gptqmodel/__init__.py:842-940). transformers' AwqQuantizer does not import gptqmodel before it validates. The first import happens inside replace_with_awq_linear (transformers/integrations/awq.py:76), after validate_environment has already run. _ensure_transformers_awq_gptqmodel_load_bridge documents this. For that late-import case the post-weight hook rebuilds the dynamic geometry (#4795/#5322). It does not rebuild the offload kernel selection.
So when a process loads its first AWQ checkpoint without import gptqmodel first, the #5262 fix is skipped. AUTO picks AwqMarlinLinear for modules that end up on CPU or disk, and the load raises exactly as in #5262. Later loads in the same process work, because the bridge is installed by then. GPTQ checkpoints are not affected: Optimum's GPTQ quantizer imports gptqmodel early. The import gptqmodel first-line variant from #5262 now passes.
Repro
Each block runs in a fresh process. AWQ-Llama-3.2-1B-g128-gemm is the AutoAWQ GEMM checkpoint from #5194/#5262.
importtorchfromtransformersimportAutoModelForCausalLM# no `import gptqmodel`ck="AWQ-Llama-3.2-1B-g128-gemm"m=AutoModelForCausalLM.from_pretrained(ck, dtype=torch.float16, device_map="auto",
max_memory={0: "300MiB", "cpu": "20GiB"})
ValueError: AWQ Marlin requires CUDA tensors, got `cpu`.
The same holds with max_memory={0: "300MiB", "cpu": "200MiB"}, offload_folder=...:
RuntimeError: CPU-offloaded Marlin requires a writable in-memory weights map: ['qweight', 'qzeros', 'scales'] are disk-backed entries that `post_init` ...
Controls on the same box, each in a fresh process:
first statement / ordering
cpu spill
disk spill
no import, AWQ-Llama first load
ValueError (Marlin)
RuntimeError (Marlin)
no import, after one earlier device_map="cuda:0" AWQ load in the same process
OK, TorchAtenAwqLinear, same greedy tokens
OK
import gptqmodel before transformers
OK
OK
import gptqmodel after from transformers import ...
OK
OK
no import, GPTQ without meta (Llama-3.2-1B-Instruct-GPTQ-4bits-gp128 with meta stripped)
OK
OK
no import, GPT-QModel AWQ ckpt (Llama-3.2-1B-Instruct-AWQ-bit4-g128-symFasle-descFalse)
OK
OK
Suggested fix
In the late-import path of _post_init_with_gptqmodel_bridge (the context is None branch, right after hf_gptqmodel_repair_awq_load), build the same hf_gptqmodel_reselect_context(...) that the validate_environment wrapper builds. Read the resolved model.hf_device_map there and run hf_gptqmodel_reselect_offloaded_kernels. Alternatively, have hf_select_quant_linear_v2 (which replace_with_awq_linear calls with the device map) treat an accelerate map that contains cpu/disk entries as cpu_offload=True.
Test that should have caught it
tests/test_hf_bridge_cpu_offload_5022.py / the #5277 tests import gptqmodel at module top, so the bridge is always installed before transformers validates. Add a subprocess test that runs from transformers import AutoModelForCausalLM only, then loads a third-party AWQ GEMM checkpoint with device_map="auto" and a CPU spill.
Severity
Medium. The failure is loud with no corruption. But "plain transformers, no extra import" is how most users load Hub AWQ checkpoints, and #5194/#5262 are closed as fixed for this exact checkpoint and call.
Activity
ZX-ModelCloud commentedon Nov 19, 2026
Agent claim released:
agent-13d0a0c8099cfinished this issue.Pull request: #5543
Reproducing the late-import AWQ offload kernel reselection failure, then fixing it with a subprocess regression test
docs(hf): document the AWQ late-import offload kernel selection (#5395)
fix(hf): reselect AWQ offload kernels when the bridge is imported mid…