Skip to content

Adam Optimizer is Not Working in the Fine-Tuning a Pretrained Model Notebook #564

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

Open
arjunaskykok opened this issue Apr 14, 2025 · 2 comments

Comments

@arjunaskykok
Copy link
Contributor

This is the notebook:

https://github.com/huggingface/notebooks/blob/main/transformers_doc/en/training.ipynb

In this code cell:

from transformers import TFAutoModelForSequenceClassification
from tensorflow.keras.optimizers import Adam

# Load and compile our model
model = TFAutoModelForSequenceClassification.from_pretrained("bert-base-cased")
# Lower learning rates are often better for fine-tuning transformers
model.compile(optimizer=Adam(3e-5))  # No loss argument!

model.fit(tokenized_data, labels)

We would get this error:

Image

@arjunaskykok
Copy link
Contributor Author

Passing string works.

model.compile(optimizer="adam")

@arjunaskykok
Copy link
Contributor Author

This one works as well.

from tf_keras.src.optimizers.legacy.adam import Adam
model.compile(optimizer=Adam(3e-5))

I executed the notebook in Google Colab. The original Adam is an instance of this class:

<keras.src.optimizers.adam.Adam at 0x7d1ec600d790>

Apparently, that class created a problem.

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

No branches or pull requests

1 participant