How to find "weight" of nn.module?

I am new to pytorch, and I am reading a piece of code :slight_smile:

import torch.nn.init as init
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                init.orthogonal_(m.weight)
                if m.bias is not None:
                    init.constant_(m.bias, 0)
            elif isinstance(m, nn.BatchNorm2d):
                init.constant_(m.weight, 1)
                init.constant_(m.bias, 0)

I read the document of nn.module and do not find any detail about this weight attribute, so please help me to find out where does this attribute defined. How to know what attribute or method I have when I use a nn.module?

nn.Module is a base class for other modules and its purpose is not only to store the learnable parameters (weights/biases) but hooks, buffers as well. In PyTorch, modules are not only the network layers (nn.Conv2d, nn.BatchNorm), but loss functions (nn.MSELoss) or containers (nn.Sequential), to name a few. So it’s not necessary for each module to store the weights. You can check the Variables section in the docs to find out what parameters the module has (e.g. for nn.Conv2d).