GraniteMoeForCausalLM
GraniteMoeForCausalLM at 32 layers and hidden size 1536. 5 published checkpoints share this shape.
The pass (full forward)
The order of operations for one forward. ×N marks a position that fires once per layer.
17 steps across nested levels, recorded from one complete forward of this shape in the author's independent implementation — the structure is what that run emitted, not a reading of the configuration.
forward
├─ embed
├─ layer ×N
│ ├─ rmsnorm_attn
│ ├─ wq
│ ├─ wk
│ ├─ wv
│ ├─ rope
│ ├─ attn
│ │ ├─ scores
│ │ └─ attn_mix
│ ├─ wo
│ ├─ rmsnorm_mlp
│ └─ moe
│ ├─ router
│ └─ expert
└─ head
Recorded separately from the structure: layer fired 32 times. A ×N run says only that it repeated — how long a run is is not part of the structure, so two models differing only in depth have the same pass.
The same thing in canonical form:
0(1 2*N(3 4 5 6 7 8(9 10) 11 12 13(14 15)) 16)
Numbers are positions in the pass, not layer indices. Two passes count as the same structure when these strings match.
Implementing it
One forward, written out, per checkpoint whose arithmetic actually differs. A shape groups checkpoints by class, depth, width and layer stack — none of which decides an activation, a rope base or a routing rule — so where the members of this shape disagree there is a block each, and each names the checkpoint it was generated from.
It is not the recorded pass above, which is captured from a real forward; it is what the published configuration says the arithmetic is. Where the configuration does not say, the line says that instead of guessing.
The names are the ones the published checkpoint uses where a name is published, and canonical otherwise. A checkpoint loader may store them differently — fusing a gate/up pair into one matrix, or splitting one published projection in two — and those are that loader's names, not the model's. Everything spelled here is what the download contains.
From granite-3.0-3b-a800m-instruct
Also covers granite-3.0-3b-a800m-base.
x = embed[ids] * 12 # [T, 1536] <- embedding_multiplier
for i in 0 .. 31:
h = rmsnorm(x, layers[i].input_layernorm, eps=1e-06)
q = h @ layers[i].self_attn.q_proj.T # [T, 24*64]
k = h @ layers[i].self_attn.k_proj.T # [T, 8*64]
v = h @ layers[i].self_attn.v_proj.T # [T, 8*64]
q, k = rope(q, k, theta=10000)
k, v = repeat_kv(k, v, 3) # 24 query heads share 8 key/value heads
a = softmax(q @ k.T * 0.015625, mask=causal) @ v # <- attention_multiplier
a = a @ layers[i].self_attn.o_proj.T
x = x + a * 0.22 # <- residual_multiplier
h = rmsnorm(x, layers[i].post_attention_layernorm)
logits_r = h @ block_sparse_moe.router.layer.T # [40], kept f32
sel = argtop8(logits_r) # ties -> lower expert index
w = softmax(logits_r[sel]) # over the selected k, not all
y = 0
for (e, w_e) in sorted(zip(sel, w), by=e): # ascending expert index
g, u = split(h @ block_sparse_moe.input_linear[e].T, 2)
y += w_e * ((silu(g) * u) @ block_sparse_moe.output_linear[e].T)
x = x + y * 0.22
x = rmsnorm(x, model.norm)
logits = (x @ embed.T) / 6 # tied to the input embedding; <- logits_scaling
From granite-3.1-3b-a800m-instruct
Also covers granite-guardian-3.2-3b-a800m, granite-3.1-3b-a800m-base.
x = embed[ids] * 12 # [T, 1536] <- embedding_multiplier
for i in 0 .. 31:
h = rmsnorm(x, layers[i].input_layernorm, eps=1e-06)
q = h @ layers[i].self_attn.q_proj.T # [T, 24*64]
k = h @ layers[i].self_attn.k_proj.T # [T, 8*64]
v = h @ layers[i].self_attn.v_proj.T # [T, 8*64]
q, k = rope(q, k, theta=10000000)
k, v = repeat_kv(k, v, 3) # 24 query heads share 8 key/value heads
a = softmax(q @ k.T * 0.015625, mask=causal) @ v # <- attention_multiplier
a = a @ layers[i].self_attn.o_proj.T
x = x + a * 0.22 # <- residual_multiplier
h = rmsnorm(x, layers[i].post_attention_layernorm)
logits_r = h @ block_sparse_moe.router.layer.T # [40], kept f32
sel = argtop8(logits_r) # ties -> lower expert index
w = softmax(logits_r[sel]) # over the selected k, not all
y = 0
for (e, w_e) in sorted(zip(sel, w), by=e): # ascending expert index
g, u = split(h @ block_sparse_moe.input_linear[e].T, 2)
y += w_e * ((silu(g) * u) @ block_sparse_moe.output_linear[e].T)
x = x + y * 0.22
x = rmsnorm(x, model.norm)
logits = (x @ embed.T) / 6 # tied to the input embedding; <- logits_scaling
Notes that apply to more than one block
Stated once here rather than under each block above.
head_dim is not published; 1536 / 24 = 64 is used.
The Granite multipliers are the part with no Llama analogue: embedding_multiplier, attention_multiplier, residual_multiplier, logits_scaling. They are ordinary floats and a port that ignores them still produces fluent text, which is what makes them worth printing where they act.
Two rules in the routing are load-bearing and neither is in the configuration. The gates are softmax of the top-k logits, not the top-k of a full softmax — the first normalises over the experts that ran, the second over all of them and then discards most of the mass, which scales the block down by whatever the losing experts held. And the selected experts are summed in ascending expert index, because floating-point addition is not associative and the reference accumulates in that order; summing in router-rank order differs by rounding at every layer.
Geometry
| layers | 32 |
| hidden size | 1,536 |
| attention heads | 24, 8 key/value |
| feed-forward width | 512 |
| experts | 40, 8 active per token |
| vocabulary | 49,155 (granite-3.0-3b-a800m-instruct, granite-3.1-3b-a800m-instruct, granite-guardian-3.2-3b-a800m); 49,152 (granite-3.0-3b-a800m-base, granite-3.1-3b-a800m-base) |
| trained context | 4,096 tokens (granite-3.0-3b-a800m-instruct, granite-3.0-3b-a800m-base); 131,072 tokens (granite-3.1-3b-a800m-instruct, granite-guardian-3.2-3b-a800m, granite-3.1-3b-a800m-base) |
| largest checkpoint | 3.4B |
Weight structure
The tensors one element of the repeating stack holds, by the names the published checkpoint uses.
| repeating stack | depth | what one element holds |
|---|---|---|
model.layers.# | 32 | block_sparse_moe.input_linear.weight, block_sparse_moe.output_linear.weight, block_sparse_moe.router.layer.weight, input_layernorm.weight, post_attention_layernorm.weight, self_attn.k_proj.weight, self_attn.o_proj.weight, self_attn.q_proj.weight, self_attn.v_proj.weight |
Other shapes of GraniteMoeForCausalLM
Identical across all of them: KV heads 8, FFN width 512, active 8.
Only the columns that differ are shown; a cell with several values means the checkpoints of that shape disagree.
| shape | layers | width | heads | experts | vocabulary | context | checkpoints |
|---|---|---|---|---|---|---|---|
32L x 1,536 (this sheet) | 32 | 1,536 | 24 | 40 | 49,152 / 49,155 | 4,096 / 131,072 | 5 |
24L x 1,024 | 24 | 1,024 | 16 | 32 | 49,152 / 49,155 | 4,096 / 131,072 | 4 |
How this was checked
implemented, evidence grade shape-parity, per the assessment, for each checkpoint of this shape: a converted checkpoint of this shape was compared against a reference recording; whether it holds this checkpoint's weights is not established. The implementation meant here and below is an unpublished independent inference implementation by the author.
What stands behind the block above, beyond the published configuration it is read from:
- a decoder implemented from the published configuration
- a checkpoint loader, which is where published tensor names are read
- an independent reference implementation of this architecture in Python, driving the published modelling code — an executable statement of what the model should compute, written against the publication rather than against any one implementation of it
Where an independent implementation and the published configuration disagree, the configuration is what this page reports and the disagreement is what it says.
Checkpoints with this architecture
| model | parameters | context | vocabulary |
|---|---|---|---|
granite-3.0-3b-a800m-instruct | 3.4B | 4,096 | 49,155 |
granite-3.0-3b-a800m-base | 3.4B | 4,096 | 49,152 |
granite-3.1-3b-a800m-instruct | 3.3B | 131,072 | 49,155 |
granite-guardian-3.2-3b-a800m | 3.3B | 131,072 | 49,155 |
granite-3.1-3b-a800m-base | 3.3B | 131,072 | 49,152 |