Unverified Commit c02d302e authored by Raushan Turganbay's avatar Raushan Turganbay Committed by GitHub
Browse files

Fix cache type in Idefics2 (#30729)

standardize cache in idefics2
parent 449894d2
......@@ -1591,8 +1591,9 @@ 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):
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)
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment