Unverified Commit 699a2293 authored by Batese2001's avatar Batese2001 Committed by GitHub
Browse files

Fixed gradient_checkpointing/use_cache bug in blenderbot (#21833)

* Fixed gradient_checkpointing/use_cache bug in blenderbot

* Update modeling_blenderbot.py

* Added back if statement

* Formatted using black
parent 6feb39b4
...@@ -990,6 +990,12 @@ class BlenderbotDecoder(BlenderbotPreTrainedModel): ...@@ -990,6 +990,12 @@ class BlenderbotDecoder(BlenderbotPreTrainedModel):
hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training) hidden_states = nn.functional.dropout(hidden_states, p=self.dropout, training=self.training)
if self.gradient_checkpointing and self.training:
if use_cache:
logger.warning(
"`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
)
use_cache = False
# decoder layers # decoder layers
all_hidden_states = () if output_hidden_states else None all_hidden_states = () if output_hidden_states else None
all_self_attns = () if output_attentions else None all_self_attns = () if output_attentions else None
...@@ -1015,11 +1021,6 @@ class BlenderbotDecoder(BlenderbotPreTrainedModel): ...@@ -1015,11 +1021,6 @@ class BlenderbotDecoder(BlenderbotPreTrainedModel):
past_key_value = past_key_values[idx] if past_key_values is not None else None past_key_value = past_key_values[idx] 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.warning_once(
"`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