Commit
·
9478dd2
1
Parent(s):
811d1c6
make style
Browse files- 1 +0 -26
- run_local.py +3 -3
- run_local_fuse_xl.py +3 -3
- run_local_xl.py +3 -1
- run_lora.py +9 -9
1
DELETED
@@ -1,26 +0,0 @@
|
|
1 |
-
#!/usr/bin/env python3
|
2 |
-
from diffusers import UNet2DConditionModel
|
3 |
-
import torch
|
4 |
-
|
5 |
-
unet = UNet2DConditionModel.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", subfolder="unet", variant="fp16", torch_dtype=torch.float16)
|
6 |
-
unet.train()
|
7 |
-
unet.enable_gradient_checkpointing()
|
8 |
-
unet = unet.to("cuda:1")
|
9 |
-
|
10 |
-
batch_size = 8
|
11 |
-
|
12 |
-
sample = torch.randn((1, 4, 128, 128)).half().to(unet.device).repeat(batch_size, 1, 1, 1)
|
13 |
-
time_ids = (torch.arange(6) / 6)[None, :].half().to(unet.device).repeat(batch_size, 1)
|
14 |
-
encoder_hidden_states = torch.randn((1, 77, 2048)).half().to(unet.device).repeat(batch_size, 1, 1)
|
15 |
-
text_embeds = torch.randn((1, 1280)).half().to(unet.device).repeat(batch_size, 1)
|
16 |
-
|
17 |
-
out = unet(sample, 1.0, added_cond_kwargs={"time_ids": time_ids, "text_embeds": text_embeds}, encoder_hidden_states=encoder_hidden_states).sample
|
18 |
-
|
19 |
-
loss = ((out - sample) ** 2).mean()
|
20 |
-
loss.backward()
|
21 |
-
|
22 |
-
print(torch.cuda.max_memory_allocated(device=unet.device))
|
23 |
-
|
24 |
-
|
25 |
-
# no gradient checkpointing: 12,276,695,552
|
26 |
-
# curr gradient checkpointing: 10,862,276,096
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
run_local.py
CHANGED
@@ -13,13 +13,13 @@ from io import BytesIO
|
|
13 |
|
14 |
path = sys.argv[1]
|
15 |
# path = "ptx0/pseudo-journey-v2"
|
16 |
-
# path = "stabilityai/stable-diffusion-2-1"
|
17 |
|
18 |
api = HfApi()
|
19 |
start_time = time.time()
|
20 |
pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
|
|
|
21 |
|
22 |
-
pipe.unet = torch.compile(pipe.unet)
|
23 |
|
24 |
# pipe = StableDiffusionImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16, safety_checker=None)
|
25 |
|
@@ -45,7 +45,7 @@ prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intric
|
|
45 |
|
46 |
generator = torch.Generator(device="cpu").manual_seed(0)
|
47 |
# images = pipe(prompt=prompt, image=image, generator=generator, num_images_per_prompt=4, num_inference_steps=25).images
|
48 |
-
images = pipe(prompt=prompt, generator=generator, num_images_per_prompt=
|
49 |
|
50 |
for i, image in enumerate(images):
|
51 |
file_name = f"bb_1_{i}"
|
|
|
13 |
|
14 |
path = sys.argv[1]
|
15 |
# path = "ptx0/pseudo-journey-v2"
|
|
|
16 |
|
17 |
api = HfApi()
|
18 |
start_time = time.time()
|
19 |
pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
|
20 |
+
pipe.enable_xformers_memory_efficient_attention()
|
21 |
|
22 |
+
# pipe.unet = torch.compile(pipe.unet)
|
23 |
|
24 |
# pipe = StableDiffusionImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16, safety_checker=None)
|
25 |
|
|
|
45 |
|
46 |
generator = torch.Generator(device="cpu").manual_seed(0)
|
47 |
# images = pipe(prompt=prompt, image=image, generator=generator, num_images_per_prompt=4, num_inference_steps=25).images
|
48 |
+
images = pipe(prompt=prompt, generator=generator, num_images_per_prompt=1, num_inference_steps=50).images
|
49 |
|
50 |
for i, image in enumerate(images):
|
51 |
file_name = f"bb_1_{i}"
|
run_local_fuse_xl.py
CHANGED
@@ -13,14 +13,14 @@ import torch
|
|
13 |
|
14 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
|
15 |
pipe.load_lora_weights("stabilityai/stable-diffusion-xl-base-1.0", weight_name="sd_xl_offset_example-lora_1.0.safetensors")
|
16 |
-
pipe.unet.fuse_lora()
|
17 |
|
18 |
pipe.to(torch_dtype=torch.float16)
|
19 |
pipe.to("cuda")
|
20 |
|
21 |
-
torch.manual_seed(
|
22 |
|
23 |
-
prompt = "beautiful scenery nature glass bottle landscape,
|
24 |
negative_prompt = "text, watermark"
|
25 |
|
26 |
image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=25).images[0]
|
|
|
13 |
|
14 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
|
15 |
pipe.load_lora_weights("stabilityai/stable-diffusion-xl-base-1.0", weight_name="sd_xl_offset_example-lora_1.0.safetensors")
|
16 |
+
# pipe.unet.fuse_lora()
|
17 |
|
18 |
pipe.to(torch_dtype=torch.float16)
|
19 |
pipe.to("cuda")
|
20 |
|
21 |
+
torch.manual_seed(33)
|
22 |
|
23 |
+
prompt = "beautiful scenery nature glass bottle landscape, purple galaxy bottle"
|
24 |
negative_prompt = "text, watermark"
|
25 |
|
26 |
image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=25).images[0]
|
run_local_xl.py
CHANGED
@@ -12,12 +12,13 @@ from pathlib import Path
|
|
12 |
import requests
|
13 |
from PIL import Image
|
14 |
from io import BytesIO
|
|
|
15 |
|
16 |
api = HfApi()
|
17 |
start_time = time.time()
|
18 |
|
19 |
# use_refiner = bool(int(sys.argv[1]))
|
20 |
-
use_refiner =
|
21 |
use_diffusers = True
|
22 |
path = "stabilityai/stable-diffusion-xl-base-1.0"
|
23 |
refiner_path = "stabilityai/stable-diffusion-xl-refiner-1.0"
|
@@ -27,6 +28,7 @@ vae = AutoencoderKL.from_pretrained(vae_path, torch_dtype=torch.float16, force_u
|
|
27 |
if use_diffusers:
|
28 |
# pipe = StableDiffusionXLPipeline.from_pretrained(path, vae=vae, torch_dtype=torch.float16, variant="fp16", use_safetensors=True, local_files_only=True)
|
29 |
pipe = StableDiffusionXLPipeline.from_pretrained(path, torch_dtype=torch.float16, vae=vae, variant="fp16", use_safetensors=True, local_files_only=True, add_watermarker=False)
|
|
|
30 |
print(time.time() - start_time)
|
31 |
pipe.to("cuda")
|
32 |
|
|
|
12 |
import requests
|
13 |
from PIL import Image
|
14 |
from io import BytesIO
|
15 |
+
import xformers
|
16 |
|
17 |
api = HfApi()
|
18 |
start_time = time.time()
|
19 |
|
20 |
# use_refiner = bool(int(sys.argv[1]))
|
21 |
+
use_refiner = False
|
22 |
use_diffusers = True
|
23 |
path = "stabilityai/stable-diffusion-xl-base-1.0"
|
24 |
refiner_path = "stabilityai/stable-diffusion-xl-refiner-1.0"
|
|
|
28 |
if use_diffusers:
|
29 |
# pipe = StableDiffusionXLPipeline.from_pretrained(path, vae=vae, torch_dtype=torch.float16, variant="fp16", use_safetensors=True, local_files_only=True)
|
30 |
pipe = StableDiffusionXLPipeline.from_pretrained(path, torch_dtype=torch.float16, vae=vae, variant="fp16", use_safetensors=True, local_files_only=True, add_watermarker=False)
|
31 |
+
# pipe.enable_xformers_memory_efficient_attention()
|
32 |
print(time.time() - start_time)
|
33 |
pipe.to("cuda")
|
34 |
|
run_lora.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
-
from diffusers import StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler, DPMSolverMultistepScheduler
|
3 |
import time
|
4 |
import os
|
5 |
from huggingface_hub import HfApi
|
@@ -11,20 +11,20 @@ import requests
|
|
11 |
from PIL import Image
|
12 |
from io import BytesIO
|
13 |
|
14 |
-
path = "
|
15 |
-
lora_id = "takuma104/lora-test-text-encoder-lora-target"
|
16 |
|
17 |
api = HfApi()
|
18 |
start_time = time.time()
|
19 |
-
pipe =
|
20 |
-
pipe.
|
21 |
-
|
|
|
|
|
22 |
|
23 |
-
prompt = "
|
24 |
|
25 |
images = pipe(prompt=prompt,
|
26 |
-
num_inference_steps=
|
27 |
-
cross_attention_kwargs={"scale": 0.5},
|
28 |
generator=torch.manual_seed(0)
|
29 |
).images
|
30 |
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
+
from diffusers import AutoPipelineForText2Image, StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler, DPMSolverMultistepScheduler
|
3 |
import time
|
4 |
import os
|
5 |
from huggingface_hub import HfApi
|
|
|
11 |
from PIL import Image
|
12 |
from io import BytesIO
|
13 |
|
14 |
+
path = "stabilityai/stable-diffusion-xl-base-0.9"
|
|
|
15 |
|
16 |
api = HfApi()
|
17 |
start_time = time.time()
|
18 |
+
pipe = AutoPipelineForText2Image.from_pretrained(path, torch_dtype=torch.float16)
|
19 |
+
pipe.enable_model_cpu_offload()
|
20 |
+
lora_model_id = "hf-internal-testing/sdxl-0.9-kamepan-lora"
|
21 |
+
lora_filename = "kame_sdxl_v2-000020-16rank.safetensors"
|
22 |
+
pipe.load_lora_weights(lora_model_id, weight_name=lora_filename)
|
23 |
|
24 |
+
prompt = "masterpiece, best quality, mountain"
|
25 |
|
26 |
images = pipe(prompt=prompt,
|
27 |
+
num_inference_steps=20,
|
|
|
28 |
generator=torch.manual_seed(0)
|
29 |
).images
|
30 |
|