Skip to content

Conversation

@tengyifei
Copy link
Contributor

Fixes the issue discussed in #10838. hidden_size should be the last dimension regardless if we're in ONNX or PyTorch.

@soumith
Copy link
Contributor

soumith commented Sep 7, 2018

@tengyifei have you tested this patch with your use-case?

@tengyifei
Copy link
Contributor Author

tengyifei commented Sep 7, 2018

@soumith Correct. The use case was converting the exported ONNX model to other formats e.g. TensorFlow, which typically assume the [seq_len, batch, num_directions * hidden_size] shape.
In particular, if there are two stacked bidi-RNN layers, the second layer relies on the output from the first layer being flattened num_directions * hidden_size style, not the other way around.

# We have to convert to match pytorch's expected
# seq_len, batch, hidden_size * num_directions
# seq_len, batch, num_directions * hidden_size
# by first moving num_directions to the end with

This comment was marked as off-topic.

This comment was marked as off-topic.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soumith is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@soumith
Copy link
Contributor

soumith commented Sep 8, 2018

thank you!

PenghuiCheng pushed a commit to PenghuiCheng/pytorch that referenced this pull request Sep 11, 2018
Summary:
Fixes the issue discussed in pytorch#10838. `hidden_size` should be the last dimension regardless if we're in ONNX or PyTorch.
Pull Request resolved: pytorch#11368

Differential Revision: D9734814

Pulled By: soumith

fbshipit-source-id: 7f69947a029964e092c7b88d1d79b188a417bf5f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants