@Ryrenz: Explosive! Hugging Face fully open-sourced and reproduced the entire training pipeline of DeepSeek-R1. GitHub 26.4k stars, from the official Hugging Face team, the most authoritative one. DeepSeek-R1 amazed everyone, but the real training recipe…
Summary
The official Hugging Face team fully open-sourced and reproduced the entire training pipeline of DeepSeek-R1 (Open-R1 project), including data, training, and evaluation. It has received 26.4k stars on GitHub, providing a reproducible textbook for training reasoning models for the industry.
View Cached Full Text
Cached at: 07/04/26, 12:45 AM
Boom! Hugging Face has completely open-sourced the full training pipeline of DeepSeek-R1 and reproduced it step by step. With 26.4k stars on GitHub, this comes from the official Hugging Face team—the most authoritative take yet. DeepSeek-R1 stunned everyone, but the true training recipe remained out of reach for outsiders. Open-R1 openly reproduces the entire pipeline—from data and training to evaluation—step by step. You can follow along to understand exactly how a reasoning model is trained; it’s a textbook for anyone wanting to train or study reasoning models. For those working on large models, this is a public assignment that tears open the closed-source black box and lays it all on the table. As model capabilities grow stronger, open-sourcing the training process is what truly drives the whole industry forward.
GitHub: —
huggingface/open-r1
Source: https://github.com/huggingface/open-r1
Open R1
A fully open reproduction of DeepSeek-R1. This repo is a work in progress, let’s build it together!
Table of Contents
- Overview
- Plan of attack
- Installation
- Training models
- Evaluating models
- Reproducing Deepseek’s evaluation results
- Data generation
- Contributing
Overview
The goal of this repo is to build the missing pieces of the R1 pipeline such that everybody can reproduce and build on top of it. The project is simple by design and mostly consists of:
src/open_r1: contains the scripts to train models as well as generate synthetic data:grpo.py: trains a model with GRPO on a given dataset.sft.py: performs a simple SFT of a model on a dataset.generate.py: generates synthetic data from a model using Distilabel (https://github.com/argilla-io/distilabel).
Makefile: contains easy-to-run commands for each step in the R1 pipeline leveraging the scripts above.
Plan of attack
We will use the DeepSeek-R1 tech report (https://github.com/deepseek-ai/DeepSeek-R1) as a guide, which can roughly be broken down into three main steps:
- Step 1: replicate the R1-Distill models by distilling a high-quality corpus from DeepSeek-R1.
- Step 2: replicate the pure RL pipeline that DeepSeek used to create R1-Zero. This will likely involve curating new, large-scale datasets for math, reasoning, and code.
- Step 3: show we can go from base model to RL-tuned via multi-stage training.
News 🗞️
- 🧑🍳 [2025/05/26] (Step 1 completed!) We release Mixture-of-Thoughts (https://huggingface.co/datasets/open-r1/Mixture-of-Thoughts)–a curated reasoning dataset of 350k verified traces distilled from R1. The dataset spans tasks in mathematics, coding, and science, and is designed to teach language models to reason step-by-step. We also provide a recipe to train OpenR1-Distill-7B (https://huggingface.co/open-r1/OpenR1-Distill-7B), which replicates the reasoning capabilities of deepseek-ai/DeepSeek-R1-Distill-Qwen-7B (https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B) and marks the completion of step 1 in the Open R1 project.
- ⚡️ [2025/03/11] (update #3) (https://huggingface.co/blog/open-r1/update-3): We release the CodeForces-CoTs (https://huggingface.co/datasets/open-r1/codeforces-cots) dataset of 10k competitive programming problems and 100k solutions distilled from R1. We also release IOI24: a new benchmark of very hard problems from international olympiads. A 7B Qwen model trained on CodeForces-CoTs can outperform Claude 3.7 Sonnet on IOI24, while a 32B model can outperform R1 itself.
- ∞ [2025/02/10] (update #2) (https://huggingface.co/blog/open-r1/update-2): We release the OpenR1-Math-220k (https://huggingface.co/datasets/open-r1/OpenR1-Math-220k) dataset of 220k traces distilled from R1 on a new version of NuminaMath. Models trained on this dataset match the performance of DeepSeek’s distilled ones.
- 🔥 [2025/02/02] (update #1) (https://huggingface.co/blog/open-r1/update-1): We implement the first parts of the training (https://github.com/huggingface/open-r1?tab=readme-ov-file#training-models), inference (https://github.com/huggingface/open-r1?tab=readme-ov-file#data-generation), and evaluation (https://github.com/huggingface/open-r1?tab=readme-ov-file#reproducing-deepseeks-evaluation-results) pipelines. Let’s go!
Installation
Libraries rely on CUDA 12.4. If you see errors related to segmentation faults, double check the version your system is running with
nvcc --version.
To run the code in this project, first, create a Python virtual environment using e.g. uv. To install uv, follow the UV Installation Guide (https://docs.astral.sh/uv/getting-started/installation/).
As a shortcut, run
make installto setup development libraries (spelled out below). Afterwards, if everything is setup correctly you can try out the Open-R1 models.
shell uv venv openr1 --python 3.11 && source openr1/bin/activate && uv pip install --upgrade pip
For Hugging Face cluster users, add
export UV_LINK_MODE=copyto your.bashrcto suppress cache warnings fromuv
Next, install vLLM and FlashAttention:
shell uv pip install vllm==0.8.5.post1 uv pip install setuptools && uv pip install flash-attn --no-build-isolation
This will also install PyTorch v2.6.0 and it is very important to use this version since the vLLM binaries are compiled for it.
You can then install the remaining dependencies for your specific use case via pip install -e .[LIST OF MODES]. For most contributors, we recommend:
shell GIT_LFS_SKIP_SMUDGE=1 uv pip install -e ".[dev]"
Next, log into your Hugging Face and Weights and Biases accounts as follows:
shell huggingface-cli login wandb login
Finally, check whether your system has Git LFS installed so that you can load and push models/datasets to the Hugging Face Hub:
shell git-lfs --version
If it isn’t installed, run:
shell sudo apt-get install git-lfs
Training models
The training commands below are configured for a node of 8 x H100s (80GB). For different hardware and topologies, you may need to tune the batch size and number of gradient accumulation steps.
We support training models with either DDP or DeepSpeed (ZeRO-2 and ZeRO-3). For example, to perform SFT on a dataset distilled from DeepSeek-R1 with reasoning traces such as open-r1/Mixture-of-Thoughts (https://huggingface.co/datasets/open-r1/Mixture-of-Thoughts), run:
``shell
Train via command line
accelerate launch –config_file=recipes/accelerate_configs/zero3.yaml src/open_r1/sft.py \
–model_name_or_path open-r1/Qwen2.5-Math-7B-RoPE-300k \
–dataset_name open-r1/Mixture-of-Thoughts \
–dataset_config all \
–eos_token ‘<|im_end|>’ \
–learning_rate 4.0e-5 \
–num_train_epochs 5 \
–max_seq_length 32768 \
–per_device_train_batch_size 2 \
–gradient_checkpointing \
–bf16 \
–use_liger_kernel \
–output_dir data/OpenR1-Distill-7B
Train via YAML config
accelerate launch –config_file recipes/accelerate_configs/zero3.yaml src/open_r1/sft.py \
–config recipes/OpenR1-Distill-7B/sft/config_distill.yaml
``
Currently, the following tasks are supported:
- Supervised Fine-Tuning
sft - Group Relative Policy Optimization
grpo
If you scale up/down the number of GPUs, we recommend also scaling up the per-device batch size or number of gradient accumulation steps to keep the global batch size constant.
By default, these scripts will push each model to your Hugging Face Hub username, i.e. {username}/{model_name}-{task}. You can override the parameters in each YAML config by appending them to the command as follows:
``shell
Change the base model to a smaller variant
accelerate launch –config_file recipes/accelerate_configs/zero3.yaml src/open_r1/sft.py \
–config recipes/OpenR1-Distill-7B/sft/config_distill.yaml \
–model_name_or_path Qwen/Qwen3-0.6B-Base \
–hub_model_id OpenR1-Distill-0.6B \
–output_dir data/OpenR1-Distill-0.6B
``
If you also wish to override the Weights and Biases default settings, you can do so as follows:
shell accelerate launch --config_file recipes/accelerate_configs/zero3.yaml src/open_r1/sft.py \ --config recipes/OpenR1-Distill-7B/sft/config_distill.yaml --wandb_entity huggingface --wandb_project open-r1 --run_name Qwen2.5-1.5B-GRPO
🚨 WARNING 🚨
Most base models like meta-llama/Llama-3.2-1B do not have a chat template, so we set ChatML as the default during training. However, for Qwen base models like Qwen/Qwen2.5-1.5B, a chat template is pre-defined in the tokenizer, so the EOS token must be set accordingly, e.g.
``diff
Align EOS token with chat template for Qwen base models
accelerate launch –config_file=recipes/accelerate_configs/zero3.yaml src/open_r1/sft.py \
–model_name_or_path Qwen/Qwen2.5-1.5B \
- –eos_token ‘<|im_end|>’
–dataset_name open-r1/Mixture-of-Thoughts \
–dataset_config all \
–learning_rate 4.0e-5 \
–num_train_epochs 1 \
–max_seq_length 32768 \
–per_device_train_batch_size 16 \
–gradient_checkpointing \
–bf16 \
–use_liger_kernel \
–output_dir data/Qwen2.5-1.5B-Open-R1-Distill
``
If you wish to use a custom chat template (e.g. Llama or Gemma), then the chat template and associated EOS token must be provided:
``diff
Align EOS token with custom chat template
accelerate launch –config_file=recipes/accelerate_configs/zero3.yaml src/open_r1/sft.py \
–model_name_or_path meta-llama/Llama-3.2-1B \
- –chat_template “$(cat llama_chat_template.jinja)” \
- –eos_token ‘<|eot_id|>’ \
–dataset_name open-r1/Mixture-of-Thoughts \
–dataset_config all \
–learning_rate 4.0e-5 \
–num_train_epochs 1 \
–max_seq_length 32768 \
–per_device_train_batch_size 16 \
–gradient_checkpointing \
–bf16 \
–use_liger_kernel \
–output_dir data/Llama-3.2-1B-Open-R1-Distill
``
SFT distillation
We provide a recipe to reproduce the reasoning capabilities of deepseek-ai/DeepSeek-R1-Distill-Qwen-7B (https://huggingface.co/deepseek-ai/DeepSeek-R1-Distill-Qwen-7B), starting from the same base model. To do so, run:
shell ACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/zero3.yaml \ src/open_r1/sft.py \ --config recipes/OpenR1-Distill-7B/sft/config_distill.yaml
The result will be a model like open-r1/OpenR1-Distill-7B (https://huggingface.co/open-r1/OpenR1-Distill-7B), with the following downstream performance:
| Model | AIME 2024 | MATH-500 | GPQA Diamond | LiveCodeBench v5 |
|---|---|---|---|---|
| OpenR1-Distill-7B | 52.7 | 89.0 | 52.8 | 39.4 |
| DeepSeek-R1-Distill-Qwen-7B | 51.3 | 93.5 | 52.4 | 37.4 |
You can adjust the YAML config to train on a different base model or dataset.
GRPO
We use TRL’s vLLM backend (https://huggingface.co/docs/trl/speeding_up_training?vllm+examples=GRPO#vllm-for-fast-generation-in-online-methods) to scale training to large models across multiple nodes. For single-node training of smol models across 8 GPUs, use vllm_mode="colocate" to run vLLM in the same process as the training script:
shell ACCELERATE_LOG_LEVEL=info \ accelerate launch --config_file recipes/accelerate_configs/zero3.yaml \ src/open_r1/grpo.py --config recipes/DeepSeek-R1-Distill-Qwen-1.5B/grpo/config_demo.yaml \ --vllm_mode colocate
The chat template used in the distilled DeepSeek models omits the contents of the reasoning block within the
andtags. It also prefills the assistant response with `` which interferes with the format reward function. To handle that, it is important to override the chat template as done in e.g. recipes/DeepSeek-R1-Distill-Qwen-1.5B/grpo/config_demo.yaml.
For multi-node training on N+1 nodes, with 1 node running the vLLM server and N nodes running training, we provide an example Slurm script. For example, to run the above example on 1+1 nodes with data parallelism, run:
shell sbatch --nodes=2 slurm/train.slurm --model Qwen2.5-1.5B-Instruct --task grpo --config demo --accelerator zero2 --dp 8 --tp 1
See the Launching jobs on a Slurm cluster section for more details.
GRPO dataset filtering
We provide support to filter datasets by generating and computing pass rate on veriable tasks, see this README
👨💻 Training with a code interpreter
We provide a code reward function for executing code generated by the policy during training. Currently, this reward function targets code contests like Codeforces (https://codeforces.com), where solutions are executed against a set of test cases and the overall success rate is returned as the final reward. To ensure safe execution, we support multiple sandbox providers:
- E2B (https://e2b.dev) - Fast, cloud-based sandboxes with focus on Python execution
- Morph (https://cloud.morph.so/web/) - Cloud-based sandboxes with broader language support - Python/JS/C++/Rust
To use the code reward function, first install the necessary dependencies:
shell uv pip install -e '.[code]'
E2B Provider
To use E2B sandboxes, create a .env file and add your E2B API token:
E2B_API_KEY="e2b_xxx"
Morph Provider
To use Morph, first install the morphcloud package:
shell pip install morphcloud
Then add your Morph API token to the .env file:
MORPH_API_KEY="YOUR_MORPH_API_KEY"
To specify which provider to use, add the provider_type parameter in your configuration:
``yaml
For E2B
provider_type: e2b
For Morph
provider_type: morph
``
Dataset Requirements
Make sure your dataset contains a verification_info column with the following schema (adopted from PrimeIntellect’s excellent datasets (https://huggingface.co/collections/PrimeIntellect/synthetic-1-67a2c399cfdd6c9f7fae0c37) of verifiable problems):
python { "language": "python", # Morph supports more languages including C++, Java, etc. "test_cases": [ { "input": "4\n4\n0001\n1000\n0011\n0111\n3\n010\n101\n0\n2\n00000\n00001\n4\n01\n001\n0001\n00001\n", "output": "1\n3 \n-1\n0\n\n2\n1 2 \n", "type": "stdin_stdout", } ], }
For example, to train a smol model on Python problems, start the vLLM server:
shell CUDA_VISIBLE_DEVICES=0 trl vllm-serve --model Qwen/Qwen2.5-1.5B-Instruct
Then run training with:
shell CUDA_VISIBLE_DEVICES=1,2,3,4,5,6,7 ACCELERATE_LOG_LEVEL=info \ accelerate launch --config_file recipes/accelerate_configs/zero2.yaml --num_processes=7 \ src/open_r1/grpo.py --config recipes/Qwen2.5-1.5B-Instruct/grpo/config_demo_code.yaml
Using Router Services
It is possible to be rate limited when too many scripts are executed on sandbox services. For both providers, we offer router scripts that can be launched on a CPU node:
For E2B:
shell sbatch slurm/e2b_router.slurm
For Morph:
shell sbatch slurm/morph_router.slurm
Then add the router URL in your training YAML config:
``yaml
For E2B
e2b_router_url: 1.2.3.4:8000
For Morph
morph_router_url: 1.2.3.4:8000
``
The port should match the one used when launching the router. All training jobs can share the same router IP which will ensure parallel executions are properly managed.
Competitive Programming problems: IOI & CodeForces
We provide ioi_code_reward and cf_code_reward reward functions for executing problems from IOI (https://hf.co/datasets/open-r1/ioi) and CodeForces (https://huggingface.co/datasets/open-r1/codeforces), respectively. You can use either piston (https://github.com/engineer-man/piston) or Morph (currently IOI only) as your execution provider.
Piston
To use Piston:
- Get piston workers running, see slurm/piston/README.md
- Set your environment variable
PISTON_ENDPOINTStoslurmor to a list of piston worker endpoints
For IOI:
3. In your configuration, use ioi_provider: "piston"
For CodeForces:
3. Download the generated (hard) test cases:
``
change PATH_TO_SAVE_TESTCASES. Increase –max-workers according to your machine’s capacity
huggingface-cli download open-r1/codeforces –repo-type=dataset –include=‘generated_tests/*.parquet’ –max-workers=8 –local-dir PATH_TO_SAVE_TESTCASES
4. Save the path in .env:
CF_TESTS_FOLDER=PATH_TO_SAVE
Similar Articles
Open Reproduction of DeepSeek-R1
Hugging Face's Open R1 project provides a fully open reproduction pipeline for DeepSeek-R1, including distilled datasets, training scripts, and evaluation tools, with the goal of enabling anyone to replicate and build on top of R1's reasoning capabilities.
@nini_incrypto_: Hugging Face automates entire AI training pipeline! Recently, a project called ml-intern has gone viral on GitHub. It's like a 24/7 algorithmic intern that can independently perform post-training of large models. 1. Autonomous research: It will…
The ml-intern project from Hugging Face has gone viral on GitHub, enabling full automation of the entire workflow including paper research, data processing, training script writing, and model training, without human intervention. It significantly improves the performance of small models (such as Qwen3-1.7B), even surpassing Claude Code.
@wsl8297: For those who usually use DeepSeek for coding, check out DeepSeek-Code-Whale. GitHub: https://github.com/usewhale/DeepSeek-Code-Whale... Open-source terminal AI coding agent, specialized...
DeepSeek-Code-Whale is an open-source terminal AI coding agent, specifically optimized for DeepSeek models, supporting MCP tools, Skills extensions, prefix caching optimization (90% cache hit rate) and 1M context window, aimed at reducing AI coding costs and providing efficient command-line workflows.
@Soranlan: https://x.com/sweexx9/status/2057560520916414628/video/1… This project is definitely going to be popular, but you need to be careful. Someone created a GitHub repo that redirects Claude Code traffic to Dee…
Introduces a GitHub repo that redirects Claude Code traffic to over a dozen free models like DeepSeek and Kimi, already used by 20,000+ developers. The article emphasizes that this tool reveals the trend of replaceability across layers: frontend interaction, workflow, model providers, etc.
@tom_doerr: Fully open sources training data for 30B scale search agents https://github.com/PolarSeeker/OpenSeeker…
OpenSeeker fully open-sources training data and models for 30B-scale ReAct-based search agents, achieving state-of-the-art performance on multiple benchmarks including BrowseComp and Humanity's Last Exam. It is the first purely academic project to reach frontier search benchmark performance while releasing complete training data.