Diffusers 文档

AutoPipeline

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

AutoPipeline

Diffusers 提供了许多 pipelines 用于生成图像、视频、音频和图像修复等基本任务。除此之外,还有专门用于适配器和功能的 pipelines,例如放大、超分辨率等等。不同的 pipeline 类甚至可以使用相同的检查点,因为它们共享相同的预训练模型!由于有如此多的不同 pipelines,因此可能很难知道要使用哪个 pipeline 类。

AutoPipeline 类旨在简化 Diffusers 中各种 pipelines。它是一个通用的任务优先 pipeline,让您可以专注于任务(AutoPipelineForText2ImageAutoPipelineForImage2ImageAutoPipelineForInpainting),而无需知道具体的 pipeline 类。AutoPipeline 会自动检测要使用的正确 pipeline 类。

例如,让我们使用 dreamlike-art/dreamlike-photoreal-2.0 检查点。

在底层,AutoPipeline

  1. model_index.json 文件中检测到 "stable-diffusion" 类。
  2. 根据您感兴趣的任务,它会加载 StableDiffusionPipelineStableDiffusionImg2ImgPipelineStableDiffusionInpaintPipeline。您可以传递给这些特定 pipelines 的任何参数(strengthnum_inference_steps 等)也可以传递给 AutoPipeline
文本到图像
图像到图像
图像修复
from diffusers import AutoPipelineForText2Image
import torch

pipe_txt2img = AutoPipelineForText2Image.from_pretrained(
    "dreamlike-art/dreamlike-photoreal-2.0", torch_dtype=torch.float16, use_safetensors=True
).to("cuda")

prompt = "cinematic photo of Godzilla eating sushi with a cat in a izakaya, 35mm photograph, film, professional, 4k, highly detailed"
generator = torch.Generator(device="cpu").manual_seed(37)
image = pipe_txt2img(prompt, generator=generator).images[0]
image

不支持的检查点

AutoPipeline 支持 Stable DiffusionStable Diffusion XLControlNetKandinsky 2.1Kandinsky 2.2DeepFloyd IF 检查点。

如果您尝试加载不支持的检查点,您将收到错误。

from diffusers import AutoPipelineForImage2Image
import torch

pipeline = AutoPipelineForImage2Image.from_pretrained(
    "openai/shap-e-img2img", torch_dtype=torch.float16, use_safetensors=True
)
"ValueError: AutoPipeline can't find a pipeline linked to ShapEImg2ImgPipeline for None"
< > 在 GitHub 上更新