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
OpenDAS
Megatron-LM
Commits
5f174c07
Commit
5f174c07
authored
Apr 10, 2020
by
Mohammad
Browse files
fp32 fixes
parent
1c1a55da
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
3 deletions
+7
-3
megatron/model/transformer.py
megatron/model/transformer.py
+3
-2
megatron/training.py
megatron/training.py
+4
-1
No files found.
megatron/model/transformer.py
View file @
5f174c07
...
...
@@ -102,6 +102,7 @@ class ParallelSelfAttention(MegatronModule):
output_layer_init_method
,
layer_number
):
super
(
ParallelSelfAttention
,
self
).
__init__
()
args
=
get_args
()
self
.
fp16
=
args
.
fp16
self
.
attention_mask_func
=
attention_mask_func
self
.
apply_query_key_layer_scaling
=
args
.
apply_query_key_layer_scaling
...
...
@@ -244,7 +245,7 @@ class ParallelSelfAttention(MegatronModule):
query_layer
,
key_layer
)
# fp32 conversion.
if
self
.
attention_softmax_in_fp32
:
if
self
.
fp16
and
self
.
attention_softmax_in_fp32
:
attention_scores
=
attention_scores
.
float
()
# Apply attention mask. [b, np, s, s]
...
...
@@ -267,7 +268,7 @@ class ParallelSelfAttention(MegatronModule):
attention_probs
=
self
.
_get_attention_probs
(
attention_scores
)
# fp16 conversion
if
self
.
attention_softmax_in_fp32
:
if
self
.
fp16
and
self
.
attention_softmax_in_fp32
:
attention_probs
=
attention_probs
.
half
()
# Context layer. [b, s, hp]
...
...
megatron/training.py
View file @
5f174c07
...
...
@@ -379,9 +379,12 @@ def train(forward_step_func, model, optimizer, lr_scheduler,
iteration
+=
1
# Logging.
loss_scale
=
None
if
args
.
fp16
:
loss_scale
=
optimizer
.
loss_scale
report_memory_flag
=
training_log
(
loss_dict
,
total_loss_dict
,
optimizer
.
param_groups
[
0
][
'lr'
],
iteration
,
optimizer
.
loss_scale
,
iteration
,
loss_scale
,
report_memory_flag
)
# Autoresume
...
...
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