Safe By Design AI

GraniteSWAForCausalLM

GraniteSWAForCausalLM at 24 layers and hidden size 2560. One published checkpoint has this shape.

Layer map

One character per layer, input on the left.

AssAsssAsssAsssAsssAsssA
layer kindcount
ssliding attention17
Aattention7

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
│  ├─ w_gate
│  ├─ w_up
│  └─ w_down
└─ head

Recorded separately from the structure: layer fired 24 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.

Generated from granite-swash-2b.

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

for i in 0 .. 23:
    h = rmsnorm(x, layers[i].input_layernorm, eps=1e-05)
    q = h @ layers[i].self_attn.q_proj.T       # [T, 20*128]
    k = h @ layers[i].self_attn.k_proj.T       # [T, 4*128]
    v = h @ layers[i].self_attn.v_proj.T       # [T, 4*128]
    q, k = rope(q, k, theta=10000)
    k, v = repeat_kv(k, v, 5)            # 20 query heads share 4 key/value heads
    # win = 128 on the 17 sliding layers, unbounded on the other 7
    p, lse = softmax_with_lse(q @ k.T * 0.0078125, mask=causal, window=win)
    a = (p @ v) * sigmoid(lse - layers[i].self_attn.sinks[head])
    #  ^ one learned scalar per query head, on every layer — the
    #    config never mentions it. Equivalent to an extra softmax
    #    key with logit `sink` and value zero, so a head with
    #    nothing worth attending to emits near zero instead of
    #    averaging its window.
    a = a @ layers[i].self_attn.o_proj.T
    x = x + a * 0.28        # <- 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.28

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

head_dim is not published; 2560 / 20 = 128 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.

This checkpoint carries a learned attention sink per head that the configuration never mentions. self_attn.sinks is [20] on every layer — including the unwindowed ones — and scales each head's output by sigmoid(lse - sink), where lse is that head's log-sum-exp. Read as one expression it is an extra key appended to the softmax whose logit is the sink and whose value is zero, so a head with nothing worth attending to can output near zero instead of being forced to average its window. Nothing above is derived from it because nothing in config.json says it is there; it is in the weights.

Geometry

layers24
hidden size2,560
attention heads20, 4 key/value
feed-forward width8,192
sliding window128 tokens
vocabulary100,352
trained context8,192 tokens
largest checkpoint2.1B

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.#24input_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.sinks, self_attn.v_proj.weight

How this was checked

implemented, evidence grade checkpoint-parity, per the assessment: this checkpoint's logits were compared against a recording made with the model's own published reference implementation. 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:

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

modelparameterscontext
granite-swash-2b2.1B8,192