RLHF_in_notebooks  by ash80

RLHF implementation for LLM alignment

Created 1 year ago
252 stars

Top 99.6% on SourcePulse

GitHubView on GitHub
Project Summary

<2-3 sentences summarising what the project addresses and solves, the target audience, and the benefit.> This repository offers a practical, step-by-step implementation of Reinforcement Learning from Human Feedback (RLHF) for aligning Large Language Models (LLMs). Targeting engineers and researchers, it demystifies RLHF through three focused Jupyter notebooks, enabling hands-on understanding and application of LLM alignment techniques.

How It Works

The project implements RLHF in three stages using Jupyter notebooks: Supervised Fine-Tuning (SFT) adapts a pre-trained GPT-2 model to a target domain (movie review sentiment using SST2). A Reward Model (RM) is then trained on the same dataset to predict sentiment scores, mimicking human preferences. Finally, Proximal Policy Optimization (PPO) fine-tunes the SFT model, using the RM to guide generation towards desired outputs (positive sentiment sentences). This modular, notebook-driven approach simplifies the complex RLHF pipeline.

Quick Start & Requirements

  • Prerequisites: A Hugging Face Access Token is required to download pre-trained models.
  • Setup: Set the token as an environment variable: export HF_TOKEN='your_huggingface_token_here' (local) or within a notebook cell (import os; os.environ['HF_TOKEN'] = 'your_huggingface_token_here').
  • Running: Execute the provided Jupyter notebooks sequentially: 1-SFT.ipynb, 2-RM Training.ipynb, and 3-RLHF.ipynb.
  • Resources: Requires Python environment, Hugging Face libraries. GPU recommended for practical training times.
  • Links: HuggingFace Quickstart Guide for token acquisition.

Highlighted Details

  • Adapts the general RLHF framework to specifically fine-tune GPT-2 for generating positive sentiment sentences, using the Stanford Sentiment Treebank (SST2) dataset.
  • Provides a clear, code-centric walkthrough of each RLHF component (SFT, RM, PPO) within separate, executable notebooks.

Maintenance & Community

No specific details regarding maintainers, community channels (e.g., Discord, Slack), or project roadmap are provided in the README.

Licensing & Compatibility

The repository README does not specify a software license. This lack of explicit licensing information may pose compatibility issues for commercial use or integration into closed-source projects.

Limitations & Caveats

The implementation is presented as a reference for understanding RLHF components and is tailored to a specific task (sentiment generation) using GPT-2 and the SST2 dataset. It may require significant adaptation for other LLMs, tasks, or datasets. No information on alpha status, known bugs, or performance benchmarks is provided.

Health Check
Last Commit

1 year ago

Responsiveness

Inactive

Pull Requests (30d)
0
Issues (30d)
0
Star History
0 stars in the last 30 days

Explore Similar Projects

Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems") and Junyang Lin Junyang Lin(Core Maintainer at Alibaba Qwen).

safe-rlhf by PKU-Alignment

0%
2k
Safe RLHF for constrained value alignment in LLMs
Created 3 years ago
Updated 9 months ago
Starred by Chip Huyen Chip Huyen(Author of "AI Engineering", "Designing Machine Learning Systems"), Wing Lian Wing Lian(Founder of Axolotl AI), and
3 more.

ROLL by alibaba

0%
3k
RL library for large language models
Created 1 year ago
Updated 2 days ago
Feedback? Help us improve.