Diffusers documentation

旧版检查点

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

旧版检查点

这些设置主要适用于较旧的 Stable Diffusion 系列检查点。

安全检查器

Diffusers 为较旧的 Stable Diffusion 检查点提供了 安全检查器,以防止生成有害内容。它会针对一组硬编码的有害概念对生成的输出进行筛查。Qwen-Image 等较新的模型不包含此检查器。

如果要禁用安全检查器,请在 from_pretrained() 中传入 safety_checker=None,如下所示。

from diffusers import DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained(
  "stable-diffusion-v1-5/stable-diffusion-v1-5", safety_checker=None
)
"""
You have disabled the safety checker for <class 'diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion.StableDiffusionPipeline'> by passing `safety_checker=None`. Ensure that you abide by the conditions of the Stable Diffusion license and do not expose unfiltered results in services or applications open to the public. Both the diffusers team and Hugging Face strongly recommend keeping the safety filter enabled in all public-facing circumstances, disabling it only for use cases that involve analyzing network behavior or auditing its results. For more information, please have a look at https://github.com/huggingface/diffusers/pull/254 .
"""

重新缩放调度

去噪过程从纯噪声开始,因此信噪比(SNR)初始值为零。某些模型实际上并非从纯噪声开始,这使得生成极亮和极暗的极端值变得困难。

通过向训练脚本添加 --prediction_type="v_prediction" 标志,使用 v_prediction 训练你自己的模型。你还可以 搜索 使用 v_prediction 训练的现有模型。

对于 v_prediction 模型,请启用以下调度器参数。

  • 将 rescale_betas_zero_snr=True 设置为 True,可将噪声调度重新缩放至最后一个时间步,使其信噪比(SNR)恰好为零。
  • 设置 timestep_spacing="trailing" 以强制从最后的时间步(纯噪声)进行采样
from diffusers import DiffusionPipeline, DDIMScheduler

pipeline = DiffusionPipeline.from_pretrained("ptx0/pseudo-journey-v2", device_map="cuda")  # or "mps", "xpu", "cpu"

pipeline.scheduler = DDIMScheduler.from_config(
    pipeline.scheduler.config, rescale_betas_zero_snr=True, timestep_spacing="trailing"
)

在 pipeline 中设置 guidance_rescale 以避免图像过曝。值越低,亮度越高,但部分细节可能会显得褪色。

prompt = """
cinematic photo of a snowy mountain at night with the northern lights aurora borealis
overhead, 35mm photograph, film, professional, 4k, highly detailed
"""
image = pipeline(prompt, guidance_rescale=0.7).images[0]
无零信噪比
零信噪比和尾部间距
Update on GitHub