# Welcome Qwen 4: Cutting-edge intelligence on-device

> Source: <https://huggingface.co/blog/qwen4>
> Published: 2026-12-04 00:00:00+00:00

**Key takeaway:** Qwen4-35B-A3B activates only ~3.8B of its ~35B main parameters per token and ships day-0 in transformers, llama.cpp, vLLM, SGLang, and MLX with BF16, FP8, OMLX, and GGUF checkpoints, so developers can run a 1M-token multimodal MoE locally or via Inference Endpoints.

[Image-Text-to-Text •  57B • Updated   •  12  •  108](https://huggingface.co/Qwen/Qwen4-35B-A3B)  

# 
		Welcome Qwen 4: Cutting-edge intelligence on-device
	

 [Update on GitHub](https://github.com/huggingface/blog/blob/main/qwen4.md)

[**Qwen4-35B-A3B**](https://huggingface.co/Qwen/Qwen4-35B-A3B/) by the Alibaba Qwen Team is out on Hugging Face!

Following the architectural preview in Qwen3.8-Flash-Next, **Qwen4-35B-A3B** brings Qwen's full next-generation hybrid design into production. It is a natively multimodal Mixture-of-Experts (MoE) model with **~35B main parameters and ~3.8B active parameters per token** and **~20.5B Per-Layer N-gram Embedding (PLE) parameters** (~56B total). It supports native **text, image, and video** inputs, a **1M token context window**, and is licensed under **Apache-2.0**.

We collaborated with the Qwen Team to ship day-0 support across transformers, llama.cpp, Llama App, vLLM, SGLang, MLX, Inference Providers, and Inference Endpoints. This post walks through the salient features of the architecture, how to run it, and how to fine-tune it for your own tasks.

**TL;DR**

- **Architecture:** Multimodal MoE with 256 routed experts, ~35B parameters with ~3.8B active, plus ~20.5B per-layer n-gram embeddings.
- **Modalities & Context:** Native text, image, and video inputs → text output, with a 1M token native context window.
- **Checkpoints:** BF16, FP8, OMLX, GGUF quantized versions
- **Inference:** Multi-Token Prediction (MTP) drafter for GGUF and OMLX, adjustable reasoning_effort levels ("xhigh", "high", "low", "off").
- **Day-0 Ecosystem support:** transformers, llama.cpp / Llama App, vLLM, SGLang, TRL, Inference Providers, and Inference Endpoints.

## 
		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:

``` python
from transformers import pipeline

pipe = pipeline("image-text-to-text", model="Qwen/Qwen4-35B-A3B", processor="huggingface/Qwen4-35B-A3B-processor", device_map="auto")

messages = [{"role": "user", "content": "Who are you?"}]
outputs = pipe(messages, max_new_tokens=2048, return_full_text=False)
print(outputs[0]["generated_text"])
```

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.

``` python
from transformers import AutoModelForMultimodalLM, AutoProcessor

model_id = "Qwen/Qwen4-35B-A3B"

processor = AutoProcessor.from_pretrained("huggingface/Qwen4-35B-A3B-processor")
model = AutoModelForMultimodalLM.from_pretrained(
    model_id,
    device_map="auto"
)

messages = [{"role": "user", "content": "Who are you?"}]
inputs = processor.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=True,
    return_dict=True,
    return_tensors="pt",
    reasoning_effort="off", # "xhigh", "high", "low", or "off
).to(model.device)

outputs = model.generate(**inputs, max_new_tokens=512)
print(processor.batch_decode(outputs, skip_special_tokens=True))
```

#### 
**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.

``` python
from transformers import AutoModelForMultimodalLM, AutoProcessor

model_id = "Qwen/Qwen4-35B-A3B"

processor = AutoProcessor.from_pretrained("huggingface/Qwen4-35B-A3B-processor")
model = AutoModelForMultimodalLM.from_pretrained(
    model_id,
    device_map="auto"
)
```

**Text-only inference**

```
messages = [
    {"role": "system", "content": "You should only answer with a number."},
    {"role": "user", "content": "What is 17 * 23?"},
]

inputs = processor.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=True,
    return_dict=True,
    return_tensors="pt",
    reasoning_effort="off", # "xhigh", "high", "low", or "off
).to(model.device)

outputs = model.generate(**inputs, max_new_tokens=512)
print(processor.batch_decode(outputs, skip_special_tokens=True))
```

**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`.

```
messages = [
    {
    "role": "user",
    "content": [
        {"type": "image", "image": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/llama.cpp/pills.jpg"},
        {"type": "text", "text": "Do the components of these drugs interact with each other?"},
    ],
    }
]

inputs = processor.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=True,
    return_dict=True,
    return_tensors="pt",
    reasoning_effort="off", 
).to(model.device)

outputs = model.generate(**inputs, max_new_tokens=512)
print(processor.batch_decode(outputs, skip_special_tokens=True))
```

**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.

```
messages = [
    {
        "role": "user",
        "content": [
            {"type": "video", "video": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/llama.cpp/pf.mp4"},
            {"type": "text", "text": "What is this video about?"},
        ],
    }
]

inputs = processor.apply_chat_template(
    messages,
    add_generation_prompt=True,
    tokenize=True,
    return_dict=True,
    return_tensors="pt",
    reasoning_effort="off",
).to(model.device)

outputs = model.generate(**inputs, max_new_tokens=512)
print(processor.batch_decode(outputs, skip_special_tokens=True))
```

**Tool calling**

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

``` python
def get_current_temperature(location: str, unit: str):
    """
    Get the current temperature at a location.

    Args:
        location: The location to get the temperature for, in the format "City, Country"
        unit: The unit to return the temperature in. (choices: ["celsius", "fahrenheit"])
    """
    return 22.0  # A real function would call a weather API here

messages = [{"role": "user", "content": "Hey, what's the temperature in Paris right now?"}]
inputs = processor.apply_chat_template(
    messages,
    tools=[get_current_temperature],
    add_generation_prompt=True,
    tokenize=True,
    return_dict=True,
    return_tensors="pt",
    reasoning_effort="off", 
).to(model.device)

outputs = model.generate(**inputs, max_new_tokens=512)
print(processor.batch_decode(outputs, skip_special_tokens=True))
```

### 
		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](https://huggingface.co/ggml-org/Qwen4-35B-A3B-GGUF).

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

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.

```
llama serve -hf ggml-org/Qwen4-35B-A3B-GGUF:Q4_K_M --spec-type draft-mtp --spec-draft-n-max 3
```

### 
		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](https://huggingface.co/mlx-community/Qwen4-35B-A3B-oQ4e) 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.

```
mlx_lm.generate --model mlx-community/Qwen4-35B-A3B-4bit-text \ 
  --prompt "Explain sparse attention like I am 5" \
  --max-tokens 4096
```

### 
		SGLang and vLLM
	

We recommend going to [SGLang docs](https://docs.sglang.io/cookbook/autoregressive/Qwen/Qwen4-35B-A3B) and [vLLM docs](https://recipes.vllm.ai/Qwen/Qwen4-35B-A3B)  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](https://huggingface.co/spaces/trl-lib/trl-recipes-qwen4#/harness-adapters/Qwen4-35B-A3B) to train a model that triages security alerts and cites the evidence behind each decision.

### 
		The pipeline
	

We will use [`AsyncGRPOTrainer`](https://huggingface.co/docs/trl/en/async_grpo_trainer) 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 `<your-org>` 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.

```
hf jobs run --name qwen4-alert-triage \
  --flavor h200x2 --timeout 3h \
  --secrets HF_TOKEN \
  --volume hf://Qwen/qwen4-35b-a3b:/model \
  --volume hf://datasets/burtenshaw/alert-triage:/triage \
  --volume 'hf://buckets/<your-org>/triage-runs:/outputs' \
  ghcr.io/openenv/qwen4-triage:latest \
  /opt/qwen4/train-triage /model /triage /outputs
```

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](https://huggingface.co/buckets/huggingface-projects/qwen-release-assets).

**Animation videos**

We asked Qwen to make an introduction video to [a speculative decoding benchmarking tool](https://github.com/merveenoyan/specbench/blob/main/README.md) 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](https://llama.app/docs/introduction)  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!
