fix(checkpoint): Preserve destination tensor dtype - #149
Open
suharvest wants to merge 1 commit into
Open
Conversation
Signed-off-by: suharvest <suharvest@gmail.com>
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.
What does this PR do?
Preserves the declared half-precision dtype of an existing checkpoint
destination when loading a floating-point source tensor.
Previously
_set_tensor()only converted BF16 sources through its legacy FP16fallback. Assigning an FP32 checkpoint tensor could replace an existing FP16
or BF16 parameter with an FP32 parameter, leaving the exported model in an
unexpected mixed-dtype state.
FP32, BF16, and FP16 sources now use the existing destination dtype when that
destination is FP16 or BF16. Existing behavior remains unchanged for FP32
destinations, non-floating tensors, and attributes without a declared
parameter/buffer dtype; the legacy unknown-destination BF16-to-FP16 fallback is
retained.
Scope
Validation
3 failed, 4 passed.7 passed.BF16 → declared FP16, FP32 destination, unknown destination legacy fallback,
and non-floating input.
_set_tensor()function and use only standardPyTorch modules/parameters/buffers.
git diff --check, andmerge-tree validation pass.
The CPU test environment used PyTorch 2.11 rather than the repository-pinned
2.12 release. A complete model export → build → inference run requires the
official GPU environment and is still requested from CI/device testing.
Closes #144.