Diffusers documentation

FreeU

You are viewing main version, which requires installation from source. If you'd like regular pip install, checkout the latest stable version (v0.43.0).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

FreeU

FreeU 通过重新平衡 UNet 解码器从主干特征与跳跃连接特征中提取信息的比例来提升图像细节。跳跃连接可能会淹没主干的语义特征,从而导致输出中出现不自然的细节。FreeU 无需训练,你可以在文本生成图像和文本生成视频推理流程中随时开启或关闭它。

FreeU 仅适用于基于 UNet 的流水线,例如 Stable Diffusion、SDXL 和 AnimateDiff。它不支持基于 Transformer 的流水线,例如 Flux 或 Qwen-Image。

在您的 pipeline 上使用 enable_freeu() 方法并配置缩放因子。b1 和 b2 用于放大主干特征,而 s1 和 s2 用于衰减跳跃特征。1 和 2 分别指代 UNet 解码器的前两个上采样阶段。有关不同模型的参考超参数,请参阅 FreeU 仓库。

从模型的仓库值开始。若要针对其他模型进行调优,请保持 s1=0.9 和 s2=0.2 不变,并优先调整 b1 和 b2。将四个因子全部设置为 1.0 等同于禁用 FreeU。较大的 b 值会增强效果,但可能会过度平滑精细纹理,而降低 s1 和 s2 可以抵消这种影响。

import torch
from diffusers import DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0", dtype=torch.float16,
).to("cuda")  # or "mps", "xpu", "cpu"
pipeline.enable_freeu(s1=0.9, s2=0.2, b1=1.3, b2=1.4)
generator = torch.Generator(device="cpu").manual_seed(13)
prompt = "A squirrel eating a burger"
image = pipeline(prompt, generator=generator).images[0]
image
FreeU 已禁用
已启用 FreeU

调用 disable_freeu() 方法以禁用 FreeU。

pipeline.disable_freeu()

后续步骤

Update on GitHub