Hi,
I have been trying to implement the LSTM siamese for sentence similarity as introduced in the initial paper 16 on my own but I am struggling to get the last hidden layer for each iterations without using a for loop.
h3 and h4 respectively on this diagram that come from the paper.

Image 2018-12-13 at 9.16.01 PM.png1104×668 41.8 KB

All the implementations I have seen (see here 20 and there 9 for examples) use for loop to go one by one to get the final hidden layer. It looks correct to me but this is super inefficient as when I am training it on my cpu it only uses one CPU (because of the for loop as far as I understand).
I understand that I could run multiple epoch in parallel but I’d really like to find a way to solve it in the LSTM code itself by not using the for loop which would allow the code to run faster.
My guess tell me that maybe I could do something with register hook but I am going into uncharted territory.
Could anyone give me a help or give me a hint in order to make this fast with pytorch?
Thanks in advance for any help.