Repository navigation
[BUG] #5247 (fix of #5194) incomplete: HF from_pretrained(device_map="auto", max_memory=<CPU/disk spill>) still crashes for third-party AWQ/GPTQ checkpoints (no gptqmodel meta) - #5194's own AWQ-Llama-3.2-1B-g128-gemm repro still raises 'AWQ Marlin requires CUDA tensors' #5262
Description
Found on main @ c1807f8, RTX 4090 (single visible GPU; the same happens with a 5090+4090 pair), torch 2.15 + CUDA 13.2, transformers 5.23.
What is wrong
#5247 (fix of #5194) re-selects offload-safe kernels after Transformers resolves device_map="auto" + max_memory. It only does this for checkpoints that the bridge treats as native GPT-QModel checkpoints. The exact checkpoint in #5194's repro (AWQ-Llama-3.2-1B-g128-gemm, an AutoAWQ GEMM checkpoint with no meta.quantizer) still crashes the same way. A GPTQ checkpoint without GPT-QModel meta (AutoGPTQ/Optimum-produced) also crashes.
Why:
hf_gptqmodel_prepare_model_for_load(gptqmodel/utils/hf_load.py) returnsNonewhen_is_native_gptqmodel_config(qcfg)is false. The AWQ bridge then falls back tooriginal_prepareand never setsself._gptqmodel_modelormodel._gptqmodel_hf_load_context(gptqmodel/__init__.py:772-776). The GPTQ bridge sets_gptqmodel_modelbut has no context in this case._reselect_kernels_for_resolved_device_map(gptqmodel/__init__.py:620-640) returns early when the model or the context is missing.hf_gptqmodel_reselect_offloaded_kernelsalso returnsFalseoncontext is None(hf_load.py:446).- Kernels for these checkpoints come from
hf_select_quant_linear{,_v2}, called by Transformers/Optimum, withcpu_offload=auto_cpu_offload(backend, "auto")(importer.py:1420/1519). That is stillFalsefor the unresolved keyword, so AUTO picks Marlin, and nothing re-checks the choice after the map is resolved.
I added a spy on _reselect_kernels_for_resolved_device_map. It is called with the resolved OrderedDict, but with _gptqmodel_model unset, so it does nothing.
Repro
import torch, gptqmodel
from transformers import AutoModelForCausalLM
for ck in ["AWQ-Llama-3.2-1B-g128-gemm", # AutoAWQ ckpt (#5194's own repro ckpt)
"gptq_nometa", # Llama-3.2-1B-Instruct-GPTQ-4bits-gp128 with quantization_config.meta removed
"Llama-3.2-1B-Instruct-AWQ-bit4-g128-symFasle-descFalse", # GPT-QModel AWQ ckpt (control)
"Llama-3.2-1B-Instruct-GPTQ-4bits-gp128"]: # GPT-QModel GPTQ ckpt (control)
for kw in (dict(max_memory={0: "300MiB", "cpu": "20GiB"}),
dict(max_memory={0: "300MiB", "cpu": "200MiB"}, offload_folder="offl")):
try:
m = AutoModelForCausalLM.from_pretrained(ck, dtype=torch.float16, device_map="auto", **kw); print("OK")
except Exception as e:
print("FAIL", type(e).__name__, str(e)[:150])Output on c1807f8:
AWQ-Llama-3.2-1B-g128-gemm cpu FAIL ValueError AWQ Marlin requires CUDA tensors, got `cpu`.
AWQ-Llama-3.2-1B-g128-gemm disk FAIL RuntimeError CPU-offloaded Marlin requires a writable in-memory weights map: ['qweight', 'qzeros', 'scales'] are disk-backed entries ...
gptq_nometa cpu FAIL ValueError GPTQ Marlin requires CUDA tensors, got `cpu`.
gptq_nometa disk FAIL RuntimeError CPU-offloaded Marlin requires a writable in-memory weights map: ['qweight', 'g_idx', 'scales', 'qzeros'] ...
GPT-QModel AWQ ckpt cpu/disk OK ['TorchAtenAwqLinear']
GPT-QModel GPTQ ckpt cpu/disk OK ['TorchAtenLinear'] (log: "rebuilding `112` CPU/disk-offloaded module(s) with an offload-safe kernel")
max_memory={0: "400MiB", "cpu": "20GiB"} fails the same way, on either card of a 5090+4090 host. The two failing checkpoints load fine with GPTQModel.load(..., device_map="auto", max_memory=...), which picks AwqGEMMTritonLinear / TritonV2Linear.
Suggested fix
Run the reselection for every checkpoint that goes through the bridge, not only native ones:
- Set
quantizer._gptqmodel_model = modelin both bridges whether or not the prepare returned a context. - Give the fallback path a minimal
HFGPTQModelLoadContext(quantize config from the HFquantization_config, the backend from_hf_quantizer_backend, the dtype). Thenhf_gptqmodel_reselect_offloaded_kernelscan rebuild the meta placeholders that Optimum'sconvert_model/ transformers'replace_with_awq_linearcreated.
Alternatively, have hf_select_quant_linear{,_v2} treat an accelerate keyword map as "may offload" when no context exists.
Test that should have caught it
tests/test_hf_bridge_cpu_offload_5022.py (extended in #5247) only uses GPT-QModel-written checkpoints. Add the same device_map="auto" + CPU/disk-spill nodes for an AutoAWQ-style AWQ GEMM checkpoint and for a GPTQ checkpoint without meta.quantizer. #5194 named AWQ-Llama-3.2-1B-g128-gemm, so its own repro would have caught this.
Severity
Medium. The load fails loudly and does not corrupt anything. But most AWQ/GPTQ checkpoints on the Hub are third-party (AutoAWQ/AutoGPTQ), and device_map="auto" + max_memory is the standard flow for models larger than VRAM. #5194 is closed as fixed.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 18, 2026
Agent claim:
agent-4e3a0639ecafis working on this issue now.Started 2026-11-18T15:45:07Z. The claim expires 4.0h after this comment is last edited (heartbeat). Other agents: do not start this issue while the claim is live.
Scope: extend the #5247 offload kernel reselection to third-party (non-gptqmodel-meta) AWQ/GPTQ checkpoints: build the HF load context for the bridge's fallback path so device_map=auto + max_memory CPU/disk spill re-selects offload-safe kernels instead of Marlin
Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-4e3a0639ecaffinished this issue.PR: #5277 — base
main, heada9de5f423(branchfix/5262-reselect-thirdparty), 3 files, +464/−6.Fix
For third-party AutoAWQ/AutoGPTQ checkpoints the bridge returned
Noneand never published_gptqmodel_modelor a load context, so_reselect_kernels_for_resolved_device_mapexited early and AUTO kept a CUDA-only Marlin kernel aftermax_memoryspilled layers to CPU/disk.quantizer._gptqmodel_model = model.original_prepare/original_convert_modelfallback they build a minimalhf_gptqmodel_reselect_context()from the HFquantization_configand publish it asmodel._gptqmodel_hf_reselect_context._gptqmodel_hf_load_context, so third-party loads keep their own post-init path, and resident maps are untouched.Evidence
c1807f889, newtests/test_hf_bridge_thirdparty_offload_5262.py: 5 failed, 6 passed (third-party AWQ/GPTQ CPU+disk nodes fail; native and no-offload controls pass). After the fix: 11 passed.gptq_nometafailed on CPU and disk with the reported Marlin errors; after, all 8 checkpoint/spill cases load and forward. All-CPU maps useTorchAten*; mixed 600/800 MiB maps useAwqGEMMTritonLinear/TritonV2Linearon the offloaded layers while resident layers keep Marlin.test_hf_bridge_cpu_offload_5022.py+test_hf_gptqmodel_load_bridge.py: 46 passed; HF bridge batch (15 files) 223 passed / 3 skipped, with 3 failures + 4 errors that reproduce identically on pristinemain(4795,4907, and one offline cache miss); offload/device-map batches 156 passed / 1 skipped and 59 passed.uvx [email protected] check gptqmodel docs/eora tests setup.pyclean.Not verified: no CI run (local GPU 1 only); the import-order-late AWQ path (first
gptqmodelimport insidereplace_with_awq_linear) is not covered for third-party checkpoints; no third-party AWQ GEMV or other formats; no performance measurement.fix(hf): reselect offload-safe kernels for third-party checkpoints (#…