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
c02d302e
Unverified
Commit
c02d302e
authored
May 14, 2024
by
Raushan Turganbay
Committed by
GitHub
May 14, 2024
Browse files
Fix cache type in Idefics2 (#30729)
standardize cache in idefics2
parent
449894d2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
src/transformers/models/idefics2/modeling_idefics2.py
src/transformers/models/idefics2/modeling_idefics2.py
+7
-3
No files found.
src/transformers/models/idefics2/modeling_idefics2.py
View file @
c02d302e
...
...
@@ -1591,9 +1591,10 @@ class Idefics2Model(Idefics2PreTrainedModel):
raise
ValueError
(
"You have to specify either input_ids or inputs_embeds"
)
past_seen_tokens
=
0
if
use_cache
:
if
not
isinstance
(
past_key_values
,
Cache
):
past_key_values
=
DynamicCache
.
from_legacy_cache
(
past_key_values
)
return_legacy_cache
=
False
if
use_cache
and
not
isinstance
(
past_key_values
,
Cache
):
# kept for BC (non `Cache` `past_key_values` inputs)
return_legacy_cache
=
True
past_key_values
=
DynamicCache
.
from_legacy_cache
(
past_key_values
)
past_seen_tokens
=
past_key_values
.
get_usable_length
(
seq_length
)
if
inputs_embeds
is
not
None
and
input_ids
is
None
and
past_seen_tokens
==
0
:
...
...
@@ -1667,6 +1668,9 @@ class Idefics2Model(Idefics2PreTrainedModel):
return_dict
=
return_dict
,
)
if
return_legacy_cache
:
outputs
.
past_key_values
=
outputs
.
past_key_values
.
to_legacy_cache
()
if
not
return_dict
:
return
tuple
(
v
for
v
in
[
*
outputs
,
image_hidden_states
]
if
v
is
not
None
)
...
...
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