nnterp · encyclopedia gemma4_text · nnterp.families.gemma4_text

family gemma4_text

Gemma 4

The block

01 · the residual stream

One block of the stack. Hover any part for its nnterp name; click to pin the card. The slider picks a block; this family's blocks differ by layer_types.

embed_tokenstoken_embeddings
→
layers× 35
→
normfinal_norm_output
→
lm_headlm_head_output
→
logitssoftcapped
i = 0

identity (layers[i].input + self_attn.attention_output + mlp.mlp_output + per_layer_output) * layer_scalar == layer_output

The vision encoder

· Gemma 4 ViT · Gemma4VisionModel

The image's path into the text model, then one block of the vision encoder. Hover any part for its nnterp name; click to pin the card.

imagepixel_values
→
patch_embedpatch_embeddings
→
layers× 16 · tower_output
→
projectorinput: the pooler's soft tokens, after vision.tower_output
→
image_featuresat the scatter
→
layers[0].inputat image_token_mask
rows
One row per image: its patches, then padding up to max_soft_tokens * pooling_kernel_size**2 rows (2520 by default); the processor's image_position_ids is (-1, -1) on the padded rows.
positions
patch_embeddings is patch_embedder.input_proj's output; patch_embedder then adds a learned x and a learned y embedding per patch (zero on the padded rows), and every attention rotates queries and keys by the patch's 2D position.
masking
No causal mask: a row attends to every patch of its image; the padded rows are masked as keys.
final norm
None: vision.tower_output is the encoder's output, padded rows included, and the vision encoder's pooler follows it, outside the blocks.

identity vision.layers[i].input + self_attn.attention_output + mlp.mlp_output == layer_output

The API

02 · support()

Values, by host

⚠︎ marks a value this checkpoint has only under some load: hover it for the condition.

model Gemma4ForConditionalGenerationlayoutwhat it isread at
logits Logits [batch seq vocab_size] The logits the model returns, after anything it does past lm_head (a softcap, a scale)

the module's own output

token_embeddings Residual [batch seq hidden_size] The embedding module's output; layers[0].input is what enters the first block

the child module embed_tokens's output

final_norm_output Residual [batch seq hidden_size] The residual stream after the final norm, what lm_head reads

the child module norm's output

lm_head_output Logits [batch seq vocab_size] The head's logits before anything the model does past lm_head (a softcap, a scale)

the child module lm_head's output

next_token_probs NextTokenProbs [batch vocab_size] The next-token distribution at the last position; derived, read-only

the module's own output

input_ids Tokens [batch seq] The token ids the model was called with

the module's own input

attention_mask Tokens [batch seq] The attention mask the model was called with; zeros are padding

the module's own input

input_size scalar [batch, seq] of the current call; read-only

the module's own input

model.layers[i] Gemma4TextDecoderLayerlayoutwhat it isread at
layer_input Residual [batch seq hidden_size] The residual stream entering the block

the module's own input

attention_norm_output Residual [batch seq hidden_size] The normed stream entering the attention

the child module input_layernorm's output

layer_mid Residual [batch seq hidden_size] The residual stream after the attention add

the child module pre_feedforward_layernorm's input

mlp_norm_output Residual [batch seq hidden_size] The normed stream entering the MLP

the child module pre_feedforward_layernorm's output

mlp_input Residual [batch seq hidden_size] What the MLP is called with

the child module mlp's input

layer_output Residual [batch seq hidden_size] The residual stream leaving the block, a tensor even when the block returns a tuple

the module's own output

per_layer_output Residual [batch seq hidden_size] What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output

the child module post_per_layer_input_norm's output

model.layers[i].self_attn Gemma4TextAttentionlayoutwhat it isread at
attention_queries_prerope Queries [batch num_heads seq qk_head_dim] The queries entering the rotary embedding

inside the forward: the input of apply_rotary_pos_emb_0

⚠︎attention_keys_prerope Keys [batch num_kv_heads seq qk_head_dim] The keys entering the rotary embedding

inside the forward: the input of apply_rotary_pos_emb_1

⚠︎attention_queries Queries [batch num_heads seq qk_head_dim] The queries entering attention

inside the forward: the arguments of attention_interface_1, element 1

⚠︎attention_keys Keys [batch num_kv_heads seq qk_head_dim] The keys entering attention

inside the forward: the arguments of attention_interface_1, element 2

⚠︎attention_values Values [batch num_kv_heads seq head_dim] The values entering attention

inside the forward: the arguments of attention_interface_1, element 3

⚠︎attention_scores Pattern [batch num_heads query key] The attention scores entering the softmax, masked

inside the forward: the input of nn_functional_softmax_0 inside attention_interface_1

attention_premix HeadOutputs [batch seq num_heads head_dim] Every head's output side by side, as the output projection takes it

the child module o_proj's input

attention_output Residual [batch seq hidden_size] What the attention adds to the residual stream: the post-attention norm's output

the sibling module post_attention_layernorm's output

⚠︎attention_probabilities Pattern [batch num_heads query key] The attention pattern the values are mixed with

inside the forward: the output of nn_functional_dropout_0 inside attention_interface_1

⚠︎attention_head_outputs HeadOutputs [batch seq num_heads head_dim] The per-head outputs before the output projection

inside the forward: the output of attention_interface_1, element 0

⚠︎interface method (Queries, Keys, Values) -> (HeadOutputs, Pattern) The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments

read at the arguments of attention_interface_1, with the queries, keys and values; called, the function that call ran, on the tensors given and the call's other arguments

model.layers[i].mlp Gemma4TextMLPlayoutwhat it isread at
mlp_activation Neurons [batch seq intermediate_size] The activation function's output

the child module act_fn'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

the child module down_proj's input

mlp_output Residual [batch seq hidden_size] What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output

the sibling module post_feedforward_layernorm's output

router_logits RouterLogits [batch seq num_experts] The router's logits, one per expert, before the scoring

nowhere: this checkpoint's blocks run no mixture of experts (enable_moe_block is false)

expert_weights ExpertWeights [batch seq top_k] The weight each selected expert's output is scaled by

nowhere: this checkpoint's blocks run no mixture of experts (enable_moe_block is false)

expert_indices ExpertIndices [batch seq top_k] The expert each routing slot sends the token to

nowhere: this checkpoint's blocks run no mixture of experts (enable_moe_block is false)

expert_outputs ExpertOutputs [batch seq top_k hidden_size] Each routing slot's weighted expert output

nowhere: this checkpoint's blocks run no mixture of experts (enable_moe_block is false)

routed_output Residual [batch seq hidden_size] The routed experts' combined output

nowhere: this checkpoint's blocks run no mixture of experts (enable_moe_block is false)

shared_expert_output Residual [batch seq hidden_size] The dense MLP's output, before its post-norm: the shared expert beside the mixture

nowhere: this checkpoint's blocks run no mixture of experts (enable_moe_block is false)

the vision encoder · Gemma 4 ViT

model.vision Gemma4VisionModellayoutwhat it isread at
image_token_mask ImageTokenMask [batch seq] Which positions hold image tokens: input_ids == the config's image_token_id; read-only

the model's own inputs, at the root

patch_embeddings Patches [images patches vision_hidden_size] The patch embedding's output, one row per patch

the child module patch_embed's output

tower_output Patches [images patches vision_hidden_size] The last block's stream after the tower's final norm, before any pooling or adapter

the child module encoder's output

image_features ImageFeatures [image_tokens hidden_size] The image features the text model receives at the image tokens, flat over them

inside model.model's forward: the arguments of inputs_embeds_masked_scatter_0, element 1

model.vision.layers[i] Gemma4VisionEncoderLayerlayoutwhat it isread at
layer_input Patches [images patches vision_hidden_size] The tower's stream entering the block

the module's own input

attention_norm_output Patches [images patches vision_hidden_size] The normed stream entering the attention

the child module input_layernorm's output

layer_mid Patches [images patches vision_hidden_size] The tower's stream after the attention add

the child module pre_feedforward_layernorm's input

mlp_norm_output Patches [images patches vision_hidden_size] The normed stream entering the MLP

the child module pre_feedforward_layernorm's output

mlp_input Patches [images patches vision_hidden_size] What the MLP is called with

the child module mlp's input

layer_output Patches [images patches vision_hidden_size] The tower's stream leaving the block

the module's own output

model.vision.layers[i].self_attn Gemma4VisionAttentionlayoutwhat it isread at
attention_queries_prerope Queries [batch num_heads seq qk_head_dim] The queries entering the rotary embedding

nowhere: a vision tower's attention: the queries and keys before a rotary embedding, and rotate, are served on the text model's blocks (a tower's rotary, where it has one, runs over 2-D patch positions)

attention_keys_prerope Keys [batch num_kv_heads seq qk_head_dim] The keys entering the rotary embedding

nowhere: a vision tower's attention: the queries and keys before a rotary embedding, and rotate, are served on the text model's blocks (a tower's rotary, where it has one, runs over 2-D patch positions)

⚠︎attention_queries Queries [batch num_heads seq qk_head_dim] The queries entering attention

inside the forward: the arguments of attention_interface_1, element 1

⚠︎attention_keys Keys [batch num_kv_heads seq qk_head_dim] The keys entering attention

inside the forward: the arguments of attention_interface_1, element 2

⚠︎attention_values Values [batch num_kv_heads seq head_dim] The values entering attention

inside the forward: the arguments of attention_interface_1, element 3

⚠︎attention_scores Pattern [batch num_heads query key] The attention scores entering the softmax, masked

inside the forward: the input of nn_functional_softmax_0 inside attention_interface_1

attention_premix HeadOutputs [batch seq num_heads head_dim] Every head's output side by side, as the output projection takes it

the child module o_proj's input

attention_output Patches [images patches vision_hidden_size] What the attention adds to the tower's stream: the post-attention norm's output

the sibling module post_attention_layernorm's output

⚠︎attention_probabilities Pattern [batch num_heads query key] The attention pattern the values are mixed with

inside the forward: the output of nn_functional_dropout_0 inside attention_interface_1

⚠︎attention_head_outputs HeadOutputs [batch seq num_heads head_dim] The per-head outputs before the output projection

inside the forward: the output of attention_interface_1, element 0

⚠︎interface method (Queries, Keys, Values) -> (HeadOutputs, Pattern) The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments

read at the arguments of attention_interface_1, with the queries, keys and values; called, the function that call ran, on the tensors given and the call's other arguments

model.vision.layers[i].mlp Gemma4VisionMLPlayoutwhat it isread at
mlp_activation Neurons [batch seq intermediate_size] The activation function's output

the child module act_fn's output

mlp_neurons Neurons [batch seq intermediate_size] What the down projection receives

the child module down_proj's input

mlp_output Patches [images patches vision_hidden_size] What the MLP adds to the tower's stream: the post-feedforward norm's output

the sibling module post_feedforward_layernorm's output

Printout

What print(model) shows on google/gemma-4-E2B: the native modules, standard names and every standard value with its layout.

Gemma4ForConditionalGeneration(
  (lm_head): Linear(in_features=1536, out_features=262144, bias=False)
  (generator): Generator(
    (streamer): Streamer()
  )
  (embed_tokens): Gemma4TextScaledWordEmbedding(262144, 1536, padding_idx=0)
  (layers): ModuleList(
    (0-3): 4 x Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=2048, bias=False)
        (q_norm): Gemma4RMSNorm()
        (k_norm): Gemma4RMSNorm()
        (v_norm): Gemma4RMSNorm()
        (k_proj): Linear(in_features=1536, out_features=256, bias=False)
        (v_proj): Linear(in_features=1536, out_features=256, bias=False)
        (o_proj): Linear(in_features=2048, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=6144, bias=False)
        (up_proj): Linear(in_features=1536, out_features=6144, bias=False)
        (down_proj): Linear(in_features=6144, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (4): Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=4096, bias=False)
        (q_norm): Gemma4RMSNorm()
        (k_norm): Gemma4RMSNorm()
        (v_norm): Gemma4RMSNorm()
        (k_proj): Linear(in_features=1536, out_features=512, bias=False)
        (v_proj): Linear(in_features=1536, out_features=512, bias=False)
        (o_proj): Linear(in_features=4096, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=6144, bias=False)
        (up_proj): Linear(in_features=1536, out_features=6144, bias=False)
        (down_proj): Linear(in_features=6144, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (5-8): 4 x Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=2048, bias=False)
        (q_norm): Gemma4RMSNorm()
        (k_norm): Gemma4RMSNorm()
        (v_norm): Gemma4RMSNorm()
        (k_proj): Linear(in_features=1536, out_features=256, bias=False)
        (v_proj): Linear(in_features=1536, out_features=256, bias=False)
        (o_proj): Linear(in_features=2048, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=6144, bias=False)
        (up_proj): Linear(in_features=1536, out_features=6144, bias=False)
        (down_proj): Linear(in_features=6144, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (9): Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=4096, bias=False)
        (q_norm): Gemma4RMSNorm()
        (k_norm): Gemma4RMSNorm()
        (v_norm): Gemma4RMSNorm()
        (k_proj): Linear(in_features=1536, out_features=512, bias=False)
        (v_proj): Linear(in_features=1536, out_features=512, bias=False)
        (o_proj): Linear(in_features=4096, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=6144, bias=False)
        (up_proj): Linear(in_features=1536, out_features=6144, bias=False)
        (down_proj): Linear(in_features=6144, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (10-13): 4 x Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=2048, bias=False)
        (q_norm): Gemma4RMSNorm()
        (k_norm): Gemma4RMSNorm()
        (v_norm): Gemma4RMSNorm()
        (k_proj): Linear(in_features=1536, out_features=256, bias=False)
        (v_proj): Linear(in_features=1536, out_features=256, bias=False)
        (o_proj): Linear(in_features=2048, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=6144, bias=False)
        (up_proj): Linear(in_features=1536, out_features=6144, bias=False)
        (down_proj): Linear(in_features=6144, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (14): Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=4096, bias=False)
        (q_norm): Gemma4RMSNorm()
        (k_norm): Gemma4RMSNorm()
        (v_norm): Gemma4RMSNorm()
        (k_proj): Linear(in_features=1536, out_features=512, bias=False)
        (v_proj): Linear(in_features=1536, out_features=512, bias=False)
        (o_proj): Linear(in_features=4096, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=6144, bias=False)
        (up_proj): Linear(in_features=1536, out_features=6144, bias=False)
        (down_proj): Linear(in_features=6144, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (15-18): 4 x Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=2048, bias=False)
        (q_norm): Gemma4RMSNorm()
        (o_proj): Linear(in_features=2048, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (up_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (down_proj): Linear(in_features=12288, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (19): Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=4096, bias=False)
        (q_norm): Gemma4RMSNorm()
        (o_proj): Linear(in_features=4096, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (up_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (down_proj): Linear(in_features=12288, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (20-23): 4 x Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=2048, bias=False)
        (q_norm): Gemma4RMSNorm()
        (o_proj): Linear(in_features=2048, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (up_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (down_proj): Linear(in_features=12288, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (24): Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=4096, bias=False)
        (q_norm): Gemma4RMSNorm()
        (o_proj): Linear(in_features=4096, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (up_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (down_proj): Linear(in_features=12288, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (25-28): 4 x Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=2048, bias=False)
        (q_norm): Gemma4RMSNorm()
        (o_proj): Linear(in_features=2048, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (up_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (down_proj): Linear(in_features=12288, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (29): Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=4096, bias=False)
        (q_norm): Gemma4RMSNorm()
        (o_proj): Linear(in_features=4096, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (up_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (down_proj): Linear(in_features=12288, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (30-33): 4 x Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=2048, bias=False)
        (q_norm): Gemma4RMSNorm()
        (o_proj): Linear(in_features=2048, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (up_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (down_proj): Linear(in_features=12288, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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
    )
    (34): Gemma4TextDecoderLayer(
      (self_attn): Gemma4TextAttention(
        (q_proj): Linear(in_features=1536, out_features=4096, bias=False)
        (q_norm): Gemma4RMSNorm()
        (o_proj): Linear(in_features=4096, out_features=1536, bias=False)
        (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_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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream: the post-attention norm's output
        (attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries 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_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
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (mlp): Gemma4TextMLP(
        (gate_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (up_proj): Linear(in_features=1536, out_features=12288, bias=False)
        (down_proj): Linear(in_features=12288, out_features=1536, bias=False)
        (act_fn): GELUTanh()
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP (and, on a mixture block, the experts) adds to the residual stream: the post-feedforward norm's output
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (shared_expert_output) -> Residual [batch seq hidden_size]: The dense MLP's output, before its post-norm: the shared expert beside the mixture
        (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
        (expert_weights) -> ExpertWeights [batch seq top_k]: The weight each selected expert's output is scaled by
        (expert_indices) -> ExpertIndices [batch seq top_k]: The expert each routing slot sends the token to
        (expert_outputs) -> ExpertOutputs [batch seq top_k hidden_size]: Each routing slot's weighted expert output
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output
      )
      (input_layernorm): Gemma4RMSNorm()
      (post_attention_layernorm): Gemma4RMSNorm()
      (pre_feedforward_layernorm): Gemma4RMSNorm()
      (post_feedforward_layernorm): Gemma4RMSNorm()
      (act_fn): GELUTanh()
      (per_layer_input_gate): Linear(in_features=1536, out_features=256, bias=False)
      (per_layer_projection): Linear(in_features=256, out_features=1536, bias=False)
      (post_per_layer_input_norm): Gemma4RMSNorm()
      (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
      (per_layer_output) -> Residual [batch seq hidden_size]: What the per-layer-embedding branch adds to the residual stream: the post-per-layer-input norm's output
      (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): Gemma4RMSNorm()
  (vision): Gemma4VisionModel(
    (encoder): Gemma4VisionEncoder(
      (rotary_emb): Gemma4VisionRotaryEmbedding()
      (layers): ModuleList(
        (0-15): 16 x Gemma4VisionEncoderLayer(
          (self_attn): Gemma4VisionAttention(
            (q_proj): Gemma4ClippableLinear(
              (linear): Linear(in_features=768, out_features=768, bias=False)
            )
            (k_proj): Gemma4ClippableLinear(
              (linear): Linear(in_features=768, out_features=768, bias=False)
            )
            (v_proj): Gemma4ClippableLinear(
              (linear): Linear(in_features=768, out_features=768, bias=False)
            )
            (o_proj): Gemma4ClippableLinear(
              (linear): Linear(in_features=768, out_features=768, bias=False)
            )
            (q_norm): Gemma4RMSNorm()
            (k_norm): Gemma4RMSNorm()
            (v_norm): Gemma4RMSNorm()
            (attention_output) -> Patches [images patches vision_hidden_size]: What the attention adds to the tower's stream: the post-attention norm's output
            (attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
            (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_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_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
            (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
          )
          (mlp): Gemma4VisionMLP(
            (gate_proj): Gemma4ClippableLinear(
              (linear): Linear(in_features=768, out_features=3072, bias=False)
            )
            (up_proj): Gemma4ClippableLinear(
              (linear): Linear(in_features=768, out_features=3072, bias=False)
            )
            (down_proj): Gemma4ClippableLinear(
              (linear): Linear(in_features=3072, out_features=768, bias=False)
            )
            (act_fn): GELUTanh()
            (mlp_output) -> Patches [images patches vision_hidden_size]: What the MLP adds to the tower's stream: the post-feedforward norm's output
            (mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
            (mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives
          )
          (input_layernorm): Gemma4RMSNorm()
          (post_attention_layernorm): Gemma4RMSNorm()
          (pre_feedforward_layernorm): Gemma4RMSNorm()
          (post_feedforward_layernorm): Gemma4RMSNorm()
          (layer_mid) -> Patches [images patches vision_hidden_size]: The tower's stream after the attention add
          (mlp_norm_output) -> Patches [images patches vision_hidden_size]: The normed stream entering the MLP
          (layer_input) -> Patches [images patches vision_hidden_size]: The tower's stream entering the block
          (attention_norm_output) -> Patches [images patches vision_hidden_size]: The normed stream entering the attention
          (mlp_input) -> Patches [images patches vision_hidden_size]: What the MLP is called with
          (layer_output) -> Patches [images patches vision_hidden_size]: The tower's stream leaving the block
        )
      )
    )
    (pooler): Gemma4VisionPooler()
    (patch_embed): Linear(in_features=768, out_features=768, bias=False)
    (layers): ModuleList(
      (0-15): 16 x Gemma4VisionEncoderLayer(
        (self_attn): Gemma4VisionAttention(
          (q_proj): Gemma4ClippableLinear(
            (linear): Linear(in_features=768, out_features=768, bias=False)
          )
          (k_proj): Gemma4ClippableLinear(
            (linear): Linear(in_features=768, out_features=768, bias=False)
          )
          (v_proj): Gemma4ClippableLinear(
            (linear): Linear(in_features=768, out_features=768, bias=False)
          )
          (o_proj): Gemma4ClippableLinear(
            (linear): Linear(in_features=768, out_features=768, bias=False)
          )
          (q_norm): Gemma4RMSNorm()
          (k_norm): Gemma4RMSNorm()
          (v_norm): Gemma4RMSNorm()
          (attention_output) -> Patches [images patches vision_hidden_size]: What the attention adds to the tower's stream: the post-attention norm's output
          (attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
          (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_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_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
          (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
        )
        (mlp): Gemma4VisionMLP(
          (gate_proj): Gemma4ClippableLinear(
            (linear): Linear(in_features=768, out_features=3072, bias=False)
          )
          (up_proj): Gemma4ClippableLinear(
            (linear): Linear(in_features=768, out_features=3072, bias=False)
          )
          (down_proj): Gemma4ClippableLinear(
            (linear): Linear(in_features=3072, out_features=768, bias=False)
          )
          (act_fn): GELUTanh()
          (mlp_output) -> Patches [images patches vision_hidden_size]: What the MLP adds to the tower's stream: the post-feedforward norm's output
          (mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
          (mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives
        )
        (input_layernorm): Gemma4RMSNorm()
        (post_attention_layernorm): Gemma4RMSNorm()
        (pre_feedforward_layernorm): Gemma4RMSNorm()
        (post_feedforward_layernorm): Gemma4RMSNorm()
        (layer_mid) -> Patches [images patches vision_hidden_size]: The tower's stream after the attention add
        (mlp_norm_output) -> Patches [images patches vision_hidden_size]: The normed stream entering the MLP
        (layer_input) -> Patches [images patches vision_hidden_size]: The tower's stream entering the block
        (attention_norm_output) -> Patches [images patches vision_hidden_size]: The normed stream entering the attention
        (mlp_input) -> Patches [images patches vision_hidden_size]: What the MLP is called with
        (layer_output) -> Patches [images patches vision_hidden_size]: The tower's stream leaving the block
      )
    )
    (tower_output) -> Patches [images patches vision_hidden_size]: The last block's stream after the tower's final norm, before any pooling or adapter
    (image_token_mask) -> ImageTokenMask [batch seq]: Which positions hold image tokens: input_ids == the config's image_token_id; read-only
    (patch_embeddings) -> Patches [images patches vision_hidden_size]: The patch embedding's output, one row per patch
    (image_features) -> ImageFeatures [image_tokens hidden_size]: The image features the text model receives at the image tokens, flat over them
  )
  (projector): Gemma4MultimodalEmbedder(
    (embedding_projection): Linear(in_features=768, out_features=1536, bias=False)
    (embedding_pre_projection_norm): Gemma4RMSNorm()
  )
  (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
)

Config

model.num_layers35
model.hidden_size1536
model.num_heads8
model.num_kv_heads1
model.head_dim256
model.qk_head_dim256
model.vocab_size262144
model.intermediate_size6144
architecturesGemma4ForConditionalGeneration
num_hidden_layers35
hidden_size1536
intermediate_size6144
num_attention_heads8
num_key_value_heads1
head_dim256
vocab_size262144
max_position_embeddings131072
sliding_window512
hidden_activationgelu_pytorch_tanh
rms_norm_eps1e-06
final_logit_softcapping30.0
tie_word_embeddingsTrue
dtypebfloat16
num_kv_shared_layers20
attention_biasFalse
enable_moe_blockFalse
hidden_size_per_layer_input256
attention_k_eq_vFalse
Vision Config

Vision Config

model.vision.num_layers16
model.vision.vision_hidden_size768
model.vision.num_heads12
model.vision.head_dim64
model.vision.intermediate_size3072
model.vision.patch_size16
model.vision.image_sizevaries

The Notes

03 · what to know before you run

Each block scales its whole sum by layer_scalar

h   = x + post_attention_layernorm(self_attn(input_layernorm(x)))
h   = h + post_feedforward_layernorm(mlp(pre_feedforward_layernorm(h)))
h   = h + per_layer_output                # E2B and E4B
out = h * layer_scalar

attention_output, mlp_output and per_layer_output are the post-norms' outputs, before the scalar, and on E2B every scalar is below one. A term's weight in the last stream is the product of its own block's scalar and every later one, so direct logit attribution multiplies each term by that product first, and a vector added to mlp_output reaches layer_output scaled by the block's scalar.

Patching token_embeddings does not swap the token on E2B and E4B

Each block's per-layer input is a table lookup by token id plus a projection of token_embeddings, so writing another token's embedding into token_embeddings changes only the projected half. To swap a token, also patch model.model.language_model.embed_tokens_per_layer.output at that position.

Borrowed keys and values are copies

On E2B and E4B the last blocks attend with an earlier block's keys and values, served to each borrowing block as its own copy. An edit to the source block's attention_keys or attention_values reaches only that block; an edit to its k_proj output reaches every block that borrows from it.

On 26B-A4B the dense MLP runs beside the experts

mlp.output is the dense MLP's, served as shared_expert_output, and mlp_output norms it together with routed_output. expert_weights are the top-8 softmax entries renormalized to sum to one, then multiplied by the learned per_expert_scale.

Vision notes

· Gemma 4 ViT · Gemma 4

The Gemma 4 ViT vision encoder

The block is a sandwich

h   = x + post_attention_layernorm(self_attn(input_layernorm(x)))
out = h + post_feedforward_layernorm(mlp(pre_feedforward_layernorm(h)))

Four RMSNorms per block, no per-layer branch and no scalar. attention_output and mlp_output are the post-norms' outputs, so vision.layers[i].input + attention_output + mlp_output == layer_output holds exactly in float32, and an ablation or a steering vector on a sublayer goes on attention_output or mlp_output.

Queries, keys and values are normed, and the scores are not scaled

The attention norms each head's queries and keys (q_norm, k_norm) and its values (v_norm, without gain), rotates queries and keys by the patch's x and y position, and computes the scores with scaling 1.0. model.vision.head_dim is the config's head_dim: 64 on E2B and E4B, with 12 heads over a 768-wide stream.

The padded rows run through every block

The processor resizes an image within a budget of max_soft_tokens * pooling_kernel_size**2 patches of 16 pixels and pads the row to that length: a square image is 48 × 48 = 2304 patches and 216 padded rows of 2520. The padded rows are masked as keys, so no patch reads them, but they are rows of every block's layer_output and of tower_output, with values. Select the image's patches with the processor's positions:

encoding = model.processor(text=prompt, images=[image], return_tensors="pt")
padded = (encoding["image_position_ids"] == -1).all(-1)   # [images, 2520]

with model.trace(dict(encoding)):
    stream = model.vision.layers[0].layer_output.save()

stream[~padded]                         # the 2304 patches

The pooler makes the soft tokens

After the last block the vision encoder's pooler zeroes the padded rows, averages each 3 × 3 block of patches by position (pooling_kernel_size), multiplies by √vision_hidden_size and drops the padding: 2304 patches become 256 soft tokens, [soft_tokens, vision_hidden_size] flat over the images. These soft tokens are model.projector.input. A write to tower_output at the padded rows changes nothing downstream; at the patches it reaches the text model. On 26B-A4B and 31B (standardize) the pooled tokens are then shifted by std_bias and scaled by std_scale, inside the vision encoder.

Gemma 4

The projector reads the pooler's soft tokens

embed_vision reads the soft tokens the vision encoder's pooler averages from tower_output, not tower_output itself.

On 26B-A4B and 31B an image's tokens attend to each other on the sliding blocks

On a sliding block an image's tokens attend to every token of the same image within the window, later ones included; the full blocks stay causal. E2B and E4B are causal throughout.

From the family module

04 · nnterp/families/gemma4_text.py

Gemma 4, text (Gemma4ForCausalLM, model_type gemma4_text): E2B, E4B, 26B-A4B and 31B.

model.{embed_tokens, layers[i].{input_layernorm, self_attn, post_attention_layernorm, pre_feedforward_layernorm, mlp, post_feedforward_layernorm}, norm} and lm_head: Gemma-3's sandwich tree. A gemma4 checkpoint (Gemma4ForConditionalGeneration, the published repos) nests its config's text_config, of this type; the text-generation task builds the wrapper, whose text stack sits at model.language_model.{embed_tokens, layers, norm} with lm_head at the root, so RENAME carries both spellings and whichever the tree has binds.

The block, in order::

x1 = x  + post_attention_layernorm(self_attn(input_layernorm(x)))
x2 = x1 + post_feedforward_layernorm(mlp(pre_feedforward_layernorm(x1)) [+ experts])
p  = gelu(per_layer_input_gate(x2)) * per_layer_input
x3 = x2 + post_per_layer_input_norm(per_layer_projection(p))
out = x3 * layer_scalar          # in place, on x3
  • The contributions are the post-norms' outputs, as on Gemma-2/3. On a mixture-of-experts checkpoint (26B-A4B, enable_moe_block) the block also runs router and experts, direct children of the block, not of mlp: post_feedforward_layernorm_1(mlp(...)) + post_feedforward_layernorm_2(experts(pre_feedforward_layernorm_2(x1))), and post_feedforward_layernorm norms that sum, so mlp_output is the dense MLP and the experts together, what the block adds. The mixture has no module of its own, so mlp (a Moe) hosts its values, reading the block's router and experts through its parent. The router runs on x1, the stream after the attention's add (the block's residual at that point, not its input), with its own norm, and returns probabilities; router_logits are its projection's output (router.proj). shared_expert_output is the dense MLP's output, before its post-norm: mlp_output == post_feedforward_layernorm( post_feedforward_layernorm_1(shared_expert_output) + post_feedforward_layernorm_2(routed_output)). On a dense checkpoint every mixture value is unavailable.
  • Per-layer embeddings (E2B/E4B, hidden_size_per_layer_input): a third add, served as layers[i].per_layer_output (the post-per-layer-input norm's output). per_layer_input is the block's second argument, one slice of the model's per-layer embedding table mixed with a projection of the token embeddings. On a checkpoint without them the value is unavailable.
  • layer_scalar, a per-block buffer, multiplies the sum in place. The contributions are served unscaled, so the identity is (input + attention_output + mlp_output [+ per_layer_output]) * layer_scalar == layer_output.
  • Keys and values that are not the block's own. The last num_kv_shared_layers blocks have no k_proj/v_proj: each borrows the keys and values of the last earlier block of the same kind (sliding or full) before the sharing starts. On a checkpoint with attention_k_eq_v (26B-A4B, 31B) the full-attention blocks have no v_proj: their values are v_norm(k_proj(x)), the keys' projection before k_norm and the rotary embedding. attention_keys and attention_values are what the attention receives on every block, borrowed or not, served as copies private to the block: an edit, in place or by assignment, changes what that block attends with and nothing else, and the blocks that borrow a source block's tensors keep the originals.
  • Per-layer sizes. Sliding and full blocks differ in head_dim (and on 26B-A4B/31B in num_key_value_heads), and on E2B (use_double_wide_mlp) the KV-sharing blocks' MLP is twice intermediate_size wide; the config marks the attention sizes per-layer and refuses a plain config.head_dim. The root's head_dim and num_kv_heads report the config's top-level values (the sliding blocks'); each block's own are on layers[i].self_attn and layers[i].mlp, read off the module.

final_logit_softcapping is in the text config; the root's project_on_vocab reads it there.

On the wrapper the vision tower model.vision_tower is vision (a Vision) and model.embed_vision, the last module before the scatter, is projector. The tower is a ViT over each image's patches: the patch embedder's linear over the processor's flattened patches (patch_embedder.input_proj) is vision.patch_embed, so vision.patch_embeddings is before the 2D position embedding patch_embedder adds, and the blocks (encoder.layers) are vision.layers. Each block is the text block's sandwich, so its contributions are the post-norms' outputs too (VisionAttention, VisionMlp). The processor pads every image's patches to max_soft_tokens * pooling_kernel_size**2 rows with zero pixels at position (-1, -1); the padded rows run through every block (masked as keys only), so they are present in vision.layers[i].layer_output. There is no final norm: the tower's pooler zeroes the padded rows, average-pools the patches pooling_kernel_size by pooling_kernel_size and multiplies by sqrt(vision_hidden_size) (in float32); the tower then strips the padding and, where the vision config sets standardize (26B-A4B, 31B), subtracts std_bias and multiplies by std_scale. So vision.tower_output is the encoder's output (the last block's stream, padded) and projector.input is the pooled, scaled (and standardized) soft tokens, flat over the images. The audio tower (model.audio_tower, a Conformer) and its embedder model.embed_audio keep their native names.