MCPcopy
hub / github.com/tinygrad/tinygrad / print_step

Function print_step

tinygrad/viz/cli.py:67–82  ·  view source on GitHub ↗
(step:dict, print_graph=False, reconstruct_matches=False)

Source from the content-addressed store, hash-verified

65 def emit(val, to_str=str) -> str: return json.dumps(val if isinstance(val, dict) else {"value":val}) if args.json else to_str(val)
66
67 def print_step(step:dict, print_graph=False, reconstruct_matches=False) -> None:
68 data = viz.get_render(viz_data, step["query"])
69 if isinstance(data.get("value"), Iterator):
70 for m in data["value"]:
71 if print_graph and "graph" in m and not args.json:
72 for k,v in m["graph"].items():
73 print(f"[{k}] {' '.join((lines:=v['label'].splitlines())[:5])}{'...' if len(lines) > 5 else ''}"+(f" tag={v['tag']}" if v['tag'] else ''))
74 if v["src"]:
75 print(" src: "+", ".join([f"{i}->[{x}]" for i,x in v["src"][:5]])+(f", ... and {len(v['src'])-5} more" if len(v["src"]) > 5 else ""))
76 elif "uop" in m: print(emit(m["graph"] if print_graph else m["uop"]))
77 if not reconstruct_matches: return None
78 if m.get("diff"):
79 loc = pathlib.Path(m["upat"][0][0])
80 print(emit(f"{loc.parent.name}/{loc.name}:{m['upat'][0][1]}\n{m['upat'][1]}"))
81 for line in m["diff"]: print(emit(colored(line, "red" if line.startswith("-") else "green" if line.startswith("+") else None)))
82 if data.get("src") is not None: print(emit(data["src"]))
83
84 profile_bytes = viz.get_profile(viz_data, viz.load_pickle(args.profile_path, default=[]))
85 if profile_bytes is None: raise RuntimeError(f"empty profile in {args.profile_path}")

Callers 1

render_eventFunction · 0.85

Calls 3

coloredFunction · 0.90
emitFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…