[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-huggingface--alignment-handbook":3,"tool-huggingface--alignment-handbook":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",149489,2,"2026-04-10T11:32:46",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":32,"last_commit_at":59,"category_tags":60,"status":17},4721,"markitdown","microsoft\u002Fmarkitdown","MarkItDown 是一款由微软 AutoGen 团队打造的轻量级 Python 工具，专为将各类文件高效转换为 Markdown 格式而设计。它支持 PDF、Word、Excel、PPT、图片（含 OCR）、音频（含语音转录）、HTML 乃至 YouTube 链接等多种格式的解析，能够精准提取文档中的标题、列表、表格和链接等关键结构信息。\n\n在人工智能应用日益普及的今天，大语言模型（LLM）虽擅长处理文本，却难以直接读取复杂的二进制办公文档。MarkItDown 恰好解决了这一痛点，它将非结构化或半结构化的文件转化为模型“原生理解”且 Token 效率极高的 Markdown 格式，成为连接本地文件与 AI 分析 pipeline 的理想桥梁。此外，它还提供了 MCP（模型上下文协议）服务器，可无缝集成到 Claude Desktop 等 LLM 应用中。\n\n这款工具特别适合开发者、数据科学家及 AI 研究人员使用，尤其是那些需要构建文档检索增强生成（RAG）系统、进行批量文本分析或希望让 AI 助手直接“阅读”本地文件的用户。虽然生成的内容也具备一定可读性，但其核心优势在于为机器",93400,"2026-04-06T19:52:38",[52,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":76,"owner_email":76,"owner_twitter":72,"owner_website":77,"owner_url":78,"languages":79,"stars":92,"forks":93,"last_commit_at":94,"license":95,"difficulty_score":96,"env_os":97,"env_gpu":98,"env_ram":99,"env_deps":100,"category_tags":108,"github_topics":109,"view_count":32,"oss_zip_url":76,"oss_zip_packed_at":76,"status":17,"created_at":113,"updated_at":114,"faqs":115,"releases":141},6337,"huggingface\u002Falignment-handbook","alignment-handbook","Robust recipes to align language models with human and AI preferences","alignment-handbook 是由 Hugging Face 推出的开源项目，旨在提供一套稳健的“食谱”，帮助开发者将语言模型与人类及 AI 的偏好进行对齐。在 ChatGPT 引发大模型热潮后，虽然许多团队能通过监督微调让模型学会遵循指令，但如何进一步提升模型的有用性与安全性仍是行业难题。该项目正是为了解决这一痛点，填补了从数据收集、训练策略到评估指标全流程公开资源的空白。\n\n它非常适合希望构建高质量聊天机器人或代码助手的研究人员与工程开发者使用。无论是从零开始继续预训练，还是进行监督微调（SFT），alignment-handbook 都提供了完整的脚本支持。其技术亮点在于涵盖了多种先进的偏好对齐算法，包括经典的 DPO（直接偏好优化）、ORPO 以及基于宪法 AI 的对齐方法，并支持 DeepSpeed ZeRO-3 分布式训练及 LoRA\u002FQLoRA 高效微调。通过复现 Zephyr、SmolLM 等知名模型的训练路径，用户能够轻松掌握让大模型更“懂人心”的关键技术，低成本打造属于自己的智能助手。","\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhuggingface_alignment-handbook_readme_5543a4ac1782.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","\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhuggingface_alignment-handbook_readme_5543a4ac1782.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\">模型与数据集\u003C\u002Fa> | 📃 \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2310.16944\" target=\"_blank\">技术报告\u003C\u002Fa>\n\u003C\u002Fp>\n\n# 对齐手册\n\n用于继续预训练以及将语言模型与人类和AI偏好对齐的稳健方法。\n\n## 这是什么？\n\n就在一年前，聊天机器人还不流行，大多数人甚至从未听说过通过人类反馈强化学习（RLHF）等技术来使语言模型与人类偏好对齐的方法。随后，OpenAI凭借ChatGPT引爆了互联网，Meta也紧随其后发布了Llama系列语言模型，这使得机器学习社区能够构建属于自己的强大聊天机器人。由此催生了一个丰富的数据集和模型生态系统，这些资源大多专注于通过监督微调（SFT）来教会语言模型遵循指令。\n\n然而，从[InstructGPT](https:\u002F\u002Fhuggingface.co\u002Fpapers\u002F2203.02155)和[Llama2](https:\u002F\u002Fhuggingface.co\u002Fpapers\u002F2307.09288)这两篇论文中我们可以了解到，通过结合人类（或AI）偏好来增强SFT，可以在帮助性和安全性方面取得显著提升。与此同时，将语言模型与一组偏好对齐仍是一个相对较新的概念，目前公开可用的关于如何训练这些模型、收集哪些数据以及使用何种指标来衡量下游性能的最佳实践资源仍然十分有限。\n\n《对齐手册》旨在填补这一空白，为社区提供一系列覆盖整个流程的稳健训练方案。\n\n## 新闻 🗞️\n* **2025年7月24日**：我们发布了SmolLM3-3B背后的完整[后训练配方](recipes\u002Fsmollm3\u002FREADME.md)，这是一种最先进的混合推理模型 💭\n* **2024年11月21日**：我们发布了微调SmolLM2-Instruct的[配方](recipes\u002Fsmollm2\u002FREADME.md)。\n* **2024年8月18日**：我们发布了SmolLM-Instruct v0.2，并附带了微调小型LLM的[配方](recipes\u002Fsmollm\u002FREADME.md) 💻\n* **2024年4月12日**：我们与Argilla和Kaist AI合作发布了Zephyr 141B (A35B)，并附带了使用ORPO微调Mixtral 8x22B的配方 🪁\n* **2024年3月12日**：我们发布了StarChat2 15B，并附带了训练高效编码助手的配方 🌟\n* **2024年3月1日**：我们发布了Zephyr 7B Gemma，这是一个全新的配方，用于将Gemma 7B与RLAIF对齐 🔥\n* **2024年2月1日**：我们发布了一种将开源LLM与宪章式AI对齐的配方 📜！详情请参阅[配方](https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Falignment-handbook\u002Ftree\u002Fmain\u002Frecipes\u002Fconstitutional-ai)和[博客文章](https:\u002F\u002Fhuggingface.co\u002Fblog\u002Fconstitutional_ai)。\n* **2024年1月18日**：我们发布了一系列DPO、KTO和IPO的评估结果，详情请参阅[配方](recipes\u002Fpref_align_scan\u002FREADME.md)和[博客文章](https:\u002F\u002Fhuggingface.co\u002Fblog\u002Fpref-tuning)。\n* **2023年11月10日**：我们发布了所有用于复现Zephyr-7b-β的训练代码 🪁！同时，我们还发布了[No Robots](https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002FHuggingFaceH4\u002Fno_robots)，这是一个全新的数据集，包含1万条由熟练的人类标注者完全手工编写的指令和演示。\n\n## 链接 🔗\n\n* [Zephyr 7B模型、数据集和演示](https:\u002F\u002Fhuggingface.co\u002Fcollections\u002FHuggingFaceH4\u002Fzephyr-7b-6538c6d6d5ddd1cbb1744a66)\n\n## 如何浏览该项目 🧭\n\n本项目设计简洁，主要由以下部分组成：\n\n* [`scripts`](.\u002Fscripts\u002F)：用于训练和评估模型的脚本。包括四个步骤：继续预训练、面向对话的监督微调（SFT）、使用DPO进行偏好对齐，以及结合偏好对齐的ORPO监督微调。每个脚本都支持使用DeepSpeed ZeRO-3进行全模型权重的分布式训练，或者使用LoRA\u002FQLoRA进行参数高效的微调。\n* [`recipes`](.\u002Frecipes\u002F)：用于复现Zephyr 7B等模型的配方。每个配方以YAML文件的形式呈现，包含了单次训练运行的所有参数。此外，还提供了一个`gpt2-nl`配方，用以说明如何利用本手册进行语言或领域适应，例如在不同语言上继续预训练，然后进行SFT和DPO调优。\n\n我们还在编写一系列指南，解释诸如直接偏好优化（DPO）等方法的工作原理，以及在实际收集人类偏好过程中所获得的经验教训。要开始使用，我们建议您按照以下步骤操作：\n\n1. 按照[安装说明](#installation-instructions)设置您的环境等。\n2. 按照[配方说明](.\u002Frecipes\u002Fzephyr-7b-beta\u002FREADME.md)复现Zephyr-7b-β。\n\n如果您希望使用自己的数据集来训练聊天模型，我们建议您参考[此处](.\u002Fscripts\u002FREADME.md#fine-tuning-on-your-datasets)的数据集格式化说明。\n\n\n## 目录\n\n手册的初始版本将重点介绍以下技术：\n\n* **继续预训练**：使语言模型适应新的语言或领域，或者仅仅通过在新数据集上进行因果语言建模的继续预训练来提升模型性能。\n* **监督微调**：教导语言模型遵循指令，并提供有关如何收集和整理训练数据集的技巧。\n* **奖励建模**：教会语言模型根据人类或AI偏好来区分不同的模型响应。\n* **拒绝采样**：一种简单但强大的技术，可显著提升SFT模型的性能。\n* **直接偏好优化（DPO）**：一种强大且前景广阔的PPO替代方案。\n* **几率比偏好优化（ORPO）**：一种结合SFT和DPO于一体的技术，用于以人类偏好为目标对语言模型进行微调。\n\n## 安装说明\n\n要运行本项目中的代码，首先使用例如 `uv` 创建一个 Python 虚拟环境：\n\n```shell\nuv venv handbook --python 3.11 && source handbook\u002Fbin\u002Factivate && uv pip install --upgrade pip\n```\n\n> [!TIP]\n> 若要安装 `uv`，请按照 [UV 安装指南](https:\u002F\u002Fdocs.astral.sh\u002Fuv\u002Fgetting-started\u002Finstallation\u002F) 进行操作。\n\n接下来，安装 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\n请注意，精确的版本号对于实验的可重复性非常重要！由于这与硬件相关，我们还建议您参考 [PyTorch 安装页面](https:\u002F\u002Fpytorch.org\u002Fget-started\u002Flocally\u002F)。\n\n然后，您可以按如下方式安装其余的包依赖项：\n\n```shell\nuv pip install .\n```\n\n此外，您还需要安装 Flash Attention 2，可以通过以下命令完成：\n\n```shell\nuv pip install \"flash-attn==2.7.4.post1\" --no-build-isolation\n```\n\n接下来，请按照以下步骤登录您的 Hugging Face 账户：\n\n```shell\nhuggingface-cli login\n```\n\n最后，安装 Git LFS，以便将模型推送到 Hugging Face Hub：\n\n```shell\nsudo apt-get install git-lfs\n```\n\n现在，您可以查看 `scripts` 和 `recipes` 目录，了解如何训练一些模型的说明 🪁！\n\n## 项目结构\n\n```\n├── LICENSE\n├── Makefile                    \u003C- 包含诸如 `make style` 等命令的 Makefile\n├── README.md                   \u003C- 面向开发者的顶级 README 文件\n├── recipes                     \u003C- 配置文件、加速配置和 Slurm 脚本\n├── scripts                     \u003C- 用于训练和评估聊天模型的脚本\n├── setup.cfg                   \u003C- 安装配置（主要用于配置代码质量和测试）\n├── setup.py                    \u003C- 使项目可通过 pip 安装（pip install -e .），从而可以导入 `alignment`\n├── src                         \u003C- 本项目中使用的源代码\n└── tests                       \u003C- 单元测试\n```\n\n## 引用\n\n如果您在工作中觉得本仓库的内容有所帮助，请通过 `\\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```","# Alignment Handbook 快速上手指南\n\n**Alignment Handbook** 是由 Hugging Face 提供的一套稳健的训练配方，旨在帮助开发者对语言模型进行持续预训练、监督微调（SFT）以及基于人类或 AI 偏好的对齐（如 DPO、ORPO）。本指南将协助你快速搭建环境并运行首个模型训练任务。\n\n## 环境准备\n\n在开始之前，请确保你的开发环境满足以下要求：\n\n*   **操作系统**: Linux (推荐) 或 macOS。Windows 用户建议使用 WSL2。\n*   **Python 版本**: 3.11 (官方推荐以保证复现性)。\n*   **GPU**: 支持 CUDA 的 NVIDIA 显卡（用于加速训练）。\n*   **存储**: 足够的磁盘空间以存放模型权重、数据集及检查点。\n*   **账号**: 已注册 [Hugging Face](https:\u002F\u002Fhuggingface.co\u002F) 账号，并拥有访问相关模型和数据集的权限。\n*   **工具**: 已安装 `git` 和 `git-lfs`。\n\n## 安装步骤\n\n本项目推荐使用 `uv` 进行包管理，以获得更快的安装速度和更好的依赖解析体验。\n\n### 1. 安装 uv (如未安装)\n如果尚未安装 `uv`，请参考官方指南：[UV Installation Guide](https:\u002F\u002Fdocs.astral.sh\u002Fuv\u002Fgetting-started\u002Finstallation\u002F)。\n\n### 2. 创建虚拟环境并激活\n```shell\nuv venv handbook --python 3.11 && source handbook\u002Fbin\u002Factivate && uv pip install --upgrade pip\n```\n\n### 3. 安装 PyTorch\n请根据你的硬件环境安装指定版本的 PyTorch。以下为 CUDA 12.6 环境的安装命令（**注意：版本号对复现性至关重要**）：\n```shell\nuv pip install torch==2.6.0 --index-url https:\u002F\u002Fdownload.pytorch.org\u002Fwhl\u002Fcu126\n```\n> **提示**：如果你的 CUDA 版本不同，请访问 [PyTorch 官网](https:\u002F\u002Fpytorch.org\u002Fget-started\u002Flocally\u002F) 获取对应的安装命令。国内用户若遇到下载慢的问题，可尝试使用清华源或阿里源替代 `--index-url`。\n\n### 4. 安装项目依赖\n```shell\nuv pip install .\n```\n\n### 5. 安装 Flash Attention 2\n为了获得最佳训练性能，必须安装 Flash Attention 2：\n```shell\nuv pip install \"flash-attn==2.7.4.post1\" --no-build-isolation\n```\n\n### 6. 登录 Hugging Face 并配置 Git LFS\n```shell\nhuggingface-cli login\nsudo apt-get install git-lfs\n```\n\n## 基本使用\n\n本项目通过 `recipes`（配方）和 `scripts`（脚本）来组织训练流程。每个配方是一个 YAML 文件，包含了单次训练所需的所有参数。\n\n### 最简单的使用示例：复现 Zephyr-7b-β\n\n以下是复现经典的 Zephyr-7b-β 模型的最简流程：\n\n1.  **查看配方配置**\n    进入 `recipes\u002Fzephyr-7b-beta\u002F` 目录，你会看到包含 SFT 和 DPO 阶段的 YAML 配置文件。\n\n2.  **执行训练脚本**\n    假设你要进行监督微调（SFT），可以使用 `accelerate` 启动训练。以下是一个典型的启动命令示例（具体参数需参考对应 recipe 的 README）：\n\n    ```bash\n    accelerate launch --config_file recipes\u002Faccelerate_configs\u002Fdeepspeed_zero3.yaml \\\n      scripts\u002Frun_sft.py \\\n      recipes\u002Fzephyr-7b-beta\u002Fsft_config.yaml\n    ```\n\n    *   `--config_file`: 指定分布式训练配置（如 DeepSpeed ZeRO-3）。\n    *   `scripts\u002Frun_sft.py`: 调用监督微调脚本。\n    *   `recipes\u002F...\u002Fsft_config.yaml`: 加载具体的超参数和数据集路径。\n\n3.  **自定义数据集训练**\n    如果你想用自己的数据集训练聊天模型，请按照 `scripts\u002FREADME.md` 中的说明格式化你的数据集（通常为 JSONL 格式，包含 `messages` 字段），然后在 YAML 配置文件中修改 `dataset_name` 指向你的本地路径或 Hugging Face 数据集 ID。\n\n### 核心训练阶段说明\n该手册覆盖了完整的对齐流水线，你可以根据需求选择运行不同的脚本：\n*   **持续预训练 (Continued Pretraining)**: 适应新语言或领域。\n*   **监督微调 (SFT)**: 教会模型遵循指令。\n*   **偏好对齐 (DPO\u002FORPO)**: 基于人类或 AI 反馈优化模型回答质量。\n\n更多详细的配方（如 SmolLM3, StarChat2 等）请参阅 `recipes\u002F` 目录下的具体说明文档。","某初创团队希望基于开源基座模型，快速构建一个既懂医疗知识又符合安全规范的智能问诊助手。\n\n### 没有 alignment-handbook 时\n- **技术门槛极高**：团队需从零摸索 RLHF、DPO 等复杂的对齐算法，缺乏成熟的代码参考，研发周期长达数月。\n- **数据准备困难**：不知道如何收集或构建高质量的偏好数据集（如“好回答”与“坏回答”的对比），导致模型训练效果不稳定。\n- **训练资源浪费**：缺乏优化的分布式训练配置，显存占用高且容易报错，多次尝试均因显存溢出或收敛失败而中止。\n- **安全性无法保障**：仅靠指令微调（SFT）无法有效抑制模型幻觉和有害输出，直接部署存在严重的合规风险。\n\n### 使用 alignment-handbook 后\n- **开箱即用流程**：直接复用项目中成熟的 DPO 和 ORPO 训练脚本，几天内即可完成从基座模型到对齐模型的完整流水线。\n- **优质数据支持**：利用其提供的\"No Robots\"等高质量人类标注数据集作为基准，快速构建出符合医疗场景的偏好数据。\n- **高效稳定训练**：内置 DeepSpeed ZeRO-3 和 QLoRA 配置，显著降低显存需求，确保在有限算力下也能稳定收敛。\n- **显著提升安全性**：通过标准的偏好对齐步骤，模型不仅回答更准确，还大幅减少了胡编乱造和不当建议，满足上线标准。\n\nalignment-handbook 将原本高深莫测的对齐技术转化为标准化的“烹饪食谱”，让开发者能低成本、高效率地打造出安全可控的专用大模型。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fhuggingface_alignment-handbook_5543a4ac.png","huggingface","Hugging Face","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fhuggingface_90da21a4.png","The AI community building the future.",null,"https:\u002F\u002Fhuggingface.co\u002F","https:\u002F\u002Fgithub.com\u002Fhuggingface",[80,84,88],{"name":81,"color":82,"percentage":83},"Python","#3572A5",85.7,{"name":85,"color":86,"percentage":87},"Shell","#89e051",12.3,{"name":89,"color":90,"percentage":91},"Makefile","#427819",2.1,5555,480,"2026-04-09T22:14:03","Apache-2.0",4,"Linux","必需 NVIDIA GPU，需安装 Flash Attention 2 (v2.7.4.post1)，指定 CUDA 12.6 (cu126) 版本的 PyTorch","未说明",{"notes":101,"python":102,"dependencies":103},"建议使用 uv 工具管理虚拟环境和依赖；PyTorch 版本必须严格为 2.6.0 以确保复现性；需登录 Hugging Face 账户；需安装 Git LFS 以上传模型；支持 DeepSpeed ZeRO-3 分布式训练及 LoRA\u002FQLoRA 参数高效微调。","3.11",[104,105,106,107],"torch==2.6.0","flash-attn==2.7.4.post1","huggingface-cli","git-lfs",[14,35],[110,111,112],"llm","rlhf","transformers","2026-03-27T02:49:30.150509","2026-04-11T03:24:23.972838",[116,121,126,131,136],{"id":117,"question_zh":118,"answer_zh":119,"source_url":120},28696,"Alignment Handbook 的相关代码何时发布？","代码已经发布。您可以访问 alignment-handbook 仓库查看完整代码和文档。早期用户曾通过 PR #11 获得预览，目前仓库已公开可用。","https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Falignment-handbook\u002Fissues\u002F6",{"id":122,"question_zh":123,"answer_zh":124,"source_url":125},28692,"遇到 'cannot import name log from torch.distributed.elastic.agent.server.api' 或 'SFTConfig object has no attribute dataset_num_proc' 错误怎么办？","这通常是由于 deepspeed 版本不兼容导致的。请尝试安装特定版本的 deepspeed 来解决此问题，例如：\npip install deepspeed==0.14.4\n该版本已验证可以解决上述导入错误和属性缺失问题。","https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Falignment-handbook\u002Fissues\u002F180",{"id":127,"question_zh":128,"answer_zh":129,"source_url":130},28693,"为什么训练前模型是 bf16，但训练保存后变成了 fp32？","这是因为在加载预训练模型进行检查时，如果没有显式指定 `torch_dtype`，默认会使用 `torch.float32`。\n若要正确加载并检查模型的精度（如 bf16 或 fp16），请使用以下代码：\n```python\nimport torch\nfrom transformers import AutoModelForCausalLM\n\nmodel = AutoModelForCausalLM.from_pretrained(pretrained_model_name_or_path, torch_dtype=torch.float16)\nprint(model.dtype)\n```\n请确保将 `torch.float16` 替换为您实际使用的精度类型（如 `torch.bfloat16`）。","https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Falignment-handbook\u002Fissues\u002F174",{"id":132,"question_zh":133,"answer_zh":134,"source_url":135},28694,"在多 GPU 训练时使用 accelerate，push_to_hub() 无法完成上传或卡住怎么办？","这通常是因为在使用分片模型（sharded model）时，错误地将 `trainer.save_model()` 放在了 `if trainer.accelerator.is_main_process:` 判断块中。在主进程保存会导致其他进程的模型分片未被正确处理。\n解决方法是将 `trainer.save_model()` 移到条件判断之外，确保所有进程参与保存过程，然后再执行 `trainer.push_to_hub()`。参考当前最新版本代码的结构进行调整。","https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Falignment-handbook\u002Fissues\u002F198",{"id":137,"question_zh":138,"answer_zh":139,"source_url":140},28695,"使用 SFT 和 QLoRA 微调时报错，提示与 quantization_config 相关的错误如何解决？","在 `alignment_handbook\u002Fscripts\u002Frun_sft.py` 文件中（通常在实例化模型配置处，约第 120 行），需要将 `quantization_config=quantization_config` 修改为 `quantization_config=quantization_config.to_dict()`。\nBitsAndBytes 配置对象不能直接传递，必须转换为字典格式。修改示例：\n```python\n# 修改前\nquantization_config=quantization_config\n# 修改后\nquantization_config=quantization_config.to_dict()\n```","https:\u002F\u002Fgithub.com\u002Fhuggingface\u002Falignment-handbook\u002Fissues\u002F189",[]]