From 0560fa7b0f04bced77a20cfa6434e71125e1ff84 Mon Sep 17 00:00:00 2001 From: George Hotz <72895+geohot@users.noreply.github.com> Date: Wed, 22 Apr 2026 11:15:02 +0800 Subject: [PATCH] add shape to range/special (#15862) --- tinygrad/uop/ops.py | 8 +++++--- tinygrad/viz/serve.py | 1 - 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/tinygrad/uop/ops.py b/tinygrad/uop/ops.py index ae2125b5a6..9e220b2476 100644 --- a/tinygrad/uop/ops.py +++ b/tinygrad/uop/ops.py @@ -211,8 +211,8 @@ class UOp(OpMixin, metaclass=UOpMetaClass): def _shape(self) -> tuple[sint, ...]|None: match self.op: # late ops don't have shape - case Ops.UNIQUE | Ops.LUNIQUE | Ops.DEVICE | Ops.RANGE | Ops.LOAD | Ops.STORE | Ops.IF | Ops.BARRIER | Ops.CUSTOM | Ops.CUSTOMI | \ - Ops.VECTORIZE | Ops.GEP | Ops.SPECIAL | Ops.UNROLL | Ops.CONTRACT | Ops.SINK | \ + case Ops.UNIQUE | Ops.LUNIQUE | Ops.DEVICE | Ops.LOAD | Ops.STORE | Ops.IF | Ops.BARRIER | Ops.CUSTOM | Ops.CUSTOMI | \ + Ops.VECTORIZE | Ops.GEP | Ops.UNROLL | Ops.CONTRACT | Ops.SINK | \ Ops.LINEAR | Ops.PROGRAM | Ops.SOURCE | Ops.BINARY | Ops.INS | Ops.TUPLE | Ops.CALL | Ops.FUNCTION: return None @@ -241,7 +241,9 @@ class UOp(OpMixin, metaclass=UOpMetaClass): return self.src[0].shape[len(self.src[1:]):] # some ops init the shape - case Ops.CONST | Ops.VCONST | Ops.DEFINE_VAR | Ops.BIND: return () + case Ops.CONST | Ops.DEFINE_VAR | Ops.BIND | Ops.RANGE | Ops.SPECIAL: return () + # TODO: VCONST should have the shape of the arg + case Ops.VCONST: return () case Ops.BUFFER: return (self.arg,) case Ops.BUFFER_VIEW: return (self.arg[0],) case Ops.CUSTOM_FUNCTION: return None diff --git a/tinygrad/viz/serve.py b/tinygrad/viz/serve.py index d2a056cb9b..4978423cfd 100755 --- a/tinygrad/viz/serve.py +++ b/tinygrad/viz/serve.py @@ -113,7 +113,6 @@ def uop_to_json(data:VizData, x:UOp) -> dict[int, dict]: # always exclude DEVICE/CONST/UNIQUE if u.op in {Ops.DEVICE, Ops.CONST, Ops.UNIQUE, Ops.LUNIQUE} and u is not x: excluded.add(u) if u.op is Ops.CONST and len(u.src) and u.src[0].op in {Ops.UNIQUE, Ops.LUNIQUE}: excluded.remove(u) - if u.op is Ops.VCONST and u.dtype.scalar() == dtypes.weakint and u is not x: excluded.add(u) if u.op is Ops.VECTORIZE and len(u.src) == 0: excluded.add(u) # exclude RESHAPE/EXPAND that only serve to broadcast a CONST if u.op in {Ops.RESHAPE, Ops.EXPAND} and len(u.src) >= 1 and u.src[0] in excluded and u is not x: excluded.add(u)