Repository navigation
fix(pt): preserve legacy property checkpoint semantics #6083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8b5e3f8
b8652c5
8581488
5335e2b
8befcc3
50d1c05
3ade174
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,10 @@ | |
| from deepmd.utils.finetune import ( | ||
| warn_configuration_mismatch_during_finetune, | ||
| ) | ||
| from deepmd.utils.pt_checkpoint import ( | ||
| apply_pt_checkpoint_defaults, | ||
| normalize_pt_model_params, | ||
| ) | ||
| from deepmd.utils.stat_file import ( | ||
| StatFileSpec, | ||
| open_stat_file, | ||
|
|
@@ -1795,6 +1799,18 @@ def __init__( | |
| self.restart_training = restart_model is not None | ||
|
|
||
| model_params = config["model"] | ||
| if resuming and not resume_model.endswith((".pte", ".pt2")): | ||
| resume_state = torch.load( | ||
| resume_model, map_location="cpu", weights_only=True | ||
| ) | ||
| if "model" in resume_state: | ||
| resume_state = resume_state["model"] | ||
| resume_model_params = resume_state.get("_extra_state", {}).get( | ||
| "model_params" | ||
| ) | ||
| if isinstance(resume_model_params, dict): | ||
| apply_pt_checkpoint_defaults(model_params, resume_model_params) | ||
|
Comment on lines
+1811
to
+1812
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Persist the effective property config after experimental resume For a legacy Please likewise retain the effective construction parameters in the experimental checkpoint metadata and cover legacy checkpoint → explicit-True init/restart → save → reload. I reproduced the metadata transition Agent: dot |
||
| del resume_state | ||
| training_params = config["training"] | ||
| optimizer_params = config.get("optimizer", {}) | ||
| validating_params = config.get("validating", {}) or {} | ||
|
|
@@ -2150,7 +2166,9 @@ def initialize_statistics( | |
| pretrained_model_params = data["model_def_script"] | ||
| pretrained_model = BaseModel.deserialize(data["model"]).to(DEVICE) | ||
| else: | ||
| pretrained_model_params = state_dict["_extra_state"]["model_params"] | ||
| pretrained_model_params = normalize_pt_model_params( | ||
| state_dict["_extra_state"]["model_params"] | ||
| ) | ||
|
|
||
| # Build pretrained model (single-task or multi-task) | ||
| if "model_dict" not in pretrained_model_params: | ||
|
|
@@ -2279,6 +2297,18 @@ def update_finetune_bias( | |
| ) | ||
| else: | ||
| # --- Normal resume (init_model / restart) -------------------- | ||
| # Keep the effective model parameters from the current | ||
| # construction. Legacy checkpoints omit property | ||
| # ``distinguish_types``; restoring their extra state here | ||
| # would make a subsequent save lose an explicit config value. | ||
| current_extra_state = self._unwrapped.state_dict()["_extra_state"] | ||
| if self.restart_training: | ||
| state_dict["_extra_state"] = { | ||
| **state_dict.get("_extra_state", {}), | ||
| "model_params": current_extra_state["model_params"], | ||
| } | ||
| else: | ||
| state_dict["_extra_state"] = current_extra_state | ||
| self._unwrapped.load_state_dict(state_dict) | ||
|
|
||
| if shared_links is not None: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.