Delete SDXL.py
Browse files
SDXL.py
DELETED
|
@@ -1,32 +0,0 @@
|
|
| 1 |
-
# https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0
|
| 2 |
-
# pip install diffusers transformers accelerate safetensors
|
| 3 |
-
# HF_ENDPOINT=https://hf-mirror.com python SDXL.py
|
| 4 |
-
|
| 5 |
-
## download
|
| 6 |
-
# git clone https://hf-mirror.com/stabilityai/stable-diffusion-xl-base-1.0
|
| 7 |
-
# cd unet && wget -c https://hf-mirror.com/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/unet/diffusion_pytorch_model.fp16.safetensors
|
| 8 |
-
# cd vae && wget -c https://hf-mirror.com/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/vae/diffusion_pytorch_model.fp16.safetensors
|
| 9 |
-
# wget -c https://hf-mirror.com/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0_0.9vae.safetensors
|
| 10 |
-
|
| 11 |
-
from diffusers import DiffusionPipeline
|
| 12 |
-
import torch
|
| 13 |
-
|
| 14 |
-
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
|
| 15 |
-
|
| 16 |
-
def t2i(prompt):
|
| 17 |
-
pipe = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
| 18 |
-
pipe.to("cuda")
|
| 19 |
-
|
| 20 |
-
# 使用 torch >= 2.0 时,通过 torch.compile 可以将推理速度提高 20-30%。在运行管道之前,使用 torchcompile 简单地包装unet:
|
| 21 |
-
# pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
| 22 |
-
|
| 23 |
-
# if using torch < 2.0
|
| 24 |
-
# pipe.enable_xformers_memory_efficient_attention()
|
| 25 |
-
|
| 26 |
-
image = pipe(prompt=prompt).images[0]
|
| 27 |
-
return image
|
| 28 |
-
|
| 29 |
-
if __name__ == "__main__":
|
| 30 |
-
prompt = "a girl in beijing"
|
| 31 |
-
image = t2i(prompt)
|
| 32 |
-
image.save("sdxl_output.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|