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
6d3adf65
Unverified
Commit
6d3adf65
authored
Jan 12, 2023
by
Patrick von Platen
Committed by
GitHub
Jan 12, 2023
Browse files
Fix slow tests (#1983)
* [Slow tests] Fix tests * Update tests/pipelines/karras_ve/test_karras_ve.py
parent
dbdd585c
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
7 deletions
+45
-7
src/diffusers/pipelines/stochastic_karras_ve/pipeline_stochastic_karras_ve.py
...nes/stochastic_karras_ve/pipeline_stochastic_karras_ve.py
+1
-1
tests/pipelines/karras_ve/test_karras_ve.py
tests/pipelines/karras_ve/test_karras_ve.py
+38
-0
tests/test_pipelines.py
tests/test_pipelines.py
+6
-6
No files found.
src/diffusers/pipelines/stochastic_karras_ve/pipeline_stochastic_karras_ve.py
View file @
6d3adf65
...
@@ -82,7 +82,7 @@ class KarrasVePipeline(DiffusionPipeline):
...
@@ -82,7 +82,7 @@ class KarrasVePipeline(DiffusionPipeline):
model
=
self
.
unet
model
=
self
.
unet
# sample x_0 ~ N(0, sigma_0^2 * I)
# sample x_0 ~ N(0, sigma_0^2 * I)
sample
=
randn_tensor
(
shape
,
device
=
self
.
device
)
*
self
.
scheduler
.
init_noise_sigma
sample
=
randn_tensor
(
shape
,
generator
=
generator
,
device
=
self
.
device
)
*
self
.
scheduler
.
init_noise_sigma
self
.
scheduler
.
set_timesteps
(
num_inference_steps
)
self
.
scheduler
.
set_timesteps
(
num_inference_steps
)
...
...
tests/pipelines/karras_ve/test_karras_ve.py
View file @
6d3adf65
...
@@ -25,6 +25,44 @@ from diffusers.utils.testing_utils import require_torch, slow, torch_device
...
@@ -25,6 +25,44 @@ from diffusers.utils.testing_utils import require_torch, slow, torch_device
torch
.
backends
.
cuda
.
matmul
.
allow_tf32
=
False
torch
.
backends
.
cuda
.
matmul
.
allow_tf32
=
False
class
KarrasVePipelineFastTests
(
unittest
.
TestCase
):
@
property
def
dummy_uncond_unet
(
self
):
torch
.
manual_seed
(
0
)
model
=
UNet2DModel
(
block_out_channels
=
(
32
,
64
),
layers_per_block
=
2
,
sample_size
=
32
,
in_channels
=
3
,
out_channels
=
3
,
down_block_types
=
(
"DownBlock2D"
,
"AttnDownBlock2D"
),
up_block_types
=
(
"AttnUpBlock2D"
,
"UpBlock2D"
),
)
return
model
def
test_inference
(
self
):
unet
=
self
.
dummy_uncond_unet
scheduler
=
KarrasVeScheduler
()
pipe
=
KarrasVePipeline
(
unet
=
unet
,
scheduler
=
scheduler
)
pipe
.
to
(
torch_device
)
pipe
.
set_progress_bar_config
(
disable
=
None
)
generator
=
torch
.
manual_seed
(
0
)
image
=
pipe
(
num_inference_steps
=
2
,
generator
=
generator
,
output_type
=
"numpy"
).
images
generator
=
torch
.
manual_seed
(
0
)
image_from_tuple
=
pipe
(
num_inference_steps
=
2
,
generator
=
generator
,
output_type
=
"numpy"
,
return_dict
=
False
)[
0
]
image_slice
=
image
[
0
,
-
3
:,
-
3
:,
-
1
]
image_from_tuple_slice
=
image_from_tuple
[
0
,
-
3
:,
-
3
:,
-
1
]
assert
image
.
shape
==
(
1
,
32
,
32
,
3
)
expected_slice
=
np
.
array
([
0.0
,
1.0
,
0.0
,
0.0
,
0.0
,
1.0
,
0.0
,
0.0
,
0.0
])
assert
np
.
abs
(
image_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
assert
np
.
abs
(
image_from_tuple_slice
.
flatten
()
-
expected_slice
).
max
()
<
1e-2
@
slow
@
slow
@
require_torch
@
require_torch
class
KarrasVePipelineIntegrationTests
(
unittest
.
TestCase
):
class
KarrasVePipelineIntegrationTests
(
unittest
.
TestCase
):
...
...
tests/test_pipelines.py
View file @
6d3adf65
...
@@ -742,10 +742,10 @@ class PipelineSlowTests(unittest.TestCase):
...
@@ -742,10 +742,10 @@ class PipelineSlowTests(unittest.TestCase):
new_ddpm
.
to
(
torch_device
)
new_ddpm
.
to
(
torch_device
)
generator
=
torch
.
Generator
(
device
=
torch_device
).
manual_seed
(
0
)
generator
=
torch
.
Generator
(
device
=
torch_device
).
manual_seed
(
0
)
image
=
ddpm
(
generator
=
generator
,
output_type
=
"numpy"
).
images
image
=
ddpm
(
generator
=
generator
,
num_inference_steps
=
5
,
output_type
=
"numpy"
).
images
generator
=
generator
.
manual_seed
(
0
)
generator
=
generator
.
manual_seed
(
0
)
new_image
=
new_ddpm
(
generator
=
generator
,
output_type
=
"numpy"
).
images
new_image
=
new_ddpm
(
generator
=
generator
,
num_inference_steps
=
5
,
output_type
=
"numpy"
).
images
assert
np
.
abs
(
image
-
new_image
).
sum
()
<
1e-5
,
"Models don't give the same forward pass"
assert
np
.
abs
(
image
-
new_image
).
sum
()
<
1e-5
,
"Models don't give the same forward pass"
...
@@ -763,10 +763,10 @@ class PipelineSlowTests(unittest.TestCase):
...
@@ -763,10 +763,10 @@ class PipelineSlowTests(unittest.TestCase):
ddpm_from_hub
.
set_progress_bar_config
(
disable
=
None
)
ddpm_from_hub
.
set_progress_bar_config
(
disable
=
None
)
generator
=
torch
.
Generator
(
device
=
torch_device
).
manual_seed
(
0
)
generator
=
torch
.
Generator
(
device
=
torch_device
).
manual_seed
(
0
)
image
=
ddpm
(
generator
=
generator
,
output_type
=
"numpy"
).
images
image
=
ddpm
(
generator
=
generator
,
num_inference_steps
=
5
,
output_type
=
"numpy"
).
images
generator
=
generator
.
manual_seed
(
0
)
generator
=
generator
.
manual_seed
(
0
)
new_image
=
ddpm_from_hub
(
generator
=
generator
,
output_type
=
"numpy"
).
images
new_image
=
ddpm_from_hub
(
generator
=
generator
,
num_inference_steps
=
5
,
output_type
=
"numpy"
).
images
assert
np
.
abs
(
image
-
new_image
).
sum
()
<
1e-5
,
"Models don't give the same forward pass"
assert
np
.
abs
(
image
-
new_image
).
sum
()
<
1e-5
,
"Models don't give the same forward pass"
...
@@ -786,10 +786,10 @@ class PipelineSlowTests(unittest.TestCase):
...
@@ -786,10 +786,10 @@ class PipelineSlowTests(unittest.TestCase):
ddpm_from_hub_custom_model
.
set_progress_bar_config
(
disable
=
None
)
ddpm_from_hub_custom_model
.
set_progress_bar_config
(
disable
=
None
)
generator
=
torch
.
Generator
(
device
=
torch_device
).
manual_seed
(
0
)
generator
=
torch
.
Generator
(
device
=
torch_device
).
manual_seed
(
0
)
image
=
ddpm_from_hub_custom_model
(
generator
=
generator
,
output_type
=
"numpy"
).
images
image
=
ddpm_from_hub_custom_model
(
generator
=
generator
,
num_inference_steps
=
5
,
output_type
=
"numpy"
).
images
generator
=
generator
.
manual_seed
(
0
)
generator
=
generator
.
manual_seed
(
0
)
new_image
=
ddpm_from_hub
(
generator
=
generator
,
output_type
=
"numpy"
).
images
new_image
=
ddpm_from_hub
(
generator
=
generator
,
num_inference_steps
=
5
,
output_type
=
"numpy"
).
images
assert
np
.
abs
(
image
-
new_image
).
sum
()
<
1e-5
,
"Models don't give the same forward pass"
assert
np
.
abs
(
image
-
new_image
).
sum
()
<
1e-5
,
"Models don't give the same forward pass"
...
...
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