make UOp.dtype recursive_property [PR] (#17827)

This commit is contained in:
chenyu
2026-08-28 19:43:47 -04:00
committed by GitHub
parent 812d5cef62
commit a9830e2b4d
+1 -3
View File
@@ -198,8 +198,6 @@ class UOpMetaClass(type):
# NOTE: the key must separate nodes of different dtype: a CONST's dtype is the type of its arg, and True == 1 as dict keys
if (wret:=UOpMetaClass.ucache.get(key:=(op, src, arg, tag, type(arg)), None)) is not None and (ret:=wret()) is not None: return ret
UOpMetaClass.ucache[key] = weakref.ref(created:=super().__call__(op, src, arg, tag))
# derive at construction: bottom up, so no recursion, and a bad node fails where it is built
created.__dict__["dtype"] = dtype_from_uop(op, src, arg)
if metadata is not None: all_metadata[created] = metadata
# NOTE: this value is set by pickle when pickling a realized tensor
if _buffer is not None:
@@ -243,7 +241,7 @@ class UOp(RandMixin, metaclass=UOpMetaClass):
src:tuple[UOp, ...] = tuple()
arg:Any = None
tag:Any = None
@functools.cached_property
@recursive_property
def dtype(self) -> DType: return dtype_from_uop(self.op, self.src, self.arg)
def __del__(self):
# NOTE: getattr because this object may be partially constructed (e.g. if __init__ raised, like the BEAM timeout SIGALRM)