Views
No views yet

sdxl_lightning_Nstep.safetensors: All-in-one checkpoint, for ComfyUI.sdxl_lightning_Nstep_unet.safetensors: UNet checkpoint only, for Diffusers.sdxl_lightning_Nstep_lora.safetensors: LoRA checkpoint, for Diffusers and ComfyUI.1import torch
2from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler
3from huggingface_hub import hf_hub_download
4from safetensors.torch import load_file
5
6base = "stabilityai/stable-diffusion-xl-base-1.0"
7repo = "ByteDance/SDXL-Lightning"
8ckpt = "sdxl_lightning_4step_unet.safetensors" # Use the correct ckpt for your step setting!
9
10# Load model.
11unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
12unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
13pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
14
15# Ensure sampler uses "trailing" timesteps.
16pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
17
18# Ensure using the same inference steps as the loaded model and CFG set to 0.
19pipe("A girl smiling", num_inference_steps=4, guidance_scale=0).images[0].save("output.png")1import torch
2from diffusers import StableDiffusionXLPipeline, EulerDiscreteScheduler
3from huggingface_hub import hf_hub_download
4
5base = "stabilityai/stable-diffusion-xl-base-1.0"
6repo = "ByteDance/SDXL-Lightning"
7ckpt = "sdxl_lightning_4step_lora.safetensors" # Use the correct ckpt for your step setting!
8
9# Load model.
10pipe = StableDiffusionXLPipeline.from_pretrained(base, torch_dtype=torch.float16, variant="fp16").to("cuda")
11pipe.load_lora_weights(hf_hub_download(repo, ckpt))
12pipe.fuse_lora()
13
14# Ensure sampler uses "trailing" timesteps.
15pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
16
17# Ensure using the same inference steps as the loaded model and CFG set to 0.
18pipe("A girl smiling", num_inference_steps=4, guidance_scale=0).images[0].save("output.png")1import torch
2from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler
3from huggingface_hub import hf_hub_download
4from safetensors.torch import load_file
5
6base = "stabilityai/stable-diffusion-xl-base-1.0"
7repo = "ByteDance/SDXL-Lightning"
8ckpt = "sdxl_lightning_1step_unet_x0.safetensors" # Use the correct ckpt for your step setting!
9
10# Load model.
11unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
12unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
13pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
14
15# Ensure sampler uses "trailing" timesteps and "sample" prediction type.
16pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing", prediction_type="sample")
17
18# Ensure using the same inference steps as the loaded model and CFG set to 0.
19pipe("A girl smiling", num_inference_steps=1, guidance_scale=0).images[0].save("output.png")sdxl_lightning_Nstep.safetensors) to /ComfyUI/models/checkpoints.
sdxl_lightning_Nstep_lora.safetensors) to /ComfyUI/models/loras
sdxl_lightning_1step_x0.safetensors) to /ComfyUI/models/checkpoints.
@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}
}