Home > Software engineering >  module 'torch.optim' has no attribute 'NAdam'
module 'torch.optim' has no attribute 'NAdam'

Time:11-26

nadam = torch.optim.NAdam(model.parameters())

This gives the error AttributeError: module 'torch.optim' has no attribute 'NAdam'. My PyTorch version is '1.9.1 cu102', the python version is 3.7.11. VS code does not even suggest the optimizer but the documentation clearly mentions the optimizer. I can import other optimizers like Adam

CodePudding user response:

https://pytorch.org/docs/1.9.1/optim.html

From the official website, NAdam is not among the optimizers in pytorch v 1.9.1. Try upgrading to v 1.10.0, and your code should work just fine.

CodePudding user response:

According to documentation, NAdam is new in 1.10. It does not show in https://pytorch.org/docs/1.9.1/optim.html?highlight=optim#module-torch.optim

It is in https://pytorch.org/docs/1.10.0/optim.html?highlight=optim#module-torch.optim

  • Related