From 1e0bae14da365a1c8d76c385c769ab4959e0f1a7 Mon Sep 17 00:00:00 2001 From: William Falcon Date: Wed, 24 Jul 2019 17:01:25 -0400 Subject: [PATCH] added test for no dist sampler --- tests/test_models.py | 55 +++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/tests/test_models.py b/tests/test_models.py index 6f3f933e..22e7711d 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -20,6 +20,35 @@ np.random.seed(SEED) # ------------------------------------------------------------------------ # TESTS # ------------------------------------------------------------------------ +def test_ddp_sampler_error(): + """ + Make sure DDP + AMP work + :return: + """ + if not torch.cuda.is_available(): + warnings.warn('test_amp_gpu_ddp cannot run. Rerun on a GPU node to run this test') + return + if not torch.cuda.device_count() > 1: + warnings.warn('test_amp_gpu_ddp cannot run. Rerun on a node with 2+ GPUs to run this test') + return + + os.environ['MASTER_PORT'] = str(np.random.randint(12000, 19000, 1)[0]) + + hparams = get_hparams() + model = LightningTestModel(hparams, force_remove_distributed_sampler=True) + + trainer_options = dict( + progress_bar=True, + max_nb_epochs=1, + gpus=[0, 1], + distributed_backend='ddp', + use_amp=True + ) + + with pytest.raises(MisconfigurationException): + run_gpu_model_test(trainer_options, model, hparams) + + def test_cpu_model(): """ Make sure model trains on CPU @@ -202,33 +231,7 @@ def test_amp_gpu_ddp(): run_gpu_model_test(trainer_options, model, hparams) -def test_ddp_sampler_error(): - """ - Make sure DDP + AMP work - :return: - """ - if not torch.cuda.is_available(): - warnings.warn('test_amp_gpu_ddp cannot run. Rerun on a GPU node to run this test') - return - if not torch.cuda.device_count() > 1: - warnings.warn('test_amp_gpu_ddp cannot run. Rerun on a node with 2+ GPUs to run this test') - return - os.environ['MASTER_PORT'] = str(np.random.randint(12000, 19000, 1)[0]) - - hparams = get_hparams() - model = LightningTestModel(hparams, force_remove_distributed_sampler=True) - - trainer_options = dict( - progress_bar=True, - max_nb_epochs=1, - gpus=[0, 1], - distributed_backend='ddp', - use_amp=True - ) - - with pytest.raises(MisconfigurationException): - run_gpu_model_test(trainer_options, model, hparams) # ------------------------------------------------------------------------