字节跳动SDXL

AI绘画

字节跳动的SDXL Lightning:一种快速的文本到图像模型,可通过4个步骤生成高质量图像

SDXL-lightning

介绍图片

SDXL-Lightning 是一种闪电般快速的文本到图像生成模型。它可以通过几个步骤生成高质量的 1024px 图像。欲了解更多信息,请参阅我们的研究论文:SDXL-Lightning:渐进式对抗扩散蒸馏。作为研究的一部分,我们开源了该模型。

我们的模型是从stableai/stable-diffusion-xl-base-1.0中提炼出来的。该存储库包含 1 步、2 步、4 步和 8 步蒸馏模型的检查点。我们的 2 步、4 步和 8 步模型的生成质量令人惊叹。我们的一步模型更具实验性。

我们提供完整的 UNet 和 LoRA 检查点。完整的 UNet 模型具有最佳质量,而 LoRA 模型可以应用于其他基础模型。

演示

社区已经制作了一些基于 SDXL-Lightning 的令人惊叹的第三方演示。在这里,我们精选了一些最好的:

  • 使用所有配置生成,最佳质量:演示
  • 打字时实时生成,速度快如闪电:Demo1Demo2
  • 与其他型号的比较:链接

扩散器的使用

请始终为相应的推理步骤使用正确的检查点。

2 步、4 步、8 步 UNet

import torch
from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file

base = "stabilityai/stable-diffusion-xl-base-1.0"
repo = "ByteDance/SDXL-Lightning"
ckpt = "sdxl_lightning_4step_unet.safetensors" # Use the correct ckpt for your step setting!

# Load model.
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")

# Ensure sampler uses "trailing" timesteps.
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")

# Ensure using the same inference steps as the loaded model and CFG set to 0.
pipe("A girl smiling", num_inference_steps=4, guidance_scale=0).images[0].save("output.png")

复制

2 步、4 步、8 步 LoRA

import torch
from diffusers import StableDiffusionXLPipeline, EulerDiscreteScheduler
from huggingface_hub import hf_hub_download

base = "stabilityai/stable-diffusion-xl-base-1.0"
repo = "ByteDance/SDXL-Lightning"
ckpt = "sdxl_lightning_4step_lora.safetensors" # Use the correct ckpt for your step setting!

# Load model.
pipe = StableDiffusionXLPipeline.from_pretrained(base, torch_dtype=torch.float16, variant="fp16").to("cuda")
pipe.load_lora_weights(hf_hub_download(repo, ckpt))
pipe.fuse_lora()

# Ensure sampler uses "trailing" timesteps.
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")

# Ensure using the same inference steps as the loaded model and CFG set to 0.
pipe("A girl smiling", num_inference_steps=4, guidance_scale=0).images[0].save("output.png")

复制

一步UNet

1步模型只是实验性的,质量不太稳定。考虑使用两步模型以获得更好的质量。

1步模型使用“样本”预测而不是“epsilon”预测!需要正确配置调度程序。

import torch
from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file

base = "stabilityai/stable-diffusion-xl-base-1.0"
repo = "ByteDance/SDXL-Lightning"
ckpt = "sdxl_lightning_1step_unet_x0.safetensors" # Use the correct ckpt for your step setting!

# Load model.
unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")

# Ensure sampler uses "trailing" timesteps and "sample" prediction type.
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", prediction_type="sample")

# Ensure using the same inference steps as the loaded model and CFG set to 0.
pipe("A girl smiling", num_inference_steps=1, guidance_scale=0).images[0].save("output.png")

复制

ComfyUI 用法

请始终为相应的推理步骤使用正确的检查点。请使用 Euler 采样器和 sgm_uniform 调度程序。

2 步、4 步、8 步 UNet

  1. 将完整的检查点 ( sdxl_lightning_Nstep.safetensors) 下载到/ComfyUI/models/checkpoints
  2. 下载我们的ComfyUI 完整工作流程

SDXL-Lightning ComfyUI 完整工作流程

2 步、4 步、8 步 LoRA

  1. 准备您自己的基础模型。
  2. 下载 LoRA 检查点 ( sdxl_lightning_Nstep_lora.safetensors) 到/ComfyUI/models/loras
  3. 下载我们的ComfyUI LoRA 工作流程

SDXL-Lightning ComfyUI LoRA 工作流程

一步UNet

1步模型只是实验性的,质量不太稳定。考虑使用两步模型以获得更好的质量。

  1. 将您的 ComfyUI 更新到最新版本。
  2. 将完整的检查点 ( sdxl_lightning_1step_x0.safetensors) 下载到/ComfyUI/models/checkpoints
  3. 下载我们的ComfyUI 完整的一步工作流程

SDXL-Lightning ComfyUI 完整的 1 步工作流程

引用我们的工作

@misc{lin2024sdxllightning,
      title={SDXL-Lightning: Progressive Adversarial Diffusion Distillation}, 
      author={Shanchuan Lin and Anran Wang and Xiao Yang},
      year={2024},
      eprint={2402.13929},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}