Merge branch 'main' of https://huggingface.co/diffusers/tools into main
Browse files- plot_bench.py +72 -0
- run_local.py +22 -11
plot_bench.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
import matplotlib.pyplot as plt
|
| 3 |
+
import numpy as np
|
| 4 |
+
import seaborn as sns
|
| 5 |
+
|
| 6 |
+
sns.set(font_scale=1.1)
|
| 7 |
+
|
| 8 |
+
batch_sizes = {
|
| 9 |
+
"fp16_4": {
|
| 10 |
+
"A100": [4.75, 3.26, 3.24, 3.10], # those values are made up
|
| 11 |
+
"A10": [13.94, 9.81, 10.01, 9.35],
|
| 12 |
+
"T4": [38.81, 30.09, 29.74, 27.55],
|
| 13 |
+
"V100": [9.84, 8.16, 8.09, 7.65],
|
| 14 |
+
"3090": [10.04, 7.82, 7.89, 7.47],
|
| 15 |
+
"3090TI": [9.07, 7.14, 7.15, 6.81],
|
| 16 |
+
},
|
| 17 |
+
"fp16_16": {
|
| 18 |
+
"A100": [18.95, 13.57, 13.67, 12.25],
|
| 19 |
+
"A10": [0, 37.55, 38.31, 36.81],
|
| 20 |
+
"T4": [0, 111.47, 113.26, 106.93],
|
| 21 |
+
"V100": [0, 30.29, 29.84, 28.22],
|
| 22 |
+
"3090": [0, 29.06, 29.06, 28.2],
|
| 23 |
+
"3090TI": [0, 26.1, 26.28, 25.46],
|
| 24 |
+
},
|
| 25 |
+
"fp32_4": {
|
| 26 |
+
"A100": [16.56, 12.42, 12.2, 11.84],
|
| 27 |
+
"A10": [34.77, 27.63, 22.77, 22.07],
|
| 28 |
+
"T4": [0, 85.72, 85.78, 84.48],
|
| 29 |
+
"V100": [0, 25.73, 25.31, 24.7],
|
| 30 |
+
"3090": [22.69, 21.45, 18.67, 18.09],
|
| 31 |
+
"3090TI": [20.32, 19.31, 16.9, 16.37],
|
| 32 |
+
},
|
| 33 |
+
"fp32_16": {
|
| 34 |
+
"A100": [0, 47.08, 46.27, 44.8],
|
| 35 |
+
"A10": [0, 116.49, 88.56, 86.64],
|
| 36 |
+
"T4": [0, 276.47, 280.26, 270.93], # numbers are made up
|
| 37 |
+
"V100": [0, 84.99, 84.73, 82.55],
|
| 38 |
+
"3090": [0, 85.35, 72.37, 70.25],
|
| 39 |
+
"3090TI": [0, 75.37, 65.25, 64.32],
|
| 40 |
+
},
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
batch_size = 16
|
| 44 |
+
dtype = "fp32"
|
| 45 |
+
|
| 46 |
+
key = f"{dtype}_{batch_size}"
|
| 47 |
+
|
| 48 |
+
methods = {
|
| 49 |
+
"Vanilla Attention": [x[0] for x in batch_sizes[key].values()],
|
| 50 |
+
"xFormers": [x[1] for x in batch_sizes[key].values()],
|
| 51 |
+
"PyTorch2.0 SDPA": [x[2] for x in batch_sizes[key].values()],
|
| 52 |
+
"SDPA + torch.compile": [x[3] for x in batch_sizes[key].values()],
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
x = np.arange(len(batch_sizes[key])) # the label locations
|
| 56 |
+
width = 0.1 # the width of the bars
|
| 57 |
+
multiplier = 0
|
| 58 |
+
|
| 59 |
+
fig, ax = plt.subplots(constrained_layout=True)
|
| 60 |
+
|
| 61 |
+
for attribute, measurement in methods.items():
|
| 62 |
+
offset = width * multiplier
|
| 63 |
+
rects = ax.bar(x + offset, measurement, width, label=attribute)
|
| 64 |
+
multiplier += 1
|
| 65 |
+
|
| 66 |
+
# Add some text for labels, title and custom x-axis tick labels, etc.
|
| 67 |
+
ax.set_ylabel('Time (s)')
|
| 68 |
+
ax.set_title(f'Inference Speed at Batch Size={batch_size} for {dtype}')
|
| 69 |
+
ax.set_xticks(x + width, batch_sizes[key])
|
| 70 |
+
ax.legend(loc='upper left')
|
| 71 |
+
|
| 72 |
+
plt.show()
|
run_local.py
CHANGED
|
@@ -4,6 +4,7 @@ from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepSchedu
|
|
| 4 |
import time
|
| 5 |
import os
|
| 6 |
from huggingface_hub import HfApi
|
|
|
|
| 7 |
import torch
|
| 8 |
import sys
|
| 9 |
from pathlib import Path
|
|
@@ -16,21 +17,31 @@ start_time = time.time()
|
|
| 16 |
#pipe.scheduler = HeunDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 17 |
pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
|
| 18 |
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
pipe = pipe.to("cuda")
|
| 20 |
|
| 21 |
prompt = "a highly realistic photo of green turtle"
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
print("Time", time.time() - start_time)
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
|
|
|
| 29 |
|
| 30 |
-
api.upload_file(
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
)
|
| 36 |
-
print("https://huggingface.co/datasets/patrickvonplaten/images/blob/main/
|
|
|
|
| 4 |
import time
|
| 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
|
|
|
|
| 17 |
#pipe.scheduler = HeunDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 18 |
pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
|
| 19 |
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
|
| 20 |
+
|
| 21 |
+
compel = Compel(tokenizer=pipe.tokenizer, text_encoder=pipe.text_encoder)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
pipe = pipe.to("cuda")
|
| 25 |
|
| 26 |
prompt = "a highly realistic photo of green turtle"
|
| 27 |
|
| 28 |
+
prompts = ["a cat playing with a ball++ in the forest", "a cat playing with a ball++ in the forest", "a cat playing with a ball-- in the forest"]
|
| 29 |
+
|
| 30 |
+
prompt_embeds = torch.cat([compel.build_conditioning_tensor(prompt) for prompt in prompts])
|
| 31 |
+
|
| 32 |
+
generator = [torch.Generator(device="cuda").manual_seed(0) for _ in range(prompt_embeds.shape[0])]
|
| 33 |
+
images = pipe(prompt_embeds=prompt_embeds, generator=generator, num_inference_steps=15).images
|
| 34 |
+
|
| 35 |
print("Time", time.time() - start_time)
|
| 36 |
|
| 37 |
+
for i, image in enumerate(image):
|
| 38 |
+
path = os.path.join(Path.home(), "images", f"aa_{i}.png")
|
| 39 |
+
image.save(path)
|
| 40 |
|
| 41 |
+
api.upload_file(
|
| 42 |
+
path_or_fileobj=path,
|
| 43 |
+
path_in_repo=path.split("/")[-1],
|
| 44 |
+
repo_id="patrickvonplaten/images",
|
| 45 |
+
repo_type="dataset",
|
| 46 |
+
)
|
| 47 |
+
print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa_{i}.png")
|