family stablelm
Llama's block with LayerNorms and rotary on the first quarter of each head; StableLM-2-12B makes it parallel (use_parallel_residual) and norms each query and key head (qk_layernorm).
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.
⚠︎ marks a value this checkpoint has only under some load: hover it for the condition.
What print(model) shows on stabilityai/stablelm-2-1_6b: the native modules, standard names and every standard value with its layout.
StableLmForCausalLM(
(lm_head): Linear(in_features=2048, out_features=100352, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(100352, 2048)
(layers): ModuleList(
(0-23): 24 x StableLmDecoderLayer(
(self_attn): StableLmAttention(
(q_proj): Linear(in_features=2048, out_features=2048, bias=True)
(k_proj): Linear(in_features=2048, out_features=2048, bias=True)
(v_proj): Linear(in_features=2048, out_features=2048, bias=True)
(o_proj): Linear(in_features=2048, out_features=2048, bias=False)
(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): StableLmMLP(
(gate_proj): Linear(in_features=2048, out_features=5632, bias=False)
(up_proj): Linear(in_features=2048, out_features=5632, bias=False)
(down_proj): Linear(in_features=5632, out_features=2048, bias=False)
(act_fn): SiLUActivation()
(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((2048,), eps=1e-05, elementwise_affine=True, bias=True)
(post_attention_layernorm): LayerNorm((2048,), eps=1e-05, elementwise_affine=True, bias=True)
(dropout): Dropout(p=0.0, inplace=False)
(layer_mid): The residual stream after the attention add
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP
(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
(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((2048,), 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 stabilityai/stablelm-2-zephyr-1_6b: the native modules, standard names and every standard value with its layout.
StableLmForCausalLM(
(lm_head): Linear(in_features=2048, out_features=100352, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(100352, 2048)
(layers): ModuleList(
(0-23): 24 x StableLmDecoderLayer(
(self_attn): StableLmAttention(
(q_proj): Linear(in_features=2048, out_features=2048, bias=True)
(k_proj): Linear(in_features=2048, out_features=2048, bias=True)
(v_proj): Linear(in_features=2048, out_features=2048, bias=True)
(o_proj): Linear(in_features=2048, out_features=2048, bias=False)
(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): StableLmMLP(
(gate_proj): Linear(in_features=2048, out_features=5632, bias=False)
(up_proj): Linear(in_features=2048, out_features=5632, bias=False)
(down_proj): Linear(in_features=5632, out_features=2048, bias=False)
(act_fn): SiLUActivation()
(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((2048,), eps=1e-05, elementwise_affine=True, bias=True)
(post_attention_layernorm): LayerNorm((2048,), eps=1e-05, elementwise_affine=True, bias=True)
(dropout): Dropout(p=0.0, inplace=False)
(layer_mid): The residual stream after the attention add
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP
(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
(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((2048,), 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 stabilityai/stablelm-2-12b: the native modules, standard names and every standard value with its layout.
StableLmForCausalLM(
(lm_head): Linear(in_features=5120, out_features=100352, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(100352, 5120)
(layers): ModuleList(
(0-39): 40 x StableLmDecoderLayer(
(self_attn): StableLmAttention(
(q_proj): Linear(in_features=5120, out_features=5120, bias=False)
(k_proj): Linear(in_features=5120, out_features=1280, bias=False)
(v_proj): Linear(in_features=5120, out_features=1280, bias=False)
(o_proj): Linear(in_features=5120, out_features=5120, bias=False)
(q_layernorm): StableLmLayerNormPerHead(
(norms): ModuleList(
(0-31): 32 x LayerNorm((160,), eps=1e-05, elementwise_affine=True, bias=False)
)
)
(k_layernorm): StableLmLayerNormPerHead(
(norms): ModuleList(
(0-7): 8 x LayerNorm((160,), eps=1e-05, elementwise_affine=True, bias=False)
)
)
(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): StableLmMLP(
(gate_proj): Linear(in_features=5120, out_features=13824, bias=False)
(up_proj): Linear(in_features=5120, out_features=13824, bias=False)
(down_proj): Linear(in_features=13824, out_features=5120, bias=False)
(act_fn): SiLUActivation()
(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((5120,), eps=1e-05, elementwise_affine=True, bias=True)
(dropout): Dropout(p=0.0, inplace=False)
(layer_mid): The residual stream after the attention add
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP
(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
(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((5120,), 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 stabilityai/stablelm-3b-4e1t: the native modules, standard names and every standard value with its layout.
StableLmForCausalLM(
(lm_head): Linear(in_features=2560, out_features=50304, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(50304, 2560)
(layers): ModuleList(
(0-31): 32 x StableLmDecoderLayer(
(self_attn): StableLmAttention(
(q_proj): Linear(in_features=2560, out_features=2560, bias=False)
(k_proj): Linear(in_features=2560, out_features=2560, bias=False)
(v_proj): Linear(in_features=2560, out_features=2560, bias=False)
(o_proj): Linear(in_features=2560, out_features=2560, bias=False)
(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): StableLmMLP(
(gate_proj): Linear(in_features=2560, out_features=6912, bias=False)
(up_proj): Linear(in_features=2560, out_features=6912, bias=False)
(down_proj): Linear(in_features=6912, out_features=2560, bias=False)
(act_fn): SiLUActivation()
(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((2560,), eps=1e-05, elementwise_affine=True, bias=True)
(post_attention_layernorm): LayerNorm((2560,), eps=1e-05, elementwise_affine=True, bias=True)
(dropout): Dropout(p=0.0, inplace=False)
(layer_mid): The residual stream after the attention add
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP
(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
(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((2560,), 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 stabilityai/stablelm-zephyr-3b: the native modules, standard names and every standard value with its layout.
StableLmForCausalLM(
(lm_head): Linear(in_features=2560, out_features=50304, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(50304, 2560)
(layers): ModuleList(
(0-31): 32 x StableLmDecoderLayer(
(self_attn): StableLmAttention(
(q_proj): Linear(in_features=2560, out_features=2560, bias=False)
(k_proj): Linear(in_features=2560, out_features=2560, bias=False)
(v_proj): Linear(in_features=2560, out_features=2560, bias=False)
(o_proj): Linear(in_features=2560, out_features=2560, bias=False)
(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): StableLmMLP(
(gate_proj): Linear(in_features=2560, out_features=6912, bias=False)
(up_proj): Linear(in_features=2560, out_features=6912, bias=False)
(down_proj): Linear(in_features=6912, out_features=2560, bias=False)
(act_fn): SiLUActivation()
(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((2560,), eps=1e-05, elementwise_affine=True, bias=True)
(post_attention_layernorm): LayerNorm((2560,), eps=1e-05, elementwise_affine=True, bias=True)
(dropout): Dropout(p=0.0, inplace=False)
(layer_mid): The residual stream after the attention add
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP
(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
(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((2560,), 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
)# StableLM-2-1.6B, StableLM-3B-4E1T (use_parallel_residual false)
h = x + self_attn(input_layernorm(x))
out = h + mlp(post_attention_layernorm(h))
# StableLM-2-12B (use_parallel_residual true)
n = input_layernorm(x)
out = x + self_attn(n) + mlp(n)
The configs differ: only stablelm-2-12b sets use_parallel_residual: true, and the others leave
it out and take the default, false. On the parallel block post_attention_layernorm does not
exist, both sublayers read the one input_layernorm output, and an edit to attention_output
leaves that block's mlp.input bit-identical. The diagram draws each checkpoint's own block: the
parallel one on 12B, the sequential one on 1.6B and 3B. Read model.config.use_parallel_residual
before reusing a recipe across sizes. The pinned checkpoint has 12B's shape.
attention_output is self_attn.output[0] and mlp_output is mlp.output; the block's dropout
after the MLP is the identity in eval. The identity holds exactly in float32 on both shapes: on the
pinned parallel checkpoint and on StableLM-2-1.6B (block 5). On the sequential block the stream
between the adds, post_attention_layernorm.input, equals layers[i].input + attention_output.
with model.trace(prompt):
x = model.layers[5].input.save()
attn = model.layers[5].self_attn.attention_output.save()
mlp = model.layers[5].mlp.mlp_output.save()
out = model.layers[5].layer_output.save()
torch.equal(x + attn + mlp, out) # True
Every config sets partial_rotary_factor: 0.25. On 1.6B, head_dim is 64, so the first 16
dimensions of each query and key head are rotated, as two halves of 8 (rotate_half), and the
other 48 are the projection's output unchanged; only those 16 make a score depend on the distance
between two tokens. On StableLM-2-1.6B the queries past dimension 16 equal q_proj's output split
into heads, and the first 16 do not:
attn = model.layers[5].self_attn
with model.trace(prompt):
q_raw = attn.source.self_q_proj_0.output.save()
q = attn.attention_queries.save()
b, s, _ = q_raw.shape
q_pre = q_raw.view(b, s, -1, model.head_dim).transpose(1, 2)
rot = int(model.head_dim * model.config.rope_parameters["partial_rotary_factor"]) # 16
torch.equal(q_pre[..., rot:], q[..., rot:]) # True
The query scale is head_dim ** -0.5, and rope_theta is 10000.
stablelm-2-12b sets qk_layernorm: true: the attention has q_layernorm and k_layernorm, each
a list of LayerNorms without bias, one per query head (32) and one per key/value head (8), applied
to the split heads before the rotary. attention_queries and attention_keys are read after both,
so past the rotary dimensions they equal q_layernorm.output and k_layernorm.output, not the
projections (checked on the pinned checkpoint, which has them). The other checkpoints have no such
modules.
use_qkv_bias is true on stablelm-2-1_6b and its zephyr, false on 12B and the 3B models.
Where set, q_proj, k_proj and v_proj add a bias before the rotary; o_proj and the MLP have
none. On 1.6B the biases are large: the key bias has a larger norm than the input-dependent part
W_k·x (median over the tokens of a prompt) on most blocks, 14.5 times on block 0, and the query
bias is the larger on blocks 0 to 4. So a zeroed attention input does not silence the attention;
ablate attention_output itself.
1.6B and the 3B models have 32 query heads and 32 key/value heads, one per query head. 12B has 32 query heads
over 8 key/value heads, so an edit to key/value head j reaches query heads 4j to 4j + 3.
A default load runs sdpa, and the six attention interior values report unavailable;
attn_implementation="eager" serves them. There is no window, softcap or sink, so the two compute
the same function. The 1.6B files are float16; pass dtype=torch.float32 for exact comparisons.
model.logits is model.lm_head.output, and lm_head has its own weight on every checkpoint.
The final norm is a LayerNorm with a bias, so a logit lens adds lm_head.weight @ norm.bias at
every block; on 1.6B its standard deviation is 0.31 logits and its top tokens are the, and,
a, to, that. StableLM 2 uses a 100289-token tokenizer (vocab_size 100352), StableLM-3B
GPT-NeoX's (50277 tokens, vocab_size 50304); neither prepends a BOS, so position 0 is the text's
first token.
StableLM / StableLM-2 (StableLmForCausalLM).
Llama's containers. With use_parallel_residual the block is parallel with one
input_layernorm and a dropout; without it there is a
post_attention_layernorm too. Under qk_layernorm the attention norms its
queries and keys per head (q_layernorm / k_layernorm). Of the released
checkpoints only StableLM-2-12B sets both (as does the pinned tiny); StableLM-2-1.6B
and StableLM-3B-4E1T are sequential with no q/k norms.