2020-03-06 17:00:05 +00:00
|
|
|
"""Test deprecated functionality which will be removed in vX.Y.Z"""
|
2020-10-27 10:57:16 +00:00
|
|
|
from argparse import ArgumentParser
|
2020-10-23 04:29:12 +00:00
|
|
|
import pytest
|
2020-04-23 21:34:47 +00:00
|
|
|
import sys
|
2020-10-27 10:57:16 +00:00
|
|
|
from unittest import mock
|
2020-04-23 21:34:47 +00:00
|
|
|
|
2020-06-16 03:06:17 +00:00
|
|
|
import torch
|
2020-03-06 17:00:05 +00:00
|
|
|
|
2020-05-10 17:15:28 +00:00
|
|
|
from tests.base import EvalModelTemplate
|
2020-10-25 09:26:40 +00:00
|
|
|
from pytorch_lightning.metrics.functional.classification import auc
|
2020-03-06 17:00:05 +00:00
|
|
|
|
2020-10-27 10:57:16 +00:00
|
|
|
from pytorch_lightning import Trainer
|
2020-10-23 04:29:12 +00:00
|
|
|
from pytorch_lightning.callbacks import ModelCheckpoint
|
2020-10-27 10:57:16 +00:00
|
|
|
from pytorch_lightning.profiler.profilers import PassThroughProfiler, SimpleProfiler
|
2020-10-23 04:29:12 +00:00
|
|
|
from pytorch_lightning.utilities.exceptions import MisconfigurationException
|
|
|
|
|
|
|
|
|
2020-11-02 05:18:20 +00:00
|
|
|
def test_tbd_remove_in_v1_3_0(tmpdir):
|
|
|
|
with pytest.deprecated_call(match='will no longer be supported in v1.3'):
|
2020-10-30 03:47:37 +00:00
|
|
|
callback = ModelCheckpoint()
|
|
|
|
Trainer(checkpoint_callback=callback, callbacks=[], default_root_dir=tmpdir)
|
|
|
|
|
|
|
|
|
2020-10-23 04:29:12 +00:00
|
|
|
def test_tbd_remove_in_v1_2_0():
|
|
|
|
with pytest.deprecated_call(match='will be removed in v1.2'):
|
|
|
|
checkpoint_cb = ModelCheckpoint(filepath='.')
|
|
|
|
|
|
|
|
with pytest.deprecated_call(match='will be removed in v1.2'):
|
|
|
|
checkpoint_cb = ModelCheckpoint('.')
|
|
|
|
|
|
|
|
with pytest.raises(MisconfigurationException, match='inputs which are not feasible'):
|
|
|
|
checkpoint_cb = ModelCheckpoint(filepath='.', dirpath='.')
|
|
|
|
|
2020-03-20 19:51:14 +00:00
|
|
|
|
2020-10-27 10:57:16 +00:00
|
|
|
# TODO: remove bool from Trainer.profiler param in v1.3.0, update profiler_connector.py
|
|
|
|
@pytest.mark.parametrize(['profiler', 'expected'], [
|
|
|
|
(True, SimpleProfiler),
|
|
|
|
(False, PassThroughProfiler),
|
|
|
|
])
|
|
|
|
def test_trainer_profiler_remove_in_v1_3_0(profiler, expected):
|
|
|
|
with pytest.deprecated_call(match='will be removed in v1.3'):
|
|
|
|
trainer = Trainer(profiler=profiler)
|
|
|
|
assert isinstance(trainer.profiler, expected)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
['cli_args', 'expected_parsed_arg', 'expected_profiler'],
|
|
|
|
[
|
|
|
|
('--profiler', True, SimpleProfiler),
|
|
|
|
('--profiler True', True, SimpleProfiler),
|
|
|
|
('--profiler False', False, PassThroughProfiler),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
def test_trainer_cli_profiler_remove_in_v1_3_0(cli_args, expected_parsed_arg, expected_profiler):
|
|
|
|
cli_args = cli_args.split(' ')
|
|
|
|
with mock.patch("argparse._sys.argv", ["any.py"] + cli_args):
|
|
|
|
parser = ArgumentParser(add_help=False)
|
|
|
|
parser = Trainer.add_argparse_args(parent_parser=parser)
|
|
|
|
args = Trainer.parse_argparser(parser)
|
|
|
|
|
|
|
|
assert getattr(args, "profiler") == expected_parsed_arg
|
|
|
|
trainer = Trainer.from_argparse_args(args)
|
|
|
|
assert isinstance(trainer.profiler, expected_profiler)
|
|
|
|
|
|
|
|
|
2020-04-23 21:34:47 +00:00
|
|
|
def _soft_unimport_module(str_module):
|
|
|
|
# once the module is imported e.g with parsing with pytest it lives in memory
|
|
|
|
if str_module in sys.modules:
|
|
|
|
del sys.modules[str_module]
|
2020-03-06 17:00:05 +00:00
|
|
|
|
|
|
|
|
2020-05-10 17:15:28 +00:00
|
|
|
class ModelVer0_6(EvalModelTemplate):
|
2020-03-20 19:51:14 +00:00
|
|
|
|
|
|
|
# todo: this shall not be needed while evaluate asks for dataloader explicitly
|
|
|
|
def val_dataloader(self):
|
2020-05-10 17:15:28 +00:00
|
|
|
return self.dataloader(train=False)
|
2020-03-20 19:51:14 +00:00
|
|
|
|
2020-04-02 15:53:37 +00:00
|
|
|
def validation_step(self, batch, batch_idx, *args, **kwargs):
|
2020-06-16 03:06:17 +00:00
|
|
|
return {'val_loss': torch.tensor(0.6)}
|
2020-04-02 15:53:37 +00:00
|
|
|
|
2020-03-20 19:51:14 +00:00
|
|
|
def validation_end(self, outputs):
|
2020-06-16 03:06:17 +00:00
|
|
|
return {'val_loss': torch.tensor(0.6)}
|
2020-03-20 19:51:14 +00:00
|
|
|
|
2020-04-02 15:53:37 +00:00
|
|
|
def test_dataloader(self):
|
2020-05-10 17:15:28 +00:00
|
|
|
return self.dataloader(train=False)
|
2020-04-02 15:53:37 +00:00
|
|
|
|
2020-03-20 19:51:14 +00:00
|
|
|
def test_end(self, outputs):
|
2020-06-16 03:06:17 +00:00
|
|
|
return {'test_loss': torch.tensor(0.6)}
|
2020-03-20 19:51:14 +00:00
|
|
|
|
|
|
|
|
2020-05-10 17:15:28 +00:00
|
|
|
class ModelVer0_7(EvalModelTemplate):
|
2020-03-20 19:51:14 +00:00
|
|
|
|
|
|
|
# todo: this shall not be needed while evaluate asks for dataloader explicitly
|
|
|
|
def val_dataloader(self):
|
2020-05-10 17:15:28 +00:00
|
|
|
return self.dataloader(train=False)
|
2020-03-20 19:51:14 +00:00
|
|
|
|
2020-04-02 15:53:37 +00:00
|
|
|
def validation_step(self, batch, batch_idx, *args, **kwargs):
|
2020-06-16 03:06:17 +00:00
|
|
|
return {'val_loss': torch.tensor(0.7)}
|
2020-04-02 15:53:37 +00:00
|
|
|
|
2020-03-20 19:51:14 +00:00
|
|
|
def validation_end(self, outputs):
|
2020-06-16 03:06:17 +00:00
|
|
|
return {'val_loss': torch.tensor(0.7)}
|
2020-03-20 19:51:14 +00:00
|
|
|
|
2020-04-02 15:53:37 +00:00
|
|
|
def test_dataloader(self):
|
2020-05-10 17:15:28 +00:00
|
|
|
return self.dataloader(train=False)
|
2020-04-02 15:53:37 +00:00
|
|
|
|
2020-03-20 19:51:14 +00:00
|
|
|
def test_end(self, outputs):
|
2020-06-16 03:06:17 +00:00
|
|
|
return {'test_loss': torch.tensor(0.7)}
|
2020-10-25 09:26:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_auc_reorder_remove_in_v1_1_0():
|
|
|
|
with pytest.deprecated_call(match='The `reorder` parameter to `auc` has been deprecated'):
|
|
|
|
_ = auc(torch.tensor([0, 1, 2, 3]), torch.tensor([0, 1, 2, 2]), reorder=True)
|