Used torch.equal in test_foreach_copy_with_multi_dtypes (#134861)

`self.assertEqual` allows some tolerance, but here, we want to show that `_foreach_copy_` gives bitwise equivalent results. Let us use `torch.equal` then.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/134861
Approved by: https://github.com/Skylion007, https://github.com/janeyx99, https://github.com/crcrpar
This commit is contained in:
Andrew Gu
2024-08-30 08:39:18 -07:00
committed by PyTorch MergeBot
parent 1993a2aa9e
commit a0d0c6b7e6

View File

@ -1302,13 +1302,12 @@ class TestForeach(TestCase):
out = foreach_copy_(
(self_tensors, src_tensors), is_cuda=True, expect_fastpath=True
)
self.assertEqual(
out,
[
torch.empty_like(t).copy_(s)
for t, s in zip(self_tensors, src_tensors)
],
)
ref_out = [
torch.empty_like(t).copy_(s)
for t, s in zip(self_tensors, src_tensors)
]
for t, ref_t in zip(out, ref_out):
self.assertTrue(torch.equal(t, ref_t))
# Test reverse-mode & forward-mode AD if supported.
@onlyCUDA