Skip to content

[BUG] HF bridge: a matching-width pre-7.3.4 qzeros is deferred to meta, so a mixed GPU/CPU device_map fails in dispatch_model #6396

Done

Description

@Qubitium

Summary

Loading a published pre-7.3.4 GPTQ checkpoint with a mixed GPU+CPU
device_map fails inside accelerate.dispatch_model:

ValueError: qzeros is on the meta device, we need a `value` to put in on 0.

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, sym=true, desc_act=true). All 196 qzeros tensors in it are
32-aligned and already have the current ceil width.

Reproduction (origin/main 1615accf9)

from transformers import AutoModelForCausalLM

P = "/monster/data/model/DeepSeek-R1-Distill-Qwen-7B-gptqmodel-4bit-vortex-v1"
AutoModelForCausalLM.from_pretrained(
    P,
    device_map="auto",
    max_memory={0: "3GiB", "cpu": "14GiB"},
    offload_folder="/tmp/off",
)
ValueError: qzeros is on the meta device, we need a `value` to put in on 0.

The failing tensor is a GPU-placed Marlin projection
(self_attn.k_proj.qzeros). With max_memory={0: "1GiB", ...} the same load
instead fails later with ValueError: GPTQ Marlin requires CUDA tensors, got 'cpu'; that second failure is #6387 and this repro was measured on top of it.

Mechanism

_hf_legacy_qzeros_quant_linear wraps every symmetric checkpoint from a
pre-7.3.4 producer in a subclass with _HF_DEFER_SYM_QZEROS = True.
PackedGroupedQuantLinear._save_to_state_dict then pops qzeros from the
state dict used to build the loader's expected-key set, so the checkpoint
tensor is never loaded and the module keeps its constructor (meta) buffer.
_materialize_hf_sym_qzeros regenerates it, but Optimum calls that from
post_init_model, i.e. after accelerate.dispatch_model.

The deferral only exists to hide the pre-#2983 floor-width mismatch
(out_features // 32 * bits vs ceil(out_features * bits / 32)). The two
widths are identical for every 32-aligned projection, so for those layers
there is nothing to defer.

Fix direction

Resolve the deferral per layer at construction: when the legacy wrapper is
built for a 32-aligned out_features, clear _HF_DEFER_SYM_QZEROS so the
checkpoint tensor is loaded normally. A genuine floor-width projection keeps
the deferral and is still regenerated after loading. Moving
_materialize_hf_sym_qzeros earlier is not safe because the kernel class can
still change during post-init (#6253/#6387).

Activity

  1. Qubitium commented on Nov 29, 2026

    @Qubitium
    CollaboratorAuthor

    Fixed by #6409 (merged as 203031939): GPTQQuantLinear.__init__ now clears _HF_DEFER_SYM_QZEROS for a 32-aligned legacy projection, so the checkpoint qzeros is loaded instead of staying meta until post-init. Floor-width layers keep the deferral. Verified on the checkpoint from this report with max_memory={0: "3GiB", "cpu": "14GiB"}: 3GiB OK {MarlinLinear: 196}, finite logits.

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