feat(pt): Add support for finetuning from .pth (frozen) models#4956
Draft
feat(pt): Add support for finetuning from .pth (frozen) models#4956
Conversation
- Fix get_finetune_rules() to handle both .pt and .pth files - Update training logic to support .pth model loading - Add comprehensive tests for both file types - Use appropriate loading methods: torch.load() for .pt, torch.jit.load() for .pth - Maintain backward compatibility with existing .pt workflow Fixes #4262
Copilot
AI
changed the title
[WIP] Encounting NotImplementedError when finetuning a Single-Task .pth model
feat(pt): Add support for finetuning from .pth (frozen) models
Sep 3, 2025
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.
This PR fixes the
NotImplementedErrorthat occurs when attempting to finetune from.pth(frozen/scripted) models in PyTorch backend.Problem
Users encountered a
RuntimeErrorwhen trying to finetune from frozen models:The error occurred because the
get_finetune_rules()function unconditionally usedtorch.load()withweights_only=Trueto load finetune models, which fails for.pthfiles that are created withtorch.jit.save()and requiretorch.jit.load().Solution
Updated
get_finetune_rules()function indeepmd/pt/utils/finetune.py:.ptfiles:torch.load()withweights_only=True(existing behavior).pthfiles:torch.jit.load()and extract model params viaget_model_def_script()Updated training logic in
deepmd/pt/train/training.py:.pthsupport in model resuming/loading logicstrict=Falsewhen loading state dict from.pthfiles to handle different key structuresThe implementation follows the existing pattern used in the
change_bias()function, ensuring consistency across the codebase.Testing
.ptand.pthfinetune workflows.ptfinetune 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.