From d0a2d40df30242d2249a236db4aedd239caa6adb Mon Sep 17 00:00:00 2001 From: qazal <77887910+Qazalin@users.noreply.github.com> Date: Sat, 18 May 2024 14:15:25 +0800 Subject: [PATCH] root cause fix for UOps.CONST bad args (#4638) * delete that * real fix --- tinygrad/codegen/linearizer.py | 2 +- tinygrad/codegen/uops.py | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tinygrad/codegen/linearizer.py b/tinygrad/codegen/linearizer.py index 6b3209df16..5d37e68cec 100644 --- a/tinygrad/codegen/linearizer.py +++ b/tinygrad/codegen/linearizer.py @@ -52,7 +52,7 @@ class Linearizer(Kernel): # NOTE: the consts have to be cached for deduping of downstream uops to work def const(self, b:ConstType, dtype:DType=dtypes.int32) -> UOp: if isinstance(b, Variable): return self.uops.add(UOps.DEFINE_VAR, dtype, tuple(), b.unbind()[0]) - else: return self.uops.add(UOps.CONST, dtype, tuple(), b) + else: return self.uops.add(UOps.CONST, dtype, tuple(), dtypes.as_const(b, dtype)) def cast(self, val: UOp, dtype) -> UOp: return self.uops.add(UOps.CAST, dtype, (val,)) if val.dtype != dtype else val diff --git a/tinygrad/codegen/uops.py b/tinygrad/codegen/uops.py index 898c1ed66a..7c681a6e88 100644 --- a/tinygrad/codegen/uops.py +++ b/tinygrad/codegen/uops.py @@ -360,9 +360,6 @@ class UOpGraph: if type_verify: self.type_verify() def add(self, uop:UOps, dtype:Optional[DType]=None, vin:Tuple[UOp, ...]=tuple(), arg:Any=None) -> UOp: - if uop is UOps.CONST: - assert dtype is not None - arg = dtypes.as_const(arg, dtype) # TODO: this doesn't belong here if found:=self.nodes.get(key:=(uop, dtype, vin, arg)): return found self.nodes[key] = ret = UOp(*key) return ret