-
Notifications
You must be signed in to change notification settings - Fork 120
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
Custom early stop callback #377
Comments
Hey there @Kaltxi, can you also provide the code that you are using to run the optimization? If it's a complete example that we can compile and run, it's way easier to debug. Thanks! |
@rcurtin Hello! Here is a minimal example that minimizes a trivial function with a slow down in its |
It looks like you never pass the callback to the Optimize function:
should be something like: OptimizationEarlyStop early_stop;
const double minimum = optimizer.Optimize(f, coefs, ens::Report{}, early_stop); |
@zoq Yeah, thats a typo, fixing it yields the same behavior. In any case the |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions! 👍 |
let's keep this open |
Hello @Kaltxi, Please do correct me if I overlooked something. |
I spent a little time digging into the situation and I think there is some confusion here. In fact, one example demonstrates the whole situation pretty clearly: https://www.ensmallen.org/docs.html#early-stopping-at-minimum-loss Here, we have a custom callback example that returns Throughout the codebase, sometimes we call callbacks and check their return value and terminate if it is true. Other times (DE is one of these cases), we don't. With a quick, trivial, and somewhat wrong grep I see 103 uses where we don't use the return value and 83 where we do. I believe our original intention was to always check the callback result; see Section 3.2 of the technical report: So, I think what's happened here is just that the code has gotten out of sync with our original intentions. I think the solution here is to do a couple of things:
I'm happy to do this, although I may skip the extra credit 😄 if someone else wants to jump in and do it feel free---it'll be a little while until I get to it. @Kaltxi I think @SuvarshaChennareddy has provided a usable workaround, but if you want to get your hands directly dirty, you can modify the |
@rcurtin Rather than having an option, I recommend this to be mandatory. Otherwise inside ensmallen we'd need to explicitly handle two cases (one with void returned, and one with bool returned). This unnecessarily complicates the codebase, which in turn leads to higher maintenance burden, increased risk of bugs, etc, all of which are time wasters. The mandatory requirement is a good way to enforce not paying the opportunity costs in terms of time. For example, having it mandatory will prevent problems like this issue from occurring again (eg. when someone implements a new optimiser). The mandatory bool return is not an onerous requirement for user code. If the user doesn't want to take advantage of the functionality, their callback function can simply return false in all cases. |
I agree with @conradsnicta happy to open a PR with the changes. |
I've also encountered this issue (with another callback method). After looking through the code, I found out that the reason is that the return type of bool form of several callback methods is mistakenly specified as void (likely a copy-paste error). PR #382 should fix this. When the code check if a bool form
|
With #382, #383, and #384 merged, the example here should work, so I'll go ahead and close the issue. @DiscreteLogarithm and @Kaltxi please feel free to reopen or open a new issue if anything is still wrong. Thanks for the report! |
Issue description
I am trying to make a custom callback to be able to stop optimization asynchronously. Documentation says that the callback should return true to end the process, so I made the following callback:
That said the callback doesn't seem to run. If I make the
Evaluate
returnvoid
the callback runs, but I can't returnbool
in this case.Your environment
Steps to reproduce
Defining the
Evaluate()
callback withbool
return type makes callback unable to be run.Expected behavior
I expect to be able to define
bool Evaluate()
and be able to stop optimization with it.The text was updated successfully, but these errors were encountered: