Commit
·
4861382
1
Parent(s):
c9b0b96
up
Browse files- run_local.py +21 -49
- run_local_sag.py +34 -0
run_local.py
CHANGED
@@ -1,61 +1,33 @@
|
|
1 |
#!/usr/bin/env python3
|
2 |
-
from diffusers import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
import time
|
4 |
-
import os
|
5 |
-
from huggingface_hub import HfApi
|
6 |
-
# from compel import Compel
|
7 |
import torch
|
8 |
import sys
|
9 |
from pathlib import Path
|
10 |
-
import requests
|
11 |
-
from PIL import Image
|
12 |
-
from io import BytesIO
|
13 |
|
14 |
-
path = sys.argv[1]
|
15 |
-
|
|
|
16 |
|
17 |
-
api = HfApi()
|
18 |
-
start_time = time.time()
|
19 |
pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
|
20 |
-
pipe.
|
21 |
-
|
22 |
-
# pipe.unet = torch.compile(pipe.unet)
|
23 |
-
|
24 |
-
# pipe = StableDiffusionImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16, safety_checker=None)
|
25 |
-
|
26 |
-
# compel = Compel(tokenizer=pipe.tokenizer, text_encoder=pipe.text_encoder)
|
27 |
-
|
28 |
-
|
29 |
-
pipe = pipe.to("cuda")
|
30 |
|
31 |
prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k"
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
# url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
|
40 |
-
|
41 |
-
# response = requests.get(url)
|
42 |
-
# image = Image.open(BytesIO(response.content)).convert("RGB")
|
43 |
-
# image.thumbnail((768, 768))
|
44 |
-
|
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}"
|
52 |
-
path = os.path.join(Path.home(), "images", f"{file_name}.png")
|
53 |
-
image.save(path)
|
54 |
|
55 |
-
|
56 |
-
path_or_fileobj=path,
|
57 |
-
path_in_repo=path.split("/")[-1],
|
58 |
-
repo_id="patrickvonplaten/images",
|
59 |
-
repo_type="dataset",
|
60 |
-
)
|
61 |
-
print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{file_name}.png")
|
|
|
1 |
#!/usr/bin/env python3
|
2 |
+
from diffusers import (
|
3 |
+
SASolverScheduler,
|
4 |
+
StableDiffusionPipeline,
|
5 |
+
KDPM2DiscreteScheduler,
|
6 |
+
StableDiffusionImg2ImgPipeline,
|
7 |
+
HeunDiscreteScheduler,
|
8 |
+
KDPM2AncestralDiscreteScheduler,
|
9 |
+
DDIMScheduler,
|
10 |
+
)
|
11 |
import time
|
|
|
|
|
|
|
12 |
import torch
|
13 |
import sys
|
14 |
from pathlib import Path
|
|
|
|
|
|
|
15 |
|
16 |
+
# path = sys.argv[1]
|
17 |
+
path = "runwayml/stable-diffusion-v1-5"
|
18 |
+
device = "mps"
|
19 |
|
|
|
|
|
20 |
pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
|
21 |
+
pipe.scheduler = SASolverScheduler.from_config(pipe.scheduler.config)
|
22 |
+
pipe.to(device)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k"
|
25 |
|
26 |
+
start_time = time.time()
|
27 |
+
generator = torch.Generator(device=device).manual_seed(0)
|
28 |
+
images = pipe(
|
29 |
+
prompt=prompt, generator=generator, num_images_per_prompt=1, num_inference_steps=30
|
30 |
+
).images
|
31 |
+
print(time.time() - start_time)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
images[0].show()
|
|
|
|
|
|
|
|
|
|
|
|
run_local_sag.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python3
|
2 |
+
from diffusers import (
|
3 |
+
StableDiffusionSAGPipeline,
|
4 |
+
StableDiffusionPipeline,
|
5 |
+
KDPM2DiscreteScheduler,
|
6 |
+
StableDiffusionImg2ImgPipeline,
|
7 |
+
HeunDiscreteScheduler,
|
8 |
+
KDPM2AncestralDiscreteScheduler,
|
9 |
+
DDIMScheduler,
|
10 |
+
)
|
11 |
+
import time
|
12 |
+
import torch
|
13 |
+
import sys
|
14 |
+
from pathlib import Path
|
15 |
+
|
16 |
+
# path = sys.argv[1]
|
17 |
+
path = "runwayml/stable-diffusion-v1-5"
|
18 |
+
device = "cpu"
|
19 |
+
dtype = torch.float32
|
20 |
+
|
21 |
+
pipe = StableDiffusionSAGPipeline.from_pretrained(path, torch_dtype=dtype)
|
22 |
+
# pipe.scheduler = SASolverScheduler.from_config(pipe.scheduler.config)
|
23 |
+
pipe.to(device)
|
24 |
+
|
25 |
+
prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k"
|
26 |
+
|
27 |
+
start_time = time.time()
|
28 |
+
generator = torch.Generator(device=device).manual_seed(0)
|
29 |
+
images = pipe(
|
30 |
+
prompt=prompt, generator=generator, num_images_per_prompt=1, num_inference_steps=30
|
31 |
+
).images
|
32 |
+
print(time.time() - start_time)
|
33 |
+
|
34 |
+
images[0].show()
|