IR Pretty Printing #
Pretty-printing utilities for NN.IR.Graph.
We use these functions when:
- a compiler pass produces a malformed graph and we want a clear, compact dump,
- a verifier rejects a graph and we want to see the exact node/parent structure,
- we want a quick visualization of a graph in GraphViz.
This module is intentionally not a stable serialization format. The IR itself evolves (new ops, new payload conventions, new invariants), and we want the freedom to change the pretty output without treating it as part of the public API.
PyTorch analogy:
prettyis like printing an FX graph as a node list,toDotis like emitting a visualization of the dataflow graph.
References:
- GraphViz DOT language: https://graphviz.org/doc/info/lang.html
- PyTorch FX (for the mental model of an op-tagged graph): https://pytorch.org/docs/stable/fx.html
Render a parent id list in a compact form.
parents in TorchLean's IR are data dependencies: an edge p -> n means "node n consumes
the value produced by node p."
We keep this concise because it shows up in logs; for more context you typically want the whole
graph listing (or the .dot output).
One-line rendering of a node (useful for logs).
Instances For
Plain text rendering #
Render the graph as a simple line-per-node listing.
This assumes the usual IR invariant that nodes are in id/topological order, but it does not enforce
it; if you need validation, run Graph.checkWellFormed / Graph.checkShapes first.
Instances For
GraphViz .dot rendering #
Emit a GraphViz .dot representation.
Edges point from a node to its consumers (i.e. from parent to child), matching the “dataflow” picture most ML frameworks use.
Usage:
IO.FS.writeFile "g.dot" (Graph.toDot g)dot -Tpng g.dot -o g.png