Skip to content

Adding and use assertAllClose API in our tests.  #34096

@ailzhang

Description

@ailzhang

Currently we have many uses of

self.assertEqual(ans.shape, expected.shape)
self.assertTrue(np.allclose(ans.cpu(), expected, rtol=1e-02, atol=1e-03, equal_nan=True))

in our tests. e.g. https://github.com/pytorch/pytorch/blob/master/test/test_torch.py#L11270
torch.allclose won't work well here as it only accept two tensors.
But this way is hard for backends like XLA to override precisions :P
We want to propose make an API

self.assertAllClose(torch_tensor, np_array, rtol, atol, equal_nan)

to replace it.
@mruberry @gchanan @ezyang Does this sound good?
cc: @JackCaoG

Metadata

Metadata

Assignees

Labels

enhancementNot as big of a feature, but technically not a bug. Should be easy to fixmodule: testsIssues related to tests (not the torch.testing module)triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions