family youtu
Llama's dense block with DeepSeek-V2's latent attention: queries and keys wider than values, and every head's key and value expanded from one latent per token.
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 tencent/Youtu-LLM-2B-Base: the native modules, standard names and every standard value with its layout.
YoutuForCausalLM(
(lm_head): Linear(in_features=2048, out_features=128256, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(128256, 2048)
(layers): ModuleList(
(0-31): 32 x YoutuDecoderLayer(
(self_attn): YoutuAttention(
(q_a_proj): Linear(in_features=2048, out_features=1536, bias=False)
(q_a_layernorm): YoutuRMSNorm((1536,), eps=1e-06)
(q_b_proj): Linear(in_features=1536, out_features=3072, bias=False)
(kv_a_proj_with_mqa): Linear(in_features=2048, out_features=576, bias=False)
(kv_a_layernorm): YoutuRMSNorm((512,), eps=1e-06)
(kv_b_proj): Linear(in_features=512, out_features=4096, bias=False)
(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): YoutuMLP(
(gate_proj): Linear(in_features=2048, out_features=6144, bias=False)
(up_proj): Linear(in_features=2048, out_features=6144, bias=False)
(down_proj): Linear(in_features=6144, 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): YoutuRMSNorm((2048,), eps=1e-06)
(post_attention_layernorm): YoutuRMSNorm((2048,), eps=1e-06)
(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): YoutuRMSNorm((2048,), eps=1e-06)
(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 tencent/Youtu-LLM-2B: the native modules, standard names and every standard value with its layout.
YoutuForCausalLM(
(lm_head): Linear(in_features=2048, out_features=128256, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(128256, 2048)
(layers): ModuleList(
(0-31): 32 x YoutuDecoderLayer(
(self_attn): YoutuAttention(
(q_a_proj): Linear(in_features=2048, out_features=1536, bias=False)
(q_a_layernorm): YoutuRMSNorm((1536,), eps=1e-06)
(q_b_proj): Linear(in_features=1536, out_features=3072, bias=False)
(kv_a_proj_with_mqa): Linear(in_features=2048, out_features=576, bias=False)
(kv_a_layernorm): YoutuRMSNorm((512,), eps=1e-06)
(kv_b_proj): Linear(in_features=512, out_features=4096, bias=False)
(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): YoutuMLP(
(gate_proj): Linear(in_features=2048, out_features=6144, bias=False)
(up_proj): Linear(in_features=2048, out_features=6144, bias=False)
(down_proj): Linear(in_features=6144, 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): YoutuRMSNorm((2048,), eps=1e-06)
(post_attention_layernorm): YoutuRMSNorm((2048,), eps=1e-06)
(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): YoutuRMSNorm((2048,), eps=1e-06)
(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)) # multi-head latent attention
out = h + mlp(post_attention_layernorm(h)) # a dense gated MLP on every block
Llama's pre-norm block and Llama's names. The block adds each sublayer's output to the stream and returns a tensor, so 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)
attention_queries and attention_keys are qk_head_dim wide (qk_nope_head_dim +
qk_rope_head_dim, 128 + 64 = 192), attention_values and attention_head_outputs head_dim
(v_head_dim, 128). transformers sets the config's head_dim to qk_rope_head_dim (64), which
no served value has. Queries go through a compressed rank (q_lora_rank 1536: q_a_proj,
q_a_layernorm and q_b_proj, with no q_proj module). The scores are scaled by
qk_head_dim ** -0.5 (self_attn.scaling, 0.0722): the checkpoints have no YaRN scaling.
Keys and values are expanded from one latent per token (kv_lora_rank 512) for every head, so
attention_keys has num_heads (16) heads, and the last 64 dimensions of every head's key are one
shared rotary key. The attention interior needs attn_implementation="eager".
attn = model.layers[1].self_attn
with model.trace(prompt):
q = attn.attention_queries.save() # [1, 16, seq, 192]
k = attn.attention_keys.save() # [1, 16, seq, 192]
v = attn.attention_values.save() # [1, 16, seq, 128]
assert torch.equal(k[:, 0, :, -64:], k[:, 1, :, -64:]) # one rotary key
An edit to one head's last 64 key dimensions reaches that head only: the expansion has already
copied the rotary key into every head when attention_keys is read.
rope_interleave is true: the attention rotates pair (2i, 2i + 1) of the projection into
dimensions i and i + 32 of the rotary part. attention_queries[..., -64:] and
attention_keys[..., -64:] are in that rotate-half order, not the order of q_b_proj's output:
at position 0, where rotary is the identity, the served rotary part is the projection's even
dimensions followed by its odd ones.
with model.trace(prompt):
proj = attn.q_b_proj.output.save()
with model.trace(prompt):
q = attn.attention_queries.save()
rope = proj.view(1, -1, model.num_heads, model.qk_head_dim)[0, 0, 0, -64:]
torch.testing.assert_close(q[0, 0, 0, -64:], torch.cat([rope[0::2], rope[1::2]]))
lm_head.weight is embed_tokens.weight, so a direction read off the unembedding is also the
embedding's: a write to one weight changes both. logits is lm_head.output, with no softcap
or scale, and project_on_vocab applies norm and then the tied head.
Youtu-LLM (YoutuForCausalLM).
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, which returns a bare tensor. Attention is DeepSeek-V2's
multi-head latent attention through the shared eager forward: queries and keys are
qk_head_dim wide (qk_nope_head_dim + qk_rope_head_dim), values
v_head_dim, and the interface sees num_heads key/value heads. The config
maps head_dim to qk_rope_head_dim, the rotary part only, so both widths come
from deepseek_v2's size functions. The MLP is dense on every block.