Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Where is EarlyStopping searching for metrics? #670

Closed
felixkreuk opened this issue Jan 8, 2020 · 8 comments
Closed

Where is EarlyStopping searching for metrics? #670

felixkreuk opened this issue Jan 8, 2020 · 8 comments
Labels
question Further information is requested

Comments

@felixkreuk
Copy link

felixkreuk commented Jan 8, 2020

Where is EarlyStopping search for metrics?

Code

    def validation_end(self, outputs):
        ...
        metrics = {
        'val_acc': val_acc,
        'val_loss': val_loss
        }
        ...
        output = OrderedDict({
            'val_acc':  torch.tensor(metrics['val_acc']),
            'val_loss': torch.tensor(metrics['val_loss']),
            'progress_bar': metrics,
            'log': metrics
        })
        return output

if I attempt to early stop according to val_acc I get the following error:

RuntimeWarning: Early stopping conditioned on metric 'val_acc' which is not available. Available metrics are: loss,train_loss

The metrics mentioned (loss,train_loss) are from training_step from what I could find.

I guess I'm doing something wrong, could anyone point me in the correct direction?

  • OS: Ubuntu
  • Packaging: pip
  • Version 0.5.3.2

Update #1: the same code works with version 0.5.1. Bug in 0.5.3?

Update #2:
I found that this line in trainer/training_loop.py:

self.callback_metrics = {k: v for d in all_callback_metrics for k, v in d.items()}

From what I see, before this line is executed, self.callback_metrics contains val_acc. After this line values that were put in callback_metrics after validation are gone, therefore EarlyStopping can't find them. Can anyone confirm this is an issue?

@felixkreuk felixkreuk added the question Further information is requested label Jan 8, 2020
@felixkreuk felixkreuk changed the title Where is EarlyStopping searching for metrics? #question Where is EarlyStopping searching for metrics? Jan 8, 2020
@kuynzereb
Copy link
Contributor

If I understand correctly it is a known issue. Please look at #490. #492 fixes this in master.

@felixkreuk
Copy link
Author

Hi @kuynzereb, thanks! this was indeed the issue.
Kind of an embarrassing question, what is the best way to get these fixes from master?
Install like so?

pip install git+https://github.com/williamFalcon/pytorch-lightning.git@master --upgrade

@kuynzereb
Copy link
Contributor

Well, I don't really know either, but it looks like you are right :)

@williamFalcon
Copy link
Contributor

pip install git+https://github.com/williamFalcon/pytorch-lightning.git@master --upgrade

@Borda
Copy link
Member

Borda commented Jan 14, 2020

pip install https://github.com/PyTorchLightning/pytorch-lightning/archive/master.zip -U

@ajoino
Copy link

ajoino commented Jan 20, 2020

I tried installing with both William's and Borda's methods but I still get an error that it can't find the val_loss metric. My validation_step is defined as

def validation_step(self, batch, batch_np):
    x, y = batch
    y_hat, _ = self.forward(x)

    return {'val_loss': loss(y_hat, y)}

and as I understand that should be enough. Any ideas what might be wrong?

@kuynzereb
Copy link
Contributor

You should also define validation_end(), not only validation_step().

@ajoino
Copy link

ajoino commented Jan 20, 2020

That worked, thank you!

I must say that from the documentation it is not clear to me that it is necessary to define validation_end() as well

The outputs here are strictly for the progress bar. If you don't need to display anything, don't return anything.

As for as I know I am not doing anything progress-bar related and I should not have to define validation end. What is it that I have misunderstood?

@Lightning-AI Lightning-AI locked and limited conversation to collaborators Feb 4, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants