Skip to content

Commit

Permalink
[fbsync] Use torch.testing.assert_close in test_models.py (#3879)
Browse files Browse the repository at this point in the history
Summary: Co-authored-by: Philip Meier <github.pmeier@posteo.de>

Reviewed By: vincentqb, cpuhrsch

Differential Revision: D28679965

fbshipit-source-id: 18f1fb6e548afbb1d3b97ec88cc5d3f6d4699582
  • Loading branch information
datumbox authored and facebook-github-bot committed May 25, 2021
1 parent 29585bc commit 73e5297
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def check_out(out):
# predictions match.
expected_file = self._get_expected_file(name)
expected = torch.load(expected_file)
self.assertEqual(out.argmax(dim=1), expected.argmax(dim=1), prec=prec)
torch.testing.assert_close(out.argmax(dim=1), expected.argmax(dim=1), rtol=prec, atol=prec)
return False # Partial validation performed

return True # Full validation performed
Expand Down Expand Up @@ -205,7 +205,8 @@ def compute_mean_std(tensor):
# scores.
expected_file = self._get_expected_file(name)
expected = torch.load(expected_file)
self.assertEqual(output[0]["scores"], expected[0]["scores"], prec=prec)
torch.testing.assert_close(output[0]["scores"], expected[0]["scores"], rtol=prec, atol=prec,
check_device=False, check_dtype=False)

# Note: Fmassa proposed turning off NMS by adapting the threshold
# and then using the Hungarian algorithm as in DETR to find the
Expand Down Expand Up @@ -301,10 +302,8 @@ def test_memory_efficient_densenet(self):
model2.eval()
out2 = model2(x)

max_diff = (out1 - out2).abs().max()

self.assertTrue(num_params == num_grad)
self.assertTrue(max_diff < 1e-5)
torch.testing.assert_close(out1, out2, rtol=0.0, atol=1e-5)

def test_resnet_dilation(self):
# TODO improve tests to also check that each layer has the right dimensionality
Expand Down

0 comments on commit 73e5297

Please sign in to comment.