Snapshot của huggingface/alignment-handbook: 5.7k★ · Python · AI Tools. Robust recipes to align language models with human and AI preferences
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
Robust recipes to continue pretraining and 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 🗞️
July 24, 2025: We release the full post-training recipe behind SmolLM3-3B: a state-of-the-art hybrid reasoning model 💭
November 21, 2024: We release the recipe for fine-tuning SmolLM2-Instruct.
August 18, 2024: We release SmolLM-Instruct v0.2, along with the recipe to fine-tuning small LLMs 💻
April 12, 2024: We release Zephyr 141B (A35B), in collaboration with Argilla and Kaist AI, along with the recipe to fine-tune Mixtral 8x22B with ORPO 🪁
March 12, 2024: We release StarChat2 15B, along with the recipe to train capable coding assistants 🌟
March 1, 2024: We release Zephyr 7B Gemma, which is a new recipe to align Gemma 7B with RLAIF 🔥
February 1, 2024: We release a recipe to align open LLMs with Constitutional AI 📜! See the recipe and the blog post for details.
January 18, 2024: We release a suite of evaluations of DPO vs KTO vs IPO, see the recipe and the blog post for details.
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 🔗
Zephyr 7B models, datasets, and demos
How to navigate this project 🧭
This project is simple by design and mostly consists of:
scripts to train and evaluate models. Four steps are included: continued pretraining, supervised-finetuning (SFT) for chat, preference alignment with DPO, and supervised-finetuning with preference alignment with ORPO. 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. A gpt2-nl recipe is also given to illustrate how this handbook can be used for language or domain adaptation, e.g. by continuing to pretrain on a different language, and then SFT and DPO tuning the result.
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:
Follow the installation instructions to set up your environment etc.
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:
Continued pretraining: adapt language models to a new language or domain, or simply improve it by continued pretraining (causal language modeling) on a new dataset.
Supervised fine-tuning: teach language models to follow instructions and tips on how to collect and curate your 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.
Odds Ratio Preference Optimisation (ORPO): a technique to fine-tune language models with human preferences, combining SFT and DPO in a single stage.
Installation instructions
To run the code in this project, first, create a Python virtual environment using e.g. uv:
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
├── 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 via \usepackage{biblatex}:
@software{Tunstall_The_Alignment_Handbook,
author = {Tunstall, Lewis and Beeching, Edward and Lambert, Nathan and Rajani, Nazneen and Huang, Shengyi and Rasul, Kashif and Bartolome, Alvaro, and M. Patiño, Carlos and M. Rush, Alexander and Wolf, Thomas},
license = {Apache-2.0},
title = {{The Alignment Handbook}},
url = {https://github.com/huggingface/alignment-handbook},
version = {0.4.0.dev0}
}
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/huggingface/alignment-handbook là nguồn chính thức.
huggingface/alignment-handbook có những chủ đề gì?
GitHub topics của huggingface/alignment-handbook: "llm", "rlhf", "transformers". TopGit xếp repo vào nhóm AI Tools.
huggingface/alignment-handbook có phải mã nguồn mở không?
Có — huggingface/alignment-handbook phát hành theo license Apache-2.0, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/huggingface/alignment-handbook.
huggingface/alignment-handbook có trang demo không?
Dự án có trang chủ ở https://huggingface.co/HuggingFaceH4. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
huggingface/alignment-handbook còn đang phát triển không?
Commit gần nhất trên huggingface/alignment-handbook là 5 tháng trước (theo timestamp GitHub). Repo có 496 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
huggingface/alignment-handbook dùng license gì?
huggingface/alignment-handbook phát hành theo license Apache-2.0. Nên mở file LICENSE trên GitHub để xác nhận — license metadata đôi khi lệch với thực tế dự án.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về alignment-handbook?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về alignment-handbook.