WithAI.Design

5 min read

就在刚刚!字节发布SDXLlightning!没有最快只有更快!

就在刚刚!字节发布SDXLlightning!没有最快只有更快!

就在刚刚,字节发布了SDXL-lightning模型,速度和质量上已经超越了LCM和SDXL-turbo,速度快如闪电!!

速度和效果王炸!

速度

大家可以感受以下速度,使用了一步UNet的工作流,视频没有加速:

SDXL-lightning01.gif

4090显卡,生成1024x1024分辨率的图,在0.5秒以内,几乎是实时了。

质量

出图效果跟SDXL正常步数出图的效果差不多了。但貌似用非1024x1024分辨率出图会有问题。这里质量最好的8步模型,后面大家使用的时候可以根据实际需求选择。

速度有多重要?

关注AI绘画的朋友应该都还记得,LCM和SDXL turbo出来的时候,海外的AI公司Kera就推出了实时绘画功能,震惊了业界,其背后技术,就是用了LCM技术。

SDXL-lightning02.gif

SDXL-lightning03.gif

根据其技术原理,我也在本地搭了comfyui工作流,使用ipad和3D软件,复现了实时绘画的功能。

但因为是采用了LCM,底模是SD1.5的,所以效果和出图尺寸上还是比不上SDXL,现在SDXL-lightning的推出,恰好弥补了质量和分辨率的问题。 后续,我会用SDXL-lightning模型,进行实时绘画的测试。

如何使用?

多种方式,灵活使用

官方在抱脸上https://huggingface.co/ByteDance/SDXL-Lightning已经有详细说明了,也有官方的comfyui工作流,使用起来非常简单。目前有几种方式:

  1. 底模模式。直接使用SDXL-lightning底模,支持2-8步的采样;
  2. UNET模式。使用UNET,最低支持1步,但官方表示,1步可能不稳定;
  3. LoRA模式。通过加载LoRA方式加速,支持支持2-8步的采样;

官方说明

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 模型可以应用于其他基础模型。

扩散器的使用

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

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 完整工作流程

2 步、4 步、8 步 LoRA

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

一步UNet

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

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

关注我公众号(设计小站):sjxz00,获取更多AI辅助设计和设计灵感趋势。

标签