-
Notifications
You must be signed in to change notification settings - Fork 599
feat(pt): Add command to check the available model branches in multi-task pre-trained model(Issue #3742) #3796
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
Merged
Merged
Changes from all commits
Commits
Show all changes
74 commits
Select commit
Hold shift + click to select a range
5485d15
Init 3742
Chengqian-Zhang 1ecb898
change trival error
Chengqian-Zhang c684419
change help info
Chengqian-Zhang f5dea36
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f60300a
Merge branch 'devel' into 3742
Chengqian-Zhang 09d2fec
Update deepmd/pt/entrypoints/main.py
Chengqian-Zhang 6a8b1b4
init 3741
Chengqian-Zhang be6b71c
Add doc
Chengqian-Zhang 065cc2d
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang c30ac5a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8a8f027
Change list-model-branch to command
Chengqian-Zhang 84e8698
Merge branch '3741' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang 019d361
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang 50b0009
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] fbe438b
delete useless info
Chengqian-Zhang cac06ec
Solve comflict
Chengqian-Zhang acb2a67
Solve comflict 2
Chengqian-Zhang afaa455
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8568fcf
Change doc
Chengqian-Zhang 539f745
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang 84a5f1d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 041152d
Change assert info
Chengqian-Zhang e2547e5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5920a56
Update deepmd/main.py
Chengqian-Zhang cce4434
Change to
Chengqian-Zhang 76a1f15
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 83e3f3d
Change dp --pt list-model-branch model.pt to dp --pt show model.ot --…
Chengqian-Zhang 040921d
refactor dp show and add UT
Chengqian-Zhang b2d2549
delete useless file
Chengqian-Zhang b5cf87b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 34d602f
change doc
Chengqian-Zhang a2cac49
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang dbdacd5
Solve pre-commit
Chengqian-Zhang 5759897
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] d31ce48
Merge branch 'devel' into 3742
Chengqian-Zhang 4311a2c
Merge branch 'devel' into 3742
iProzd 0630733
Change UT
Chengqian-Zhang a0bc7a9
Delete output.txt
Chengqian-Zhang 138b3c2
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang e0c59c2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e3f426d
Merge branch 'devel' into 3742
iProzd b2361f2
Debug: delete UT
Chengqian-Zhang 6cf96c1
Add UT again
Chengqian-Zhang 586697f
Update source/tests/pt/test_dp_show.py
Chengqian-Zhang ba6fef5
Update source/tests/pt/test_dp_show.py
Chengqian-Zhang 4270df0
Update source/tests/pt/test_dp_show.py
Chengqian-Zhang 3de8737
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7a2873f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 8fa2e79
Debug remote
Chengqian-Zhang 511f799
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5a61eb5
Solve pre-commit
Chengqian-Zhang 4431c50
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang d8dadda
one test debug
Chengqian-Zhang b869cc0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 68eda81
Add 2 UT
Chengqian-Zhang 7cfab57
Add 2 UT
Chengqian-Zhang 5554dd2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 5f49f40
Merge branch 'devel' into 3742
Chengqian-Zhang a4800e2
change UT
Chengqian-Zhang f3ccd04
Change UT
Chengqian-Zhang ec2659d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] ed87119
Add error test
Chengqian-Zhang 42b5990
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang ba41868
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0a679b9
rerun UT
Chengqian-Zhang cae47aa
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang 0d1e35b
rerun UT
Chengqian-Zhang d549b21
Delete error UT
Chengqian-Zhang 0aa62ab
Merge branch 'devel' into 3742
Chengqian-Zhang fb47a3b
Add erro UT
Chengqian-Zhang 2d3454d
Merge branch '3742' of github.com:Chengqian-Zhang/deepmd-kit into 3742
Chengqian-Zhang f6a6d46
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 0d1c29d
Merge branch 'devel' into 3742
Chengqian-Zhang d9cb79f
Merge branch 'devel' into 3742
wanghan-iapcm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
| from deepmd.pt.entrypoints.main import ( | ||
| main, | ||
| ) | ||
|
|
||
|
|
||
| def run_dp(cmd: str) -> int: | ||
| """Run DP directly from the entry point instead of the subprocess. | ||
|
|
||
| It is quite slow to start DeePMD-kit with subprocess. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| cmd : str | ||
| The command to run. | ||
|
|
||
| Returns | ||
| ------- | ||
| int | ||
| Always returns 0. | ||
| """ | ||
| cmds = cmd.split() | ||
| if cmds[0] == "dp": | ||
| cmds = cmds[1:] | ||
| else: | ||
| raise RuntimeError("The command is not dp") | ||
|
|
||
| main(cmds) | ||
| return 0 |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
| import io | ||
| import json | ||
| import os | ||
| import shutil | ||
| import unittest | ||
| from contextlib import ( | ||
| redirect_stderr, | ||
| ) | ||
| from copy import ( | ||
| deepcopy, | ||
| ) | ||
| from pathlib import ( | ||
| Path, | ||
| ) | ||
|
|
||
| from deepmd.pt.entrypoints.main import ( | ||
| get_trainer, | ||
| ) | ||
| from deepmd.pt.utils.multi_task import ( | ||
| preprocess_shared_params, | ||
Chengqian-Zhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| from .common import ( | ||
| run_dp, | ||
| ) | ||
| from .model.test_permutation import ( | ||
| model_se_e2_a, | ||
| ) | ||
|
|
||
|
|
||
| class TestSingleTaskModel(unittest.TestCase): | ||
| def setUp(self): | ||
| input_json = str(Path(__file__).parent / "water/se_atten.json") | ||
| with open(input_json) as f: | ||
| self.config = json.load(f) | ||
| self.config["training"]["numb_steps"] = 1 | ||
| self.config["training"]["save_freq"] = 1 | ||
| data_file = [str(Path(__file__).parent / "water/data/single")] | ||
| self.config["training"]["training_data"]["systems"] = data_file | ||
| self.config["training"]["validation_data"]["systems"] = data_file | ||
| self.config["model"] = deepcopy(model_se_e2_a) | ||
| self.config["model"]["type_map"] = ["O", "H", "Au"] | ||
| trainer = get_trainer(deepcopy(self.config)) | ||
| trainer.run() | ||
| run_dp("dp --pt freeze") | ||
|
|
||
| def test_checkpoint(self): | ||
| INPUT = "model.pt" | ||
| ATTRIBUTES = "type-map descriptor fitting-net" | ||
| with redirect_stderr(io.StringIO()) as f: | ||
| run_dp(f"dp --pt show {INPUT} {ATTRIBUTES}") | ||
| results = f.getvalue().split("\n")[:-1] | ||
| assert "This is a singletask model" in results[-4] | ||
| assert "The type_map is ['O', 'H', 'Au']" in results[-3] | ||
| assert ( | ||
| "{'type': 'se_e2_a'" and "'sel': [46, 92, 4]" and "'rcut': 4.0" | ||
| ) in results[-2] | ||
| assert ( | ||
| "The fitting_net parameter is {'neuron': [24, 24, 24], 'resnet_dt': True, 'seed': 1}" | ||
| in results[-1] | ||
| ) | ||
|
|
||
| def test_frozen_model(self): | ||
| INPUT = "frozen_model.pth" | ||
| ATTRIBUTES = "type-map descriptor fitting-net" | ||
| with redirect_stderr(io.StringIO()) as f: | ||
| run_dp(f"dp --pt show {INPUT} {ATTRIBUTES}") | ||
| results = f.getvalue().split("\n")[:-1] | ||
| assert "This is a singletask model" in results[-4] | ||
| assert "The type_map is ['O', 'H', 'Au']" in results[-3] | ||
| assert ( | ||
| "{'type': 'se_e2_a'" and "'sel': [46, 92, 4]" and "'rcut': 4.0" | ||
| ) in results[-2] | ||
| assert ( | ||
| "The fitting_net parameter is {'neuron': [24, 24, 24], 'resnet_dt': True, 'seed': 1}" | ||
| in results[-1] | ||
| ) | ||
|
|
||
| def test_checkpoint_error(self): | ||
|
||
| INPUT = "model.pt" | ||
| ATTRIBUTES = "model-branch type-map descriptor fitting-net" | ||
| with self.assertRaisesRegex( | ||
| RuntimeError, "The 'model-branch' option requires a multitask model" | ||
| ): | ||
| run_dp(f"dp --pt show {INPUT} {ATTRIBUTES}") | ||
|
|
||
| def tearDown(self): | ||
| for f in os.listdir("."): | ||
| if f.startswith("model") and f.endswith("pt"): | ||
| os.remove(f) | ||
| if f in ["lcurve.out", "frozen_model.pth", "output.txt", "checkpoint"]: | ||
| os.remove(f) | ||
| if f in ["stat_files"]: | ||
| shutil.rmtree(f) | ||
Chengqian-Zhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| class TestMultiTaskModel(unittest.TestCase): | ||
| def setUp(self): | ||
| input_json = str(Path(__file__).parent / "water/multitask.json") | ||
| with open(input_json) as f: | ||
| self.config = json.load(f) | ||
| self.config["model"]["shared_dict"]["my_descriptor"] = model_se_e2_a[ | ||
| "descriptor" | ||
| ] | ||
| data_file = [str(Path(__file__).parent / "water/data/data_0")] | ||
| self.stat_files = "se_e2_a" | ||
| os.makedirs(self.stat_files, exist_ok=True) | ||
| self.config["training"]["data_dict"]["model_1"]["training_data"]["systems"] = ( | ||
| data_file | ||
| ) | ||
| self.config["training"]["data_dict"]["model_1"]["validation_data"][ | ||
| "systems" | ||
| ] = data_file | ||
| self.config["training"]["data_dict"]["model_1"]["stat_file"] = ( | ||
| f"{self.stat_files}/model_1" | ||
| ) | ||
| self.config["training"]["data_dict"]["model_2"]["training_data"]["systems"] = ( | ||
| data_file | ||
| ) | ||
| self.config["training"]["data_dict"]["model_2"]["validation_data"][ | ||
| "systems" | ||
| ] = data_file | ||
| self.config["training"]["data_dict"]["model_2"]["stat_file"] = ( | ||
| f"{self.stat_files}/model_2" | ||
| ) | ||
| self.config["model"]["model_dict"]["model_1"]["fitting_net"] = { | ||
| "neuron": [1, 2, 3], | ||
| "seed": 678, | ||
| } | ||
| self.config["model"]["model_dict"]["model_2"]["fitting_net"] = { | ||
| "neuron": [9, 8, 7], | ||
| "seed": 1111, | ||
| } | ||
| self.config["training"]["numb_steps"] = 1 | ||
| self.config["training"]["save_freq"] = 1 | ||
| self.origin_config = deepcopy(self.config) | ||
| self.config["model"], self.shared_links = preprocess_shared_params( | ||
| self.config["model"] | ||
| ) | ||
| trainer = get_trainer(deepcopy(self.config), shared_links=self.shared_links) | ||
| trainer.run() | ||
| run_dp("dp --pt freeze --head model_1") | ||
|
|
||
| def test_checkpoint(self): | ||
| INPUT = "model.ckpt.pt" | ||
| ATTRIBUTES = "model-branch type-map descriptor fitting-net" | ||
| with redirect_stderr(io.StringIO()) as f: | ||
| run_dp(f"dp --pt show {INPUT} {ATTRIBUTES}") | ||
| results = f.getvalue().split("\n")[:-1] | ||
| assert "This is a multitask model" in results[-8] | ||
| assert "Available model branches are ['model_1', 'model_2']" in results[-7] | ||
| assert "The type_map of branch model_1 is ['O', 'H', 'B']" in results[-6] | ||
| assert "The type_map of branch model_2 is ['O', 'H', 'B']" in results[-5] | ||
| assert ( | ||
| "model_1" | ||
| and "'type': 'se_e2_a'" | ||
| and "'sel': [46, 92, 4]" | ||
| and "'rcut_smth': 0.5" | ||
| ) in results[-4] | ||
| assert ( | ||
| "model_2" | ||
| and "'type': 'se_e2_a'" | ||
| and "'sel': [46, 92, 4]" | ||
| and "'rcut_smth': 0.5" | ||
| ) in results[-3] | ||
| assert ( | ||
| "The fitting_net parameter of branch model_1 is {'neuron': [1, 2, 3], 'seed': 678}" | ||
| in results[-2] | ||
| ) | ||
| assert ( | ||
| "The fitting_net parameter of branch model_2 is {'neuron': [9, 8, 7], 'seed': 1111}" | ||
| in results[-1] | ||
| ) | ||
|
|
||
| def test_frozen_model(self): | ||
| INPUT = "frozen_model.pth" | ||
| ATTRIBUTES = "type-map descriptor fitting-net" | ||
| with redirect_stderr(io.StringIO()) as f: | ||
| run_dp(f"dp --pt show {INPUT} {ATTRIBUTES}") | ||
| results = f.getvalue().split("\n")[:-1] | ||
| assert "This is a singletask model" in results[-4] | ||
| assert "The type_map is ['O', 'H', 'B']" in results[-3] | ||
| assert ( | ||
| "'type': 'se_e2_a'" and "'sel': [46, 92, 4]" and "'rcut_smth': 0.5" | ||
| ) in results[-2] | ||
| assert ( | ||
| "The fitting_net parameter is {'neuron': [1, 2, 3], 'seed': 678}" | ||
| in results[-1] | ||
| ) | ||
|
|
||
| def tearDown(self): | ||
| for f in os.listdir("."): | ||
| if f.startswith("model") and f.endswith("pt"): | ||
| os.remove(f) | ||
| if f in ["lcurve.out", "frozen_model.pth", "checkpoint", "output.txt"]: | ||
| os.remove(f) | ||
| if f in ["stat_files", self.stat_files]: | ||
| shutil.rmtree(f) | ||
Chengqian-Zhang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.