Downloads · 30 days
13
18% of all-time downloads
FunPony/Qwen3.5-REAP-20B-A3B
Qwen3.5-REAP-20B-A3B is a text generation model from FunPony. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
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.
Downloads · 30 days
13
18% of all-time downloads
All-time downloads
71
Public
Parameters
18.5B
37.1 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors37.1 GB · 100%
From the Hugging Face model README
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
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.
main branch) — the qwen3_5_moe model type is not in any released version yetdevice_map="auto" for CPU offloading)Install transformers from main:
pip install git+https://github.com/huggingface/transformers.git@main
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
model_id = "atbender/Qwen3.5-REAP-20B-A3B"
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16, # Required — float16 causes NaN
device_map="auto",
trust_remote_code=True,
)
messages = [{"role": "user", "content": "Write a Python function to compute fibonacci numbers."}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer([text], return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512, do_sample=True, temperature=0.7, top_p=0.9)
print(tokenizer.decode(outputs[0][len(inputs.input_ids[0]):], skip_special_tokens=True))
Tested with vLLM v0.17.0rc1 (vllm/vllm-openai:cu130-nightly). Requires --enforce-eager due to hybrid attention.
vllm serve atbender/Qwen3.5-REAP-20B-A3B \
--dtype bfloat16 \
--trust-remote-code \
--enforce-eager \
--max-model-len 4096
| Parameter | Value | Why |
|---|---|---|
--dtype bfloat16 | Required | GDN linear attention overflows float16 |
--enforce-eager | Recommended | Avoids torch.compile issues with hybrid linear/full attention |
--trust-remote-code | Required | Qwen3.5 MoE uses custom model code |
For single GPU with limited VRAM:
vllm serve atbender/Qwen3.5-REAP-20B-A3B \
--dtype bfloat16 \
--trust-remote-code \
--enforce-eager \
--gpu-memory-utilization 0.85 \
--cpu-offload-gb 10 \
--max-model-len 2048
The pruning was done using this Docker image which has all dependencies pre-installed:
FROM modelscope-registry.cn-hangzhou.cr.aliyuncs.com/modelscope-repo/modelscope:ubuntu22.04-cuda12.9.1-py311-torch2.8.0-vllm0.11.0-modelscope1.32.0-swift3.11.3
RUN pip install --no-cache-dir \
git+https://github.com/huggingface/transformers.git@main \
git+https://github.com/huggingface/peft.git@main
Note: Both
transformersandpeftmust be installed frommain— the released versions don't supportqwen3_5_moeand have aHybridCacheimport error respectively.
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.
Saliency score per expert:
$$S_j = \frac{1}{|T_j|} \sum_{t \in T_j} g_{t,j} \cdot |e_{t,j}|_2$$
Where:
Unlike frequency-only pruning, REAP weighs each expert's contribution by both how often it's selected and how much it actually activates.
Changes Made:
gate_up_proj, down_proj) sliced along expert dimensionnum_experts_per_tok = 8) unchangedQwen3.5-35B-A3B uses a hybrid attention architecture distinct from previous Qwen models:
Qwen3_5MoeExperts with stacked tensors (gate_up_proj: [num_experts, 2*intermediate, hidden], down_proj: [num_experts, hidden, intermediate]), not individual nn.ModuleList entriesQwen3_5MoeTopKRouter returns (softmax_probs, normalized_topk_scores, topk_indices) — different from standard Qwen3 MoEFused 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, not model.config.text_config.num_experts (which applies to the multimodal ConditionalGeneration variant).
256 samples of 2,048 tokens from NeelNanda/pile-10k:
| Property | Value |
|---|---|
| Dataset | NeelNanda/pile-10k |
| Samples | 256 |
| Sequence Length | 2,048 |
| Seed | 42 |
| 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 |
qwen3_5_moe model type not in any released version yet@article{lasby2025reap,
title={REAP: Router-weighted Expert Activation Pruning for Scalable Mixture-of-Experts Compression},
author={Lasby, Mike and others},
year={2025},
url={https://github.com/CerebrasResearch/reap}
}
Apache License 2.0 — same as the base Qwen3.5-35B-A3B model.