Training GLM and Other Open Models on Your Own Code: What It Actually Buys You (2026)

July 29, 2026
11 min read

July 29, 2026
11 min read
Every few weeks a founder asks some version of the same question: can we take an open model like GLM, train it on our codebase, and get an agent that writes code the way our team writes code? It is a good instinct, and in 2026 it is finally a reasonable one — the open-weight field is genuinely strong enough to build on, and a fine-tune that used to cost tens of thousands now costs less than lunch. But the request hides a trap. “Train it on our codebase” is actually three separate asks wearing one coat, and only one of them is a training job. Teams that fine-tune before separating them spend a month producing a model that writes in the house style and still cannot tell you which service owns the billing retry.
This is a practical guide to doing it in the right order: what the open-weight field looks like right now, how to split the three asks, what a LoRA adapter measurably fixes, what the whole thing costs, and how to pick a base model using your own repo instead of someone else's leaderboard.
Start with why this is worth doing at all. GLM-5.2, released by Z.ai in June 2026, is a 744-billion-parameter mixture-of-experts model with a one-million-token context window, full weights on Hugging Face, and an MIT license. It was built explicitly for coding, reasoning and tool-driven agentic work, and it lands within about a percentage point of Anthropic's Opus 4.8 on a key agentic benchmark at roughly a fifth of the cost. The MIT part matters more than the benchmark: you can train on it, ship it, and host it without asking anyone.
It is not the only option, and the right base depends on the shape of your workload. Qwen3-Coder-480B is Apache-2.0 and sits around 69.6% on SWE-bench Verified, with smaller variants that are far easier to self-host. DeepSeek-V3.2 is MIT-licensed and reaches roughly 70%. Kimi K2.6 is the pick for multimodal and multi-agent work, and MiniMax M3 for low-cost, high-throughput jobs. In practice, GLM-5.2 is the strongest default for long-context and long-horizon agent work, while Qwen3-Coder is where most teams land when they need something that runs on hardware they control.
One caution on the numbers: GLM-5.2 shipped without published independent benchmarks at launch, positioned by its maker as better than prior versions on long-horizon coding. Treat every figure in this section as a filter, not a decision. Which brings us to the part that actually matters.
Benchmarks filter, your repo decides
Make the final call with a private evaluation set built from your own tasks, run against the exact quantized checkpoint you will deploy, inside the same agent framework you will run in production. A model that tops a leaderboard at full precision can behave very differently at 4-bit inside your harness.
When someone says they want a model trained on their code, they usually want three different things at once. Naming them separately is most of the work.
The first ask is facts. What exists in the codebase, where it lives, which service owns which table, what that helper actually returns. This is knowledge, and knowledge changes — your repo changes daily, and a set of weights does not. Baking facts into a checkpoint means retraining every time someone merges. This ask belongs to retrieval, and it stays with retrieval permanently. The 2026 consensus is blunt about it: if the answer depends on data that changes, use retrieval, and fine-tune only for behaviour that should not change.
The second ask is conventions. How your team does things: the review checklist, the migration procedure, the way errors are wrapped, the rule that nothing talks to the database outside a repository class. This looks like a training problem and almost never is. Curated skill files — plain instructions describing when and how to do something — give you the same behaviour instantly, work across model providers, and can be edited, versioned, tested and rolled back without touching a checkpoint. Fine-tuning changes behaviour permanently and is slow and awkward to reverse; a skill file is a pull request.
There is an important caveat here, and it is one of the more useful research findings of the year: the mere presence of skills guarantees nothing. Auto-generated skills provide no benefit on average, curated human-authored ones consistently beat the no-skill baseline, and low-quality skills measurably degrade agent performance. So do not point a model at your repo and ask it to write its own conventions. Have your strongest engineer write ten real ones, by hand, from things that actually go wrong in review.
The third ask is form and tool schemas — and this one is a genuine training job. Getting the model to emit your internal API calls with your parameter names, follow your output structure exactly, and reliably choose the right tool from your own tool set is precisely what fine-tuning is good at. This is form, not facts, and it is stable in a way that file locations are not.
The clearest published example of the third ask is a team that needed a model to understand their specific tool schemas and parameter naming. Their agent's tool-call success rate was 40% — which, if you have shipped an agent, you will recognise as the number where nothing works and everyone blames the model. After a QLoRA fine-tune they were at 90%. The run cost roughly $1,500 all-in on a single RTX 4090, and landed within 1% of a full fine-tune on every benchmark they measured.
Notice what moved. Not the model's knowledge of their system, and not its general coding ability — its compliance with their interface. That is the honest promise of training on your own code: agents that stop fumbling your tools. If your agent currently fails because it invents parameter names, returns malformed structures, or picks the wrong tool, an adapter will fix it. If it fails because it does not know your architecture, an adapter will not, and no amount of training will.
The raw compute is now almost free. A LoRA or QLoRA fine-tune of a 7–8B model runs $3–$10 in GPU time — two to four hours on a rented A100, under $3 on a 4090 you already own. A 70B QLoRA run lands around $15–$30. Managed services charge roughly $0.48–$0.50 per million tokens, so a typical 50M-token job on an 8B model is about $25 hosted versus $3–$10 done yourself. LoRA is the right choice for the overwhelming majority of cases, and adapters compose surprisingly well — a code-style adapter and a security-reasoning adapter largely do not interfere with each other.
The GPU bill is not the cost
Training is $10. The real budget goes to curating examples that represent how your team actually works, and to building the evaluation set that tells you whether the adapter helped. Teams that skip both get a model that is confidently different rather than measurably better — and no way to tell which.
The sequence practitioners converged on in 2026 is prompt, then retrieval, then fine-tune, then distil — and the highest-return fine-tune is a thin LoRA adapter on a strong base model, paired with retrieval rather than replacing it. Each step is cheaper and more reversible than the one after it, so working in order means you often discover you can stop early.
That ordering also protects you from the most expensive mistake here, which is coupling yourself to a checkpoint too early. Retrieval lets you swap base models freely; a fine-tune does not. Given how fast this field moves — GLM-5.1 to 5.2 inside a few months — you want the part of your system that encodes your business to be the part you can carry to a better base model in an afternoon.
There is a reason this conversation is happening around GLM and Qwen rather than the closed APIs. Training on your own code means your code becomes training data, and with MIT or Apache-2.0 weights you can run that process entirely inside infrastructure you control — which is the difference between a conversation with your security team and a conversation with your customers' security teams. For anyone operating under data-residency commitments or enterprise processing terms, self-hosting an open base is often the only version of this project that survives review.
The second reason is portability. Open weights plus a model-agnostic agent harness means the adapter you trained this quarter can move to whatever tops the field next quarter. That is a meaningfully different position from building your workflow on top of one vendor's hosted fine-tuning product and hoping the pricing holds.
If you want to know whether any of this is worth your time, do not start with a training run. Start by finding out which of the three asks is actually costing you.
Run that in order and one of two things happens. Either you discover most of your pain was facts and conventions — in which case you have solved it in a week with retrieval and skill files, for free, and skipped the training project entirely. Or you find a hard core of interface failures that no prompt fixes, and you spend $10 turning a 40% tool-call rate into something you can ship. Both are good outcomes. The bad outcome is the one where you start with the fine-tune, because it is the most interesting part, and end up with a model that has learned your house style well enough to be wrong in it convincingly.
The open-weight field crossed a real threshold this year: for the first time, a founder can take a frontier-class, MIT-licensed coding model, adapt it to their own interfaces for the price of a coffee, and run the whole thing on hardware they control. That is a genuine shift in what a small team can own. It is just worth remembering that the leverage comes from knowing which of the three asks you are answering — not from the training run itself.