Skip to content

fix(export): preserve dense Parameter dtypes and repack checkpoint snapshots (#4466) - #4507

Merged
Qubitium merged 1 commit into
mainfrom
fix/export-dense-dtype-4466
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/export-dense-dtype-4466

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4466.

  1. Dense Parameter dtypes. _restore_checkpoint_buffers restored only module._buffers, so a dense Parameter (e.g. model.norm.weight) stored at fp16 came back bf16 after load/re-save. It now restores floating _parameters too, keeping Parameter identity via .data so 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.
  2. Transformed CPU runtime operands. _copy_packed_state copied the live int4pack runtime qweight/qzeros/scales when re-packing after a forward. It now substitutes the canonical checkpoint-layout tensors from the fused-train snapshot, with a new checkpoint_layout_tensor() helper that fails closed if the runtime state was modified (no checkpoint inverse).

Validation

Exact issue repro:

before: model.norm.weight expected torch.float16 1.0009765625 actual torch.bfloat16 1.0
after:  model.norm.weight expected torch.float16 1.0009765625 actual torch.float16 1.0009765625

CPU int4pack repack after one forward:

before: RuntimeError: The size of tensor a (16) must match the size of tensor b (64)
after:  output 128.0, correct

Tests:

  • new tests/test_resave_dense_parameter_dtype_4466.py → 2 passed
  • 4379/4303/4305 resave suites → 16 passed
  • test_hf_packing_api.py → 51 passed, 4 skipped
  • test_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 check clean

Residual: legacy .bin checkpoints expose no dtype map and keep the pre-existing behavior; normal GPTQModel.load() still casts dense Parameters to the requested dtype by design — only re-save preserves storage dtype.

Resolves #4466.

…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
Qubitium merged commit 92ea993 into main Nov 17, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/export-dense-dtype-4466 branch November 17, 2026 00:08
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Checkpoint export still loses dense tensor dtypes and copies transformed CPU runtime operands

1 participant