Skip to content

Conversation

@b1n1yam
Copy link
Contributor

@b1n1yam b1n1yam commented Aug 28, 2025

Fix: Correct AdamW import path

Update the import statement for AdamW to use torch.optim.AdamW instead of transformers.AdamW. This corrects the import path to align with the standard PyTorch library, ensuring compatibility and proper usage of the AdamW optimizer.

What does this PR do?

This PR fixes an ImportError by correcting the import path for the AdamW optimizer in the PyTorch training code snippet. It changes the import from a potentially incorrect location (like transformers or transformers.optimization) to the correct one within the PyTorch library (torch.optim).

@Vaibhavs10
@pcuenca

Update the import statement for AdamW to use `torch.optim.AdamW` instead of `transformers.AdamW`
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

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

Hi @b1n1yam, the line you proposed is malfomed and would not work.

also cc @burtenshaw

@b1n1yam
Copy link
Contributor Author

b1n1yam commented Aug 30, 2025

Hi @b1n1yam, the line you proposed is malfomed and would not work.

also cc @burtenshaw

Thanks for pointing that out @pcuenca - the issue has been addressed in the latest commit.

@b1n1yam b1n1yam requested a review from pcuenca August 30, 2025 18:13
Copy link
Member

@Vaibhavs10 Vaibhavs10 left a comment

Choose a reason for hiding this comment

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

thanks - this must be a very old notebook 😅

@b1n1yam
Copy link
Contributor Author

b1n1yam commented Sep 3, 2025

thanks - this must be a very old notebook 😅

Yeah, it looks like this notebook was using some outdated imports. I’ve updated it to use the correct AdamW path from PyTorch. Let me know if you spot anything else that needs updating!

Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

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

There's still a missing \n that needs to go at the end of line from torch.optim import AdamW

Copy link
Collaborator

@burtenshaw burtenshaw left a comment

Choose a reason for hiding this comment

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

Thanks

@burtenshaw burtenshaw merged commit 3316cea into huggingface:main Sep 5, 2025
@pcuenca
Copy link
Member

pcuenca commented Sep 8, 2025

Thanks @burtenshaw for the final fix!

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.

4 participants