Skip to content

Commit

Permalink
fix: fix PyTorch model extension in simplify (#1596)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
- Improved model file search logic to dynamically construct file
patterns, ensuring better compatibility with different model suffixes.
- Added an assertion to ensure at least one model file is found,
providing clearer error messaging when no models are present.

- **Tests**
- Enhanced test setup by generating fake model files, improving
robustness and reliability of tests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Jinzhe Zeng <[email protected]>
Co-authored-by: Han Wang <[email protected]>
  • Loading branch information
njzjz and wanghan-iapcm authored Jul 19, 2024
1 parent 3a1ed00 commit b309304
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion dpgen/simplify/simplify.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ def run_model_devi(iter_index, jdata, mdata):
commands = []
run_tasks = ["."]
# get models
models = glob.glob(os.path.join(work_path, "graph*pb"))
suffix = _get_model_suffix(jdata)
models = glob.glob(os.path.join(work_path, f"graph*{suffix}"))
assert len(models) > 0, "No model file found."
model_names = [os.path.basename(ii) for ii in models]
task_model_list = []
for ii in model_names:
Expand Down
3 changes: 3 additions & 0 deletions tests/simplify/test_run_model_devi.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class TestOneH5(unittest.TestCase):
def setUp(self):
work_path = Path("iter.000000") / "01.model_devi"
work_path.mkdir(parents=True, exist_ok=True)
# fake models
for ii in range(4):
(work_path / f"graph.{ii:03d}.pb").touch()
with tempfile.TemporaryDirectory() as tmpdir:
with open(Path(tmpdir) / "test.xyz", "w") as f:
f.write(
Expand Down

0 comments on commit b309304

Please sign in to comment.