# Best Local LLM for Coding by RAM (2026)

> Best local LLM for coding by RAM: compare Qwen3-Coder and Qwen2.5-Coder sizes, quantized weights, and 32K context cache before you pull an Ollama model.

The best local LLM for coding is the one that fits with context left over. The model card says 256K context, but the 30B model's weights already take 19 GB in Ollama's Q4_K_M build, and 32K tokens add another 3 GiB of BF16 KV cache. A printed context maximum is not a memory plan. I checked the current Qwen model configs and published Ollama artifact sizes to make the choice by machine budget.

**The short answer:** for a local coding model, start with Qwen2.5-Coder-7B-Instruct at Q4_K_M on an 8 GB inference memory pool, Qwen2.5-Coder-14B-Instruct at Q4_K_M on 16 GB with a shorter context, and Qwen3-Coder-30B-A3B-Instruct at Q4_K_M from 32 GB. On 64 GB, Q8 is a practical quality-first variant. A 128 GB machine does not need a larger local coder for ordinary repo work; more memory mostly buys context or concurrent sessions.

I build Octomind, an open-source coding agent, so I care about whether a model can edit a repo through tools as well as autocomplete a line. This is a memory-fit guide, not a model bake-off: I did not run these models, and the benchmark statements below are the makers' claims.

## Which local LLM is best for coding?

The best local coding model to start with is the largest instruct model that leaves room for its context cache and runtime. For a practical agent, I would choose Qwen3-Coder-30B-A3B at Q4_K_M if the machine can spare about 25 GB; if not, move down to the 14B or 7B Qwen2.5-Coder model and shorten context.

| Your inference memory pool | Start here                           | Why it fits                                                                                                                                                          |
| -------------------------- | ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 8 GB                       | Qwen2.5-Coder-7B-Instruct, Q4_K_M    | 4.7 GB published artifact; use 8K context if other processes share memory.                                                                                           |
| 16 GB                      | Qwen2.5-Coder-14B-Instruct, Q4_K_M   | 9.0 GB artifact; 8K context costs about 1.5 GiB of BF16 KV cache.                                                                                                    |
| 32 GB                      | Qwen3-Coder-30B-A3B-Instruct, Q4_K_M | 19 GB artifact plus 3 GiB cache at 32K.                                                                                                                              |
| 64 GB                      | Qwen3-Coder-30B-A3B-Instruct, Q8_0   | 32 GB artifact plus 3 GiB cache at 32K; leaves more room for runtime and other work.                                                                                 |
| 128 GB                     | Qwen3-Coder-30B-A3B-Instruct, Q8_0   | Same choice as 64 GB. The 480B Q4 artifact is 290 GB, so it does not fit; extra RAM can support a longer context or another model, not an automatic quality upgrade. |

The sizes are a starting filter, not a promise that every runner will load them. On a Mac with unified memory, the operating system and apps draw from the same pool; on a discrete GPU, the VRAM budget is separate from system RAM unless your runner offloads layers. Subtract what those other processes consume before choosing a row.

## How much memory do model weights and context use?

Weight quantization sets the first cost; the KV cache grows with the number of tokens you keep in context. For a full-attention model with BF16 cache, calculate one sequence as:

```text
KV bytes = layers × 2 (key and value) × KV heads × head dimension × 2 bytes × tokens
```

For Qwen2.5-Coder-7B, the config has 28 layers, 4 KV heads, and 128 dimensions per head (`hidden_size ÷ attention_heads = 3584 ÷ 28`). That is 1.75 GiB at 32K tokens. The 14B model has 48 layers and 8 KV heads, so its 32K cache is 6 GiB. Qwen3-Coder-30B-A3B has 48 layers, 4 KV heads, and 128 dimensions, which makes its 32K cache 3 GiB.

The inputs come from the [Qwen 7B config, 2024](https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct/blob/main/config.json), [Qwen 14B config, 2024](https://huggingface.co/Qwen/Qwen2.5-Coder-14B-Instruct/blob/main/config.json), and [Qwen3-Coder config, 2025](https://huggingface.co/Qwen/Qwen3-Coder-30B-A3B-Instruct/blob/main/config.json).

The simple weight estimate is `parameters × bits ÷ 8`. It gives a lower-bound payload, not the size of a downloadable file: a 30B model at 4 bits has a 15 GB floor, while Ollama's Q4_K_M artifact is 19 GB. Quantization metadata, scales, and tensors stored at higher precision add space.

KV cache uses another dtype; the calculations above assume BF16, and a runner that supports quantized KV cache can change that cost.

For a reproducible artifact size, use the actual runner tag. Ollama lists Qwen2.5-Coder-7B-Instruct at 4.7 GB for Q4_K_M, 5.4 GB for Q5_K_M, and 8.1 GB for Q8_0; its 14B instruct versions are 9.0, 11, and 16 GB respectively ([Ollama Qwen2.5-Coder tags, checked November 2026](https://registry.ollama.com/library/qwen2.5-coder/tags)).

Ollama lists Qwen3-Coder-30B at 19 GB for Q4_K_M and 32 GB for Q8_0 ([Ollama Qwen3-Coder tags, checked November 2026](https://ollama.com/library/qwen3-coder/tags)). Its Q5 estimate from the bit formula is about 18.75 GB, but I did not find a Q5_K_M tag for that model in the opened library listing, so treat it as a rough floor rather than a pullable file size.

The cache equation assumes one full-attention sequence and counts only K and V tensors. Multiple parallel requests multiply cache use. Leave additional room for the runner, temporary buffers, operating system, editor, and desktop display. If the model loads but starts swapping or errors when the prompt grows, lower context first; the [KV cache explainer](/blog/kv-cache) shows why.

## Which model fits each RAM tier?

Compare cache costs at 32K, then choose a context that leaves operating room. Headroom is your remaining budget after weights and 32K BF16 cache, before runtime overhead; the 8 GB and 16 GB picks need shorter contexts to be comfortable.

| Model and quant                   |                              Published weight artifact | 32K BF16 KV cache |         Weight + cache | Fit call                                                                                    |
| --------------------------------- | -----------------------------------------------------: | ----------------: | ---------------------: | ------------------------------------------------------------------------------------------- |
| Qwen2.5-Coder-7B-Instruct Q4_K_M  |                                                 4.7 GB |          1.75 GiB |           about 6.6 GB | 8 GB: viable for a single session; set 8K if memory is shared.                              |
| Qwen2.5-Coder-7B-Instruct Q5_K_M  |                                                 5.4 GB |          1.75 GiB |           about 7.3 GB | 8 GB: almost no room left at 32K; prefer Q4 or 8K context.                                  |
| Qwen2.5-Coder-7B-Instruct Q8_0    |                                                 8.1 GB |          1.75 GiB |          about 10.0 GB | 8 GB: does not fit at 32K.                                                                  |
| Qwen2.5-Coder-14B-Instruct Q4_K_M |                                                 9.0 GB |             6 GiB |          about 15.4 GB | 16 GB: reduce to 8K (about 1.5 GiB cache) and leave runtime space.                          |
| Qwen2.5-Coder-14B-Instruct Q5_K_M |                                                  11 GB |             6 GiB |          about 17.4 GB | 16 GB: use a shorter context or Q4.                                                         |
| Qwen2.5-Coder-14B-Instruct Q8_0   |                                                  16 GB |             6 GiB |          about 22.4 GB | 16 GB: does not fit at 32K.                                                                 |
| Qwen3-Coder-30B-A3B Q4_K_M        |                                                  19 GB |             3 GiB |          about 22.2 GB | 32 GB: leaves roughly 10 GB for runtime and apps.                                           |
| Qwen3-Coder-30B-A3B Q5 estimate   | about 18.75 GB floor; no opened Ollama Q5_K_M artifact |             3 GiB | at least about 22.0 GB | 32 GB: possible by payload math, but select only after checking the actual file and runner. |
| Qwen3-Coder-30B-A3B Q8_0          |                                                  32 GB |             3 GiB |          about 35.2 GB | 64 GB: comfortable starting point; 128 GB: more context or concurrency, same model.         |

The combined figures convert cache GiB to approximate decimal GB for easier comparison with Ollama's artifact sizes. They still exclude runtime overhead. Don't count an 8 GB laptop's shared memory and an 8 GB GPU's VRAM as one pool unless your runtime actually supports that placement.

## Which model is best for a local coding agent?

For a tool-using coding agent, begin with an instruct checkpoint and leave context for the agent's instructions, tool results, and files. Qwen3-Coder is explicitly trained for multi-turn tool use.

Qwen's launch article, which centers on the 480B-A35B flagship, says "Qwen3-Coder achieves state-of-the-art performance among open-source models on SWE-Bench Verified without test-time scaling" but gives no numerical score in text and does not name the 30B-A3B in that claim. That is the maker's benchmark claim, not evidence that this 30B quantization will solve the same tasks on your machine ([Qwen3-Coder article, 2025](https://qwenlm.github.io/blog/qwen3-coder/)).

Do not read `30B-A3B` as a 3 GB download. The Q4_K_M artifact is 19 GB: the full model weights still need to reside in memory even when a model activates only part of its parameters for a token.

If your work is mostly inline completion, a smaller model may feel more responsive, but this guide has no comparable latency measurements to recommend a speed winner. If you want the model to inspect files, call tools, and edit a repository, test it against three real tasks from your own codebase and check whether the runner preserves tool calls.

A [local coding agent setup with Ollama](/blog/run-coding-agent-locally-ollama) walks through the next step. Octomind supports Ollama and local OpenAI-compatible endpoints, but any agent that can talk to those endpoints can be paired with a local model.

## How do you run a local coding model with Ollama?

Start with the best Ollama model for coding that fits your memory row, then let Ollama download the published quantization:

```sh
ollama run qwen2.5-coder:7b
```

For a 32 GB machine, run Qwen3-Coder on Ollama with the 30B artifact instead:

```sh
ollama run qwen3-coder:30b
```

These commands are copied from Ollama's model library instructions; they are docs-only here, not tested on your machine. The default Qwen2.5-Coder tag is the 7B instruct build at 4.7 GB and 32K listed context; Qwen3-Coder's `30b` tag resolves to its 19 GB Q4_K_M build.

Reduce the runner's context setting if a 14B model fails under a 16 GB limit; the published 32K maximum does not mean 32K fits alongside its weights. [LM Studio vs Ollama](/blog/lm-studio-vs-ollama) compares the two local runners if you prefer a desktop model picker.

## Can a local model replace a cloud coding agent?

A local model is a good fit when source code must stay on your machine, the change is bounded, and you can accept slower or less reliable tool use. A cloud model is still the practical choice when a task needs stronger reasoning, long unattended runs, or a maintained coding harness and you do not want to operate local inference.

“Free” means no per-token API bill after you own or already have the hardware; it does not mean zero cost. The hardware, electricity, setup time, and occasional model or tool failure still count. For more capable hosted open weights, see [open weight models for coding](/blog/open-weight-models-for-coding); that is API-hosted inference, so it avoids fitting the weights on your own GPU but is not local.

If you have 8 GB, use Qwen2.5-Coder-7B-Instruct at Q4_K_M and start with 8K context. At 16 GB, the 14B Q4 model is the reasonable ceiling unless you reduce context substantially. At 32 GB or more, Qwen3-Coder-30B-A3B at Q4 is the strongest recommendation this memory check supports. Keep Q8 for a 64 GB-or-larger pool, and use 128 GB for longer context or parallel sessions rather than assuming a larger model is automatically better.

Related reading: [run a coding agent locally](/blog/run-coding-agent-locally-ollama) · [how KV cache uses memory](/blog/kv-cache) · [open weight coding models](/blog/open-weight-models-for-coding)
