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

Optimizer don't have apply() method #20801

Open
konstantin-frolov opened this issue Jan 23, 2025 · 1 comment
Open

Optimizer don't have apply() method #20801

konstantin-frolov opened this issue Jan 23, 2025 · 1 comment
Assignees
Labels
stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.

Comments

@konstantin-frolov
Copy link

konstantin-frolov commented Jan 23, 2025

Environment:

Python 3.12.7
Tensorflow 2.16.1
Keras 3.8.0

Problem:

All optimizers from tf.keras.optimizers do not have a method apply() to write the train routine from scratch.
But the docs states that it exists.

AttributeError                            Traceback (most recent call last)
Cell In[11], line 1
----> 1 getattr(tf.keras.optimizers.Optimizer(name="test"), "apply")

AttributeError: 'Optimizer' object has no attribute 'apply'

Possible solution

Need to use method apply_gradients(zip(gradients, model_parameters))

@dhantule dhantule added the type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited. label Jan 27, 2025
@dhantule
Copy link
Contributor

@konstantin-frolov, thanks for reporting this.

If you're trying to apply gradients to variable you can use apply_gradients(zip(gradients, model_parameters)), you can read more about theapply_gradients method here. If that doesn't work please provide some minimal reproducible code. Attaching gist for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat:awaiting response from contributor type:support User is asking for help / asking an implementation question. Stackoverflow would be better suited.
Projects
None yet
Development

No branches or pull requests

3 participants