Skip to content

[BUG] Regression from #6274+#6253: published pre-7.3.4 GPTQ checkpoints fail with device_map="auto" + max_memory offload (ValueError: GPTQ Marlin requires CUDA tensors, got cpu) #6383

Done

Description

@Qubitium

Summary

A published GPTQ v1 checkpoint (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) loads fine with device_map="cpu" but fails with device_map="auto" + max_memory offload on main (3082b02d0):

ValueError: GPTQ Marlin requires CUDA tensors, got `cpu`.
  optimum/gptq/quantizer.py:624 post_init_model
  -> gptqmodel/utils/model.py hf_gptqmodel_post_init
  -> gptqmodel/utils/model.py gptqmodel_post_init
  -> _post_init_cpu_offloaded_marlin(module)
  -> module.post_init()
  -> marlin.py:408 marlin_validate_runtime_device

The same checkpoint on 0dd8e8ab (before today's 12-PR merge wave) loads and runs: offload OK {'TorchLinear': 196}.

Mechanism

#6274's per-layer dispatcher now keeps the AUTO kernel for group-aligned layers, so an offloaded layer is a real MarlinLinear instead of the shape-blind TorchLinear fallback. #6253's _reselect_offloaded_marlin_kernels is supposed to swap such a layer for an offload-safe kernel, but at reselect time the layer is still a meta placeholder, hf_device_map is not attached yet, and there is no _h_f_hook, so:

_marlin_needs_offload_kernel(meta=True)
  -> _marlin_offload_needs_reselection()
       -> _layer_offload_hook() raises RuntimeError   # no hook yet
       -> except RuntimeError: return False           # "bridge does not own the map"

it declines to reselect. _post_init_cpu_offloaded_marlin then sees a payload that is no longer meta (materialized onto the CPU device), finds no hook, and takes its resident path -> module.post_init() on CPU tensors -> Marlin rejects.

Reproduction (no download needed if the checkpoint is cached)

from transformers import AutoModelForCausalLM
AutoModelForCausalLM.from_pretrained(
    "ModelCloud/DeepSeek-R1-Distill-Qwen-7B-gptqmodel-4bit-vortex-v1",
    device_map="auto", max_memory={0: "350MiB", "cpu": "14GiB"},
    offload_folder="/tmp/off",
)

A 1-layer synthetic equivalent also reproduces (quantize a tiny Llama with QuantizeConfig(bits=4, group_size=32, sym=True, desc_act=False), BACKEND.GPTQ_TORCH, save, then set checkpoint_format: "gptq" and meta.quantizer: ["gptqmodel:1.7.4"] in both quantize_config.json and config.json).

Scope

Any pre-7.3.4 GPT-QModel GPTQ checkpoint (a large share of the Hub) whose layer widths are group-aligned, loaded with device_map="auto" + max_memory. Third-party (AutoGPTQ) v1 checkpoints are affected the same way, because they have no meta.quantizer and take the same "cannot prove it is current" branch.

Suggested direction

_marlin_needs_offload_kernel must not conclude "the bridge does not own the map" from a missing hook when the payload is still meta and no device map is attached — that state is transient (Accelerate resolves max_memory after the kernel is selected). Either reselect when the resolved execution device is CPU even for a meta payload, or make _post_init_cpu_offloaded_marlin refuse to run post_init() on a CPU-resident Marlin layer and reselect there.

Activity

  1. Qubitium commented on Nov 29, 2026

    @Qubitium
    CollaboratorAuthor

    Fixed by #6391 (merged as c32f2b346). Re-measured on that commit with the published checkpoint: both the disk-offload (350MiB) and mixed (1GiB) max_memory maps now load with TorchLinear x196, matching 0dd8e8ab. A separate case (max_memory={0: "3GiB"}) still fails with ValueError: qzeros is on the meta device — that is #6274's deferred-qzeros-at-dispatch-time issue, tracked separately.

  2. Qubitium commented on Nov 29, 2026

    @Qubitium
    CollaboratorAuthor

    Fixed by three merged PRs. Closing.

    What was actually broken

    The report conflated three independent defects that only appear together on a published pre-7.3.4 GPTQ checkpoint + device_map="auto" + max_memory:

    # defect fix
    1 a resident-CPU layer kept MarlinLinear because the offload test looked at checkpoint_payload_is_meta() (True only because the deferred qzeros is meta) → ValueError: GPTQ Marlin requires CUDA tensors, got 'cpu' #6391 (c32f2b346)
    2 after reselect, the portable kernel inherited Marlin's tile-layout qzeros Parameter, and _materialize_hf_sym_qzeros emptied it → IndexError on the first forward #6395 (407298ad2)
    3 a matching-width qzeros was still deferred to meta and never loaded, so accelerate.dispatch_model's init_hook raised qzeros is on the meta device, we need a 'value' to put in on 0 on any GPU/disk placement #6409 (203031939)

    Defect 3 was filed separately as #6396 and is fixed there; defects 1 and 2 are the two halves of this report.

    Verification on main = 407298ad2

    GPU (RTX 4090, CUDA_VISIBLE_DEVICES=1):

    test_hf_bridge_reselected_qzeros_6383.py test_deferred_qzeros_dispatch_6396.py
    6 passed
    

    Real published checkpoints, via transformers.AutoModelForCausalLM.from_pretrained:

    checkpoint budget result
    DeepSeek-R1-Distill-Qwen-7B-gptqmodel-4bit-vortex-v1 (gptqmodel:1.7.4) {0:"3GiB","cpu":"14GiB"} loads, 196× MarlinLinear, no meta qzeros, finite forward
    same {0:"1GiB"} loads, 196× TorchLinear, no meta qzeros
    Llama-3.2-1B-…-vortex-v1 (gptqmodel:1.1.0) {0:"1GiB"} loads, 112× MarlinLinear, finite forward
    same {0:"350MiB"} + offload_folder loads, 112× TorchLinear, finite forward
    same device_map="cpu" loads, 112× TorchCpuAvx512Linear, finite forward

    Floor-width control (out_features % 32 != 0) still defers and still rebuilds correctly; current >=7.3.4 checkpoints never take the legacy path.

    One caveat worth recording: for a floor-width legacy checkpoint on a CPU/disk-offloaded layer, the documented refusal still fires:

    RuntimeError: a legacy floor-width symmetric GPTQ checkpoint cannot be materialized on a
    CPU/disk-offloaded layer. Load it with offload_state_dict=False and a resident device map.
    

    Note that offload_state_dict=False is not actionable on transformers 5.23 (it pops and ignores that kwarg in modeling_utils.py), so only the "resident device map" half of that advice works. That is unchanged by these fixes and is the intended fail-closed behaviour rather than a silent wrong result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions