LLD · v1.0Updated 2 December 2026
CodeMind low-level design
Module-level detail of the model, the training stages and the preference-training pipeline, including the TPU-specific engineering. For the overview see the high-level design.
1. Model
| Item | Value |
| Base | Qwen2.5-Coder-1.5B Base, all 1.54B parameters trained |
| Decoder | 28 layers, hidden size 1,536 |
| Attention | 96-token sliding window in three of every four layers; full causal attention in every fourth |
| Experts | Final two decoder layers: each token routed to the top 2 of 4 low-rank adapters |
| Tokenizer | Qwen2.5 tokenizer with its native fill-in-the-middle tokens |
| Precision | SFT and release in bfloat16; DPO updates the dense weights in float32 |
2. Prompt format
Every training example and every completion request uses the same fill-in-the-middle layout. The model writes the middle span and stops at the first stop token.
<|fim_prefix|>{code before the cursor}<|fim_suffix|>{code after the cursor}<|fim_middle|>
→ generated middle span, ended by <|endoftext|> or another stop token
Stop tokens: <|endoftext|>, <|fim_pad|>, <|file_sep|>, <|repo_name|>, <|im_end|> and the three FIM markers.
3. Supervised fine-tuning
| Setting | Value |
| Data | 2,000,000 fill-in-the-middle examples in four languages |
| Context | 512 tokens |
| Schedule | 31,250 steps × 64 examples, about 122 examples/s, about 4.6 hours |
| Result | Validation loss 2.571 → 2.370; perplexity 10.7 on the missing-span tokens |
4. Preference-training modules
| Module | Responsibility |
multipl_e.py | Builds Java, JavaScript and TypeScript problems from MultiPL-E |
data.py | FIM record schema and loaders |
generate.py, xla_gen.py | Candidate sampling; fixed-shape decoding on TPU |
pairs_8chip.sh | Launches one sampling process per TPU chip and merges their output |
reward.py | Execution reward: runs each completion against its unit tests |
pairs.py | Builds chosen/rejected pairs from the rewards |
train_dpo.py | DPO training on one TPU chip |
eval.py | Evaluation harness |
4.1 Problems
| Language | Source | Problems used | Pairs |
| Python | HumanEval+ (EvalPlus) | 164 | 34 |
| JavaScript | MultiPL-E HumanEval + MBPP (558) | 500 | 154 |
| TypeScript | MultiPL-E HumanEval + MBPP (549) | 500 | 146 |
| Java | MultiPL-E HumanEval + MBPP (544) | 500 | 68 |
Each problem becomes a FIM record: the prefix is the function signature and documentation, the suffix is the closing brace (empty for Python), and the model fills the body.
4.2 Candidate sampling on TPU
- Sharding: 8 processes, each pinned to one chip; process i takes problems i, i+8, i+16 and so on.
- Sampling: 8 completions per problem, temperature 0.9, top-p 0.95 within the top 512 tokens, up to 256 new tokens.
- Fixed shapes: prompts are left-padded to 256-token buckets (up to 1,536 tokens) and rows are processed in fixed chunks of 32, so each bucket compiles once.
- Decoding: each step reruns the model over the full fixed-length buffer, with future positions masked, and writes the new token through a device-side index. Recomputing costs more FLOPs than a KV cache but avoids a recompile per token.
- Early stop: every 32 tokens the sampler checks whether all rows have produced a stop token.
4.3 Execution reward
| Language | Program that is run | Command |
| Python | prompt + completion + tests | python |
| JavaScript | prompt + completion + closing brace + tests | node |
| TypeScript | prompt + completion + closing brace + tests | tsc --target esnext, then node |
| Java | prompt + completion + tests (which close the class) | javac, then java -ea |
- Test execution. Each problem gets a temporary directory. Each run has a 20-second timeout. Exit code 0 indicates a pass.
- Scores: 1.0 if the tests pass, 0.1 if they fail, 0.0 if the code does not parse.
- Pairs: one pair per problem, the highest against the lowest score, only when at least one completion passes and the two texts differ. Problems where all 8 completions pass, or all fail, give no pair.
4.4 DPO training
| Setting | Value |
| Trainer | TRL DPOTrainer on PyTorch/XLA, one TPU v6e chip |
| Policy | Dense transformer weights in float32. The SFT adapter experts were excluded from this stage. |
| Reference | The SFT model, frozen, in bfloat16 |
| Objective | Sigmoid DPO loss, β = 0.1 |
| Optimizer | Adafactor, learning rate 5e-6 |
| Batching | 1 pair per micro-batch, 16 micro-batches per update |
| Sequence length | 768 tokens, every batch padded to exactly 768 |
| Data split | 381 training pairs, 21 held out (5%), 1 epoch |
| Result | Held-out DPO loss 0.693 → 0.456; preference accuracy 81%; reward margin 0.82 |
5. TPU engineering notes
Issues found while moving the pipeline to Cloud TPU, and how each was resolved.
| Symptom | Cause | Fix |
| Sampling stalled | Standard generation grows the attention mask every token, so XLA recompiled every step | Fixed-shape decoding (section 4.2) |
| Training hung at start | With all 8 chips visible, a synchronization step waited for 8 processes that never existed | Pin training to one chip |
| Crash in the forward pass | The run’s gradient-checkpointing configuration failed on XLA | Checkpointing off on TPU |
| Updates lost to rounding | The bf16 training flag switched the whole TPU to 16-bit, including the float32 policy | bf16 flag off on TPU |
| Out of memory, 10-minute compiles | All 16 accumulated micro-batches were traced into one graph | Cut the graph after every micro-batch |
6. Artifacts
| Artifact | Content |
| SFT checkpoint | bfloat16 weights, 2.9 GB |
| DPO checkpoint | float32 weights, 7.1 GB; converted to bfloat16 (about 3.5 GB) for release |
| Preference pairs | 402 test-verified pairs as JSON Lines, per language and merged |
| Run bundle | Code, configs, datasets and logs for reproducing the run |
7. Open items
- pass@1 comparison: preference accuracy measures ranking, not generation; a before-and-after pass@1 run of the SFT and DPO models is next.
- Adapter experts in DPO: this DPO run updated the dense transformer weights; the SFT adapter experts were not part of DPO training.
- More Python problems: MBPP-style Python problems need function signatures before they can join the test-based pipeline.
- Java yield: Java produced 68 pairs from 500 problems (13.6%). Compilation errors are a candidate for investigation.