From 12f7d284e0a35bf23c7721be39c52c43190f8038 Mon Sep 17 00:00:00 2001 From: chenyu Date: Mon, 9 Dec 2024 16:15:09 -0500 Subject: [PATCH] failed test case for int pow (#8128) also updated test_ops so that non-float compares with `assert_equal`. removed `test_multinomial` which is tested better in test_randomness --- test/test_ops.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/test_ops.py b/test/test_ops.py index e7d6055cc1cb..2a4fc69b256f 100644 --- a/test/test_ops.py +++ b/test/test_ops.py @@ -36,7 +36,10 @@ def compare(s, tinygrad_output, torch_output, atol, rtol): try: assert tinygrad_output.shape == torch_output.shape, f"shape mismatch: tinygrad={tinygrad_output.shape} | torch={torch_output.shape}" assert tinygrad_output.dtype == torch_output.dtype, f"dtype mismatch: tinygrad={tinygrad_output.dtype} | torch={torch_output.dtype}" - np.testing.assert_allclose(tinygrad_output, torch_output, atol=atol, rtol=rtol) + if np.issubdtype(tinygrad_output.dtype, np.floating): + np.testing.assert_allclose(tinygrad_output, torch_output, atol=atol, rtol=rtol) + else: + np.testing.assert_equal(tinygrad_output, torch_output) except Exception as e: raise Exception(f"{s} failed shape {tinygrad_output.shape}: {e}") @@ -573,6 +576,12 @@ def _test(base, exponent): helper_test_op(None, lambda x,y: x**y, vals=[base, ex # NOTE: torch 0 ** -1 is 0 _test([0, 0, 0], [0, 1, 2]) + np.testing.assert_equal((Tensor(11) ** Tensor(7)).item(), 11 ** 7) + np.testing.assert_equal((Tensor([11]) ** Tensor(7)).item(), 11 ** 7) + # TODO: fix non-precise int pow + with self.assertRaises(AssertionError): np.testing.assert_equal((Tensor(11) ** Tensor([7])).item(), 11 ** 7) + with self.assertRaises(AssertionError): np.testing.assert_equal((Tensor([11]) ** Tensor([7])).item(), 11 ** 7) + def test_sqrt(self): helper_test_op([(45,65)], lambda x: x.sqrt()) helper_test_op([()], lambda x: x.sqrt()) @@ -796,11 +805,6 @@ def test_mish(self): helper_test_op([(45,65)], torch.nn.functional.mish, Tensor.mish) helper_test_op([()], torch.nn.functional.mish, Tensor.mish) - def test_multinomial(self): - # NOTE: this is random, so it has a very large atol - helper_test_op([(1000,)], lambda x: torch.multinomial(x.clip(0,1), num_samples=1).type(torch.int32), - lambda x: Tensor.multinomial(x.clip(0,1)), forward_only=True, atol=1000.) - def test_small_cumsum(self): helper_test_op([(10)], lambda x: torch.cumsum(x, dim=0), lambda x: Tensor.cumsum(x, axis=0)) def test_simple_cumsum(self):