contenox

Best Ollama models for coding, by VRAM

Updated

MODELS AND COST Best 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 memoryPickDownloadContextAlso good
8 GBqwen3.5:9b, short tasks only6.6 GB256kOllama Cloud for agent work
12 GBqwen3.5:9b6.6 GB256kgemma4:12b (8 GB)
16 GBqwen3.5:9b-q8_010 GB256kqwen3-coder:30b, partly on the CPU
24 GBqwen3.8:27b18 GB256kqwen3.5:27b, devstral-small-2, flint:40b
48 GBqwen3.8:27b-q8_030 GB256kqwen3.5:35b-a3b-q8_0 (39 GB), flint:40b
64 GB and upqwen3-coder-next52 GB256kqwen3.5:122b (81 GB)
Ollama Cloudglm-5.3:cloudnone1Mkimi-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:

ModelDownload (4-bit)KV cache per tokenAt 64kAt 128k
qwen3.5:9b6.6 GB32 KiB2 GiB4 GiB
qwen3.8:27b18 GB64 KiB4 GiB8 GiB
qwen3-coder:30b19 GB96 KiB6 GiB12 GiB
devstral-small-215 GB160 KiB10 GiB20 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?

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.

The other strong options at 24 GB:

ModelDownloadWhat the maker reportsWatch out for
qwen3.5:27b17 GBSWE-bench Verified 72.4, Terminal-Bench 2 41.6The older generation of the pick
devstral-small-215 GBSWE-bench Verified 68.0, Terminal-Bench 2 22.510 GiB of cache at 64k; use OLLAMA_KV_CACHE_TYPE=q8_0
flint:40b23 GBSWE-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:30b19 GBNo SWE-bench number on the model cardFast, 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.

ModelContextWhat it is
glm-5.3:cloud1MZ.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:cloud256kMoonshot 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:cloud1MDeepSeek’s fast model, tools and thinking. DeepSeek reports Terminal-Bench 2.1 90.6
deepseek-v4-pro:cloud1MDeepSeek’s larger model
gpt-oss:120b-cloud128kOpenAI’s open model; the example in Ollama’s Codex docs

Ollama’s Claude Code page recommends glm-5.3-flash, gemma4:cloud and kimi-k2.7-code:cloud for Claude Code. If you search for DeepSeek: deepseek-v4-flash was retired from Ollama on 25 September 2026; use deepseek-v4.1-flash:cloud. Ollama shows upcoming retirements in your usage settings.

Plans and usage limits are on Ollama’s pricing page. For scale, from the team 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.

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.

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

Related

Esc to close