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
ea01a4c7
Commit
ea01a4c7
authored
Oct 28, 2022
by
Patrick von Platen
Browse files
fix
parents
cbbb2939
d37f08da
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
8 deletions
+25
-8
src/diffusers/utils/__init__.py
src/diffusers/utils/__init__.py
+1
-0
src/diffusers/utils/testing_utils.py
src/diffusers/utils/testing_utils.py
+17
-1
tests/models/test_models_unet_2d.py
tests/models/test_models_unet_2d.py
+7
-7
No files found.
src/diffusers/utils/__init__.py
View file @
ea01a4c7
...
@@ -43,6 +43,7 @@ if is_torch_available():
...
@@ -43,6 +43,7 @@ if is_torch_available():
from
.testing_utils
import
(
from
.testing_utils
import
(
floats_tensor
,
floats_tensor
,
load_image
,
load_image
,
load_numpy
,
parse_flag_from_env
,
parse_flag_from_env
,
require_torch_gpu
,
require_torch_gpu
,
slow
,
slow
,
...
...
src/diffusers/utils/testing_utils.py
View file @
ea01a4c7
...
@@ -4,11 +4,14 @@ import os
...
@@ -4,11 +4,14 @@ import os
import
random
import
random
import
re
import
re
import
unittest
import
unittest
import
urllib.parse
from
distutils.util
import
strtobool
from
distutils.util
import
strtobool
from
io
import
StringIO
from
io
import
BytesIO
,
StringIO
from
pathlib
import
Path
from
pathlib
import
Path
from
typing
import
Union
from
typing
import
Union
import
numpy
as
np
import
PIL.Image
import
PIL.Image
import
PIL.ImageOps
import
PIL.ImageOps
import
requests
import
requests
...
@@ -165,6 +168,19 @@ def load_image(image: Union[str, PIL.Image.Image]) -> PIL.Image.Image:
...
@@ -165,6 +168,19 @@ def load_image(image: Union[str, PIL.Image.Image]) -> PIL.Image.Image:
return
image
return
image
def
load_numpy
(
path
)
->
np
.
ndarray
:
if
not
path
.
startswith
(
"http://"
)
or
path
.
startswith
(
"https://"
):
path
=
os
.
path
.
join
(
"https://huggingface.co/datasets/fusing/diffusers-testing/resolve/main"
,
urllib
.
parse
.
quote
(
path
)
)
response
=
requests
.
get
(
path
)
response
.
raise_for_status
()
array
=
np
.
load
(
BytesIO
(
response
.
content
))
return
array
# --- pytest conf functions --- #
# --- pytest conf functions --- #
# to avoid multiple invocation from tests/conftest.py and examples/conftest.py - make sure it's called only once
# to avoid multiple invocation from tests/conftest.py and examples/conftest.py - make sure it's called only once
...
...
tests/models/test_models_unet_2d.py
View file @
ea01a4c7
...
@@ -21,7 +21,7 @@ import unittest
...
@@ -21,7 +21,7 @@ import unittest
import
torch
import
torch
from
diffusers
import
UNet2DConditionModel
,
UNet2DModel
from
diffusers
import
UNet2DConditionModel
,
UNet2DModel
from
diffusers.utils
import
floats_tensor
,
require_torch_gpu
,
slow
,
torch_all_close
,
torch_device
from
diffusers.utils
import
floats_tensor
,
load_numpy
,
require_torch_gpu
,
slow
,
torch_all_close
,
torch_device
from
parameterized
import
parameterized
from
parameterized
import
parameterized
from
..test_modeling_common
import
ModelTesterMixin
from
..test_modeling_common
import
ModelTesterMixin
...
@@ -411,6 +411,9 @@ class NCSNppModelTests(ModelTesterMixin, unittest.TestCase):
...
@@ -411,6 +411,9 @@ class NCSNppModelTests(ModelTesterMixin, unittest.TestCase):
@
slow
@
slow
class
UNet2DConditionModelIntegrationTests
(
unittest
.
TestCase
):
class
UNet2DConditionModelIntegrationTests
(
unittest
.
TestCase
):
def
get_file_format
(
self
,
seed
,
shape
):
return
f
"gaussian_noise_s=
{
seed
}
_shape=
{
'_'
.
join
([
str
(
s
)
for
s
in
shape
])
}
.npy"
def
tearDown
(
self
):
def
tearDown
(
self
):
# clean up the VRAM after each test
# clean up the VRAM after each test
super
().
tearDown
()
super
().
tearDown
()
...
@@ -418,11 +421,8 @@ class UNet2DConditionModelIntegrationTests(unittest.TestCase):
...
@@ -418,11 +421,8 @@ class UNet2DConditionModelIntegrationTests(unittest.TestCase):
torch
.
cuda
.
empty_cache
()
torch
.
cuda
.
empty_cache
()
def
get_latents
(
self
,
seed
=
0
,
shape
=
(
4
,
4
,
64
,
64
),
fp16
=
False
):
def
get_latents
(
self
,
seed
=
0
,
shape
=
(
4
,
4
,
64
,
64
),
fp16
=
False
):
batch_size
,
channels
,
height
,
width
=
shape
generator
=
torch
.
Generator
(
device
=
torch_device
).
manual_seed
(
seed
)
dtype
=
torch
.
float16
if
fp16
else
torch
.
float32
dtype
=
torch
.
float16
if
fp16
else
torch
.
float32
image
=
torch
.
randn
(
batch_size
,
channels
,
height
,
width
,
device
=
torch_device
,
generator
=
generator
,
dtype
=
dtype
)
image
=
torch
.
from_numpy
(
load_numpy
(
self
.
get_file_format
(
seed
,
shape
))).
to
(
torch_device
).
to
(
dtype
)
return
image
return
image
def
get_unet_model
(
self
,
fp16
=
False
,
model_id
=
"CompVis/stable-diffusion-v1-4"
):
def
get_unet_model
(
self
,
fp16
=
False
,
model_id
=
"CompVis/stable-diffusion-v1-4"
):
...
@@ -437,9 +437,9 @@ class UNet2DConditionModelIntegrationTests(unittest.TestCase):
...
@@ -437,9 +437,9 @@ class UNet2DConditionModelIntegrationTests(unittest.TestCase):
return
model
return
model
def
get_encoder_hidden_states
(
self
,
seed
=
0
,
shape
=
(
4
,
77
,
768
),
fp16
=
False
):
def
get_encoder_hidden_states
(
self
,
seed
=
0
,
shape
=
(
4
,
77
,
768
),
fp16
=
False
):
generator
=
torch
.
Generator
(
device
=
torch_device
).
manual_seed
(
seed
)
dtype
=
torch
.
float16
if
fp16
else
torch
.
float32
dtype
=
torch
.
float16
if
fp16
else
torch
.
float32
return
torch
.
randn
(
shape
,
device
=
torch_device
,
generator
=
generator
,
dtype
=
dtype
)
hidden_states
=
torch
.
from_numpy
(
load_numpy
(
self
.
get_file_format
(
seed
,
shape
))).
to
(
torch_device
).
to
(
dtype
)
return
hidden_states
@
parameterized
.
expand
(
@
parameterized
.
expand
(
[
[
...
...
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