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
OpenDAS
diffusers
Commits
4974b845
Unverified
Commit
4974b845
authored
Mar 14, 2024
by
Dhruv Nair
Committed by
GitHub
Mar 14, 2024
Browse files
Update Cascade Tests (#7324)
* update * update * update
parent
83062fb8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
33 deletions
+25
-33
tests/models/unets/test_models_unet_stable_cascade.py
tests/models/unets/test_models_unet_stable_cascade.py
+2
-6
tests/pipelines/stable_cascade/test_stable_cascade_decoder.py
...s/pipelines/stable_cascade/test_stable_cascade_decoder.py
+13
-15
tests/pipelines/stable_cascade/test_stable_cascade_prior.py
tests/pipelines/stable_cascade/test_stable_cascade_prior.py
+10
-12
No files found.
tests/models/unets/test_models_unet_stable_cascade.py
View file @
4974b845
...
@@ -50,9 +50,7 @@ class StableCascadeUNetModelSlowTests(unittest.TestCase):
...
@@ -50,9 +50,7 @@ class StableCascadeUNetModelSlowTests(unittest.TestCase):
gc
.
collect
()
gc
.
collect
()
torch
.
cuda
.
empty_cache
()
torch
.
cuda
.
empty_cache
()
unet
=
StableCascadeUNet
.
from_pretrained
(
unet
=
StableCascadeUNet
.
from_pretrained
(
"stabilityai/stable-cascade-prior"
,
subfolder
=
"prior"
,
variant
=
"bf16"
)
"stabilityai/stable-cascade-prior"
,
subfolder
=
"prior"
,
revision
=
"refs/pr/2"
,
variant
=
"bf16"
)
unet_config
=
unet
.
config
unet_config
=
unet
.
config
del
unet
del
unet
gc
.
collect
()
gc
.
collect
()
...
@@ -74,9 +72,7 @@ class StableCascadeUNetModelSlowTests(unittest.TestCase):
...
@@ -74,9 +72,7 @@ class StableCascadeUNetModelSlowTests(unittest.TestCase):
gc
.
collect
()
gc
.
collect
()
torch
.
cuda
.
empty_cache
()
torch
.
cuda
.
empty_cache
()
unet
=
StableCascadeUNet
.
from_pretrained
(
unet
=
StableCascadeUNet
.
from_pretrained
(
"stabilityai/stable-cascade"
,
subfolder
=
"decoder"
,
variant
=
"bf16"
)
"stabilityai/stable-cascade"
,
subfolder
=
"decoder"
,
revision
=
"refs/pr/44"
,
variant
=
"bf16"
)
unet_config
=
unet
.
config
unet_config
=
unet
.
config
del
unet
del
unet
gc
.
collect
()
gc
.
collect
()
...
...
tests/pipelines/stable_cascade/test_stable_cascade_decoder.py
View file @
4974b845
...
@@ -21,13 +21,13 @@ import torch
...
@@ -21,13 +21,13 @@ import torch
from
transformers
import
CLIPTextConfig
,
CLIPTextModelWithProjection
,
CLIPTokenizer
from
transformers
import
CLIPTextConfig
,
CLIPTextModelWithProjection
,
CLIPTokenizer
from
diffusers
import
DDPMWuerstchenScheduler
,
StableCascadeDecoderPipeline
from
diffusers
import
DDPMWuerstchenScheduler
,
StableCascadeDecoderPipeline
from
diffusers.image_processor
import
VaeImageProcessor
from
diffusers.models
import
StableCascadeUNet
from
diffusers.models
import
StableCascadeUNet
from
diffusers.pipelines.wuerstchen
import
PaellaVQModel
from
diffusers.pipelines.wuerstchen
import
PaellaVQModel
from
diffusers.utils.testing_utils
import
(
from
diffusers.utils.testing_utils
import
(
enable_full_determinism
,
enable_full_determinism
,
load_
image
,
load_
numpy
,
load_pt
,
load_pt
,
numpy_cosine_similarity_distance
,
require_torch_gpu
,
require_torch_gpu
,
skip_mps
,
skip_mps
,
slow
,
slow
,
...
@@ -258,7 +258,7 @@ class StableCascadeDecoderPipelineIntegrationTests(unittest.TestCase):
...
@@ -258,7 +258,7 @@ class StableCascadeDecoderPipelineIntegrationTests(unittest.TestCase):
def
test_stable_cascade_decoder
(
self
):
def
test_stable_cascade_decoder
(
self
):
pipe
=
StableCascadeDecoderPipeline
.
from_pretrained
(
pipe
=
StableCascadeDecoderPipeline
.
from_pretrained
(
"
diffusers/S
table
C
ascade
-decoder
"
,
torch_dtype
=
torch
.
bfloat16
"
stabilityai/s
table
-c
ascade
"
,
variant
=
"bf16
"
,
torch_dtype
=
torch
.
bfloat16
)
)
pipe
.
enable_model_cpu_offload
()
pipe
.
enable_model_cpu_offload
()
pipe
.
set_progress_bar_config
(
disable
=
None
)
pipe
.
set_progress_bar_config
(
disable
=
None
)
...
@@ -271,18 +271,16 @@ class StableCascadeDecoderPipelineIntegrationTests(unittest.TestCase):
...
@@ -271,18 +271,16 @@ class StableCascadeDecoderPipelineIntegrationTests(unittest.TestCase):
)
)
image
=
pipe
(
image
=
pipe
(
prompt
=
prompt
,
image_embeddings
=
image_embedding
,
num_inference_steps
=
10
,
generator
=
generator
prompt
=
prompt
,
image_embeddings
=
image_embedding
,
output_type
=
"np"
,
num_inference_steps
=
2
,
generator
=
generator
,
).
images
[
0
]
).
images
[
0
]
assert
image
.
size
==
(
1024
,
1024
)
assert
image
.
shape
==
(
1024
,
1024
,
3
)
expected_image
=
load_numpy
(
expected_image
=
load_image
(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_cascade/stable_cascade_decoder_image.npy"
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_cascade/t2i.png"
)
)
max_diff
=
numpy_cosine_similarity_distance
(
image
.
flatten
(),
expected_image
.
flatten
())
image_processor
=
VaeImageProcessor
()
assert
max_diff
<
1e-4
image_np
=
image_processor
.
pil_to_numpy
(
image
)
expected_image_np
=
image_processor
.
pil_to_numpy
(
expected_image
)
self
.
assertTrue
(
np
.
allclose
(
image_np
,
expected_image_np
,
atol
=
53e-2
))
tests/pipelines/stable_cascade/test_stable_cascade_prior.py
View file @
4974b845
...
@@ -29,7 +29,8 @@ from diffusers.models.attention_processor import LoRAAttnProcessor, LoRAAttnProc
...
@@ -29,7 +29,8 @@ from diffusers.models.attention_processor import LoRAAttnProcessor, LoRAAttnProc
from
diffusers.utils.import_utils
import
is_peft_available
from
diffusers.utils.import_utils
import
is_peft_available
from
diffusers.utils.testing_utils
import
(
from
diffusers.utils.testing_utils
import
(
enable_full_determinism
,
enable_full_determinism
,
load_pt
,
load_numpy
,
numpy_cosine_similarity_distance
,
require_peft_backend
,
require_peft_backend
,
require_torch_gpu
,
require_torch_gpu
,
skip_mps
,
skip_mps
,
...
@@ -319,7 +320,9 @@ class StableCascadePriorPipelineIntegrationTests(unittest.TestCase):
...
@@ -319,7 +320,9 @@ class StableCascadePriorPipelineIntegrationTests(unittest.TestCase):
torch
.
cuda
.
empty_cache
()
torch
.
cuda
.
empty_cache
()
def
test_stable_cascade_prior
(
self
):
def
test_stable_cascade_prior
(
self
):
pipe
=
StableCascadePriorPipeline
.
from_pretrained
(
"diffusers/StableCascade-prior"
,
torch_dtype
=
torch
.
bfloat16
)
pipe
=
StableCascadePriorPipeline
.
from_pretrained
(
"stabilityai/stable-cascade-prior"
,
variant
=
"bf16"
,
torch_dtype
=
torch
.
bfloat16
)
pipe
.
enable_model_cpu_offload
()
pipe
.
enable_model_cpu_offload
()
pipe
.
set_progress_bar_config
(
disable
=
None
)
pipe
.
set_progress_bar_config
(
disable
=
None
)
...
@@ -327,17 +330,12 @@ class StableCascadePriorPipelineIntegrationTests(unittest.TestCase):
...
@@ -327,17 +330,12 @@ class StableCascadePriorPipelineIntegrationTests(unittest.TestCase):
generator
=
torch
.
Generator
(
device
=
"cpu"
).
manual_seed
(
0
)
generator
=
torch
.
Generator
(
device
=
"cpu"
).
manual_seed
(
0
)
output
=
pipe
(
prompt
,
num_inference_steps
=
10
,
generator
=
generator
)
output
=
pipe
(
prompt
,
num_inference_steps
=
2
,
output_type
=
"np"
,
generator
=
generator
)
image_embedding
=
output
.
image_embeddings
image_embedding
=
output
.
image_embeddings
expected_image_embedding
=
load_numpy
(
expected_image_embedding
=
load_pt
(
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_cascade/stable_cascade_prior_image_embeddings.npy"
"https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_cascade/image_embedding.pt"
)
)
assert
image_embedding
.
shape
==
(
1
,
16
,
24
,
24
)
assert
image_embedding
.
shape
==
(
1
,
16
,
24
,
24
)
self
.
assertTrue
(
max_diff
=
numpy_cosine_similarity_distance
(
image_embedding
.
flatten
(),
expected_image_embedding
.
flatten
())
np
.
allclose
(
assert
max_diff
<
1e-4
image_embedding
.
cpu
().
float
().
numpy
(),
expected_image_embedding
.
cpu
().
float
().
numpy
(),
atol
=
5e-2
)
)
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