Qwen3 Architecture
Explore the Qwen 3.6‑35B model architecture
Qwen3.6-35B-A3B is a hybrid Mixture-of-Experts language model. 35 billion total parameters, but only 3 billion are active per token. 40 layers, 256 experts, 256K context window, multi-modal.
At a glance:
| Parameter | Value |
|---|---|
| Total params | ~35B |
| Active per token | ~3B |
| Hidden dim | 2048 |
| Layers | 40 (30 GDN + 10 Full) |
| Q heads / KV heads | 16 / 2 (GQA 8:1) |
| Total experts | 256 (8 active) |
| Context | 262K tokens |
| Vocab | 248,320 |
The model never sees text — it sees integers.
BPE Tokenizer splits input into subword tokens from a vocabulary of 248,320. That's massive — GPT-2 had 50K. This large vocabulary handles 119 languages and includes special tokens for images (248053–248057) and video.
Embedding Lookup maps each token ID to a 2048-dimensional vector. The lookup table is 248,320 × 2048 — 509 million parameters just for the input embedding. It's untied from the output embedding, so the LM head is another 509M.
mRoPE — Multi-resolution Rotary Position Embedding — adds position information. Only 25% of each head dimension (64 of 256) receives rotary encoding. The remaining 192 dims stay position-free, encoding pure content. The three sections [11, 11, 10] encode temporal (T), height (H), and width (W) — this is 3D position encoding, built for multi-modal input where visual tokens have spatial and temporal positions.
💡 This stage is covered in detail in Ep07 (Tokenization & Embeddings) and Ep08 (Positional Embeddings).
This is where the computation happens. 40 identical blocks, each with two sub-blocks:
RMSNorm → Attention Mixer → +residual → RMSNorm → MoE FFN → +residual
Two residual connections preserve gradient flow. Pre-LN (LayerNorm before each sub-block) for training stability.
The attention type varies by layer index:
O(n) time, O(1) memoryThis hybrid design is the key architectural innovation. Full attention is O(n²) — prohibitive for 256K context on all 40 layers. Gated DeltaNet handles local-to-medium-range context efficiently via a recurrent state update, while the 10 full-attention layers provide unrestricted global token mixing.
Uses Grouped Query Attention with 16 query heads and only 2 key-value heads — an 8:1 compression that cuts KV cache memory by 8×. Head dimension is 256 (double the typical 128) for more expressive attention per head.
The Q projection is special — it outputs double the expected size. The first half is the actual query; the second half becomes an element-wise gate applied after attention:
attn_output = softmax(QK^T / √256) × V
attn_output = attn_output × sigmoid(gate) ← learned gating
QK-Norm applies RMSNorm per head before RoPE, preventing attention entropy collapse during training.
Not Mamba. Gated DeltaNet is a different linear attention mechanism using a gated delta rule recurrence:
S_t = (1-β)S_{t-1} + β v k^T, output o_t = S_t qResult: O(n) time and O(1) memory per layer — critical for 256K sequences.
Every layer has exactly the same MoE FFN structure, regardless of attention type.
Router: A learned linear layer 2048 → 256 scores all 256 experts for each token. Softmax, then top-8 are selected and their weights renormalized to sum to 1.
Experts: Each of the 256 experts is a tiny SwiGLU feed-forward network:
expert_e(x) = SiLU(x · W_gate_e) ⊙ (x · W_up_e) · W_down_e
Gate and up projections are merged into a single parameter tensor [256, 1024, 2048] for efficiency. Each expert has intermediate dimension 512 and output dimension 2048 — just 3.15M parameters per expert. Only 8 fire per token, so 25.2M active expert parameters out of 806M total.
Shared Expert: Same SwiGLU structure, but always active for every token. Controlled by a learned scalar gate: sigmoid(Linear(x, 1)) × shared(x). Handles common patterns so routed experts can specialize.
Load Balancing: An auxiliary loss (coefficient 0.001) penalizes uneven expert utilization, ensuring all 256 experts get used across the batch.
💡 The sparse MoE design is why 35B total params → only 3B active per token. The model has vast capacity but uses it selectively.
After the 40th transform block:
2048 → 248,320 — produces raw logits over the vocabulary. Untied from the input embedding: another 509M parameters.The Qwen3 technical report describes the predecessor (Qwen3-30B-A3B). Qwen3.6-35B-A3B introduces significant architectural evolution:
| Aspect | Qwen3-30B-A3B | Qwen3.6-35B-A3B |
|---|---|---|
| Total params | 30B | ~35B |
| Layers | 48 | 40 |
| Attention | Full only (48 layers) | Hybrid: 30 linear + 10 full |
| Total experts | 128 | 256 |
| Shared expert | ❌ Removed | ✅ Added back |
| Head dim | 128 (typical) | 256 |
| Context | 128K | 262K |
| RoPE | Standard | mRoPE 3D |
| MTP | ❌ | ✅ |
| Vision | ❌ | ✅ ViT encoder |
This overview covered the what — the architecture. Upcoming episodes will cover the how:
Open the interactive diagram and click through each box — the step-by-step annotations are your recording guide.
Explore the Qwen 3.6‑35B model architecture