enable testing DDP examples (#4995)

* enable testing DDP examples

* args

* ddp_spawn

* ddp as extra script

* path

# Conflicts:
#	.drone.yml

* install

* -u

* q
This commit is contained in:
Jirka Borovec 2021-02-15 16:36:13 +01:00 committed by GitHub
parent b2950296d5
commit ba806c8ee0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 30 deletions

View File

@ -88,3 +88,9 @@ jobs:
- script: | - script: |
python -m pytest benchmarks pl_examples -v --maxfail=2 --durations=0 python -m pytest benchmarks pl_examples -v --maxfail=2 --durations=0
displayName: 'Testing: extended' displayName: 'Testing: extended'
- script: |
python setup.py install --user --quiet
bash pl_examples/run_ddp-example.sh
pip uninstall -y pytorch-lightning
displayName: 'Examples'

View File

@ -0,0 +1,12 @@
#!/bin/bash
ARGS_DEFAULT=" --default_root_dir %(tmpdir)s --max_epochs 1 --batch_size 32 --limit_train_batches 2 --limit_val_batches 2"
ARGS_EXTRA_DDP=" --gpus 2 --accelerator ddp"
ARGS_EXTRA_AMP=" --precision 16"
python pl_examples/basic_examples/simple_image_classifier.py ${ARGS_DEFAULT} ${ARGS_EXTRA_DDP}
python pl_examples/basic_examples/simple_image_classifier.py ${ARGS_DEFAULT} ${ARGS_EXTRA_DDP} ${ARGS_EXTRA_AMP}
python pl_examples/basic_examples/backbone_image_classifier.py ${ARGS_DEFAULT} ${ARGS_EXTRA_DDP}
python pl_examples/basic_examples/backbone_image_classifier.py ${ARGS_DEFAULT} ${ARGS_EXTRA_DDP} ${ARGS_EXTRA_AMP}
python pl_examples/basic_examples/autoencoder.py ${ARGS_DEFAULT} ${ARGS_EXTRA_DDP}
python pl_examples/basic_examples/autoencoder.py ${ARGS_DEFAULT} ${ARGS_EXTRA_DDP} ${ARGS_EXTRA_AMP}

View File

@ -38,17 +38,7 @@ ARGS_DP = ARGS_DEFAULT + """
--accelerator dp \ --accelerator dp \
""" """
ARGS_DP_AMP = ARGS_DP + """ ARGS_AMP = """
--precision 16 \
"""
ARGS_DDP = ARGS_DEFAULT + """
--gpus 2 \
--accelerator ddp \
--precision 16 \
"""
ARGS_DDP_AMP = ARGS_DEFAULT + """
--precision 16 \ --precision 16 \
""" """
@ -61,7 +51,7 @@ ARGS_DDP_AMP = ARGS_DEFAULT + """
] ]
) )
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine") @pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine")
@pytest.mark.parametrize('cli_args', [ARGS_DP, ARGS_DP_AMP]) @pytest.mark.parametrize('cli_args', [ARGS_DP, ARGS_DP + ARGS_AMP])
def test_examples_dp(tmpdir, import_cli, cli_args): def test_examples_dp(tmpdir, import_cli, cli_args):
module = importlib.import_module(import_cli) module = importlib.import_module(import_cli)
@ -72,24 +62,6 @@ def test_examples_dp(tmpdir, import_cli, cli_args):
module.cli_main() module.cli_main()
# ToDo: fix this failing example
# @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_DDP, ARGS_DDP_AMP])
# def test_examples_ddp(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( @pytest.mark.parametrize(
'import_cli', [ 'import_cli', [
'pl_examples.basic_examples.simple_image_classifier', 'pl_examples.basic_examples.simple_image_classifier',