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.42.1).
Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

FreeU

FreeU improves image detail by rebalancing how much the UNet decoder draws from backbone features versus skip-connection features. Skip connections can drown out the backbone’s semantic features, which produces unnatural detail in the output. FreeU needs no training, and you can turn it on or off at inference time for text-to-image and text-to-video pipelines.

FreeU работает только с пайплайнами на основе UNet, такими как Stable Diffusion, SDXL и AnimateDiff. Он не поддерживается в пайплайнах на основе трансформеров, таких как Flux или Qwen-Image.

Используйте метод 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()

Дальнейшие шаги

  • См. справочник API enable_freeu() для полного описания параметров.
  • Попробуйте FreeU для видео с AnimateDiff.
Update on GitHub