{"id":24756609,"url":"https://github.com/huggingface/open-r1","last_synced_at":"2025-05-13T15:05:03.206Z","repository":{"id":274113166,"uuid":"921777121","full_name":"huggingface/open-r1","owner":"huggingface","description":"Fully open reproduction of DeepSeek-R1","archived":false,"fork":false,"pushed_at":"2025-05-13T12:50:42.000Z","size":1384,"stargazers_count":24382,"open_issues_count":294,"forks_count":2243,"subscribers_count":293,"default_branch":"main","last_synced_at":"2025-05-13T13:53:13.301Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/huggingface.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-01-24T15:44:11.000Z","updated_at":"2025-05-13T13:46:16.000Z","dependencies_parsed_at":"2025-02-11T09:40:47.606Z","dependency_job_id":"dea9c845-6fc8-4325-a99b-8a8c74053dfe","html_url":"https://github.com/huggingface/open-r1","commit_stats":null,"previous_names":["huggingface/open-r1"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huggingface%2Fopen-r1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huggingface%2Fopen-r1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huggingface%2Fopen-r1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huggingface%2Fopen-r1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huggingface","download_url":"https://codeload.github.com/huggingface/open-r1/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253968990,"owners_count":21992261,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-28T14:01:26.091Z","updated_at":"2025-05-13T15:04:58.197Z","avatar_url":"https://github.com/huggingface.png","language":"Python","funding_links":[],"categories":["Python","💼 Projects (blogs, repos, Twitter threads etc.)","others","A01_文本生成_文本对话","Trending LLM Projects","📄 Paper List","Summary","GitHub projects","Uncategorized","Part 1: O1 Replication","RelatedRepos","Codebases"],"sub_categories":["大语言对话模型及数据","Large Language Models","Uncategorized","Replicates of DeepSeek-R1 and DeepSeek-R1-Zero"],"readme":"# Open R1\n\n*A fully open reproduction of DeepSeek-R1. This repo is a work in progress, let's build it together!*\n\n**Table of Contents**  \n1. [Overview](#overview)  \n2. [Plan of attack](#plan-of-attack)  \n3. [Installation](#installation)  \n4. [Training models](#training-models)  \n   - [SFT](#sft)  \n   - [GRPO](#grpo)  \n5. [Evaluating models](#evaluating-models)  \n6. [Reproducing Deepseek's evaluation results](#reproducing-deepseeks-evaluation-results)  \n7. [Data generation](#data-generation)  \n   - [Generate data from a smol distilled R1 model](#generate-data-from-a-smol-distilled-r1-model)  \n   - [Generate data from DeepSeek-R1](#generate-data-from-deepseek-r1)  \n8. [Contributing](#contributing)\n\n## Overview\n\nThe 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:\n\n\n- `src/open_r1`: contains the scripts to train and evaluate models as well as generate synthetic data:\n    - `grpo.py`: trains a model with GRPO on a given dataset.\n    - `sft.py`: performs a simple SFT of a model on a dataset.\n    - `evaluate.py`: evaluates a model on the R1 benchmarks.\n    - `generate.py`: generates synthetic data from a model using [Distilabel](https://github.com/argilla-io/distilabel).\n- `Makefile`: contains easy-to-run commands for each step in the R1 pipeline leveraging the scripts above.\n\n### Plan of attack\n\nWe 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:\n\n* Step 1: replicate the R1-Distill models by distilling a high-quality corpus from DeepSeek-R1.\n* 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.\n* Step 3: show we can go from base model to RL-tuned via multi-stage training.\n\n\u003ccenter\u003e\n    \u003cimg src=\"assets/plan-of-attack.png\" width=\"500\"\u003e\n\u003c/center\u003e\n\n## News 🗞️\n\n* **⚡️ [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.\n* **∞ [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.\n* **🔥 [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!  \n\n## Installation\n\n\u003e [!CAUTION]\n\u003e 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`.\n\nTo run the code in this project, first, create a Python virtual environment using e.g. `uv`.\nTo install `uv`, follow the [UV Installation Guide](https://docs.astral.sh/uv/getting-started/installation/).\n\n\n\u003e [!NOTE]\n\u003e As a shortcut, run `make install` to setup development libraries (spelled out below). Afterwards, if everything is setup correctly you can try out the Open-R1 models.\n\n\n```shell\nuv venv openr1 --python 3.11 \u0026\u0026 source openr1/bin/activate \u0026\u0026 uv pip install --upgrade pip\n```\n\n\u003e [!TIP]\n\u003e For Hugging Face cluster users, add `export UV_LINK_MODE=copy` to your `.bashrc` to suppress cache warnings from `uv`\n\nNext, install vLLM and FlashAttention:\n\n```shell\nuv pip install vllm==0.8.4\nuv pip install setuptools \u0026\u0026 uv pip install flash-attn --no-build-isolation\n```\n\nThis 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:\n\n```shell\nGIT_LFS_SKIP_SMUDGE=1 uv pip install -e \".[dev]\"\n```\n\nNext, log into your Hugging Face and Weights and Biases accounts as follows:\n\n```shell\nhuggingface-cli login\nwandb login\n```\n\nFinally, check whether your system has Git LFS installed so that you can load and push models/datasets to the Hugging Face Hub:\n\n```shell\ngit-lfs --version\n```\n\nIf it isn't installed, run:\n\n```shell\nsudo apt-get install git-lfs\n```\n\n## Training models\n\n\u003e [!NOTE]\n\u003e 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.\n\nWe support training models with either DDP or DeepSpeed (ZeRO-2 and ZeRO-3). For example, to run SFT on a dataset distilled from DeepSeek-R1 with reasoning traces such as [open-r1/OpenR1-Math-220k](https://huggingface.co/datasets/open-r1/OpenR1-Math-220k), run:\n\n```shell\n# Train via command line\naccelerate launch --config_file=recipes/accelerate_configs/zero3.yaml src/open_r1/sft.py \\\n    --model_name_or_path Qwen/Qwen2.5-1.5B-Instruct \\\n    --dataset_name open-r1/OpenR1-Math-220k \\\n    --learning_rate 5.0e-5 \\\n    --num_train_epochs 1 \\\n    --max_seq_length 16384 \\\n    --per_device_train_batch_size 16 \\\n    --gradient_checkpointing \\\n    --bf16 \\\n    --use_liger_kernel \\\n    --output_dir data/Qwen2.5-1.5B-Open-R1-Distill\n\n# Train via YAML config\naccelerate launch --config_file recipes/accelerate_configs/zero3.yaml src/open_r1/sft.py \\\n    --config recipes/Qwen2.5-1.5B-Instruct/sft/config_demo.yaml\n```\n\nCurrently, the following tasks are supported:\n\n* Supervised Fine-Tuning `sft`\n* Group Relative Policy Optimization `grpo`\n\n\u003e [!TIP]\n\u003e 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.\n\nBy 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: \n\n```shell\n# Change batch size, number of epochs etc\naccelerate launch --config_file recipes/accelerate_configs/zero3.yaml src/open_r1/sft.py \\\n    --config recipes/Qwen2.5-1.5B-Instruct/sft/config_demo.yaml\n    --per_device_train_batch_size=1 --num_train_epochs=5\n```\n\nIf you also wish to override the Weights and Biases default settings, you can do so as follows:\n\n```shell\naccelerate launch --config_file recipes/accelerate_configs/zero3.yaml src/open_r1/sft.py \\\n    --config recipes/Qwen2.5-1.5B-Instruct/sft/config_demo.yaml\n    --wandb_entity huggingface --wandb_project open-r1 --run_name Qwen2.5-1.5B-GRPO\n```\n\n**🚨 WARNING 🚨**\n\nMost 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.\n\n```diff\n# Align EOS token with chat template for Qwen base models\naccelerate launch --config_file=recipes/accelerate_configs/zero3.yaml src/open_r1/sft.py \\\n    --model_name_or_path Qwen/Qwen2.5-1.5B \\\n+   --eos_token '\u003c|im_end|\u003e'\n    --dataset_name open-r1/OpenR1-Math-220k \\\n    --learning_rate 5.0e-5 \\\n    --num_train_epochs 1 \\\n    --max_seq_length 16384 \\\n    --per_device_train_batch_size 16 \\\n    --gradient_checkpointing \\\n    --bf16 \\\n    --use_liger_kernel \\\n    --output_dir data/Qwen2.5-1.5B-Open-R1-Distill\n```\n\nIf you wish to use a custom chat template (e.g. Llama or Gemma), then the chat template and associated EOS token must be provided:\n\n```diff\n# Align EOS token with custom chat template\naccelerate launch --config_file=recipes/accelerate_configs/zero3.yaml src/open_r1/sft.py \\\n    --model_name_or_path meta-llama/Llama-3.2-1B \\\n+   --chat_template \"$(cat llama_chat_template.jinja)\" \\\n+   --eos_token '\u003c|eot_id|\u003e' \\\n    --dataset_name open-r1/OpenR1-Math-220k \\\n    --learning_rate 5.0e-5 \\\n    --num_train_epochs 1 \\\n    --max_seq_length 16384 \\\n    --per_device_train_batch_size 16 \\\n    --gradient_checkpointing \\\n    --bf16 \\\n    --use_liger_kernel \\\n    --output_dir data/Llama-3.2-1B-Open-R1-Distill\n```\n\n### SFT\n\nTo run SFT on a dataset distilled from DeepSeek-R1 with reasoning traces such as [open-r1/OpenR1-Math-220k](https://huggingface.co/datasets/open-r1/OpenR1-Math-220k), run:\n\n```shell\nACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/zero3.yaml \\\n    src/open_r1/sft.py \\\n    --config recipes/Qwen2.5-1.5B-Instruct/sft/config_demo.yaml\n```\n\n### GRPO\n\nWe 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, first spin up the vLLM server to run on e.g. 1 GPU as follows:\n\n```shell\nCUDA_VISIBLE_DEVICES=0 trl vllm-serve --model deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B\n```\n\nOnce the server is up, run training on the remaining GPUs as follows:\n\n```shell\nCUDA_VISIBLE_DEVICES=1,2,3,4,5,6,7 ACCELERATE_LOG_LEVEL=info \\\n    accelerate launch --config_file recipes/accelerate_configs/zero2.yaml --num_processes 7 \\\n    src/open_r1/grpo.py --config recipes/DeepSeek-R1-Distill-Qwen-1.5B/grpo/config_demo.yaml\n```\n\n\u003e [!WARNING]\n\u003e The chat template used in the distilled DeepSeek models omits the contents of the reasoning block within the `\u003cthink\u003e` and `\u003c/think\u003e` tags. It also prefills the assistant response with `\u003cthink\u003e` 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](./recipes/DeepSeek-R1-Distill-Qwen-1.5B/grpo/config_demo.yaml).\n\nTo increase the throughput with data parallel on e.g. 2 GPUs, run:\n\n```shell\nCUDA_VISIBLE_DEVICES=0,1 trl vllm-serve --model deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B --data_parallel_size 2\n```\n\nThen run training on the remaining GPUs as follows:\n\n```shell\nCUDA_VISIBLE_DEVICES=2,3,4,5,6,7 ACCELERATE_LOG_LEVEL=info \\\n    accelerate launch --config_file recipes/accelerate_configs/zero2.yaml --num_processes 6 \\\n    src/open_r1/grpo.py --config recipes/DeepSeek-R1-Distill-Qwen-1.5B/grpo/config_demo.yaml\n```\n\nFor larger models, use tensor parallelism:\n\n```shell\nCUDA_VISIBLE_DEVICES=0,1 trl vllm-serve --model deepseek-ai/DeepSeek-R1-Distill-Qwen-14B --tensor_parallel_size 2\n``` \n\nFor 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:\n\n```shell\nsbatch --nodes=2 slurm/train.slurm --model Qwen2.5-1.5B-Instruct --task grpo --config demo --accelerator zero2 --dp 8 --tp 1\n```\n\nSee the [Launching jobs on a Slurm cluster](#launching-jobs-on-a-slurm-cluster) section for more details.\n\n#### 👨‍💻 Training with a code interpreter\n\nWe 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 use [E2B](https://e2b.dev) sandboxes, which are fast and cheap to run. To use this reward function, first install the necessary dependencies:\n\n```shell\nuv pip install -e '.[code]'\n```\n\nThen create a `.env` file and place an API token from E2B within it:\n\n```\nE2B_API_KEY=\"e2b_xxx\"\n```\n\nThen 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):\n\n```python\n{\n    \"language\": \"python\",\n    \"test_cases\": [\n        {\n            \"input\": \"4\\n4\\n0001\\n1000\\n0011\\n0111\\n3\\n010\\n101\\n0\\n2\\n00000\\n00001\\n4\\n01\\n001\\n0001\\n00001\\n\",\n            \"output\": \"1\\n3 \\n-1\\n0\\n\\n2\\n1 2 \\n\",\n            \"type\": \"stdin_stdout\",\n        }\n    ],\n}\n```\n\nFor example, to train a smol model on Python problems, start the vLLM server:\n\n```shell\nCUDA_VISIBLE_DEVICES=0 trl vllm-serve --model Qwen/Qwen2.5-1.5B-Instruct\n```\n\nThen run training with:\n\n```shell\nCUDA_VISIBLE_DEVICES=1,2,3,4,5,6,7 ACCELERATE_LOG_LEVEL=info \\\n    accelerate launch --config_file recipes/accelerate_configs/zero2.yaml --num_processes=7 \\\n    src/open_r1/grpo.py --config recipes/Qwen2.5-1.5B-Instruct/grpo/config_demo_code.yaml\n```\n\nIt is possible to be rate limited when too many scripts are executed on E2B Sandboxes, so we provide an E2B router script that can be launched on a CPU node on your cluster:\n\nFor GRPO training:\nFirst start the router and get its IP\n\n```shell\nsbatch slurm/e2b_router.slurm\n```\n\nThen add this line in your training YAML config: (for example)\n```\ne2b_router_url: 1.2.3.4:8000\n```\nThe port here should match the one used when launching the router.\nAll training jobs can share the same router IP which will ensure there are at most 20 parallel executions.\n\n#### IOI problems\n\nWe provide a `ioi_code_reward` reward function for executing problems from [IOI](https://hf.co/datasets/open-r1/ioi) using [piston](https://github.com/engineer-man/piston).\n\nTo get piston workers running, see [slurm/piston/README.md](./slurm/piston/README.md).\nSet your environment variable `PISTON_ENDPOINTS` to `slurm` or to a list of piston worker endpoints.\n\nSee the [example recipe](./recipes/Qwen2.5-1.5B-Instruct/grpo/config_demo_code_ioi.yaml) for how to use the reward function:\n\n```shell\nACCELERATE_LOG_LEVEL=info accelerate launch --config_file recipes/accelerate_configs/zero2.yaml \\\n    --num_processes=7 src/open_r1/grpo.py \\\n    --config recipes/Qwen2.5-1.5B-Instruct/grpo/config_demo_code_ioi.yaml\n```\n\n### Launching jobs on a Slurm cluster\n\nIf you have access to a Slurm cluster, we provide a `slurm/train.slurm` script that will automatically queue training jobs for you. Here's how you can use it:\n\n```shell\nsbatch --job-name=open_r1 --nodes=1 slurm/train.slurm --model {model_name} --task {task} --config {config_suffix} --accelerator {accelerator}\n```\n\nHere `{model_name}` and `{task}` are defined as above, while `{config_suffix}` refers to the specific config and `{accelerator}` refers to the choice of 🤗 Accelerate config in `recipes/accelerate_configs`. If you wish to override the default config parameters, you can provide them by appending a space-separated string like `'--arg1=value1 --arg2=value2'`. Here's a concrete example to run SFT on 1 node of 8 GPUs:\n\n```shell\nsbatch --job-name=open_r1 --nodes=1 slurm/train.slurm --model Qwen2.5-1.5B-Instruct --task sft --config demo --accelerator zero3\n```\n\nYou can scale the number of nodes by increasing the `--nodes` flag.\n\nFor GRPO, we use 1 node for the vLLM server and N nodes for training. For example, to run GRPO on 1+1 nodes with mixed data and tensor parallelism, run:\n\n```shell\nsbatch --job-name=open_r1 --nodes=2 slurm/train.slurm --model Qwen2.5-1.5B-Instruct --task grpo --config demo --accelerator zero2 --dp 4 --tp 2\n```\n\n\u003e [!NOTE]\n\u003e The configuration in `slurm/train.slurm` is optimised for the Hugging Face Compute Cluster and may require tweaking to be adapted to your own compute nodes.\n\n## Evaluating models\n\nWe use `lighteval` to evaluate models. For models which fit on a single GPU, run:\n\n```shell\nexport VLLM_WORKER_MULTIPROC_METHOD=spawn # Required for vLLM\nMODEL=deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B\nMODEL_ARGS=\"model_name=$MODEL,dtype=bfloat16,max_model_length=32768,gpu_memory_utilization=0.8,generation_parameters={max_new_tokens:32768,temperature:0.6,top_p:0.95}\"\nOUTPUT_DIR=data/evals/$MODEL\n\n# AIME 2024\nTASK=aime24\nlighteval vllm $MODEL_ARGS \"lighteval|$TASK|0|0\" \\\n    --use-chat-template \\\n    --output-dir $OUTPUT_DIR\n\n# MATH-500\nTASK=math_500\nlighteval vllm $MODEL_ARGS \"lighteval|$TASK|0|0\" \\\n    --use-chat-template \\\n    --output-dir $OUTPUT_DIR\n\n# GPQA Diamond\nTASK=gpqa:diamond\nlighteval vllm $MODEL_ARGS \"lighteval|$TASK|0|0\" \\\n    --use-chat-template \\\n    --output-dir $OUTPUT_DIR\n\n# LiveCodeBench\nlighteval vllm $MODEL_ARGS \"extended|lcb:codegeneration|0|0\" \\\n    --use-chat-template \\\n    --output-dir $OUTPUT_DIR \n```\n\nTo increase throughput across multiple GPUs, use _data parallel_ as follows:\n\n```shell\nNUM_GPUS=8\nMODEL=deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B\nMODEL_ARGS=\"model_name=$MODEL,dtype=bfloat16,data_parallel_size=$NUM_GPUS,max_model_length=32768,gpu_memory_utilization=0.8,generation_parameters={max_new_tokens:32768,temperature:0.6,top_p:0.95}\"\nTASK=aime24\nOUTPUT_DIR=data/evals/$MODEL\n\nlighteval vllm $MODEL_ARGS \"lighteval|$TASK|0|0\" \\\n    --use-chat-template \\\n    --output-dir $OUTPUT_DIR\n```\n\nFor large models which require sharding across GPUs, use _tensor parallel_ and run:\n\n```shell\nNUM_GPUS=8\nMODEL=deepseek-ai/DeepSeek-R1-Distill-Qwen-32B\nMODEL_ARGS=\"model_name=$MODEL,dtype=bfloat16,tensor_parallel_size=$NUM_GPUS,max_model_length=32768,gpu_memory_utilization=0.8,generation_parameters={max_new_tokens:32768,temperature:0.6,top_p:0.95}\"\nTASK=aime24\nOUTPUT_DIR=data/evals/$MODEL\n\nexport VLLM_WORKER_MULTIPROC_METHOD=spawn\nlighteval vllm $MODEL_ARGS \"lighteval|$TASK|0|0\" \\\n    --use-chat-template \\\n    --output-dir $OUTPUT_DIR\n```\n\nYou can also launch an evaluation with `make evaluate`, specifying the model, task, and optionally the parallelism technique and number of GPUs.\n\nTo evaluate on a single GPU:\n\n```shell\nmake evaluate MODEL=deepseek-ai/DeepSeek-R1-Distill-Qwen-32B TASK=aime24\n```\n\nTo use Data Parallelism:\n\n```shell\nmake evaluate MODEL=deepseek-ai/DeepSeek-R1-Distill-Qwen-32B TASK=aime24 PARALLEL=data NUM_GPUS=8\n```\n\nTo use Tensor Parallelism:\n\n```shell\nmake evaluate MODEL=deepseek-ai/DeepSeek-R1-Distill-Qwen-32B TASK=aime24 PARALLEL=tensor NUM_GPUS=8\n```\n\n## Reproducing Deepseek's evaluation results\n\n\u003e [!NOTE]\n\u003e The DeepSeek-R1 paper uses sampling with 4-64 responses per query to estimate `pass@1` accuracy, but does not specify the specific number of responses per benchmark. For AIME 2024, we report the results from sampling 32 response per query, while for all others we report the accuracy from sampling 1 response. These choices likely explains the small 1-3σ discrepancies between our results and DeepSeek's.\n\n### AIME 2024\n\nWe are able to reproduce Deepseek's reported results on the AIME 2024 benchmark within ~1-3 standard deviations:\n\n| Model                         | AIME 2024 (🤗 LightEval) | AIME 2024 (DeepSeek Reported) |\n|:------------------------------|:-----------------------:|:----------------------------:|\n| DeepSeek-R1-Distill-Qwen-1.5B |          30.6           |             28.9             |\n| DeepSeek-R1-Distill-Qwen-7B   |          52.8           |             55.5             |\n| DeepSeek-R1-Distill-Qwen-14B  |          65.6           |             69.7             |\n| DeepSeek-R1-Distill-Qwen-32B  |          71.0           |             72.6             |\n| DeepSeek-R1-Distill-Llama-8B  |          44.8           |             41.7             |\n| DeepSeek-R1-Distill-Llama-70B |          63.0           |             70.0             |\n\nTo reproduce these results use the following command:\n\n```shell\nNUM_GPUS=1 # Set to 8 for 32B and 70B models\nMODEL=deepseek-ai/{model_name}\nMODEL_ARGS=\"model_name=$MODEL,dtype=bfloat16,max_model_length=32768,gpu_memory_utilization=0.8,data_parallel_size=$NUM_GPUS,generation_parameters={max_new_tokens:32768,temperature:0.6,top_p:0.95}\"\nOUTPUT_DIR=data/evals/$MODEL\n\nlighteval vllm $MODEL_ARGS \"lighteval|aime24|0|0\" \\\n    --use-chat-template \\\n    --output-dir $OUTPUT_DIR\n```\n\nAlternatively, you can launch Slurm jobs as follows:\n\n```shell\npython scripts/run_benchmarks.py --model-id {model_id}  --benchmarks aime24\n```\n\n### MATH-500\n\nWe are able to reproduce Deepseek's reported results on the MATH-500 benchmark within ~1-3 standard deviations:\n\n| Model                         | MATH-500 (🤗 LightEval) | MATH-500 (DeepSeek Reported) |\n|:------------------------------|:-----------------------:|:----------------------------:|\n| DeepSeek-R1-Distill-Qwen-1.5B |          84.4           |             83.9             |\n| DeepSeek-R1-Distill-Qwen-7B   |          94.4           |             92.8             |\n| DeepSeek-R1-Distill-Qwen-14B  |          94.2           |             93.9             |\n| DeepSeek-R1-Distill-Qwen-32B  |          95.8           |             94.3             |\n| DeepSeek-R1-Distill-Llama-8B  |          88.4           |             89.1             |\n| DeepSeek-R1-Distill-Llama-70B |          96.0           |             94.5             |\n\nTo reproduce these results use the following command:\n\n```shell\nexport VLLM_WORKER_MULTIPROC_METHOD=spawn\nNUM_GPUS=1 # Set to 8 for 32B and 70B models\nMODEL=deepseek-ai/{model_name}\nMODEL_ARGS=\"model_name=$MODEL,dtype=bfloat16,max_model_length=32768,gpu_memory_utilization=0.8,data_parallel_size=$NUM_GPUS,generation_parameters={max_new_tokens:32768,temperature:0.6,top_p:0.95}\"\nOUTPUT_DIR=data/evals/$MODEL\n\nlighteval vllm $MODEL_ARGS \"lighteval|math_500|0|0\" \\\n    --use-chat-template \\\n    --output-dir $OUTPUT_DIR\n```\n\nAlternatively, you can launch Slurm jobs as follows:\n\n```shell\npython scripts/run_benchmarks.py --model-id {model_id}  --benchmarks math_500\n```\n\n### GPQA Diamond\n\nWe are able to reproduce Deepseek's reported results on the GPQA Diamond benchmark within ~1-3 standard deviations:\n\n| Model                         | GPQA Diamond (🤗 LightEval) | GPQA Diamond (DeepSeek Reported) |\n|:------------------------------|:---------------------------:|:--------------------------------:|\n| DeepSeek-R1-Distill-Qwen-1.5B |            36.9             |               33.8               |\n| DeepSeek-R1-Distill-Qwen-7B   |            51.6             |               49.1               |\n| DeepSeek-R1-Distill-Qwen-14B  |            59.6             |               59.1               |\n| DeepSeek-R1-Distill-Qwen-32B  |            63.1             |               62.1               |\n| DeepSeek-R1-Distill-Llama-8B  |            54.0             |               49.0               |\n| DeepSeek-R1-Distill-Llama-70B |            68.2             |               65.2               |\n\nTo reproduce these results use the following command:\n\n```shell\nexport VLLM_WORKER_MULTIPROC_METHOD=spawn\nNUM_GPUS=1 # Set to 8 for 32B and 70B models\nMODEL=deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B\nMODEL_ARGS=\"model_name=$MODEL,dtype=bfloat16,max_model_length=32768,gpu_memory_utilization=0.8,generation_parameters={max_new_tokens:32768,temperature:0.6,top_p:0.95}\"\nOUTPUT_DIR=data/evals/$MODEL\n\nlighteval vllm $MODEL_ARGS \"lighteval|gpqa:diamond|0|0\" \\\n    --use-chat-template \\\n    --output-dir $OUTPUT_DIR\n```\n\n```shell\npython scripts/run_benchmarks.py --model-id {model_id}  --benchmarks gpqa\n```\n\n### LiveCodeBench\n\nWe are able to reproduce Deepseek's reported results on the LiveCodeBench code generation benchmark within ~1-3 standard deviations:\n\n| Model                         | LiveCodeBench (🤗 LightEval) | LiveCodeBench (DeepSeek Reported) |\n|:------------------------------|:----------------------------:|:--------------------------------:|\n| DeepSeek-R1-Distill-Qwen-1.5B |             16.1             |               16.9               |\n| DeepSeek-R1-Distill-Qwen-7B   |             37.4             |               37.6               |\n| DeepSeek-R1-Distill-Qwen-14B  |             51.3             |               53.1               |\n| DeepSeek-R1-Distill-Qwen-32B  |             56.0             |               57.2               |\n| DeepSeek-R1-Distill-Llama-8B  |             37.4             |               39.6               |\n| DeepSeek-R1-Distill-Llama-70B |             55.9             |               57.5               |\n\nTo reproduce these results use the following command:\n\n```shell\nNUM_GPUS=1 # Set to 8 for 32B and 70B models, or data_parallel_size=8 with the smaller models for speed\nMODEL=deepseek-ai/{model_name}\nMODEL_ARGS=\"model_name=$MODEL,dtype=bfloat16,max_model_length=32768,gpu_memory_utilization=0.8,data_parallel_size=$NUM_GPUS,generation_parameters={max_new_tokens:32768,temperature:0.6,top_p:0.95}\"\nOUTPUT_DIR=data/evals/$MODEL\n\nlighteval vllm $MODEL_ARGS \"extended|lcb:codegeneration|0|0\" \\\n    --use-chat-template \\\n    --output-dir $OUTPUT_DIR\n```\n\n```shell\npython scripts/run_benchmarks.py --model-id {model_id}  --benchmarks lcb\n```\n\n## Data generation\n\n### Generate data from a smol distilled R1 model\n\nThe following example can be run in 1xH100. \nFirst install the following dependencies:\n\n```shell\nuv pip install \"distilabel[vllm]\u003e=1.5.2\"\n```\n\nNow save the following snippet into a file named `pipeline.py` and run it with `python pipeline.py`. It will generate 4 outputs for each of the 10 examples (change the username for the repository to your org/user name):\n\n```python\nfrom datasets import load_dataset\nfrom distilabel.models import vLLM\nfrom distilabel.pipeline import Pipeline\nfrom distilabel.steps.tasks import TextGeneration\n\n\nprompt_template = \"\"\"\\\nYou will be given a problem. Please reason step by step, and put your final answer within \\boxed{}:\n{{ instruction }}\"\"\"\n\ndataset = load_dataset(\"AI-MO/NuminaMath-TIR\", split=\"train\").select(range(10))\n\nmodel_id = \"deepseek-ai/DeepSeek-R1-Distill-Qwen-7B\"  # Exchange with another smol distilled r1\n\nwith Pipeline(\n    name=\"distill-qwen-7b-r1\",\n    description=\"A pipeline to generate data from a distilled r1 model\",\n) as pipeline:\n\n    llm = vLLM(\n        model=model_id,\n        tokenizer=model_id,\n        extra_kwargs={\n            \"tensor_parallel_size\": 1,\n            \"max_model_len\": 8192,\n        },\n        generation_kwargs={\n            \"temperature\": 0.6,\n            \"max_new_tokens\": 8192,\n        },\n    )\n    prompt_column = \"problem\"\n    text_generation = TextGeneration(\n        llm=llm, \n        template=prompt_template,\n        num_generations=4,\n        input_mappings={\"instruction\": prompt_column} if prompt_column is not None else {}\n    )\n\n\nif __name__ == \"__main__\":\n    distiset = pipeline.run(dataset=dataset)\n    distiset.push_to_hub(repo_id=\"username/numina-deepseek-r1-qwen-7b\")\n```\n\nTake a look at the sample dataset at [HuggingFaceH4/numina-deepseek-r1-qwen-7b](https://huggingface.co/datasets/HuggingFaceH4/numina-deepseek-r1-qwen-7b).\n\n\n### Generate data from DeepSeek-R1\n\nTo run the bigger DeepSeek-R1, we used 2 nodes, each with 8×H100 GPUs using the slurm file present in this repo at `slurm/generate.slurm`. First, install the dependencies:\n\n(for now we need to install the vllm dev wheel that [fixes the R1 cuda graph capture](https://github.com/vllm-project/vllm/commits/221d388cc5a836fa189305785ed7e887cea8b510/csrc/moe/moe_align_sum_kernels.cu))\n```shell\npip install https://wheels.vllm.ai/221d388cc5a836fa189305785ed7e887cea8b510/vllm-1.0.0.dev-cp38-abi3-manylinux1_x86_64.whl --extra-index-url https://download.pytorch.org/whl/cu121\n\nuv pip install \"distilabel[vllm,ray,openai]\u003e=1.5.2\"\n```\n\nAnd then run the following command:\n\n```shell\nsbatch slurm/generate.slurm \\\n    --hf-dataset AI-MO/NuminaMath-TIR \\\n    --temperature 0.6 \\\n    --prompt-column problem \\\n    --model deepseek-ai/DeepSeek-R1 \\\n    --hf-output-dataset username/r1-dataset\n```\n\n\u003e [!NOTE]  \n\u003e While the job is running, you can setup an SSH tunnel through the cluster login node to access the Ray dashboard from your computer running `ssh -L 8265:ray_ip_head_node:8265 \u003clogin_node\u003e`, then browsing `http://localhost:8265`\n\n\n### Data decontamination\n\nFollowing [s1: Simple test-time scaling](https://arxiv.org/abs/2501.19393) the data can be decontaminated using the script at: [scripts/decontaminate.py](./scripts/decontaminate.py), which decontaminates a dataset using 8-grams and deduplicate the data. Sample run:\n\n```shell\npython scripts/decontaminate.py \\\n    --dataset \"open-r1/verifiable-coding-problems-python\" \\\n    --problem_column problem \\\n    --cleanup\n```\n\nIt will decontaminate against the benchmark datasets, and remove the contaminated samples afterwards. If no argument `--new_dataset_name` is provided, the same dataset will be reused, adding a `_decontaminated`. It runs against the prompt, which for this dataset is the column `problem`, but a different one can be provided.\n\nArguments for the script:\n\n```shell\nusage: decontaminate.py [-h] --dataset DATASET [--split SPLIT] [--ngram_size NGRAM_SIZE] [--problem_column PROBLEM_COLUMN] [--cleanup] [--new_dataset_name NEW_DATASET_NAME]\n\noptions:\n  -h, --help            show this help message and exit\n  --dataset DATASET     Name of the dataset to check for contamination.\n  --split SPLIT         Split to check for contamination, defaults to `train`.\n  --ngram_size NGRAM_SIZE\n                        Size of n-grams to build, defaults to 8.\n  --problem_column PROBLEM_COLUMN\n                        Name of the column containing the problem (prompt).\n  --cleanup           Whether to remove the contaminated rows before pushing the dataset.\n  --new_dataset_name NEW_DATASET_NAME\n                        New name for the dataset. If not provided, will reuse the name and add a `_decontaminated` to the name.\n```\n\n## Contributing\n\nContributions are welcome. Please refer to https://github.com/huggingface/open-r1/issues/23.\n\n## Acknowledgements\n\nThis project is built with the collective efforts of many groups and individuals in the open AI community. We are especially grateful to the vLLM and SGLang teams for creating high-performance tooling to scale the rollouts of GRPO. We also thank the teams at [OpenThoughts](https://www.open-thoughts.ai), [Prime Intellect](https://www.primeintellect.ai), and [General Reasoning](https://gr.inc) for creating and sharing high-quality datasets for reasoning.\n\n## Citation\n\nIf you find this project is useful in your own work, please consider citing as follows:\n\n```\n@misc{openr1,\n    title = {Open R1: A fully open reproduction of DeepSeek-R1},\n    url = {https://github.com/huggingface/open-r1},\n    author = {Hugging Face},\n    month = {January},\n    year = {2025}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuggingface%2Fopen-r1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuggingface%2Fopen-r1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuggingface%2Fopen-r1/lists"}