clear skipping tests (#1285)

* clear skipping tests

* fix simple/multi GPU

* review: simplify
This commit is contained in:
Jirka Borovec
2020-03-30 18:29:23 -04:00
committed by GitHub
parent 31a658e558
commit 2ca5356429
5 changed files with 15 additions and 49 deletions
-12
View File
@@ -210,18 +210,6 @@ def assert_ok_model_acc(trainer, key='test_acc', thr=0.4):
assert acc > thr, f"Model failed to get expected {thr} accuracy. {key} = {acc}"
def can_run_gpu_test():
if not torch.cuda.is_available():
warnings.warn('test_multi_gpu_model_ddp cannot run.'
' Rerun on a GPU node to run this test')
return False
if not torch.cuda.device_count() > 1:
warnings.warn('test_multi_gpu_model_ddp cannot run.'
' Rerun on a node with 2+ GPUs to run this test')
return False
return True
def reset_seed():
seed = RANDOM_SEEDS.pop()
torch.manual_seed(seed)
+6 -15
View File
@@ -1,6 +1,7 @@
import os
import pytest
import torch
import tests.base.utils as tutils
from pytorch_lightning import Trainer
@@ -10,13 +11,11 @@ from tests.base import (
)
@pytest.mark.skipif(not torch.cuda.is_available(), reason="test requires GPU machine")
def test_amp_single_gpu(tmpdir):
"""Make sure DDP + AMP work."""
tutils.reset_seed()
if not tutils.can_run_gpu_test():
return
hparams = tutils.get_default_hparams()
model = LightningTestModel(hparams)
@@ -33,13 +32,11 @@ def test_amp_single_gpu(tmpdir):
@pytest.mark.spawn
@pytest.mark.skipif(not torch.cuda.is_available(), reason="test requires GPU machine")
def test_no_amp_single_gpu(tmpdir):
"""Make sure DDP + AMP work."""
tutils.reset_seed()
if not tutils.can_run_gpu_test():
return
hparams = tutils.get_default_hparams()
model = LightningTestModel(hparams)
@@ -58,11 +55,9 @@ def test_no_amp_single_gpu(tmpdir):
assert result == 1
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
def test_amp_gpu_ddp(tmpdir):
"""Make sure DDP + AMP work."""
if not tutils.can_run_gpu_test():
return
tutils.reset_seed()
tutils.set_random_master_port()
@@ -82,11 +77,9 @@ def test_amp_gpu_ddp(tmpdir):
@pytest.mark.spawn
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
def test_amp_gpu_ddp_slurm_managed(tmpdir):
"""Make sure DDP + AMP work."""
if not tutils.can_run_gpu_test():
return
tutils.reset_seed()
# simulate setting slurm flags
@@ -150,13 +143,11 @@ def test_cpu_model_with_amp(tmpdir):
@pytest.mark.spawn
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
def test_amp_gpu_dp(tmpdir):
"""Make sure DP + AMP work."""
tutils.reset_seed()
if not tutils.can_run_gpu_test():
return
model, hparams = tutils.get_default_model()
trainer_options = dict(
default_save_path=tmpdir,
+1 -3
View File
@@ -206,12 +206,10 @@ def test_disabled_validation():
assert model.validation_end_invoked, 'did not run `validation_end` with `fast_dev_run=True`'
@pytest.mark.skipif(not torch.cuda.is_available(), reason="test requires GPU machine")
def test_single_gpu_batch_parse():
tutils.reset_seed()
if not tutils.can_run_gpu_test():
return
trainer = Trainer()
# batch is just a tensor
+5 -12
View File
@@ -17,10 +17,9 @@ from tests.base import LightningTestModel
PRETEND_N_OF_GPUS = 16
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
def test_multi_gpu_model_ddp2(tmpdir):
"""Make sure DDP2 works."""
if not tutils.can_run_gpu_test():
return
tutils.reset_seed()
tutils.set_random_master_port()
@@ -40,10 +39,9 @@ def test_multi_gpu_model_ddp2(tmpdir):
tutils.run_model_test(trainer_options, model)
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
def test_multi_gpu_model_ddp(tmpdir):
"""Make sure DDP works."""
if not tutils.can_run_gpu_test():
return
tutils.reset_seed()
tutils.set_random_master_port()
@@ -62,10 +60,9 @@ def test_multi_gpu_model_ddp(tmpdir):
tutils.run_model_test(trainer_options, model)
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
def test_ddp_all_dataloaders_passed_to_fit(tmpdir):
"""Make sure DDP works with dataloaders passed to fit()"""
if not tutils.can_run_gpu_test():
return
tutils.reset_seed()
tutils.set_random_master_port()
@@ -195,13 +192,11 @@ def test_cpu_slurm_save_load(tmpdir):
trainer.fit(model)
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
def test_multi_gpu_none_backend(tmpdir):
"""Make sure when using multiple GPUs the user can't use `distributed_backend = None`."""
tutils.reset_seed()
if not tutils.can_run_gpu_test():
return
model, hparams = tutils.get_default_model()
trainer_options = dict(
default_save_path=tmpdir,
@@ -216,13 +211,11 @@ def test_multi_gpu_none_backend(tmpdir):
tutils.run_model_test(trainer_options, model)
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
def test_multi_gpu_model_dp(tmpdir):
"""Make sure DP works."""
tutils.reset_seed()
if not tutils.can_run_gpu_test():
return
model, hparams = tutils.get_default_model()
trainer_options = dict(
default_save_path=tmpdir,
+3 -7
View File
@@ -16,10 +16,9 @@ from tests.base import (
)
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
def test_running_test_pretrained_model_ddp(tmpdir):
"""Verify `test()` on pretrained model."""
if not tutils.can_run_gpu_test():
return
tutils.reset_seed()
tutils.set_random_master_port()
@@ -151,13 +150,11 @@ def test_load_model_from_checkpoint(tmpdir):
tutils.assert_ok_model_acc(new_trainer)
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
def test_running_test_pretrained_model_dp(tmpdir):
"""Verify test() on pretrained model."""
tutils.reset_seed()
if not tutils.can_run_gpu_test():
return
hparams = tutils.get_default_hparams()
model = LightningTestModel(hparams)
@@ -195,10 +192,9 @@ def test_running_test_pretrained_model_dp(tmpdir):
tutils.assert_ok_model_acc(new_trainer)
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
def test_dp_resume(tmpdir):
"""Make sure DP continues training correctly."""
if not tutils.can_run_gpu_test():
return
tutils.reset_seed()