Skip to content

[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

Closed

Description

@Qubitium

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) returns None when _is_native_gptqmodel_config(qcfg) is false. The AWQ bridge then falls back to original_prepare and never sets self._gptqmodel_model or model._gptqmodel_hf_load_context (gptqmodel/__init__.py:772-776). The GPTQ bridge sets _gptqmodel_model but 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_kernels also returns False on context is None (hf_load.py:446).
  • Kernels for these checkpoints come from hf_select_quant_linear{,_v2}, called by Transformers/Optimum, with cpu_offload=auto_cpu_offload(backend, "auto") (importer.py:1420/1519). That is still False for 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 = model in both bridges whether or not the prepare returned a context.
  • Give the fallback path a minimal HFGPTQModelLoadContext (quantize config from the HF quantization_config, the backend from _hf_quantizer_backend, the dtype). Then hf_gptqmodel_reselect_offloaded_kernels can rebuild the meta placeholders that Optimum's convert_model / transformers' replace_with_awq_linear created.

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

  1. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-4e3a0639ecaf is 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

  2. Qubitium commented on Nov 18, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-4e3a0639ecaf finished this issue.

    PR: #5277 — base main, head a9de5f423 (branch fix/5262-reselect-thirdparty), 3 files, +464/−6.

    Fix

    For third-party AutoAWQ/AutoGPTQ checkpoints the bridge returned None and never published _gptqmodel_model or a load context, so _reselect_kernels_for_resolved_device_map exited early and AUTO kept a CUDA-only Marlin kernel after max_memory spilled layers to CPU/disk.

    • Both bridges now always set quantizer._gptqmodel_model = model.
    • On the original_prepare / original_convert_model fallback they build a minimal hf_gptqmodel_reselect_context() from the HF quantization_config and publish it as model._gptqmodel_hf_reselect_context.
    • Reselection consults the native context first, then the fallback context. The fallback is deliberately kept separate from _gptqmodel_hf_load_context, so third-party loads keep their own post-init path, and resident maps are untouched.

    Evidence

    • Pristine c1807f889, new tests/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.
    • Exact issue repro on local real checkpoints: before, third-party AWQ and gptq_nometa failed on CPU and disk with the reported Marlin errors; after, all 8 checkpoint/spill cases load and forward. All-CPU maps use TorchAten*; mixed 600/800 MiB maps use AwqGEMMTritonLinear / TritonV2Linear on 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 pristine main (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.py clean.

    Not verified: no CI run (local GPU 1 only); the import-order-late AWQ path (first gptqmodel import inside replace_with_awq_linear) is not covered for third-party checkpoints; no third-party AWQ GEMV or other formats; no performance measurement.

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