Where is the torch.nn.init

I just update the newest version of pytorch. I want to use the init module, but got some error as following:

In [1]: torch.__version__
Out[1]: '0.1.11_5'

In [2]: torch.nn.init
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-6-a03bb0a8e5dc> in <module>()
----> 1 torch.nn.init

AttributeError: module 'torch.nn' has no attribute 'init'

Have you tried from torch.nn import init?

1 Like

Thank you ~ It does really work! Can you explain why?

@Shawn1993 it is standard python packages and how they behave. Without importing something it wont be available.

I can do something like:

import torch.nn.functional as F

But I can’t do the same operation with init package.

This should work: import torch.nn.init as weight_init

Yes, you are right! It just can’t be autocomplete with Ipython . It seems a silly question now.

No it is not silly question look this

import torch.nn as nn
import torch.nn.init
Traceback (most recent call last):
File “/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.py”, line 2883, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “”, line 1, in
import torch.nn.init
File “/home/adel/Desktop/pycharm-community-2016.3.3/helpers/pydev/_pydev_bundle/pydev_import_hook.py”, line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ImportError: No module named init