Training code LLMs with Chain of Continuous Thought (COCONUT) for bug fixing tasks on SWE-bench.
✨ COCONUT Multi-stage Training
- Stage 0: Language-based Chain of Thought
- Stage N: Gradual replacement with latent reasoning
- Improved reasoning without token overhead
✨ Production-Ready Code
- Clean architecture with separation of concerns
- Comprehensive logging throughout
- Easy hyperparameter management via YAML config
- Type hints and docstrings
✨ Optimizations
- 4-bit quantization with bitsandbytes
- LoRA for efficient fine-tuning
- FlashAttention-2 support
- Gradient accumulation
pip install -r requirements.txt
Edit config/default.yaml:
model: name: "Qwen/Qwen3-0.6B" use_quantization: true use_lora: true
training: num_stages: 3 latent_dim: 256 continuous_thought_steps: 4
optimizer: lr: 5e-5 weight_decay: 0.01
python scripts/train.py
python scripts/evaluate.py
config/— Configuration filessrc/— Main source codeconfig.py— Config managementmodel.py— COCONUT modeldata.py— Dataset loading & preprocessingtrainer.py— Training loopoptimizer.py— Optimizer & schedulerlogger.py— Logging setuputils.py— Utilities
scripts/— Training & evaluationtests/— Unit tests
All events logged to:
- Console (INFO level)
outputs/{experiment_name}.log(DEBUG level)- W&B (if enabled)
- COCONUT: Training Large Language Models to Reason in a Continuous Latent Space
- Meta AI Research, 2024
MIT
bash
mkdir -p coconut-code-llm/{src,config,scripts,tests,outputs}
cp config/default.yaml coconut-code-llm/config/ cp src/.py coconut-code-llm/src/ cp scripts/.py coconut-code-llm/scripts/ cp requirements.txt coconut-code-llm/
cd coconut-code-llm pip install -r requirements.txt
python scripts/train.py