AIARTICLE

4 min read

Qwen4-35B-A3B runs locally with sparse MoE and 1M token context: what changes for those building RAG and agents

Qwen4-35B-A3B runs locally with sparse MoE and 1M token context: what changes for those building RAG and agents
Image: Alan Andrade
Article · AI
Reading
4 min
Tables
1
Code
1
In short

Alibaba launched Qwen4-35B-A3B on December 4, a multimodal mixture-of-experts model with 1M token context and day-zero support in transformers, llama.cpp, and vLLM. The pitch: cutting-edge intelligence running locally, without API vendor lock-in.

Alibaba, through the Qwen Team, published Qwen4-35B-A3B on Hugging Face on December 4, 2026, a multimodal mixture-of-experts (MoE) model with day-zero support in transformers, llama.cpp, vLLM, SGLang, MLX, and the platform's own Inference Endpoints. The announcement, published on Hugging Face's official blog, draws attention for a detail that matters directly to product builders: the model was designed to run on-device, with GGUF and OMLX quantizations ready for laptops and even Apple Silicon.

For those building RAG and agents today dependent on paid APIs (OpenAI, Anthropic, Google), the natural question is whether Qwen4 is already a viable piece for removing that dependency from the picture. The short answer: partly yes, but with real technical trade-offs worth understanding before swapping the stack.

Architecture: why it's lightweight despite being large

Qwen4-35B-A3B has about 35 billion primary parameters, but only activates ~3.8 billion per token, thanks to the MoE with 256 routed experts. Add to that ~20.5 billion parameters in a per-layer embeddings (PLE) table, and the total reaches ~56B, but the computational cost per token stays close to that of a much smaller model.

The text decoder architecture repeats a four-layer pattern ten times: three layers use Gated DeltaNet, which updates a fixed-size memory for each token read, and the fourth uses Qwen Sparse Attention (QSA), which lets the current token look at specific tokens anywhere in the context. An indexer groups tokens into blocks of four, averages the keys, and for each query selects up to 512 groups, giving access to up to 2,048 selected tokens.

This matters in practice because it's what sustains the native 1M token context window without blowing up the cost of full dense attention. For RAG, this changes the calculation: instead of aggressively chunking documents and depending on a precise retriever, you can throw a much larger volume of raw context directly into the prompt and let the model filter internally.

What changes for those running RAG and agents without an API

The model ships with checkpoints in BF16, FP8, and GGUF and OMLX quantizations, covering everything from GPU servers to laptops with Apple Silicon. The license is Apache-2.0, without the commercial restrictions that weigh on other open models.

In llama.cpp, the serve command is straightforward:

llama serve -hf ggml-org/Qwen4-35B-A3B-GGUF:Q6_K

Hugging Face reports that speculative decoding via Multi-Token Prediction (MTP), enabled with --spec-type draft-mtp --spec-draft-n-max 3, increased generation speed by 22% running on an Apple Silicon M5 with Q4 quantization. That's the kind of number that matters for anyone thinking about running a local agent: the difference between a usable prototype and one that stalls on every response.

On server infrastructure, the published throughput numbers are more robust:

SetupTokens/s (single request)Time to first tokenThroughput (64 reqs)
vLLM, 1x H200 141GB~330~90 ms~2,660 tokens/s
SGLang, same config~260~80 ms~2,180 tokens/s

These numbers come from Hugging Face's own benchmarks, with MTP speculative decoding enabled and tool calling turned on. For an agent making several tool calls in sequence, the 80-90ms latency to first token is competitive with commercial APIs, though a fair comparison would require measuring the same workload on both sides, which the material doesn't provide.

Native multimodality and tool calling

Qwen4-35B-A3B accepts text, image, and video as native input, with text output. A vision transformer processes images in 16x16 patches, merging 2x2 groups into one visual token; video is sampled at 2 frames per second. This opens room for agents that need to interpret screenshots, error prints, or screen recordings, without needing a separate OCR pipeline or another vision model.

Tool calling is natively supported via transformers, just by passing a list of Python functions decorated as tools at generation time. In Hugging Face's own example, a get_current_temperature function is dispatched automatically when the model decides it needs the information. For those who already build agents with function calling from OpenAI or Anthropic, the interface migration is straightforward; what changes is the orchestrator behind it, which becomes local.

The model also has a reasoning_effort control with four levels (xhigh, high, low, off), adjustable per request via chat_template_kwargs. This gives a computational cost control that normally only exists in closed models like GPT-5 with its reasoning levels, but here running on hardware you control.

Where lock-in really breaks, and where it doesn't yet

In summary: swapping an API for a local model solves third-party dependency, but doesn't solve operations. Running a 56B total MoE, even with only 3.8B active per token, still requires a decent GPU or plenty of unified RAM on a Mac; it's not a model that runs trivially on any corporate laptop. The promise of

Translated from the Brazilian Portuguese original · Read the original

View profile →