McGill-NLP/nano-aha-moment
소개
"LLM을 위한 RL"을 위한 단일 파일·단일 GPU·처음부터 구현된·효율적인 전체 파라미터 튜닝 라이브러리
학습 및 교육측정된 스타 증가
- in 24h
- 0
- in 7 days
- +4
- in 15 days
- +6
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalnanoAhaMoment: Single File "RL for LLM" Library
Amirhossein Kazemnejad*, Milad Aghajohari*, Alessandro Sordoni, Aaron Courville, Siva Reddy
Implementation of DeepSeek R1-zero style training with:
- Single 80G GPU (and also multi-GPU)
- No RL Library
- 3B Base Model (and also 7B models with multi-GPU)
- Full Parameter Tuning
- Efficient (Competetive performance to verl but much simpler)
- Up to 32K context size for 3B model with multi-GPU (or 16K context size for 7B model)
News
- June 2025: Added multi-GPU support for faster training and 7B models
- June 2025: Added VinePPO episode generation (experimental)
Inspired by TinyZero and Mini-R1, but designed to be much simpler, cleaner, and faster, with every line of code visible and understandable.
Karpathy-style Detailed Lecture on YouTube
- nanoAhaMoment: RL for LLM from Scratch with 1 GPU - Part 1
- nanoAhaMoment: RL for LLM from Scratch with 1 GPU - Part 2
File Descriptions
nano_r1.ipynbis the interactive single file jupyter notebook with tutorial.nano_r1_script.pyis also just thenano_r1.ipynbbut for convenience of running with python and multi-GPU support.notebooks/checkpoint_playground.ipynbis a notebook for comparing different model checkpoints (including our trained model) and playing with them.- 🤗 McGill-NLP/nano-aha-moment-3b: The HF model trained using the above script (~60% Accuracy on CountDown Task)
Setup Instructions
Clone the repository
git clone https://github.com/McGill-NLP/nano-aha-moment.gitInstall dependencies
First, make sure cuda 12.4 is installed.Install PyTorch:
pip install torch==2.5.1 --index-url https://download.pytorch.org/whl/cu124Install the rest of the dependencies:
pip install -r requirements.txtAlternative Installation with uv (Optional)
uv sync uv sync --extra compile # Install flash-attentionRun the training script
Opennano_r1.ipynbornano_r1_script.pyand start training.If using uv, you can run with either
uv run nano_r1_script.pyor activate the env withsource .venv/bin/activateand run withpython nano_r1_script.py
Multi-GPU Training
Here is the command to run the training script with 4 GPUs:
python nano_r1_script.py --nproc 4 # Use 4 GPUs
Batch Sizes for different context lengths
| Context Length | 3B Model (per_device_batch_size) | 7B Model (per_device_batch_size) |
|---|---|---|
| 1024 | 32 | 16 |
| 2048 | 16 | 8 |
| 4K | 8 | 4 |
| 8K | 4 | 2 |
| 16K | 2 | 1 |
| 32K | 1 | N/A |
Note: These batch sizes are optimized for 4xA100 80GB GPUs. For other GPU types, you may need to adjust the batch sizes accordingly.
Todos
- Full evaluation suite
- Multi-GPU support (Added June 2025)
Acknowledgement
We gratefully acknowledge the support of Lambda for providing compute resources through their research compute grant.
Citation
If you use this codebase in your research, please cite us using:
@misc{Kazemnejad2025:NanoAhaMoment,
author = {Amirhossein Kazemnejad and Milad Aghajohari and Alessandro Sordoni and Aaron Courville and Siva Reddy},
title = {Nano Aha! Moment: Single File "RL for LLM" Library},
year = {2025},
howpublished = {\url{https://github.com/McGill-NLP/nano-aha-moment}},
note = {GitHub repository}
}
관련 프로젝트 살펴보기
불러오는 중…