Skip to content

fix(load): load quantized-module buffers at their checkpoint dtype (#4458, #4452) - #4495

Merged
Qubitium merged 1 commit into
mainfrom
fix/checkpoint-buffer-dtype-4458-4452
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/checkpoint-buffer-dtype-4458-4452

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

TL;DR

1. The problem

Mechanism (at 4bc0413) Gap
utils/model.py:3269-3276 restores scales of any BaseQuantLinear other quantization buffers (QQQ, ParoQuant, VPTQ, bnb 8-bit) are rounded to BF16
utils/model.py:3277-3280 checks QUANT_TYPE == "awq_torch" to keep the bias a name check
models/loader.py:3365 enables the generic restore only for FORMAT.EXL3 every other format is excluded
utils/model.py:3305-3326 loops over checkpoint keys and calls get_submodule crashes on orphan keys such as self_attn.rotary_emb.inv_freq (#4452)

2. The new flow

flowchart TD
    A["accelerate.load_checkpoint_in_model"] --> B["_checkpoint_tensor_dtypes (headers)"]
    B --> C["for each model.named_modules()"]
    C --> D{"declares MODEL_DTYPE_BUFFERS<br/>or re-save shell?"}
    D -- "no" --> S["skip"]
    D -- "yes" --> E["each persistent floating buffer in checkpoint"]
    E --> G{"re-save shell?"}
    G -- "yes" --> H{"dtype differs?"}
    G -- "no" --> I{"declared model-dtype buffer?"}
    I -- "no" --> J{"_load_narrowed?"}
    I -- "yes" --> S
    H -- "yes" --> R["_restore_checkpoint_buffers"]
    J -- "yes" --> R
    H -- "no" --> S
    J -- "no" --> S
    style R fill:#d1e7dd,stroke:#146c43,stroke-width:2px
Loading

Checkpoint keys that have no module are never visited (#4452).

3. Declarations

Module MODEL_DTYPE_BUFFERS
BaseQuantLinear ("bias",)
AwqTorchLinear ()
ParoLinear ("bias",)
MacaqLinear ("bias", "BH", "pre_scale")
ExllamaV3Linear, ExllamaV3TorchLinear ()

4. Validation

Llama-3.2-1B-Instruct, 4-bit g128, BF16, 80-window wikitext-2 PPL, RTX 4090:

Checkpoint In-session Reload before Reload after
QQQ 35.0052 35.5230 35.0052
GPTQ (TorchLinear) 34.635 34.635 34.635, logits bitwise equal
AWQ (AwqTorchLinear) 21.6461 21.6461 21.6461, logits bitwise equal
GPTQ / AWQ Marlin (AUTO) 34.3546 / 21.6463 identical, logits bitwise equal

TheBloke/Llama-2-7B-GPTQ load().save(): before, AttributeError: LlamaAttention has no attribute rotary_emb. After, it saves, and the re-saved logits are bitwise equal to the original.

5. Tests

  • tests/test_checkpoint_quant_buffer_dtypes_4458.py, all of which fail on main:
    • 11 formats: save → BF16 load → buffers bit-identical to the safetensors file;
    • QQQ end-to-end reload;
    • orphan-key re-save.
  • 32 related test files: the failure set after rebasing on 6d849b3 is identical to origin/main (6 pre-existing CPU failures in test_macaq.py, test_bitsandbytes.py and test_checkpoint_modules.py).

6. Out of scope

  • Quant-module parameters: Marlin, Machete and Swordfish scales, and VPTQ codebook embeddings.
  • The BitBLAS load path.

Reference page: docs/checkpoint-and-runtime-contracts.md §4.

Fixes #4458
Fixes #4452

🤖 Generated with Claude Code

…4458, #4452)

Accelerate casts every floating buffer to the model dtype. The loader only
restored `scales`, the Torch AWQ bias (by QUANT_TYPE name) and the bnb 4-bit
state, and enabled the generic restore for EXL3 alone, so a BF16 load rounded
QQQ's FP16 `s_group` and FP32 `s_channel` (Llama-3.2-1B QQQ PPL 35.005
in-session vs 35.523 reloaded), ParoQuant `theta`/`channel_scales`, VPTQ
`weight_scale`/`weight_bias` and bnb 8-bit `weight_scb`.

Kernels now declare their activation-side buffers in
`MODEL_DTYPE_BUFFERS` (`("bias",)` on BaseQuantLinear); every other
persistent floating buffer of a declaring module is restored from the
checkpoint when the load narrowed it. Torch AWQ, MACaQ and EXL3 declare their
exceptions, which replaces the `awq_torch` name check and the EXL3-only loader
flag.

The restore loop walks the model's buffers instead of the checkpoint keys, so
a checkpoint tensor without a module (legacy per-layer `rotary_emb.inv_freq`)
no longer crashes `save()` with `get_submodule` (#4452).

Fixes #4458
Fixes #4452

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Qubitium
Qubitium merged commit 218ce13 into main Nov 16, 2026
8 checks passed
@Qubitium
Qubitium deleted the fix/checkpoint-buffer-dtype-4458-4452 branch November 16, 2026 19:33
Qubitium added a commit to mikemikimike/GPTQModel that referenced this pull request Nov 16, 2026
The dtype-restore loop now iterates live model buffers (ModelCloud#4495), so a
checkpoint-only module path is never looked up and the local try/except is
obsolete. Keep the regression test that pins the contract.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant