Diffusers documentation

来自 DiffusionPipeline

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

来自 DiffusionPipeline

如果您熟悉 DiffusionPipeline,并且是第一次使用 ModularPipeline,那么有一些地方的工作方式有所不同。以下列出了这些差异,以便您在开始 快速入门 之前心中有数。

  • 加载是惰性的且灵活的。 from_pretrained() 根据仓库中的 modular_model_index.json 构建 pipeline,而不会加载任何权重。随后,load_components() 负责加载这些组件,且无需一次性全部加载:默认情况下它会加载所有组件,但你可以通过 names 仅加载指定的组件,或通过 workflow 加载某个工作流所需的组件集合。update_components() 允许你复用已有的组件,或使用与仓库规范不同的组件。请参阅 加载组件 和 更新组件。
  • ModularPipeline 读取的是另一个索引文件 modular_model_index.json,但只要模型具有模块化流水线,它同样适用于仅包含 model_index.json 的仓库。反之则不成立:DiffusionPipeline 和 AutoPipeline 类无法处理仅包含 modular_model_index.json 的仓库。
  • 调用会返回 pipeline 状态,其中也包含中间值(prompt_embeds、latents 等)。使用 output 参数指定所需内容,例如 output="images" 或 output=["images", "latents"],或者像 快速入门 中那样读取状态的属性。参见 States。
  • guider 组件支持 Classifier-free guidance,而非 guidance_scale 调用参数:pipe.update_components(guider=ClassifierFreeGuidance(guidance_scale=5.0))。请参阅 guiders 指南。
  • 没有 callback_on_step_end;不过,你可以在去噪循环中插入一个代码块,以使用现有的回调函数。请参阅回调指南中的 模块化流水线。
  • 该流水线是一个由块组成的图,您可以在使用 init_pipeline() 构建之前对其进行修改(弹出、插入、替换);pipe.blocks 返回的是副本,因此请先编辑块。参见 组合新的工作流。
  • 卸载由 ComponentsManager 处理,它可以为共享组件的多个流水线提供服务。请参阅 ComponentsManager 指南。
Update on GitHub