empty graph rewrite to VIZ tensor graph [pr] (#8658)

* empty graph rewrite to VIZ tensor graph [pr]

* fix lint
This commit is contained in:
George Hotz
2025-01-17 11:29:33 -08:00
committed by GitHub
parent 8609b880bd
commit 0d7bd4f389
2 changed files with 6 additions and 3 deletions

View File

@@ -519,9 +519,12 @@ remove_movement_ops = PatternMatcher([
@track_rewrites(named=True)
def create_schedule_with_vars(outs:list[UOp], skip_check:bool=not __debug__) -> tuple[list[ScheduleItem], dict[Variable, int], dict[UOp, UOp]]:
if not skip_check: type_verify(list(UOp.sink(*outs).toposort), tensor_uop_spec)
big_sink = UOp.sink(*outs)
# if using VIZ, do an empty graph rewrite to vizualize the Tensor graph
if getenv("VIZ"): graph_rewrite(big_sink, PatternMatcher([]))
if not skip_check: type_verify(list(big_sink.toposort), tensor_uop_spec)
# to_uop is removing (many) of the movement ops
sink = add_buffers(UOp.sink(*outs), ctx:=ScheduleContext(), cache={})
sink = add_buffers(big_sink, ctx:=ScheduleContext(), cache={})
# const folding and fusion
sink = graph_rewrite(sink, remove_movement_ops+ops_folding+do_realize, ctx)
sink = graph_rewrite(sink, merge_bufs, ctx)

View File

@@ -73,7 +73,7 @@ def uop_to_json(x:UOp) -> dict[int, tuple[str, str, list[int], str, str]]:
if u.op is Ops.VIEW:
argst = ("\n".join([f"{v.shape} / {v.strides}"+(f"\nMASK {v.mask}" if v.mask is not None else "")+
("" if v.offset == 0 else f" / {v.offset}") for v in unwrap(u.st).views]))
label = f"{str(u.op).split('.')[1]}{(' '+word_wrap(argst.replace(':', ''))) if u.arg is not None else ''}\n{str(u.dtype)}"
label = f"{str(u.op).split('.')[1]}{(chr(10)+word_wrap(argst.replace(':', ''))) if u.arg is not None else ''}\n{str(u.dtype)}"
for idx,x in enumerate(u.src):
if x in excluded:
if x.op is Ops.CONST and dtypes.is_float(u.dtype): label += f"\nCONST{idx} {x.arg:g}"