Skip to content
Sudhanshu ShuklaAI Lab · GenAI Engineering
Menu
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

ItemValue
BaseQwen2.5-Coder-1.5B Base, all 1.54B parameters trained
Decoder28 layers, hidden size 1,536
Attention96-token sliding window in three of every four layers; full causal attention in every fourth
ExpertsFinal two decoder layers: each token routed to the top 2 of 4 low-rank adapters
TokenizerQwen2.5 tokenizer with its native fill-in-the-middle tokens
PrecisionSFT 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

SettingValue
Data2,000,000 fill-in-the-middle examples in four languages
Context512 tokens
Schedule31,250 steps × 64 examples, about 122 examples/s, about 4.6 hours
ResultValidation loss 2.571 → 2.370; perplexity 10.7 on the missing-span tokens

4. Preference-training modules

ModuleResponsibility
multipl_e.pyBuilds Java, JavaScript and TypeScript problems from MultiPL-E
data.pyFIM record schema and loaders
generate.py, xla_gen.pyCandidate sampling; fixed-shape decoding on TPU
pairs_8chip.shLaunches one sampling process per TPU chip and merges their output
reward.pyExecution reward: runs each completion against its unit tests
pairs.pyBuilds chosen/rejected pairs from the rewards
train_dpo.pyDPO training on one TPU chip
eval.pyEvaluation harness

4.1 Problems

LanguageSourceProblems usedPairs
PythonHumanEval+ (EvalPlus)16434
JavaScriptMultiPL-E HumanEval + MBPP (558)500154
TypeScriptMultiPL-E HumanEval + MBPP (549)500146
JavaMultiPL-E HumanEval + MBPP (544)50068

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

4.3 Execution reward

LanguageProgram that is runCommand
Pythonprompt + completion + testspython
JavaScriptprompt + completion + closing brace + testsnode
TypeScriptprompt + completion + closing brace + teststsc --target esnext, then node
Javaprompt + completion + tests (which close the class)javac, then java -ea

4.4 DPO training

SettingValue
TrainerTRL DPOTrainer on PyTorch/XLA, one TPU v6e chip
PolicyDense transformer weights in float32. The SFT adapter experts were excluded from this stage.
ReferenceThe SFT model, frozen, in bfloat16
ObjectiveSigmoid DPO loss, β = 0.1
OptimizerAdafactor, learning rate 5e-6
Batching1 pair per micro-batch, 16 micro-batches per update
Sequence length768 tokens, every batch padded to exactly 768
Data split381 training pairs, 21 held out (5%), 1 epoch
ResultHeld-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.

SymptomCauseFix
Sampling stalledStandard generation grows the attention mask every token, so XLA recompiled every stepFixed-shape decoding (section 4.2)
Training hung at startWith all 8 chips visible, a synchronization step waited for 8 processes that never existedPin training to one chip
Crash in the forward passThe run’s gradient-checkpointing configuration failed on XLACheckpointing off on TPU
Updates lost to roundingThe bf16 training flag switched the whole TPU to 16-bit, including the float32 policybf16 flag off on TPU
Out of memory, 10-minute compilesAll 16 accumulated micro-batches were traced into one graphCut the graph after every micro-batch

6. Artifacts

ArtifactContent
SFT checkpointbfloat16 weights, 2.9 GB
DPO checkpointfloat32 weights, 7.1 GB; converted to bfloat16 (about 3.5 GB) for release
Preference pairs402 test-verified pairs as JSON Lines, per language and merged
Run bundleCode, configs, datasets and logs for reproducing the run

7. Open items