From 0a475af8a76ecb82c87326ad52a1a46bc8df0902 Mon Sep 17 00:00:00 2001 From: Carlos Mocholi Date: Sat, 28 Aug 2021 05:20:25 +0200 Subject: [PATCH] Deduplicate tests --- .azure-pipelines/gpu-tests.yml | 2 ++ pl_examples/test_examples.py | 51 +++------------------------------- 2 files changed, 6 insertions(+), 47 deletions(-) diff --git a/.azure-pipelines/gpu-tests.yml b/.azure-pipelines/gpu-tests.yml index 46f631ab1d886e..f009ea1b9bb0bd 100644 --- a/.azure-pipelines/gpu-tests.yml +++ b/.azure-pipelines/gpu-tests.yml @@ -108,6 +108,8 @@ jobs: bash pl_examples/run_examples.sh --trainer.gpus=1 bash pl_examples/run_examples.sh --trainer.gpus=2 --trainer.accelerator=ddp bash pl_examples/run_examples.sh --trainer.gpus=2 --trainer.accelerator=ddp --trainer.precision=16 + bash pl_examples/run_examples.sh --trainer.gpus=2 --trainer.accelerator=dp + bash pl_examples/run_examples.sh --trainer.gpus=2 --trainer.accelerator=dp --trainer.precision=16 env: PL_USE_MOCKED_MNIST: "1" displayName: 'Testing: examples' diff --git a/pl_examples/test_examples.py b/pl_examples/test_examples.py index d9960a811fc45d..051d02cd109b00 100644 --- a/pl_examples/test_examples.py +++ b/pl_examples/test_examples.py @@ -11,70 +11,27 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. - -import importlib -import platform from unittest import mock import pytest -import torch from pl_examples import _DALI_AVAILABLE +from tests.helpers.runif import RunIf ARGS_DEFAULT = ( "--trainer.default_root_dir %(tmpdir)s " "--trainer.max_epochs 1 " "--trainer.limit_train_batches 2 " "--trainer.limit_val_batches 2 " + "--trainer.limit_test_batches 2 " + "--trainer.limit_predict_batch4es 2 " "--data.batch_size 32 " ) ARGS_GPU = ARGS_DEFAULT + "--trainer.gpus 1 " -ARGS_DP = ARGS_DEFAULT + "--trainer.gpus 2 --trainer.accelerator dp " -ARGS_AMP = "--trainer.precision 16 " - - -@pytest.mark.parametrize( - "import_cli", - [ - "pl_examples.basic_examples.simple_image_classifier", - "pl_examples.basic_examples.backbone_image_classifier", - "pl_examples.basic_examples.autoencoder", - ], -) -@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine") -@pytest.mark.parametrize("cli_args", [ARGS_DP, ARGS_DP + ARGS_AMP]) -def test_examples_dp(tmpdir, import_cli, cli_args): - - module = importlib.import_module(import_cli) - # update the temp dir - cli_args = cli_args % {"tmpdir": tmpdir} - - with mock.patch("argparse._sys.argv", ["any.py"] + cli_args.strip().split()): - module.cli_main() - - -@pytest.mark.parametrize( - "import_cli", - [ - "pl_examples.basic_examples.simple_image_classifier", - "pl_examples.basic_examples.backbone_image_classifier", - "pl_examples.basic_examples.autoencoder", - ], -) -@pytest.mark.parametrize("cli_args", [ARGS_DEFAULT]) -def test_examples_cpu(tmpdir, import_cli, cli_args): - - module = importlib.import_module(import_cli) - # update the temp dir - cli_args = cli_args % {"tmpdir": tmpdir} - - with mock.patch("argparse._sys.argv", ["any.py"] + cli_args.strip().split()): - module.cli_main() @pytest.mark.skipif(not _DALI_AVAILABLE, reason="Nvidia DALI required") -@pytest.mark.skipif(not torch.cuda.is_available(), reason="test requires GPU machine") -@pytest.mark.skipif(platform.system() != "Linux", reason="Only applies to Linux platform.") +@RunIf(min_gpus=1, skip_windows=True) @pytest.mark.parametrize("cli_args", [ARGS_GPU]) def test_examples_mnist_dali(tmpdir, cli_args): from pl_examples.basic_examples.dali_image_classifier import cli_main