I’m new to Pytorch, I feel puzzled when I run the code:
from torch.nn.init import zeros_

and use it to initialize some veriables:

and I got an error: ImportError: cannot import name ‘zeros_’ :tired_face:

where torch.version is 0.4.0


I ran your code, and I did not get any error.
If you want to init with constant values, here is a better approach:

torch.nn.init.constant_(tensor, 0)


1 Like


Thanks for your reply!
I will try to use the approach to init with constant values.

I solve this problem by updating the torch version.

when the torch version is 0.4.0

import torch

and can not find ‘zeros_’ in the result. So I updata the torch version(0.4.1).

Thanks ! :smile:

You are welcome.

I think it is great idea to use latest version. There are a lot of optimization and development now. Furthermore, your code will be usable for different purposes.

Good luck