LSTM Cell weights from LSTM

How can I load the weights of an LSTM module to an LSTMCell?

I tried :
self.lstm_cell.load_state_dict(self.lstm.state_dict)

but I get the following error:

self.lstm_cell.load_state_dict(self.lstm.state_dict)
  File "/home/luca/anaconda3/envs/rdkit_env/lib/python3.7/site-packages/torch/nn/modules/module.py", line 812, in load_state_dict
    state_dict = state_dict.copy()
AttributeError: 'function' object has no attribute 'copy'

You should probably take another look at the Doc. I remembered state_dict is not a attribute nor a property: it is a function, as described in the traceback. So, you should use state_dict = lstm.state_dict()

Hi, true, that was stupid. However, now I get the error:

RuntimeError: Error(s) in loading state_dict for LSTMCell:
	Missing key(s) in state_dict: "weight_ih", "weight_hh", "bias_ih", "bias_hh". 
	Unexpected key(s) in state_dict: "weight_ih_l0", "weight_hh_l0", "bias_ih_l0", "bias_hh_l0".

I guess this is, because a LSTM has several layer, and the l0 indicates, that it is the first one?

Yes.

Also, say u have 2 lstm: A, B. These two have different structures. I guess what u r doing is using the weights from A to initialize B, which of course won’t work.