-
Notifications
You must be signed in to change notification settings - Fork 599
feat: add new batch size rules for large systems #4659
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
17 commits
Select commit
Hold shift + click to select a range
33f4c15
feat: add new batch size rules for large systems
caic99 8ba1d28
use logger for class scope
caic99 ec47d31
ensure at least one system left
caic99 18a0f13
change keyword name to `filter`
caic99 f169a98
add ut
caic99 7ade4af
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 10defcb
add test for unknown batch size handling
caic99 199d9b7
add debug info
caic99 63392f6
Update source/tests/pt/test_dploaderset.py
caic99 5bf8fff
Update source/tests/pt/test_dploaderset.py
caic99 5fa3582
test: capture log by explicitly setting logger name `deepmd`
caic99 b43a4ab
add docs
caic99 456868f
update argcheck params
caic99 8a5fc80
avoid using assert
caic99 281959e
port the impl to paddle backend
caic99 aa07bf1
update docs
caic99 bb41847
fix UT
caic99 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,86 @@ | ||
| # SPDX-License-Identifier: LGPL-3.0-or-later | ||
| import json | ||
| import unittest | ||
| from pathlib import ( | ||
| Path, | ||
| ) | ||
|
|
||
| from deepmd.common import ( | ||
| expand_sys_str, | ||
| ) | ||
| from deepmd.pt.utils.dataloader import ( | ||
| DpLoaderSet, | ||
| ) | ||
|
|
||
|
|
||
| class TestSampler(unittest.TestCase): | ||
| def setUp(self) -> None: | ||
| with open(str(Path(__file__).parent / "water/se_e2_a.json")) as fin: | ||
| content = fin.read() | ||
| config = json.loads(content) | ||
| data_file = [ | ||
| str(Path(__file__).parent / "model/water/data/data_0"), | ||
| ] | ||
| config["training"]["training_data"]["systems"] = data_file | ||
| config["training"]["validation_data"]["systems"] = data_file | ||
| model_config = config["model"] | ||
| self.rcut = model_config["descriptor"]["rcut"] | ||
| self.rcut_smth = model_config["descriptor"]["rcut_smth"] | ||
| self.sel = model_config["descriptor"]["sel"] | ||
| self.batch_size = config["training"]["training_data"]["batch_size"] | ||
| self.systems = config["training"]["validation_data"]["systems"] | ||
| self.type_map = model_config["type_map"] | ||
| if isinstance(self.systems, str): | ||
| self.systems = expand_sys_str(self.systems) | ||
|
|
||
| def get_batch_sizes(self, batch_size) -> int: | ||
| dataset = DpLoaderSet( | ||
| self.systems, | ||
| batch_size, | ||
| self.type_map, | ||
| seed=10, | ||
| shuffle=False, | ||
| ) | ||
| return dataset.batch_sizes[0] | ||
|
|
||
| def test_batchsize(self) -> None: | ||
| # 192 atoms, 1 system | ||
| assert len(self.systems) == 1 | ||
|
|
||
| # test: batch_size:int | ||
| self.assertEqual(self.get_batch_sizes(3), 3) | ||
|
|
||
| # test: batch_size:list[int] | ||
| self.assertEqual(self.get_batch_sizes([3]), 3) | ||
|
|
||
| # test: batch_size:str = "auto" | ||
| self.assertEqual(self.get_batch_sizes("auto:384"), 2) | ||
| self.assertEqual(self.get_batch_sizes("auto:383"), 2) | ||
| self.assertEqual(self.get_batch_sizes("auto:193"), 2) | ||
| self.assertEqual(self.get_batch_sizes("auto:192"), 1) | ||
| self.assertEqual(self.get_batch_sizes("auto:191"), 1) | ||
| self.assertEqual(self.get_batch_sizes("auto:32"), 1) | ||
| self.assertEqual(self.get_batch_sizes("auto"), 1) | ||
|
|
||
| # test: batch_size:str = "max" | ||
| self.assertEqual(self.get_batch_sizes("max:384"), 2) | ||
| self.assertEqual(self.get_batch_sizes("max:383"), 1) | ||
| self.assertEqual(self.get_batch_sizes("max:193"), 1) | ||
| self.assertEqual(self.get_batch_sizes("max:192"), 1) | ||
| self.assertEqual(self.get_batch_sizes("max:191"), 1) | ||
|
|
||
| # test: batch_size:str = "filter" | ||
| self.assertEqual(self.get_batch_sizes("filter:193"), 1) | ||
| self.assertEqual(self.get_batch_sizes("filter:192"), 1) | ||
| with self.assertLogs(logger="deepmd") as cm: | ||
| self.assertRaises(ValueError, self.get_batch_sizes, "filter:191") | ||
| self.assertIn("Remove 1 systems with more than 191 atoms", cm.output[-1]) | ||
|
|
||
| # test: unknown batch_size: str | ||
| with self.assertRaises(ValueError) as context: | ||
| self.get_batch_sizes("unknown") | ||
| self.assertIn("Unsupported batch size rule: unknown", str(context.exception)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.