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 + fc2.output == layer_output
What print(model) shows on facebook/xglm-564M: the native modules, standard names and every standard value with its layout.
XGLMForCausalLM(
(lm_head): Linear(in_features=1024, out_features=256008, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): XGLMScaledWordEmbedding(256008, 1024, padding_idx=1)
(layers): ModuleList(
(0-23): 24 x XGLMDecoderLayer(
(self_attn): XGLMAttention(
(k_proj): Linear(in_features=1024, out_features=1024, bias=True)
(v_proj): Linear(in_features=1024, out_features=1024, bias=True)
(q_proj): Linear(in_features=1024, out_features=1024, bias=True)
(o_proj/out_proj): Linear(in_features=1024, out_features=1024, bias=True)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention, already scaled by 1/sqrt(head_dim)
(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_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
(attention_queries_prerope) -> Queries [batch num_heads seq qk_head_dim]: The queries entering the rotary embedding
(attention_keys_prerope) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering the rotary embedding
(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
(interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
)
(activation_fn): GELUActivation()
(input_layernorm/self_attn_layer_norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True, bias=True)
(fc1): Linear(in_features=1024, out_features=4096, bias=True)
(fc2): Linear(in_features=4096, out_features=1024, bias=True)
(final_layer_norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True, bias=True)
(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 feed-forward path
(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((1024,), 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 facebook/xglm-1.7B: the native modules, standard names and every standard value with its layout.
XGLMForCausalLM(
(lm_head): Linear(in_features=2048, out_features=256008, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): XGLMScaledWordEmbedding(256008, 2048, padding_idx=1)
(layers): ModuleList(
(0-23): 24 x XGLMDecoderLayer(
(self_attn): XGLMAttention(
(k_proj): Linear(in_features=2048, out_features=2048, bias=True)
(v_proj): Linear(in_features=2048, out_features=2048, bias=True)
(q_proj): Linear(in_features=2048, out_features=2048, bias=True)
(o_proj/out_proj): Linear(in_features=2048, out_features=2048, bias=True)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention, already scaled by 1/sqrt(head_dim)
(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_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
(attention_queries_prerope) -> Queries [batch num_heads seq qk_head_dim]: The queries entering the rotary embedding
(attention_keys_prerope) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering the rotary embedding
(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
(interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
)
(activation_fn): GELUActivation()
(input_layernorm/self_attn_layer_norm): LayerNorm((2048,), eps=1e-05, elementwise_affine=True, bias=True)
(fc1): Linear(in_features=2048, out_features=8192, bias=True)
(fc2): Linear(in_features=8192, out_features=2048, bias=True)
(final_layer_norm): LayerNorm((2048,), eps=1e-05, elementwise_affine=True, bias=True)
(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 feed-forward path
(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 facebook/xglm-2.9B: the native modules, standard names and every standard value with its layout.
XGLMForCausalLM(
(lm_head): Linear(in_features=2048, out_features=256008, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): XGLMScaledWordEmbedding(256008, 2048, padding_idx=1)
(layers): ModuleList(
(0-47): 48 x XGLMDecoderLayer(
(self_attn): XGLMAttention(
(k_proj): Linear(in_features=2048, out_features=2048, bias=True)
(v_proj): Linear(in_features=2048, out_features=2048, bias=True)
(q_proj): Linear(in_features=2048, out_features=2048, bias=True)
(o_proj/out_proj): Linear(in_features=2048, out_features=2048, bias=True)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention, already scaled by 1/sqrt(head_dim)
(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_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
(attention_queries_prerope) -> Queries [batch num_heads seq qk_head_dim]: The queries entering the rotary embedding
(attention_keys_prerope) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering the rotary embedding
(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
(interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
)
(activation_fn): GELUActivation()
(input_layernorm/self_attn_layer_norm): LayerNorm((2048,), eps=1e-05, elementwise_affine=True, bias=True)
(fc1): Linear(in_features=2048, out_features=8192, bias=True)
(fc2): Linear(in_features=8192, out_features=2048, bias=True)
(final_layer_norm): LayerNorm((2048,), eps=1e-05, elementwise_affine=True, bias=True)
(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 feed-forward path
(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 facebook/xglm-4.5B: the native modules, standard names and every standard value with its layout.
XGLMForCausalLM(
(lm_head): Linear(in_features=2048, out_features=256008, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): XGLMScaledWordEmbedding(256008, 2048, padding_idx=1)
(layers): ModuleList(
(0-47): 48 x XGLMDecoderLayer(
(self_attn): XGLMAttention(
(k_proj): Linear(in_features=2048, out_features=2048, bias=True)
(v_proj): Linear(in_features=2048, out_features=2048, bias=True)
(q_proj): Linear(in_features=2048, out_features=2048, bias=True)
(o_proj/out_proj): Linear(in_features=2048, out_features=2048, bias=True)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention, already scaled by 1/sqrt(head_dim)
(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_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
(attention_queries_prerope) -> Queries [batch num_heads seq qk_head_dim]: The queries entering the rotary embedding
(attention_keys_prerope) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering the rotary embedding
(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
(interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
)
(activation_fn): ReLU()
(input_layernorm/self_attn_layer_norm): LayerNorm((2048,), eps=1e-05, elementwise_affine=True, bias=True)
(fc1): Linear(in_features=2048, out_features=16384, bias=True)
(fc2): Linear(in_features=16384, out_features=2048, bias=True)
(final_layer_norm): LayerNorm((2048,), eps=1e-05, elementwise_affine=True, bias=True)
(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 feed-forward path
(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 facebook/xglm-7.5B: the native modules, standard names and every standard value with its layout.
XGLMForCausalLM(
(lm_head): Linear(in_features=4096, out_features=256008, bias=False)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): XGLMScaledWordEmbedding(256008, 4096, padding_idx=1)
(layers): ModuleList(
(0-31): 32 x XGLMDecoderLayer(
(self_attn): XGLMAttention(
(k_proj): Linear(in_features=4096, out_features=4096, bias=True)
(v_proj): Linear(in_features=4096, out_features=4096, bias=True)
(q_proj): Linear(in_features=4096, out_features=4096, bias=True)
(o_proj/out_proj): Linear(in_features=4096, out_features=4096, bias=True)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention, already scaled by 1/sqrt(head_dim)
(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_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
(attention_queries_prerope) -> Queries [batch num_heads seq qk_head_dim]: The queries entering the rotary embedding
(attention_keys_prerope) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering the rotary embedding
(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
(interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
)
(activation_fn): GELUActivation()
(input_layernorm/self_attn_layer_norm): LayerNorm((4096,), eps=1e-05, elementwise_affine=True, bias=True)
(fc1): Linear(in_features=4096, out_features=16384, bias=True)
(fc2): Linear(in_features=16384, out_features=4096, bias=True)
(final_layer_norm): LayerNorm((4096,), eps=1e-05, elementwise_affine=True, bias=True)
(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 feed-forward path
(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((4096,), 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
)layers[i].fc2.outputThere is no mlp module, so mlp_output and the other mlp values do not exist. The MLP path adds
layers[i].fc2.output to the stream, and its neurons are layers[i].activation_fn.output.
attention_keys and attention_values are read after the cache update, over the whole batch, so
under several invokes each invoke reads every invoke's keys and values and an edit in one reaches
them all. Edit keys and values in a trace with one invoke.
XGLM (XGLMForCausalLM).
model.{embed_tokens, embed_positions, layers[i].{self_attn, self_attn_layer_norm, fc1, fc2, final_layer_norm}, layer_norm} and lm_head. embed_tokens is a
scaled embedding (times sqrt(d_model) under scale_embedding), so
token_embeddings is the scaled lookup; the sinusoidal positions are added
after it, outside any module with a standard name. As on OPT there is no MLP
module: fc1 and fc2 sit on the block, so mlp and mlp_output do not
exist here and StandardizedTransformer.support says so. The block's own
final_layer_norm is the pre-MLP norm and keeps its native name. The block
returns a bare tensor. The attention does its own arithmetic whatever
attn_implementation says (the model has no other): queries scaled by
1/sqrt(head_dim) as they are projected, queries, keys and values flattened to
[batch * num_heads, seq, head_dim] for torch.bmm, the mask added and clamped,
softmax, dropout, bmm with the values; the interior needs no eager load. The
queries, scores, pattern and head outputs are read where the forward holds them
batch first, so each invoke reads and edits its own rows; the keys and values, read
after the cache update, are the whole batch's in every invoke.