tests from remove uop mutability [pr] (#8442)

* tests from remove uop mutability [pr]

* more test fix

* simpler test fix

* remove that
This commit is contained in:
George Hotz
2024-12-29 12:14:10 -05:00
committed by GitHub
parent b7511cc390
commit b71c51191b
6 changed files with 48 additions and 15 deletions

View File

@@ -1,10 +1,45 @@
import unittest
from tinygrad import Tensor
from tinygrad.ops import UPat, Ops
from tinygrad.ops import UPat, Ops, UOp
realized_pattern = UPat(Ops.VIEW, src=(UPat(Ops.BUFFER),))
const_pattern = UPat(Ops.CONST, src=(UPat(Ops.VIEW, src=(UPat(Ops.DEVICE),),)))
def is_pattern(ten:Tensor, pat:UPat): assert pat.match(ten.lazydata, {})
def is_pattern_uop(u:UOp, pat:UPat): assert pat.match(u, {}), f"{u}\nis not\n{pat}"
def is_pattern(ten:Tensor, pat:UPat): is_pattern_uop(ten.lazydata, pat)
class TestTensorMutates(unittest.TestCase):
# this fails because uops are mutating
@unittest.expectedFailure
def test_mutate_add(self):
a = Tensor([1,2,3])
b = Tensor([4,5,6])
ret = a+b
pa = a.lazydata
pb = b.lazydata
pr = ret.lazydata
ret.schedule()
self.assertIsNot(pa, a.lazydata)
self.assertIsNot(pb, b.lazydata)
self.assertIsNot(pr, ret.lazydata)
for t in [a,b,ret]: is_pattern(t, realized_pattern)
def test_reshape_is_same_parent(self):
a = Tensor([1,2,3])
b = Tensor([4,5,6])
c = a+b
d = (a+b).reshape(3,1)
d.realize()
is_pattern_uop(d.lazydata.base, realized_pattern)
is_pattern_uop(c.lazydata.base, realized_pattern)
def test_reshape_is_same_child(self):
a = Tensor([1,2,3])
b = Tensor([4,5,6])
c = a+b
d = (a+b).reshape(3,1)
c.realize()
is_pattern_uop(c.lazydata.base, realized_pattern)
is_pattern_uop(d.lazydata.base, realized_pattern)
class TestTensorUopRepresentation(unittest.TestCase):
def test_realized(self):