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

fix adagrad error #4743

Conversation

chengxiaohua1105
Copy link

fix the bug of adagrad algorithm.

The adagrad algorithm is implemented as follows:

for (size_t i = 0; i < param.size(); ++i) {
accum_g[i] += grad[i] * grad[i];
param[i] += learning_rate * grad[i] / std::sqrt(accum_g[i] + epsilon_) + learning_rate * decay_ * param[i];
}

it should be implemented as follows

for (size_t i = 0; i < param.size(); ++i) {
accum_g[i] += grad[i] * grad[i];
param[i] -= learning_rate * grad[i] / std::sqrt(accum_g[i] + epsilon_) + learning_rate * decay_ * param[i];
}

@tonyyang-svail
Copy link

@abhinavarora please confirm this. It looks suspicious to me.

@abhinavarora
Copy link
Contributor

The correction from += to -= is definitely correct. However, the way the weight decay is being added is mathematically incorrect. We should be modifying the gradient first and then using the modified gradient for the updates. However, I checked that this implementation is incorrect in all optimizers. We can refer to http://pytorch.org/docs/0.1.12/optim.html for more details.
@chengxiaohua1105 Should we open an issue for all optimizers?

@CLAassistant
Copy link

CLAassistant commented Jul 22, 2019

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


litao seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@luotao1
Copy link
Contributor

luotao1 commented Jul 23, 2019

close due to paddle/optimizer/adagrad_optimizer.cc are not in the develop branch now.

@luotao1 luotao1 closed this Jul 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants