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

Subtle difference with Pytorch AdamW? #35504

Closed
kyleliang919 opened this issue Jan 4, 2025 · 5 comments · Fixed by #36177
Closed

Subtle difference with Pytorch AdamW? #35504

kyleliang919 opened this issue Jan 4, 2025 · 5 comments · Fixed by #36177

Comments

@kyleliang919
Copy link

denom = exp_avg_sq.sqrt().add_(group["eps"])

It does correction after epsilon is added, whereas pytorch:
https://pytorch.org/docs/stable/_modules/torch/optim/adamw.html#AdamW

step = _get_value(step_t)

bias_correction1 = 1 - beta1**step
bias_correction2 = 1 - beta2**step

step_size = lr / bias_correction1

bias_correction2_sqrt = bias_correction2**0.5

if amsgrad:
    # Maintains the maximum of all 2nd moment running avg. till now
    torch.maximum(max_exp_avg_sqs[i], exp_avg_sq, out=max_exp_avg_sqs[i])

    # Use the max. for normalizing running avg. of gradient
    denom = (max_exp_avg_sqs[i].sqrt() / bias_correction2_sqrt).add_(eps)
else:
    denom = (exp_avg_sq.sqrt() / bias_correction2_sqrt).add_(eps)

param.addcdiv_(exp_avg, denom, value=-step_size)
Copy link

github-actions bot commented Feb 3, 2025

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

@Rocketknight1
Copy link
Member

cc @ArthurZucker - is there a reason for us to maintain our own AdamW? In future, should we just wrap Torch's optimizer for this class?

@ArthurZucker
Copy link
Collaborator

Yeah no reason anymore AFAIK!

@Rocketknight1
Copy link
Member

Opened a PR at #36177 to do that!

Copy link

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the contributing guidelines are likely to be ignored.

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 a pull request may close this issue.

3 participants