-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from Media-Smart/fix_seed_bug
fix seed bug
- Loading branch information
Showing
8 changed files
with
81 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright (c) Open-MMLab. All rights reserved. | ||
from vedacore.misc import registry | ||
from .base_hook import BaseHook | ||
|
||
|
||
@registry.register_module('hook') | ||
class DistSamplerSeedHook(BaseHook): | ||
"""Data-loading sampler for distributed training. | ||
When distributed training, it is only useful in conjunction with | ||
:obj:`EpochBasedRunner`, while :obj:`IterBasedRunner` achieves the same | ||
purpose with :obj:`IterLoader`. | ||
""" | ||
|
||
def before_train_epoch(self, looper): | ||
if hasattr(looper.train_dataloader.sampler, 'set_epoch'): | ||
# in case the data loader uses `SequentialSampler` in Pytorch | ||
looper.train_dataloader.sampler.set_epoch(looper.epoch) | ||
elif hasattr(looper.train_dataloader.batch_sampler.sampler, 'set_epoch'): | ||
# batch sampler in pytorch warps the sampler as its attributes. | ||
looper.train_dataloader.batch_sampler.sampler.set_epoch(looper.epoch) | ||
|
||
@property | ||
def modes(self): | ||
return ['train'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from vedacore.misc import registry | ||
from .base_hook import BaseHook | ||
|
||
|
||
@registry.register_module('hook') | ||
class WorkerInitHook(BaseHook): | ||
"""Worker init for training. | ||
""" | ||
|
||
def before_train_epoch(self, looper): | ||
worker_init_fn = looper.train_dataloader.worker_init_fn | ||
if worker_init_fn is not None and hasattr(worker_init_fn, 'set_epoch'): | ||
worker_init_fn.set_epoch(looper.epoch) | ||
|
||
@property | ||
def modes(self): | ||
return ['train'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters