AI Trends

Qwen4-35B-A3B Released with a 1M-Token Context Window and Multimodal Capabilities for On-Device Use

Hugging FaceUpdated Dec 4 10:55

AI summary

Qwen4-35B-A3B is a multimodal MoE model supporting images, video, and text, with a 1M-token context window. The model received day-0 support from transformers, llama.cpp, vLLM, SGLang, Inference Providers, and Inference Endpoints, and is available in Q4_K_M 4-bit, Q6_K 6-bit, and Q8_0 8-bit quantized versions. With MTP speculative decoding enabled and 3 draft tokens, its Q4 quantized version achieved a 22% increase in generation speed on Apple Silicon M5.

Why read this

SelectedAI score 86

The article details sparse attention, multiple residual streams, quantization, and multi-backend support, facilitating evaluation of the model's long-context capabilities and local deployment options.

Topics

Tags

Body

What is new with Qwen4?

Qwen4-35B-A3B is a multimodal mixture-of-experts model with 1M-token context window. The text decoder repeats the same four-layer pattern ten times. The first three layers use Gated DeltaNet, which updates a fixed-size memory as it reads each token. The fourth uses Qwen Sparse Attention (QSA), which lets the current token look back at individual tokens from anywhere in the context. To decide where to look, a small indexer groups tokens in groups of four tokens and averages their keys. For each query, it picks up to 512 groups. The attention layer then reads the individual tokens in those groups, plus any tokens in the last unfinished group. That gives it up to 2,048 selected tokens and at most three more at the end.

Qwen4-35B-A3B also changes how information moves between layers. Each token starts with four copies of its 2,048-dimensional embedding. These become four residual streams. Before each attention or MoE block, learned gates mix the streams into a single input. The eight selected experts and the shared expert process that input and produce one combined output. Each stream then adds a scaled copy of that same output to its own state. A learned gate sets the scale separately for each stream. One of the biggest pieces of the model sits in the second decoder layer. This layer has a per-layer embedding table (PLE), which consists of 20.5B parameters. Each token reads just 16 rows of the PLE table. Eight lookups encode the last two tokens and the other eight lookups encode the last three tokens (the current token and two tokens immediately before that). The layer joins those 16 embeddings into one, gates their contribution to each residual stream, and uses a short convolution to mix in nearby patterns.

The model employs a vision transformer to encode images and video. The ViT reads images into 16 × 16 patches and merges each 2 × 2 group of spatial patches into one visual token, which is passed to the text decoder. For video, the processor samples 2 frames per second and groups consecutive sampled frames into pairs. The vision transformer then lets every patch attend to every other patch within that frame pair.

Benchmark Results

Qwen team has published the model benchmarks in the model card, we have picked community favorites across different tasks below. Qwen4-35B-A3B punches way above its size and class across various benchmarks. For example, it is comparable to the much larger Qwen 3.8 Flash Next, or even better in some tasks. For example, it is comparable to the much larger Qwen 3.8 Flash Next, or even better in some tasks.

Inference Support

Qwen4-35B-A3B ships with day-0 support in transformers, llama.cpp, vLLM, SGLang, Inference Providers, and Inference Endpoints.

Transformers

The quickest way to run the model is the any-to-any pipeline:

Going one level lower, you can load the model and processor with the auto classes, AutoModelForMultimodalLM and AutoProcessor . You can control reasoning effort directly, it takes four values ( "xhigh" , "high" , "low" , or "off” ) and defaults to high if no value is provided.

Inference with different modalities

In the following sections we will showcase how to run inference on different modalities. A common setup for all the sections will be to load the model and the processor.

Text-only inference

Images and text

To run inference with image and text you can simply add images to the messages and pass them to apply_chat_template .

Video inference

Similarly, you can also add videos to the messages and pass them to apply_chat_template . Note that you need to have torchcodec and ffmpeg installed.

Tool calling

We can also provide tools that the model can use to solve the request. This is how you would do it.

llama.cpp

Qwen4-35B-A3B comes with day-0 llama.cpp and Llama App support. We ship 3 quantized versions to the Hub, specifically Q4_K_M 4-bit, Q6_K 6-bit and Q8_0 8-bit. You can find them in this GGUF repository .

MTP speculative decoding is supported out of the box. You simply need to enable it using the --spec-type and --spec-draft-n-max options. We got great results using 3 draft tokens: generation speed increased 22% on an Apple Silicon M5 with the Q4 quant.

MLX

Qwen4-35B-A3B runs on Apple Silicon with oMLX and mlx-lm.

oMLX uses custom Metal kernels for QSA and the gated residual. It also supports image input, MTP and PLE offloading to SSD, with oQ quants optimized for oMLX and mlx-lm.

mlx-lm support for the language model is on its way to the official repository. Pass --chat-template-config '{"reasoning_effort": "low"}' to change the reasoning effort.

SGLang and vLLM

We recommend going to SGLang docs and vLLM docs to see how to run the model effectively on their inference engine.

Reinforcement Learning of Qwen 4 for cyber defense with TRL

Use the Qwen4 harness-adapter recipe to train a model that triages security alerts and cites the evidence behind each decision.

The pipeline

We will use AsyncGRPOTrainer in TRL to train Qwen4-35B-A3B to label vulnerabilities and cite evidence from the code base.

First, we send a case to Qwen4 . Give it a sanitized alert and its evidence records. For example, in a case with repeated sign-in failures and incomplete device data, the analyst’s expected reply might be to escalate and cite events like “A17”.

Next, we sample and score replies . vLLM samples several replies for the same alert. Each reply earns a reward of 1 when its triage label and citations match the analyst’s criteria, and 0 otherwise.

Then we update the adapter. TRL’s asynchronous GRPO trainer uses the relative rewards within each group of replies to update the LoRA adapter.

Finally, we evaluate held-out incidents. Give the base model and saved adapters the same cases and decoding settings. Compare triage label accuracy, citation accuracy, and missed escalations.

Run the pipeline on Hugging Face Jobs

Use a two-GPU Job and a CUDA image with the trainer, vLLM, and the triage verifier. The bucket has a script that runs vLLM on one GPU and training on the other.

Sign in with hf auth login, then replace with the namespace of your writable triage-runs bucket. Jobs mounts the model and triage dataset as inputs and the bucket for rewards and checkpoints.

Use hf jobs logs JOB_ID to follow training and retrieve the saved checkpoints from the bucket.

Training reward and cyber evaluation

Each point shows the mean reward of the training rollouts scored at that logging step. The verifier rewards successful outcomes and adds a small bonus for using fewer tool calls. Use the held-out CyberDefense Bench results to help choose which checkpoint to keep.

On the same 12 held-out CyberDefense Bench tasks, the base model passed 4/12 , the update-50 adapter passed 6/12 , and the update-100 adapter passed 3/12 . The earlier checkpoint performed best on this sample, even as the overall training reward trended upward.

If you train your own adapter, share it on the hub!

Demos

We used Qwen4-35B-A3B with the Pi coding agent and paired it with some skills to see what it can do zero-shot.

All the html files and videos can be found here .

Animation videos

We asked Qwen to make an introduction video to a speculative decoding benchmarking tool we developed. It picked up frontend design skills from Google and web animation skills from Vercel and built an introductory video you can find below.

Slide Deck

We asked Qwen4-35B-A3B make a presentation with just this prompt “make an educational slide deck on how llama app and llama.cpp relates to each other, here's the docs use the similar branding on the website for the slide deck”

Qwen picked up the frontend-slides skill and asked us follow-up questions about density and audience, we asked it to build a slide deck for developers with high information density and it built the below slide deck.

Real-time scene generation

We asked Qwen4-35B-A3B to generate a scenery of a cinematic flight over mountains and clouds with no skills. You can find the prompt in the traces.

Wrapping Up

We are very glad to partner with the Qwen team to ship Qwen4-35B-A3B, a high-quality mid-sized model for local setups. We are excited to see what you can do with it, give it a try and let us know what you think in the comments!

Models mentioned in this article 2

Qwen/Qwen4-35B-A3B

ggml-org/Qwen4-35B-A3B-GGUF

More Articles from our Blog

Models mentioned in this article 2

Qwen/Qwen4-35B-A3B

ggml-org/Qwen4-35B-A3B-GGUF

Source

Hugging Face