Code Models: From Codex to Local Coding Assistants

How models that finish your line of code went from a private OpenAI experiment to a download you can run offline

Contents

Programming is the odd job that language models turned out to be unreasonably good at. Code has strict grammar, enormous public training data and a built-in answer key, because you can run it and see whether it works. Within about two years of the first demos, “autocomplete that writes the next ten lines” had moved from research curiosity to default editor feature. Within four it had moved onto laptops, with no network connection required.

This post follows that line: Codex and Copilot in 2021, the open models of 2023 (StarCoder and Code Llama), the Qwen2.5-Coder family of 2024, and what the lineage means for anyone who wants an assistant running on their own machine. It is the overview that sits above the individual pieces, including the Codex deep dive and the practical walkthrough of a first local coding assistant with Ollama.

2021: Codex and the proof of concept

OpenAI’s Codex was GPT-3 fine-tuned on public code from GitHub. The accompanying paper, “Evaluating Large Language Models Trained on Code” (July 2021), introduced HumanEval, a set of 164 hand-written Python problems each checked by unit tests. The headline result is covered in the Codex post: the 12-billion-parameter Codex solved 28.8 per cent of problems with a single attempt, a figure that rose to 37.7 per cent for a variant fine-tuned further on correct standalone functions, while the original GPT-3 solved essentially none.

The more consequential move was the product. GitHub Copilot opened as a technical preview in June 2021, built on Codex, and became generally available on 21 June 2022 at 10 US dollars a month or 100 dollars a year, free for verified students and maintainers of popular open-source projects. GitHub reported that more than 1.2 million developers had taken part in the preview and that nearly 40 per cent of code in popular languages such as Python was being written by Copilot in files where it was switched on.

Codex itself was available only through OpenAI’s servers. The idea was out, and the weights were not. That gap is the story of the next two years.

An illustrated scene of a small glowing machine beside a desk completing lines of luminous script.
An illustration of the idea of a local coding assistant: a small model running on a machine beside the developer. AI-generated illustration.

Fill-in-the-middle: the trick that makes editors work

A language model trained in the usual way continues text left to right. That fits chat, where the model writes the next paragraph. It fits an editor badly. When you type in the middle of a function, the useful completion depends on the code after the cursor as well as the code before it: the variable that gets used two lines down, the closing bracket already present.

Fill-in-the-middle (FIM) training solves this by rearranging documents during training. Each file is cut into three pieces, prefix, middle and suffix, and reordered so the model sees the prefix and suffix first and writes the middle last. Special marker tokens tell it which part is which. At run time the editor sends the code before and after the cursor and the model fills the gap.

What the editor sees: code before the cursor, code after it, and a gap.Prefixdef area(r):Middle (to generate)return 3.14159 * r**2Suffixprint(area(2))<fim_prefix> prefix <fim_suffix> suffix <fim_middle>The model is prompted in this order and writes the middle last.Token names follow StarCoder; other models use their own markers.
Fill-in-the-middle. The marker names shown follow StarCoder; other model families use their own.

StarCoder supports it, and so do Code Llama’s smaller models and the Qwen2.5-Coder family. It is the difference between an assistant that completes a line gracefully and one that can only append text at the end of a file. When a model card says “supports infilling”, this is what it means.

2023: the open models arrive

StarCoder (May 2023). The BigCode project, an open collaboration led by Hugging Face and ServiceNow, released StarCoder and StarCoderBase. According to the paper, StarCoderBase is a 15.5-billion-parameter model with an 8,000-token context window, trained on 1 trillion tokens from The Stack, a collection of permissively licensed GitHub repositories. StarCoder is that base model fine-tuned on a further 35 billion Python tokens. The authors report that it outperforms every open code model supporting multiple languages at the time and matches or exceeds OpenAI’s code-cushman-001, reaching 40 per cent pass@1 on HumanEval when prompted appropriately. It uses multi-query attention for cheaper inference and supports fill-in-the-middle. Releasing the models under an OpenRAIL licence, with an improved personal-data redaction pipeline and an attribution-tracing tool, was an explicit attempt to answer the licensing worries that had followed Copilot.

Code Llama (August 2023). Meta announced Code Llama on 24 August 2023, building it on Llama 2. It came in 7, 13 and 34 billion parameters, each in three flavours: a foundation model, a Python specialist and an instruction-following variant. A 70-billion-parameter version followed on 29 January 2024. The paper reports training on 16,000-token sequences, with improvements on inputs up to 100,000 tokens, and supports infilling in the smaller models. One result got a lot of attention: according to the paper, Code Llama - Python 7B outperforms Llama 2 70B on HumanEval and MBPP. A small specialist beating a general model ten times its size is a theme of this whole field, and it is the same pattern covered in the Mistral 7B profile. The licence is the Llama community licence, permitting research and commercial use with conditions, which makes it open weights rather than open source in the sense explained in open weights versus open source.

Together these two releases established the recipe: take a strong general base, continue training on a large pile of code, add infilling, release in several sizes so people can pick one that fits their hardware.

2024: Qwen2.5-Coder and the small-model squeeze

Alibaba’s Qwen team released Qwen2.5-Coder in September 2024, with a technical report posted that month and a final revision in November 2024. The report describes six sizes, 0.5, 1.5, 3, 7, 14 and 32 billion parameters, built by continued pretraining on a corpus of over 5.5 trillion tokens of source code, text-code grounding data and synthetic data. The team claims state-of-the-art results among open models across more than ten benchmarks covering generation, completion, reasoning and repair, and that the models outperform larger ones of the same class, while keeping general and mathematical skill through careful data mixing. As with every vendor benchmark claim, the benchmarks post explains why to hold the numbers loosely. Check each size’s model card for its exact licence, because families like this often license sizes differently. The Qwen family profile places it in context.

The point for local users is the spread of sizes. A 1.5-billion-parameter model is small enough to autocomplete on a modest laptop; the 32-billion model targets a machine with a serious GPU or plenty of unified memory. Size choice follows the rules in how much hardware you need and picking a model size.

What a local coding assistant is made of

Three pieces, matching the stack in the anatomy of a local AI setup: the weights (a code model), a runtime and server (Ollama, llama.cpp or similar) and a front-end (an editor extension). The extension sends context to the server over a local HTTP port; the server returns text.

Two different models often do the two different jobs. Autocomplete wants a small, fast FIM-trained model that answers in a fraction of a second, because a suggestion that arrives after you have typed the next word is useless. Chat and refactoring can use a bigger instruction-tuned model, since you will wait a few seconds for a considered answer. Using one 7-billion model for both is a reasonable compromise on a single machine.

To try a Qwen2.5-Coder size through Ollama, the model is a pull away:

1
2
ollama pull qwen2.5-coder:7b
ollama run qwen2.5-coder:7b "Write a Python function that parses ISO 8601 dates"

Ollama’s generate endpoint also accepts a suffix field for models whose template supports infilling, which is how an editor extension asks for a fill-in-the-middle completion:

1
2
3
4
5
6
curl http://localhost:11434/api/generate -d '{
  "model": "qwen2.5-coder:7b",
  "prompt": "def area(r):\n    ",
  "suffix": "\n\nprint(area(2))",
  "stream": false
}'

I have run Llama- and Qwen-family models on an NVIDIA GPU box and on an Apple Silicon Mac, and the pattern that matters in practice is the one above: the runtime is interchangeable and the model size decides what feels usable. The hardware comparison in GPU vs Apple Silicon vs CPU covers where each platform shines.

Where code models still go wrong

Plausible and wrong. A model trained to produce likely code will produce code that looks right. Hallucinated function names and API arguments are the classic failure, the same mechanism described in why models hallucinate. Tests, type checkers and a compiler are the answer, and they were the idea behind HumanEval from the start.

Stale knowledge. A model’s picture of a library freezes at its training cutoff. A framework that changed its API last year will be suggested in its old form.

Licensing and provenance. Models trained on public code raise unresolved questions about reproduced snippets. StarCoder’s attribution tracing and its permissively licensed training set were a response to this, and the debate has not ended.

Context limits. An assistant sees a window of your repository, not the whole thing. Suggestions that need knowledge of a distant file will miss.

Benchmark narrowness. HumanEval’s 164 short Python functions look nothing like a day’s real work in a large codebase, and a model near the top of such a list can still stumble on an ordinary refactor. Newer benchmarks try to widen the test, but the gap between a leaderboard and your repository persists.

Is a local code model worth running?

For autocomplete and quick questions on code you would rather not send to a third party, yes. The small models are good enough that the experience feels like a modern editor feature, and nothing leaves the machine. For large multi-file changes and deep reasoning, the biggest hosted models still lead, and the honest setup for many people is both: a local model for the constant low-stakes help, a hosted one for the hard problems. The line from Codex to a 7-billion-parameter download in an editor sidebar took less than four years, and the sizes in between are the interesting part.

Sources: Chen et al., Evaluating Large Language Models Trained on Code (Codex) · Li et al., StarCoder: may the source be with you! (arXiv 2305.06161) · Rozière et al., Code Llama: Open Foundation Models for Code (arXiv 2308.12950) · Hui et al., Qwen2.5-Coder Technical Report (arXiv 2409.12186) · GitHub: Copilot is generally available to all developers

Smarc
Written by Smarc

Founder and editor of Aside House. A lifelong tinkerer who self-hosts far more than is sensible, hardens Linux boxes for fun, and prods the latest AI tools to see what they can really do. The how-to guides here are the notes Smarc wishes had existed the first time round.

Smarc is the editor of Aside House. The homelab, the hardware and the opinions are real; the guides are drafted with AI assistance. Infrastructure details are genericised on purpose.