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
71f56c77
Unverified
Commit
71f56c77
authored
Nov 07, 2023
by
Dhruv Nair
Committed by
GitHub
Nov 07, 2023
Browse files
Model tests xformers fixes (#5679)
* fix model xformers test * update
parent
6a89a6c9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
11 deletions
+9
-11
tests/models/test_modeling_common.py
tests/models/test_modeling_common.py
+9
-11
No files found.
tests/models/test_modeling_common.py
View file @
71f56c77
...
...
@@ -293,7 +293,16 @@ class ModelTesterMixin:
with
torch
.
no_grad
():
output_2
=
model
(
**
inputs_dict
)[
0
]
model
.
set_attn_processor
(
XFormersAttnProcessor
())
assert
all
(
type
(
proc
)
==
XFormersAttnProcessor
for
proc
in
model
.
attn_processors
.
values
())
with
torch
.
no_grad
():
output_3
=
model
(
**
inputs_dict
)[
0
]
torch
.
use_deterministic_algorithms
(
True
)
assert
torch
.
allclose
(
output
,
output_2
,
atol
=
self
.
base_precision
)
assert
torch
.
allclose
(
output
,
output_3
,
atol
=
self
.
base_precision
)
assert
torch
.
allclose
(
output_2
,
output_3
,
atol
=
self
.
base_precision
)
@
require_torch_gpu
def
test_set_attn_processor_for_determinism
(
self
):
...
...
@@ -315,11 +324,6 @@ class ModelTesterMixin:
with
torch
.
no_grad
():
output_2
=
model
(
**
inputs_dict
)[
0
]
model
.
enable_xformers_memory_efficient_attention
()
assert
all
(
type
(
proc
)
==
XFormersAttnProcessor
for
proc
in
model
.
attn_processors
.
values
())
with
torch
.
no_grad
():
model
(
**
inputs_dict
)[
0
]
model
.
set_attn_processor
(
AttnProcessor2_0
())
assert
all
(
type
(
proc
)
==
AttnProcessor2_0
for
proc
in
model
.
attn_processors
.
values
())
with
torch
.
no_grad
():
...
...
@@ -330,18 +334,12 @@ class ModelTesterMixin:
with
torch
.
no_grad
():
output_5
=
model
(
**
inputs_dict
)[
0
]
model
.
set_attn_processor
(
XFormersAttnProcessor
())
assert
all
(
type
(
proc
)
==
XFormersAttnProcessor
for
proc
in
model
.
attn_processors
.
values
())
with
torch
.
no_grad
():
output_6
=
model
(
**
inputs_dict
)[
0
]
torch
.
use_deterministic_algorithms
(
True
)
# make sure that outputs match
assert
torch
.
allclose
(
output_2
,
output_1
,
atol
=
self
.
base_precision
)
assert
torch
.
allclose
(
output_2
,
output_4
,
atol
=
self
.
base_precision
)
assert
torch
.
allclose
(
output_2
,
output_5
,
atol
=
self
.
base_precision
)
assert
torch
.
allclose
(
output_2
,
output_6
,
atol
=
self
.
base_precision
)
def
test_from_save_pretrained_variant
(
self
,
expected_max_diff
=
5e-5
):
init_dict
,
inputs_dict
=
self
.
prepare_init_args_and_inputs_for_common
()
...
...
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