On December 4, Alibaba's Qwen team published the first open-weight model of the Qwen 4 family: Qwen4-35B-A3B. It is a multimodal mixture-of-experts model with 35 billion total parameters, only about 3 billion active per token, a native context window of 1,048,576 tokens, and weights released under the Apache-2.0 licence. It accepts text, images, and video, and it ships with day-one support in llama.cpp, Ollama, vLLM, SGLang, Transformers, and MLX.

The headline number is the context window. A million tokens is roughly 750,000 words — an entire codebase, a shelf of documents, or an hour of video in a single conversation. Previous open models with that kind of reach needed a data-centre GPU to run. Qwen4-35B-A3B is designed to run on a single machine: the hybrid attention architecture (linear attention for most layers, sparse attention for the rest) keeps the memory footprint small enough that the 4-bit build runs on a 32 GB Mac, and a 3-bit build fits on 18 GB of RAM. That is the story of this release — frontier-class context on hardware people actually own.

This tutorial takes you from zero to a working local Qwen4: picking the right file for your machine, installing llama.cpp, chatting in the terminal, serving the model as an OpenAI-compatible API, the one-command Ollama route, sending it an image, and tuning its thinking effort. Every command below comes from the model card or the Hugging Face launch post, and the full workflow was verified end to end in a sandbox. One honest caveat: the smallest runnable build needs about 18 GB of RAM and a 21 GB download, and the sandbox has 7.7 GB of RAM — so the live runs used the same commands with a small Qwen3 model as a stand-in, and the Qwen4 steps are flagged wherever they are documented rather than run here. Nothing in this tutorial asks you to take a command on trust that the official docs do not also print.

What you'll need#

  • 18 GB of RAM minimum for the smallest 3-bit build, 32 GB for the recommended 4-bit build, or a GPU with 24 GB+ of VRAM. The table in Step 1 gives the exact numbers per file.
  • 21–60 GB of free disk, depending on the file you pick. The download is the slow part — budget real time for it.
  • macOS, Linux, or Windows. The llama.cpp route works on all three; Ollama and Docker Model Runner do too.
  • No account, no API key, no cloud. The weights are free under Apache-2.0. The only costs are disk space, bandwidth, and electricity.
  • Python 3.10+ and pip install openai for the API-client step. Everything before that is shell commands.

1. Pick your file#

Qwen4-35B-A3B ships as one model in several precisions. The headline parameter count needs a footnote: the 35 billion covers the main weights, and there are 20.5 billion more parameters in a per-layer n-gram embedding table (PLE) at layer 2, plus a 2 billion-parameter multi-token prediction (MTP) head — about 56 billion parameters in total on disk. The PLE table is the trick that makes the model work: each token reads just 16 rows of it, encoding the previous two and three tokens, so it adds quality without adding compute. It is also the reason the file sizes below look bigger than the "35B" name suggests.

The official GGUF builds live in ggml-org/Qwen4-35B-A3B-GGUF on Hugging Face. These are the numbers from that repo's README — file size, then the RAM the model actually occupies once loaded:

FileDownloadResident RAMWho it is for
Q4_K_M36.0 GB21.9 GBThe default. Best balance of size and quality; runs on a 32 GB Mac.
Q6_K51.0 GB29.2 GBCloser to the full model; runs on a 48 GB Mac.
Q8_059.4 GB37.6 GBNear-lossless; runs on a 64 GB Mac.
BF16111.1 GB70.1 GBServers and workstations only.

Resident RAM is much smaller than the download because of lazy loading. Under llama.cpp's default lazy mode, the 20 billion-parameter n-gram embedding table — 14.1 GB in Q4_K_M, 21.8 GB in Q6_K and Q8_0 — stays on disk and is read on demand instead of being loaded into memory. That is what makes a 36 GB file run in 22 GB of RAM. If your machine has less than 32 GB, use Unsloth's builds (unsloth/Qwen4-35B-A3B-GGUF) instead: their Engram feature keeps the n-gram table on SSD, and the 3-bit build runs on 18 GB of RAM.

Quality cost is measurable. The ggml-org README reports KL divergence against the BF16 model over 20 × 512 tokens: Q8_0 0.0359 (94.0% same top token), Q6_K 0.0479 (92.9%), Q4_K_M 0.1252 (87.9%). In practice: pick Q4_K_M unless you have a specific reason to go bigger — it is the build the Hugging Face launch post uses in its examples, and the quality gap to Q6_K is small next to the 15 GB you save. Also download the vision projector if you want image input later: mmproj-Qwen4-35B-A3B-BF16.gguf, 903 MB, in the same repo.

2. Install llama.cpp#

llama.cpp is the inference engine this tutorial uses for the terminal and server steps. It is a single binary — no Python environment, no dependencies — and the install is one command. On macOS or Linux:

curl -LsSf https://llama.app/install.sh | sh

On Windows (PowerShell):

winget install llama.cpp

Verify the install:

llama --version

The sandbox run printed version: 1.1.0-dev (build 12970, commit 2d4f84836), built with Clang 22.1.8. The install puts the binary in ~/.llama-app/; if your shell does not pick it up, run it as ~/.llama-app/llama or add that directory to your PATH. The binary provides two commands you will use throughout: llama cli for chatting in the terminal and llama serve for the API server.

3. Chat in the terminal#

The fastest way to meet the model is the terminal chat. This is the exact command from the Hugging Face launch post, using the 6-bit build:

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

The first run downloads the file — about 51 GB for Q6_K, 36 GB for Q4_K_M if you swap the name after the colon — then loads it and drops you at a prompt. Type a question and press Enter. To run a single prompt and exit, add -p and -n (max new tokens):

llama cli -hf ggml-org/Qwen4-35B-A3B-GGUF:Q6_K \
  -p "Write a Python function to merge two sorted linked lists." \
  -n 200 --no-display-prompt

The sandbox ran this exact shape with a small stand-in model (Qwen3-0.6B, Q8_0) because the full model does not fit the sandbox's memory. It loaded, thought out loud, and answered: prompt processing ran at 48–65 tokens per second and generation at 12.3 tokens per second on a 4-core CPU with no GPU. Expect the 35B model to be slower on CPU and dramatically faster with a GPU offloading the work — the point of the verification is that the commands, the flags, and the output format are exactly as printed here.

Two things to notice on your first run. First, the model thinks before it answers: you will see a [Start thinking] block before the reply. Thinking is on by default (Step 7 explains how to control it). Second, generation speed on CPU is usable but not fast — if you plan to use the model daily, the server in the next step with GPU offload, or the Ollama route in Step 5, is the better home for it.

Diagram of a local inference setup: a downloaded model file feeding a terminal chat and an API server on a laptop
AI-generated illustration: the local setup in this tutorial — one downloaded model file, a terminal chat, and an API server on your own machine.

4. Serve it as an OpenAI-compatible API#

A chat in the terminal is a demo; a server is a tool. llama serve turns the same model into a local HTTP server speaking the OpenAI chat-completions API, so every tool, script, and agent that talks to OpenAI can talk to your local Qwen4 by changing one URL. Start it:

llama serve -hf ggml-org/Qwen4-35B-A3B-GGUF:Q6_K -c 4096 --port 8080

The -c flag sets the context window for the server. The model natively supports 1,048,576 tokens, but the key-value cache for a million-token conversation needs far more memory than the weights alone — start at 4096 for a first run and raise it only when you know your machine's headroom. The server listens on http://127.0.0.1:8080 and serves only on localhost by default, so nothing leaves your machine.

Check what the server loaded:

curl http://127.0.0.1:8080/v1/models

Then send it a chat completion:

curl http://127.0.0.1:8080/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{"model": "ggml-org/Qwen4-35B-A3B-GGUF:Q6_K",
       "messages": [{"role": "user", "content": "Write a Python function to merge two sorted linked lists."}],
       "max_tokens": 512, "temperature": 1.0}'

Use the exact model id from the /v1/models response — llama.cpp reports the file or repo you loaded, and the id must match. The sandbox ran both calls against the small stand-in model. The models endpoint listed the loaded file, and the completions call returned a full OpenAI-shaped response: a reasoning_content field carrying the thinking trace, the answer in content, token usage, and timings (prompt 48.8 tokens/sec, generation 9.9 tokens/sec on this CPU).

One real gotcha surfaced in that test, and it is worth knowing before you build on the API: with max_tokens set to 64, the small model spent all 64 tokens thinking and returned an empty answer. Thinking consumes your token budget. For short answers, either set max_tokens generously (512 is a safe floor) or turn thinking off for that call, as Step 7 shows. The same call from Python, using the model card's own example:

from openai import OpenAI

client = OpenAI(base_url="http://127.0.0.1:8080/v1", api_key="local")

completion = client.chat.completions.create(
    model="ggml-org/Qwen4-35B-A3B-GGUF:Q6_K",
    messages=[{"role": "user", "content": "Write a Python function to merge two sorted linked lists."}],
    max_tokens=512,
)
print(completion.choices[0].message.content)

The local server does not validate the API key — "local" is a placeholder the client library requires. Point any OpenAI-compatible client at http://127.0.0.1:8080/v1 and it works the same way.

5. The one-command Ollama route#

If you would rather not manage files and flags, Ollama is the shortest path. Install it from ollama.com/download, then run the model with one command — this is the command from the model card, using Unsloth's 4-bit build:

ollama run hf.co/unsloth/Qwen4-35B-A3B-GGUF:UD-Q4_K_M

Ollama downloads the file on first run (about 35 GB for UD-Q4_K_M), then opens a chat. Swap the name after the colon for a different quant: UD-IQ3_XXS is the smallest, for 18 GB machines. Useful commands once it is running: ollama list shows downloaded models, ollama stop <model> unloads one, and ollama serve runs the background server that the ollama CLI talks to (it also exposes the same OpenAI-compatible API on port 11434).

Sandbox status: Ollama 0.40.21 installed and serving on this machine, and the run loop was verified end to end by importing a small Qwen3 GGUF locally (ollama create from a Modelfile, then ollama run, which answered 17 × 23 = 391 correctly). One caveat: the registry download itself — ollama pull qwen3:0.6b — timed out in this sandbox with a manifest-fetch error (context deadline exceeded reaching registry.ollama.ai), so the 35 GB Qwen4 download is the one step here that is documented from the model card rather than run live. The command is the model card's own; if the hf.co/ form ever fails on your install, the equivalent is ollama pull hf.co/unsloth/Qwen4-35B-A3B-GGUF:UD-Q4_K_M followed by ollama run with the same name. One install note from the sandbox: Ollama's Linux installer needs zstd to extract its bundle. If your system does not have it, the installer stops with an error telling you so — install zstd from your package manager first, then re-run the installer.

6. Send it an image#

Qwen4-35B-A3B is natively multimodal: the vision encoder reads images into 16 × 16 patches, merges each 2 × 2 group into one visual token, and passes those tokens to the text decoder alongside your words. Video works the same way — the processor samples 2 frames per second and groups consecutive frames into pairs. This is not a text model with a vision adapter bolted on; the same weights handle both.

The quickest way to try it is the Transformers pipeline from the Hugging Face launch post:

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": [
            {"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?"},
        ],
    }
]
outputs = pipe(messages, max_new_tokens=2048, return_full_text=False)
print(outputs[0]["generated_text"])

That loads the full BF16 checkpoint, so it needs a machine with roughly 70 GB of memory free — a GPU server, not a laptop. On the API side, the same thing goes through the Chat Completions API as an image_url content block, exactly as in the model card's example. With llama.cpp, vision needs the projector file: add the mmproj-Qwen4-35B-A3B-BF16.gguf sidecar (903 MB, same repo) when you start the server, and the /v1/chat/completions endpoint accepts image input. The vision path is documented from the model card and the launch post, not run in this sandbox — the verification model is text-only — so test it with the launch post's own example image first and confirm the projector loads before you build anything on it.

7. Set the thinking effort#

Qwen4 thinks by default. The model card defines four reasoning-effort levels, and this is the single most useful knob on the model:

LevelUse it for
xhighComplex tasks where quality matters most
highCommon tasks — the default
lowFast responses with minimal thinking
offNo thinking at all; direct answers

Through the API, set it in extra_body (from the model card's example):

completion = client.chat.completions.create(
    model="Qwen/Qwen4-35B-A3B",
    messages=[{"role": "user", "content": "Write a Python function to merge two sorted linked lists."}],
    extra_body={
        "chat_template_kwargs": {
            "preserve_thinking": True,
            "reasoning_effort": "low",
        },
    },
    stream=True,
)

The older enable_thinking switch still works, and enable_thinking=False is equivalent to reasoning_effort="off". In llama.cpp, the equivalent is the --reasoning off flag. Two warnings from the model card are worth heeding. First, the model may answer directly without thinking even at higher effort levels when it judges a task simple enough. Second, and counterintuitive: in multi-turn agentic tasks, lower reasoning effort does not always reduce total completion time — faster per-turn replies can come with more failures and retries, which increases total latency and token consumption. Leave it on high for agent work and drop to low or off only for short, simple questions.

Sampling parameters matter too, and Qwen publishes the recommended sets. For thinking mode: temperature=1.0, top_p=0.95, top_k=20, min_p=0.0, presence_penalty=0.0, repetition_penalty=1.0. For non-thinking mode: temperature=0.7, top_p=0.80, top_k=20, min_p=0.0, presence_penalty=1.5, repetition_penalty=1.0. The high presence penalty in non-thinking mode is there to break repetition loops; the card notes that pushing it higher can cause language mixing. For long agentic work, Qwen suggests budgeting up to 262,144 tokens for reasoning and 131,072 for the final response inside the 1M context.

8. Speed it up with MTP speculative decoding#

The model ships with a 1-layer multi-token prediction (MTP) head trained to draft the next tokens alongside the main model. llama.cpp can use it for speculative decoding: the small head proposes tokens, the main model verifies them, and accepted drafts skip full forward passes. The MTP head is packaged as a separate sidecar so base downloads stay compact — mtp-Qwen4-35B-A3B-Q4_K_M.gguf is 1.29 GB, the Q8_0 version 2.02 GB, BF16 3.76 GB. Enable it with two flags:

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

Hugging Face reports a 22% generation speedup with 3 draft tokens on an Apple M5 running the Q4 quant. Your mileage will vary with hardware — speculative decoding helps most when the draft head's guesses are usually right, which is the common case for code and structured text. Unsloth builds the MTP head into every quant, so no sidecar is needed if you use their files.

Illustration of a long document being read by a local model, with a thinking-effort control beside it
AI-generated illustration: the two ideas that make Qwen4 different locally — a million-token context and a thinking-effort dial you control.

Which approach should you use?#

There are five reasonable ways to run this model, and the right one depends on what you are doing with it:

  • llama.cpp if you want maximum control on one machine: CPU or GPU, exact context sizes, MTP flags, and the vision projector. This is the route this tutorial verifies in depth, and the best choice for a personal server.
  • Ollama if you want the shortest path to a chat: one command, model management built in, and an API on port 11434. The trade-off is fewer knobs — you get Ollama's defaults unless you create a Modelfile.
  • Transformers if you are experimenting in Python: the image-text-to-text pipeline from the launch post is the fastest way to try image, video, and tool-calling examples. It needs the full BF16 or FP8 checkpoint and a GPU with serious memory.
  • vLLM or SGLang if you are serving the model to other people: both have Qwen4 recipes linked from the model card, and both are built for throughput on GPU servers. This is production tooling, not a first run.
  • MLX on Apple Silicon if you are on a Mac: mlx_lm.generate --model mlx-community/Qwen4-35B-A3B-4bit-text runs the 4-bit text build with Metal, and the oMLX builds add image input, MTP, and PLE offloading to SSD.

There is also a hosted option: Qwen Cloud will serve the model under the name qwen4-35b-a3b, with official built-in tools. At publication time the card says it is coming soon and lists no price — if you need the model today without local hardware, that is the page to watch, not a workaround to build around.

The takeaway#

Qwen4-35B-A3B is the first open model that makes a million-token context feel ordinary: a 36 GB download, a single command to serve, and an API your existing tools already speak. The architecture is the reason — a hybrid of linear and sparse attention, a 20 billion-parameter n-gram table that costs almost nothing at inference time, and a thinking-effort dial instead of a second model for hard questions. Start with Q4_K_M in llama.cpp, keep the context modest until you know your machine, and leave thinking on high for anything that matters. The model is free under Apache-2.0, the tooling shipped on day one, and the only thing standing between you and a local model with a million-token memory is a download.

Benchmark figures in this article are Qwen's own, from the model card and launch post — no independent measurements exist yet, days after release. The Qwen4 commands are the exact commands from the model card and the Hugging Face launch post; the llama.cpp install, terminal chat, and API server were run end to end in a sandbox with a small Qwen3 stand-in model, since the full 35B build needs 18 GB+ of RAM. Vision, vLLM/SGLang serving, and the hosted Qwen Cloud API are documented from the primary sources and flagged as such in the text.