family ernie4_5
Llama's pre-norm block whose rotary turns adjacent pairs of query and key dimensions, (2i, 2i + 1), and whose grouped query heads are together wider than the residual stream.
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 baidu/ERNIE-4.5-0.3B-Base-PT: the native modules, standard names and every standard value with its layout.
Ernie4_5ForCausalLM(
(lm_head): Linear(in_features=1024, out_features=103424, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(103424, 1024, padding_idx=0)
(layers): ModuleList(
(0-17): 18 x Ernie4_5DecoderLayer(
(self_attn): Ernie4_5Attention(
(q_proj): Linear(in_features=1024, out_features=2048, bias=False)
(k_proj): Linear(in_features=1024, out_features=256, bias=False)
(v_proj): Linear(in_features=1024, out_features=256, bias=False)
(o_proj): Linear(in_features=2048, out_features=1024, 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): Ernie4_5MLP(
(gate_proj): Linear(in_features=1024, out_features=3072, bias=False)
(up_proj): Linear(in_features=1024, out_features=3072, bias=False)
(down_proj): Linear(in_features=3072, out_features=1024, 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): Ernie4_5RMSNorm((1024,), eps=1e-05)
(post_attention_layernorm): Ernie4_5RMSNorm((1024,), eps=1e-05)
(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): Ernie4_5RMSNorm((1024,), eps=1e-05)
(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 baidu/ERNIE-4.5-0.3B-PT: the native modules, standard names and every standard value with its layout.
Ernie4_5ForCausalLM(
(lm_head): Linear(in_features=1024, out_features=103424, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(103424, 1024, padding_idx=0)
(layers): ModuleList(
(0-17): 18 x Ernie4_5DecoderLayer(
(self_attn): Ernie4_5Attention(
(q_proj): Linear(in_features=1024, out_features=2048, bias=False)
(k_proj): Linear(in_features=1024, out_features=256, bias=False)
(v_proj): Linear(in_features=1024, out_features=256, bias=False)
(o_proj): Linear(in_features=2048, out_features=1024, 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): Ernie4_5MLP(
(gate_proj): Linear(in_features=1024, out_features=3072, bias=False)
(up_proj): Linear(in_features=1024, out_features=3072, bias=False)
(down_proj): Linear(in_features=3072, out_features=1024, 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): Ernie4_5RMSNorm((1024,), eps=1e-05)
(post_attention_layernorm): Ernie4_5RMSNorm((1024,), eps=1e-05)
(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): Ernie4_5RMSNorm((1024,), eps=1e-05)
(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))
out = h + mlp(post_attention_layernorm(h))
Llama's pre-norm block and Llama's names. Nothing norms a sublayer's output, so
attention_output is o_proj's output and mlp_output the MLP's, and the identity is the
plain sum:
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.testing.assert_close(x + attn + mlp, out)
No projection has a bias (use_bias is false).
0.3B has hidden_size 1024 and 16 query heads of head_dim 128, so q_proj maps 1024 to 2048 and
o_proj 2048 back to 1024. The 16 query heads share 2 key/value heads, 8 to each: an edit to key
head 0 at attention_keys reaches query heads 0 to 7. The attention interior needs
attn_implementation="eager".
The rotary embedding rotates dimensions (2i, 2i + 1) of each query and key head together, at
frequency rope_theta ** (-2i / head_dim) (rope_theta 500000), where Llama's rotates i with
i + 64. The served queries and keys keep the projection's order: at position 0 attention_queries
is q_proj's output split into heads, and at position 1 dimensions 0 and 1 are that pair turned
by one radian:
attn = model.layers[1].self_attn
with model.trace(prompt):
proj = attn.q_proj.output.save()
with model.trace(prompt):
q = attn.attention_queries.save() # [batch, num_heads, seq, head_dim]
p = proj.view(1, -1, model.num_heads, model.head_dim)
torch.testing.assert_close(q[0, :, 0], p[0, 0])
c, s = math.cos(1.0), math.sin(1.0)
a, b = p[0, 1, 0, 0], p[0, 1, 0, 1]
torch.testing.assert_close(q[0, 0, 1, :2], torch.stack([a * c - b * s, b * c + a * s]))
A probe or a patch that splits a head into a rotating half and its partner, as a rotate-half layout would, pairs the wrong dimensions here.
logits is lm_head.output, with no cap or scale, and project_on_vocab on the last block's
layer_output equals logits. On 0.3B lm_head is embed_tokens's matrix
(tie_word_embeddings).
ERNIE 4.5 dense (Ernie4_5ForCausalLM).
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.