patrickvonplaten
commited on
Commit
•
7f2323b
1
Parent(s):
df3b621
test all
Browse files- _ +35 -0
- benchmark/sd_inpaint.py +22 -7
- hey.npy +3 -0
- run_local_img2img_xl.py +3 -2
- run_local_xl.py +15 -16
- run_video.py +24 -5
- ~ +51 -0
_
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
import torch
|
3 |
+
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
4 |
+
import numpy as np
|
5 |
+
import gc
|
6 |
+
from diffusers.utils import export_to_video
|
7 |
+
from PIL import Image
|
8 |
+
|
9 |
+
pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_576w", torch_dtype=torch.float16)
|
10 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
11 |
+
pipe.enable_model_cpu_offload()
|
12 |
+
pipe.enable_xformers_memory_efficient_attention()
|
13 |
+
pipe.enable_vae_slicing()
|
14 |
+
|
15 |
+
prompt = "spiderman running in the desert"
|
16 |
+
video_frames = pipe(prompt, num_inference_steps=2, height=320, width=576, num_frames=24, output_type="latent".frames
|
17 |
+
# video_path = export_to_video(video_frames, output_video_path="/home/patrick/videos/video_576_spiderman_24.mp4")
|
18 |
+
|
19 |
+
pipe.to("cpu")
|
20 |
+
del pipe
|
21 |
+
gc.collect()
|
22 |
+
torch.cuda.empty_cache()
|
23 |
+
|
24 |
+
import ipdb; ipdb.set_trace()
|
25 |
+
|
26 |
+
pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_XL", torch_dtype=torch.float16)
|
27 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
28 |
+
pipe.enable_model_cpu_offload()
|
29 |
+
pipe.enable_xformers_memory_efficient_attention()
|
30 |
+
pipe.enable_vae_slicing()
|
31 |
+
|
32 |
+
video = [Image.fromarray(frame).resize((1024, 576)) for frame in video_frames]
|
33 |
+
|
34 |
+
video_frames = pipe(prompt, video=video, num_inference_steps=2, strength=0.6).frames
|
35 |
+
video_path = export_to_video(video_frames, output_video_path="/home/patrick/videos/video_1024_spiderman_24.mp4")
|
benchmark/sd_inpaint.py
CHANGED
@@ -4,6 +4,11 @@ import requests
|
|
4 |
import torch
|
5 |
from PIL import Image
|
6 |
from io import BytesIO
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
|
9 |
|
@@ -24,13 +29,23 @@ run_compile = True # Set True / False
|
|
24 |
|
25 |
pipe = StableDiffusionInpaintPipeline.from_pretrained(path, torch_dtype=torch.float16)
|
26 |
pipe = pipe.to("cuda:0")
|
27 |
-
pipe.unet.to(memory_format=torch.channels_last)
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
|
|
34 |
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
4 |
import torch
|
5 |
from PIL import Image
|
6 |
from io import BytesIO
|
7 |
+
import os
|
8 |
+
from pathlib import Path
|
9 |
+
from huggingface_hub import HfApi
|
10 |
+
|
11 |
+
api = HfApi()
|
12 |
|
13 |
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
|
14 |
|
|
|
29 |
|
30 |
pipe = StableDiffusionInpaintPipeline.from_pretrained(path, torch_dtype=torch.float16)
|
31 |
pipe = pipe.to("cuda:0")
|
|
|
32 |
|
33 |
+
torch.manual_seed(33)
|
34 |
+
|
35 |
+
prompt = "A cute dog"
|
36 |
+
|
37 |
+
image = pipe(prompt=prompt, image=init_image, mask_image=mask_image, force_unmasked_unchanged=True).images[0]
|
38 |
+
# image = pipe(prompt=prompt, image=init_image, mask_image=mask_image, force_unmasked_unchanged=False).images[0]
|
39 |
+
|
40 |
+
file_name = "aa"
|
41 |
|
42 |
+
path = os.path.join(Path.home(), "images", f"{file_name}.png")
|
43 |
+
image.save(path)
|
44 |
|
45 |
+
api.upload_file(
|
46 |
+
path_or_fileobj=path,
|
47 |
+
path_in_repo=path.split("/")[-1],
|
48 |
+
repo_id="patrickvonplaten/images",
|
49 |
+
repo_type="dataset",
|
50 |
+
)
|
51 |
+
print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{file_name}.png")
|
hey.npy
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3d14df8aac190ef2626cc2bd48c4428152a170029bc8322d190c1d2481d9c914
|
3 |
+
size 8847488
|
run_local_img2img_xl.py
CHANGED
@@ -16,7 +16,8 @@ path = sys.argv[1]
|
|
16 |
|
17 |
api = HfApi()
|
18 |
start_time = time.time()
|
19 |
-
pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(path)
|
|
|
20 |
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
21 |
# pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
22 |
# pipe = StableDiffusionImg2ImgXLPipeline.from_pretrained(path, torch_dtype=torch.float16, safety_checker=None
|
@@ -33,7 +34,7 @@ prompt = "An astronaut riding a green horse on Mars"
|
|
33 |
# url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
|
34 |
#
|
35 |
# response = requests.get(url)
|
36 |
-
init_image = torch.from_numpy(np.load("/home/patrick/images/xl_latents.npy"))
|
37 |
|
38 |
image = pipe(prompt=prompt, image=init_image).images[0]
|
39 |
|
|
|
16 |
|
17 |
api = HfApi()
|
18 |
start_time = time.time()
|
19 |
+
pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16)
|
20 |
+
pipe.to("cuda")
|
21 |
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
22 |
# pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
23 |
# pipe = StableDiffusionImg2ImgXLPipeline.from_pretrained(path, torch_dtype=torch.float16, safety_checker=None
|
|
|
34 |
# url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
|
35 |
#
|
36 |
# response = requests.get(url)
|
37 |
+
init_image = torch.from_numpy(np.load("/home/patrick/images/xl_latents.npy")).to("cuda")
|
38 |
|
39 |
image = pipe(prompt=prompt, image=init_image).images[0]
|
40 |
|
run_local_xl.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
from diffusers import DiffusionPipeline, EulerDiscreteScheduler, StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler
|
3 |
import time
|
|
|
4 |
import os
|
5 |
from huggingface_hub import HfApi
|
6 |
# from compel import Compel
|
@@ -11,33 +12,31 @@ import requests
|
|
11 |
from PIL import Image
|
12 |
from io import BytesIO
|
13 |
|
14 |
-
path = sys.argv[1]
|
15 |
-
|
16 |
api = HfApi()
|
17 |
start_time = time.time()
|
18 |
-
pipe = DiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
|
19 |
-
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
20 |
-
# pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
21 |
-
# pipe = StableDiffusionImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16, safety_checker=None
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
24 |
|
|
|
|
|
|
|
25 |
|
26 |
-
|
|
|
|
|
27 |
|
28 |
-
|
|
|
29 |
|
30 |
# pipe.unet.to(memory_format=torch.channels_last)
|
31 |
# pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
32 |
# pipe(prompt=prompt, num_inference_steps=2).images[0]
|
33 |
|
34 |
-
image = pipe(prompt=prompt, num_images_per_prompt=1, num_inference_steps=40, output_type="latent").images
|
35 |
-
pipe.to("cpu")
|
36 |
-
|
37 |
-
pipe = DiffusionPipeline.from_pretrained("/home/patrick/diffusers-sd-xl/stable-diffusion-xl-refiner-0.9", torch_dtype=torch.float16)
|
38 |
-
pipe.to("cuda")
|
39 |
-
|
40 |
-
image = pipe(prompt=prompt, image=image, strength=0.5).images[0]
|
41 |
|
42 |
file_name = f"aaa"
|
43 |
path = os.path.join(Path.home(), "images", f"{file_name}.png")
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
from diffusers import DiffusionPipeline, EulerDiscreteScheduler, StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler
|
3 |
import time
|
4 |
+
from pytorch_lightning import seed_everything
|
5 |
import os
|
6 |
from huggingface_hub import HfApi
|
7 |
# from compel import Compel
|
|
|
12 |
from PIL import Image
|
13 |
from io import BytesIO
|
14 |
|
|
|
|
|
15 |
api = HfApi()
|
16 |
start_time = time.time()
|
|
|
|
|
|
|
|
|
17 |
|
18 |
+
use_refiner = bool(int(sys.argv[1]))
|
19 |
+
|
20 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", torch_dtype=torch.float16, variant="fp16", use_safetensors=True)
|
21 |
+
pipe.to("cuda")
|
22 |
+
# pipe.enable_model_cpu_offload()
|
23 |
|
24 |
+
if use_refiner:
|
25 |
+
refiner = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-refiner-0.9", torch_dtype=torch.float16)
|
26 |
+
refiner.enable_model_cpu_offload()
|
27 |
|
28 |
+
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
|
29 |
+
seed_everything(0)
|
30 |
+
image = pipe(prompt=prompt, output_type="latent" if use_refiner else "pil").images[0]
|
31 |
|
32 |
+
if use_refiner:
|
33 |
+
image = refiner(prompt=prompt, image=image[None, :]).imagas[0]
|
34 |
|
35 |
# pipe.unet.to(memory_format=torch.channels_last)
|
36 |
# pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
37 |
# pipe(prompt=prompt, num_inference_steps=2).images[0]
|
38 |
|
39 |
+
# image = pipe(prompt=prompt, num_images_per_prompt=1, num_inference_steps=40, output_type="latent").images
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
file_name = f"aaa"
|
42 |
path = os.path.join(Path.home(), "images", f"{file_name}.png")
|
run_video.py
CHANGED
@@ -1,12 +1,31 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
import torch
|
3 |
-
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
|
|
|
|
4 |
from diffusers.utils import export_to_video
|
|
|
5 |
|
6 |
-
pipe =
|
7 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
8 |
pipe.enable_model_cpu_offload()
|
|
|
9 |
|
10 |
-
prompt = "
|
11 |
-
video_frames = pipe(prompt, num_inference_steps=
|
12 |
-
video_path = export_to_video(video_frames, output_video_path="/home/patrick/videos/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
import torch
|
3 |
+
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler, TextToVideoSDPipeline
|
4 |
+
import numpy as np
|
5 |
+
import gc
|
6 |
from diffusers.utils import export_to_video
|
7 |
+
from PIL import Image
|
8 |
|
9 |
+
pipe = TextToVideoSDPipeline.from_pretrained("cerspense/zeroscope_v2_XL", torch_dtype=torch.float16)
|
10 |
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
11 |
pipe.enable_model_cpu_offload()
|
12 |
+
pipe.enable_vae_slicing()
|
13 |
|
14 |
+
prompt = "spiderman running in the desert"
|
15 |
+
video_frames = pipe(prompt, num_inference_steps=2, height=576, width=1024, num_frames=24).frames
|
16 |
+
# video_path = export_to_video(video_frames, output_video_path="/home/patrick/videos/video_576_spiderman_24.mp4")
|
17 |
+
pipe.to("cpu")
|
18 |
+
import ipdb; ipdb.set_trace()
|
19 |
+
|
20 |
+
del pipe
|
21 |
+
gc.collect()
|
22 |
+
torch.cuda.empty_cache()
|
23 |
+
|
24 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
|
25 |
+
pipe.enable_model_cpu_offload()
|
26 |
+
pipe.enable_vae_slicing()
|
27 |
+
|
28 |
+
video = [Image.fromarray(frame).resize((1024, 576)) for frame in video_frames]
|
29 |
+
|
30 |
+
video_frames = pipe(prompt, video=video, num_inference_steps=2, strength=0.6).frames
|
31 |
+
video_path = export_to_video(video_frames, output_video_path="/home/patrick/videos/video_1024_spiderman_24.mp4")
|
~
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from diffusers import DiffusionPipeline, EulerDiscreteScheduler, StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler, StableDiffusionXLImg2ImgPipeline
|
3 |
+
import time
|
4 |
+
import numpy as np
|
5 |
+
import os
|
6 |
+
from huggingface_hub import HfApi
|
7 |
+
# from compel import Compel
|
8 |
+
import torch
|
9 |
+
import sys
|
10 |
+
from pathlib import Path
|
11 |
+
import requests
|
12 |
+
from PIL import Image
|
13 |
+
from io import BytesIO
|
14 |
+
|
15 |
+
path = sys.argv[1]
|
16 |
+
|
17 |
+
api = HfApi()
|
18 |
+
start_time = time.time()
|
19 |
+
pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(path)
|
20 |
+
pipe.to("cuda")
|
21 |
+
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
22 |
+
# pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
|
23 |
+
# pipe = StableDiffusionImg2ImgXLPipeline.from_pretrained(path, torch_dtype=torch.float16, safety_checker=None
|
24 |
+
|
25 |
+
# compel = Compel(tokenizer=pipe.tokenizer, text_encoder=pipe.text_encoder)
|
26 |
+
|
27 |
+
|
28 |
+
prompt = "An astronaut riding a green horse on Mars"
|
29 |
+
|
30 |
+
|
31 |
+
# pipe.unet.to(memory_format=torch.channels_last)
|
32 |
+
# pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
33 |
+
# pipe(prompt=prompt, num_inference_steps=2).images[0]
|
34 |
+
# url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
|
35 |
+
#
|
36 |
+
# response = requests.get(url)
|
37 |
+
init_image = torch.from_numpy(np.load("/home/patrick/images/xl_latents.npy")).to("cuda")
|
38 |
+
|
39 |
+
image = pipe(prompt=prompt, image=init_image).images[0]
|
40 |
+
|
41 |
+
file_name = f"aaa"
|
42 |
+
path = os.path.join(Path.home(), "images", f"{file_name}.png")
|
43 |
+
image.save(path)
|
44 |
+
|
45 |
+
api.upload_file(
|
46 |
+
path_or_fileobj=path,
|
47 |
+
path_in_repo=path.split("/")[-1],
|
48 |
+
repo_id="patrickvonplaten/images",
|
49 |
+
repo_type="dataset",
|
50 |
+
)
|
51 |
+
print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{file_name}.png")
|