Models
The integer format
Weights, the step program, the state layout and their Merkle roots.
A compiled model is a folder of four files. This page gives each file's layout, the encoding of weights and steps, the layout of the state, how every root on the Model account is computed from the files, and the limits a model meets to be registered and to have any of its steps proven in one transaction.
The files
| File | Holds |
|---|---|
program.bin | The header, the step list and the page names. |
weights.bin | The weight chunks with their index. |
vocab.txt | The tokenizer: the uncased WordPiece vocabulary, one piece per line, each piece's token id its line counted from 0. Both models on the network use the same file. The step function never reads it. |
manifest.json | The model's description, its counts, its three roots and the SHA-256 of the other three files. |
The store serves each file by its SHA-256. The manifest's own SHA-256 is the files_hash on the Model account, so the chain vouches for the manifest and the manifest vouches for the rest.
manifest.json
slugstringrequired- The model's slug, the seed of its
Modelaccount. namestringrequired- The display name.
task'judge' | 'market'required- What kind of input the model reads: a claim and its evidence, or one text.
summarystringrequired- One line on what the model answers.
archnumberrequired0for the judge,1for the market model. Both are compiled from the BERT layout. The same byte is inprogram.bin.weightsobjectrequiredsource,licenceandurlof the open weights the model was compiled from.parametersnumberrequired- The parameter count of the source weights.
sizeBytesnumberrequired- The size of
weights.bin. stepCountnumberrequired- Steps in a run.
statePagesnumberrequired- Pages in the state.
chunkCountnumberrequired- Weight chunks.
inputMaxnumberrequired- The most input tokens a request may carry.
outputLennumberrequired- The exact number of output tokens.
labelsstring[] | nullrequired- The label of each output token id, in order.
rootsobjectrequiredprogram,weightsandinit: the three roots as 64 lowercase hex characters.filesobjectrequiredprogram,weightsandtokenizer, each withhash(SHA-256, hex) andbytes.
The file is JSON with two-space indentation and a trailing newline. Its bytes are hashed as written, so reformatting it changes files_hash.
weights.bin
All integers are little-endian.
| Offset | Bytes | Field |
|---|---|---|
| 0 | 8 | The magic LPLCWGT1. |
| 8 | 4 | count, the number of chunks, as a u32. |
| 12 | 4 × (count + 1) | Offsets as u32. Chunk i spans offset i to offset i + 1, counted from the start of the chunk data. The first offset is 0. |
12 + 4 × (count + 1) | the rest | The chunks, back to back. |
A chunk is the unit a step reads and the unit weights_root commits to. There are three layouts:
| Read by | Layout |
|---|---|
embed, add-row | One i32 scale, then one i8 per word. The word's value in Q16 is (i8 * scale) >> 8. |
matvec | For r rows of n columns: r scales as i32, then r biases as i32 in Q16 when the step's BIAS flag is set, then r × n weights as i8, row by row. |
norm-apply | The gain exponent as i32, the bias exponent as i32, n gains as i16, n biases as i16. |
A scale is in units of 2^-24, so a weight's real value is i8 * scale / 2^24. An i16 value with exponent shift is v / 2^shift.
Chunking
A matrix is cut so that no step reads more than a transaction carries. Its input is taken one page at a time, 128 columns per page, and its rows are grouped so that a matvec step reads at most 512 weight bytes: 4 rows of 128 columns. A group never crosses from one output page into the next. The bias travels with the slice that covers the first input page.
Chunks with identical bytes are stored once, so a matrix applied at every token position is one set of chunks. Embedding rows are addressed by position from a base index and are never shared: row t of a table whose vectors span p pages is the p chunks starting at base + t × p. There are two such tables, the word embeddings by token id, and the position and segment embeddings summed into one row per pair.
program.bin
| Offset | Bytes | Field |
|---|---|---|
| 0 | 8 | The magic LPLCPRG1. |
| 8 | 1 | arch. |
| 9 | 2 | input_max as a u16. |
| 11 | 2 | output_len as a u16. |
| 13 | 4 | pages, the number of state pages, as a u32. |
| 17 | 4 | steps, the step count, as a u32. |
| 21 | 32 × steps | The step descriptors, in run order. |
21 + 32 × steps | the rest | One name per page: its length as a u16, then UTF-8 bytes. |
The page names (input, token 0 · hidden · 1, norm stats, answer) are for people. They are not part of any root.
The step descriptor
Each step is 32 bytes. The descriptor is the leaf program_root commits to and the first thing in a prove_step payload.
| Offset | Bytes | Field | Meaning |
|---|---|---|---|
| 0 | 1 | op | The operator code. |
| 1 | 1 | flags | The value 1 is BIAS: the chunk carries one bias per row. The value 2 is OVERWRITE: the step writes its result instead of adding it to the target. A step with both holds 3. |
| 2 | 2 | r | For matvec, the number of rows. |
| 4 | 4 | a | The first page the step reads. |
| 8 | 4 | b | The second page the step reads. |
| 12 | 4 | c | The target page. |
| 16 | 4 | w | The weight chunk, or the base index of a table. |
| 20 | 12 | p | Six u16 parameters, p0 to p5, whose meaning depends on the operator. |
A page or chunk field that is unused holds 0xFFFFFFFF.
What each operator takes from the descriptor:
| Code | Name | Pages | Chunk and parameters |
|---|---|---|---|
| 0 | load | c the input page | None. |
| 1 | embed | a the input page, c the target | w the table base, p0 the token position, p1 the page within the vector, p2 pages per vector, p3 words written. The chunk is w + token × p2 + p1. |
| 2 | add-row | a the input page, c the target | As embed. The chunk is w + (p0 × 2 + segment) × p2 + p1. |
| 3 | matvec | a the input, c the target | w the chunk, r rows, p0 the first target word, p1 the columns read from a, flags. |
| 4 | norm-stats | a and optionally b the pages measured, c the stats page | p0 the slot: the mean goes to word 2 × p0, the inverse deviation to the next. p1 words per page. |
| 5 | norm-apply | a the stats page, c the target | w the chunk, p0 the slot, p1 words. |
| 6 | norm-sum | a the page measured, c the stats page | p0 the token: its four words start at 4 × p0 and hold the sum, 0, and the sum of squares as low and high 32 bits. p1 words. OVERWRITE on the vector's first page. |
| 7 | activation | c the target | p0 the function (0 GELU, otherwise tanh), p1 the first word, p2 the count. |
| 8 | norm-stats | c the stats page | p0 the token, as norm-sum: the mean goes to word 4 × p0, the inverse deviation to the next, which norm-apply reads as slot 2 × p0. p1 the vector's width in words. |
| 9 | residual | a the addend, c the target | p1 the first word, p2 the count. |
| 11 | scores | a a query page, b a key page, c the scores page | p0 the key's token: the score lands in word p0 of each head's row. p2 heads per page (0 for 2), p3 keys per row (0 for 64), p4 the scale in Q16 (0 for 1/8, a shift by 3). |
| 13 | softmax | a the input page, c the scores page | p2 and p3 as scores. The valid length is the input's length, at most p3. |
| 14 | weighted-sum | a the scores page, b a value page, c the target | p0 the value's token, p2 and p3 as scores, flags. |
| 16 | argmax | a the logits, c the target | p1 the number of words compared. |
| 19 | output | a the page holding the answer | None. It answers word 0 of a as one token. |
The judge's attention steps hold 0 in p2, p3 and p4: two heads of 64 dimensions per page, 64 keys, scaled by 1/8. The market model's hold 4, 32 and 11585. load, embed and argmax overwrite the target without reading it. Every other operator reads the target's old contents. Deterministic inference says what each operator computes.
The state
The state is pages pages. A page is 128 words, each an i32 in Q16, stored and hashed as 512 little-endian bytes. Every page is zero before step 0.
A vector wider than 128 words spans consecutive pages: a 256-wide hidden vector is two pages, a 384-wide one three, a 1,536-wide one twelve. Which page holds what is the model's layout, fixed by its compiler and visible in the page names.
The input page is the one load writes:
| Words | Content |
|---|---|
| 0 | The number of input tokens. |
| 1 to 64 | The tokens. A model reads as many positions as its input_max. |
| 126 | The low 32 bits of the seed. |
| 127 | The high 32 bits of the seed. |
The BERT layout
Each token position has its own pages, and a few pages serve the whole run:
| Pages | Per | Holds |
|---|---|---|
hidden | Position, one hidden vector | The running hidden state. |
query, key, value | Position, one hidden vector each | The attention projections. |
scores | Position, one hidden vector | The attention scores, one row of keys per head. |
attention | Position, one hidden vector | The weighted sum of values. |
sublayer out | Position, one hidden vector | The attention output and the feed-forward output before each residual. |
ffn | Position, one intermediate vector | The feed-forward block. |
input | Run | The input page. |
norm stats | Run | The mean and inverse deviation of every position's norm. |
pooled | Run, one hidden vector | The pooler on the first position. |
logits | Run | The three class logits. |
answer | Run | The class argmax chose, in word 0. |
judge | market | |
|---|---|---|
| Positions | 64 | 32 |
| Pages per hidden vector | 2 | 3 |
| Pages per intermediate vector | 8 | 12 |
| Pages per position | 22 | 33 |
| Pages for the run | 6 | 7 |
| State pages | 1,414 | 1,063 |
How each root is computed
Every tree is a binary Merkle tree with SHA-256:
leaf = sha256(0x00 || bytes)
node = sha256(0x01 || left || right)The tree's depth is the smallest d with 2^d at least the number of leaves, and positions past the last leaf hold 32 zero bytes.
| Root | Leaves | Recorded |
|---|---|---|
program_root | One per step: the leaf hash of its 32-byte descriptor. | On the Model account. |
weights_root | One per chunk: the leaf hash of its bytes. | On the Model account. |
init_root | One per page: the leaf hash of 512 zero bytes. | On the Model account. It is the state root before step 0. |
| State root | One per page: the leaf hash of the page's 512 bytes. | Committed by each side in the game. |
| Trace root | The roots of a run in order, used as they are: the init_root, the state root after each step but the last, then the output leaf. step_count + 1 leaves. | On the receipt. |
files_hash | Not a tree: the SHA-256 of manifest.json. | On the Model account. |
The output leaf is sha256("laplace.output" || count as u16 || each output token as u16).
@laplace/sdk/vm computes the three model roots from the two binary files: loadModel(program, weights) returns a model with programRoot, weightsRoot, initRoot and stepCount.
Limits
register_model accepts a model when all of these hold, and fails with InvalidModel (6002) otherwise:
| Field | Requirement |
|---|---|
slug | 1 to 24 bytes, each a lowercase letter, a digit or -. |
step_count, state_pages, chunk_count | Above zero. Each is a u32. |
input_max | 1 to 64. |
output_len | 1 to 64. |
window_secs | Above zero. A u32. |
bond_lamports | Above zero. A u64. |
The 64-token bounds are the size of the input page and of the input and output fields of a receipt.
For any step of the model to be proven in one transaction, the format bounds what a step touches:
| Bound | Value |
|---|---|
| Pages a step opens | At most 3, each 512 bytes. |
| Chunks a step reads | At most 1. Its length is a u16 in the payload. |
| Hashes in one path or multiproof | A u8 count, so at most 255. |
Weight bytes in one matvec step, as the compiler cuts them | 512. |
The whole prove_step transaction | 4096 bytes. The SDK refuses to build a larger one. |
One step on chain gives the largest payload each model on the network produces.