I run my lstm code, it work.
This is my lstm module:

lstmmodule.jpg914×679 55.2 KB

This is my lstm code:

lstmwork.jpg852×396 51.2 KB

And then, I want to transform my lstm module into lstmcell module.
This is my lstmcell module:

lstmcellmodule.jpg762×457 41.6 KB

This is my lstmcell code:

lstmcellwork.jpg846×399 55.3 KB

It runs so slow! And a error occured when I set  ‘retain_graph’ False and j==1:
RuntimeError: Trying to backward through the graph a second time, but the buffers have already been freed. Specify retain_graph=True when calling backward the first time.
I want to make my lstmcell module more faster .So how should I do?
I noticed that the attribute called ‘grad_fn’ of  ‘prediction’ are different between my two case. One is ThAddmmBackward, the other is StackBackward.This is the only difference I found.
Thank you!