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

Trainer.test() does not allow to save logs #1859

Closed
Varal7 opened this issue May 17, 2020 · 6 comments
Closed

Trainer.test() does not allow to save logs #1859

Varal7 opened this issue May 17, 2020 · 6 comments
Labels
bug Something isn't working help wanted Open to be worked on

Comments

@Varal7
Copy link
Contributor

Varal7 commented May 17, 2020

🐛 Bug

When we use trainer.test() on a fresh trainer, the call to self.log_metrics(log_metrics, {}, step) fails to produce logs.

To Reproduce

Steps to reproduce the behavior:

Code sample

model = ...  
test_dl = ... 
logger = ...
trainer = pl.Trainer(
   logger=logger
)
trainer.test(model, test_dataloaders=test_dl)

Expected behavior

Metrics are logged.

@Varal7 Varal7 added bug Something isn't working help wanted Open to be worked on labels May 17, 2020
@Varal7
Copy link
Contributor Author

Varal7 commented May 17, 2020

Because of the way aggregate_metrics is implemented, logs are only produced when we are leaving the current step. Because there is only one step in testing, the logs are stored in self._metrics_to_agg = [metrics] but never logged.

@edenlightning
Copy link
Contributor

@ justusschock any ideas?

@Varal7
Copy link
Contributor Author

Varal7 commented Jun 8, 2020

Btw, I was able to log my logs by adding self.logger.log_metrics(logs) at the end of test_epoch_end but I believe this should be the default.

@edenlightning
Copy link
Contributor

@Varal7 would you be able to send a PR with the fix?

@williamFalcon
Copy link
Contributor

results = trainer.test()

results is a dict with the results

@wconnell
Copy link

if you encounter no logging on end of epoch it may be because you are using ddp, requiring explicit usage of test_step_end see the documentation here:

def test_step(self, batch, batch_idx):
    X, y = batch
    y_hat = self(X)
    return y_hat, y

def test_step_end(self, output_results):
    y_hat, y  = output_results
    loss = criterion(y_hat, y)
    self.log(loss, epoch_end=True)

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
Projects
None yet
Development

No branches or pull requests

4 participants