Skip to content
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

feat(pt): Add command to check the available model branches in multi-task pre-trained model(Issue #3742) #3796

Merged
merged 74 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
5485d15
Init 3742
Chengqian-Zhang May 20, 2024
1ecb898
change trival error
Chengqian-Zhang May 20, 2024
c684419
change help info
Chengqian-Zhang May 20, 2024
f5dea36
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 20, 2024
f60300a
Merge branch 'devel' into 3742
Chengqian-Zhang May 20, 2024
09d2fec
Update deepmd/pt/entrypoints/main.py
Chengqian-Zhang May 20, 2024
6a8b1b4
init 3741
Chengqian-Zhang May 20, 2024
be6b71c
Add doc
Chengqian-Zhang May 20, 2024
065cc2d
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang May 20, 2024
c30ac5a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 20, 2024
8a8f027
Change list-model-branch to command
Chengqian-Zhang May 20, 2024
84e8698
Merge branch '3741' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang May 20, 2024
019d361
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang May 20, 2024
50b0009
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 20, 2024
fbe438b
delete useless info
Chengqian-Zhang May 20, 2024
cac06ec
Solve comflict
Chengqian-Zhang May 20, 2024
acb2a67
Solve comflict 2
Chengqian-Zhang May 20, 2024
afaa455
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 20, 2024
8568fcf
Change doc
Chengqian-Zhang May 20, 2024
539f745
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang May 20, 2024
84a5f1d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 20, 2024
041152d
Change assert info
Chengqian-Zhang May 20, 2024
e2547e5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 20, 2024
5920a56
Update deepmd/main.py
Chengqian-Zhang May 21, 2024
cce4434
Change to
Chengqian-Zhang May 21, 2024
76a1f15
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 21, 2024
83e3f3d
Change dp --pt list-model-branch model.pt to dp --pt show model.ot --…
Chengqian-Zhang May 21, 2024
040921d
refactor dp show and add UT
Chengqian-Zhang May 22, 2024
b2d2549
delete useless file
Chengqian-Zhang May 22, 2024
b5cf87b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2024
34d602f
change doc
Chengqian-Zhang May 22, 2024
a2cac49
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang May 22, 2024
dbdacd5
Solve pre-commit
Chengqian-Zhang May 22, 2024
5759897
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 22, 2024
d31ce48
Merge branch 'devel' into 3742
Chengqian-Zhang May 22, 2024
4311a2c
Merge branch 'devel' into 3742
iProzd May 23, 2024
0630733
Change UT
Chengqian-Zhang May 24, 2024
a0bc7a9
Delete output.txt
Chengqian-Zhang May 24, 2024
138b3c2
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang May 24, 2024
e0c59c2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 24, 2024
e3f426d
Merge branch 'devel' into 3742
iProzd May 24, 2024
b2361f2
Debug: delete UT
Chengqian-Zhang May 24, 2024
6cf96c1
Add UT again
Chengqian-Zhang May 24, 2024
586697f
Update source/tests/pt/test_dp_show.py
Chengqian-Zhang May 24, 2024
ba6fef5
Update source/tests/pt/test_dp_show.py
Chengqian-Zhang May 24, 2024
4270df0
Update source/tests/pt/test_dp_show.py
Chengqian-Zhang May 24, 2024
3de8737
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 24, 2024
7a2873f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 24, 2024
8fa2e79
Debug remote
Chengqian-Zhang May 24, 2024
511f799
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 24, 2024
5a61eb5
Solve pre-commit
Chengqian-Zhang May 24, 2024
4431c50
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang May 24, 2024
d8dadda
one test debug
Chengqian-Zhang May 24, 2024
b869cc0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 24, 2024
68eda81
Add 2 UT
Chengqian-Zhang May 24, 2024
7cfab57
Add 2 UT
Chengqian-Zhang May 24, 2024
5554dd2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 24, 2024
5f49f40
Merge branch 'devel' into 3742
Chengqian-Zhang May 27, 2024
a4800e2
change UT
Chengqian-Zhang May 27, 2024
f3ccd04
Change UT
Chengqian-Zhang May 27, 2024
ec2659d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 27, 2024
ed87119
Add error test
Chengqian-Zhang May 27, 2024
42b5990
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang May 27, 2024
ba41868
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 27, 2024
0a679b9
rerun UT
Chengqian-Zhang May 27, 2024
cae47aa
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang May 27, 2024
0d1e35b
rerun UT
Chengqian-Zhang May 27, 2024
d549b21
Delete error UT
Chengqian-Zhang May 27, 2024
0aa62ab
Merge branch 'devel' into 3742
Chengqian-Zhang May 28, 2024
fb47a3b
Add erro UT
Chengqian-Zhang May 28, 2024
2d3454d
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang May 28, 2024
f6a6d46
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] May 28, 2024
0d1c29d
Merge branch 'devel' into 3742
Chengqian-Zhang May 28, 2024
d9cb79f
Merge branch 'devel' into 3742
wanghan-iapcm May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions deepmd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ def main_parser() -> argparse.ArgumentParser:
default="",
help="(Supported backend: PyTorch) Model branch chosen for fine-tuning if multi-task. If not specified, it will re-init the fitting net.",
)
parser_train.add_argument(
"--list-model-branch",
action="store_true",
help="(Supported backend: PyTorch) List model branches of a multitask pretrained model.",
)
parser_train.add_argument(
"--force-load",
action="store_true",
Expand Down
19 changes: 18 additions & 1 deletion deepmd/pt/entrypoints/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
from deepmd.pt.train import (
training,
)
from deepmd.pt.utils import (
env,
)
from deepmd.pt.utils.dataloader import (
DpLoaderSet,
)
Expand Down Expand Up @@ -309,7 +312,21 @@
log.info("DeepMD version: %s", __version__)

if FLAGS.command == "train":
train(FLAGS)
if FLAGS.list_model_branch:
assert (

Check warning on line 316 in deepmd/pt/entrypoints/main.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/entrypoints/main.py#L316

Added line #L316 was not covered by tests
FLAGS.finetune is not None
), "Error: The '--list-model-branch' option requires the '--finetune' argument to specify the model."
state_dict = torch.load(FLAGS.finetune, map_location=env.DEVICE)
if "model" in state_dict:
state_dict = state_dict["model"]
model_params = state_dict["_extra_state"]["model_params"]
finetune_from_multi_task = "model_dict" in model_params

Check warning on line 323 in deepmd/pt/entrypoints/main.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/entrypoints/main.py#L319-L323

Added lines #L319 - L323 were not covered by tests
# Pretrained model must be multitask mode
assert finetune_from_multi_task, "Error: The '--list-model-branch' option requires a multitask pretrained model. The provided model does not meet this criterion."
model_branch = list(model_params["model_dict"].keys())
log.info(f"Available model branches are {model_branch}")

Check warning on line 327 in deepmd/pt/entrypoints/main.py

View check run for this annotation

Codecov / codecov/patch

deepmd/pt/entrypoints/main.py#L325-L327

Added lines #L325 - L327 were not covered by tests
else:
train(FLAGS)
elif FLAGS.command == "freeze":
if Path(FLAGS.checkpoint_folder).is_dir():
checkpoint_path = Path(FLAGS.checkpoint_folder)
Expand Down
9 changes: 5 additions & 4 deletions doc/train/finetuning.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ $ dp --pt train input.json --finetune multitask_pretrained.pt --model-branch CHO
```

:::{note}
To check the available model branches, you can typically refer to the documentation of the pre-trained model.
If you're still unsure about the available branches, you can try inputting an arbitrary branch name.
This will prompt an error message that displays a list of all the available model branches.
One can check the available model branches in multi-task pre-trained model by refering to the documentation of the pre-trained model or by using the following command:

```bash
$ dp --pt train input.json --finetune multitask_pretrained.pt --list-model-branch
```

Please note that this feature will be improved in the upcoming version to provide a more user-friendly experience.
:::

This command will start fine-tuning based on the pre-trained model's descriptor and the selected branch's fitting net.
Expand Down
Loading