[Falcon] Set use_cache=False before creating presents which relies on use_cache (#26328)

* Set `presents=None` when `use_cache` is set to False for activation ckpt

* Update modeling_falcon.py

* fix black
This commit is contained in:
Yun Dai 2023-10-05 01:18:27 -07:00 committed by GitHub
parent 253f9a3f97
commit 2ab76c2c4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1094,6 +1094,12 @@ class FalconModel(FalconPreTrainedModel):
hidden_states = inputs_embeds
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
all_self_attentions = () if output_attentions else None
all_hidden_states = () if output_hidden_states else None
@ -1137,11 +1143,6 @@ class FalconModel(FalconPreTrainedModel):
all_hidden_states = all_hidden_states + (hidden_states,)
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 custom_forward(*inputs):