Skip to content

[pytorch] Add strong Wolfe line search for lbfgs#8824

Closed
fehiepsi wants to merge 9 commits intopytorch:masterfrom
fehiepsi:lbfgs
Closed

[pytorch] Add strong Wolfe line search for lbfgs#8824
fehiepsi wants to merge 9 commits intopytorch:masterfrom
fehiepsi:lbfgs

Conversation

@fehiepsi
Copy link
Copy Markdown
Contributor

@fehiepsi fehiepsi commented Jun 23, 2018

This pull request adds a line search for lbfgs. "strong Wolfe" is the default line search method in minFunc and it is also recommended in the Numerical Optimization book.

The implementation is based on four sources:

The 'lua' version is based on an old version of minFunc, which has been updated in 2012. I made a couple of small changes based on the updated version. Due to that, the test of comparing with .lua version is not consistent (that's is the reason I changed a learning rate in the test).

Differential Revision: D15740107

Comment thread torch/optim/lbfgs.py
# store new direction/step
old_dirs.append(y)
old_stps.append(s)
ro.append(1. / ys)

This comment was marked as off-topic.

Comment thread torch/optim/lbfgs.py

# directional derivative is below tolerance
if gtd > -tolerance_change:
break

This comment was marked as off-topic.

Comment thread torch/optim/lbfgs.py

if d.mul(t).abs_().sum() <= tolerance_change:
# lack of progress
if d.mul(t).abs().max() <= tolerance_change:

This comment was marked as off-topic.

Comment thread torch/optim/lbfgs.py

flat_grad = self._gather_flat_grad()
abs_grad_sum = flat_grad.abs().sum()
opt_cond = flat_grad.abs().max() <= tolerance_grad

This comment was marked as off-topic.

Comment thread torch/optim/lbfgs.py
min_pos = x1 - (x1 - x2) * ((g1 + d2 - d1) / (g1 - g2 + 2 * d2))
return min(max(min_pos, xmin_bound), xmax_bound)
else:
return (xmin_bound + xmax_bound) / 2.

This comment was marked as off-topic.

Comment thread test/test_optim.py Outdated
lambda params: optim.LBFGS(params, lr=5e-2, max_iter=5),
wrap_old_fn(old_optim.lbfgs, learningRate=5e-2, maxIter=5)
lambda params: optim.LBFGS(params, lr=1, max_iter=5),
wrap_old_fn(old_optim.lbfgs, learningRate=1, maxIter=5)

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@ssnl
Copy link
Copy Markdown
Collaborator

ssnl commented Jun 25, 2018

I'll review this soon.

@ailzhang
Copy link
Copy Markdown
Contributor

cc: @ssnl

@zdevito zdevito removed their request for review February 13, 2019 01:22
@gchanan gchanan removed their request for review February 28, 2019 16:18
@jeffreyksmithjr jeffreyksmithjr added triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module module: optimizer Related to torch.optim labels Jun 10, 2019
Comment thread torch/optim/lbfgs.py
Comment thread torch/optim/lbfgs.py
Comment thread torch/optim/lbfgs.py
Comment thread torch/optim/lbfgs.py Outdated
Comment thread torch/optim/lbfgs.py
@fehiepsi
Copy link
Copy Markdown
Contributor Author

Thanks for reviewing @vincentqb !

Copy link
Copy Markdown
Contributor

@vincentqb vincentqb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the references! This PR looks good to me :)

Copy link
Copy Markdown
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vincentqb is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@vincentqb merged this pull request in ad73ea2.

nghorbani pushed a commit to nghorbani/human_body_prior that referenced this pull request Aug 9, 2019
This has been copied from pytorch/pytorch#8824
PyTorch 1.2.0 has already merged this pull-request and we will incorporate it from the official repository in our code in near future.
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
This pull request adds a line search for lbfgs. "strong Wolfe" is the default line search method in [minFunc](https://www.cs.ubc.ca/~schmidtm/Software/minFunc.html) and it is also recommended in the [Numerical Optimization](https://www.springer.com/gp/book/9780387303031) book.

The implementation is based on four sources:
+ https://www.cs.ubc.ca/~schmidtm/Software/minFunc.html
+ https://www.springer.com/gp/book/9780387303031 Algorithms 3.5, 3.6, formula 3.59
+ https://github.com/torch/optim/blob/master/lswolfe.lua
+ https://github.com/torch/optim/blob/master/polyinterp.lua

The 'lua' version is based on an old version of `minFunc`, which has been updated in 2012. I made a couple of small changes based on the updated version. Due to that, the test of comparing with `.lua` version is not consistent (that's is the reason I changed a learning rate in the test).
Pull Request resolved: pytorch#8824

Differential Revision: D15783067

Pulled By: vincentqb

fbshipit-source-id: 5316d9088233981120376d79c7869d5f97e51b69
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module: optimizer Related to torch.optim open source triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants