TraceToGraphBuilder

class TraceToGraphBuilder(graph: ComputeGraph, session: TraceSession? = null)(source)

Shared builder to convert OpTrace streams into a ComputeGraph. Used by both GraphSink (online) and DefaultExecutionTape.toComputeGraph() (offline).

Deterministic ID policy (FR7):

  • Node IDs: sequential per builder instance using insertion order, formatted as: "n_" Example: n0_Add, n1_Relu. This ensures stability for a given trace ordering.

  • Edge IDs: derived from endpoints and port indices, formatted as: "e___" Example: e_n0_Add_0__n1_Relu_0. This is deterministic given the node IDs and wiring.

By default this builder does NOT synthesize explicit "input" placeholder nodes for tensors without a known producer. Call finalize after adding all traces to synthesize "input" and "weight" constant nodes for unresolved external inputs. This is required for StableHLO compilation where every operand must be wired through graph edges.

Constructors

Link copied to clipboard
constructor(graph: ComputeGraph, session: TraceSession? = null)

Functions

Link copied to clipboard
fun addAll(traces: Iterable<OpTrace>)
Link copied to clipboard
fun addTrace(trace: OpTrace)

Add a single OpTrace into the graph, wiring known producers to inputs and registering the outputs as new producers.

Link copied to clipboard
fun finalize(inputTensorIds: Set<String> = emptySet())

Synthesize placeholder nodes for tensor inputs that had no known producer.