Skip to main content

Module fuse

Module fuse 

Source
Expand description

The shared optimizer: one table of fusion rules over the one IR, decided once for every chip.

Each rule is legal by dataflow alone — a producer’s only reader, nothing between that writes what it reads — and commits only when the chip’s shim runs the result whole. Rules run in a fixed order, each to a fixed point over the slots in turn, and any can be held back. A rule’s result is a fused symbol defined by its parts, a part read in place (a strided access), or a result landing in rows or units of another tensor (a destination): the meaning never changes, and tensor_graph::eval computes the same values from the rewritten graph as from the lifted one.

The rules keep the names and the order of the lane’s table, so a compile answers fired("add_norm") as it always has, and each fused op sits at the slot the lane’s launch sits at, so the launch order does not move.

Structs§

BinaryForm
The elementwise op an op is: its operator, operands, the gate folded in, the row a bias is broadcast over, its length.
ChipRule
A chip’s own rule: its name, the classes it builds, and what it does — reading the chip’s own configuration.
ConvForm
A convolution: its input, weights, ring, output, channels, taps, rows, whether a SiLU and a per-head L2 norm follow inside it.
Decision
One place a rule could fire — the class it builds over the lifted ops it would compute — and what became of it.
Fired
A rule that fired: its name, the class it built, and the lifted ops the result computes.
GemvForm
A matrix product by a constant: its activation, weights and how they are stored, its bias, where it lands, and its shape (k in, n out, m rows).
MoeForm
A mixture of experts, its shared expert folded in or not, and its rows: the lifted mixture, one a rule built, or a block’s mixtures as one.
NormForm
A norm: the input it reads (in place as a part of a wider tensor, or whole), the operand it adds first, the norm it takes of that operand, whether it writes the sum on, its weight, rows and columns, epsilon, and where it lands.
Optimized
A graph after the shared rules, every rule that fired on it, and the report of every decision.
Report
Every decision a compile made, in the order the table made them: the fusions a model received on a chip, and every one it did not with the reason.
Rewriter
The graph being rewritten: its slots, the lifted graph’s tensors, the chip’s shim, what has fired, the rule running and every decision made.
RopeForm
A rotation: its input (whole or as a part of every unit of a wider tensor), the per-head norm folded in, its tables, its position, where it lands, and its heads (per_row a row), head width and rotated half.
Rule
One rule of the table.
SliceForm
A head slice, or a row of a table taken as a copy: y[g·width + i] = x[g·every + from + i] over groups groups.

Enums§

Outcome
What became of a place a rule could fire.
RuleKind
What a rule does.
Weights
A matrix product’s weights: rows of a checkpoint tensor in a block format, or values.

Constants§

ADVANCE
The rule that always closes the table: the arg-max that picks the next token moves the step on.
LATE
The rules that apply once every product’s activation is quantized where it will be read.
RULES
The rule table, in the order the rules apply.

Functions§

activation
The activation a lifted unary op applies.
binary
candidate
A candidate op for the shim to judge: class over parts as they stand — each a lifted op or one a rule built — so the shim reads every member as it is.
class
A fused op’s class, if any.
classes_built
The classes the table builds, by rule.
conv
gates_rows
Whether a gated attention’s parts gate a batch’s rows (attn_output_gate): its attentions’ results set into rows of the table its product gates, not one attention’s result gated whole.
gemv
leaves
The lifted ops a slot computes, as leaves: each member’s in turn, in the order the members run.
moe
norm
The RMS norm an op is: a lifted norm without a bias, or a norm a rule built.
optimize
g with the shared rules but those held applied under shim, every firing, and the report of every decision. A rule held, or one building a class the chip does not link whole, is run on a copy of the graph to report where it would have fired.
read_in_place
Read to with access wherever op — or any part of it — reads from.
realizes
Every class op realizes: its own and each member’s; the placements its reads and its result take — a part read in place (an attention’s values read in its key rows), a result written into rows of a table or into units of a wider tensor — and the composites they make: a rotation landing in a cache’s rows appends to it (rope_kv_append, and qk_norm_rope_kv_append with its per-head norm folded in), a gated delta rule norms its output gated by the SiLU of its gate (gated_norm), a gate and an up product of one activation run as one product (merged_gate_up: two products side by side of one width, or a gated pair), a token-sorted mixture gathers each expert’s rows inside its product (moe_gather_in_operand), and a mixture with its shared expert folded in computes the router and the shared expert’s gate in one op (router_shared_gate_merge).
rope
rule_names
The names of the shared rules a compile can hold back, in the order they apply.
set_dst
Land op’s result where dst says — on the op, and on the part of a fused op that computes its result, so the placement survives the op being fused again.
slice
steps
Every step a compile under shim can hold, in the order it runs them: each shared rule with the chip’s own rules before and after it, the numerics fold (fused_quant, a producer taking the quantize of its result), the late rules with theirs, then the chip’s closing rules. Holding every step from one on leaves the graph as the steps before it make it.
unit_input
The input an op reads unit by unit and its units, (x, units, width), for an op that can read them as a part of every unit of a wider tensor: a norm (not of what it adds), a rotation, a per-head product — none reading in place already.
unit_output
The units an op writes its result in, (units, width), when it can write them as a part of every unit of a wider tensor: a norm, a rotation, a per-head product.
weights
The weights of a product by w, when w is a constant whose storage says how it is read.
written
The elements a row-writing producer writes, and the row width it writes them in: a matrix product, a rotation, a mixture, a norm, a join, a per-head product.