-
Notifications
You must be signed in to change notification settings - Fork 24
fix: make a seed respect to distributed settings #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,12 @@ | |
def run(local_rank: int, config: Any, *args: Any, **kwargs: Any): | ||
"""function to be run by idist.Parallel context manager.""" | ||
|
||
# ---------------------- | ||
# make a certain seed | ||
# ---------------------- | ||
rank = idist.get_rank() | ||
manual_seed(config.seed + rank) | ||
|
||
# ----------------------------- | ||
# datasets and dataloaders | ||
# ----------------------------- | ||
|
@@ -30,7 +36,16 @@ def run(local_rank: int, config: Any, *args: Any, **kwargs: Any): | |
# TODO : PLEASE replace `kwargs` with your desirable DataLoader arguments | ||
# See : https://pytorch.org/ignite/distributed.html#ignite.distributed.auto.auto_dataloader | ||
|
||
if rank > 0: | ||
# Ensure that only rank 0 download the dataset | ||
idist.barrier() | ||
|
||
train_dataset, eval_dataset = get_datasets(path=config.data_path) | ||
|
||
if rank == 0: | ||
# Ensure that only rank 0 download the dataset | ||
idist.barrier() | ||
|
||
train_dataloader = idist.auto_dataloader( | ||
train_dataset, | ||
batch_size=config.train_batch_size, | ||
|
@@ -110,7 +125,10 @@ def run(local_rank: int, config: Any, *args: Any, **kwargs: Any): | |
lr_scheduler=lr_scheduler, | ||
output_names=None, | ||
) | ||
logger_handler = get_logger(config=config, train_engine=train_engine, eval_engine=eval_engine, optimizers=optimizer) | ||
|
||
# setup ignite logger only on rank 0 | ||
if rank == 0: | ||
logger_handler = get_logger(config=config, train_engine=train_engine, eval_engine=eval_engine, optimizers=optimizer) | ||
|
||
# ----------------------------------- | ||
# resume from the saved checkpoints | ||
|
@@ -183,12 +201,13 @@ def _(): | |
# close the logger after the training completed / terminated | ||
# ------------------------------------------------------------ | ||
|
||
if isinstance(logger_handler, WandBLogger): | ||
# why handle differently for wandb ? | ||
# See : https://github.com/pytorch/ignite/issues/1894 | ||
logger_handler.finish() | ||
elif logger_handler: | ||
logger_handler.close() | ||
if rank == 0: | ||
if isinstance(logger_handler, WandBLogger): | ||
# why handle differently for wandb ? | ||
# See : https://github.com/pytorch/ignite/issues/1894 | ||
logger_handler.finish() | ||
elif logger_handler: | ||
logger_handler.close() | ||
Comment on lines
+204
to
+210
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, we can say that the code generator aims ignite nightly version and it will be also in the stable version ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are currently testing with ignite v0.4.4, we will update that once there is a new release |
||
|
||
# ----------------------------------------- | ||
# where is my best and last checkpoint ? | ||
|
@@ -200,7 +219,6 @@ def _(): | |
def main(): | ||
parser = ArgumentParser(parents=[get_default_parser()]) | ||
config = parser.parse_args() | ||
manual_seed(config.seed) | ||
|
||
if config.output_dir: | ||
now = datetime.now().strftime("%Y%m%d-%H%M%S") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for delay with the review @ydcjeff . Maybe we could hide these barriers inside
get_datasets
. I also realized that here it should belocal_rank == 0
and notrank == 0
as in case multi-node case the application wont download the data for other nodes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK! Then Ignite examples need a fix too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, that can be possible. Thanks for pointing out! Can you please open an issue and someone could fix it.