Safe By Design AI

XLMRobertaModel

XLMRobertaModel at 12 layers and hidden size 768. One published checkpoint has this shape.

Implementing it

How to read this sheet: method.

Generated from granite-embedding-278m-multilingual.

x = word[ids] + position[pos] + token_type[0]   # [T, 768]
x = layernorm(x, embeddings.LayerNorm, eps=1e-05)
# pos = padding_idx + 1 + i for real tokens (`pad_token_id: 1`), and
#   padding_idx for padding: real tokens start at row 2 (see Notes).

for i in 0 .. 11:
    q = x @ layers[i].attention.self.query.T + layers[i].attention.self.query.bias
    k = x @ layers[i].attention.self.key.T   + layers[i].attention.self.key.bias
    v = x @ layers[i].attention.self.value.T + layers[i].attention.self.value.bias
    a = softmax(q @ k.T / sqrt(64), mask=padding) @ v     # bidirectional
    o = a @ layers[i].attention.output.dense.T + layers[i].attention.output.dense.bias
    x = layernorm(x + o, layers[i].attention.output.LayerNorm, eps=1e-05)   # post-norm
    h = gelu(x @ layers[i].intermediate.dense.T + layers[i].intermediate.dense.bias)   # [T, 3072]
    o = h @ layers[i].output.dense.T + layers[i].output.dense.bias
    x = layernorm(x + o, layers[i].output.LayerNorm, eps=1e-05)

emb = x[0]                                # the CLS row (`1_Pooling`)
emb = emb / norm(emb)                     # `2_Normalize`

Notes

Position ids start at padding_idx + 1 = 2. create_position_ids_from_input_ids numbers real tokens from padding_idx + 1 and gives padding the id padding_idx (modeling_xlm_roberta.py L1537-L1550). With pad_token_id: 1, row 0 of the 514-row position table is never read, row 1 only at padding positions, and a 512-token input reads rows 2 to 513, so the 514-row table (max_position_embeddings) holds 512 usable positions. A port that starts at row 0 looks everything up successfully and shifts every position by 2.

The attention is bidirectional: only padding is masked, so every position reads the whole sequence.

This lineage is post-norm: each sublayer's LayerNorm comes after the residual add, the opposite of every decoder on these pages.

The sentence vector is what the repository's sentence-transformers configuration builds: CLS pooling, then L2 normalisation (modules.json, 1_Pooling/config.json).

Geometry

layers12
hidden size768
attention heads12
feed-forward width3,072
vocabulary250,002
trained context514 tokens
largest checkpoint278M

Weight structure

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

repeating stackdepthwhat one element holds
encoder.layer.#12attention.output.LayerNorm.bias, attention.output.LayerNorm.weight, attention.output.dense.bias, attention.output.dense.weight, attention.self.key.bias, attention.self.key.weight, attention.self.query.bias, attention.self.query.weight, attention.self.value.bias, attention.self.value.weight, intermediate.dense.bias, intermediate.dense.weight, output.LayerNorm.bias, output.LayerNorm.weight, output.dense.bias, output.dense.weight

Other shapes of XLMRobertaModel

Identical across all of them: heads 12, vocabulary 250,002, context 514.

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

shapelayerswidthFFN widthcheckpoints
12L x 768 (this sheet)127683,0721
6L x 38463841,5361

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-embedding-278m-multilingual278M514

Recorded pass: passes.