Git Product home page Git Product logo

alignment-handbook's Introduction

๐Ÿค— Models & Datasets | ๐Ÿ“ƒ Technical Report

The Alignment Handbook

Robust recipes to align language models with human and AI preferences.

What is this?

Just one year ago, chatbots were out of fashion and most people hadn't heard about techniques like Reinforcement Learning from Human Feedback (RLHF) to align language models with human preferences. Then, OpenAI broke the internet with ChatGPT and Meta followed suit by releasing the Llama series of language models which enabled the ML community to build their very own capable chatbots. This has led to a rich ecosystem of datasets and models that have mostly focused on teaching language models to follow instructions through supervised fine-tuning (SFT).

However, we know from the InstructGPT and Llama2 papers that significant gains in helpfulness and safety can be had by augmenting SFT with human (or AI) preferences. At the same time, aligning language models to a set of preferences is a fairly novel idea and there are few public resources available on how to train these models, what data to collect, and what metrics to measure for best downstream performance.

The Alignment Handbook aims to fill that gap by providing the community with a series of robust training recipes that span the whole pipeline.

News ๐Ÿ—ž๏ธ

  • January 18, 2024: We release a suite of Evalutions of DPO vs KTO vs IPO, see the recipe and the blogpost
  • November 10, 2023: We release all the training code to replicate Zephyr-7b-ฮฒ ๐Ÿช! We also release No Robots, a brand new dataset of 10,000 instructions and demonstrations written entirely by skilled human annotators.

Links ๐Ÿ”—

How to navigate this project ๐Ÿงญ

This project is simple by design and mostly consists of:

  • scripts to train and evaluate chat models. Each script supports distributed training of the full model weights with DeepSpeed ZeRO-3, or LoRA/QLoRA for parameter-efficient fine-tuning.
  • recipes to reproduce models like Zephyr 7B. Each recipe takes the form of a YAML file which contains all the parameters associated with a single training run.

We are also working on a series of guides to explain how methods like direct preference optimization (DPO) work, along with lessons learned from gathering human preferences in practice. To get started, we recommend the following:

  1. Follow the installation instructions to set up your environment etc.
  2. Replicate Zephyr-7b-ฮฒ by following the recipe instructions.

If you would like to train chat models on your own datasets, we recommend following the dataset formatting instructions here.

Contents

The initial release of the handbook will focus on the following techniques:

  • Supervised fine-tuning: teach language models to follow instructions and tips on how to collect and curate your own training dataset.
  • Reward modeling: teach language models to distinguish model responses according to human or AI preferences.
  • Rejection sampling: a simple, but powerful technique to boost the performance of your SFT model.
  • Direct preference optimisation (DPO): a powerful and promising alternative to PPO.

Installation instructions

To run the code in this project, first, create a Python virtual environment using e.g. Conda:

conda create -n handbook python=3.10 && conda activate handbook

Next, install PyTorch v2.1.2 - the precise version is important for reproducibility! Since this is hardware-dependent, we direct you to the PyTorch Installation Page.

You can then install the remaining package dependencies as follows:

git clone https://github.com/huggingface/alignment-handbook.git
cd ./alignment-handbook/
python -m pip install .

You will also need Flash Attention 2 installed, which can be done by running:

python -m pip install flash-attn==2.3.6 --no-build-isolation

Note If your machine has less than 96GB of RAM and many CPU cores, reduce the MAX_JOBS arguments, e.g. MAX_JOBS=4 pip install flash-attn==2.3.6 --no-build-isolation

Next, log into your Hugging Face account as follows:

huggingface-cli login

Finally, install Git LFS so that you can push models to the Hugging Face Hub:

sudo apt-get install git-lfs

You can now check out the scripts and recipes directories for instructions on how to train some models ๐Ÿช!

Project structure

โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ Makefile                    <- Makefile with commands like `make style`
โ”œโ”€โ”€ README.md                   <- The top-level README for developers using this project
โ”œโ”€โ”€ chapters                    <- Educational content to render on hf.co/learn
โ”œโ”€โ”€ recipes                     <- Recipe configs, accelerate configs, slurm scripts
โ”œโ”€โ”€ scripts                     <- Scripts to train and evaluate chat models
โ”œโ”€โ”€ setup.cfg                   <- Installation config (mostly used for configuring code quality & tests)
โ”œโ”€โ”€ setup.py                    <- Makes project pip installable (pip install -e .) so `alignment` can be imported
โ”œโ”€โ”€ src                         <- Source code for use in this project
โ””โ”€โ”€ tests                       <- Unit tests

Citation

If you find the content of this repo useful in your work, please cite it as follows:

@misc{alignment_handbook2023,
  author = {Lewis Tunstall and Edward Beeching and Nathan Lambert and Nazneen Rajani and Alexander M. Rush and Thomas Wolf},
  title = {The Alignment Handbook},
  year = {2023},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/huggingface/alignment-handbook}}
}

alignment-handbook's People

Contributors

lewtun avatar edbeeching avatar dmilcevski avatar nathan-az avatar alvarobartt avatar randl avatar girrajjangid avatar kashif avatar kirill-fedyanin avatar mishig25 avatar natolambert avatar nielsrogge avatar rtrompier avatar scottfleming avatar schram2 avatar anakin87 avatar tcapelle avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.