CodeMind high-level design
How CodeMind is built, trained and run: a fill-in-the-middle coding model trained in the cloud and served entirely on the developer's laptop. For implementation details, see the low-level design.
1. Goals and constraints
- Private by design. Inference runs offline on the developer's machine; code, keys and IP never leave it.
- Built for the cursor. The core task is fill-in-the-middle (FIM): generate the code between what comes before and after the cursor.
- Four languages. Python, Java, JavaScript and TypeScript.
- Modest hardware. Small enough (1.54B parameters, about 3.5 GB in 16-bit) for a consumer-grade GPU.
- Correctness over style. Alignment rewards code that passes unit tests, not code that merely looks right.
2. Architecture overview
- Training data2M FIM examples for SFT; HumanEval+ and MultiPL-E problems with unit tests for preference training.
- Supervised fine-tuningAll 1.54B weights, 31,250 steps, 512-token context, about 4.6 hours.
- Test-based DPOSample completions, run the unit tests, update the dense weights in FP32 on 381 pairs and evaluate on 21 held-out pairs.
- Cloud StorageSFT and DPO checkpoints, pairs, configs and logs in one bucket.
- Evaluation harnessHumanEval(+), MBPP(+), FIM and held-out preference accuracy.
- Release buildConverted to 16-bit, about 3.5 GB, downloaded once.
- Editor and runtimeThe editor sends the code around the cursor to the local runtime, which returns the filled middle. Nothing leaves the laptop.
3. Components
| Component | Responsibility | Runs on |
|---|---|---|
| Base model | Qwen2.5-Coder-1.5B Base, extended with hybrid attention and a sparse mixture of adapter experts | — |
| SFT trainer | Full fine-tuning on 2M fill-in-the-middle examples | Cloud TPU v6e-8 |
| Candidate sampler | Generates 8 completions per problem, one process per TPU chip | Cloud TPU v6e-8 |
| Execution reward | Runs each completion against its unit tests (Python, Node.js, tsc, javac) | TPU host CPUs |
| Pair builder | Turns pass/fail results into chosen/rejected preference pairs | TPU host CPUs |
| DPO trainer | Aligns the model to prefer passing code, against a frozen SFT reference | One TPU v6e chip |
| Evaluation harness | Benchmarks and held-out metrics for every checkpoint | GPU or TPU |
| Artifact store | Checkpoints, datasets, pairs, configs and logs | Google Cloud Storage |
| Local runtime | Loads the 16-bit release and serves completions to the editor | Developer laptop |
4. Data flow
Cloud training (once per release)
Fill-in-the-middle examples train the base model with supervised fine-tuning. The SFT model then samples several completions for coding problems that ship with unit tests; the tests decide which completions pass. Passing and failing completions of the same problem become preference pairs, and DPO trains the model to prefer the passing ones. Checkpoints go to Cloud Storage, are evaluated, and the release is converted to 16-bit.
Inference path (every keystroke pause)
The editor captures the code before and after the cursor, wraps it in the FIM prompt format, and sends it to the local runtime. The model generates the middle span until a stop token, and the editor shows it inline. There is no server round trip.
5. Key design decisions
| Decision | Why |
|---|---|
| Fill-in-the-middle | Inline completion needs both sides of the cursor, not only the code above it (Bavarian et al., 2022). |
| 1.5B base model | Large enough for useful code, small enough for a laptop GPU with low latency. |
| Hybrid attention | A 96-token sliding window in three of every four layers keeps long files fast; full attention every fourth layer keeps global context. |
| Sparse adapter experts | Top-2 of 4 low-rank adapters in the final two layers add capacity at little inference cost. |
| Unit tests as the reward | Pass or fail is objective and cheap to compute; no learned reward model or human labeling is needed. DPO uses these test results as preference labels. |
| DPO rather than PPO | DPO learns directly from preference pairs, with no reward model or online rollouts, so it fits a single accelerator. |
| 32-bit DPO weights | DPO learning rates are tiny (5e-6); in 16-bit most updates would round away. The release is converted to 16-bit afterwards. |
| Sampling on 8 chips | Sampling is the expensive step; one process per TPU chip divides it eight ways. |
6. Current status
- 1 December 2026: supervised fine-tuning complete (validation perplexity 10.7).
- 2 December 2026: test-based DPO complete: 81% preference accuracy on held-out pairs (17 of 21).
- Next: a before-and-after pass@1 comparison of the SFT and DPO models.