This guide will help you fine-tune the Qwen3-Coder model (a Qwen-based language model optimized for code generation) to support the Amber programming language.
The goal is to train the model with hundreds of Amber scripting examples, enabling it to:
- Generate Amber code
- Convert Bash or Python scripts to Amber
- Important Note
- Hardware Requirements
- Prerequisites
- Download Qwen3-Coder Model
- Prepare the Dataset
- Fine-Tuning Options
- Test the Fine-Tuned Model
This guide assumes basic knowledge of Linux, Python, and machine learning.
Fine-tuning a large model requires significant resources. To reduce memory requirements, this guide uses PEFT (Parameter-Efficient Fine-Tuning) with LoRA.
- GPU: NVIDIA with minimum 8GB VRAM (tested on RTX 3060 with 12GB)
- RAM: Minimum 16GB (31GB recommended for larger datasets)
- Disk: ~40GB free space for model download and checkpoints
- CUDA: Compatible with CUDA 11.8+
- Python 3.10+
- NVIDIA GPU with compatible drivers
Install dependencies by running install.sh:
chmod +x install.sh
./install.sh
The huggingface-cli tool downloads files directly to disk without loading them into memory, avoiding OOM issues on machines with limited RAM/VRAM.
Install huggingface-cli first (required for downloading without loading into memory):
source ./amber-finetune-env/bin/activate
pip install huggingface_hub[cli]
If you encounter authentication errors:
huggingface-cli login
Run:
source ./amber-finetune-env/bin/activate
./prepare_dataset.py /Amber/src/tests/stdlib/ /Amber/src/tests/translating/
Both workflows use the same dataset preparation. Choose one based on your hardware:
Run training on the full model:
python train.py
This uses the existing train.py script which automatically loads the model in 4-bit if needed.
The LoRA approach trains only ~1% of parameters, making it suitable for lower-VRAM GPUs.
-
Update download script for 8B (edit
download-qwen-coder.py):- Use model name:
"Qwen/Qwen2.5-Coder-8B-Instruct"
- Use model name:
-
Download the model:
python download-qwen-coder.pyThe model downloads to
./qwen3-coder-base. -
Train with LoRA:
python train_lora_8b.py --epochs 3 --batch-size 1 --lr 5e-5 -
Test:
python test.py
Run:
python test.py