nnterp · encyclopedia jetmoe · nnterp.families.jetmoe

family jetmoe

JetMoE

The block

01 · the residual stream

One block of the stack. Hover any part for its nnterp name; click to pin the card.

embed_tokenstoken_embeddings
→
layers× 24
→
normfinal_norm_output
→
lm_headlm_head_output
→
logitsthe output
i = 0

identity 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 JetMoeForCausalLMlayoutwhat 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] JetMoeDecoderLayerlayoutwhat 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 post_attention_layernorm's input

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

the child module post_attention_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

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

nowhere: routed experts; read per-expert via the Moe component

mlp_neurons Neurons [batch seq intermediate_size] What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise

nowhere: routed experts; read per-expert via the Moe component

mlp_output Residual [batch seq hidden_size] What the MLP adds to the residual stream

the module's own output

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

the child module router.layer's output

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

inside router's forward: the output of top_k_gates_0

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

inside router's forward: the output of logits_topk_0, element 1

expert_outputs scalar Unavailable: JetMoE's mixture runs its experts over the slots sorted by expert; no tensor holds them in token order

nowhere: the family does not serve it

routed_output Residual [batch seq hidden_size] The routed experts' combined output, before the mixture's bias

inside the forward: the output of layer_output_1

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

inside the forward: the arguments of apply_rotary_pos_emb_0, element 0

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

inside the forward: the arguments of apply_rotary_pos_emb_0, element 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 scalar Unavailable: a mixture of attention heads: the output projection is per expert, inside experts

nowhere: the family does not serve it

attention_output Residual [batch seq hidden_size] What the attention adds to the residual stream

the module's own 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

Printout

What print(model) shows on jetmoe/jetmoe-8b: the native modules, standard names and every standard value with its layout.

JetMoeForCausalLM(
  (lm_head): Linear(in_features=2048, out_features=32000, bias=False)
  (generator): Generator(
    (streamer): Streamer()
  )
  (embed_tokens): Embedding(32000, 2048)
  (layers): ModuleList(
    (0-23): 24 x JetMoeDecoderLayer(
      (mlp): JetMoeMoE(
        (act_fn/activation): SiLUActivation()
        (input_linear): JetMoeParallelExperts()
        (down_proj/output_linear): JetMoeParallelExperts()
        (router): JetMoeTopKGating(
          (layer): Linear(in_features=2048, out_features=8, bias=False)
        )
        (router_logits) -> RouterLogits [batch seq num_experts]: The router's logits, one per expert, before the scoring
        (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): Unavailable: JetMoE's mixture runs its experts over the slots sorted by expert; no tensor holds them in token order
        (routed_output) -> Residual [batch seq hidden_size]: The routed experts' combined output, before the mixture's bias
        (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
        (shared_expert_output) -> Residual [batch seq hidden_size]: The shared expert's output
        (mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
      )
      (input_layernorm): JetMoeRMSNorm((2048,), eps=1e-06)
      (post_attention_layernorm): JetMoeRMSNorm((2048,), eps=1e-06)
      (self_attn/self_attention): JetMoeAttention(
        (experts): JetMoeMoA(
          (input_linear): JetMoeParallelExperts()
          (down_proj/output_linear): JetMoeParallelExperts()
          (router): JetMoeTopKGating(
            (layer): Linear(in_features=2048, out_features=8, bias=False)
          )
        )
        (kv_proj): Linear(in_features=2048, out_features=4096, bias=False)
        (attention_premix): Unavailable: a mixture of attention heads: the output projection is per expert, inside experts
        (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_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
        (attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
        (attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
        (interface): The attention function this call ran, as f(queries, keys, values) -> (head outputs, pattern), with the rest of the call's arguments
      )
      (layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
      (attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
      (layer_mid) -> Residual [batch seq hidden_size]: The residual stream after the attention add
      (mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP
      (mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
      (layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
    )
  )
  (norm): JetMoeRMSNorm((2048,), eps=1e-05)
  (logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
  (token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
  (final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
  (lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
  (next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
  (input_ids) -> Tokens [batch seq]: The token ids the model was called with
  (attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
  (input_size): [batch, seq] of the current call; read-only
)

Config

model.num_layers24
model.hidden_size2048
model.num_heads32
model.num_kv_heads16
model.head_dim128
model.qk_head_dim128
model.vocab_size32000
model.intermediate_size5632
architecturesJetMoEForCausalLM
num_hidden_layers24
hidden_size2048
intermediate_size5632
num_attention_heads32
num_key_value_heads16
vocab_size32000
max_position_embeddings4096
rms_norm_eps1e-05
tie_word_embeddingsTrue
n_positions4096
activation_functionsilu
layer_norm_epsilon1e-05
num_experts_per_tok2
num_local_experts8
kv_channels128

The Notes

03 · what to know before you run

A query head is a routing slot, not an expert

Each chosen attention expert projects the token's queries for num_kv_heads heads, so query head h belongs to slot h // num_kv_heads, and the expert behind it changes from token to token. nnterp serves no routing values for the attention. Its router logits are self_attn.experts.router.layer.output, flat over tokens, and their top top_k give each slot's expert in order. To ablate attention expert e, zero attention_head_outputs in the slots that chose it.

attention_keys holds one copy of the keys per slot

The shared keys and values are tiled to every query head, so attention_keys and attention_values have num_heads heads, top_k copies of num_kv_heads. An edit to one head reaches only its slot's queries. Edit key/value head j at every copy (j, j + num_kv_heads), or at kv_proj.output, to reach every query that reads it.

Both mixtures add a bias after the experts

mlp_output is routed_output plus the mixture's bias, and attention_output is the experts' gated sum plus self_attn.experts.bias. Ablating every expert leaves the bias in the stream.

From the family module

04 · nnterp/families/jetmoe.py

JetMoE (JetMoeForCausalLM).

Llama's tree with the attention under its own name: model.{embed_tokens, layers[i].{input_layernorm, self_attention, post_attention_layernorm, mlp}, norm} and lm_head, the residual added in the block, which returns a bare tensor. self_attention is aliased self_attn.

The attention is a mixture of attention heads: a router picks num_experts_per_tok experts per token, each expert projects that token's queries for num_key_value_heads heads (experts.map) and later projects their outputs back (experts.reduce, in place of an o_proj). Keys and values come from one shared kv_proj and are tiled (repeat, not interleaved) to every query head before the shared attention interface, so the interface sees num_heads key/value heads and interface head h is routing slot h // num_kv_heads over kv head h % num_kv_heads: which expert's parameters a head's query came from varies by token. The attention returns (attn_output, attn_weights, router_logits). The MLP is a mixture of experts (Moe) that returns the routed hidden states plus a bias as one tensor.

The MLP's mixture has no experts module: its router (JetMoeTopKGating) takes a top-k of the logits of a child nn.Linear (router.layer), softmaxes the top-k, and sorts the slots by expert; the mixture then runs input_linear and output_linear over the sorted slots. So expert_indices and expert_weights are the router's top-k indices and gates, [tokens, top_k] in token order, before the sort; routed_output is the mixture's routed sum before + bias; and the per-slot outputs, sorted by expert, are unavailable.