Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
c82bd371
"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "101b9a7eb13c5ad0967b4d7615d974bb9d3ab93e"
Unverified
Commit
c82bd371
authored
Mar 03, 2023
by
Karim Foda
Committed by
GitHub
Mar 03, 2023
Browse files
Fix gradient checkpointing megatron bert (#21921)
parent
99a62347
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
src/transformers/models/megatron_bert/modeling_megatron_bert.py
...ansformers/models/megatron_bert/modeling_megatron_bert.py
+6
-5
No files found.
src/transformers/models/megatron_bert/modeling_megatron_bert.py
View file @
c82bd371
...
@@ -530,6 +530,12 @@ class MegatronBertEncoder(nn.Module):
...
@@ -530,6 +530,12 @@ class MegatronBertEncoder(nn.Module):
output_hidden_states
:
Optional
[
bool
]
=
False
,
output_hidden_states
:
Optional
[
bool
]
=
False
,
return_dict
:
Optional
[
bool
]
=
True
,
return_dict
:
Optional
[
bool
]
=
True
,
)
->
Union
[
Tuple
,
BaseModelOutputWithPastAndCrossAttentions
]:
)
->
Union
[
Tuple
,
BaseModelOutputWithPastAndCrossAttentions
]:
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
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
.
add_cross_attention
else
None
all_cross_attentions
=
()
if
output_attentions
and
self
.
config
.
add_cross_attention
else
None
...
@@ -543,11 +549,6 @@ class MegatronBertEncoder(nn.Module):
...
@@ -543,11 +549,6 @@ class MegatronBertEncoder(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
.
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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment