question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AttributeError: 'Adam' object has no attribute 'zero_grads'

See original GitHub issue

Im using a code not writing by me. So when executing this code we get error about the inexistance of zero_grads()

optimizer.zero_grads()
AttributeError: 'Adam' object has no attribute 'zero_grads'

This code is:

import chainer.optimizers as O optimizer = O.Adam() optimizer.setup(model) clip = chainer.optimizer.GradientClipping(5.0) optimizer.add_hook(clip) …

optimizer.zero_grads() Does i should change: optimizer.zero_grads() to

optimizer.use_cleargrads(use=True)? Note that im using chainer 4.0 version and the code what building with chainer 1.5.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
abhayraw1commented, May 5, 2018

I guess instead of passing True for use argument you’ll have to pass False:

optimizer.use_cleargrads(use=False) you can have a look at the function definition here which resides in the base class of Adam

Hope it helps.

0reactions
yazidhadnicommented, Jun 14, 2021

For those like me that had the same issue and have landed here : there is no zero_grads(), you should write zero_grad() instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adam' object has no attribute 'zero_grads' - Stack Overflow
AttributeError : 'MomentumSGD' object has no attribute 'zero_grads'. However, when you want to use the code written in chainer v1.5, ...
Read more >
tf.keras.optimizers.Optimizer | TensorFlow v2.11.0
A Tensor, or Python object convertible to a Tensor, defaults to None. The initial value of the optimizer variable, if None, the initial...
Read more >
chainer.optimizers.Adam — Chainer 7.8.1 documentation
This method allocates arrays for all gradients which have None . This method is called before and after every optimizer hook. If an...
Read more >
Chainerのzero_gradsについてです。 - Teratail
というコードがあったのですが、 'Adam' object has no attribute ... has been deleted and it is recommended to use Link.zerograds(), ...
Read more >
tf.keras.optimizers.Adam
Attributes : iterations : Variable. The number of training steps this Optimizer has run. weights : Returns variables of this Optimizer based ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found