2020-03-06 17:00:05 +00:00
|
|
|
"""Test deprecated functionality which will be removed in vX.Y.Z"""
|
2020-06-17 17:42:28 +00:00
|
|
|
import random
|
2020-04-23 21:34:47 +00:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import pytest
|
2020-06-16 03:06:17 +00:00
|
|
|
import torch
|
2020-03-06 17:00:05 +00:00
|
|
|
|
|
|
|
from pytorch_lightning import Trainer
|
2020-09-04 10:02:16 +00:00
|
|
|
from pytorch_lightning.callbacks import GpuUsageLogger, LearningRateLogger
|
2020-05-10 17:15:28 +00:00
|
|
|
from tests.base import EvalModelTemplate
|
2020-03-06 17:00:05 +00:00
|
|
|
|
2020-03-20 19:51:14 +00:00
|
|
|
|
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-09-03 18:17:15 +00:00
|
|
|
def test_tbd_remove_in_v0_11_0_trainer():
|
|
|
|
with pytest.deprecated_call(match='will be removed in v0.11.0'):
|
|
|
|
lr_logger = LearningRateLogger()
|
|
|
|
|
|
|
|
|
2020-09-04 10:02:16 +00:00
|
|
|
@pytest.mark.skipif(not torch.cuda.is_available(), reason="test requires GPU machine")
|
|
|
|
def test_tbd_remove_in_v0_11_0_trainer_gpu():
|
|
|
|
with pytest.deprecated_call(match='will be removed in v0.11.0'):
|
|
|
|
gpu_usage = GpuUsageLogger()
|
|
|
|
|
|
|
|
|
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-03-20 19:51:14 +00:00
|
|
|
|
2020-07-30 21:19:28 +00:00
|
|
|
|
2020-07-22 17:53:10 +00:00
|
|
|
# def test_tbd_remove_in_v1_0_0_model_hooks():
|
|
|
|
#
|
|
|
|
# model = ModelVer0_6()
|
|
|
|
#
|
|
|
|
# with pytest.deprecated_call(match='will be removed in v1.0. Use `test_epoch_end` instead'):
|
|
|
|
# trainer = Trainer(logger=False)
|
|
|
|
# trainer.test(model)
|
2020-09-07 13:31:42 +00:00
|
|
|
# assert trainer.logger_connector.callback_metrics == {'test_loss': torch.tensor(0.6)}
|
2020-07-22 17:53:10 +00:00
|
|
|
#
|
|
|
|
# with pytest.deprecated_call(match='will be removed in v1.0. Use `validation_epoch_end` instead'):
|
|
|
|
# trainer = Trainer(logger=False)
|
|
|
|
# # TODO: why `dataloder` is required if it is not used
|
|
|
|
# result = trainer._evaluate(model, dataloaders=[[None]], max_batches=1)
|
|
|
|
# assert result[0] == {'val_loss': torch.tensor(0.6)}
|
|
|
|
#
|
|
|
|
# model = ModelVer0_7()
|
|
|
|
#
|
|
|
|
# with pytest.deprecated_call(match='will be removed in v1.0. Use `test_epoch_end` instead'):
|
|
|
|
# trainer = Trainer(logger=False)
|
|
|
|
# trainer.test(model)
|
2020-09-07 13:31:42 +00:00
|
|
|
# assert trainer.logger_connector.callback_metrics == {'test_loss': torch.tensor(0.7)}
|
2020-07-22 17:53:10 +00:00
|
|
|
#
|
|
|
|
# with pytest.deprecated_call(match='will be removed in v1.0. Use `validation_epoch_end` instead'):
|
|
|
|
# trainer = Trainer(logger=False)
|
|
|
|
# # TODO: why `dataloder` is required if it is not used
|
|
|
|
# result = trainer._evaluate(model, dataloaders=[[None]], max_batches=1)
|
|
|
|
# assert result[0] == {'val_loss': torch.tensor(0.7)}
|