mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-08-29 11:16:07 +00:00
viz: fix walk rewrite (#16791)
This commit is contained in:
@@ -215,6 +215,13 @@ class TestViz(unittest.TestCase):
|
||||
nop = UOp(Ops.NOOP, arg="infinite loop in fixed_point_rewrite")
|
||||
self.assertEqual(graphs[2], uop_to_json(VizData(), nop)[id(nop)])
|
||||
|
||||
def test_walk_rewrite(self):
|
||||
from tinygrad.uop.ops import _substitute
|
||||
with save_viz() as viz:
|
||||
a = UOp.variable("a", 0, 10)
|
||||
graph_rewrite(a + 4, TrackedPatternMatcher(_substitute.patterns), {a:a+1}, walk=True)
|
||||
list(viz.get_details(0, 0))
|
||||
|
||||
def test_const_node_visibility(self):
|
||||
with save_viz() as viz:
|
||||
a = UOp.variable("a", 0, 10, dtype=dtypes.int)
|
||||
|
||||
+3
-1
@@ -1396,6 +1396,7 @@ class TrackedGraphRewrite:
|
||||
name:str # name of the rewrite
|
||||
depth:int # depth if it's a subrewrite
|
||||
bottom_up:bool
|
||||
walk:bool
|
||||
|
||||
tracked_keys:list[TracingKey] = []
|
||||
tracked_ctxs:list[list[TrackedGraphRewrite]] = []
|
||||
@@ -1452,7 +1453,8 @@ def profile_matches(fxn:Callable):
|
||||
depth = len(active_rewrites)
|
||||
if not tracked_ctxs: add_trace_group(TracingKey(f"default {fxn.__name__}"))
|
||||
dest_group = active_group[-1] if active_group else len(tracked_ctxs)-1
|
||||
tracked_ctxs[dest_group].append(ctx:=TrackedGraphRewrite(loc, args[0].trace_num, [], name, depth, kwargs.get("bottom_up", False)))
|
||||
tracked_ctxs[dest_group].append(ctx:=TrackedGraphRewrite(loc, args[0].trace_num, [], name, depth, kwargs.get("bottom_up", False),
|
||||
kwargs.get("walk", False)))
|
||||
active_rewrites.append(ctx)
|
||||
with cpu_profile(name, "TINY"):
|
||||
ret = fxn(*args, **kwargs)
|
||||
|
||||
@@ -184,7 +184,7 @@ def get_full_rewrite(data:VizData, ctx:TrackedGraphRewrite, depth:int|None=None)
|
||||
replaces: dict[UOp, UOp] = {}
|
||||
for u0_num,u1_num,upat_loc,dur in tqdm(ctx.matches, disable=not ctx.matches):
|
||||
replaces[u0:=_reconstruct(data, u0_num, depth=depth)] = u1 = _reconstruct(data, u1_num, depth=depth)
|
||||
try: new_sink = next_sink.substitute(replaces)
|
||||
try: new_sink = next_sink.substitute(replaces, walk=ctx.walk)
|
||||
except RuntimeError as e: new_sink = UOp(Ops.NOOP, arg=str(e))
|
||||
match_repr = f"# {dur*1e6:.2f} us\n"+printable(upat_loc)
|
||||
yield {"graph":(sink_json:=uop_to_json(data, new_sink)), "uop":pystr(new_sink), "change":[id(x) for x in u1.toposort() if id(x) in sink_json],
|
||||
|
||||
Reference in New Issue
Block a user