LlamaForCausalLM
LlamaForCausalLM at 32 layers and hidden size 2560. 4 published checkpoints share this shape.
Implementing it
How to read this sheet: method.
From granite-3b-code-base-128k
Also covers granite-3b-code-instruct-128k.
x = embed[ids] # [T, 2560]
for i in 0 .. 31:
h = rmsnorm(x, layers[i].input_layernorm, eps=1e-05)
q = h @ layers[i].self_attn.q_proj.T + bias # [T, 32*80]
k = h @ layers[i].self_attn.k_proj.T + bias # [T, 32*80]
v = h @ layers[i].self_attn.v_proj.T + bias # [T, 32*80]
# `attention_bias: true` puts a bias on all four attention
# projections, o_proj included (see Notes).
q, k = rope(q, k, theta=10000000)
a = softmax(q @ k.T / sqrt(80), mask=causal) @ v
a = a @ layers[i].self_attn.o_proj.T + bias
x = x + a
h = rmsnorm(x, layers[i].post_attention_layernorm)
g = silu(h @ layers[i].mlp.gate_proj.T + ...bias) # [T, 10240]
u = h @ layers[i].mlp.up_proj.T + ...bias
y = (g * u) @ layers[i].mlp.down_proj.T + ...bias
# `mlp_bias: true` — three more bias tensors, one per projection.
x = x + y
x = rmsnorm(x, model.norm)
logits = x @ embed.T # tied to the input embedding
Differs from the block above
The same arithmetic with this value changed. Everything not listed is as above.
| checkpoint | rope theta | context |
|---|---|---|
granite-3b-code-base-2k, granite-3b-code-instruct-2k | 10,000 | 2,048 |
Notes
head_dim is not published; 2560 / 32 = 80 is used.
In transformers' LlamaAttention at v4.57.1, attention_bias sets the bias on q, k, v and o_proj (L210-L221), and mlp_bias on all three MLP projections (L149-L151); the checkpoint ships all seven bias tensors. Qwen2 has no such flag: it hard-codes a bias on q, k and v and none on o_proj (modeling_qwen2.py L134-L137), so a port that borrows Qwen2's attention drops o_proj.bias.
Geometry
| layers | 32 |
| hidden size | 2,560 |
| attention heads | 32 |
| feed-forward width | 10,240 |
| vocabulary | 49,152 |
| trained context | 128,000 tokens (granite-3b-code-base-128k, granite-3b-code-instruct-128k); 2,048 tokens (granite-3b-code-base-2k, granite-3b-code-instruct-2k) |
| largest checkpoint | 3.5B |
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 | input_layernorm.weight, mlp.down_proj.bias, mlp.down_proj.weight, mlp.gate_proj.bias, mlp.gate_proj.weight, mlp.up_proj.bias, mlp.up_proj.weight, post_attention_layernorm.weight, self_attn.k_proj.bias, self_attn.k_proj.weight, self_attn.o_proj.bias, self_attn.o_proj.weight, self_attn.q_proj.bias, self_attn.q_proj.weight, self_attn.v_proj.bias, self_attn.v_proj.weight |
Other shapes of LlamaForCausalLM
Identical across all of them: heads 32.
Only the columns that differ are shown; a cell with several values means the checkpoints of that shape disagree.
| shape | layers | width | KV heads | FFN width | vocabulary | context | checkpoints |
|---|---|---|---|---|---|---|---|
36L x 4,096 | 36 | 4,096 | 8 | 14,336 | 49,152 | 4,096 / 128,000 | 4 |
32L x 4,096 | 32 | 4,096 | 32 | 10,928 / 11,008 | 32,000 / 32,008 / 49,152 | 4,096 / 8,192 | 11 |
32L x 2,560 (this sheet) | 32 | 2,560 | 32 | 10,240 | 49,152 | 2,048 / 128,000 | 4 |
How this was checked
Status and evidence grade in the assessment (see what the grades mean):
- each of the 4 checkpoints of this shape: runs,
class— the architecture class is implemented; nothing checkpoint-specific was measured
Parts of the author's unpublished implementation that exist for this shape:
- 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
Checkpoints with this architecture
| model | parameters | context |
|---|---|---|
granite-3b-code-base-128k | 3.5B | 128,000 |
granite-3b-code-base-2k | 3.5B | 2,048 |
granite-3b-code-instruct-128k | 3.5B | 128,000 |
granite-3b-code-instruct-2k | 3.5B | 2,048 |
Recorded pass: passes.