This repo implements Group Relative Policy Optimization (GRPO) and Direct Preference Optimization (DPO) from scratch in PyTorch, without relying on off-the-shelf libraries like TRL or VERL.
To open the black box: we unpack the training details—masking, KL penalties, scheduling, and evaluation—so you can see exactly how these algorithms work in practice.
Both evaluation pipelines are included.
The scripts default to multi-GPU training with PyTorch DDP, and can be easily adapted to a single GPU by adjusting the launch command and disabling distributed initialization. The evaluation is preformed using a single GPU.
Training:
torchrun --standalone --nproc_per_node=8 dpo/grpo_train_from_scratch.py
Evaluation:
python dpo/grpo_evaluation.py
I’ve written down explanation of the two algorithms in the following blogs:
1 commits
Python
100.0%
This repo implements Group Relative Policy Optimization (GRPO) and Direct Preference Optimization (DPO) from scratch in PyTorch, without relying on off-the-shelf libraries like TRL or VERL.
To open the black box: we unpack the training details—masking, KL penalties, scheduling, and evaluation—so you can see exactly how these algorithms work in practice.
Both evaluation pipelines are included.
The scripts default to multi-GPU training with PyTorch DDP, and can be easily adapted to a single GPU by adjusting the launch command and disabling distributed initialization. The evaluation is preformed using a single GPU.
Training:
torchrun --standalone --nproc_per_node=8 dpo/grpo_train_from_scratch.py
Evaluation:
python dpo/grpo_evaluation.py
I’ve written down explanation of the two algorithms in the following blogs:
1 commits
Python
100.0%