Skip to content

Commit

Permalink
tests: fix all_close to respect max 2 positional args (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
Titus-von-Koeller committed Feb 21, 2024
1 parent 0bf7198 commit d11b506
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@


def assert_all_approx_close(a, b, rtol=1e-3, atol=1e-3, count=0, throw=True):
idx = torch.isclose(a, b, rtol, atol)
idx = torch.isclose(a, b, rtol=rtol, atol=atol)
sumval = (idx == 0).sum().item()
if sumval > count:
if throw:
print(f"Too many values not close: assert {sumval} < {count}")
torch.testing.assert_close(a, b, rtol, atol)
torch.testing.assert_close(a, b, rtol=rtol, atol=atol)

return sumval

Expand Down
4 changes: 2 additions & 2 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ def get_args():


def assert_all_approx_close(a, b, atol=1e-8, rtol=1e-5, count=10):
idx = torch.isclose(a, b, rtol, atol)
idx = torch.isclose(a, b, rtol=rtol, atol=atol)
sumval = (idx == 0).sum().item()
if sumval > count:
print(f"Too many values not close: assert {sumval} < {count}")
torch.testing.assert_close(a, b, rtol, atol)
torch.testing.assert_close(a, b, rtol=rtol, atol=atol)


class LinearFunction(torch.autograd.Function):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_optim.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_optimizer32bit(dim1, dim2, gtype, optim_name):

# since Lion can have pretty noisy updates where things lie at the boundary
# allow up to 10 errors for Lion
assert_most_approx_close(p1, p2.float(), atol, rtol, max_error_count=10)
assert_most_approx_close(p1, p2.float(), atol=atol, rtol=rtol, max_error_count=10)

if i % (k // 5) == 0 and i > 0:
path = get_temp_dir()
Expand All @@ -157,7 +157,7 @@ def test_optimizer32bit(dim1, dim2, gtype, optim_name):
rm_path(path)
# since Lion can have pretty noisy updates where things lie at the boundary
# allow up to 10 errors for Lion
assert_most_approx_close(p1, p2.float(), atol, rtol, max_error_count=10)
assert_most_approx_close(p1, p2.float(), atol=atol, rtol=rtol, max_error_count=10)
for name1, name2 in str2statenames[optim_name]:
# since Lion can have pretty noisy updates where things lie at the boundary
# allow up to 10 errors for Lion
Expand Down

0 comments on commit d11b506

Please sign in to comment.