mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-11 12:31:23 +08:00
Option to provide seed to random generators to ensure reproducibility (#1572)
* Option to provide seed to random generators to ensure reproducibility I added small function in utilities which imports torch, numpy, python random and sets seed for all of the libraries to ensure reproducibility of results. * Apply recommendations from core contributors on seeding 1. Moved the seeding code to another file 2. Make deterministic as a parameter for trainer class 3. Add assertions for seeding numpy 4. Added warnings 5. torch.manual_seed should be enough for seeding torch * Revert "Apply recommendations from core contributors on seeding" This reverts commit a213c8e6882eec8a9e7408b9418926d2db7c5461. * Revert "Revert "Apply recommendations from core contributors on seeding"" This reverts commit 59b2da53c62878de7aab0aa3feb3115e105eea06. * Change in test, for correct seeding * Allow seed equal to 0 * Allow seed to be uint32.max * Added deterministic to benchmarks * Cuda manual seed as in benchmark seeding * Seeding should be done before model initialization * cuda manual_seed is not necessary * Fixing seed test_cpu_lbfgs On some seeds seems like lbfgs doesn't converge. So I fixed the seed during testing. * rebasing issue with old reproducibility.py * Improved documentation and ability to seed before initializing Train class * Change in docs * Removed seed from trainer, update for documentation * Typo in the docs * Added seed_everything to _all_ * Fixing old changes * Model initialization should be earlier then Trainer * Update pytorch_lightning/trainer/__init__.py From Example to testcode Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> * Fixing according to the contributors suggestions * Moving horovod deterministic to Trainer class * deterministic flag affects horovod docs update * Improved static typing * Added deterministic to test runners of horovod It is failing on some versions, not very predictable * static seeds for horovod tests * Change for reset_seed function in tests * Seeding horovod using reset_seed from tutils * Update pytorch_lightning/trainer/__init__.py * chlog * Update trainer.py * change "testcode" to "Example" in trainer init documentation * Update pytorch_lightning/trainer/seed.py, first line in comment Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> Co-authored-by: Jirka <jirka.borovec@seznam.cz> Co-authored-by: William Falcon <waf2107@columbia.edu>
This commit is contained in:
co-authored by
Jirka Borovec
Jirka
William Falcon
parent
7af4505519
commit
619f984c36
@@ -39,6 +39,7 @@ def _nccl_available():
|
||||
|
||||
def _run_horovod(trainer_options, on_gpu=False):
|
||||
"""Execute the training script across multiple workers in parallel."""
|
||||
tutils.reset_seed()
|
||||
cmdline = [
|
||||
'horovodrun',
|
||||
'-np', '2',
|
||||
@@ -62,7 +63,8 @@ def test_horovod_cpu(tmpdir):
|
||||
max_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
distributed_backend='horovod'
|
||||
distributed_backend='horovod',
|
||||
deterministic=True,
|
||||
)
|
||||
_run_horovod(trainer_options)
|
||||
|
||||
@@ -78,6 +80,7 @@ def test_horovod_cpu_implicit(tmpdir):
|
||||
max_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
deterministic=True,
|
||||
)
|
||||
_run_horovod(trainer_options)
|
||||
|
||||
@@ -96,6 +99,7 @@ def test_horovod_multi_gpu(tmpdir):
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
gpus=1,
|
||||
deterministic=True,
|
||||
distributed_backend='horovod'
|
||||
)
|
||||
_run_horovod(trainer_options, on_gpu=True)
|
||||
@@ -130,6 +134,7 @@ def test_horovod_transfer_batch_to_gpu(tmpdir):
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
gpus=1,
|
||||
deterministic=True,
|
||||
distributed_backend='horovod'
|
||||
)
|
||||
tutils.run_model_test_without_loggers(trainer_options, model)
|
||||
@@ -147,6 +152,7 @@ def test_horovod_multi_optimizer(tmpdir):
|
||||
max_epochs=1,
|
||||
train_percent_check=0.4,
|
||||
val_percent_check=0.2,
|
||||
deterministic=True,
|
||||
distributed_backend='horovod'
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user