Safe By Design AI

GraniteMoeHybridForCausalLM

GraniteMoeHybridForCausalLM at 40 layers and hidden size 2560. 3 published checkpoints share this shape.

Layer map

One character per layer, input on the left, read from the published configuration.

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
layer kindcount
Aattention40

Implementing it

How to read this sheet: method.

Generated from granite-4.0-micro, which covers all 3 checkpoints of this shape — they agree on every field below.

# The config also carries `mamba_*` keys (d_state 256, 128 heads,
#   1 group, conv width 4, chunk 256). `layer_types` lists
#   every layer as attention and transformers picks each layer's
#   mixer from that list alone, so the keys build nothing here.

x = embed[ids] * 12                    # [T, 2560]   <- 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, 40*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, 5)            # 40 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, u = split(h @ layers[i].shared_mlp.input_linear.T, 2)   # [T, 8192] each
    y = (silu(g) * u) @ layers[i].shared_mlp.output_linear.T
    x = x + y * 0.22

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

head_dim is not published; 2560 / 40 = 64 is used.

Layer kinds. transformers builds each layer's mixer from layer_types alone (L1125–L1128), so with every entry attention the mamba_* keys build nothing. Without layer_types it would make every layer state-space (configuration_granitemoehybrid.py L252–L253).

Multiplier placement: embedding, attention scale, residual, logits.

num_local_experts: 0: transformers builds no block_sparse_moe for such a layer (L1116–L1117) and the feed-forward is shared_mlp alone (L1202–L1207).

Geometry

layers40
hidden size2,560
attention heads40, 8 key/value
feed-forward width8,192
vocabulary100,352
trained context131,072 tokens
largest checkpoint3.4B

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, post_attention_layernorm.weight, self_attn.k_proj.weight, self_attn.o_proj.weight, self_attn.q_proj.weight, self_attn.v_proj.weight, shared_mlp.input_linear.weight, shared_mlp.output_linear.weight

Other shapes of GraniteMoeHybridForCausalLM

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

shapelayerswidthstackheadsKV headsFFN widthexpertsactivevocabularycontextcheckpoints
40L x 4,096404,09636 state space + 4 attention3287687210100,352131,0722
40L x 2,560 (this sheet)402,560attention4088,192——100,352131,0723
40L x 2,048402,048attention1644,096——100,352131,0722
40L x 2,048402,04836 state space + 4 attention3288,192——100,352131,0722
40L x 1,536401,53636 state space + 4 attention124512 / 4,096— / 62 / 64— / 649,160 / 50,304 / 100,352131,0726
32L x 7683276828 state space + 4 attention1242,048——100,35232,7682
28L x 1,024281,024attention1642,048——100,35232,7682

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

modelparameterscontext
granite-4.0-micro3.4B131,072
granite-4.0-micro-base3.4B131,072
granite-guardian-4.0-3b-toxicity-ja3.4B131,072

Recorded pass: passes.