Repository navigation
Description
Found on main @ 396b5f0, RTX 5090 (sm_120, single visible GPU), torch 2.15 + CUDA 13.2, transformers 5.22.
What is wrong
#5022's headline scenario still fails. Plain transformers loading of a GPT-QModel GPTQ/RTN or AWQ-GEMM checkpoint with device_map="auto" plus a max_memory budget that spills to CPU crashes at load time, now with a different error than in #5022. The #5046 fix (with #5051/#5052) only covers explicit dict maps that contain "cpu" entries.
gptqmodel/utils/hf_load.py:382(native bridgemake_quant) andgptqmodel/utils/importer.py:1384/1483(hf_select_quant_linear{,_v2}) passcpu_offload=auto_cpu_offload(backend, device_map).auto_cpu_offload→device_map_uses_cpu(importer.py:1336) returnsFalsefor any non-dict map. Transformers calls the bridge before it resolves"auto"frommax_memory(the comment athf_load.py:~352says so, and fix(hf): resolve an accelerate keyword map before validating GPU capabilities (#5084) #5123 relies on it). So the bridge receives the string"auto", decides "no CPU offload", and AUTO picksMarlinLinear/AwqMarlinLinear.- After dispatch, the spilled layers are CPU-resident, so
_post_init_cpu_offloaded_marlin→MarlinLinear.post_init→marlin_validate_runtime_deviceraises. If the spill goes to disk (offload_folder), the fix(load): honour a CPU-offload device map in the HF bridge (#5022) #5046 disk-index guard refuses instead. Its message tells the user to "let AUTO select a kernel that declaresSUPPORTS_CPU_OFFLOAD", but AUTO is what selected Marlin.
GPTQModel.load with the same device_map="auto", max_memory=... works: the native loader resolves the map before it selects kernels and picks TritonV2Linear / AwqGEMMTritonLinear. HF with an equivalent explicit dict map works too, and so does HF "auto" when the model fits on the card.
Repro
import torch, gptqmodel
from transformers import AutoModelForCausalLM
for ckpt in ["Llama-3.2-1B-Instruct-GPTQ-4bits-gp128", # GPT-QModel GPTQ ckpt
"AWQ-Llama-3.2-1B-g128-gemm"]: # AWQ GEMM ckpt
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(ckpt, dtype=torch.float16, device_map="auto", **kw)
print("ok")
except Exception as e:
print(type(e).__name__, str(e)[:160])
Output:
ValueError GPTQ Marlin requires CUDA tensors, got `cpu`.
RuntimeError CPU-offloaded Marlin requires a writable in-memory weights map: ['qweight', 'g_idx', 'scales', 'qzeros'] are disk-backed entries that `post_init` cannot rewrite. Load with `offload_state_dict=False`, or let AUTO select a kernel that declares `SUPPORTS_CPU_OFFLOAD`.
ValueError AWQ Marlin requires CUDA tensors, got `cpu`.
RuntimeError CPU-offloaded Marlin requires a writable in-memory weights map: ['qweight', 'qzeros', 'scales'] are disk-backed entries ...
Traceback (GPTQ): GptqHfQuantizer._process_model_after_weight_loading → gptqmodel/__init__.py:655 _after_with_gptqmodel_bridge → hf_load.py:427 hf_gptqmodel_post_init_for_load → model.py:2200 gptqmodel_post_init → model.py:2006 _post_init_cpu_offloaded_marlin → marlin.py:378 post_init → utils/marlin.py:72.
Controls on the same checkpoints:
GPTQModel.load(ckpt, device_map="auto", max_memory={0: "300MiB", "cpu": "20GiB"})loads with['cpu', 'cuda:0'], picksTritonV2Linear/AwqGEMMTritonLinear, and greedygenerategives the expected tokens.- HF
from_pretrainedwith the explicit dict map{embed/norm/lm_head/layers.0-7: 0, layers.8-15: "cpu"}loads with the same kernels and identical tokens.
Suggested fix
The bridge cannot see max_memory, so it must not assume "no offload" for a keyword map. Two options:
- Treat an accelerate keyword map (
"auto"/"balanced"/"balanced_low_0"/"sequential") as possibly offloading inauto_cpu_offload. This is simple, but it costs Marlin speed for keyword loads that fit on the GPU. - Better: keep Marlin for the selection, then in the post-weight hook (
hf_gptqmodel_post_init_for_load, where fix(hf): resolve an accelerate keyword map before validating GPU capabilities (#5084) #5123 already reads the dispatchedmodel.hf_device_map) re-select an offload-capable kernel for any quantized module whose resolved placement iscpu/disk, beforepost_initruns.
Also fix the disk-offload error text, which currently recommends the AUTO path that produced it.
Tests that should have caught it
tests/test_hf_bridge_cpu_offload_5022.py only drives explicit dict maps (the "late-layer"/"embeddings" shapes). Add a node with device_map="auto" and a max_memory that forces a CPU spill (and one that forces a disk spill), for GPTQ and AWQ GEMM. It should compare against GPTQModel.load with the same budget.
Severity
Medium. The load crashes rather than corrupting anything, but device_map="auto" + max_memory is the standard Transformers flow for running a model larger than VRAM, and #5022 is closed as fixed.
🤖 Generated with Claude Code
Activity
Qubitium commentedon Nov 18, 2026
Agent claim released:
agent-fb5145b84190finished this issue.Pull request: #5247
Will re-select an offload-capable kernel for modules the dispatched HF map places on cpu/disk, before post_init runs, and cover device_map='auto' + max_memory for GPTQ and AWQ GEMM.
fix(hf): reselect kernels after `device_map="auto"` resolves to an of…
Strict everywhere: port Accelerate-dispatch tests to GPTQModel placem…
Merge wl-placement-api: GPT-QModel no longer consumes Accelerate's de…
Remove accelerate: explicit WeightLoader for weight loading, placemen…