Skip to content

Adam solver#2856

Closed
PatWie wants to merge 1 commit intoBVLC:masterfrom
PatWie:adam
Closed

Adam solver#2856
PatWie wants to merge 1 commit intoBVLC:masterfrom
PatWie:adam

Conversation

@PatWie
Copy link
Copy Markdown
Contributor

@PatWie PatWie commented Aug 4, 2015

This commit implements the Adam solver by Kingma et. al for CPU and
GPU. All solver parameters are defined in the caffe.proto. This also
adds an example for the MNIST dataset.

see issue #2827

Before merging, please review the code. I will add changes to this branch (and rebase) if there should be something to change.

@shelhamer shelhamer added the focus label Aug 4, 2015
@shelhamer
Copy link
Copy Markdown
Member

@philkr could you review this if you have a chance?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why not use momentum here, to be consistent with other solvers?

@shelhamer
Copy link
Copy Markdown
Member

@PatWie thanks for the solver! All SGD solvers need gradient checks. See for instance the AdaGrad tests https://github.com/BVLC/caffe/blob/master/src/caffe/test/test_gradient_based_solver.cpp#L431-L483

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why divide by stepsize here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think t is the epoch rather than the iteration by the definition of Caffe.

@PatWie
Copy link
Copy Markdown
Contributor Author

PatWie commented Aug 4, 2015

@shelhamer Ah. i didn't realized that there is already a unit-test. I will add one of course.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The three commands above can be written as a single caffe_cpu_axpby using beta1 instead of 0 and val_m_ instead of val_t_.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah I see. Blas is completely new for me. I will change this tomorrow at all places in my code.

@Nanne
Copy link
Copy Markdown

Nanne commented Aug 5, 2015

I think there's some confusion going on in the code due to the usage of the stepsize param. Which is made worse by using lr_policy "step" in the MNIST example.

The alpha/stepsize from the paper should be set via the base_lr, and used with lr_policy: "fixed" as I don't see any recommendations for changing alpha during training. This way you can also get rid of gamma and power in the prototxt (the latter wasn't being used anyway).

The stepsize param should only be used together with lr_policy "step", and if we already set the alpha via base_lr then it is not needed at all. t can just be iter_ +1, as it's afaik not needed to compute the effective stepsize. This also removes the need for a check if stepsize > 0 in the header.

Moreover, it makes sense to change the MNIST example to use the recommended value from the paper for the base_lr (0.001) and explicitly set momentum and momentum2 to 0.9 and 0.999 respectively, rather than relying on the default values.

@PatWie
Copy link
Copy Markdown
Contributor Author

PatWie commented Aug 5, 2015

I applied all changes in memory usage, solver_mnist proto, t is now the current iteration instead of epoche. And there is a unit test.
There are still some trivial things todo:

  • update solver page in the wiki
  • implement learning rate heuristic 1/sqrt(t) for reproducing results from the paper

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A reference to a shared pointer is never good idea, just copy the pointer.

@philkr
Copy link
Copy Markdown
Contributor

philkr commented Aug 5, 2015

The solver looks good to me now. I haven't tested it though. I do think that caffe_ipow should be it's own PR if we really want to add it. Currently it just bloats this PR request and doesn't add any benefit (see https://en.wikipedia.org/wiki/Amdahl%27s_law).

@ronghanghu ronghanghu added the RH label Aug 5, 2015
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ronghanghu
Copy link
Copy Markdown
Member

@PatWie Thank you for this great PR! I just added some comment on the code. Please fix indent to 4 space indents when continuing from previous lines, and add more test cases. After that, squash into one commit and I can merge.

@ronghanghu
Copy link
Copy Markdown
Member

#2836 and #2866 introduced new conflicts to be resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants