Functional¶
Functions for a graph's body, under torch.nn.functional's names.
Each records the operator steps that compute it and returns their handle.
Weights are a checkpoint's (out, in), as torch.nn.Linear stores
them. A handle's own + - * / are steps too, and @ of one row.
ConvState
dataclass
¶
What a short causal conv carries between calls.
read, the K - 1 rows before a call's first, and write, where
the K - 1 ending it go; and the scratch states a call stages them
in, window (2, chunk, channels) and tail (K - 1, channels).
linear
¶
Return x @ weight.T, plus bias on every row if given.
weight is (out, in), as torch.nn.Linear stores it. One row
runs on GEMV, which always rounds once in float32 regardless of
precision; several rows run on flm.ProjectionGEMM at precision,
or on GEMM at Precision.HIGHEST.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in iron/functional.py
rms_norm
¶
x over the RMS of its last axis, times weight if given.
eps None is x's dtype's machine epsilon, as torch's.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in iron/functional.py
layer_norm
¶
Layer-normalize x over its last axis, as torch's layer_norm.
Subtract the mean, divide by the standard deviation (eps under the
root), then multiply by weight and add bias when given.
Raises:
| Type | Description |
|---|---|
ValueError
|
|
Source code in iron/functional.py
silu
¶
gelu
¶
Apply GELU, exact by default as torch's.
Or by its tanh approximation (approximate="tanh",
gelu_pytorch_tanh).
rope
¶
causal_conv1d
¶
Return x (rows, channels) through a depth-wise causal filter of K taps.
Each channel its own column of taps (K, channels): output row
t is sum_k taps[k] * x[t - K + 1 + k]. The K - 1
rows before x's first row are read from state.read, and the
K - 1 rows ending this call (counting those read) are written to
state.write for the next call. When x's rows are bounded per
call (x[:n]), the call is a prompt chunk of at most chunk rows;
otherwise x is one row, a decode step.