Pytorch-lightning: Question about `trainer.test()`

Created on 20 Jun 2020  Â·  4Comments  Â·  Source: PyTorchLightning/pytorch-lightning

Hi!

A noob question and maybe I am missing something. Why does it call fit() again when a model is loaded from checkpoint?

https://github.com/PyTorchLightning/pytorch-lightning/blob/c7f8367650d1dd1a497586153c607ff6479367c7/pytorch_lightning/trainer/trainer.py#L1177-L1179

Thanks!

enhancement question

Most helpful comment

Fit function handles both training and testing. self.testing is set to True in .test().
https://github.com/PyTorchLightning/pytorch-lightning/blob/f972ab3a828eae1847a793da0b2c25c6074647a4/pytorch_lightning/trainer/trainer.py#L1169

and if self.testing == True, it will test only.
https://github.com/PyTorchLightning/pytorch-lightning/blob/f972ab3a828eae1847a793da0b2c25c6074647a4/pytorch_lightning/trainer/trainer.py#L1052-L1056

Training is done with self.train()
https://github.com/PyTorchLightning/pytorch-lightning/blob/f972ab3a828eae1847a793da0b2c25c6074647a4/pytorch_lightning/trainer/trainer.py#L1092-L1093

I still think .fit() should be renamed to something else that can be easy to interpret if someone is new to lightning.

All 4 comments

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

Fit function handles both training and testing. self.testing is set to True in .test().
https://github.com/PyTorchLightning/pytorch-lightning/blob/f972ab3a828eae1847a793da0b2c25c6074647a4/pytorch_lightning/trainer/trainer.py#L1169

and if self.testing == True, it will test only.
https://github.com/PyTorchLightning/pytorch-lightning/blob/f972ab3a828eae1847a793da0b2c25c6074647a4/pytorch_lightning/trainer/trainer.py#L1052-L1056

Training is done with self.train()
https://github.com/PyTorchLightning/pytorch-lightning/blob/f972ab3a828eae1847a793da0b2c25c6074647a4/pytorch_lightning/trainer/trainer.py#L1092-L1093

I still think .fit() should be renamed to something else that can be easy to interpret if someone is new to lightning.

@rohitgr7 A PR for this was proposed here: #2107. Eventually it will be done out of necessity ;)

I am getting an error from MlFlowLogger, because self.logger.log_hyperparams(ref_model.hparams) stays before self.run_evaluation(test_mode=True). Consequently, mlflow throws an error due to logging hyperparams twice

Was this page helpful?
0 / 5 - 0 ratings

Related issues

williamFalcon picture williamFalcon  Â·  3Comments

monney picture monney  Â·  3Comments

as754770178 picture as754770178  Â·  3Comments

polars05 picture polars05  Â·  3Comments

versatran01 picture versatran01  Â·  3Comments