How to use
The model uses Qwen2.5-Coder's fill-in-the-middle tokens. Put the code before the cursor after <|fim_prefix|> and the code after it after <|fim_suffix|>; the model writes the middle.
import torchfrom transformers import AutoModelForCausalLM, AutoTokenizer repo = "sudhanshu42844/codemind-1.5b-fp32"tok = AutoTokenizer.from_pretrained(repo)# bfloat16 halves the memory (about 3.5 GB) with no meaningful quality loss for inference.# Leave out dtype to load the full float32 weights.model = AutoModelForCausalLM.from_pretrained(repo, dtype=torch.bfloat16, device_map="auto") prefix = "def is_palindrome(s: str) -> bool:\n "suffix = "\n\nprint(is_palindrome('racecar'))\n"prompt = f"<|fim_prefix|>{prefix}<|fim_suffix|>{suffix}<|fim_middle|>" inputs = tok(prompt, return_tensors="pt").to(model.device)stop_ids = tok.convert_tokens_to_ids([ "<|endoftext|>", "<|fim_pad|>", "<|file_sep|>", "<|repo_name|>", "<|fim_prefix|>", "<|fim_suffix|>", "<|fim_middle|>", "<|im_end|>",])out = model.generate(**inputs, max_new_tokens=128, do_sample=False, eos_token_id=stop_ids)print(tok.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
device_map="auto" needs the accelerate package; without it, call model.to("cuda") or run on CPU. The checkpoint was saved with transformers 5.20.2.
Training
Stage 1: supervised fine-tuning
Table with columns: Setting, Value| Setting | Value |
|---|
| Data | 2,000,000 fill-in-the-middle examples in four languages |
| Context length | 512 tokens |
| Schedule | 31,250 steps × 64 examples, about 4.6 hours |
| Hardware | Cloud TPU v6e |
Stage 2: RLHF with DPO
For each coding problem, the SFT model sampled 8 completions (temperature 0.9, top-p 0.95). Every completion was run against the problem's unit tests with python, node, tsc + node or javac + java. A problem gave one preference pair when at least one completion passed and another failed. No learned reward model or human labelling was used; strictly, this is reinforcement learning from execution feedback.
Table with columns: Language, Problems, Source, Preference pairs| Language | Problems | Source | Preference pairs |
|---|
| Python | 164 | HumanEval+ (EvalPlus) | 34 |
| JavaScript | 500 | MultiPL-E (HumanEval + MBPP) | 154 |
| TypeScript | 500 | MultiPL-E (HumanEval + MBPP) | 146 |
| Java | 500 | MultiPL-E (HumanEval + MBPP) | 68 |
| Total | | | 402 |
Table with columns: Setting, Value| Setting | Value |
|---|
| Method | DPO, sigmoid loss, β = 0.1 |
| Policy | all weights in float32 |
| Reference | the SFT model, frozen |
| Optimiser | Adafactor, learning rate 5e-6 |
| Batch | 1 pair per micro-batch, 16 micro-batches per update |
| Sequence length | 768 tokens |
| Data | 381 training pairs, 21 held out, 1 epoch |
| Hardware | one Cloud TPU v6e chip, 27 minutes |
Evaluation
Table with columns: Stage, Metric, Result| Stage | Metric | Result |
|---|
| SFT | Validation perplexity on the missing-span tokens (held-out FIM split) | 10.7 (loss 2.571 → 2.370) |
| SFT | Local sample: HumanEval / HumanEval+ (10 tasks) | 4/10 · 4/10 |
| SFT | Local sample: MBPP / MBPP+ (8 tasks) | 2/8 · 1/8 |
| DPO | Held-out preference accuracy (prefers the passing completion) | 81% (17 of 21 pairs; chance is 50%) |
| DPO | Held-out DPO loss | 0.693 → 0.456 |
| DPO | Held-out reward margin | 0.82 |
The SFT code-generation scores come from a small local sample of 18 tasks. Preference accuracy measures how the model ranks a passing completion against a failing one on pairs it never trained on. It is not a pass@1 score: a before-and-after pass@1 comparison of the SFT and DPO models on full benchmarks has not been run yet.
Limitations
- Small evaluation. The scores above come from small samples (18 tasks; 21 held-out pairs) and are not full-benchmark results.
- Dense weights only. The SFT stage also trained a small sparse mixture of low-rank adapter experts (top-2 of 4, in the final two layers). Those adapters are not part of this checkpoint, and DPO updated the dense weights only.
- Short training context. SFT used 512-token examples; quality on much longer files is untested.
- Function-level focus. The preference problems are self-contained functions; repository-level completion is untested.
- Code can be wrong or unsafe. Like any code model, CodeMind can produce incorrect, insecure or licence-encumbered code. Review and test what it writes.
Licence and attribution
Released under the Apache-2.0 licence. Built on Qwen2.5-Coder-1.5B (Apache-2.0). Preference problems come from MultiPL-E (MIT) and HumanEval+ from EvalPlus.
Fill-in-the-middle training follows Bavarian et al. (2022), Efficient Training of Language Models to Fill in the Middle. DPO follows Rafailov et al. (2023), Direct Preference Optimization.
More