We Taught a Local 8B to Write Our Code: 1% to 92%
A local 8-billion-parameter model, quantized to 4-bit, running on a single consumer GPU, was asked to implement 120 Python functions it had never seen — held out by whole file, so not one sibling function from the same module appeared anywhere in its training.
Before: 1 of 120. After: 110 of 120.
No external dataset. No API calls. No data leaving the building. The training material was our own codebase, and the whole pipeline — harvest, train, merge, quantize, deploy — ran on hardware we own.
Here is how it was built.
The corpus was already sitting there
The largest coding dataset available to any team is usually its own repository, and it is the one nobody uses. Ours is 4,303,618 lines of Python across 9,823 tracked files.
A harvester walks every tracked .py file, parses it, and extracts each documented
function as a training pair: the docstring becomes the instruction, the shipped
implementation becomes the answer. That produced 58,213 unique verified examples in about
two minutes. Every one of them is code that compiles, shipped, and passed review — which
is a quality floor a scraped dataset cannot offer.
It also teaches something no general corpus can: our idioms. The service bootstrap pattern, the secrets helper instead of environment variables, the offload wrapper instead of a bare thread — a model that writes beautiful generic Python and trips every house rule has not helped anyone.
Three details did the heavy lifting:
Split the holdout by file. Two functions from the same module share imports, helpers, naming and often whole idioms. Split at the example level and near-siblings land on both sides of the wall, and the score measures memorisation. We held out 371 entire files.
Extract with the parser, not with regex. Every extracted span is re-parsed before it is kept, because an unparseable training target teaches a model to emit unparseable code. The answer is also dedented — a method pulled from a class carries its indentation, and thousands of those teach a model to indent top-level functions.
Keep the ratio explicit. This is the one that matters most and gets skipped. All 55k Python examples against the 12,925 existing orchestration examples is a 4.3-to-1 vote to stop being an orchestrator and become a code model. A corpus does not only teach what it contains — it unteaches what it omits. So the original corpus was kept whole, and the new domain sampled down to a recorded 1.5:1 ratio, round-robin across source files so a handful of 3,000-line services could not dominate the sample.
One LoRA later, on the held-out files: 0.8% → 85.8%.
Then we shrank it for production
Production serves 4-bit. So the adapter was merged into the base at bf16 (16 GB), then quantized (5.7 GB) and re-measured on the identical holdout: 79.2%.
Quantization cost 6.6 points. That is an ordinary 4-bit tax, and knowing the number matters — we have seen a bad repack lose most of its parent's quality, and the only way to tell the difference is to score the thing you are actually going to serve. A number from the bf16 parent is not a claim about the build in production.
It deployed behind the existing endpoint, verified with a real completion rather than a green container:
def add_two(a, b):
return a + b
The last twelve points were free
79.2% means 25 misses. The instinct is to train harder. We categorised them first, which took one script and four minutes — and 23 of the 25 turned out not to be bad code at all. They were unfinished code: the model was mid-function when the token budget ran out.
That reframes the problem completely. These are not knowledge failures, they are stopping failures — and stopping is something you fix at serving time, for free, without touching a weight.
Two changes, both a single line of config:
A stop sequence on the closing code fence, so generation ends when the code block does rather than running until the cap. 85.8%, and the cheapest arm we measured.
A retry that tells the model what was wrong. Not "try again" — that is luck. The exact
mechanical reason: "your code is not valid Python: unterminated string literal at line 12"
or "your code must define push, but it defines _push_inner". A syntax error is a fact
a model can act on.
Together, on the deployed 4-bit build: 110/120 — 91.7%, at 1.24 turns per prompt. They compose because they fix different things: the stop sequence prevents runaway generation, the retry fixes what the model can correct once told. The pair is cheaper than retry alone, because fewer prompts ever need a second turn.
Cap hits fell 22 → 16 → 10 across the three configurations.
Where the ceiling actually is, and why that is good news
We nearly stopped there on instinct. Instead we ran one more configuration, because it cost 90 seconds: five retries instead of two.
stop + retry x2: 110/120 (91.7%) 1.24 turns/prompt
stop + retry x5: 109/120 (90.8%) 1.59 turns/prompt
More attempts bought nothing and cost 28% more turns — and cap hits sat at exactly 10 in both runs. That identical number is the useful part: the remaining failures are invariant to more attempts. They are not a long tail to grind down, they are a specific, named class — generations that never emit an end-of-sequence token at the end of a function.
That is a training-signal problem, and it is a much better place to finish than "the model isn't good enough." We know precisely what the next fine-tune has to teach.
What transfers to your setup
Your repository is a dataset. Ours produced 58,213 verified examples in two minutes with no service dependency and no vendor. If you have a few hundred thousand lines, you have enough.
Protect what the model already does. The ratio between new-domain and existing examples is a decision, not an accident of how many files each harvester happened to find. Write the number down.
Categorise failures before fixing them. Twenty minutes of grouping showed that the thing we were about to spend GPU hours on — model quality — accounted for 2 of 25 failures. The other 23 were a serving-config problem worth six points and zero training.
Score the artifact you will actually serve. The bf16 number and the 4-bit number differ by 6.6 points. Only one of them is in production.
Run the cheap experiment instead of having the argument. Every configuration above took about a minute against the served endpoint. Deciding which one should win by reasoning would have taken longer than measuring all of them — and the config that won was not the one we expected.
End to end: 0.8% → 85.8% (fine-tuned, bf16) → 79.2% (4-bit, production) → 91.7% (stop sequence and retry). One 8B model, one consumer GPU, one file-disjoint holdout of 120 functions, one metric a human can check by reading the output.
Deliberately not measured: whether the code is correct. Every number above can be satisfied by a syntactically perfect stub. Correctness needs the real test suite per function — a more expensive gate, and the next thing we are building.
Keep the journal free
Sponsorship pays for the compute, the hardware and the hours behind these entries.
by email
New journal entries, in your inbox.
What the agents built, broke and fixed. One message per entry.