brainpy / BrainPy

Brain Dynamics Programming in Python
https://brainpy.readthedocs.io/
GNU General Public License v3.0
491 stars 90 forks source link

Fix "amsgrad" is used before being defined when initializing the AdamW optimizer #660

Closed CloudyDory closed 3 months ago

CloudyDory commented 3 months ago

When initializing the "AdamW" optimizer, property "amsgrad" is used before it is defined. Therefore the following code generates error: AttributeError: 'AdamW' object has no attribute 'amsgrad'.

import brainpy as bp
import brainpy.math as bm

weights = {'weight': bm.TrainVar(bm.zeros(10))}
optimizer = bp.optim.AdamW(lr=0.01, train_vars=weights)

This PR fixes this error.

Types of changes

Checklist