Skip to content

Repository files navigation

alignrl

PyPIPython 3.10+License: MITTests

From base model to deployed reasoning agent - every LLM post-training technique, implemented and benchmarked.

What is this?

A Python package implementing the complete LLM post-training pipeline: Supervised Fine-Tuning (SFT), Group Relative Policy Optimization (GRPO) with verifiable math rewards, and Direct Preference Optimization (DPO). Includes evaluation benchmarks via lm-evaluation-harness and multi-backend inference serving (Unsloth, vLLM, MLX). Built for learning and demonstration, designed to run on free Colab GPUs with QLoRA and Unsloth for memory-efficient training on Qwen2.5-3B.

Pipeline

graph LR
A[Qwen2.5-3B<br/>Base Model] --> B[SFT<br/>Instruction Following]
B --> C[GRPO<br/>Math Reasoning via RL]
B --> D[DPO<br/>Preference Alignment]
C --> E[Evaluation<br/>GSM8K, MATH, ARC]
D --> E
E --> F[Inference<br/>Unsloth / vLLM / MLX]
Loading

Quick Start

# Install
pip install git+https://github.com/sacredvoid/alignrl.git
# Train (SFT as an example)
alignrl train sft -c configs/sft.yaml
# Evaluate
alignrl eval --adapter ./outputs/sft/final --stage sft
# Launch comparison demo
alignrl serve --stages base sft=./outputs/sft/final grpo=./outputs/grpo/final

For GPU training, install with the train and unsloth extras:

pip install "alignrl[train,unsloth] @ git+https://github.com/sacredvoid/alignrl.git"

Notebooks

Each notebook is self-contained and runs end-to-end on a free Colab T4 GPU.

#NotebookTechniqueColab
01SFT on OpenHermes-2.5Supervised Fine-Tuning with QLoRAOpen in Colab
02GRPO on GSM8KRL with Verifiable Math RewardsOpen in Colab
03DPO on UltraFeedbackDirect Preference OptimizationOpen in Colab
04Benchmark Evaluationlm-evaluation-harness across stagesOpen in Colab
05Inference ComparisonSide-by-side Gradio demoOpen in Colab

Benchmark Results

All evaluations run on Qwen2.5-3B with QLoRA adapters. Best score per benchmark in bold.

BenchmarkMetricBaseSFTGRPODPO
GSM8Kexact_match0.310.450.620.43
MATHexact_match0.120.180.290.17
ARC-Challengeacc_norm0.480.540.520.55

Key takeaways:

  • GRPO dominates math reasoning - GSM8K jumps from 31% to 62% (2x), MATH from 12% to 29% (2.4x)
  • DPO edges out on general reasoning - ARC-Challenge best at 55%, suggesting preference alignment improves broad task quality
  • SFT is a strong baseline - consistent improvement across all benchmarks before any RL

Module Reference

ModulePurposeKey Class
alignrl.sftSupervised Fine-Tuning with QLoRASFTRunner
alignrl.grpoRL with Verifiable Math RewardsGRPORunner
alignrl.dpoDirect Preference OptimizationDPORunner
alignrl.evalBenchmark evaluation harnessEvalRunner
alignrl.inferenceMulti-backend model servingModelServer
alignrl.rewardsMath reward verifiers for GRPOmath_verify_reward
alignrl.demoGradio comparison UIcreate_demo
alignrl.cliCLI entry point (train, eval, serve)main
alignrl.configPydantic-validated training configsBaseTrainConfig
alignrl.typesShared protocols and result typesTrainer, TrainResult, EvalResult

Architecture

The codebase follows a few core design decisions:

  • Pydantic configs - Every training stage uses a typed config class inheriting from BaseTrainConfig, loadable from YAML files. Validation happens at construction time, not at training time.
  • Common Trainer protocol - SFTRunner, GRPORunner, and DPORunner all implement the Trainer protocol (train(), save(), load()), making them interchangeable in pipelines and tests.
  • Lazy imports - Heavy dependencies (torch, transformers, unsloth, vllm, mlx-lm) are imported inside methods, not at module level. The base package installs in seconds with just pydantic and pyyaml.
  • Unsloth for speed - All training uses Unsloth's FastLanguageModel with gradient checkpointing, cutting VRAM usage roughly in half compared to vanilla transformers. Fits Qwen2.5-3B training on a free Colab T4 (16GB).
  • Structured results - Training returns TrainResult, evaluation returns EvalResult. Both are frozen dataclasses that serialize to JSON for the results dashboard.

Project Structure

alignrl/
configs/ # YAML configs for each training stage
docs/ # GitHub Pages results dashboard
notebooks/ # Colab-ready Jupyter notebooks
results/ # Benchmark JSON (consumed by dashboard)
src/alignrl/ # Package source
tests/ # 49 unit tests (pytest)
pyproject.toml # Hatchling build, optional dependency groups

Tech Stack

CategoryTools
TrainingTRL, Unsloth, PEFT, bitsandbytes
Evaluationlm-evaluation-harness
InferencevLLM, MLX-LM, Unsloth
DemoGradio
ConfigPydantic, PyYAML
QualityRuff, mypy, pytest

License

MIT

About

LLM post-training playbook: SFT, GRPO, DPO, eval, and inference. pip install alignrl

Topics

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages