Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
renzhc
diffusers_dcu
Commits
03cd6252
Unverified
Commit
03cd6252
authored
Mar 03, 2024
by
Sayak Paul
Committed by
GitHub
Mar 03, 2024
Browse files
feat: add ip adapter benchmark (#6936)
* feat: add ip adapter benchmark * sdxl support too. * Empty-Commit
parent
001b1402
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
1 deletion
+62
-1
benchmarks/base_classes.py
benchmarks/base_classes.py
+29
-0
benchmarks/benchmark_ip_adapters.py
benchmarks/benchmark_ip_adapters.py
+32
-0
benchmarks/run_all.py
benchmarks/run_all.py
+1
-1
No files found.
benchmarks/base_classes.py
View file @
03cd6252
...
@@ -236,6 +236,35 @@ class InpaintingBenchmark(ImageToImageBenchmark):
...
@@ -236,6 +236,35 @@ class InpaintingBenchmark(ImageToImageBenchmark):
)
)
class
IPAdapterTextToImageBenchmark
(
TextToImageBenchmark
):
url
=
"https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/load_neg_embed.png"
image
=
load_image
(
url
)
def
__init__
(
self
,
args
):
pipe
=
self
.
pipeline_class
.
from_pretrained
(
args
.
ckpt
,
torch_dtype
=
torch
.
float16
).
to
(
"cuda"
)
pipe
.
load_ip_adapter
(
args
.
ip_adapter_id
[
0
],
subfolder
=
"models"
if
"sdxl"
not
in
args
.
ip_adapter_id
[
1
]
else
"sdxl_models"
,
weight_name
=
args
.
ip_adapter_id
[
1
],
)
if
args
.
run_compile
:
pipe
.
unet
.
to
(
memory_format
=
torch
.
channels_last
)
print
(
"Run torch compile"
)
pipe
.
unet
=
torch
.
compile
(
pipe
.
unet
,
mode
=
"reduce-overhead"
,
fullgraph
=
True
)
pipe
.
set_progress_bar_config
(
disable
=
True
)
self
.
pipe
=
pipe
def
run_inference
(
self
,
pipe
,
args
):
_
=
pipe
(
prompt
=
PROMPT
,
ip_adapter_image
=
self
.
image
,
num_inference_steps
=
args
.
num_inference_steps
,
num_images_per_prompt
=
args
.
batch_size
,
)
class
ControlNetBenchmark
(
TextToImageBenchmark
):
class
ControlNetBenchmark
(
TextToImageBenchmark
):
pipeline_class
=
StableDiffusionControlNetPipeline
pipeline_class
=
StableDiffusionControlNetPipeline
aux_network_class
=
ControlNetModel
aux_network_class
=
ControlNetModel
...
...
benchmarks/benchmark_ip_adapters.py
0 → 100644
View file @
03cd6252
import
argparse
import
sys
sys
.
path
.
append
(
"."
)
from
base_classes
import
IPAdapterTextToImageBenchmark
# noqa: E402
IP_ADAPTER_CKPTS
=
{
"runwayml/stable-diffusion-v1-5"
:
(
"h94/IP-Adapter"
,
"ip-adapter_sd15.bin"
),
"stabilityai/stable-diffusion-xl-base-1.0"
:
(
"h94/IP-Adapter"
,
"ip-adapter_sdxl.bin"
),
}
if
__name__
==
"__main__"
:
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"--ckpt"
,
type
=
str
,
default
=
"runwayml/stable-diffusion-v1-5"
,
choices
=
list
(
IP_ADAPTER_CKPTS
.
keys
()),
)
parser
.
add_argument
(
"--batch_size"
,
type
=
int
,
default
=
1
)
parser
.
add_argument
(
"--num_inference_steps"
,
type
=
int
,
default
=
50
)
parser
.
add_argument
(
"--model_cpu_offload"
,
action
=
"store_true"
)
parser
.
add_argument
(
"--run_compile"
,
action
=
"store_true"
)
args
=
parser
.
parse_args
()
args
.
ip_adapter_id
=
IP_ADAPTER_CKPTS
[
args
.
ckpt
]
benchmark_pipe
=
IPAdapterTextToImageBenchmark
(
args
)
args
.
ckpt
=
f
"
{
args
.
ckpt
}
(IP-Adapter)"
benchmark_pipe
.
benchmark
(
args
)
benchmarks/run_all.py
View file @
03cd6252
...
@@ -72,7 +72,7 @@ def main():
...
@@ -72,7 +72,7 @@ def main():
command
+=
" --run_compile"
command
+=
" --run_compile"
run_command
(
command
.
split
())
run_command
(
command
.
split
())
elif
file
==
"benchmark_sd_inpainting.py"
:
elif
file
in
[
"benchmark_sd_inpainting.py"
,
"benchmark_ip_adapters.py"
]
:
sdxl_ckpt
=
"stabilityai/stable-diffusion-xl-base-1.0"
sdxl_ckpt
=
"stabilityai/stable-diffusion-xl-base-1.0"
command
=
f
"python
{
file
}
--ckpt
{
sdxl_ckpt
}
"
command
=
f
"python
{
file
}
--ckpt
{
sdxl_ckpt
}
"
run_command
(
command
.
split
())
run_command
(
command
.
split
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment