Repository navigation
fix(export): preserve dense Parameter dtypes and repack checkpoint snapshots (#4466) - #4507
Merged
Merged
Conversation
…apshots (#4466) The re-save export shell allocates dense Parameters in the config model dtype. Accelerate's dtype=None load copies each checkpoint tensor into that slot, so a mixed-dtype checkpoint (for example an FP16 norm next to a BF16 config) was narrowed on re-save. Extend the checkpoint dtype restoration (already used for buffers) to dense Parameters; the normal load path keeps casting them to the explicitly requested model dtype. A CPU int4pack forward rewrites qweight/qzeros/scales into the kernel's private runtime layout. hf_repack_layer copied those live operands, so a repack that worked before inference failed after one valid forward. Repack now consumes the canonical checkpoint tensors retained in the _fused_train_state snapshot, and fails closed when that runtime state was modified and has no checkpoint inverse.
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
…me/device mapping #4507 taught _restore_checkpoint_buffers to restore dense Parameters and to fall back to the slot device; keep that and the packed-FP8 runtime->source name map plus device_map placement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #4466.
_restore_checkpoint_buffersrestored onlymodule._buffers, so a denseParameter(e.g.model.norm.weight) stored at fp16 came back bf16 after load/re-save. It now restores floating_parameterstoo, keeping Parameter identity via.dataso tied weights stay tied. The export shell (restore_checkpoint_buffer_dtypes=True) adds dense Parameters whose checkpoint dtype differs; a normal load still casts to the explicitly requested model dtype._copy_packed_statecopied the live int4pack runtimeqweight/qzeros/scaleswhen re-packing after a forward. It now substitutes the canonical checkpoint-layout tensors from the fused-train snapshot, with a newcheckpoint_layout_tensor()helper that fails closed if the runtime state was modified (no checkpoint inverse).Validation
Exact issue repro:
CPU int4pack repack after one forward:
Tests:
tests/test_resave_dense_parameter_dtype_4466.py→ 2 passedtest_hf_packing_api.py→ 51 passed, 4 skippedtest_checkpoint_quant_buffer_dtypes_4458.py+ interop/state-invariant → 54 passed, 9 skipped (4 AVX512-BF16 param failures are pre-existing on this host and fail identically on the unmodified base)ruff checkcleanResidual: legacy
.bincheckpoints expose no dtype map and keep the pre-existing behavior; normalGPTQModel.load()still casts dense Parameters to the requested dtype by design — only re-save preserves storage dtype.Resolves #4466.