SuperAPI AI Directory

safe-rlhf

Constrained value alignment via safe reinforcement learning from human feedback.

Open website

About this tool

Safe RLHF is an open-source RLHF framework developed by the PKU-Alignment team at Peking University, with the project name Beaver. Its goal is to provide training data and reproducible code pipelines for alignment research, with a particular focus on constrained alignment research through the Safe RLHF method.

Main Uses Safe RLHF (Safe Reinforcement Learning from Human Feedback) aims to achieve constrained reward maximization through preference learning, while using a reward function and a cost function (neural network proxies trained on human preferences), ultimately finding a model that is both helpful (high reward) and harmless (low cost). The framework aims to provide support for constrained value alignment (CVA) of LLMs.

Main Capabilities

  1. Supports SFT, RLHF, and Safe RLHF training, and is applicable to popular pretrained models such as LLaMA, OPT, and Baichuan.
  2. Provides large-scale human-annotated datasets (up to 1 million pairs), including both helpfulness and harmlessness preferences, for reproducible RLHF research.
  3. Supports training of the Reward Model and Cost Model, and provides pretrained checkpoints.
  4. Supports custom parameters and datasets for SFT and RLHF.
  5. Provides multi-scale safety constraint validation metrics, such as BIG-bench and GPT-4 Evaluation.
  6. Supports an Arena for evaluating reward and cost models as well as GPT-4 evaluation.
  7. Supports Chinese pretrained models (such as Baichuan and InternLM) and Chinese datasets (such as Firefly and the MOSS series).
  8. Supports custom datasets, and multiple datasets can be mixed with specified proportions.
  9. Supports memory-efficient training options (DeepSpeed ZeRO-Offload, --offload parameter), and supports multi-node training.

Datasets The PKU-SafeRLHF dataset is a human-annotated dataset containing performance and safety preferences. Its constraints cover more than ten dimensions, including insults, immorality, crime, emotional harm, and privacy, and it is used for fine-grained value alignment in RLHF techniques. The data is released gradually through rolling updates. On June 13, 2024, version 1.0 of the PKU-SafeRLHF dataset was open-sourced. Compared with the initial beta version, it adds joint human-AI annotation, expands the scope of harm categories, and introduces detailed severity labels. PKU-SafeRLHF-10K is the first round of Safe RLHF A subset of the training data (10,000 entries, including safety preferences). The plan is to gradually release the complete Safe-RLHF dataset, containing 1 million human-annotated preference pairs. The dataset is available at PKU-Alignment/PKU-SafeRLHF on Hugging Face.

Model Beaver is a LLaMA-based large language model trained with safe-rlhf, built on the Alpaca model, by collecting human preference data related to helpfulness and harmlessness and training with Safe RLHF techniques. While maintaining Alpaca's helpfulness performance, it significantly improves harmlessness. The Beaver-7B v1/v2/v3 models and the corresponding Reward Models v1/v2/v3/unified and Cost Models v1/v2/v3/unified checkpoints have been open-sourced on Hugging Face.

Usage

  1. Clone the source code from GitHub.
  2. Environment setup: You can use conda/mamba to create a conda environment (native runner), which automatically installs all dependencies; you can also use a Docker image (containerized runner), but you must first configure nvidia-docker according to the NVIDIA Container Toolkit and NVIDIA Docker installation guides, then run the corresponding commands to build and start a container with dependencies installed (the host path / is mapped to /host, and the current working directory is mapped to /workspace).
  3. Training workflow: Supports the complete workflow from supervised fine-tuning (SFT) to preference model training and then RLHF alignment training, including Supervised Fine-Tuning, Value Models (reward model & cost model), and RLHF (optional). You can update script parameters according to the machine configuration (such as the number of training GPUs, training batch size, etc.).
  4. Multiple datasets can be passed with specified proportions (separated by colons), and local paths already cloned from Hugging Face can also be passed. Note that the dataset class must be imported before the training script starts parsing command-line arguments.

Applicable scenarios Suitable for RLHF alignment research in academia and scientific research, constrained value alignment research, safety preference modeling, reward model and cost model training and evaluation, etc.

Limitations and notes The training process is based on LLaMA-7B on a configured with 8 x NVIDIA A800-80GB GPUs on a cloud server. Users with insufficient GPU memory can enable DeepSpeed ZeRO-Offload to reduce peak memory usage. For multi-node settings, refer to the DeepSpeed resource configuration documentation. The project uses the Apache License 2.0. Future plans include training larger LLMs and supporting memory-efficient training such as LoRA and PEFT.

Citation and attribution This work is supported and funded by Peking University, with members advised by Yizhou Wang and Yaodong Yang, and the Beaver logo designed by Yi Qu. The related paper "Safe RLHF: Constrained Value Alignment via Safe Reinforcement Learning from Human Feedback" has been accepted as a Spotlight at ICLR 2024 (January 16, 2024).