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
chenpangpang
transformers
Commits
153755ee
Unverified
Commit
153755ee
authored
Sep 27, 2023
by
Younes Belkada
Committed by
GitHub
Sep 27, 2023
Browse files
[`FA` / `tests`] Add use_cache tests for FA models (#26415)
* add use_cache tests for FA * fixup
parent
a0be960d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
tests/test_modeling_common.py
tests/test_modeling_common.py
+29
-0
No files found.
tests/test_modeling_common.py
View file @
153755ee
...
...
@@ -2908,6 +2908,35 @@ class ModelTesterMixin:
self
.
assertTrue
(
torch
.
equal
(
out
,
out_fa
))
@
require_flash_attn
@
require_torch_gpu
@
mark
.
flash_attn_test
@
slow
def
test_flash_attn_2_generate_use_cache
(
self
):
import
torch
for
model_class
in
self
.
all_generative_model_classes
:
if
not
model_class
.
_supports_flash_attn_2
:
return
config
,
_
=
self
.
model_tester
.
prepare_config_and_inputs_for_common
()
model
=
model_class
(
config
)
with
tempfile
.
TemporaryDirectory
()
as
tmpdirname
:
model
.
save_pretrained
(
tmpdirname
)
dummy_input
=
torch
.
LongTensor
([[
0
,
2
,
3
,
4
],
[
0
,
2
,
3
,
4
]]).
to
(
torch_device
)
dummy_attention_mask
=
torch
.
LongTensor
([[
1
,
1
,
1
,
1
],
[
1
,
1
,
1
,
0
]]).
to
(
torch_device
)
model
=
model_class
.
from_pretrained
(
tmpdirname
,
torch_dtype
=
torch
.
float16
,
use_flash_attention_2
=
True
,
low_cpu_mem_usage
=
True
).
to
(
torch_device
)
# Just test that a large cache works as expected
_
=
model
.
generate
(
dummy_input
,
attention_mask
=
dummy_attention_mask
,
max_new_tokens
=
30
,
do_sample
=
False
)
global_rng
=
random
.
Random
()
...
...
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