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
65e6bc32
Commit
65e6bc32
authored
Mar 15, 2022
by
Lawrence McAfee
Browse files
fixed.
parent
4c598f9d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
42 deletions
+16
-42
megatron/model/fused_layer_norm.py
megatron/model/fused_layer_norm.py
+16
-28
megatron/model/language_model.py
megatron/model/language_model.py
+0
-6
megatron/schedules.py
megatron/schedules.py
+0
-8
No files found.
megatron/model/fused_layer_norm.py
View file @
65e6bc32
...
@@ -23,6 +23,8 @@ from torch.nn.parameter import Parameter
...
@@ -23,6 +23,8 @@ from torch.nn.parameter import Parameter
from
torch.nn
import
init
from
torch.nn
import
init
import
importlib
import
importlib
from
megatron.mpu
import
make_viewless_tensor
try
:
try
:
from
apex.contrib.layer_norm.layer_norm
import
FastLayerNormFN
from
apex.contrib.layer_norm.layer_norm
import
FastLayerNormFN
HAVE_PERSIST_LAYER_NORM
=
True
HAVE_PERSIST_LAYER_NORM
=
True
...
@@ -100,35 +102,21 @@ class MixedFusedLayerNorm(torch.nn.Module):
...
@@ -100,35 +102,21 @@ class MixedFusedLayerNorm(torch.nn.Module):
init
.
zeros_
(
self
.
bias
)
init
.
zeros_
(
self
.
bias
)
# def forward(self, input):
# if self.no_persist_layer_norm:
# return FusedLayerNormAffineFunction.apply(
# input, self.weight, self.bias, self.normalized_shape, self.eps)
# else:
# return FastLayerNormFN.apply(
# input, self.weight, self.bias, self.eps)
def
forward
(
self
,
input
):
def
forward
(
self
,
input
):
if
self
.
no_persist_layer_norm
:
if
self
.
no_persist_layer_norm
:
re
sult
=
FusedLayerNormAffineFunction
.
apply
(
re
turn
FusedLayerNormAffineFunction
.
apply
(
input
,
self
.
weight
,
self
.
bias
,
self
.
normalized_shape
,
self
.
eps
)
input
,
self
.
weight
,
self
.
bias
,
self
.
normalized_shape
,
self
.
eps
)
else
:
else
:
resul
t
=
FastLayerNormFN
.
apply
(
outpu
t
=
FastLayerNormFN
.
apply
(
input
,
self
.
weight
,
self
.
bias
,
self
.
eps
)
input
,
self
.
weight
,
self
.
bias
,
self
.
eps
)
result
=
make_viewless_tensor
(
inp
=
input
,
requires_grad
=
input
.
requires_grad
,
keep_grad
=
True
)
# >>>
# if torch.distributed.get_rank() == 3:
# # from lutil import pax
# # pax({"result": result})
# from megatron import get_args
# args = get_args()
# raise Exception("r %d ... hid %d, persist %d, view %d." % (
# torch.distributed.get_rank(),
# args.hidden_size,
# not args.no_persist_layer_norm,
# result._base is not None,
# ))
# <<<
return
result
# Apex's fast layer norm function outputs a 'view' tensor (i.e., has
# a populated '_base' field). This will result in schedule.py's
# deallocate_output_tensor() throwing an error, so a viewless tensor is
# created to prevent this.
output
=
make_viewless_tensor
(
inp
=
output
,
requires_grad
=
input
.
requires_grad
,
keep_graph
=
True
)
return
output
megatron/model/language_model.py
View file @
65e6bc32
...
@@ -337,12 +337,6 @@ class TransformerLanguageModel(MegatronModule):
...
@@ -337,12 +337,6 @@ class TransformerLanguageModel(MegatronModule):
else
:
else
:
self
.
encoder
=
None
self
.
encoder
=
None
# >>>
# if torch.distributed.get_rank() == 3:
# print(self.encoder)
# raise Exception("bye.")
# <<<
# Decoder (usually set to False, True if part of an encoder-decoder
# Decoder (usually set to False, True if part of an encoder-decoder
# architecture and in decoder-only stage).
# architecture and in decoder-only stage).
if
self
.
add_decoder
:
if
self
.
add_decoder
:
...
...
megatron/schedules.py
View file @
65e6bc32
...
@@ -651,14 +651,6 @@ def forward_backward_pipelining_without_interleaving(forward_step_func,
...
@@ -651,14 +651,6 @@ def forward_backward_pipelining_without_interleaving(forward_step_func,
if
not
forward_only
:
if
not
forward_only
:
input_tensors
.
append
(
input_tensor
)
input_tensors
.
append
(
input_tensor
)
output_tensors
.
append
(
output_tensor
)
output_tensors
.
append
(
output_tensor
)
# >>>
if
output_tensor
[
0
].
_base
is
not
None
:
# from lutil import pax
# pax({
# "output tensor / 0" : output_tensor[0],
# })
raise
Exception
(
">>>>>> r %d, output / 0 == view."
%
torch
.
distributed
.
get_rank
())
# <<<
deallocate_output_tensor
(
output_tensor
[
0
])
deallocate_output_tensor
(
output_tensor
[
0
])
# Before running 1F1B, need to receive first forward tensor.
# Before running 1F1B, need to receive first forward tensor.
...
...
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