test Tensor.clone has a different lazydata [pr] (#8600)

This commit is contained in:
chenyu
2025-01-13 20:13:44 -05:00
committed by GitHub
parent ae2229d727
commit c4e33048c6

View File

@@ -646,11 +646,20 @@ class TestZeroShapeTensor(unittest.TestCase):
def test_clone(self):
a = Tensor.rand(16, 16).realize()
self.assertIsNot(a.lazydata, a.clone().lazydata)
np.testing.assert_allclose(a.numpy(), a.clone().numpy())
a = Tensor.rand(16, 16).mul(5.0).add(5.0)
self.assertIsNot(a.lazydata, a.clone().lazydata)
np.testing.assert_allclose(a.numpy(), a.clone().numpy())
def test_clone_with_shrink(self):
a = Tensor.empty(16, 16)
self.assertIsNot(a.lazydata, a.clone().lazydata)
b = a.shrink(((2, 10), None))
self.assertIsNot(b.lazydata, b.clone().lazydata)
def test_clone_with_grad(self):
a = Tensor.rand(16, 16, requires_grad=True)
a.mul(5.0).add(5.0).mean().backward()