Skip to main content

Module graph

Module graph 

Source
Expand description

The one IR: a cut of a model’s one program as the tensor ops it runs and the tensors they touch.

A graph is lifted from the front end (walk): every top-level tensor statement is one op, and a statement the front end cannot lift — or a write it cannot account for — is refused by name. Each tensor carries the facts every backend reads instead of re-deriving them:

• its role — a parameter the program reads as a position or row indices (the token, a chunk’s tokens, the position), state an op writes in place (a KV cache by Set row, a convolution ring, a delta-rule memory), a constant any other declared tensor (weights, norm vectors, rotary tables), an activation what an op computes; • its element type, Real or Int, as the program declares or the op that computes it makes it; • its fill, the values the program gives a declared tensor, and its storage, where a constant’s values live (computed, values, or rows of a checkpoint tensor in a block format) — storage comes from the caller, since the IR reads no checkpoint; • whether a statement other than an op observes it (a Show, a scalar read, foreign code).

An op is a symbol over operands: a primitive the front end lifted (Sym::Prim), a fused symbol whose definition is its parts (Sym::Fused), or a view into another tensor. Each operand is read whole or as a part of every unit of a wider tensor (Access), and each result lands in its own buffer or in rows or units of another (Dst). covers names the lifted ops an op computes, so every op of the program is accounted for exactly once however the graph is rewritten.

Structs§

Dst
Where an op writes its result: a buffer of its own, or the rows of a table of rows pitch wide from a starting row — the whole of it, or (unit) a part of every unit of it, each unit’s share of the result width values.
Fused
A fused symbol: its class and its definition, the ops it computes, in order.
Lifted
A source walked by the front end, and the graph of every statement the walk lifts.
Op
One op of the graph: its symbol, its operands and how it reads each, its result and where that lands, the further results it writes whole, and the lifted ops it computes.
Part
A part of every unit of a wider tensor: unit u’s values start u·pitch + offset in.
SeqIo
A batch’s sequence past its first: the position it reads, the logits it computes and the next token it picks.
StepIo
The names a step reads and writes across steps: its token(s), its position, its logits and its next token — its first sequence’s, and a batch’s every other sequence’s in more, sequence b’s next token written to item b of the token tensor.
Strided
A part of every unit of a wider tensor read in place: unit u’s width values from u·pitch + offset, for every whole unit of the tensor.
Tensor
One tensor of the graph: its shape as the program gives it (rows × cols), and its facts.
TensorGraph
A cut of a model’s one program as a graph.
Touches
The ops that touch each tensor of a graph (TensorGraph::touches).

Enums§

Access
How an op reads an operand: the whole of it, or a part of every unit of it.
Elem
A tensor’s element type.
GraphError
Why a program is not a graph, by name.
QuantFormat
How an activation is quantized for the products that read it: int8 words a 32-value block shares one scale of — one word a value, or a high and a low word.
Role
How a step treats a tensor.
RowSel
Which row of a table a write starts at: the row a parameter names (1-based), or a fixed row.
Storage
Where a tensor’s values live.
Sym
What an op computes.

Functions§

out_len
The element count of an op’s result.