Qwen3.5-REAP-20B-A3B is a Mixture of Experts (MoE) model created by applying Router-weighted Expert Activation Pruning (REAP) to Qwen/Qwen3.5-35B-A3B.
35B → 20B (REAP 50% prune) | ~3B active per token | BF16
Aspect
Original
Pruned (this model)
Model
Qwen/Qwen3.5-35B-A3B
Qwen3.5-REAP-20B-A3B
Total Parameters
~35B
~20B
Active Parameters
~3B
~3B
Experts per Layer
256
128
Experts Routed per Token
8
8
Shared Expert
1 per layer
1 per layer (preserved)
Hidden Layers
40
40
Layer Types
30 linear_attention + 10 full_attention
30 linear_attention + 10 full_attention
Hidden Size
2048
2048
MoE Intermediate Size
512
512
Context Length
262,144
262,144
Precision
BF16
BF16
Disk Size
~67 GB
~35 GB
Key Achievement: 35B → 20B total parameters | ~3B active per token | 50% expert pruning | Shared expert preserved
Important: dtype Must Be bfloat16
This model uses hybrid attention with GDN (Gated Delta Network) linear attention layers. These layers produce intermediate values that exceed float16's dynamic range (max 65504), causing NaN outputs. You must use torch_dtype=torch.bfloat16 (or --dtype bfloat16 in vLLM). The model will produce garbage output with float16.
How to Use
Requirements
transformers >= 5.x (from main branch) — the qwen3_5_moe model type is not in any released version yet
torch >= 2.4 with CUDA support
~35 GB disk + ~40 GB VRAM (or use device_map="auto" for CPU offloading)
Note: Both transformers and peft must be installed from main — the released versions don't support qwen3_5_moe and have a HybridCache import error respectively.
What Is REAP?
REAP (Router-weighted Expert Activation Pruning) is a pruning method from Cerebras Research that combines router gate statistics with expert activation norms to determine which experts to prune.
Attention layers (both linear and full), embeddings, and all non-MoE components untouched
Architecture Notes & Workarounds
Qwen3.5-35B-A3B uses a hybrid attention architecture distinct from previous Qwen models:
30 linear attention layers using GDN (Gated Delta Network) with conv1d kernels
10 full attention layers (standard multi-head attention with RoPE) at every 4th layer
Fused expert format: Experts are stored as Qwen3_5MoeExperts with stacked tensors (gate_up_proj: [num_experts, 2*intermediate, hidden], down_proj: [num_experts, hidden, intermediate]), not individual nn.ModuleList entries
Shared expert: Each MoE layer has a shared expert (always active) + shared expert gate
Custom router: Qwen3_5MoeTopKRouter returns (softmax_probs, normalized_topk_scores, topk_indices) — different from standard Qwen3 MoE
Workarounds applied during pruning
Fused expert detection: Standard REAP code assumes experts are nn.ModuleList. Qwen3.5 uses Qwen3_5MoeExperts with stacked tensors. Detection changed to check hasattr(module.experts, "gate_up_proj") instead of isinstance(module.experts, nn.ModuleList).
Manual expert computation for saliency: Since experts are fused, saliency collection manually computes each expert's output using F.linear(tokens, experts.gate_up_proj[j]) + F.linear(intermediate, experts.down_proj[j]) instead of calling individual expert modules.
Pruning via tensor slicing: Instead of removing modules from a list, pruning slices experts.gate_up_proj.data[keep_indices] and experts.down_proj.data[keep_indices] along the expert dimension, then updates experts.num_experts.
Config path: This is Qwen3_5MoeForCausalLM (text-only), so num_experts is at model.config.num_experts, notmodel.config.text_config.num_experts (which applies to the multimodal ConditionalGeneration variant).
Calibration Data
256 samples of 2,048 tokens from NeelNanda/pile-10k:
Property
Value
Dataset
NeelNanda/pile-10k
Samples
256
Sequence Length
2,048
Seed
42
Hardware & Runtime
Stage
Time
Hardware
Saliency collection (256 samples)
~8 min
1× NVIDIA RTX PRO 6000 Blackwell 98GB
Expert pruning
<1 sec
CPU
Model save
~2 min
SSD
Total pipeline
~10 min
Intended Use
Research on MoE pruning and compression techniques for Qwen3.5 hybrid attention models