Welcome Qwen 4: Cutting-edge intelligence on-device

Qwen 4‑35B‑A3B is a multimodal Mixture‑of‑Experts model with a 1 M‑token context, day‑0 support across major runtimes, and flexible inference options for text, images, and video.

Welcome Qwen 4: Cutting-edge intelligence on-device

Introduction

Qwen 4‑35B‑A3B marks the next step in Alibaba’s Qwen series, delivering a multimodal Mixture‑of‑Experts (MoE) architecture that can handle text, images, and video while maintaining a 1 million‑token context window. At roughly 35 B total parameters (3.8 B active per token) plus a massive per‑layer n‑gram embedding (PLE) component, the model offers high performance without the footprint of larger predecessors. Importantly, the release includes day‑0 integration with the major inference ecosystems—Transformers, llama.cpp, vLLM, SGLang, MLX, and Hugging Face Inference Endpoints—making it ready for production and research alike.

---

Core Architecture Highlights

  • Hybrid MoE design: 256 routed experts, with eight active experts per token and a shared expert, enable dynamic capacity allocation while keeping compute efficient.
  • Sparse attention (QSA): Tokens attend to up to 2,048 selected positions via a lightweight indexer, allowing long‑range dependencies without quadratic cost.
  • Per‑Layer N‑gram Embedding (PLE): A 20.5 B‑parameter table provides rich contextual cues; each token reads only 16 rows, keeping latency low.
  • Multimodal front‑end: A Vision Transformer processes images (16×16 patches merged into 2×2 visual tokens) and video (2 fps sampling, frame‑pair grouping) before feeding visual tokens to the text decoder.
  • Reasoning effort control: Four configurable levels ("xhigh", "high", "low", "off") let users trade off speed for depth of reasoning on a per‑request basis.

---

Getting Started with Inference

Transformers (Python)

```python from transformers import pipeline, AutoModelForMultimodalLM, AutoProcessor

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

msg = [{"role": "user", "content": "Who are you?"}] print(pipe(msg, maxnewtokens=2048, returnfulltext=False)[0]["generatedtext"]) ``` You can also load the model directly and set `reasoningeffort` via the processor: ```python model = AutoModelForMultimodalLM.frompretrained("Qwen/Qwen4-35B-A3B", devicemap="auto") processor = AutoProcessor.from_pretrained("huggingface/Qwen4-35B-A3B-processor")

inputs = processor.applychattemplate(messages, addgenerationprompt=True, tokenize=True, returntensors="pt", reasoningeffort="high").to(model.device) outputs = model.generate(**inputs, maxnewtokens=512) print(processor.batchdecode(outputs, skipspecial_tokens=True)) ```

Multimodal Examples

  • Text‑only: Simple arithmetic or factual queries.
  • Image + Text: Attach an image URL in the message payload; the model can answer visual questions.
  • Video + Text: Provide a video URL (requires `torchcodec`/`ffmpeg`); the model summarizes or describes content.
  • Tool calling: Define Python functions (e.g., a temperature lookup) and pass them via the `tools` argument; the model can invoke them during generation.

---

Running on Edge‑Optimized Runtimes

llama.cpp & Llama App

Quantized GGUF checkpoints (Q4KM, Q6K, Q80) are available. Example with speculative decoding (MTP): ```bash llama serve -hf ggml-org/Qwen4-35B-A3B-GGUF:Q6_K \ --spec-type draft-mtp --spec-draft-n-max 3 ``` On Apple Silicon M5, this yields ~22 % speed‑up over baseline.

MLX (Apple Silicon)

```bash mlxlm.generate --model mlx-community/Qwen4-35B-A3B-4bit-text \ --prompt "Explain sparse attention like I am 5" \ --max-tokens 4096 \ --chat-template-config '{"reasoningeffort": "low"}' ``` MLX leverages custom Metal kernels for QSA and gated residuals, with optional SSD offloading for the PLE table.

SGLang & vLLM

Both frameworks provide high‑throughput serving for Qwen 4. Consult their respective docs for optimal batch sizing and token‑parallel strategies.

---

Practical Tips for Production

  1. Choose the right quantization – Q4KM offers the smallest memory footprint, while Q6_K balances speed and accuracy for most workloads.
  2. Leverage reasoning effort – Set to `off` for latency‑critical tasks (e.g., simple lookups) and `xhigh` when deeper chain‑of‑thought reasoning is needed.
  3. Cache the PLE table – When using MLX or vLLM, offload the 20.5 B embedding table to fast local storage (NVMe/SSD) to avoid GPU memory pressure.
  4. Monitor token usage – The 1 M‑token context is powerful, but feeding excessively long histories can increase latency; prune older turns when possible.
  5. Combine modalities wisely – For mixed image‑text queries, batch images together to amortize Vision Transformer costs.

---

Closing Thoughts

Qwen 4‑35B‑A3B demonstrates that large‑scale multimodal models can be both high‑performing and accessible. With native support across the major inference stacks and flexible quantization paths, developers can integrate sophisticated language‑vision capabilities on everything from cloud GPUs to on‑device Apple Silicon. Whether you’re building a cyber‑defense assistant, a visual QA system, or a research prototype, Qwen 4 offers a solid foundation that balances raw power with practical deployment options.

Source

Read original source

Why we picked this

Announces a new on‑device large language model, a core AI development

← Back to all articles