CoolFace
Modelpublic

avlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
1likes166downloads
Model Card

Qwen3.5-35B-A3B — Dynamic 2/3-bit MLX (10 GB, Optimized for M4 Mini 16GB)

Part of the Qwen3.5-35B-A3B · Alis builds collection.
⚠️ This is a Text-Only model. Vision encoder is NOT included. For image/video understanding, use the VLM version: avlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw-VLM
Extreme dynamic quantization to run a 35B MoE model on 16GB Apple Silicon. Expert 2-bit + Attention/GDN 3-bit + Router bf16 strategy preserves quality while compressing to 10GB. Converted with mlx_lm, which excludes the vision encoder (text-only).

🚨 CRITICAL: 16GB Mac Users — Read This First

If you're running on a 16GB Mac (M4 Mini, MacBook Air, etc.), follow ALL of these steps or the model WILL crash with OOM:

1. Thinking Mode MUST be OFF

The model defaults to Thinking ON, which generates thousands of internal reasoning tokens and exhausts the 1.2 GB KV cache headroom.

bash
# Server mode — ALWAYS add this flag
python -m mlx_lm server \
    --model avlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw \
    --port 8888 \
    --chat-template-args '{"enable_thinking": false}'

# Generate mode — ALWAYS limit max-tokens
python -m mlx_lm generate \
    --model avlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw \
    --prompt 'Your prompt here' \
    --max-tokens 500

2. Close ALL Other Apps

16.0 GB total
- 3.5 GB  macOS + background services
- 11.3 GB model (peak)
= 1.2 GB  remaining for KV cache

Safari (1 tab) = -0.5 GB  → only 0.7 GB left
+ Slack/Discord = -0.3 GB → only 0.4 GB left → CRASH

Close Safari, Chrome, Slack, Discord, KakaoTalk, and any other apps before running.

3. Set Sampling Parameters

ParameterValueWhy
presence_penalty≥ 1.5Prevents infinite repetition loops → OOM
max_tokens≤ 2048Prevents KV cache overflow
temperature> 0 (use 0.7)Greedy decoding causes loops in quantized models

4. Recommended: Headless + SSH

The most stable setup is running headless (no monitor) with SSH access. This frees ~0.5 GB from WindowServer/display rendering.

bash
# From another machine
ssh your-mac "python -m mlx_lm server \
    --model ~/models/qwen35-dynamic-v3 \
    --port 8888 \
    --chat-template-args '{\"enable_thinking\": false}'"

Quick Checklist for 16GB

StepRequired
enable_thinking: false✅ MANDATORYPrevents 2000+ token internal reasoning
Close all apps✅ MANDATORYFrees 0.5-1.0 GB for KV cache
presence_penalty ≥ 1.5✅ MANDATORYPrevents infinite repetition loops
max_tokens ≤ 2048✅ MANDATORYPrevents KV cache overflow
temperature > 0✅ MANDATORYGreedy decoding causes loops
Headless + SSH💡 RecommendedFrees ~0.5 GB from display
💡 24GB+ users: These restrictions are much more relaxed. Thinking ON works fine with 24GB+.

Key Specs

ItemValue
Base ModelQwen/Qwen3.5-35B-A3B
Total Parameters35B (Active: 3B per token)
ArchitectureMoE 256 experts, top-8 routed + 1 shared
QuantizationDynamic mixed-precision (2/3/4-bit)
Average BPW2.579
Disk Size10 GB
Peak Memory11.3 GB
Target HardwareM4 Mac Mini 16GB
Inference Speed61 tok/s (M4 Mini) · 113 tok/s (M3 Ultra)
Korean Quality100% (20/20, no QLoRA needed)
Thinking ModeON/OFF switchable
FrameworkMLX 0.31.1, mlx-lm 0.31.2

Purpose

This model was built to run a 35B-class MoE language model on an Apple M4 Mac Mini with only 16GB unified memory.

Limitations of existing quantized models:

  • —Uniform 4-bit (~21GB): Doesn't fit in 16GB
  • —Uniform 3-bit (~14GB, peak 15.3GB): Barely fits but no room for KV cache
  • —Uniform 2-bit (~11GB): Complete quality collapse (gibberish output)

This model solves the problem through role-based dynamic quantization:

  • —Core pathways active every token (Attention, GatedDeltaNet) → protected at 3-bit
  • —Experts where only 8 of 256 are active per token → aggressively compressed to 2-bit
  • —Router and Norms → kept at bf16, never quantized

Result: 10GB model with 100% Korean quality, functional English/coding/reasoning.


Quantization Strategy

Per-Layer Bit Allocation

ComponentBitsRationale
MoE Router (mlp.gate)bf16Quantizing causes expert selection errors → hallucination. Never quantize.
Shared Expert Gate (shared_expert_gate)bf16Controls shared expert activation. Never quantize.
Norms (RMSNorm etc.)bf16Small tensors, quantization unnecessary
GDN Parameters (dt_bias, A_log, conv1d)bf16Core GatedDeltaNet parameters
Embedding (embed_tokens)3-bitToken mapping
LM Head (lm_head)3-bitOutput projection
Full Attention (self_attn, 10 layers)3-bitActive every token → quality-critical
Linear Attention / GDN (linear_attn, 30 layers)3-bitActive every token → verified: 2-bit causes repetition loops
Shared Expert (40 layers)3-bitAlways active
Routed Experts (switch_mlp, 40 × 256)2-bitOnly 8 of 256 active → 2-bit impact is distributed

Why 2-bit Works for Experts Only

This exploits a key property of MoE architecture:

  • —Only 8 of 256 experts activate per token (3.1% activation rate)
  • —Quantization error affects only 3.1% of pathways
  • —As long as the Router (bf16) correctly selects experts, slight errors in selected experts are tolerable
  • —In dense models, all parameters are active every token → 2-bit errors accumulate → collapse

Failed Approaches (Lessons Learned)

AttemptBPWSizeResultLesson
Uniform 2-bit2.5010.9GB❌ gibberishNo Router/Attn protection → total failure
mixed_2_63.1813GB⚠️ English switching, loopsSensitive layers at 6-bit → too large
mixed_3_43.67~15GB❌ Too largeDoesn't fit 16GB
Tight (linear_attn 2-bit)2.6411GB⚠️ Repetition loopsGatedDeltaNet requires 3-bit minimum
APEX v4 (edge protection)2.8211GB✅ Quality OKPeak 12.3GB → insufficient KV headroom
Dynamic v3 (this model)2.5810GB✅ PerfectOptimal balance

Usage

Installation

bash
pip install mlx-lm

Text Generation

bash
python -m mlx_lm generate \
    --model avlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw \
    --prompt 'What is the capital of South Korea?' \
    --max-tokens 200

Python API

python
from mlx_lm import load, generate

model, tokenizer = load("avlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw")

# Thinking OFF (for agents/API — answer only)
messages = [{"role": "user", "content": "Explain 5 traditional Korean foods."}]
formatted = tokenizer.apply_chat_template(
    messages, add_generation_prompt=True,
    enable_thinking=False, tokenize=False
)
response = generate(model, tokenizer, prompt=formatted, max_tokens=500)
print(response)

# Thinking ON (for complex reasoning)
formatted = tokenizer.apply_chat_template(
    messages, add_generation_prompt=True,
    enable_thinking=True, tokenize=False
)
response = generate(model, tokenizer, prompt=formatted, max_tokens=1000)
print(response)

API Server (OpenAI-Compatible)

bash
python -m mlx_lm server \
    --model avlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw \
    --port 8888 \
    --chat-template-args '{"enable_thinking": false}'
bash
curl http://localhost:8888/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "avlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw",
        "messages": [{"role": "user", "content": "Hello!"}],
        "max_tokens": 200
    }'

Recommended Settings (Based on Qwen Official)

Thinking OFF (Agents, General Chat, API Serving)

ParameterGeneral TextReasoning Tasks
temperature0.71.0
top_p0.80.95
top_k2020
min_p0.00.0
presence_penalty1.52.0
repetition_penalty1.01.0
max_tokens16,38432,768
enable_thinkingfalsefalse

Thinking ON (Math, Coding, Complex Reasoning)

ParameterGeneral ReasoningPrecise Coding (WebDev etc.)
temperature1.00.6
top_p0.950.95
top_k2020
min_p0.00.0
presence_penalty1.50.0
repetition_penalty1.01.0
max_tokens32,76832,768
enable_thinkingtruetrue

Special Notes for This 2.58 BPW Quantized Model

⚠️ This model uses extreme 2.58 BPW quantization. Repetition loops are slightly more likely than the original. Follow these recommendations:
  • —Always set `presence_penalty` to 1.5 or higher. Setting it to 0 may cause repetition loops.
  • —Never set `temperature` to 0. Greedy decoding causes quality degradation and repetitions in quantized models.
  • —For long outputs, set max_tokens sufficiently high (default 200 is too short).

Server Launch Example

bash
python -m mlx_lm server \
    --model avlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw \
    --port 8888 \
    --chat-template-args '{"enable_thinking": false}' \
    --temp 0.7 --top-p 0.8 --top-k 20

API Call Examples

bash
# Thinking OFF (Agent/General Chat)
curl http://localhost:8888/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "avlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw",
        "messages": [{"role": "user", "content": "Tell me about Korean traditional foods."}],
        "max_tokens": 2048,
        "temperature": 0.7,
        "top_p": 0.8,
        "presence_penalty": 1.5,
        "extra_body": {"top_k": 20},
        "chat_template_kwargs": {"enable_thinking": false}
    }'

# Thinking ON (Math/Reasoning)
curl http://localhost:8888/v1/chat/completions \
    -H "Content-Type: application/json" \
    -d '{
        "model": "avlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw",
        "messages": [{"role": "user", "content": "Calculate 12345 × 6789."}],
        "max_tokens": 32768,
        "temperature": 1.0,
        "top_p": 0.95,
        "presence_penalty": 1.5,
        "extra_body": {"top_k": 20},
        "chat_template_kwargs": {"enable_thinking": true}
    }'

⚠️ Important Notes

Memory Budget (M4 Mini 16GB)

Total Memory:        16.0 GB
- macOS Overhead:    -3.5 GB
- Model (peak):      -11.3 GB
= KV Cache Headroom:  1.2 GB

KV Cache and Context Length

Qwen3.5-35B-A3B's hybrid architecture makes KV cache extremely efficient:

  • —Full attention: Only 10 of 40 layers (remaining 30 are GatedDeltaNet)
  • —GQA KV heads: Only 2 (extremely low)
  • —4-bit KV per token: ~5 KB
  • —GatedDeltaNet state: ~33 MB (fixed, independent of context length)
KV Bits64K128K245K
4-bit0.31 GB ✅0.62 GB ✅1.2 GB ✅
2-bit0.16 GB ✅0.31 GB ✅0.62 GB ✅

For 128K+ context, use `--kv-bits 4` or `--kv-bits 2` with `mlx_lm generate`. Note: mlx_lm server does not currently support KV cache quantization.

Thinking Mode

  • —Default: Thinking ON (outputs internal reasoning process)
  • —For agents/API: Must set enable_thinking=False
  • —No quality degradation with Thinking OFF (Korean quality remains 100%)
  • —Thinking ON improves accuracy on complex math/reasoning problems

When NOT to Use This Model

  • —Image/Video understanding: ⚠️ No vision encoder (mlx_lm conversion excludes it). Use the VLM version.
  • —24GB+ Macs: Uniform 3-bit or 4-bit models provide better quality
  • —GPU servers: GPTQ/AWQ quantization is more suitable

Text-Only vs VLM Version Comparison

Text-Only (This Model)VLM Version
Model IDavlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpwavlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw-VLM
Size10 GB~10.8 GB
Peak Memory11.3 GB~12.1 GB
KV Headroom (16GB)1.2 GB (~245K ctx)~0.4 GB (~80K ctx)
Image Understanding❌✅
Librarymlx_lmmlx_vlm
Recommended ForAgents, coding, chatImage analysis, multimodal

Benchmarks

Korean Quality Test (M4 Mac Mini 16GB)

20 Korean prompts × Thinking OFF, max_tokens=200:

MetricResult
OK (correct Korean)20/20 (100%)
Foreign characters (JP/AR mixing)0/20 (0%)
Garbage output0/20 (0%)

Test prompts covered: capital city, traditional foods, kimchi recipe, Korean history, Seoul tourism, Hangul origins, seasonal weather, bulgogi recipe, economic industries, traditional medicine, education system, Jeju Island, IT industry, traditional music, holidays, bibimbap, healthcare system, Korean grammar, traditional architecture, K-pop global success.

Inference Speed

HardwarePrompt (tok/s)Generation (tok/s)Peak Memory
M4 Mac Mini 16GB (10 GPU cores)1146111.3 GB
M3 Ultra 512GB (80 GPU cores)15811311.3 GB

Quantization Profile Comparison (Same Hardware)

ProfileBPWSizePeakKoreanNotes
Uniform 2-bit2.5010.9GB11.0GB❌ gibberishUnusable
Dynamic v3 (this model)2.5810GB11.3GB✅ 100%Optimal
Tight (GDN 2-bit)2.6411GB11.6GB⚠️ Repetition loopsGDN needs 3-bit
Dynamic (L0-7 boost)2.8111GB12.3GB✅ 100%Insufficient KV headroom
Uniform 3-bit3.5014GB15.3GB✅ PerfectExceeds 16GB

lm-eval Benchmarks (0-shot)

Benchmark3-bit (3.50bpw)**v3 (2.58bpw)**Loss
ARC-Challenge56.40%54.86%-1.54pp
ARC-Easy83.33%82.58%-0.75pp
HellaSwag58.54%54.19%-4.35pp
TruthfulQA MC250.98%49.27%-1.71pp
Winogrande71.98%65.82%-6.16pp
Average64.25%61.34%-2.90pp

2.9pp average loss for 29% size reduction (14→10GB). 3-bit doesn't fit 16GB — v3 is the only working option.

Sensitivity Analysis

Per-layer relative error at 2-bit, measured on 8-domain calibration (Korean, English, code, reasoning):

Component2-bit Errorv3 BitsVerdict
Router0.5059bf16✅ Most sensitive
GDN in_proj0.4616-0.47703-bit✅ High sensitivity
Attention q/k/v/o0.4156-0.43693-bit✅ Medium sensitivity
Expert gate_up0.40152-bit✅ Most robust
Expert down0.39712-bit✅ Most robust

Expert layers are 6.5% more robust than attention layers (MoQE, Kim 2023). Edge vs middle layers: ratio = 1.00x → APEX edge protection unnecessary.


Reproducing the Quantization

Uses mlx-lm's custom quant_predicate API:

python
from mlx_lm.convert import convert
import re

def qwen35_v3(layer_path, layer):
    # Router: bf16 (never quantize)
    if layer_path.endswith("mlp.gate"):
        return False
    if "shared_expert_gate" in layer_path:
        return False
    # Norms: bf16
    if "norm" in layer_path and "proj" not in layer_path:
        return False
    # GDN parameters: bf16
    if any(x in layer_path for x in ["dt_bias", "A_log", "conv1d"]):
        return False
    # Embed/lm_head: 3-bit
    if "embed_tokens" in layer_path or "lm_head" in layer_path:
        return {"bits": 3, "group_size": 64}
    # Shared expert: 3-bit
    if "shared_expert" in layer_path:
        return {"bits": 3, "group_size": 64}
    # Full attention: 3-bit
    if "self_attn" in layer_path:
        return {"bits": 3, "group_size": 64}
    # Linear attention (GatedDeltaNet): 3-bit
    if "linear_attn" in layer_path:
        return {"bits": 3, "group_size": 64}
    # Routed experts: 2-bit (primary compression target)
    if "switch_mlp" in layer_path:
        return {"bits": 2, "group_size": 64}
    # Everything else: 2-bit
    if hasattr(layer, "to_quantized"):
        return {"bits": 2, "group_size": 64}
    return False

convert(
    hf_path="Qwen/Qwen3.5-35B-A3B",
    mlx_path="./qwen35-dynamic-v3",
    quantize=True,
    quant_predicate=qwen35_v3,
)
# [INFO] Quantized model with 2.579 bits per weight.

Project Background

This model is the successor to the Gemma 4 26B MoE extreme quantization project.

The Gemma4 project achieved 11GB at 92% Korean quality with OptiQ B++++ strategy, but failed to deploy on M4 Mac Mini due to an MLX bug where the 128-expert gather_mm Metal kernel malfunctions on M4 base (10 GPU cores).

Reasons for switching to Qwen3.5:

  1. 1.M4 Compatibility: 256 experts but different MLX implementation — works on M4 base
  2. 2.KV Cache Efficiency: GQA 2 heads + GatedDeltaNet hybrid → 24x more efficient than Gemma4
  3. 3.Korean Quality: 201 language support, 100% OK without QLoRA

Gemma4 vs Qwen3.5 Comparison

Gemma4 26B OptiQ**Qwen3.5 35B Dynamic v3**
M4 Mini 16GB❌ MLX bug✅ Working
Model Size11.0 GB10 GB
Parameters26B (3.8B active)35B (3B active)
Korean92% (after LoRA)100% (no LoRA)
Context74K (4-bit KV)245K (4-bit KV)
KV Efficiency122 KB/token5 KB/token (24x)
Vision✅❌ (excluded by mlx_lm)

Build Environment

  • —Quantization: M3 Ultra Mac Studio 512GB
  • —Deployment/Validation: M4 Mac Mini 16GB (macOS 26.3.1)
  • —Framework: MLX 0.31.1, mlx-lm 0.31.2
  • —Date: April 11, 2026
  • —Author: @avlp12 + Claude Opus

License

This model inherits the Apache License 2.0 from the original Qwen3.5-35B-A3B.

Citation

bibtex
@misc{qwen35-dynamic-v3-2026,
  title   = {Qwen3.5-35B-A3B Dynamic v3: 2.58 BPW Mixed-Precision for 16GB Apple Silicon},
  author  = {avlp12},
  year    = {2026},
  url     = {https://huggingface.co/avlp12/Qwen3.5-35B-A3B-Alis-MLX-Dynamic-2.6bpw},
  note    = {Expert 2-bit + Attention/GDN 3-bit + Router bf16 dynamic quantization}
}

Acknowledgments

  • —Qwen Team — Qwen3.5 model and Apache 2.0 license
  • —Apple MLX Team — MLX framework and quant_predicate API
  • —APEX-Quant — Inspiration for layer-wise precision gradient strategy
  • —Unsloth — Dynamic 2.0 quantization benchmarks and GGUF reference data