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 should run the test loop with the best weights when ModelCheckpoint is used #2046

Closed
yukw777 opened this issue Jun 1, 2020 · 9 comments · Fixed by #2190
Closed
Labels
feature Is an improvement or enhancement help wanted Open to be worked on
Milestone

Comments

@yukw777
Copy link
Contributor

yukw777 commented Jun 1, 2020

🚀 Feature

Motivation

I noticed that even when ModelCheckpoint is used, Trainer by default runs the test loop with the last weights, not the best weights saved by ModelCheckpoint. I believe the sensible default here is to run the test loop with the best weights saved by ModelCheckpoint.

Pitch

Now that ModelCheckpoint has a pointer to the best weights, Trainer can replace the last weights with the best weights before running the test loop automatically.

Alternatives

Possibly, this could be another option to Trainer. I don't like this as much b/c this is the behavior most users would expect.

Additional context

@yukw777 yukw777 added feature Is an improvement or enhancement help wanted Open to be worked on labels Jun 1, 2020
@awaelchli
Copy link
Member

awaelchli commented Jun 2, 2020

Something like this?
trainer.test(model, load_best_checkpoint=True)

@Borda
Copy link
Member

Borda commented Jun 2, 2020

I would make the load_best_checkpoint=True as default...

@Borda Borda added this to the 0.9.0 milestone Jun 2, 2020
@yukw777
Copy link
Contributor Author

yukw777 commented Jun 2, 2020

Yeah this should definitely be the default behavior.

Another question is, can we only do this when ModelCheckpoint is used since Trainer itself doesn’t keep track of the best weights? What if someone writes their own ModelCheckpoint? It seems like there needs to be a common interface that Trainer uses to retrieve the best weights for the test loop. The best weights could then be whatever the checkpoint_callback defines it to be. In this way, I don’t think we’d need to have yet another option on Trainer.

@williamFalcon
Copy link
Contributor

williamFalcon commented Jun 2, 2020

why not make it:

# default
test(..., checkpoint=‘best’)

test(..., checkpoint=PATH/CKPT)

with the option for a string ‘best’

and make this the default

@Borda
Copy link
Member

Borda commented Jun 2, 2020

why not make it:

# default
test(..., checkpoint=‘best’)

test(..., checkpoint=PATH/CKPT)

with the option for a string ‘best’

and make this the default

very good and test(..., checkpoint=None) uses the last...

@yukw777
Copy link
Contributor Author

yukw777 commented Jun 2, 2020

Nice! I like that idea. To summarize:

  • add an option to test() called checkpoint whose default value is best.
  • if it's None, use the weights from the last epoch
  • if it's another string, treat it as a path.

@williamFalcon
Copy link
Contributor

williamFalcon commented Jun 2, 2020

ummm. i prefer None to disable it.
there will 100% be cases where people need to disable that haha.

@yukw777
Copy link
Contributor Author

yukw777 commented Jun 3, 2020

ah yeah since using the last epoch weights is the current behavior, setting it to None (and using the last epoch weights) would effectively disable it. Let me know if my understanding is incorrect.

@williamFalcon
Copy link
Contributor

current behavior is equivalent to None

new default behavior should be “best”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is an improvement or enhancement help wanted Open to be worked on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants