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
e33d63cc
Commit
e33d63cc
authored
Dec 08, 2021
by
Lawrence McAfee
Browse files
added docstrings to new methods
parent
2f25c570
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
megatron/schedules.py
megatron/schedules.py
+13
-0
No files found.
megatron/schedules.py
View file @
e33d63cc
...
@@ -43,6 +43,12 @@ def get_forward_backward_func():
...
@@ -43,6 +43,12 @@ def get_forward_backward_func():
return
forward_backward_func
return
forward_backward_func
def
free_output_tensor
(
output_tensors
):
def
free_output_tensor
(
output_tensors
):
'''Pseudo-free (i.e., set to scalar) the output tensor's '.data' field.
This method should be called right after the output tensor has been
sent to the next pipeline stage. At this point, the output tensor is
only useful for its '.grad_fn' field, and not its '.data'.
'''
if
output_tensors
is
None
:
if
output_tensors
is
None
:
return
return
if
isinstance
(
output_tensors
,
torch
.
Tensor
):
if
isinstance
(
output_tensors
,
torch
.
Tensor
):
...
@@ -51,6 +57,13 @@ def free_output_tensor(output_tensors):
...
@@ -51,6 +57,13 @@ def free_output_tensor(output_tensors):
output_tensor
.
data
=
torch
.
FloatTensor
([
0
]).
to
(
output_tensor
.
data
)
output_tensor
.
data
=
torch
.
FloatTensor
([
0
]).
to
(
output_tensor
.
data
)
def
custom_backward
(
output
,
grad_output
):
def
custom_backward
(
output
,
grad_output
):
'''Directly call C++ autograd engine.
To make the 'free_output_tensor' (above) optimization work, the C++
autograd engine must be called directly, bypassing Pytorch's
torch.autograd.backward. Pytorch's 'backward' checks that the output and
grad have the same shape, while C++'s 'backward' does not.
'''
assert
output
.
numel
()
==
1
,
\
assert
output
.
numel
()
==
1
,
\
"output should be pseudo-'freed' in schedule, to optimize memory"
"output should be pseudo-'freed' in schedule, to optimize memory"
...
...
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