forked from Lightning-AI/pytorch-lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from PyTorchLightning/master
update master
- Loading branch information
Showing
5 changed files
with
161 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import pytest | ||
import torch | ||
import os | ||
from tests.backends import ddp_model | ||
from tests.utilities.dist import call_training_script | ||
|
||
|
||
@pytest.mark.parametrize('cli_args', [ | ||
pytest.param('--max_epochs 1 --gpus 2 --distributed_backend ddp'), | ||
]) | ||
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine") | ||
def test_multi_gpu_model_ddp_fit_only(tmpdir, cli_args): | ||
# call the script | ||
std, err = call_training_script(ddp_model, cli_args, 'fit', tmpdir, timeout=120) | ||
|
||
# load the results of the script | ||
result_path = os.path.join(tmpdir, 'ddp.result') | ||
result = torch.load(result_path) | ||
|
||
# verify the file wrote the expected outputs | ||
assert result['status'] == 'complete' | ||
|
||
|
||
@pytest.mark.parametrize('cli_args', [ | ||
pytest.param('--max_epochs 1 --gpus 2 --distributed_backend ddp'), | ||
]) | ||
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine") | ||
def test_multi_gpu_model_ddp_test_only(tmpdir, cli_args): | ||
# call the script | ||
call_training_script(ddp_model, cli_args, 'test', tmpdir) | ||
|
||
# load the results of the script | ||
result_path = os.path.join(tmpdir, 'ddp.result') | ||
result = torch.load(result_path) | ||
|
||
# verify the file wrote the expected outputs | ||
assert result['status'] == 'complete' | ||
|
||
|
||
# @pytest.mark.parametrize('cli_args', [ | ||
# pytest.param('--max_epochs 1 --gpus 2 --distributed_backend ddp'), | ||
# ]) | ||
# @pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine") | ||
# def test_multi_gpu_model_ddp_fit_test(tmpdir, cli_args): | ||
# # call the script | ||
# call_training_script(ddp_model, cli_args, 'fit_test', tmpdir, timeout=20) | ||
# | ||
# # load the results of the script | ||
# result_path = os.path.join(tmpdir, 'ddp.result') | ||
# result = torch.load(result_path) | ||
# | ||
# # verify the file wrote the expected outputs | ||
# assert result['status'] == 'complete' | ||
# | ||
# model_outs = result['result'] | ||
# for out in model_outs: | ||
# assert out['test_acc'] > 0.90 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import pytest | ||
import torch | ||
|
||
import tests.base.develop_pipelines as tpipes | ||
import tests.base.develop_utils as tutils | ||
from tests.base import EvalModelTemplate | ||
from pytorch_lightning.core import memory | ||
from pytorch_lightning.trainer import Trainer | ||
|
||
|
||
@pytest.mark.skipif(torch.cuda.device_count() < 2, reason="test requires multi-GPU machine") | ||
def test_multi_gpu_early_stop_ddp_spawn(tmpdir): | ||
"""Make sure DDP works. with early stopping""" | ||
tutils.set_random_master_port() | ||
|
||
trainer_options = dict( | ||
default_root_dir=tmpdir, | ||
early_stop_callback=True, | ||
max_epochs=50, | ||
limit_train_batches=10, | ||
limit_val_batches=10, | ||
gpus=[0, 1], | ||
distributed_backend='ddp_spawn', | ||
) | ||
|
||
model = EvalModelTemplate() | ||
tpipes.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_spawn(tmpdir): | ||
tutils.set_random_master_port() | ||
|
||
trainer_options = dict( | ||
default_root_dir=tmpdir, | ||
max_epochs=1, | ||
limit_train_batches=10, | ||
limit_val_batches=10, | ||
gpus=[0, 1], | ||
distributed_backend='ddp_spawn', | ||
progress_bar_refresh_rate=0 | ||
) | ||
|
||
model = EvalModelTemplate() | ||
|
||
tpipes.run_model_test(trainer_options, model) | ||
|
||
# test memory helper functions | ||
memory.get_memory_profile('min_max') | ||
|
||
|
||
@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()""" | ||
tutils.set_random_master_port() | ||
|
||
model = EvalModelTemplate() | ||
fit_options = dict(train_dataloader=model.train_dataloader(), | ||
val_dataloaders=model.val_dataloader()) | ||
|
||
trainer = Trainer( | ||
default_root_dir=tmpdir, | ||
progress_bar_refresh_rate=0, | ||
max_epochs=1, | ||
limit_train_batches=0.2, | ||
limit_val_batches=0.2, | ||
gpus=[0, 1], | ||
distributed_backend='ddp_spawn' | ||
) | ||
result = trainer.fit(model, **fit_options) | ||
assert result == 1, "DDP doesn't work with dataloaders passed to fit()." |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.