Skip to content

[BUG] After a resumed quantize(checkpoint=...), checkpoint-restored packed layers stay on meta: in-session forward / model.to() fail silently (#4498 contract not applied to resume) #4562

Closed

Description

@Qubitium

Found on main @ 4b65923, RTX 5090 (sm_120), torch 2.15 / transformers 5.22.

What is wrong

#4498 (#4450) set the contract that when quantize() returns, the in-session model is the same model offload_to_disk=False produces: no meta tensors, no offload hooks, usable for inference and model.to(...) (docs/in-session-model-after-offload.md). A quantize(checkpoint=CheckpointConfig(...)) run that resumes from a published checkpoint breaks that contract, and does so silently.

  • gptqmodel/looper/gptq_checkpoint.py:~560-605 rebuilds every completed layer's packed modules with restore_packed_module(...) on meta, writes a per-attempt index.json that points at the checkpoint object, and set_submodules them into the model ("Packed modules remain meta until the normal save path resolves their offload references", line 593). These modules carry no accelerate offload hook.
  • At loop exit, restore_disk_offloaded_modules (gptqmodel/utils/offload.py:268) only targets modules where _owns_offload_hook(module) is true, so it skips the restored modules.
  • materialize_remaining_meta_modules (gptqmodel/utils/offload.py:344) skips every module with a QUANT_TYPE (line 366).

So every layer that was restored from the checkpoint stays on meta. No error and no log line is emitted (the strict=True RuntimeError and the log.error in those two helpers never see these modules). The first in-session forward, or model.to("cuda"), raises NotImplementedError: Cannot copy out of meta tensor.

save() still works, and the resumed checkpoint is byte-identical to an uninterrupted run (verified for GPTQ and AWQ, 794/626 tensors, 0 differences). Only the in-session model is broken.

docs/looper-checkpoint-redesign.md:147 still says "Completed packed modules intentionally remain offloaded/meta until saving". That predates #4498 and conflicts with the newer in-session contract.

Repro (Qwen2.5-0.5B-Instruct, GPTQ 4-bit; AWQ behaves the same)

import os, signal, torch
from gptqmodel import GPTQModel, CheckpointConfig
from gptqmodel.looper.checkpoint import CheckpointExtension, CheckpointStopped
from gptqmodel.quantization.config import GPTQConfig

def run(stop_at=None):
    cfg = GPTQConfig(bits=4, group_size=128)          # offload_to_disk=True (default, required)
    m = GPTQModel.load("Qwen2.5-0.5B-Instruct", cfg, dtype=torch.float16)
    if stop_at is not None:                            # same trick as tests/checkpoint_quantization_driver.py
        orig = CheckpointExtension.on_boundary
        def boundary(ext, ev):
            if ev.step.index == stop_at:
                os.kill(os.getpid(), signal.SIGINT)
            orig(ext, ev)
        CheckpointExtension.on_boundary = boundary
    m.quantize(calib_16_c4_texts, checkpoint=CheckpointConfig(path="ckpt"))
    return m

# process 1
try: run(stop_at=3)
except CheckpointStopped as e: print(e)    # checkpoint committed; resume from step 4

# process 2 (fresh interpreter): resume
m = run()
meta = [n for n, t in list(m.model.named_parameters()) + list(m.model.named_buffers()) if t.is_meta]
print(len(meta), meta[:3])
ids = m.tokenizer("Hello", return_tensors="pt").input_ids
m.model(ids)              # in-session forward
m.model.to("cuda:0")

Output:

checkpoint committed; resume from step 4
152 ['model.layers.0.self_attn.q_proj.qzeros_format', 'model.layers.0.self_attn.q_proj.qweight', 'model.layers.0.self_attn.q_proj.qzeros']
NotImplementedError: Cannot copy out of meta tensor; no data!
NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty() instead of torch.nn.Module.to() ...

The same script without the stop/resume step (with or without checkpoint=) gives 0 meta tensors, a working CPU forward and a working .to("cuda:0"). With AWQ the result is the same: 124 meta tensors after the resume, and the same error.

run meta tensors after quantize() CPU forward .to("cuda") saved checkpoint vs uninterrupted
GPTQ, no checkpoint 0 ok ok —
GPTQ, checkpoint, uninterrupted 0 ok ok identical
GPTQ, checkpoint, resumed at step 4 152 NotImplementedError NotImplementedError identical
AWQ, checkpoint, resumed at step 4 124 NotImplementedError NotImplementedError identical

Suggested fix

At loop exit, materialize the checkpoint-restored packed modules from the per-attempt index the adapter writes. That index already maps every tensor to a byte range of an immutable checkpoint object, so this can reuse the undo_offload_to_disk / weights-map path. One option is to register these modules with the same offload hook as freshly offloaded modules, so the #4498 restore covers them. Then run rehome_quantized_kernel as usual. At minimum, include QUANT_TYPE modules that still own meta tensors in the strict check so the caller gets the "reload the saved checkpoint" error instead of a raw meta-tensor failure. Update docs/looper-checkpoint-redesign.md:147.

Test that should have caught it

tests/test_offload_quantized_modules_restored_4450.py covers only uninterrupted runs. The checkpoint recovery tests (tests/checkpoint_quantization_driver.py and test_checkpoint_quantization.py) compare only the saved output. One in-session forward (or a no meta tensors assertion) after the resumed quantize() in the driver would catch it.

Severity

Medium. The saved checkpoint is correct. But the documented resume workflow is quantize, then evaluate in-session, then save, and its in-session half fails after every real resume, with no diagnostic.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow.

  2. Qubitium commented on Nov 17, 2026

    @Qubitium
    CollaboratorAuthor

    Additional data on the same build (main @ 4b65923, RTX 5090, Qwen2.5-0.5B-Instruct, interrupted at step 4 and then resumed):

    method (looper) meta tensors after resumed quantize() CPU forward resumed checkpoint vs uninterrupted
    FP8 (WeightOnlyLooper) 68 (layers.0-3.*.weight, weight_scale_inv, bias) NotImplementedError: Cannot copy out of meta tensor identical (458 tensors)
    EXL3 4-bit (ModuleLooper) 0 n/a (CUDA-only kernel), works after .to("cuda") identical (794 tensors)

    So the weight-only looper is affected as well. EXL3 is not, because its restore branch load_state_dict(..., assign=True)s the CPU buffers (gptq_checkpoint.py:~584). Applying that same materialization to the other packed kinds at loop exit would cover GPTQ, AWQ and FP8.

    🤖 Generated with Claude Code

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