Skip to content

[BUG] Re-saving a loaded checkpoint casts packed/scale buffers to the model dtype: FP8 re-save becomes unloadable, GPTQ/QQQ re-save is lossy (regression from 08f1b2b) #4303

Closed

Description

@Qubitium

Severity: high (FP8), medium (GPTQ/QQQ). Status: confirmed by repro at 842d666, and confirmed clean at 08f1b2b~1. Kind: regression from 08f1b2b (#4235).

Where

gptqmodel/models/writer.py:2574: get_model_with_quantize now calls load_checkpoint_in_model_then_tie_weights(..., dtype=model_dtype, device_map={"": "cpu"}).

Cause

  • When a device_map is passed, accelerate (1.15) sends every tensor through set_module_tensor_to_device(value=param, dtype=dtype).
  • That call casts every floating tensor to the model dtype, fp8 included, and replaces the buffer.
  • Before 08f1b2b, device_map=None went through set_model_state_dict, which copies into the existing buffers and keeps their dtype.
  • The export-shell path also never applies the packed_fp8_buffer_dtypes / keep_in_fp32_modules / fp32-buffer restore that the main loader does (loader.py ~3140).

Repro 1: FP8 (the re-saved checkpoint no longer loads)

from gptqmodel import GPTQModel, QuantizeConfig, BACKEND
cal = ["The quick brown fox jumps over the lazy dog. " * 8 + str(i) for i in range(32)]
m = GPTQModel.load("meta-llama/Llama-3.2-1B-Instruct", quantize_config=QuantizeConfig(method="fp8", offload_to_disk=False))
m.quantize(cal, batch_size=4, calibration_data_min_length=1); m.save("fp8_s1")
GPTQModel.load("fp8_s1", backend=BACKEND.FP8_TORCH).save("fp8_s2")
GPTQModel.load("fp8_s2", backend=BACKEND.FP8_TORCH)   # raises
  • Actual:
    • In fp8_s2, weight is cast from float8_e4m3fn to bf16 (fp16 on an fp16 model) and weight_scale_inv from fp32 to bf16.
    • The file roughly doubles in size.
    • Reloading raises RuntimeError: Checkpoint buffer 'model.layers.0.mlp.down_proj.weight' must have packed dtype torch.float8_e4m3fn, got torch.bfloat16.
  • Expected: a byte-identical re-save. That is what 08f1b2b~1 produces.

Repro 2: GPTQ / QQQ (silently lossy)

Run GPTQModel.load(<any GPTQ checkpoint of a bf16 model>, backend=BACKEND.TORCH).save("out"), then compare the *.scales tensors.

  • GPTQ: the fp16 scales are written as bf16.
    • On a Llama-3.2-1B-Instruct GPTQ 4-bit g128 checkpoint, all 112 scales tensors change dtype.
    • In one tensor, 114,766 of 131,072 values change, with a maximum relative error of 3.9e-3.
    • The same happens with a GPTQ v2 checkpoint, a vortex v1 checkpoint, and v1↔v2 format-conversion re-saves.
  • QQQ: the s_channel tensors go from fp32 to the model dtype.
  • Effect: perplexity drifts in the third decimal.
  • Expected: 0 differences, as at 08f1b2b~1.
  • Not affected: AWQ GEMM checkpoints showed no difference.

Found during an AI-assisted review (Claude Code, round 11) of 842d666; repros were run at that commit on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.

Activity

  1. added
    bug
    on Nov 16, 2026
  2. self-assigned this
    on Nov 16, 2026
  3. Qubitium commented on Nov 16, 2026

    @Qubitium
    CollaboratorAuthor

    Taking this. I'll investigate against current main, add a targeted regression test, and open a PR. Will report back here if the claim turns out to be invalid or already fixed.

  4. Qubitium commented on Nov 16, 2026

    @Qubitium
    CollaboratorAuthor

    Confirmed independently by a second reviewer, with a cause check. At HEAD, reverting only writer.py:2574 to device_map=None gives 0 differing tensors on re-save.

    The v2 qzeros stay correct after that revert, because the idempotent load hook covers that case.

    The bf16 rewrite of scales also reproduces with the gptq_torch, gptq_triton and exllama_v2 backends on GPU and with TORCH on CPU, for:

    • a v1 single-file sym=False checkpoint;
    • a v2 checkpoint;
    • a sharded TinyLlama v1 checkpoint.

    The error is max abs 1e-4 to 2.4e-4, about 0.2% relative.

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

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions