Safe By Design AI

GraniteForCausalLM

GraniteForCausalLM at 40 layers and hidden size 2048. 9 published checkpoints share this shape.

Implementing it

How to read this sheet: method.

From granite-3.1-2b-instruct

Also covers granite-3.2-2b-instruct, granite-guardian-3.1-2b, granite-3.1-2b-base.

x = embed[ids] * 12                    # [T, 2048]   <- embedding_multiplier

for i in 0 .. 39:
    h = rmsnorm(x, layers[i].input_layernorm, eps=1e-05)
    q = h @ layers[i].self_attn.q_proj.T       # [T, 32*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=5000000)
    k, v = repeat_kv(k, v, 4)            # 32 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)
    g = silu(h @ layers[i].mlp.gate_proj.T)           # [T, 8192]
    u =       h @ layers[i].mlp.up_proj.T
    y = (g * u) @ layers[i].mlp.down_proj.T
    x = x + y * 0.22

x = rmsnorm(x, model.norm)
logits = (x @ embed.T) / 8        # tied to the input embedding; <- logits_scaling

Differs from the block above

Only the rope base differs. Everything else is as above.

checkpointsrope theta
granite-3.0-2b-instruct, granite-guardian-3.0-2b, granite-3.0-2b-base10,000
granite-3.3-2b-instruct, granite-3.3-2b-base10,000,000

Notes

head_dim is not published; 2048 / 32 = 64 is used.

Output head: the configuration says tied, the checkpoint ships a separate one. granite-3.0-2b-instruct sets tie_word_embeddings: true, which is what the block follows, but its checkpoint also ships a separate lm_head.weight [49155, 2048]. A standard transformers load reads that tensor and then, because the configuration asks for tying, replaces it with the input embedding (modeling_utils.py L2994, L5065), so the logits it computes are the ones written here. The published headers carry shapes, not values, so whether the shipped head equals embed is not known; if it does not, a loader that uses the shipped lm_head.weight computes different logits (findings §10).

Multiplier placement follows modeling_granite.py at transformers v4.57.1: embedding, attention scale, residual, logits.

Geometry

layers40
hidden size2,048
attention heads32, 8 key/value
feed-forward width8,192
vocabulary49,155 (5) / 49,159 (1) / 49,152 (3) — by checkpoint in the list below
trained context4,096 tokens (2) / 131,072 tokens (6) / 8,192 tokens (1) — by checkpoint in the list below
largest checkpoint2.6B

Weight structure

The tensors one element of the repeating stack holds, by the names the published checkpoint uses.

repeating stackdepthwhat one element holds
model.layers.#40input_layernorm.weight, mlp.down_proj.weight, mlp.gate_proj.weight, mlp.up_proj.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 GraniteForCausalLM

Identical across all of them: KV heads 8.

Only the columns that differ are shown; a cell with several values means the checkpoints of that shape disagree.

shapelayerswidthheadsFFN widthvocabularycontextcheckpoints
64L x 4,096644,0963232,768100,352131,0723
40L x 4,096404,0963212,80049,152 / 49,155 / 49,159 / 100,3524,096 / 8,192 / 131,07219
40L x 2,560402,560408,192100,352131,0723
40L x 2,048 (this sheet)402,048328,19249,152 / 49,155 / 49,1594,096 / 8,192 / 131,0729
28L x 4,096284,0963212,80049,155131,0722

How this was checked

Status and evidence grade in the assessment (see what the grades mean):

Parts of the author's unpublished implementation that exist for this shape:

Checkpoints with this architecture

modelparameterscontextvocabulary
granite-3.0-2b-instruct2.6B4,09649,155
granite-3.3-2b-instruct2.5B131,07249,159
granite-3.1-2b-instruct2.5B131,07249,155
granite-3.2-2b-instruct2.5B131,07249,155
granite-guardian-3.0-2b2.5B8,19249,155
granite-guardian-3.1-2b2.5B131,07249,155
granite-3.0-2b-base2.5B4,09649,152
granite-3.1-2b-base2.5B131,07249,152
granite-3.3-2b-base2.5B131,07249,152

Recorded pass: passes.