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
Fairseq
Commits
f4108909
Commit
f4108909
authored
Jun 05, 2018
by
Alexei Baevski
Committed by
Myle Ott
Jun 15, 2018
Browse files
build optimizer only once, otherwise it leaks cuda memory
parent
92050ef2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
5 deletions
+12
-5
fairseq/trainer.py
fairseq/trainer.py
+5
-2
train.py
train.py
+7
-3
No files found.
fairseq/trainer.py
View file @
f4108909
...
@@ -38,8 +38,7 @@ class Trainer(object):
...
@@ -38,8 +38,7 @@ class Trainer(object):
self
.
model
=
model
.
cuda
()
self
.
model
=
model
.
cuda
()
self
.
criterion
=
criterion
.
cuda
()
self
.
criterion
=
criterion
.
cuda
()
# initialize optimizer and LR scheduler
self
.
optimizer
=
None
self
.
_build_optimizer
()
# initialize meters
# initialize meters
self
.
meters
=
OrderedDict
()
self
.
meters
=
OrderedDict
()
...
@@ -96,6 +95,10 @@ class Trainer(object):
...
@@ -96,6 +95,10 @@ class Trainer(object):
def
train_step
(
self
,
sample
,
update_params
=
True
):
def
train_step
(
self
,
sample
,
update_params
=
True
):
"""Do forward, backward and parameter update."""
"""Do forward, backward and parameter update."""
if
self
.
optimizer
is
None
:
# initialize optimizer and LR scheduler if hasn't been loaded from the checkpoint
self
.
_build_optimizer
()
sample
=
self
.
_prepare_sample
(
sample
,
volatile
=
False
)
sample
=
self
.
_prepare_sample
(
sample
,
volatile
=
False
)
# forward and backward pass
# forward and backward pass
...
...
train.py
View file @
f4108909
...
@@ -310,6 +310,10 @@ def save_checkpoint(args, trainer, epoch, end_of_epoch, val_loss):
...
@@ -310,6 +310,10 @@ def save_checkpoint(args, trainer, epoch, end_of_epoch, val_loss):
for
fn
in
checkpoints
:
for
fn
in
checkpoints
:
if
os
.
path
.
exists
(
fn
):
if
os
.
path
.
exists
(
fn
):
os
.
remove
(
fn
)
os
.
remove
(
fn
)
if
not
end_of_epoch
and
args
.
keep_interval_updates
>
0
:
for
cp
in
checkpoints
:
trainer
.
save_checkpoint
(
cp
,
extra_state
)
else
:
trainer
.
save_checkpoint
(
checkpoints
[
0
],
extra_state
)
trainer
.
save_checkpoint
(
checkpoints
[
0
],
extra_state
)
for
fn
in
checkpoints
[
1
:]:
for
fn
in
checkpoints
[
1
:]:
os
.
symlink
(
os
.
path
.
basename
(
checkpoints
[
0
]),
fn
)
os
.
symlink
(
os
.
path
.
basename
(
checkpoints
[
0
]),
fn
)
...
...
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