Skip to content

Commit

Permalink
Added test in dynamo directory to check that the original and final e…
Browse files Browse the repository at this point in the history
…rror messages are both not obscured in the case that an exception happens. Also added a test for when an exception is not raised for completeness
  • Loading branch information
KevinHeeHee committed Apr 29, 2024
1 parent b040072 commit 9b70967
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/dynamo/test_same_allclose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import unittest
import torch
from torch._dynamo.testing import same

class TestSameAllclose(unittest.TestCase):
def test_same_allclose_exception(self):
ref = torch.tensor([1.0, 2.0, 3.0])
res = torch.tensor([1.0, 2.0, float('nan')])

try:
same(ref, res, equal_nan=False)
except RuntimeError as e:
self.assertIn("An unexpected error occurred while comparing tensors with torch.allclose", str(e))
self.assertIn("RuntimeError: The size of tensor a (3) must match the size of tensor b (3) at non-singleton dimension 0", str(e))
else:
self.fail("RuntimeError not raised")

def test_same_allclose_no_exception(self):
ref = torch.tensor([1.0, 2.0, 3.0])
res = torch.tensor([1.0, 2.0, 3.0])

self.assertTrue(same(ref, res))

if __name__ == '__main__':
unittest.main()

0 comments on commit 9b70967

Please sign in to comment.