Skip to content

fix(writer): skip removed checkpoint modules - #4494

Merged
Qubitium merged 2 commits into
ModelCloud:mainfrom
mikemikimike:fix/4452-missing-module
Nov 16, 2026
Merged

Qubitium merged 2 commits into
ModelCloud:mainfrom
mikemikimike:fix/4452-missing-module

Conversation

@mikemikimike

Copy link
Copy Markdown
Contributor

Summary

Fixes the checkpoint re-save regression reported in Issue #4452.

Resolves #4452

Older quantized checkpoints can contain buffers for modules removed from the current Transformers model implementation, such as legacy Llama rotary embedding buffers. During dtype preservation, the loader now skips those absent module paths because those tensors are already ignored by model loading, while continuing to restore matching current buffers.

flowchart TD
    A["checkpoint dtype map"] --> B["resolve module path"]
    B --> C{"module exists in current model?"}
    C -- "no" --> D["skip legacy checkpoint tensor"]
    C -- "yes" --> E["compare and restore buffer dtype"]
    D --> F["continue load and re-save"]
    E --> F
    style C fill:#ffe0b2,stroke:#e65100
    style F fill:#c8e6c9,stroke:#2e7d32
Loading

Before, get_submodule() raised AttributeError for a checkpoint-only module and prevented saving. After, missing legacy paths are ignored without changing restoration of existing buffers or other shape/type errors.

Failure contract

Only an absent module path is skipped. Existing module slots still undergo the same floating-point dtype and shape checks, and checkpoint read or restoration failures remain errors.

Validation

  • pytest -q tests/test_resave_missing_modules_4452.py (1 passed)
  • python -m py_compile gptqmodel/utils/model.py tests/test_resave_missing_modules_4452.py passed
  • git diff --check passed

@Qubitium

Copy link
Copy Markdown
Collaborator

@mikemikimike Please resolve merge conflict.

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.
@Qubitium
Qubitium merged commit ccbb9e0 into ModelCloud:main Nov 16, 2026
Qubitium added a commit that referenced this pull request Nov 17, 2026
… (#4509)

* fix(loader): keep packed fp8 weights out of the accelerate cast (#4387)

Accelerate casts every floating checkpoint tensor to the requested model
dtype. For an FP8 checkpoint that materialized each packed `weight` as
FP16/BF16 on the target device, and staged the whole shard there, until
the loader re-read the FP8 bytes; the load peak was ~2.1x resident.

Write a temporary safetensors checkpoint without the packed weights, let
Accelerate load only the dense tensors, and restore the packed bytes from
the source checkpoint on the `device_map` target. Key-converted
checkpoints use a runtime-to-source name map for the restore. Pickle and
non-safetensors checkpoints keep the previous path.

Measured on a GPTQModel FP8 export of SmolLM2-135M (210 packed E4M3
weights): BF16 peak allocated 376 MB -> 164 MB (= resident), host VmHWM
2.44 GB -> 2.13 GB; the state-dict SHA-256 and a fixed forward pass are
identical. A two-shard copy measured 296 MB -> 164 MB.

* fixup(#4387): keep the tie-weights stub compatible and refresh doc line refs

`_tie_weights_after_checkpoint_load` gained a keyword-only `extra_keys`
argument so the packed FP8 names the loader restores itself are not reported
as missing. The stub in the #4494 test only accepted positional arguments and
failed on the new keyword; accept keywords like the stub in
`test_checkpoint_scale_dtype.py` already does. No assertion changes.

Also point the checkpoint-load row in the FP8 lifecycle doc at the current
`accelerate.load_checkpoint_in_model` and `_restore_checkpoint_buffers` call
sites (`:3478`, `:3540`); the old `:3422`/`:3461` refs drifted during the
branch work.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants