Unverified Commit d11b5068 authored by Titus's avatar Titus Committed by GitHub
Browse files

tests: fix all_close to respect max 2 positional args (#1074)

parent 0bf71989
...@@ -26,12 +26,12 @@ k = 20 ...@@ -26,12 +26,12 @@ k = 20
def assert_all_approx_close(a, b, rtol=1e-3, atol=1e-3, count=0, throw=True): 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() sumval = (idx == 0).sum().item()
if sumval > count: if sumval > count:
if throw: if throw:
print(f"Too many values not close: assert {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)
return sumval return sumval
......
...@@ -42,11 +42,11 @@ def get_args(): ...@@ -42,11 +42,11 @@ def get_args():
def assert_all_approx_close(a, b, atol=1e-8, rtol=1e-5, count=10): 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() sumval = (idx == 0).sum().item()
if sumval > count: if sumval > count:
print(f"Too many values not close: assert {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): class LinearFunction(torch.autograd.Function):
......
...@@ -145,7 +145,7 @@ def test_optimizer32bit(dim1, dim2, gtype, optim_name): ...@@ -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 # since Lion can have pretty noisy updates where things lie at the boundary
# allow up to 10 errors for Lion # 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: if i % (k // 5) == 0 and i > 0:
path = get_temp_dir() path = get_temp_dir()
...@@ -157,7 +157,7 @@ def test_optimizer32bit(dim1, dim2, gtype, optim_name): ...@@ -157,7 +157,7 @@ def test_optimizer32bit(dim1, dim2, gtype, optim_name):
rm_path(path) rm_path(path)
# since Lion can have pretty noisy updates where things lie at the boundary # since Lion can have pretty noisy updates where things lie at the boundary
# allow up to 10 errors for Lion # 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]: for name1, name2 in str2statenames[optim_name]:
# since Lion can have pretty noisy updates where things lie at the boundary # since Lion can have pretty noisy updates where things lie at the boundary
# allow up to 10 errors for Lion # allow up to 10 errors for Lion
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment