๐Ÿง  RL vs. Distillation: Understanding Accuracy and Capability in LLM Reasoning

May 31, 2025 ยท View on GitHub

This repository contains the code used in the paper:

Reinforcement Learning vs. Distillation: Understanding Accuracy and Capability in LLM Reasoning
Minwu Kim*, Anubhav Shrestha*, Safal Shrestha, Aadim Nepal, Keith Ross

๐Ÿ“„ arXiv:2505.14216 | ๐Ÿค— Hugging Face


๐Ÿงฉ About the Paper

This paper investigates why reinforcement learning with verifiable rewards (RLVR) and distillation have different impacts on large language model (LLM) reasoning. Key findings:

  • RLVR improves accuracy but does not improve capability, due to selective reinforcement of easier questions.
  • Distillation improves both accuracy and capability, but only when it introduces new knowledge.
  • Distilling only reasoning patterns behaves similarly to RLVR, helping with easy questions but failing on hard ones.

Read the full paper ๐Ÿ‘‰ arXiv:2505.14216


๐Ÿ“ Code Structure

.
โ”œโ”€โ”€ environment.yml           # ๐Ÿงช Conda environment file
โ”œโ”€โ”€ zero3.yaml               # โš™๏ธ DeepSpeed Zero3 config for RLVR training
โ”‚
โ”œโ”€โ”€ train/
โ”‚   โ”œโ”€โ”€ RLVR/
โ”‚   โ”‚   โ”œโ”€โ”€ grpo_trainer.py     # RL training script using TRL (GRPO)
โ”‚   โ”‚   โ””โ”€โ”€ grpoconfig.yaml     # Config file for GRPO training
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ Distillation/
โ”‚       โ”œโ”€โ”€ sft_trainer.py      # Supervised fine-tuning script
โ”‚       โ””โ”€โ”€ sftconfig.yaml      # SFT config file
โ”‚
โ””โ”€โ”€ test/
    โ””โ”€โ”€ MATH500_eval.py        # ๐ŸŽฏ Evaluation script on MATH500

โš™๏ธ Environment Setup

Create the conda environment and install dependencies:

conda env create -f environment.yml
conda activate rlvsdistill

Ensure your system supports DeepSpeed and has accelerate configured.


๐Ÿš€ How to Run

๐Ÿ” Evaluation (MATH500)

python test/MATH500_eval.py

๐Ÿงช RLVR Training (GRPO via TRL + VLLM)

We use TRL for policy optimization and VLLM for fast multi-process inference during reward evaluation.

accelerate launch \
  --config_file zero3.yaml \
  --num_processes <NUM_PROCESSES> \
  train/RLVR/grpo_trainer.py

๐Ÿ’ก Note:

  • <NUM_PROCESSES> should be set to the number of available GPUs minus one (โ€“1). This is because VLLM internally uses one process for fast batched model inference, and the remaining processes will be used for parallel reward evaluation.
  • Example: If your machine has 16 logical cores, use --num_processes 15.

๐Ÿ› ๏ธ Edit train/RLVR/grpoconfig.yaml to configure:

  • Base model and reward model paths
  • Dataset locations
  • Sampling parameters
  • Reward functions

๐Ÿ“˜ Distillation Training (SFT)

python train/Distillation/sft_trainer.py --config train/Distillation/sftconfig.yaml

Use the config file to specify:

  • Teacher and student model
  • Number of training steps
  • Prompt format and dataset
  • Saving & logging behavior

๐Ÿ“ฆ Libraries Used

  • ๐Ÿค— Transformers โ€“ model loading and generation
  • ๐Ÿค— TRL โ€“ for RL fine-tuning via GRPO
  • โšก VLLM โ€“ for fast batched generation and reward model inference
  • ๐Ÿงช DeepSpeed โ€“ memory-efficient distributed training

๐Ÿงช Citation

If cite this paper in any form, please refer to the BibTeX citation shown below:

@misc{kim2024reinforcement,
      title={Reinforcement Learning vs. Distillation: Understanding Accuracy and Capability in LLM Reasoning}, 
      author={Minwu Kim and Anubhav Shrestha and Safal Shrestha and Aadim Nepal and Keith Ross},
      year={2024},
      eprint={2505.14216},
      archivePrefix={arXiv},
      primaryClass={cs.AI}
}