Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatible Trainer.test() #1720

Closed
isvoboda opened this issue May 3, 2020 · 9 comments · Fixed by #1804
Closed

Incompatible Trainer.test() #1720

isvoboda opened this issue May 3, 2020 · 9 comments · Fixed by #1804
Labels
bug Something isn't working help wanted Open to be worked on priority: 0 High priority task
Milestone

Comments

@isvoboda
Copy link

isvoboda commented May 3, 2020

🐛 Bug

Trainer.test() stops on missing definitions of train & validation dataloaders methods.

To Reproduce

Steps to reproduce the behavior:

  • Define LightningModule without train & validation dataloaders
  • Train such model with data loaders provided to Trainer.fit(...) method
  • Load model from checkpoint and test it with Trainer.test(...) method

test failes on :

'No `train_dataloader()` method defined. Lightning `Trainer` expects as minimum a'
pytorch_lightning.utilities.exceptions.MisconfigurationException: No `train_dataloader()` method defined. Lightning `Trainer` expects as minimum a `training_step()`, `training_dataloader()` and `configure_optimizers()` to be defined.

Code sample

test_data = data_loader(...)
estimator = MyEstimator.load_from_checkpoint(checkpoint_path=CKPT_PATH)
trainer = pl.Trainer(...)
trainer.test(model=estimator, test_dataloaders=test_data)

Expected behaviour

Run the test with provided test data loader, and do not stop on condition related to missing train & validation dataloaders which actually are not mandatory.

Environment

* Packages:
        - numpy:             1.18.4
        - pyTorch_debug:     False
        - pyTorch_version:   1.5.0
        - pytorch-lightning: 0.7.5
        - tensorboard:       2.2.1
        - tqdm:              4.46.0
* System:
        - OS:                Linux
        - architecture:
                - 64bit
                - ELF
        - processor:         
        - python:            3.8.2
        - version:           #1 SMP Wed, 29 Apr 2020 16:23:03 +0000
@isvoboda isvoboda added bug Something isn't working help wanted Open to be worked on labels May 3, 2020
@github-actions
Copy link
Contributor

github-actions bot commented May 3, 2020

Hi! thanks for your contribution!, great first issue!

@Borda Borda added the priority: 0 High priority task label May 3, 2020
@Borda Borda added this to the 0.7.6 milestone May 3, 2020
@isvoboda
Copy link
Author

isvoboda commented May 3, 2020

This issue relates to #1195, fit and test should be decoupled. Is there any consensus or proposition of further steps?

@rohitgr7
Copy link
Contributor

rohitgr7 commented May 5, 2020

Can't we just add

if not self.testing:
    self.check_model_configuration(model)

here because during testing the testing configuraton is already checked here.

@iakremnev
Copy link

iakremnev commented May 7, 2020

Also, using trainer.test(model) on loaded checkpoint doesn't work without explicitly passing test_dataloader parameter even if all *_dataloader methods are defined. Example.
This use case isn't documented in the 0.7.5 documentation but evidently was relevant at some point: https://pytorch-lightning.readthedocs.io/en/latest/test_set.html#test-pre-trained-model.
I suggest to either:

  • fix Test set documentation
  • (preferred) allow to call trainer.test(model) without specifying test_dataloader parameter. After all, what's the point of defining Model.test_dataloader method?

@rohitgr7
Copy link
Contributor

rohitgr7 commented May 7, 2020

@iakremnev can you fix the link? It's asking for request access.

@iakremnev
Copy link

@rohitgr7 oops, fixed it.

@rohitgr7
Copy link
Contributor

rohitgr7 commented May 7, 2020

Error coming from this line. Why is it checking whether test_dataloader() returns something or not. If we just check whether it is overridden or not wouldn't that be enough just like it is done in case of .fit() here.

@rohitgr7
Copy link
Contributor

rohitgr7 commented May 7, 2020

I would suggest

gave_test_loader = isinstance(model.test_dataloader, _PatchDataLoader) or self.is_overridden('test_dataloader', model)

here, and

if not self.testing:
    self.check_model_configuration(model)

here

@Borda
Copy link
Member

Borda commented May 11, 2020

it is the same as #1754

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Open to be worked on priority: 0 High priority task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants