Repository navigation
Conversation
The re-save export shell loaded its checkpoint with
load_checkpoint_in_model_then_tie_weights(dtype=model_dtype,
device_map={"": "cpu"}). With a device_map, accelerate sends every tensor
through set_module_tensor_to_device(value=param, dtype=dtype), which casts
every floating tensor to the model dtype: packed FP8 weights and their FP32
scales became bf16 (the re-saved checkpoint then failed to reload) and FP16
GPTQ/QQQ scales became bf16 (a lossy re-save).
Load the export shell with dtype=None so accelerate copies each checkpoint
tensor into the existing shell buffer dtype instead. Every quantized module
allocates its buffers in the checkpoint's storage dtype (packed FP8 weight,
FP16 GPTQ scales, FP32 QQQ s_channel), which is also what the pre-08f1b2b
set_model_state_dict path did. The device_map stays: it is what makes each
shard load exactly once (#4166).
Fixes #4303
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
Re-saving a loaded quantized checkpoint no longer casts packed/scale buffers to the model dtype. Fixes the FP8 regression (re-saved checkpoint became unloadable) and the GPTQ/QQQ regression (FP16/FP32 scales were silently narrowed to BF16) introduced by #4235 (08f1b2b).
What Changed
gptqmodel/models/writer.py—get_model_with_quantize(export-shell path) now loads the rebuilt shell withdtype=Noneinstead ofdtype=model_dtype.With a
device_map, accelerate routes every tensor throughset_module_tensor_to_device(value=param, dtype=dtype). Passing the model dtype therefore cast every floating tensor to bf16/fp16:weight(float8_e4m3fn) → bf16, andweight_scale_invfp32 → bf16. The re-saved checkpoint then raisedRuntimeError: Checkpoint buffer '...weight' must have packed dtype torch.float8_e4m3fn, got torch.bfloat16, and roughly doubled in size.scalesfp16 → bf16 (112/112 tensors on a real checkpoint, up to 3.9e-3 relative error).s_channelfp32 → model dtype.dtype=Nonemakes accelerate copy each checkpoint tensor into the existing shell buffer dtype (value.to(old_value.dtype)). Every quantized module allocates its buffers in the checkpoint's storage dtype (packed FP8 weight, FP16 GPTQ scales, FP32 QQQs_channel), so the round trip is byte-identical. This is the same semantics the pre-08f1b2bset_model_state_dictpath had.The
device_map={"": "cpu"}argument is intentionally kept: it is what makes each shard load exactly once, which #4166 depends on. Normal (non-export) loading is untouched.Tests
New file
tests/test_resave_preserves_buffer_dtypes_4303.py:test_export_shell_load_does_not_cast_dtypes— spies on the writer'sload_checkpoint_in_model_then_tie_weightsand assertsdtype is None; asserts every stored*.scalesstays fp16 with identical bytes across the re-save.test_gptq_resave_is_byte_identical— tiny bf16 Llama, GPTQ 4-bit g32: quantize → save → load → save; every tensor keeps its dtype and bytes, and the total checkpoint size is unchanged.test_fp8_resave_keeps_packed_weight_and_scales— tiny bf16 Llama, FP8: quantize → save → load (FP8_TORCH) → save;weightstaysfloat8_e4m3fn,weight_scale_invstays fp32, bytes identical, file size identical, and the re-saved checkpoint loads.All three fail on the parent commit and pass with the fix.
Not run: QQQ end-to-end re-save — the QQQ JIT extension does not build on this CPU-only box (
qqq_runtime_available()is False), so the QQQ case is covered by thedtype=Noneguarantee plus the fp32s_channelshell allocation rather than a round-trip test.Fixes #4303