TorchLean API

NN.IR.Pretty

IR Pretty Printing #

Pretty-printing utilities for NN.IR.Graph.

We use these functions when:

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:

References:

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:

      Instances For