Rúben GalvãoThe Rabbit Hole

The Rabbit Hole / AI / Model architectures

Microsoft · Architecture map

Phi-3.5-MoE

A 16-expert, top-2 mixture of experts that keeps LayerNorm and puts bias terms on its attention and output head.

Phi-3.5-MoE-instruct, August 2024 · Phi release timeline

Inside Phi-3.5-MoE

Parameters
42B · 6.6B active
Layers
32
Width
4,096
Mixer
Grouped-query
Select a component to explore it.
The complete Phi-3.5-MoE architectureInput IDs select embeddings. Each layer adds its updates along the residual stream. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling. Keys and values for 8 heads, 128 values each, per token per layer. Final normalisation and output weights produce vocabulary scores and the next-token distribution.Text becomes token IDs.Text → tokens → IDstheoldrabbitsleepsEmbedding lookup32,0644,096Input token vectorsCL4,096Transformer layers 1–32Transformer layers 1–32 · 32 repetitions32 layers · one layer shown32LayerNorm before this operation.LayerNormGrouped-query attention: 16 experts, 2 selected per token (expert hidden size 6400). The router is SparseMixer, with input jitter noise during training.Grouped-queryattentionRotate query and key position components before attention scores; values are unchanged. 16 experts, 2 selected per token (expert hidden size 6400). The router is SparseMixer, with input jitter noise during training.RoPE32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.Attention biasAdd the branch output to the original stream. +LayerNorm before this operation.LayerNormMoE: 16 experts, 2 selected per token (expert hidden size 6400). The router is SparseMixer, with input jitter noise during training.MoE2 of 16 routed experts selected per token. Highlighted boxes are schematic; boxes do not correspond one-to-one to experts.Add the branch output to the original stream. +2 of 16 expertsResidual streamLast columnCL4,096Final LayerNormA separate learned vocabulary projection.Output weights4,09632,064Vocabulary scoresSoftmax32,064Next-token probabilities
Inside grouped-query attention · Transformer layers 1–32
4 query heads per group × 8 K/V groups.

Earlier context dimmed · current token bright · dashed regions contain cached entries.

Phi-3.5-MoE: Transformer layers 1–32 · grouped-query attention32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling. Keys and values for 8 heads, 128 values each, per token per layer.8 KV groups; the front face shows one representative.8 KV groups4 heads / group; the front face shows one representative.4 heads / groupAttention input. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.Earlier context is dimmed; outlined columns are current.Current token computation.Attention input4,096CLWq. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.Wq + b4,096128Wk. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.Wk + b4,096128Wv. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.Wv + b4,096128RoPE. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.RoPERoPE. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.RoPEK cache. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.Earlier columns are cached; outlined columns are newly computed.Cached positions from earlier decoding steps.Current token computation.K cache128CLV cache. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.Earlier columns are cached; outlined columns are newly computed.Cached positions from earlier decoding steps.Current token computation.V cache128CLQ context. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.Earlier context is dimmed; outlined columns are current.Current token computation.Q context128CLScaled query–key scores, masking and softmax. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.CLCL×. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.×Joined heads. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.32Wo. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.Wo4,0964,096Attention output. 32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.Earlier context is dimmed; outlined columns are current.Current token computation.Attention output4,096CL
Model-specific details
Transformer layers 1–32 · 32 repetitions
16 experts, 2 selected per token (expert hidden size 6400). The router is SparseMixer, with input jitter noise during training.
Attention and positions
32 query heads share 8 key/value heads, with bias terms on the projections; causal attention over up to 131,072 tokens using LongRoPE scaling.
Memory
Keys and values for 8 heads, 128 values each, per token per layer.

Experts with SparseMixer routing

All 32 layers select two of 16 experts, without a shared expert. Attention uses 32 query heads and eight key/value heads.

The August 2024 Instruct model has about 42B parameters, 6.6B active. Its window setting equals the whole context.

Explore the components

Sources for this map