Repository navigation
Conversation
`device_map="auto"` resolves `max_memory` only after the kernel was selected,
so at reselect time an offloaded layer is still a meta placeholder with no
layer-level hook and no `hf_device_map`. `_marlin_needs_offload_kernel` read
the missing hook as "the bridge does not own the map" and declined the
reselect; `_post_init_cpu_offloaded_marlin` then saw a payload that was no
longer meta (materialized onto the CPU device), found no hook, and called
Marlin's `post_init()` on CPU tensors:
ValueError: GPTQ Marlin requires CUDA tensors, got `cpu`.
Since #6274's per-layer dispatcher keeps the AUTO kernel for group-aligned
layers, every published pre-7.3.4 GPTQ checkpoint loaded with
`device_map="auto"` + `max_memory` hit this. Measured on
`ModelCloud/DeepSeek-R1-Distill-Qwen-7B-gptqmodel-4bit-vortex-v1`:
0dd8e8a offload OK {'TorchLinear': 196}
3082b02 offload FAIL ValueError: GPTQ Marlin requires CUDA tensors
this tree offload OK {'TorchLinear': 196}
A layer that already has a layer-level hook keeps the writable-snapshot path
(#5022) and stays on Marlin; only the "no hook yet, placement is CPU" state is
now reselected.
`tests/test_marlin_offload_reselect_6383.py` pins the decision: meta + no hook
+ CPU placement reselects, a writable in-memory snapshot keeps Marlin, a
disk-backed snapshot reselects, and resident GPU/CPU layers keep their
existing outcomes.
|
Closing as superseded by #6391 ( I filed #6383 with the real-checkpoint repro and opened this PR; while it was in review #6391 merged
So main no longer reproduces #6383 and this branch's source change is redundant. I am not shipping a One case is still broken on main (reported here for the record, and being fixed in a separate That is a different defect — #6274's deferred |
Fixes a merge-induced regression from #6274 + #6253 that breaks published checkpoints.
Symptom
ModelCloud/DeepSeek-R1-Distill-Qwen-7B-gptqmodel-4bit-vortex-v1(meta.quantizer: ["gptqmodel:1.7.4"],checkpoint_format: "gptq",bits=4, group_size=32, desc_act=true, sym=true) with0dd8e8ab(before the wave)offload OK {'TorchLinear': 196}3082b02d0(merged main)ValueError: GPTQ Marlin requires CUDA tensors, got 'cpu'offload OK {'TorchLinear': 196}CPU-only load is unaffected in every tree (
TorchCpuAvx512Linear, finite logits).Mechanism
device_map="auto"resolvesmax_memoryafter the kernel is selected, so at_reselect_offloaded_marlin_kernelstime an offloaded layer is still a meta placeholder withno layer-level hook and no
hf_device_map:So the reselect declines.
_post_init_cpu_offloaded_marlinthen sees a payload that is nolonger meta (materialized onto the CPU device), finds no hook, and takes its resident path —
module.post_init()on CPU tensors, which Marlin rejects.Before #6274 the shape-blind selection returned
TorchLinearfor these checkpoints, so thepath was never taken. #6274 keeps the AUTO kernel for group-aligned layers, and #6253's
reselect is what has to catch them.
Fix
gptqmodel/utils/model.py_has_layer_offload_hook(module): non-raising form of_layer_offload_hook._marlin_needs_offload_kernel: for a meta payload, keep the existing reselect decisionsfirst (disk-backed snapshot -> reselect). If there is no layer hook yet, decide from the
resolved execution device instead of assuming the bridge does not own the map — a CPU
placement reselects. A layer that does have a hook keeps the writable-snapshot path
([BUG] Plain transformers from_pretrained with CPU offload (device_map='auto'+max_memory or cpu entries) fails for every GPTQ/RTN and AWQ-GEMM ckpt: HF bridge never passes cpu_offload (#4890 only fixed native load); #3452 Marlin path rejects Accelerate's OffloadedWeightsLoader #5022) and stays on Marlin.
This is deliberately narrow: only the "no hook yet + CPU placement" state changes.
Tests
New
tests/test_marlin_offload_reselect_6383.pypins the decision table:3082b02d0origin/main: 1 failed, 4 passed -> this branch: 5 passed.Affected suites, CPU:
test_marlin_offload_reselect_6383,test_hf_bridge_cpu_offload_5022,test_marlin_cpu_offload_post_init,test_single_device_dispatch_4847,test_hf_bridge_mixed_capability_5084,kernels/test_selection,test_cpu_offload_*->177 passed, 113 skipped (CUDA-gated).
ruff checkclean.