Fine-Tuning My First LLM: Picking the Model Is an Architecture Decision
Article

Fine-Tuning My First LLM: Picking the Model Is an Architecture Decision

How we trained a 4B model on a single used RTX 3090 to do one job as well as a 27B model, at three to four times the throughput, on our own hardware, and what happened when it worked three nights on its own: 48,000 types, 42,420 new docs. Plus how umage.ai runs local AI for development, and why the model you pick is an architecture choice, not a default.

There’s an e-ink panel on the wall in our office. It shows what one of our local AI servers has been up to, and on Sunday evening it said this:

An e-ink office panel titled "Local AI server, 7 days", showing tokens per day as a bar chart from Monday to Sunday. The footer reads 48.4M in 7 days, peak Thursday 11.7M, busy 90h59m, peak 364.7 tok/s, max 73 C.

At least 48.4 million output tokens in a week, with a request running for 91 of the week’s 168 hours, on one RTX 3090 serving qwen3.8:27b. Nobody sent it an invoice. The GPU never went above 73 °C, which is cooler than most of the tea I drink while watching it.

This is the third post in a series that started with agents rebuilding our site on Optimizely CMS 13 and continued with the knowledge base we built so agents stop forgetting what they learn. Both posts had the same quiet subplot: use the expensive model to decide, and cheaper ones to do the work. This one follows that idea all the way down, to a model small enough to train on that graphics card.

Picking the model is an architecture decision

The default in most teams is to use the biggest model for everything. It’s the safest choice for any single task and the most expensive one for the system as a whole. It’s like hiring a senior architect to change a light bulb: the bulb gets changed beautifully, and you get an invoice and a diagram.

In the CMS 13 rebuild, one Opus agent orchestrated and Sonnet did nearly all of the work. In the knowledge base, Haiku read, Sonnet verified and Opus only delegated. Neither was a cost-cutting exercise. The models were chosen per job, the same way you’d choose a database or a queue.

Choosing the model is an architecture decision. Don’t just go Opus on everything.

The far end of that idea is the small, specialised model. You can see it in the current interest in decision models like Jev and its open-source counterparts such as JevK5. They don’t chat at all. They read a situation and a typed question and return a probability for each answer in a single pass. JevK5 is built on Qwen3.5 weights, including the 4B model. Hold that thought.

Why we run local AI at all

When clients ask us about local AI, three things matter to them:

  • Data security: the code and the content never leave machines they control.
  • Guaranteed supply: nobody can withdraw the model, change its behaviour overnight or have an outage on your deadline.
  • Predictable cost: no surprise token bills, just electricity.

That’s the continuity half of AI sovereignty, which I wrote about in the spring.

For us internally, the reason is simpler, and slightly more selfish. Local inference makes experimenting free. We can point a model at thousands of codebases, websites or documents overnight, and the only question in the morning is whether the result was any good, not what it cost. Most of our heavy lifting happens while we sleep. It’s the closest thing I have to a night shift, and it has never once asked for a pizza budget. Dev grunt work gets offloaded to the local model too, through an MCP server called local-vibes, while the frontier models do the thinking.

Now, fair warning: I have a soft spot for used RTX 3090s and other people’s gaming PCs, so the hardware is unglamorous on purpose. A 3090 has 24 GB of memory, it’s cheap on the second-hand market, and it was built to run games flat out for hours. The server behind the e-ink panel is somebody else’s finished gaming machine, bought second-hand for about 3,500 DKK with 32 GB of RAM and RGB lighting included at no extra charge. The 3090 inside it was one we already had, and that cost a fair bit more, even used. Everyone knows rainbow LEDs add at least 10% to tokens per second. I haven’t benchmarked it, and I’m not going to risk finding out.

Inside a second-hand gaming PC through its glass side panel: an MSI GeForce RTX 3090 lit in rainbow RGB, a Corsair liquid cooler and pink and cyan case fans. This is the local AI server behind the e-ink panel.

None of it was bought for AI. Somewhere out there is a gamer who upgraded and has no idea their old PC now writes .NET documentation for a living. Hours are free when nobody is sitting there, but the hardware isn’t, so I won’t pretend local is free. You pay for the cards up front, and then the nights cost you electricity.

Our workhorse model right now is qwen3.8:27b, served with vLLM. With up to four requests in flight, a single 3090 delivers more than 200 output tokens per second in total, and its best 15-second average last week was 365. One request on its own is much slower: about 65 tokens per second, measured on a different setup with Ollama, so the two numbers differ in runtime and quantisation as well as in concurrency.

Credit where it’s due: most of that speed isn’t mine. The vLLM setup on that box is HyperQwen from the clever people at syv.ai, a fellow Danish AI agency. It’s a set of patches and model preparation that squeezes large Qwen models onto the GPUs people actually own. If you have a 3090 gathering dust, it’s worth an evening.

It’s been brilliant for overnight analysis and for building up knowledge. But for one job it was too slow, and that job is where the fine-tuning comes in.

Why 33,000 classes each need a paragraph

In the CMS 13 rebuild, one agent spent 28 minutes and 149 tool calls decompiling CMS 13.5.1 to work out why a preview didn’t refresh. That’s the brilliant-and-ignorant problem in a single number. Whatever an agent learns by decompiling, it learns the expensive way, and then the next agent starts from zero again, like a goldfish with a PhD.

The knowledge base fixes half of that. Its NuGet index holds the public API of 14,424 package versions, read straight from the compiled assemblies, so an agent asking about DataFactory on CMS 13 gets a fact instead of a fifteen-year-old blog post. But a signature only tells you that a type exists. It doesn’t tell you what the type is for, when you’d use it, or what the code around it usually looks like. Search the index for DataFactory and this is what came back:

Search results for DataFactory in the NuGet index browser. The official packages show a one-line description, such as "Legacy data source in EPiServer CMS" and "Should use IContentRepository instead". Several community and sample packages show "no docs".

The official packages have a line of explanation. The community ones say “no docs”, and the community packages are the long tail, where an agent is most likely to know nothing. “No docs” means it reaches for the decompiler again.

So the index stores a short, model-written doc for every public .NET type: what it does, how it’s used, a code example. Write it once and every agent after that gets the paragraph instead of the 149 tool calls. The 27B wrote those docs at about 8.7 per minute on our shared batch server, competing with everything else that runs on it. At that rate, tens of thousands of types never got a doc at all, or at least not before CMS 17. When I started this, about 33,000 distinct types were still waiting for one.

So the plan was distillation. Take the 27B as the teacher, train a much smaller student to do this one job, and run the student on a single 3090. The student was Qwen3.5-4B, the same family JevK5 is built on.

The teacher was wrong 39% of the time

The first surprise came before any training. To build the filters that decide what counts as a good doc, Haiku and Sonnet checked a sample of 245 of the 27B’s existing docs. About 39% had a real factual error. Those were the docs the index had been handing to our agents.

That changed the project. Training a student on the teacher’s existing docs would have taught it to be confidently wrong at 50 docs a minute. So the teacher got a better prompt first: it now looks up the types a doc refers to instead of remembering them, uses real usage examples, and gets a round of compiler feedback to repair its own code examples. Its output was regenerated for about 10,500 types, and 89.6% of the new docs passed every check.

The checks are what make the whole thing possible. A doc passes when its C# example actually compiles against the real package, the types it mentions actually exist, and the namespaces are right, among other things. All of that can be tested by a machine. There were no human labels anywhere in the project.

Training on a gaming GPU

The training itself was the boring part, which is how it should be. If training gets exciting, something is on fire, and with a second-hand gaming PC I mean that slightly more literally than I’d like:

  • LoRA in bf16 on the 4B model: 21.2 million trainable parameters, 0.5% of the model.
  • About 10,000 examples, two epochs, on one 3090 with a peak of about 12 GB of memory.
  • A frozen test set of 487 types from 44 package families the model never saw in training, split by family so it couldn’t cheat by recognising siblings.

Version 2 trained in 9.9 hours. The whole thing, from first experiment to production pilot, took four days, and almost all of it ran unattended from scripts that generate, score, select, train and evaluate in a chain. The heavy lifting all ran on our own hardware. Why not just use an API? The free models are worth roughly what you pay for them, and I’m too cheap to pay for the big ones at this volume of data.

Results

Share of the test set that passes the automated checksOut of 487 docs from 44 package families held out of training: the 27B teacher's historical docs 61.6%, untuned 4B 53.6%, fine-tuned 4B version 1 60.6%, fine-tuned 4B version 2 68.6%, version 2 with the checker picking the best of four candidates 82.8%, version 2 with all candidates 84.8%, and the 27B teacher with the new prompt and a repair round 84.8%.27B teacher4B27B, historical docs61.6%4B, untuned53.6%4B fine-tuned, v160.6%4B fine-tuned, v268.6%4B v2, best of 482.8%4B v2, all candidates84.8%27B, new prompt + repair84.8%
Pass rate on 487 held-out docs. The fine-tuned 4B, with the checker picking among its candidates, matches the 27B teacher running the improved prompt and a repair round.

On its own, the untuned 4B passed 53.6% of the test set. Fine-tuned, it reached 68.6%, already ahead of the teacher’s old docs, and its rate of wrong namespaces dropped from 17.9% to 6.8%. Let the checker pick the best of several candidates and it reaches 84.8%, the same as the 27B with the new prompt and a repair round.

In the benchmark it did that at about 50 docs a minute against the teacher’s 8.7. That’s not a clean comparison, since the teacher was measured on a busy shared server and the student on a dedicated card. But nobody’s arguing about whether it’s faster.

Training version 2 used an estimated 3.4 kWh. A 1,520-type pilot on real backlog types passed at 90.5% within four attempts, and 72% on the first try. From that, I predicted 25,000 to 28,000 types a night. Then I let it loose on the real thing.

Three nights on its own

The pilot was optimistic, as pilots tend to be. So was I.

From 15 to 18 November, the 4B worked three nights unattended, in batches of 4,000 types: 48,000 types in all. 45,418 of them, 94.6%, passed every check within four attempts, and after a last filter, 42,420 new docs went into the index. The same type usually appears with an unchanged public API across many versions of a package, so those docs also filled in about 1.3 million type-version entries along the way. The index now holds more than 838,000 per-type docs, and about 754,000 of them were written by a model that fits on a gaming card.

It wasn’t 25,000 a night, though. It was 20,000 the first night, 16,000 the second and 12,000 the third, and I’d cut the third night from ten hours to eight. The GPU wasn’t slowing down. It held 580 to 630 tokens per second all night, every night. The work got harder. Later batches held older package versions and bigger types, the input per batch grew from 6.1 to 9.9 million tokens, and the first-try pass rate slid from about 87% to about 77%, so more types needed the extra attempts. Averaged over the nights it comes to roughly 30 types a minute, not 50. Still three to four times the teacher.

The GPU draws about 355 watts under load, so by my estimate the three nights cost 9.4 kWh at most. That’s roughly 0.2 Wh per type, and a few kroner of electricity in total for 42,420 docs. In Copenhagen, the tea I drank while reading the logs cost more.

When I wrote this, three batches were left. After those, every type the 27B never got to will have had its turn. If the first twelve batches are anything to go by, nearly nine in ten will come out with a doc, and the rest wait for a better attempt instead of getting a bad one.

Where my favourite trick stopped working

If you’ve heard me talk about agents, you’ve heard me preach review-fix loops. A cheap model that writes, gets reviewed, and fixes what the review found beats an expensive model and hope, almost every time. I’ve said it on stage and to clients. I’ve probably said it at dinner parties, which might explain the dinner parties.

So of course that’s what I tried first. When a doc failed the checks, the 4B got its own doc back along with the checker’s list of complaints, and was asked to fix it.

It sort of did. Of the 188 docs that failed, about a third passed after the repair round, which lifted the test set from 68.6% to 74.5%. A second round squeezed out one more point, to 75.6%. Not nothing, but not the loop I’d been preaching either.

Well, the same loop on the 27B tells a different story: from 71.5% to 84.8%, a review-fix loop working exactly as advertised. My best guess at the difference is what each model has seen. A general 27B model has been trained on more code reviews, bug reports and fixes than any of us will read in a lifetime. My 4B was fine-tuned on about 10,000 examples of exactly one thing: a type goes in, a doc comes out. There wasn’t a single review in its training set, so it probably has very little idea what to do with one. Handing it a code review is a bit like handing a sommelier a parking ticket: politely received, completely misunderstood. I haven’t proven that, but it fits.

What worked better was much more boring. Ignore the failed attempt, generate a few fresh candidates with a bit more temperature, let the checker test every one of them, and keep the best. Two fresh candidates beat one repair: 78.8% against 74.5%. Four fresh candidates beat two repairs: 82.8% against 75.6%. Call it the infinite-monkeys approach, with four monkeys and a compiler. The night runs use the same idea, with up to four fresh attempts per type and the checker deciding.

That only works because the checker is deterministic. It has no opinions and no off days. It compiles the example against the real package, confirms every type and namespace it mentions exists, and says yes or no. With a judge like that, the model doesn’t need to be wise, just cheap enough to ask four times. (Every number in this post is a pass rate on those checks, by the way. They prove the code compiles and the API is real. Whether the prose is any good is still a matter of taste, mine included.)

So my sermon gets a footnote. Review-fix loops work when the model knows how to take a review. A small specialised model might not, so give it a deterministic check and several fresh attempts instead.

Local AI comes with one more chore: you’re the scheduler now, and nobody else is going to do it for you. During the pilot, an image job started on the same card. The 4B went from 614 tokens per second to 17, and stayed there for four and a half hours while 80 requests timed out. Nothing crashed, it just quietly crawled, which is worse. The runner now checks which GPU is free before every round, which I’d like to say was my idea from the start.

When I’d fine-tune, and when I wouldn’t

Fine-tuning was worth it here, for two reasons: the task is narrow, and every answer can be checked automatically. Take away either one and I’d stop.

If you can’t check the output, you can’t build the dataset, you can’t tell whether training helped, and you can’t catch a teacher that’s wrong 39% of the time. If the task is broad, a small model won’t hold it and a bigger one with a good prompt is the better architecture.

Pick the model per job. Big models to decide, smaller ones to do, and a specialised small one for the high-volume job in the middle.

Check the teacher before you copy it. Your existing outputs are probably worse than you think. Ours were.

Match the loop to the model. Review-fix loops need a model that has learned to take a review. A narrow fine-tune hasn’t, so give it a deterministic checker and best-of-n instead.

Make it boring. Scripts that chain generate, score, train and evaluate overnight are what made four days possible, and the e-ink panel is what makes it visible.

If you want local AI for your own team, from the hardware and the models to the pipelines that run while you sleep, get in touch. AI sovereignty is one of the things we do, and choosing the right model for the job turns out to be most of it.

Lesson learned: check the teacher first, then pick the smallest model that passes the checks.

P.S. No, the 4B didn’t write this post. It only knows how to document .NET types, and I’d like to keep it that way. The RGB is still on, though. Just in case.