You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Modify the opitimization line search to not return a point with non-finite gradient #3306
There are some reports (e.g. https://discourse.mc-stan.org/t/disabling-line-search/36062) optimization returning a point that has finite log density but infinite gradient. The current line search does not check that the gradient is finite. The line search could modified so that when the gradient is non-finite the corresponding log density value is considered to be -Inf and then line search would more likely keep out of problematic areas (I did this in GPstuff software many years ago)
To add to this I have also been experiencing problems where if I start at a point close to the a mode, bfgs and lbfgs results in an error (newton is not feasible due to the dimensionality of the problem). I am using a cluster to perform inference and sometimes my take weeks to run. The cluster has a max walltime of about 5 days (which can not be changed due to capacity reasons). I hence resort to running a fixed number of iterations, saving the final iteration and starting a new job from the previous point which frequently results an error "line search could not make progress". I have been using cmdstan 2.34, have not updated to the latest version.
changed the title [-]Modify the opitimization lines earch to not return a point with non-finite gradient[/-][+]Modify the opitimization line search to not return a point with non-finite gradient[/+]on Sep 11, 2026
I'm closing this. When I opened this, I did not check the actual code. The change I proposed already exists, and it already existed when I opened the issue. ModelAdaptor returns 3 when an element of the gradient is not finite (bfgs.hpp#L351-L357), and WolfeLineSearch treats any non-zero return as a failed evaluation. While expanding the step, it moves back toward the previous step, up to maxLSRestarts times (bfgs_linesearch.hpp#L257-L265); while zooming, it halves the step toward the lower end of the bracket (bfgs_linesearch.hpp#L145-L150). No accepted point has a non-finite gradient, and a non-finite gradient at the initial point stops the optimizer with "Error evaluating initial BFGS point." @nhuurre pointed this out in #3309.
The Discourse thread describes a different problem: the line search fails because its trial points keep landing where the gradient is not finite. #3229 (merged) stops the zoom from looping forever in that situation, and #3448 caps the first step, which is the usual way into such a region.
The failure in the second comment here, a restart near a mode that ends with "line search could not make progress", is a line-search failure at the limit of floating-point precision. That also needs its own issue if it still happens with current CmdStan.
Activity
Garren-H commentedon Aug 1, 2024
To add to this I have also been experiencing problems where if I start at a point close to the a mode, bfgs and lbfgs results in an error (newton is not feasible due to the dimensionality of the problem). I am using a cluster to perform inference and sometimes my take weeks to run. The cluster has a max walltime of about 5 days (which can not be changed due to capacity reasons). I hence resort to running a fixed number of iterations, saving the final iteration and starting a new job from the previous point which frequently results an error "line search could not make progress". I have been using cmdstan 2.34, have not updated to the latest version.
Fix line search to avoid non-finite gradients
[-]Modify the opitimization lines earch to not return a point with non-finite gradient[/-][+]Modify the opitimization line search to not return a point with non-finite gradient[/+]avehtari commentedon Oct 19, 2026
I'm closing this. When I opened this, I did not check the actual code. The change I proposed already exists, and it already existed when I opened the issue.
ModelAdaptorreturns 3 when an element of the gradient is not finite (bfgs.hpp#L351-L357), andWolfeLineSearchtreats any non-zero return as a failed evaluation. While expanding the step, it moves back toward the previous step, up tomaxLSRestartstimes (bfgs_linesearch.hpp#L257-L265); while zooming, it halves the step toward the lower end of the bracket (bfgs_linesearch.hpp#L145-L150). No accepted point has a non-finite gradient, and a non-finite gradient at the initial point stops the optimizer with "Error evaluating initial BFGS point." @nhuurre pointed this out in #3309.The Discourse thread describes a different problem: the line search fails because its trial points keep landing where the gradient is not finite. #3229 (merged) stops the zoom from looping forever in that situation, and #3448 caps the first step, which is the usual way into such a region.
The failure in the second comment here, a restart near a mode that ends with "line search could not make progress", is a line-search failure at the limit of floating-point precision. That also needs its own issue if it still happens with current CmdStan.