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
3bd2e973
Commit
3bd2e973
authored
Aug 16, 2021
by
Lawrence McAfee
Browse files
added flag/logic for emptying unused memory
parent
78a69eaf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
0 deletions
+18
-0
megatron/arguments.py
megatron/arguments.py
+9
-0
megatron/training.py
megatron/training.py
+9
-0
No files found.
megatron/arguments.py
View file @
3bd2e973
...
@@ -601,6 +601,15 @@ def _add_distributed_args(parser):
...
@@ -601,6 +601,15 @@ def _add_distributed_args(parser):
group
.
add_argument
(
'--use-cpu-initialization'
,
action
=
'store_true'
,
group
.
add_argument
(
'--use-cpu-initialization'
,
action
=
'store_true'
,
default
=
None
,
help
=
'If set, affine parallel weights '
default
=
None
,
help
=
'If set, affine parallel weights '
'initialization uses CPU'
)
'initialization uses CPU'
)
# group.add_argument('--empty-unused-memory-each-iter', action='store_true',
# help='Call torch.cuda.empty_cache() each iteration '
# '(training and eval), to reduce fragmentation',
# default=False)
group
.
add_argument
(
'--empty-unused-memory-each-iter'
,
default
=
0
,
type
=
int
,
choices
=
[
0
,
1
,
2
],
help
=
'Call torch.cuda.empty_cache() each iteration '
'(training and eval), to reduce fragmentation.'
'0=off, 1=moderate, 2=aggressive.'
)
return
parser
return
parser
...
...
megatron/training.py
View file @
3bd2e973
...
@@ -362,6 +362,11 @@ def train_step(forward_step_func, data_iterator,
...
@@ -362,6 +362,11 @@ def train_step(forward_step_func, data_iterator,
forward_step_func
,
data_iterator
,
model
,
forward_step_func
,
data_iterator
,
model
,
optimizer
,
timers
,
forward_only
=
False
)
optimizer
,
timers
,
forward_only
=
False
)
# Empty unused memory
if
args
.
empty_unused_memory_each_iter
>=
2
:
raise
Exception
(
"hi."
)
torch
.
cuda
.
empty_cache
()
# All-reduce if needed.
# All-reduce if needed.
if
args
.
DDP_impl
==
'local'
:
if
args
.
DDP_impl
==
'local'
:
timers
(
'backward-params-all-reduce'
).
start
()
timers
(
'backward-params-all-reduce'
).
start
()
...
@@ -408,6 +413,10 @@ def train_step(forward_step_func, data_iterator,
...
@@ -408,6 +413,10 @@ def train_step(forward_step_func, data_iterator,
else
:
else
:
skipped_iter
=
1
skipped_iter
=
1
# Empty unused memory
if
args
.
empty_unused_memory_each_iter
>=
1
:
torch
.
cuda
.
empty_cache
()
if
mpu
.
is_pipeline_last_stage
(
ignore_virtual
=
True
):
if
mpu
.
is_pipeline_last_stage
(
ignore_virtual
=
True
):
# Average loss across microbatches.
# Average loss across microbatches.
loss_reduced
=
{}
loss_reduced
=
{}
...
...
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