Nn.init not available

I’m unable to use nn.init as stated in the documentation. I previously used nninit which was merged into the official version in 0.1.10.


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'init'

I’ve ensured my version is updated:
conda list | grep pytorch
pytorch 0.1.12 py27_2cu80 [cuda80] soumith

Was originally using

import torch.nn as nn

But this works

from torch.nn import init

They weren’t importing init into the nn module. This has been fixed in a recent PR and should be in the next release. You can have it now if you compile from source on master. Unfortunately, the documentation is always reflective of master, not the latest stable release, so it can have a lot of things that don’t work in the version you may have if you’re just pip or conda installing PyTorch. I wish they would let you select the version of the docs you want to view. If that’s already possible, I haven’t found out how, but then again, I’ve made it a habit to just install PyTorch from source every time and keep it updated. That seems the best course of action with a project that is rapidly improving.

we’ve now made versioned documentation. You can click on the arrow on the docs to go to a different version than master.