bigghuggs commited on
Commit
89b61d5
·
verified ·
1 Parent(s): 9c6fad9

create genimage.py

Browse files
Files changed (1) hide show
  1. genimage.py +20 -0
genimage.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from diffusers import StableDiffusionXLPipeline, UNet2DConditionModel, EulerDiscreteScheduler
3
+ from huggingface_hub import hf_hub_download
4
+ from safetensors.torch import load_file
5
+
6
+ base = "stabilityai/stable-diffusion-xl-base-1.0"
7
+ repo = "ByteDance/SDXL-Lightning"
8
+ ckpt = "sdxl_lightning_2step_unet.safetensors" # Use the correct ckpt for your step setting!
9
+
10
+ # Load model.
11
+ unet = UNet2DConditionModel.from_config(base, subfolder="unet").to("cuda", torch.float16)
12
+ unet.load_state_dict(load_file(hf_hub_download(repo, ckpt), device="cuda"))
13
+ pipe = StableDiffusionXLPipeline.from_pretrained(base, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
14
+
15
+ # Ensure sampler uses "trailing" timesteps.
16
+ pipe.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.
19
+ #pipe("A girl smiling", num_inference_steps=2, guidance_scale=0).images[0].save("output.png")
20
+ pipe_public = pipe