Unverified Commit 4a545d18 authored by Karim Foda's avatar Karim Foda Committed by GitHub
Browse files

Fix gradient checkpointing bug in BlipText (#21978)

Make Format
parent 451263b8
...@@ -393,6 +393,12 @@ class BlipTextEncoder(nn.Module): ...@@ -393,6 +393,12 @@ class BlipTextEncoder(nn.Module):
output_hidden_states=False, output_hidden_states=False,
return_dict=True, return_dict=True,
): ):
if self.gradient_checkpointing and self.training:
if use_cache:
logger.warn(
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
)
use_cache = False
all_hidden_states = () if output_hidden_states else None all_hidden_states = () if output_hidden_states else None
all_self_attentions = () if output_attentions else None all_self_attentions = () if output_attentions else None
all_cross_attentions = () if output_attentions and self.config.is_decoder else None all_cross_attentions = () if output_attentions and self.config.is_decoder else None
...@@ -408,11 +414,6 @@ class BlipTextEncoder(nn.Module): ...@@ -408,11 +414,6 @@ class BlipTextEncoder(nn.Module):
past_key_value = past_key_values[i] if past_key_values is not None else None past_key_value = past_key_values[i] if past_key_values is not None else None
if self.gradient_checkpointing and self.training: if self.gradient_checkpointing and self.training:
if use_cache:
logger.warn(
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
)
use_cache = False
def create_custom_forward(module): def create_custom_forward(module):
def custom_forward(*inputs): def custom_forward(*inputs):
......
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