The first pass does some extra work (details in the link below), if you warm up ScriptModel by calling it a few times first the time should improve.

  
    
    
    Speed of Custom RNN is SUPER SLOW jit
  
  
    Hi, 
Based on code here 

https://github.com/pytorch/pytorch/blob/master/benchmarks/fastrnns/custom_lstms.py 

I write an example to compare the cumputation capability of native lstm and custom lstm. 
But I found that the speed of custom lstm is 100 times slower than native lstm class. 
here is my test code: 
import torch.nn as nn
import time
from models.custom_lstm import LSTMLayer, LSTMCell, script_lstm, LSTMState

input_size = 1024
cell_size =2048
batch_size =20 
seq_len = 200 

native_lstm=n…