Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
diffusers
Commits
839c2a5e
Commit
839c2a5e
authored
Nov 01, 2023
by
Patrick von Platen
Browse files
fix
parent
5712c3d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
43 deletions
+23
-43
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
...lines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
+1
-2
tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py
...s/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py
+22
-41
No files found.
src/diffusers/pipelines/t2i_adapter/pipeline_stable_diffusion_xl_adapter.py
View file @
839c2a5e
...
@@ -1068,7 +1068,6 @@ class StableDiffusionXLAdapterPipeline(
...
@@ -1068,7 +1068,6 @@ class StableDiffusionXLAdapterPipeline(
return
StableDiffusionXLPipelineOutput
(
images
=
image
)
return
StableDiffusionXLPipelineOutput
(
images
=
image
)
# Overrride to properly handle the loading and unloading of the additional text encoder.
# Overrride to properly handle the loading and unloading of the additional text encoder.
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.load_lora_weights
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline.load_lora_weights
def
load_lora_weights
(
self
,
pretrained_model_name_or_path_or_dict
:
Union
[
str
,
Dict
[
str
,
torch
.
Tensor
]],
**
kwargs
):
def
load_lora_weights
(
self
,
pretrained_model_name_or_path_or_dict
:
Union
[
str
,
Dict
[
str
,
torch
.
Tensor
]],
**
kwargs
):
...
@@ -1140,4 +1139,4 @@ class StableDiffusionXLAdapterPipeline(
...
@@ -1140,4 +1139,4 @@ class StableDiffusionXLAdapterPipeline(
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline._remove_text_encoder_monkey_patch
# Copied from diffusers.pipelines.stable_diffusion_xl.pipeline_stable_diffusion_xl.StableDiffusionXLPipeline._remove_text_encoder_monkey_patch
def
_remove_text_encoder_monkey_patch
(
self
):
def
_remove_text_encoder_monkey_patch
(
self
):
self
.
_remove_text_encoder_monkey_patch_classmethod
(
self
.
text_encoder
)
self
.
_remove_text_encoder_monkey_patch_classmethod
(
self
.
text_encoder
)
self
.
_remove_text_encoder_monkey_patch_classmethod
(
self
.
text_encoder_2
)
self
.
_remove_text_encoder_monkey_patch_classmethod
(
self
.
text_encoder_2
)
\ No newline at end of file
tests/pipelines/stable_diffusion_xl/test_stable_diffusion_xl_adapter.py
View file @
839c2a5e
...
@@ -13,8 +13,8 @@
...
@@ -13,8 +13,8 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
import
random
import
gc
import
gc
import
random
import
unittest
import
unittest
import
numpy
as
np
import
numpy
as
np
...
@@ -30,14 +30,17 @@ from diffusers import (
...
@@ -30,14 +30,17 @@ from diffusers import (
StableDiffusionXLAdapterPipeline
,
StableDiffusionXLAdapterPipeline
,
T2IAdapter
,
T2IAdapter
,
UNet2DConditionModel
,
UNet2DConditionModel
,
EulerAncestralDiscreteScheduler
,
)
)
from
diffusers.utils
import
logging
from
diffusers.utils
import
load_image
,
logging
from
diffusers.utils.testing_utils
import
enable_full_determinism
,
floats_tensor
,
torch_device
from
diffusers.utils.testing_utils
import
(
from
diffusers.utils
import
load_image
enable_full_determinism
,
from
diffusers.utils.torch_utils
import
randn_tensor
floats_tensor
,
from
diffusers.utils.testing_utils
import
enable_full_determinism
,
require_torch_gpu
,
slow
,
torch_device
numpy_cosine_similarity_distance
,
require_torch_gpu
,
slow
,
torch_device
,
)
from
..pipeline_params
import
TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
,
TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from
..pipeline_params
import
TEXT_GUIDED_IMAGE_VARIATION_BATCH_PARAMS
,
TEXT_GUIDED_IMAGE_VARIATION_PARAMS
from
..test_pipelines_common
import
(
from
..test_pipelines_common
import
(
PipelineTesterMixin
,
PipelineTesterMixin
,
...
@@ -575,38 +578,15 @@ class AdapterSDXLPipelineSlowTests(unittest.TestCase):
...
@@ -575,38 +578,15 @@ class AdapterSDXLPipelineSlowTests(unittest.TestCase):
gc
.
collect
()
gc
.
collect
()
torch
.
cuda
.
empty_cache
()
torch
.
cuda
.
empty_cache
()
def
test_canny
(
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_sequential_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
)
original_image
=
images
[
0
,
-
3
:,
-
3
:,
-
1
].
flatten
()
assert
numpy_cosine_similarity_distance
(
original_image
,
expected_image
)
<
1e-4
assert
np
.
allclose
(
original_image
,
expected_image
,
atol
=
1e-04
)
def
test_canny_lora
(
self
):
def
test_canny_lora
(
self
):
adapter
=
T2IAdapter
.
from_pretrained
(
adapter
=
T2IAdapter
.
from_pretrained
(
"TencentARC/t2i-adapter-lineart-sdxl-1.0"
,
torch_dtype
=
torch
.
float16
).
to
(
"
TencentARC/t2i-adapter-lineart-sdxl-1.0"
,
torch_dtype
=
torch
.
float16
"
cpu"
)
.
to
(
"cpu"
)
)
pipe
=
StableDiffusionXLAdapterPipeline
.
from_pretrained
(
pipe
=
StableDiffusionXLAdapterPipeline
.
from_pretrained
(
'stabilityai/stable-diffusion-xl-base-1.0'
,
adapter
=
adapter
,
torch_dtype
=
torch
.
float16
,
variant
=
"fp16"
,
"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
.
load_lora_weights
(
"CiroN2022/toy-face"
,
weight_name
=
"toy_face_sdxl.safetensors"
)
pipe
.
enable_sequential_cpu_offload
()
pipe
.
enable_sequential_cpu_offload
()
...
@@ -615,7 +595,7 @@ class AdapterSDXLPipelineSlowTests(unittest.TestCase):
...
@@ -615,7 +595,7 @@ class AdapterSDXLPipelineSlowTests(unittest.TestCase):
generator
=
torch
.
Generator
(
device
=
"cpu"
).
manual_seed
(
0
)
generator
=
torch
.
Generator
(
device
=
"cpu"
).
manual_seed
(
0
)
prompt
=
"toy"
prompt
=
"toy"
image
=
load_image
(
image
=
load_image
(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/t2i_adapter/toy_canny.png"
"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
images
=
pipe
(
prompt
,
image
=
image
,
generator
=
generator
,
output_type
=
"np"
,
num_inference_steps
=
3
).
images
...
@@ -623,6 +603,7 @@ class AdapterSDXLPipelineSlowTests(unittest.TestCase):
...
@@ -623,6 +603,7 @@ class AdapterSDXLPipelineSlowTests(unittest.TestCase):
assert
images
[
0
].
shape
==
(
768
,
512
,
3
)
assert
images
[
0
].
shape
==
(
768
,
512
,
3
)
original_image
=
images
[
0
,
-
3
:,
-
3
:,
-
1
].
flatten
()
original_image
=
images
[
0
,
-
3
:,
-
3
:,
-
1
].
flatten
()
expected_image
=
np
.
array
([
0.50346327
,
0.50708383
,
0.50719553
,
0.5135172
,
0.5155377
,
0.5066059
,
0.49680984
,
0.5005894
,
0.48509413
])
expected_image
=
np
.
array
(
[
0.50346327
,
0.50708383
,
0.50719553
,
0.5135172
,
0.5155377
,
0.5066059
,
0.49680984
,
0.5005894
,
0.48509413
]
)
assert
numpy_cosine_similarity_distance
(
original_image
,
expected_image
)
<
1e-4
assert
numpy_cosine_similarity_distance
(
original_image
,
expected_image
)
<
1e-4
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