allenai

RL4LMs: Fine-Tune Language Models with Reinforcement Learning

RL4LMs is a Python library for training language models against custom reward functions using on-policy reinforcement learning. It suits NLP researchers and developers who need configurable training components for text-generation tasks.

Stars
2.4k
Forks
202
Stars, last 8 days
+0

Our take

Health score

24/100

How it is scored
Activity
20
Community
35
Issues
21
Pull requests
21

+0 stars in the last 8 days

Overview

RL4LMs provides building blocks for fine-tuning language models with reinforcement learning, where generated text is optimized against a reward function. It brings together text-generation environments, reward and evaluation components, language-model actor-critic policies, and on-policy algorithms in a configurable workflow.

The library is aimed at researchers and practitioners experimenting with reward-driven NLP training. Its configurable datasets, rewards, and policies make it useful when existing task-specific training code is too rigid, though it is more specialized than a general-purpose language-model training toolkit.

Key Features

  • Implements PPO, A2C, TRPO, and NLPO for on-policy language-model training.
  • Supports actor-critic policies for causal and sequence-to-sequence language models.
  • Provides reward functions based on language-generation metrics and classifier scores.
  • Includes datasets and task configurations for summarization, dialogue, translation, and other text-generation tasks.
  • Lets users extend datasets, rewards, metrics, algorithms, and policies, then register custom components.
  • Uses YAML configurations to connect training components and experiment settings.
  • Supports experiment logging, checkpoint storage, and optional Weights & Biases logging.

Use Cases

  • NLP researchers comparing on-policy algorithms across text-generation tasks and reward functions.
  • Model developers testing whether a custom reward improves a specific generation behavior.
  • Teams adapting a training setup to their own dataset by adding a data pool and reward component.
  • Practitioners benchmarking reinforcement-learning approaches against supervised language-model training.

Getting Started

git clone https://github.com/allenai/RL4LMs.git
cd RL4LMs
pip install -e .

See the README for task configurations, Docker setup, and customization guidance. The project website is rl4lms.apps.allenai.org.

Alternatives

  • Verifiers: Verifiers builds custom environments for LLM training and evaluation, while RL4LMs focuses on configurable on-policy RL algorithms for text generation.
ProjectLanguageLicenseStarsStatus
RL4LMsPythonApache-2.02.4kNot checked yet
verifiersPythonMIT4.7kActive

Considerations

  • Reinforcement-learning fine-tuning involves model training and generation workloads, so plan for the compute and model resources those workloads require.
  • Some metric computations need additional CoreNLP resources, as noted in the README.
  • The repository is not marked archived, but its recorded latest push was 2024-03-01. Check the repository for current dependency compatibility and maintenance status before adopting it for a new project.
  • Its focus is text generation and on-policy reinforcement learning, so it may not fit projects that need a general-purpose training framework or other optimization methods.

Found this useful?

Share it with someone who would like RL4LMs.

Comparisons