-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_diffusers_fg_only_sdxl.py
36 lines (27 loc) · 1.35 KB
/
test_diffusers_fg_only_sdxl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from huggingface_hub import hf_hub_download
from safetensors.torch import load_file
import torch
from diffusers import StableDiffusionXLPipeline
from layer_diffuse.models import TransparentVAEDecoder
if __name__ == "__main__":
transparent_vae = TransparentVAEDecoder.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
transparent_vae.config.force_upcast = False
model_path = hf_hub_download(
'LayerDiffusion/layerdiffusion-v1',
'vae_transparent_decoder.safetensors',
)
transparent_vae.set_transparent_decoder(load_file(model_path))
pipeline = StableDiffusionXLPipeline.from_pretrained(
"stabilityai/stable-diffusion-xl-base-1.0",
vae=transparent_vae,
torch_dtype=torch.float16, variant="fp16", use_safetensors=True, add_watermarker=False
).to("cuda")
pipeline.load_lora_weights('rootonchair/diffuser_layerdiffuse', weight_name='diffuser_layer_xl_transparent_attn.safetensors')
seed = torch.randint(high=1000000, size=(1,)).item()
prompt = "a cute corgi"
negative_prompt = ""
images = pipeline(prompt=prompt,
negative_prompt=negative_prompt,
generator=torch.Generator(device='cuda').manual_seed(seed),
num_images_per_prompt=1, return_dict=False)[0]
images[0].save("result_sdxl.png")