"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "0b686a8a1e3784e283559370538f5445baf850a8"
Unverified Commit 78a93d17 authored by Younes Belkada's avatar Younes Belkada Committed by GitHub
Browse files

[`GPTNeo`] Fix gradient checkpointing bug (#21733)



* fix bug

* forward contrib credits from discussions

* change logic

---------
Co-authored-by: default avataredbeeching <edbeeching@users.noreply.github.com>
parent 36a6a1ad
...@@ -587,6 +587,13 @@ class GPTNeoModel(GPTNeoPreTrainedModel): ...@@ -587,6 +587,13 @@ class GPTNeoModel(GPTNeoPreTrainedModel):
output_shape = input_shape + (hidden_states.size(-1),) output_shape = input_shape + (hidden_states.size(-1),)
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
presents = () if use_cache else None presents = () if use_cache else None
all_self_attentions = () if output_attentions else None all_self_attentions = () if output_attentions else None
all_hidden_states = () if output_hidden_states else None all_hidden_states = () if output_hidden_states else None
...@@ -595,11 +602,6 @@ class GPTNeoModel(GPTNeoPreTrainedModel): ...@@ -595,11 +602,6 @@ class GPTNeoModel(GPTNeoPreTrainedModel):
all_hidden_states = all_hidden_states + (hidden_states,) all_hidden_states = all_hidden_states + (hidden_states,)
if self.gradient_checkpointing and 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
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