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
40dd9cb2
"vscode:/vscode.git/clone" did not exist on "8d81564b27956dbabeeac833139aab27e60e379d"
Unverified
Commit
40dd9cb2
authored
Feb 13, 2024
by
Dhruv Nair
Committed by
GitHub
Feb 13, 2024
Browse files
Move SDXL T2I Adapter lora test into PEFT workflow (#6965)
update
parent
30bcda7d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
29 deletions
+31
-29
tests/lora/test_lora_layers_peft.py
tests/lora/test_lora_layers_peft.py
+31
-1
tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py
...s/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py
+0
-28
No files found.
tests/lora/test_lora_layers_peft.py
View file @
40dd9cb2
...
@@ -37,8 +37,10 @@ from diffusers import (
...
@@ -37,8 +37,10 @@ from diffusers import (
EulerDiscreteScheduler
,
EulerDiscreteScheduler
,
LCMScheduler
,
LCMScheduler
,
StableDiffusionPipeline
,
StableDiffusionPipeline
,
StableDiffusionXLAdapterPipeline
,
StableDiffusionXLControlNetPipeline
,
StableDiffusionXLControlNetPipeline
,
StableDiffusionXLPipeline
,
StableDiffusionXLPipeline
,
T2IAdapter
,
UNet2DConditionModel
,
UNet2DConditionModel
,
)
)
from
diffusers.utils.import_utils
import
is_accelerate_available
,
is_peft_available
from
diffusers.utils.import_utils
import
is_accelerate_available
,
is_peft_available
...
@@ -2175,7 +2177,7 @@ class LoraSDXLIntegrationTests(PeftLoraLoaderMixinTests, unittest.TestCase):
...
@@ -2175,7 +2177,7 @@ class LoraSDXLIntegrationTests(PeftLoraLoaderMixinTests, unittest.TestCase):
self
.
assertTrue
(
np
.
allclose
(
images
,
expected
,
atol
=
1e-3
))
self
.
assertTrue
(
np
.
allclose
(
images
,
expected
,
atol
=
1e-3
))
release_memory
(
pipeline
)
release_memory
(
pipeline
)
def
test_canny_lora
(
self
):
def
test_
controlnet_
canny_lora
(
self
):
controlnet
=
ControlNetModel
.
from_pretrained
(
"diffusers/controlnet-canny-sdxl-1.0"
)
controlnet
=
ControlNetModel
.
from_pretrained
(
"diffusers/controlnet-canny-sdxl-1.0"
)
pipe
=
StableDiffusionXLControlNetPipeline
.
from_pretrained
(
pipe
=
StableDiffusionXLControlNetPipeline
.
from_pretrained
(
...
@@ -2199,6 +2201,34 @@ class LoraSDXLIntegrationTests(PeftLoraLoaderMixinTests, unittest.TestCase):
...
@@ -2199,6 +2201,34 @@ class LoraSDXLIntegrationTests(PeftLoraLoaderMixinTests, unittest.TestCase):
assert
np
.
allclose
(
original_image
,
expected_image
,
atol
=
1e-04
)
assert
np
.
allclose
(
original_image
,
expected_image
,
atol
=
1e-04
)
release_memory
(
pipe
)
release_memory
(
pipe
)
def
test_sdxl_t2i_adapter_canny_lora
(
self
):
adapter
=
T2IAdapter
.
from_pretrained
(
"TencentARC/t2i-adapter-lineart-sdxl-1.0"
,
torch_dtype
=
torch
.
float16
).
to
(
"cpu"
)
pipe
=
StableDiffusionXLAdapterPipeline
.
from_pretrained
(
"stabilityai/stable-diffusion-xl-base-1.0"
,
adapter
=
adapter
,
torch_dtype
=
torch
.
float16
,
variant
=
"fp16"
,
)
pipe
.
load_lora_weights
(
"CiroN2022/toy-face"
,
weight_name
=
"toy_face_sdxl.safetensors"
)
pipe
.
enable_model_cpu_offload
()
pipe
.
set_progress_bar_config
(
disable
=
None
)
generator
=
torch
.
Generator
(
device
=
"cpu"
).
manual_seed
(
0
)
prompt
=
"toy"
image
=
load_image
(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/t2i_adapter/toy_canny.png"
)
images
=
pipe
(
prompt
,
image
=
image
,
generator
=
generator
,
output_type
=
"np"
,
num_inference_steps
=
3
).
images
assert
images
[
0
].
shape
==
(
768
,
512
,
3
)
image_slice
=
images
[
0
,
-
3
:,
-
3
:,
-
1
].
flatten
()
expected_slice
=
np
.
array
([
0.4284
,
0.4337
,
0.4319
,
0.4255
,
0.4329
,
0.4280
,
0.4338
,
0.4420
,
0.4226
])
assert
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
<
1e-4
@
nightly
@
nightly
def
test_sequential_fuse_unfuse
(
self
):
def
test_sequential_fuse_unfuse
(
self
):
pipe
=
DiffusionPipeline
.
from_pretrained
(
"stabilityai/stable-diffusion-xl-base-1.0"
,
torch_dtype
=
torch
.
float16
)
pipe
=
DiffusionPipeline
.
from_pretrained
(
"stabilityai/stable-diffusion-xl-base-1.0"
,
torch_dtype
=
torch
.
float16
)
...
...
tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py
View file @
40dd9cb2
...
@@ -672,34 +672,6 @@ class AdapterSDXLPipelineSlowTests(unittest.TestCase):
...
@@ -672,34 +672,6 @@ class AdapterSDXLPipelineSlowTests(unittest.TestCase):
gc
.
collect
()
gc
.
collect
()
torch
.
cuda
.
empty_cache
()
torch
.
cuda
.
empty_cache
()
def
test_canny_lora
(
self
):
adapter
=
T2IAdapter
.
from_pretrained
(
"TencentARC/t2i-adapter-lineart-sdxl-1.0"
,
torch_dtype
=
torch
.
float16
).
to
(
"cpu"
)
pipe
=
StableDiffusionXLAdapterPipeline
.
from_pretrained
(
"stabilityai/stable-diffusion-xl-base-1.0"
,
adapter
=
adapter
,
torch_dtype
=
torch
.
float16
,
variant
=
"fp16"
,
)
pipe
.
load_lora_weights
(
"CiroN2022/toy-face"
,
weight_name
=
"toy_face_sdxl.safetensors"
)
pipe
.
enable_model_cpu_offload
()
pipe
.
set_progress_bar_config
(
disable
=
None
)
generator
=
torch
.
Generator
(
device
=
"cpu"
).
manual_seed
(
0
)
prompt
=
"toy"
image
=
load_image
(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/t2i_adapter/toy_canny.png"
)
images
=
pipe
(
prompt
,
image
=
image
,
generator
=
generator
,
output_type
=
"np"
,
num_inference_steps
=
3
).
images
assert
images
[
0
].
shape
==
(
768
,
512
,
3
)
image_slice
=
images
[
0
,
-
3
:,
-
3
:,
-
1
].
flatten
()
expected_slice
=
np
.
array
([
0.4284
,
0.4337
,
0.4319
,
0.4255
,
0.4329
,
0.4280
,
0.4338
,
0.4420
,
0.4226
])
assert
numpy_cosine_similarity_distance
(
image_slice
,
expected_slice
)
<
1e-4
def
test_download_ckpt_diff_format_is_same
(
self
):
def
test_download_ckpt_diff_format_is_same
(
self
):
ckpt_path
=
(
ckpt_path
=
(
"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors"
"https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/sd_xl_base_1.0.safetensors"
...
...
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