Skip to content

Replace deprecated AdamW from transformers with torch.optim.AdamW #311

@Lakshmi-bashyam

Description

@Lakshmi-bashyam

The codebase currently imports AdamW from transformers:

from transformers import AdamW

However, this import has been deprecated and removed in recent Transformer versions (as noted in Hugging Face issue #36954) ([GitHub]). Users now encounter:

ImportError: cannot import name 'AdamW' from 'transformers'

Additionally, a FutureWarning explicitly states:

“This implementation of AdamW is deprecated and will be removed in a future version. Use the PyTorch implementation torch.optim.AdamW instead.” ([GitHub], [Hugging Face Forums])

Suggested change:

- from transformers import AdamW
+ from torch.optim import AdamW

This change ensures compatibility with future versions of the transformers library and avoids deprecation warnings during training.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions