-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
torch.jit.trace hardcodes batch size with packed input to LSTM #15319
Comments
Unfortunately tracing only works for fixed batch sizes here, due to some quirks in how PackedSequences are used in RNNs. When #14831 lands, using the TorchScript implementation of LSTM should solve your problem, but there is no workaround today. |
assigning to @driazati to track scripting LSTM |
Fixing #16663 should fix this issue |
Should this be fixed in the nightly, then? I'm getting the same issue with 1.0.0.dev20190301 |
yep! the changes are in the nightly |
Hmm... am I doing something wrong? I run OP's example and I get the same error (although I wrap it in an
|
oh hm, it seems like tracing still fixes the size cc @driazati. Can you try using @torch.jit.script as I originally suggested? That should work. |
Thanks, it seems the next problem is that |
Re-opening since the example above still is tripping a bug somewhere, it gives me a
Looks like we have some other problems also related to tracing optional Tensors (#14455). The JIT currently supports class FeedRNN(torch.jit.ScriptModule):
def __init__(self):
super(FeedRNN, self).__init__()
self.lstm = nn.LSTM(30, 25, batch_first=True)
@torch.jit.script_method
def forward(self, X):
# type: (Tuple[Tensor, Tensor, Optional[Tensor], Optional[Tensor]])
return self.lstm(X)
feed_rnn = FeedRNN()
X = nn.utils.rnn.pack_padded_sequence(b, b_lengths, batch_first=True)
X, hidden_states = feed_rnn(X)
print(X, hidden_states) |
馃悰 Bug
Using
torch.jit.trace
on a function that feeds inputs to LSTM produces a graph with a hard-coded batch size. This makes it impossible to use the traced function with inputs of different batch sizes.To Reproduce
Steps to reproduce the behavior:
This results in:
Expected behavior
Both inputs with different batch sizes should work.
Environment
The text was updated successfully, but these errors were encountered: