Skip to content

Commit

Permalink
pt: ban torch.testing.assert_allclose (#3395)
Browse files Browse the repository at this point in the history
See pytorch/pytorch#61844

Signed-off-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
njzjz authored Mar 3, 2024
1 parent 59d3b12 commit 8d0e3ba
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ select = [
"C4", # flake8-comprehensions
"RUF", # ruff
"NPY", # numpy
"TID251", # banned-api
"TID253", # banned-module-level-imports
]

Expand Down Expand Up @@ -272,6 +273,9 @@ banned-module-level-imports = [
"torch",
]

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"torch.testing.assert_allclose".msg = "Use `torch.testing.assert_close()` instead, see https://github.com/pytorch/pytorch/issues/61844."

[tool.ruff.lint.extend-per-file-ignores]
# Also ignore `E402` in all `__init__.py` files.
"deepmd/tf/**" = ["TID253"]
Expand Down
2 changes: 1 addition & 1 deletion source/tests/pt/test_multitask.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_multitask_train(self):
if "model_2" in state_key:
self.assertIn(state_key.replace("model_2", "model_1"), multi_state_dict)
if "model_1.descriptor" in state_key:
torch.testing.assert_allclose(
torch.testing.assert_close(
multi_state_dict[state_key],
multi_state_dict[state_key.replace("model_1", "model_2")],
)
Expand Down
2 changes: 1 addition & 1 deletion source/tests/pt/test_training.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_trainable(self):
trainer_fix.run()
model_dict_after_training = deepcopy(trainer_fix.model.state_dict())
for key in model_dict_before_training:
torch.testing.assert_allclose(
torch.testing.assert_close(
model_dict_before_training[key], model_dict_after_training[key]
)
self.tearDown()
Expand Down

0 comments on commit 8d0e3ba

Please sign in to comment.