contenox

Best Ollama models for coding, by VRAM

Updated · Facts checked

MODELS AND COSTBest Ollama models for coding

The best Ollama model for coding depends on your GPU memory; these picks were checked against Ollama’s library in November 2026. With 24 GB, it’s qwen3.8:27b. With 12 to 16 GB, qwen3.5:9b. With 48 GB or more, the 8-bit qwen3.8:27b-q8_0 with a long context, or qwen3-coder-next if you have 64 GB or more. With 8 GB or less, use an Ollama Cloud model such as glm-5.3:cloud or kimi-k2.7-code:cloud for agent work.

Every pick here has the tools tag in Ollama’s library, so it can drive a coding agent, and supports at least 128k tokens of context.

The picks at a glance

Your GPU memory Pick Download Context Also good
8 GB qwen3.5:9b, short tasks only 6.6 GB 256k Ollama Cloud for agent work
12 GB qwen3.5:9b 6.6 GB 256k gemma4:12b (8 GB)
16 GB qwen3.5:9b-q8_0 10 GB 256k qwen3-coder:30b, partly on the CPU
24 GB qwen3.8:27b 18 GB 256k qwen3.5:27b, devstral-small-2, flint:40b
48 GB qwen3.8:27b-q8_0 30 GB 256k qwen3.5:35b-a3b-q8_0 (39 GB), flint:40b
64 GB and up qwen3-coder-next 52 GB 256k qwen3.5:122b (81 GB)
Ollama Cloud glm-5.3:cloud none 1M kimi-k2.7-code:cloud, deepseek-v4.1-flash:cloud

On a Mac with Apple silicon, read “GPU memory” as the unified memory you can spare after the system and your apps. Several models also have -mlx tags built for Apple silicon.

Why the download size isn’t the number that matters

The model has to fit in GPU memory together with its context. A coding agent needs at least 64k tokens of context; Ollama’s docs say so, and the agent’s instructions and tool list alone fill a good part of a smaller window. That context lives in the KV cache, and its size differs a lot between models.

Here is what 64k and 128k tokens cost at Ollama’s default f16 cache, calculated from each model’s config.json:

Model Download (4-bit) KV cache per token At 64k At 128k
qwen3.5:9b 6.6 GB 32 KiB 2 GiB 4 GiB
qwen3.8:27b 18 GB 64 KiB 4 GiB 8 GiB
qwen3-coder:30b 19 GB 96 KiB 6 GiB 12 GiB
devstral-small-2 15 GB 160 KiB 10 GiB 20 GiB

This is why the newer Qwen models win the small and mid tiers. Qwen3.5 and Qwen3.8 use full attention in only one layer out of four; the other layers keep a fixed-size state instead of a growing cache. devstral-small-2 is the smallest download of the 24 GB group, but at 64k it needs more memory in total than qwen3.8:27b.

The numbers are a floor: Ollama adds working memory on top, and running several requests at once (OLLAMA_NUM_PARALLEL) multiplies the cache. Check the real figure with ollama ps while the model is loaded. PROCESSOR should say 100% GPU. More on the mechanism: what is the KV cache?

Sizing it automatically, a case: picking the right model and settings for a given machine without asking the user sounds like a solved problem. A LinkedIn note from the maker of Contenox called it a hard nut at a layer everyone thought had been abstracted away years ago. The capacity planner built for an earlier Contenox inference daemon shows why. It reads the model’s own metadata (layer count, KV head count, head size, cache precision, any sliding window), takes a live snapshot of free GPU memory, subtracts the weights, runtime overhead, a safety margin and a floor kept for every other program on the card, and only then computes the context that fits. The cache is sized from the KV heads, not the attention heads; on models with grouped-query attention, using the wrong one overstates the memory several times. The table above is the same arithmetic done by hand.

The default-context trap: Ollama sets the context from your GPU memory: 4k under 24 GB, 32k from 24 to 48 GB, and 256k at 48 GB or more. Below 48 GB, it’s too small for an agent; raise it to 64k as shown in OpenCode with local models. At 48 GB or more, it’s the opposite: 256k of devstral-small-2 cache is 40 GiB, so the model spills onto the CPU without telling you.

8 GB: what fits, and what to use instead

qwen3.5:9b is the strongest tool-calling model that fits. Its download is 6.6 GB, and a 64k cache adds 2 GiB, which doesn’t fit 8 GB. Two ways to make it work:

  • Quantize the cache: OLLAMA_KV_CACHE_TYPE=q8_0 halves its memory with “a very small loss in precision”, per Ollama’s FAQ. It needs flash attention, which Ollama turns on by itself where the GPU supports it. The setting applies to all models.
  • Accept 32k and keep tasks short: one function, one test, one file.

Smaller options: qwen3.5:4b (3.3 GB) and gemma4:e4b (6.6 GB, 128k). They answer questions and make small edits. For multi-step agent work at this size, a cloud model is the honest answer.

12 GB: qwen3.5:9b with a full 64k context

At 12 GB, qwen3.5:9b runs with 64k context fully on the GPU: about 8.6 GB plus overhead. Qwen reports 65.6 on LiveCodeBench v6 and 66.1 on BFCL-V4, a tool-calling benchmark, for the 9B model. There are no SWE-bench numbers for it.

The alternative is gemma4:12b (8 GB, 256k context, tagged for tools). OpenCode users have reported Gemma 4 tool calls coming through as text with some Ollama versions, so test it in your agent before you settle on it.

16 GB: a better quantization, or a bigger model partly on the CPU

Two directions:

  • qwen3.5:9b-q8_0 (10 GB): the same model at 8 bits, closer to the original weights. With a 64k cache, about 12 GB, all on the GPU.
  • A mixture-of-experts model that doesn’t quite fit: qwen3-coder:30b (19 GB) or qwen3.5:35b-a3b (22 GB). Only about 3 billion of their parameters work on each token, so when part of the model sits in normal RAM, they slow down less than a dense model of the same size would. Expect it to be slower than full-GPU, and measure it on your machine.

qwen3-coder:30b doesn’t think before answering, which keeps turns short. That’s useful for agents that make many small tool calls.

24 GB: qwen3.8:27b

qwen3.8:27b is 18 GB, and with a 64k cache about 22 GB. It’s tagged for tools and thinking, with thinking on by default. Qwen’s model card reports 61.7 on SWE-bench Pro and 73.0 on Terminal-Bench 2.1, up from 53.5 and 63.4 for the previous 27B model, Qwen3.6-27B (in Ollama as qwen3.6:27b).

The other strong options at 24 GB:

Model Download What the maker reports Watch out for
qwen3.5:27b 17 GB SWE-bench Verified 72.4, Terminal-Bench 2 41.6 The older generation of the pick
devstral-small-2 15 GB SWE-bench Verified 68.0, Terminal-Bench 2 22.5 10 GiB of cache at 64k; use OLLAMA_KV_CACHE_TYPE=q8_0
flint:40b 23 GB SWE-bench Verified 74.2%, Terminal-Bench 2.1 54.9% Won’t fit with context, but only 2.5B parameters are active per token
qwen3-coder:30b 19 GB No SWE-bench number on the model card Fast, no thinking; 6 GiB of cache at 64k

Don’t rank these by the numbers alone. They come from different benchmarks (SWE-bench Verified and SWE-bench Pro are different task sets), run by the makers in their own harnesses. AI coding benchmarks, explained covers why scores from different setups don’t compare.

48 GB: 8-bit weights and long context

With 48 GB, keep the same model and spend the memory on quality and context:

  • qwen3.8:27b-q8_0 (30 GB) with a 128k cache (8 GiB): about 38 GB.
  • qwen3.5:35b-a3b-q8_0 (39 GB): the mixture-of-experts sibling, fast per token. Qwen reports SWE-bench Verified 69.2 for the 35B-A3B, below the 27B’s 72.4.
  • flint:40b (23 GB): now fully on the GPU, with room for a long context.

Set the context yourself. Ollama’s default of 256k at this size can push the model partly onto the CPU.

64 GB and up: the big local models

  • qwen3-coder-next (52 GB at 4 bits, 85 GB at 8 bits): 80B parameters, 3B active, built for agent work. Its model card reports SWE-bench Verified 70.6 and SWE-bench Pro 44.3.
  • qwen3.5:122b (81 GB): 122B parameters, 10B active.

Bigger isn’t automatically better here: qwen3-coder-next’s reported SWE-bench Verified score is below qwen3.5:27b’s. Its advantage is speed per token at a large size. Try both on your own repo before buying hardware for either.

Ollama Cloud: the biggest open models without a GPU

Cloud models run on Ollama’s servers, so your code leaves your machine; Ollama says it doesn’t train on cloud prompts. They use their full context length, so the context trap doesn’t apply. Sign in with ollama signin and use the :cloud tag like any local model.

Model Context What it is
glm-5.3:cloud 1M Z.ai’s flagship, which it calls the most capable open-weights model for coding. Z.ai reports Terminal-Bench 2.1 88.2, measured in Claude Code
kimi-k2.7-code:cloud 256k Moonshot AI’s coding model. Its own table shows it behind GPT-5.5 and Claude Opus 4.8 on most rows
deepseek-v4.1-flash:cloud 1M DeepSeek’s fast model, tools and thinking. DeepSeek reports Terminal-Bench 2.1 90.6
deepseek-v4-pro:cloud 1M DeepSeek’s larger model
gpt-oss:120b-cloud 128k OpenAI’s open model; the example in Ollama’s Codex docs

Ollama’s Claude Code page uses glm-5.3-flash, gemma4:cloud and kimi-k2.7-code:cloud in its examples. For DeepSeek: deepseek-v4-flash was retired from Ollama on 25 September 2026; use deepseek-v4.1-flash:cloud. Ollama shows upcoming retirements in the account’s usage settings.

Plans and usage limits are on Ollama’s pricing page. For scale, from the work behind this site: one 8-prompt agent session can send about 300 million input tokens. Cloud usage adds up faster than chat use suggests.

Which quantization should I pull?

  • The default tag is 4-bit (q4_K_M). It’s the right start for almost everyone.
  • q8_0 roughly doubles the download and gets closer to the original model. Worth it when the 8-bit version plus 64k of cache still fits on the GPU.
  • bf16 is the full-precision version. Locally, the memory is better spent on a bigger model or a longer context.
  • The KV cache has its own setting. OLLAMA_KV_CACHE_TYPE=q8_0 halves the cache; q4_0 quarters it with a “small-medium loss in precision”, per Ollama’s FAQ.

Measured: “a very small loss” is still a loss. In tests of an earlier Contenox inference daemon, a saved session restored into a fresh one reproduced the same greedy continuation exactly with an f16 cache; with the 8-bit cache the same test was measurably lossy. For a short chat that rarely shows. For an agent session that runs for hours, or is saved and resumed, keep f16 when the memory allows and treat q8_0 as the way to make a model fit, not a free saving.

A 4-bit model fully on the GPU beats an 8-bit model half on the CPU. Fit first, then precision.

How to test a pick on your own code

Benchmarks narrow the list. Your repo decides.

  1. Pull the model and set the context to 64k.
  2. Connect your agent; see OpenCode with local models or the Ollama page for Claude Code and Codex.
  3. Give it two real tasks from your backlog: one small fix with a failing test, and one change across three or four files.
  4. Watch for tool calls printed as text, edits to the wrong file, and loops. Those are the failures that differ most between models.

Count the malformed tool calls per model as a number of their own. Aider’s leaderboard prints a Correct edit format column beside every pass rate, and the work of hardening an earlier Contenox build’s tools named that rate as the signal that would have caught “fine on Gemini, degrades elsewhere” before a live run did. Also look for placeholder edits: a write containing // rest of code unchanged or a bare … replaces real code with a comment, a failure the same research found gemini-cli, Aider and OpenHands each guarding against on their own.

Which agent suits small local models best is its own question: see best Ollama harness.

Related

Esc to close