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
104cead1
Commit
104cead1
authored
Oct 19, 2017
by
Myle Ott
Browse files
Set seed after each epoch to improve consistency when resuming
parent
8b4c45a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
3 deletions
+10
-3
fairseq/multiprocessing_trainer.py
fairseq/multiprocessing_trainer.py
+9
-3
train.py
train.py
+1
-0
No files found.
fairseq/multiprocessing_trainer.py
View file @
104cead1
...
...
@@ -57,9 +57,6 @@ class MultiprocessingTrainer(MultiprocessingEventLoop):
"""Initialize child processes."""
self
.
args
=
args
# set torch.seed in this process
torch
.
manual_seed
(
args
.
seed
)
# set CUDA device
torch
.
cuda
.
set_device
(
device_id
)
...
...
@@ -142,6 +139,15 @@ class MultiprocessingTrainer(MultiprocessingEventLoop):
self
.
lr_scheduler
,
cuda_device
=
device_id
)
return
extra_state
def
set_seed
(
self
,
seed
):
Future
.
gen_list
([
self
.
call_async
(
rank
,
'_async_set_seed'
,
seed
=
seed
)
for
rank
in
range
(
self
.
num_replicas
)
])
def
_async_set_seed
(
self
,
rank
,
device_id
,
seed
):
torch
.
manual_seed
(
seed
)
def
train_step
(
self
,
samples
):
"""Do forward, backward and gradient step in parallel."""
# PyTorch initializes gradient buffers lazily, so the first
...
...
train.py
View file @
104cead1
...
...
@@ -133,6 +133,7 @@ def train(args, epoch, batch_offset, trainer, dataset, num_gpus):
extra_meters
=
collections
.
defaultdict
(
lambda
:
AverageMeter
())
desc
=
'| epoch {:03d}'
.
format
(
epoch
)
trainer
.
set_seed
(
args
.
seed
+
epoch
)
lr
=
trainer
.
get_lr
()
with
progress_bar
(
itr
,
desc
,
leave
=
False
)
as
t
:
for
i
,
sample
in
data
.
skip_group_enumerator
(
t
,
num_gpus
,
batch_offset
):
...
...
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