pytorch 0.4.1 - ‘LSTM’ object has no attribute ‘weight_ih_l’
Simple question. I’d like to see the initialized parameter of LSTM. How do I see it?
Do I need to always put lstm in the model to see the params?

import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
​
torch.manual_seed(1)
torch.__version__
​
lstm = nn.LSTM(3, 3)  
​
lstm.weight_ih_l



  --------------------------------------------------------------------------- AttributeError                            Traceback (most recent call
  last)  in ()
        9 lstm = nn.LSTM(3, 3)
       10 
  ---> 11 lstm.weight_ih_l
  
  ~/anaconda3/envs/pytorch0.41/lib/python3.6/site-packages/torch/nn/modules/module.py
  in getattr(self, name)
      516                 return modules[name]
      517         raise AttributeError("'{}' object has no attribute '{}'".format(
  --> 518             type(self).name, name))
      519 
      520     def setattr(self, name, value):
  
  AttributeError: 'LSTM' object has no attribute 'weight_ih_l'


nn.LSTM is implemented with nn.RNNBase which puts all the parameters inside the OrderedDict: _parameters. So to 'see' the initialized parameters, you can simply do:

import torch
torch.manual_seed(1)

import torch.nn as nn

lstm = nn.LSTM(3, 3)

print(lstm._parameters['weight_ih_l0'])


Also, to know what are the keys value in that OrderedDict, you can simply do:
print(lstm._all_weights).
