-
Notifications
You must be signed in to change notification settings - Fork 570
feat(tf): implement change-bias command #4927
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 2 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
781de36
Initial plan
Copilot 9d25645
feat(tf): add change-bias command support for TensorFlow backend
Copilot e42ce04
Changes before error encountered
Copilot c1c3bcd
fix(tf): address code review feedback - use j_loader and follow consi…
Copilot 272e087
fix(tf): address code review feedback - remove unused imports, fix Ru…
Copilot 6a60acd
Addressing PR comments
Copilot 63a94e8
Changes before error encountered
Copilot 0d97532
fix: remove test artifacts and add coverage files to .gitignore
Copilot d86fe63
feat(tf): implement comprehensive change-bias support addressing code…
Copilot 759d636
feat(tf): remove checkpoint directory support, output single model fi…
Copilot 5ea02e7
fix(tf): pass log_level to RunOptions and clarify variable restoratio…
Copilot 9db5460
fix(tf): properly initialize session and restore checkpoint variables…
Copilot ec6b2fa
fix(tf): properly call build before _init_session in change_bias
Copilot 8e018ef
fix(tf): properly restore checkpoint variables in change_bias by read…
Copilot 67ba8f7
style: fix linting issues in cross-backend change-bias test
Copilot 44b9f20
Addressing PR comments
Copilot 10d60e7
refactor: simplify tests and remove redundant CLI help checks
Copilot 2a85218
chore: remove empty consistent test file for change-bias
Copilot 88a87d9
Potential fix for code scanning alert no. 9901: Unused local variable
njzjz f14ddc0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 72ca58f
fix(tf): save updated checkpoint files after change_bias variable mod…
Copilot 697e3b0
feat(tf): save updated checkpoint files in separate directory to avoi…
Copilot 190864a
fix(tf): remove redundant logging in change_bias
Copilot 2096f7a
docs: add TensorFlow backend support to change-bias documentation
Copilot 5faffab
Refactor change-bias documentation for clarity
njzjz 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
njzjz marked this conversation as resolved.
Show resolved
Hide resolved
|
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,94 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
import tempfile | ||
import unittest | ||
from pathlib import ( | ||
Path, | ||
) | ||
|
||
from deepmd.tf.entrypoints.main import ( | ||
change_bias, | ||
) | ||
|
||
|
||
class TestChangeBias(unittest.TestCase): | ||
def setUp(self): | ||
"""Set up test fixtures.""" | ||
self.temp_dir = tempfile.mkdtemp() | ||
self.temp_path = Path(self.temp_dir) | ||
|
||
def tearDown(self): | ||
"""Clean up test fixtures.""" | ||
import shutil | ||
|
||
shutil.rmtree(self.temp_dir, ignore_errors=True) | ||
|
||
def test_change_bias_frozen_model_not_implemented(self): | ||
"""Test that frozen model support raises NotImplementedError.""" | ||
fake_pb = self.temp_path / "model.pb" | ||
fake_pb.write_text("fake model content") | ||
|
||
with self.assertRaises(NotImplementedError) as cm: | ||
change_bias( | ||
input_file=str(fake_pb), | ||
mode="change", | ||
system=".", | ||
) | ||
|
||
self.assertIn("Bias changing for frozen models", str(cm.exception)) | ||
self.assertIn(".pb/.pbtxt", str(cm.exception)) | ||
|
||
def test_change_bias_invalid_model_type(self): | ||
"""Test that invalid model types raise RuntimeError.""" | ||
fake_model = self.temp_path / "model.xyz" | ||
fake_model.write_text("fake model content") | ||
|
||
with self.assertRaises(RuntimeError) as cm: | ||
change_bias( | ||
input_file=str(fake_model), | ||
mode="change", | ||
system=".", | ||
) | ||
|
||
self.assertIn("checkpoint directory or frozen model file", str(cm.exception)) | ||
|
||
def test_change_bias_no_checkpoint_in_directory(self): | ||
"""Test that missing checkpoint in directory raises RuntimeError.""" | ||
fake_dir = self.temp_path / "fake_checkpoint" | ||
fake_dir.mkdir() | ||
|
||
# Create a fake data system for the test | ||
fake_data_dir = self.temp_path / "fake_data" | ||
fake_data_dir.mkdir() | ||
fake_set_dir = fake_data_dir / "set.000" | ||
fake_set_dir.mkdir() | ||
|
||
with self.assertRaises(RuntimeError) as cm: | ||
change_bias( | ||
input_file=str(fake_dir), | ||
mode="change", | ||
system=str(fake_data_dir), | ||
) | ||
|
||
self.assertIn("No valid checkpoint found", str(cm.exception)) | ||
|
||
def test_change_bias_user_defined_not_implemented(self): | ||
"""Test that user-defined bias raises NotImplementedError.""" | ||
fake_dir = self.temp_path / "fake_checkpoint" | ||
fake_dir.mkdir() | ||
(fake_dir / "checkpoint").write_text("fake checkpoint") | ||
|
||
with self.assertRaises(NotImplementedError) as cm: | ||
change_bias( | ||
input_file=str(fake_dir), | ||
mode="change", | ||
bias_value=[1.0, 2.0], | ||
system=".", | ||
) | ||
|
||
self.assertIn( | ||
"User-defined bias setting is not yet implemented", str(cm.exception) | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
Oops, something went wrong.
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.