mirror of
https://github.com/wassname/pytorch-lightning.git
synced 2026-09-09 11:32:07 +08:00
Removed test_dataloader call in check_testing_model_configuration (#1670)
* Removed test_dataloader call * Check if test_dataloader is actually overriden * Fixed method spelling * Replaced lambdas * Replaced None with super method * Fixed testpass
This commit is contained in:
@@ -1054,7 +1054,7 @@ class Trainer(
|
||||
|
||||
has_test_step = self.is_overridden('test_step', model)
|
||||
has_test_epoch_end = self.is_overridden('test_epoch_end', model)
|
||||
gave_test_loader = hasattr(model, 'test_dataloader') and model.test_dataloader()
|
||||
gave_test_loader = self.is_overridden('test_dataloader', model)
|
||||
|
||||
if gave_test_loader and not has_test_step:
|
||||
raise MisconfigurationException('You passed in a `test_dataloader` but did not implement `test_step()`')
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import pytest
|
||||
|
||||
import tests.base.utils as tutils
|
||||
from pytorch_lightning import Trainer
|
||||
from pytorch_lightning import Trainer, LightningModule
|
||||
from pytorch_lightning.utilities.exceptions import MisconfigurationException
|
||||
from tests.base import EvalModelTemplate
|
||||
|
||||
@@ -101,7 +101,7 @@ def test_wrong_test_settigs(tmpdir):
|
||||
# ----------------
|
||||
with pytest.raises(MisconfigurationException):
|
||||
model = EvalModelTemplate(hparams)
|
||||
model.test_dataloader = lambda: None
|
||||
model.test_dataloader = LightningModule.test_dataloader
|
||||
trainer.test(model)
|
||||
|
||||
# ----------------
|
||||
@@ -109,7 +109,7 @@ def test_wrong_test_settigs(tmpdir):
|
||||
# ----------------
|
||||
with pytest.raises(MisconfigurationException):
|
||||
model = EvalModelTemplate(hparams)
|
||||
model.test_dataloader = lambda: None
|
||||
model.test_dataloader = LightningModule.test_dataloader
|
||||
model.test_step = None
|
||||
trainer.test(model, test_dataloaders=model.dataloader(train=False))
|
||||
|
||||
@@ -118,6 +118,6 @@ def test_wrong_test_settigs(tmpdir):
|
||||
# ----------------
|
||||
with pytest.warns(RuntimeWarning):
|
||||
model = EvalModelTemplate(hparams)
|
||||
model.test_dataloader = lambda: None
|
||||
model.test_dataloader = LightningModule.test_dataloader
|
||||
model.test_epoch_end = None
|
||||
trainer.test(model, test_dataloaders=model.dataloader(train=False))
|
||||
|
||||
@@ -457,7 +457,7 @@ def test_testpass_overrides(tmpdir):
|
||||
# Misconfig when neither test_step or test_end is implemented
|
||||
with pytest.raises(MisconfigurationException, match='.*not implement `test_dataloader`.*'):
|
||||
model = EvalModelTemplate(hparams)
|
||||
model.test_dataloader = model.test_dataloader__empty
|
||||
model.test_dataloader = LightningModule.test_dataloader
|
||||
Trainer().test(model)
|
||||
|
||||
# Misconfig when neither test_step or test_end is implemented
|
||||
|
||||
Reference in New Issue
Block a user