Exporting RNN model with torch.onnx.export

Trying to export a text generation model with torch.onnx and am getting an error when running

torch.onnx.export(model, Variable(torch.LongTensor([[1]])),  "test.onx", verbose=True)
RuntimeError: /pytorch/torch/csrc/jit/tracer.h:116: getTracingState: Assertion `var_state == state` failed.

This is what my model looks like:

SequentialRNN(
  (0): RNN_Encoder(
    (encoder): Embedding(16709, 500, padding_idx=1)
    (encoder_with_dropout): EmbeddingDropout(
      (embed): Embedding(16709, 500, padding_idx=1)
    )
    (rnns): ModuleList(
      (0): WeightDrop(
        (module): LSTM(500, 500, dropout=0.1)
      )
      (1): WeightDrop(
        (module): LSTM(500, 500, dropout=0.1)
      )
      (2): WeightDrop(
        (module): LSTM(500, 500, dropout=0.1)
      )
    )
    (dropouti): LockedDropout(
    )
    (dropouth): LockedDropout(
    )
  )
  (1): LinearDecoder(
    (decoder): Linear(in_features=500, out_features=16709, bias=True)
    (dropout): LockedDropout(
    )
  )
)

I have built pytorch from commit 6185b27c. How do I go about debugging this issue?

Hi Kam,

I think you might have tried to run:

model.eval()

before you exported? I had a similar issue that ‘disappeared’ when I removed that line before exporting.

Cheers,

Nick

I am having the same issue using pytorch 0.4

It seems to matter if your dummy variable is differentiable or not. If I instatiate using torch.randn or Variable with requires_grad=True the above error disappears.
Now I have this other known problem