[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-71150":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":25,"hasPages":23,"topics":26,"createdAt":10,"pushedAt":10,"updatedAt":30,"readmeContent":31,"aiSummary":32,"trendingCount":16,"starSnapshotCount":16,"syncStatus":17,"lastSyncTime":33,"discoverSource":34},71150,"alignment-handbook","huggingface\u002Falignment-handbook","huggingface","Robust recipes to align language models with human and AI preferences","https:\u002F\u002Fhuggingface.co\u002FHuggingFaceH4",null,"Python",5609,492,103,92,0,2,5,14,6,71.98,"Apache License 2.0",false,"main",true,[27,28,29],"llm","rlhf","transformers","2026-06-12 04:00:59","\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Fraw.githubusercontent.com\u002Fhuggingface\u002Falignment-handbook\u002Fmain\u002Fassets\u002Fhandbook.png\">\n\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n    🤗 \u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002Fcollections\u002Falignment-handbook\u002Fhandbook-v01-models-and-datasets-654e424d22e6880da5ebc015\" target=\"_blank\">Models & Datasets\u003C\u002Fa> | 📃 \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2310.16944\" target=\"_blank\">Technical Report\u003C\u002Fa>\n\u003C\u002Fp>\n\n# The Alignment Handbook\n\nRobust recipes to continue pretraining and to align language models with human and AI preferences.\n\n## What is this?\n\nJust 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).\n\nHowever, we know from the [InstructGPT](https:\u002F\u002Fhuggingface.co\u002Fpapers\u002F2203.02155) and [Llama2](https:\u002F\u002Fhuggingface.co\u002Fpapers\u002F2307.09288) 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.\n\nThe Alignment Handbook aims to fill that gap by providing the community with a series of robust training recipes that span the whole pipeline.\n\n## News 🗞️\n* **July 24, 2025**: We release the full [post-training recipe](recipes\u002Fsmollm3\u002FREADME.md) behind SmolLM3-3B: a state-of-the-art hybrid reasoning model 💭\n* **November 21, 2024**: We release the [recipe](recipes\u002Fsmollm2\u002FREADME.md) for fine-tuning SmolLM2-Instruct.\n* **August 18, 2024**: We release SmolLM-Instruct v0.2, along with the [recipe](recipes\u002Fsmollm\u002FREADME.md)  to fine-tuning small LLMs 💻\n* **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 🪁\n* **March 12, 2024:** We release StarChat2 15B, along with the recipe to train capable coding assistants 🌟\n* **March 1, 2024:** We release Zephyr 7B Gemma, which is a new recipe to align Gemma 7B with RLAIF 🔥\n* **February 1, 2024:** We release a recipe to align open LLMs with Constitutional AI 📜! See the [recipe](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Falignment-handbook\u002Ftree\u002Fmain\u002Frecipes\u002Fconstitutional-ai) and the [blog post](https:\u002F\u002Fhuggingface.co\u002Fblog\u002Fconstitutional_ai) for details. \n* **January 18, 2024:** We release a suite of evaluations of DPO vs KTO vs IPO, see the [recipe](recipes\u002Fpref_align_scan\u002FREADME.md) and the [blog post](https:\u002F\u002Fhuggingface.co\u002Fblog\u002Fpref-tuning) for details.\n* **November 10, 2023:** We release all the training code to replicate Zephyr-7b-β 🪁! We also release [No Robots](https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002FHuggingFaceH4\u002Fno_robots), a brand new dataset of 10,000 instructions and demonstrations written entirely by skilled human annotators.\n\n## Links 🔗\n\n* [Zephyr 7B models, datasets, and demos](https:\u002F\u002Fhuggingface.co\u002Fcollections\u002FHuggingFaceH4\u002Fzephyr-7b-6538c6d6d5ddd1cbb1744a66)\n\n## How to navigate this project 🧭\n\nThis project is simple by design and mostly consists of:\n\n* [`scripts`](.\u002Fscripts\u002F) 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\u002FQLoRA for parameter-efficient fine-tuning.\n* [`recipes`](.\u002Frecipes\u002F) 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. \n\nWe 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:\n\n1. Follow the [installation instructions](#installation-instructions) to set up your environment etc.\n2. Replicate Zephyr-7b-β by following the [recipe instructions](.\u002Frecipes\u002Fzephyr-7b-beta\u002FREADME.md).\n\nIf you would like to train chat models on your own datasets, we recommend following the dataset formatting instructions [here](.\u002Fscripts\u002FREADME.md#fine-tuning-on-your-datasets).\n\n\n## Contents\n\nThe initial release of the handbook will focus on the following techniques:\n\n* **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.\n* **Supervised fine-tuning:** teach language models to follow instructions and tips on how to collect and curate your training dataset.\n* **Reward modeling:** teach language models to distinguish model responses according to human or AI preferences.\n* **Rejection sampling:** a simple, but powerful technique to boost the performance of your SFT model.\n* **Direct preference optimisation (DPO):** a powerful and promising alternative to PPO.\n* **Odds Ratio Preference Optimisation (ORPO)**: a technique to fine-tune language models with human preferences, combining SFT and DPO in a single stage.\n\n## Installation instructions\n\nTo run the code in this project, first, create a Python virtual environment using e.g. `uv`:\n\n```shell\nuv venv handbook --python 3.11 && source handbook\u002Fbin\u002Factivate && uv pip install --upgrade pip\n```\n\n> [!TIP]\n> To install `uv`, follow the [UV Installation Guide](https:\u002F\u002Fdocs.astral.sh\u002Fuv\u002Fgetting-started\u002Finstallation\u002F).\n\nNext, install PyTorch `v2.6.0` \n\n```shell\nuv pip install torch==2.6.0 --index-url https:\u002F\u002Fdownload.pytorch.org\u002Fwhl\u002Fcu126\n```\n\nNote that the precise version is important for reproducibility! Since this is hardware-dependent, we also direct you to the [PyTorch Installation Page](https:\u002F\u002Fpytorch.org\u002Fget-started\u002Flocally\u002F).\n\nYou can then install the remaining package dependencies as follows:\n\n```shell\nuv pip install .\n```\n\nYou will also need Flash Attention 2 installed, which can be done by running:\n\n```shell\nuv pip install \"flash-attn==2.7.4.post1\" --no-build-isolation\n```\n\nNext, log into your Hugging Face account as follows:\n\n```shell\nhuggingface-cli login\n```\n\nFinally, install Git LFS so that you can push models to the Hugging Face Hub:\n\n```shell\nsudo apt-get install git-lfs\n```\n\nYou can now check out the `scripts` and `recipes` directories for instructions on how to train some models 🪁!\n\n## Project structure\n\n```\n├── LICENSE\n├── Makefile                    \u003C- Makefile with commands like `make style`\n├── README.md                   \u003C- The top-level README for developers using this project\n├── recipes                     \u003C- Recipe configs, accelerate configs, slurm scripts\n├── scripts                     \u003C- Scripts to train and evaluate chat models\n├── setup.cfg                   \u003C- Installation config (mostly used for configuring code quality & tests)\n├── setup.py                    \u003C- Makes project pip installable (pip install -e .) so `alignment` can be imported\n├── src                         \u003C- Source code for use in this project\n└── tests                       \u003C- Unit tests\n```\n\n## Citation\n\nIf you find the content of this repo useful in your work, please cite it as follows via `\\usepackage{biblatex}`:\n\n```bibtex\n@software{Tunstall_The_Alignment_Handbook,\n  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},\n  license = {Apache-2.0},\n  title = {{The Alignment Handbook}},\n  url = {https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Falignment-handbook},\n  version = {0.4.0.dev0}\n}\n```\n","huggingface\u002Falignment-handbook 是一个提供稳健方法来继续预训练并将语言模型与人类和AI偏好对齐的项目。它通过强化学习从人类反馈（RLHF）等技术，增强语言模型在遵循指令、帮助性和安全性方面的表现。该项目使用Python编写，基于transformers库，并提供了详细的训练食谱，涵盖了从数据收集到模型微调的整个流程。适合需要定制化聊天机器人或希望提高现有语言模型性能的研究人员和开发者使用。","2026-06-11 03:36:09","high_star"]