Fix save_model to include fine-tuning head weights#371
Merged
bputzeys merged 3 commits intoApr 28, 2026
Conversation
Contributor
|
Hi @LiudengZhang and welcome to the community! Please open this PR against the main branch.
is better as a unit test. |
save_model only persisted self.model.state_dict(), silently discarding the trained fine-tuning head (ClassificationHead / RegressionHead) weights. Switch to self.state_dict() so both the backbone and the head are saved. load_model now auto-detects the checkpoint format: - full checkpoint (model + head keys) -> self.load_state_dict() - backbone-only (v2.0.0 checkpoint) -> strict=False, warn - legacy pickle (pre-v2.0.0) -> extract & load backbone
28e5ba6 to
1235729
Compare
Contributor
Author
|
Thanks for the welcome and the feedback! I've retargeted the PR to main and added a unit test that verifies fine-tuning head weights survive save/reload (sets all head params to a sentinel value, saves, loads into a fresh model, and asserts equality). Let me know if anything else needs adjusting. |
bputzeys
reviewed
Apr 28, 2026
Collaborator
|
Thanks for this PR! Good one :) |
bputzeys
approved these changes
Apr 28, 2026
dmiv-helical
approved these changes
Apr 28, 2026
Contributor
Author
|
Thanks @bputzeys and @dmiv-helical for the reviews! Good catch on the comment — noted for next time. |
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
save_model()currently callstorch.save(self.model.state_dict(), path), which only persists backbone weights and silently drops thefine_tuning_headself.state_dict()which includes both backbone and headload_modelto auto-detect three checkpoint formats for backward compatibility (full, backbone-only, legacy pickle)Test plan
🤖 Generated with Claude Code