test const pattern [pr] (#8304)

* test const pattern [pr]

* add model to test_tiny
This commit is contained in:
George Hotz
2024-12-17 23:34:17 -08:00
committed by GitHub
parent 45f2fb82d5
commit 32df46cd73
3 changed files with 27 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ from tinygrad import Tensor
from tinygrad.ops import UPat, Ops
realized_pattern = UPat(Ops.VIEW, src=(UPat(Ops.BUFFER),))
const_pattern = UPat(Ops.VIEW, src=(UPat(Ops.BUFFER), UPat(Ops.CONST)))
def is_pattern(ten:Tensor, pat:UPat): assert pat.match(ten.lazydata, {})
class TestTensorUopRepresentation(unittest.TestCase):
@@ -18,6 +19,11 @@ class TestTensorUopRepresentation(unittest.TestCase):
print(c.lazydata)
is_pattern(c, UPat(Ops.ADD, src=(realized_pattern, realized_pattern)))
def test_const_pattern(self):
a = Tensor(1)
print(a.lazydata)
is_pattern(a, const_pattern)
def test_consts_do_not_realize(self):
a = Tensor(1)
print(a.lazydata)