Skip to content

Commit

Permalink
disable use_cache if using gradient checkpointing (#30320)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzizhao authored and ydshieh committed Apr 23, 2024
1 parent 4359a98 commit 66ecc2b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/transformers/models/idefics2/modeling_idefics2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,12 @@ def forward(
use_cache = use_cache if use_cache is not None else self.config.use_cache
return_dict = return_dict if return_dict is not None else self.config.use_return_dict

if self.training and self.text_model.gradient_checkpointing and use_cache:
logger.warning_once(
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
)
use_cache = False

# retrieve input_ids and inputs_embeds
if input_ids is not None:
batch_size, seq_length = input_ids.shape
Expand Down

0 comments on commit 66ecc2b

Please sign in to comment.