-
Notifications
You must be signed in to change notification settings - Fork 641
fix(pt_expt): reuse the stored min_nbor_dist and batch the neighbor statistics #5956
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
Open
yckbz
wants to merge
9
commits into
deepmodeling:master
Choose a base branch
from
yckbz:fix-pt-expt-min-nbor-dist
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
15a0b34
fix(pt_expt): read min_nbor_dist from @variables
yckbz 110e60b
fix(pt_expt): batch the neighbor statistics
yckbz 6681b32
Potential fix for pull request finding
yckbz 12e34ad
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 7d14eae
Merge branch 'master' into fix-pt-expt-min-nbor-dist
yckbz 0c88b50
fix(pt_expt): follow the selected device when auto-batching
yckbz d850ca9
fix(pt_expt): keep min_nbor_dist in the graph-lower output
yckbz f1423c1
fix(pt_expt): assign min_nbor_dist through the spin backbone
yckbz cbb5117
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 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
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,70 @@ | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
| """Tests for reading the stored minimal neighbor distance in pt_expt compress.""" | ||
|
|
||
| from typing import ( | ||
| Any, | ||
| ) | ||
|
|
||
| import pytest | ||
|
|
||
| from deepmd.main import ( | ||
| parse_args, | ||
| ) | ||
| from deepmd.pt_expt.entrypoints.compress import ( | ||
| _read_saved_min_nbor_dist, | ||
| ) | ||
|
|
||
|
|
||
| class _FakeModel: | ||
| """Stand-in exposing only the getter that the reader calls.""" | ||
|
|
||
| def __init__(self, min_nbor_dist: float | None) -> None: | ||
| self._min_nbor_dist = min_nbor_dist | ||
|
|
||
| def get_min_nbor_dist(self) -> float | None: | ||
| return self._min_nbor_dist | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("model_min_nbor_dist", "model_dict", "expected"), | ||
| [ | ||
| # the model buffer wins over both metadata locations | ||
| ( | ||
| 1.5, | ||
| {"min_nbor_dist": 9.0, "@variables": {"min_nbor_dist": 8.0}}, | ||
| (1.5, "the model"), | ||
| ), | ||
| # the top-level key, written by pt_expt's own compress | ||
| ( | ||
| None, | ||
| {"min_nbor_dist": 2.5, "@variables": {"min_nbor_dist": 8.0}}, | ||
| (2.5, "the model file"), | ||
| ), | ||
| # "@variables", the cross-backend location that dp convert-backend writes | ||
| ( | ||
| None, | ||
| {"@variables": {"min_nbor_dist": 3.5}}, | ||
| (3.5, "the model file (@variables)"), | ||
| ), | ||
| # nothing stored anywhere | ||
| (None, {}, (None, "")), | ||
| (None, {"@variables": {}}, (None, "")), | ||
| (None, {"@variables": None}, (None, "")), | ||
| ], | ||
| ) | ||
| def test_read_saved_min_nbor_dist( | ||
| model_min_nbor_dist: float | None, | ||
| model_dict: dict[str, Any], | ||
| expected: tuple[float | None, str], | ||
| ) -> None: | ||
| """Every storage location is honored, in order of precedence.""" | ||
| assert _read_saved_min_nbor_dist(_FakeModel(model_min_nbor_dist), model_dict) == ( | ||
| expected | ||
| ) | ||
|
|
||
|
|
||
| def test_recompute_min_nbor_dist_flag_defaults_to_false() -> None: | ||
| """The compress parser exposes the flag and leaves it off by default.""" | ||
| args = ["--pt-expt", "compress", "-i", "in.pt2", "-o", "out.pt2"] | ||
| assert parse_args(args).recompute_min_nbor_dist is False | ||
| assert parse_args([*args, "--recompute-min-nbor-dist"]).recompute_min_nbor_dist |
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.