feat(pt): Add support for finetuning from .pth (frozen) models #4956
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.
This PR fixes the
NotImplementedError
that occurs when attempting to finetune from.pth
(frozen/scripted) models in PyTorch backend.Problem
Users encountered a
RuntimeError
when trying to finetune from frozen models:The error occurred because the
get_finetune_rules()
function unconditionally usedtorch.load()
withweights_only=True
to load finetune models, which fails for.pth
files that are created withtorch.jit.save()
and requiretorch.jit.load()
.Solution
Updated
get_finetune_rules()
function indeepmd/pt/utils/finetune.py
:.pt
files:torch.load()
withweights_only=True
(existing behavior).pth
files:torch.jit.load()
and extract model params viaget_model_def_script()
Updated training logic in
deepmd/pt/train/training.py
:.pth
support in model resuming/loading logicstrict=False
when loading state dict from.pth
files to handle different key structuresThe implementation follows the existing pattern used in the
change_bias()
function, ensuring consistency across the codebase.Testing
.pt
and.pth
finetune workflows.pt
finetune functionalityUsers can now successfully finetune from both checkpoint (
.pt
) and frozen (.pth
) models:Fixes #4262.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.