Skip to content

[BUG] Saving a GPTQ checkpoint loaded through subfolder= reopens the wrong directory #5380

Closed

Description

@Qubitium

Describe the bug

A normal GPTQ checkpoint with embedded quantization metadata loads correctly via subfolder=. Immediately saving the resulting wrapper to a fresh directory fails because the export path reopens the repository root instead of the loaded checkpoint.

To reproduce

At 72cef9bac, save a tiny GPTQ Llama checkpoint including its normal embedded quantization config to root/gptq. Leave the root without a model config.

from gptqmodel import BACKEND, GPTQModel

loaded = GPTQModel.load("root", subfolder="gptq", device="cpu", backend=BACKEND.GPTQ_TORCH)
assert loaded.quantized
loaded.save("resaved")

Reproduced on CPU. The load returned a quantized model with TorchLinear modules. The save raised ValueError: Unrecognized model while reading config.json at the outer root.

Expected behavior

The save should use the checkpoint directory successfully selected by the load. Subfolder resolution, wrapper construction, save setup, export shell config lookup.

Suggested mitigation

One option is to keep a resolved checkpoint source directory on the wrapper while retaining the snapshot root for repository-wide resources. The re-save setup in gptqmodel/models/writer.py could then build the export shell from that source.

A round trip can load the nested checkpoint, re-save it, then reload and compare packed tensors. Giving the initial loader the resolved checkpoint directory directly works around the path mismatch.

Activity

  1. added
    bug
    on Nov 19, 2026
  2. Qubitium commented on Nov 19, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim: agent-4e3a0639ecaf is working on this issue now.

    Started 2026-11-19T09:40:00Z. The claim expires 4.0h after this comment is last edited (heartbeat). Other agents: do not start this issue while the claim is live.

    Keep the resolved checkpoint source directory on the wrapper so save() builds its export shell from the loaded subfolder, with a load -> save -> reload round-trip regression.

  3. Qubitium commented on Nov 19, 2026

    @Qubitium
    CollaboratorAuthor

    Released: #5498 merged as db5bd1d2c (regression test).

    Status: the code fix landed earlier in #5461.

    • GPTQModel.load(root, subfolder="gptq") used to construct the wrapper with the repository root, so an immediate save() rebuilt its export shell from the root and failed with ValueError: Unrecognized model. fix(load): resolve the wrapper checkpoint directory from subfolder #5461 (abb84bf16, "resolve the wrapper checkpoint directory from subfolder") fixed exactly that.

    Verified with this issue's own repro (tiny Llama, RTN 4-bit, saved under root/gptq, root deliberately left without a config):

    tree loaded.model_local_path loaded.save("resaved")
    72cef9bac the root ValueError: Unrecognized model in <root>
    current main <root>/gptq succeeds

    What #5498 adds - the round-trip regression the issue asked for, which the existing subfolder tests did not cover: quantize into root/gptq, load through subfolder=, assert model_local_path resolves to the nested directory, save to a fresh directory, reload, and compare every qweight/qzeros/scales tensor for exact equality.

    Red -> green: 1 failed on 72cef9bac (at the model_local_path assertion) -> 1 passed on main. test_checkpoint_subfolder_resolution.py + the new file -> 23 passed; ruff clean.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions