family starcoder2
Llama's block with LayerNorms, a bias on every projection, a two-matrix GELU MLP (c_fc, c_proj) in place of SwiGLU, and a sliding window of 4096 positions on every block.
One block of the stack. Hover any part for its nnterp name; click to pin the card.
One block of the stack. Hover any part for its nnterp name; click to pin the card.
One block of the stack. Hover any part for its nnterp name; click to pin the card.
identity layers[i].input + self_attn.attention_output + mlp.mlp_output == layer_output
⚠︎ marks a value this checkpoint has only under some load: hover it for the condition.
What print(model) shows on bigcode/starcoder2-3b: the native modules, standard names and every standard value with its layout.
Starcoder2ForCausalLM(
(lm_head): Linear(in_features=3072, out_features=49152, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(49152, 3072)
(layers): ModuleList(
(0-29): 30 x Starcoder2DecoderLayer(
(self_attn): Starcoder2Attention(
(q_proj): Linear(in_features=3072, out_features=3072, bias=True)
(k_proj): Linear(in_features=3072, out_features=256, bias=True)
(v_proj): Linear(in_features=3072, out_features=256, bias=True)
(o_proj): Linear(in_features=3072, out_features=3072, bias=True)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
)
(mlp): Starcoder2MLP(
(c_fc): Linear(in_features=3072, out_features=12288, bias=True)
(down_proj/c_proj): Linear(in_features=12288, out_features=3072, bias=True)
(act_fn/act): GELUTanh()
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(input_layernorm): LayerNorm((3072,), eps=1e-05, elementwise_affine=True, bias=True)
(post_attention_layernorm): LayerNorm((3072,), eps=1e-05, elementwise_affine=True, bias=True)
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(layer_mid) -> Residual [batch seq hidden_size]: The residual stream after the attention add
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((3072,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on bigcode/starcoder2-7b: the native modules, standard names and every standard value with its layout.
Starcoder2ForCausalLM(
(lm_head): Linear(in_features=4608, out_features=49152, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(49152, 4608)
(layers): ModuleList(
(0-31): 32 x Starcoder2DecoderLayer(
(self_attn): Starcoder2Attention(
(q_proj): Linear(in_features=4608, out_features=4608, bias=True)
(k_proj): Linear(in_features=4608, out_features=512, bias=True)
(v_proj): Linear(in_features=4608, out_features=512, bias=True)
(o_proj): Linear(in_features=4608, out_features=4608, bias=True)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
)
(mlp): Starcoder2MLP(
(c_fc): Linear(in_features=4608, out_features=18432, bias=True)
(down_proj/c_proj): Linear(in_features=18432, out_features=4608, bias=True)
(act_fn/act): GELUTanh()
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(input_layernorm): LayerNorm((4608,), eps=1e-05, elementwise_affine=True, bias=True)
(post_attention_layernorm): LayerNorm((4608,), eps=1e-05, elementwise_affine=True, bias=True)
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(layer_mid) -> Residual [batch seq hidden_size]: The residual stream after the attention add
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((4608,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on bigcode/starcoder2-15b: the native modules, standard names and every standard value with its layout.
Starcoder2ForCausalLM(
(lm_head): Linear(in_features=6144, out_features=49152, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(49152, 6144)
(layers): ModuleList(
(0-39): 40 x Starcoder2DecoderLayer(
(self_attn): Starcoder2Attention(
(q_proj): Linear(in_features=6144, out_features=6144, bias=True)
(k_proj): Linear(in_features=6144, out_features=512, bias=True)
(v_proj): Linear(in_features=6144, out_features=512, bias=True)
(o_proj): Linear(in_features=6144, out_features=6144, bias=True)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
)
(mlp): Starcoder2MLP(
(c_fc): Linear(in_features=6144, out_features=24576, bias=True)
(down_proj/c_proj): Linear(in_features=24576, out_features=6144, bias=True)
(act_fn/act): GELUTanh()
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(input_layernorm): LayerNorm((6144,), eps=1e-05, elementwise_affine=True, bias=True)
(post_attention_layernorm): LayerNorm((6144,), eps=1e-05, elementwise_affine=True, bias=True)
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(layer_mid) -> Residual [batch seq hidden_size]: The residual stream after the attention add
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((6144,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on bigcode/starcoder2-15b-instruct-v0.1: the native modules, standard names and every standard value with its layout.
Starcoder2ForCausalLM(
(lm_head): Linear(in_features=6144, out_features=49152, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(49152, 6144)
(layers): ModuleList(
(0-39): 40 x Starcoder2DecoderLayer(
(self_attn): Starcoder2Attention(
(q_proj): Linear(in_features=6144, out_features=6144, bias=True)
(k_proj): Linear(in_features=6144, out_features=512, bias=True)
(v_proj): Linear(in_features=6144, out_features=512, bias=True)
(o_proj): Linear(in_features=6144, out_features=6144, bias=True)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
)
(mlp): Starcoder2MLP(
(c_fc): Linear(in_features=6144, out_features=24576, bias=True)
(down_proj/c_proj): Linear(in_features=24576, out_features=6144, bias=True)
(act_fn/act): GELUTanh()
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(input_layernorm): LayerNorm((6144,), eps=1e-05, elementwise_affine=True, bias=True)
(post_attention_layernorm): LayerNorm((6144,), eps=1e-05, elementwise_affine=True, bias=True)
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(layer_mid) -> Residual [batch seq hidden_size]: The residual stream after the attention add
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((6144,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)h = x + self_attn(input_layernorm(x)) # LayerNorm, biased q, k, v, o
out = h + mlp(post_attention_layernorm(h)) # LayerNorm, c_fc -> GELU -> c_proj
Llama's tree and Llama's names, with LayerNorms (a mean subtracted, a weight and a bias) where Llama
has RMSNorms. Every linear map carries a bias (use_bias): q_proj, k_proj, v_proj, o_proj,
c_fc and c_proj. The MLP has no gate: c_fc widens the normed stream four times, GELU (the tanh
approximation, gelu_pytorch_tanh) acts on it, and c_proj maps it back, so a neuron is one
column of c_fc and one row of c_proj. The attention and the MLP each end in a residual dropout
inside the module, the identity in eval.
attention_output is self_attn.output[0] and mlp_output is mlp.output, added to the stream
with nothing in between. The identity holds exactly, in float32 on the pinned checkpoint and in
bfloat16 on starcoder2-3b (block 5):
with model.trace(prompt):
x = model.layers[1].input.save()
attn = model.layers[1].self_attn.attention_output.save()
mlp = model.layers[1].mlp.mlp_output.save()
out = model.layers[1].layer_output.save()
torch.equal(x + attn + mlp, out) # True
With the biases, a zeroed sublayer input does not give a zero contribution: the attention falls
back to its value and output biases, and the MLP returns c_proj(gelu(c_fc.bias)), which includes
c_proj.bias.
To remove a sublayer's effect, ablate attention_output or mlp_output itself.
config.sliding_window is 4096 on every StarCoder2 checkpoint, against a
max_position_embeddings of 16384, and the config has no layer_types: every block takes the
window. A query attends to its own position and the 4095 before it, so on a prompt shorter than
4096 tokens the mask is the plain causal mask. The window is in the mask the attention receives,
so under attn_implementation="eager" it shows in attention_scores (the largest negative float
outside it) and in attention_probabilities (zero outside it). On the pinned checkpoint loaded
with sliding_window=4, each query has at most 4 nonzero keys, itself and the 3 before:
model = StandardizedTransformer(repo, attn_implementation="eager", sliding_window=4)
with model.trace(prompt):
p = model.layers[1].self_attn.attention_probabilities.save()
(p[0, 0] > 0).sum(-1) # 1, 2, 3, 4, 4, 4, ...
The pinned checkpoint itself has sliding_window null.
Every size has head_dim 128. 3B has 24 query heads over 2 key/value heads, 7B 36 over 4, 15B 48
over 4. On 3B attention_keys and attention_values are [batch, 2, seq, 128] and query head
h reads key/value head h // 12: an edit to key/value head j reaches twelve query heads,
12j to 12j + 11, half of the block's heads. The query scale is head_dim ** -0.5; the rotary
is the plain one over the whole head, with rope_theta near 1000000 on 3B and 7B and 100000 on
15B.
A default load runs sdpa, and the six attention interior values report unavailable;
attn_implementation="eager" serves them. Both paths apply the same window, so they compute the
same function.
model.logits is model.lm_head.output, and project_on_vocab is lm_head(norm(hidden)), the
final LayerNorm's bias included. That bias adds the fixed vector lm_head.weight @ norm.bias to
every lens readout. On 3B the vector is small: its standard deviation is 0.23 logits, against 2.15
for a whole readout at block 14 on a code prompt. On 3B and 7B lm_head is tied to embed_tokens
(tie_word_embeddings defaults to true and the files store no lm_head weight), so an edit to
embed_tokens.weight is an edit to the unembedding; 15B sets it to false.
The tokenizer has 49152 ids and prepends nothing: position 0 is the text's first token. The
vocabulary is built for code, and common English words split: " Paris" is two tokens, " Par" and "is".
<fim_prefix>, <fim_suffix> and <fim_middle> are special tokens for fill-in-the-middle prompts.
StarCoder2 (Starcoder2ForCausalLM).
Llama's tree and Llama's block: model.{embed_tokens, layers[i].{input_layernorm, self_attn, post_attention_layernorm, mlp}, norm} and lm_head, the residual
added in the block, attention through the shared eager forward.
The norms are nn.LayerNorm; the MLP is c_fc/c_proj with no gate; the
attention and MLP outputs pass a residual dropout inside their module, the
identity in eval.