diff --git a/README.md b/README.md
index aaf5c97e09c3..9b568d02f410 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,10 @@ limitations under the License.
+ English · 简体中文 +
+ 🤗 Diffusers is the go-to library for state-of-the-art pretrained diffusion models for generating images, audio, and even 3D structures of molecules. Whether you're looking for a simple inference solution or training your own diffusion models, 🤗 Diffusers is a modular toolbox that supports both. Our library is designed with a focus on [usability over performance](https://huggingface.co/docs/diffusers/conceptual/philosophy#usability-over-performance), [simple over easy](https://huggingface.co/docs/diffusers/conceptual/philosophy#simple-over-easy), and [customizability over abstractions](https://huggingface.co/docs/diffusers/conceptual/philosophy#tweakable-contributorfriendly-over-abstraction). 🤗 Diffusers offers three core components: diff --git a/README.zh.md b/README.zh.md new file mode 100644 index 000000000000..819b0b9fdab8 --- /dev/null +++ b/README.zh.md @@ -0,0 +1,265 @@ + + +
+
+
+
+
+ English · 简体中文 +
+ +🤗 **Diffusers** 是当前最前沿预训练扩散模型(Diffusion Models)的工业级标准库,广泛用于生成高质量图像、音频乃至分子的 3D 空间结构。无论您需要极简的高性能开箱即用推理方案,还是正在从零研究训练自有的扩散模型,🤗 Diffusers 提供的模块化工具箱都能提供全流程支持。 + +本代码库的核心设计哲学: +- [**易用性优于极致性能** (Usability over performance)](https://huggingface.co/docs/diffusers/conceptual/philosophy#usability-over-performance) +- [**直观简单优于隐晦捷径** (Simple over easy)](https://huggingface.co/docs/diffusers/conceptual/philosophy#simple-over-easy) +- [**灵活可定制优于过度抽象** (Customizability over abstractions)](https://huggingface.co/docs/diffusers/conceptual/philosophy#tweakable-contributorfriendly-over-abstraction) + +🤗 Diffusers 提供了三大核心组件: + +- **前沿扩散管线 ([Diffusion Pipelines](https://huggingface.co/docs/diffusers/api/pipelines/overview))**:只需数行代码即可运行各种 SOTA 扩散模型推理; +- **可插拔噪声调度器 ([Schedulers](https://huggingface.co/docs/diffusers/api/schedulers/overview))**:支持在生成速度与生成质量之间灵活权衡与切换; +- **基础网络模块 ([Models](https://huggingface.co/docs/diffusers/api/models/overview))**:提供 UNet、Transformer Backbone 等丰富的基础预训练网络模块,可与调度器自由组合构建专属的端到端扩散系统。 + +--- + +## 📦 安装说明 (Installation) + +推荐在独立的 Python 虚拟环境中使用 PyPI 或 Conda 安装 🤗 Diffusers。关于 [PyTorch](https://pytorch.org/get-started/locally/) 的平台特定安装指南,请参考 PyTorch 官方文档。 + +### PyTorch 环境安装 + +使用 `pip` 安装(官方标准包): + +```bash +pip install --upgrade diffusers[torch] +``` + +使用 `conda` 安装(由开源社区维护): + +```sh +conda install -c conda-forge diffusers +``` + +### Apple Silicon (M1/M2/M3/M4) MPS 加速支持 + +针对搭载 Apple Silicon 芯片的 Mac 设备,请参阅 [在 Apple Silicon 上运行 Stable Diffusion 指南](https://huggingface.co/docs/diffusers/optimization/mps)。 + +--- + +## 🚀 快速上手 (Quickstart) + +使用 🤗 Diffusers 生成内容极其简单。要通过文本生成图像,只需使用 `from_pretrained` 方法加载任意预训练扩散模型(欢迎浏览 [Hugging Face Hub](https://huggingface.co/models?library=diffusers&sort=downloads) 探索 30,000+ 个模型权重): + +```python +from diffusers import DiffusionPipeline +import torch + +pipeline = DiffusionPipeline.from_pretrained("stable-diffusion-v1-5/stable-diffusion-v1-5", dtype=torch.float16) +pipeline.to("cuda") +pipeline("An image of a squirrel in Picasso style").images[0] +``` + +您也可以直接深入调用底层的模型与噪声调度器工具箱,自主组装完整的扩散推理系统: + +```python +from diffusers import DDPMScheduler, UNet2DModel +from PIL import Image +import torch + +scheduler = DDPMScheduler.from_pretrained("google/ddpm-cat-256") +model = UNet2DModel.from_pretrained("google/ddpm-cat-256").to("cuda") +scheduler.set_timesteps(50) + +sample_size = model.config.sample_size +noise = torch.randn((1, 3, sample_size, sample_size), device="cuda") +input = noise + +for t in scheduler.timesteps: + with torch.no_grad(): + noisy_residual = model(input, t).sample + prev_noisy_sample = scheduler.step(noisy_residual, t, input).prev_sample + input = prev_noisy_sample + +image = (input / 2 + 0.5).clamp(0, 1) +image = image.cpu().permute(0, 2, 3, 1).numpy()[0] +image = Image.fromarray((image * 255).round().astype("uint8")) +image +``` + +欢迎查阅 [官方快速入门指南 (Quickstart Tour)](https://huggingface.co/docs/diffusers/quicktour),开启您的扩散模型创作之旅! + +--- + +## 🧭 文档结构导航 (How to navigate the documentation) + +| 核心文档专区 | 您能学到什么? | +| :--- | :--- | +| [**快速上手 (Quickstart)**](https://huggingface.co/docs/diffusers/quicktour) | 快速掌握管线加载、结果生成以及常见推理加速优化的极简速成课程。 | +| [**加载指南 (Loading)**](https://huggingface.co/docs/diffusers/using-diffusers/loading) | 详尽说明如何加载并配置库中所有核心组件(Pipelines、Models 和 Schedulers),以及如何切换不同调度器。 | +| [**模块化 Diffusers (Modular Diffusers)**](https://huggingface.co/docs/diffusers/main/en/modular_diffusers/overview) | 基于高度解耦的模块化管线组件,灵活搭建专属扩散系统。 | +| [**显存与推理优化 (Optimization)**](https://huggingface.co/docs/diffusers/optimization/fp16) | 深入讲解如何优化扩散模型,以实现更快推理速度和极低显存占用(FP16/BF16/FlashAttention/CPU Offload 等)。 | +| [**模型微调与训练 (Training)**](https://huggingface.co/docs/diffusers/training/overview) | 针对多样化任务(Text-to-Image、DreamBooth、LoRA、ControlNet 等)与不同训练技巧的全方位教程。 | + +--- + +## 🤝 参与贡献 (Contribution) + +我们 ❤️ 来自开源社区的每一份贡献! +如果您希望为本库贡献代码或文档,请查阅我们的 [贡献者指南 (Contribution Guide)](https://huggingface.co/docs/diffusers/main/en/conceptual/contribution)。 + +如果您正在使用 AI 智能体(AI Coding Agent)进行协作,请让其首先参考项目在 [`.ai/`](https://github.com/huggingface/diffusers/tree/main/.ai) 目录中定义的工程规范(支持通过 `claude plugin marketplace add huggingface/diffusers` 添加插件,或通过 `diffusers-cli skills add