Add UNet weights in diffusers format
#2
by
dn6
HF staff
- opened
No description provided.
Will provide safetensors. Coming soon
dn6
changed pull request status to
open
I gotta say I am not a fan of this structure... And now it is kinda late to move .pth files into folders with .safetensors because some HF spaces already use them.
Here is what I propose.
We could upload safetensors to root directory following the same naming.
Change loading logic to this.
import torch
from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel
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_lora.safetensors"
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")
The benefits are
- We don't need to store model
config.json
- The naming is just way better. I prefer to have more general naming instead of diffusers specific naming.
Anything I do not foresee?
I already updated the doc on how to load unet pth using this new method to avoid downloading original SDXL.
Updated to safetensors. Closing this PR.
PeterL1n
changed pull request status to
closed