Commit
·
6421583
1
Parent(s):
1a844e7
finish
Browse files- run_kandinsky.py +1 -2
- run_local_xl.py +9 -7
- run_xl_ediffi.py +12 -8
run_kandinsky.py
CHANGED
|
@@ -17,8 +17,7 @@ negative_prompt = "low quality, bad quality"
|
|
| 17 |
generator = torch.Generator(device="cuda").manual_seed(10)
|
| 18 |
image_embeds, negative_image_embeds = pipe_prior(prompt, negative_prompt, guidance_scale=1.0, generator=generator).to_tuple()
|
| 19 |
|
| 20 |
-
|
| 21 |
-
t2i_pipe = DiffusionPipeline.from_pretrained("../kandinsky-2-1/", scheduler=scheduler, torch_dtype=torch.float16)
|
| 22 |
t2i_pipe.to("cuda")
|
| 23 |
print(t2i_pipe.scheduler.config)
|
| 24 |
|
|
|
|
| 17 |
generator = torch.Generator(device="cuda").manual_seed(10)
|
| 18 |
image_embeds, negative_image_embeds = pipe_prior(prompt, negative_prompt, guidance_scale=1.0, generator=generator).to_tuple()
|
| 19 |
|
| 20 |
+
t2i_pipe = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
|
|
|
|
| 21 |
t2i_pipe.to("cuda")
|
| 22 |
print(t2i_pipe.scheduler.config)
|
| 23 |
|
run_local_xl.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
from diffusers import DiffusionPipeline, EulerDiscreteScheduler, StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler
|
| 3 |
-
from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipeline
|
| 4 |
import time
|
| 5 |
from pytorch_lightning import seed_everything
|
| 6 |
import os
|
|
@@ -19,15 +19,15 @@ start_time = time.time()
|
|
| 19 |
use_refiner = bool(int(sys.argv[1]))
|
| 20 |
use_diffusers = True
|
| 21 |
|
|
|
|
| 22 |
if use_diffusers:
|
| 23 |
-
|
| 24 |
-
pipe = StableDiffusionXLPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", torch_dtype=torch.float16, variant="fp16", use_safetensors=True, local_files_only=True)
|
| 25 |
print(time.time() - start_time)
|
| 26 |
pipe.to("cuda")
|
| 27 |
|
| 28 |
if use_refiner:
|
| 29 |
start_time = time.time()
|
| 30 |
-
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
| 31 |
print(time.time() - start_time)
|
| 32 |
refiner.to("cuda")
|
| 33 |
# refiner.enable_sequential_cpu_offload()
|
|
@@ -45,13 +45,15 @@ else:
|
|
| 45 |
|
| 46 |
|
| 47 |
prompt = "An astronaut riding a green horse on Mars"
|
| 48 |
-
steps =
|
| 49 |
seed = 0
|
| 50 |
seed_everything(seed)
|
| 51 |
-
|
|
|
|
|
|
|
| 52 |
|
| 53 |
if use_refiner:
|
| 54 |
-
image = refiner(prompt=prompt, num_inference_steps=steps - 10, image=image
|
| 55 |
|
| 56 |
file_name = f"aaa"
|
| 57 |
path = os.path.join(Path.home(), "images", "ediffi_sdxl", f"{file_name}.png")
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
from diffusers import DiffusionPipeline, EulerDiscreteScheduler, StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler
|
| 3 |
+
from diffusers import StableDiffusionXLPipeline, StableDiffusionXLImg2ImgPipeline, AutoencoderKL
|
| 4 |
import time
|
| 5 |
from pytorch_lightning import seed_everything
|
| 6 |
import os
|
|
|
|
| 19 |
use_refiner = bool(int(sys.argv[1]))
|
| 20 |
use_diffusers = True
|
| 21 |
|
| 22 |
+
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16, force_upcast=True)
|
| 23 |
if use_diffusers:
|
| 24 |
+
pipe = StableDiffusionXLPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", vae=vae, torch_dtype=torch.float16, variant="fp16", use_safetensors=True, local_files_only=True)
|
|
|
|
| 25 |
print(time.time() - start_time)
|
| 26 |
pipe.to("cuda")
|
| 27 |
|
| 28 |
if use_refiner:
|
| 29 |
start_time = time.time()
|
| 30 |
+
refiner = StableDiffusionXLImg2ImgPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", vae=vae, torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
| 31 |
print(time.time() - start_time)
|
| 32 |
refiner.to("cuda")
|
| 33 |
# refiner.enable_sequential_cpu_offload()
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
prompt = "An astronaut riding a green horse on Mars"
|
| 48 |
+
steps = 20
|
| 49 |
seed = 0
|
| 50 |
seed_everything(seed)
|
| 51 |
+
start_time = time.time()
|
| 52 |
+
image = pipe(prompt=prompt, num_inference_steps=steps, output_type="pil").images[0]
|
| 53 |
+
print(time.time() - start_time)
|
| 54 |
|
| 55 |
if use_refiner:
|
| 56 |
+
image = refiner(prompt=prompt, num_inference_steps=steps - 10, image=image).images[0]
|
| 57 |
|
| 58 |
file_name = f"aaa"
|
| 59 |
path = os.path.join(Path.home(), "images", "ediffi_sdxl", f"{file_name}.png")
|
run_xl_ediffi.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
from diffusers import DiffusionPipeline, EulerDiscreteScheduler, StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler
|
| 3 |
-
from diffusers import
|
| 4 |
import time
|
| 5 |
from pytorch_lightning import seed_everything
|
| 6 |
import os
|
|
@@ -18,22 +18,26 @@ from torch.nn.functional import fractional_max_pool2d_with_indices
|
|
| 18 |
api = HfApi()
|
| 19 |
start_time = time.time()
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
| 22 |
pipe_high_noise.to("cuda")
|
| 23 |
|
| 24 |
-
pipe_low_noise =
|
|
|
|
| 25 |
pipe_low_noise.to("cuda")
|
| 26 |
|
| 27 |
prompt = "A majestic lion jumping from a big stone at night"
|
| 28 |
|
| 29 |
num_inference_steps = 40
|
| 30 |
-
high_noise_frac =
|
| 31 |
|
| 32 |
-
seed = 0
|
| 33 |
-
seed_everything(seed)
|
| 34 |
|
| 35 |
-
image = pipe_high_noise(prompt=prompt, num_inference_steps=num_inference_steps, denoising_end=high_noise_frac).images
|
| 36 |
-
|
| 37 |
|
| 38 |
file_name = f"aaa_1"
|
| 39 |
path = os.path.join(Path.home(), "images", "ediffi_sdxl", f"{file_name}.png")
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
from diffusers import DiffusionPipeline, EulerDiscreteScheduler, StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler
|
| 3 |
+
from diffusers import DiffusionPipeline
|
| 4 |
import time
|
| 5 |
from pytorch_lightning import seed_everything
|
| 6 |
import os
|
|
|
|
| 18 |
api = HfApi()
|
| 19 |
start_time = time.time()
|
| 20 |
|
| 21 |
+
model_id = "stabilityai/stable-diffusion-xl-base-0.9"
|
| 22 |
+
model_id = "runwayml/stable-diffusion-v1-5"
|
| 23 |
+
pipe_high_noise = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, variant="fp16", use_safetensors=True, local_files_only=True)
|
| 24 |
+
pipe_high_noise.scheduler = EulerDiscreteScheduler.from_config(pipe_high_noise.scheduler.config)
|
| 25 |
pipe_high_noise.to("cuda")
|
| 26 |
|
| 27 |
+
pipe_low_noise = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
| 28 |
+
pipe_low_noise.scheduler = EulerDiscreteScheduler.from_config(pipe_low_noise.scheduler.config)
|
| 29 |
pipe_low_noise.to("cuda")
|
| 30 |
|
| 31 |
prompt = "A majestic lion jumping from a big stone at night"
|
| 32 |
|
| 33 |
num_inference_steps = 40
|
| 34 |
+
high_noise_frac = 0.8
|
| 35 |
|
| 36 |
+
# seed = 0
|
| 37 |
+
# seed_everything(seed)
|
| 38 |
|
| 39 |
+
image = pipe_high_noise(prompt=prompt, num_inference_steps=num_inference_steps, denoising_end=high_noise_frac, output_type="pt").images
|
| 40 |
+
image = pipe_low_noise(prompt=prompt, num_inference_steps=num_inference_steps, denoising_start=high_noise_frac, image=image).images[0]
|
| 41 |
|
| 42 |
file_name = f"aaa_1"
|
| 43 |
path = os.path.join(Path.home(), "images", "ediffi_sdxl", f"{file_name}.png")
|