Implement a Caffe2 standalone LSTM operator (#17726)
authorAhmed Aly <ahhegazy@fb.com>
Thu, 7 Mar 2019 09:03:51 +0000 (01:03 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 7 Mar 2019 09:08:49 +0000 (01:08 -0800)
commitf8778aef78f3e34e78a0cbe4cd2da9e7f1895a15
tree541b3c4d8f9886b69bd285b2c19ff0f3697251e2
parent7d02a1fbc70d324bf587ccbfe508cd2e33ed534a
Implement a Caffe2 standalone LSTM operator (#17726)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/17726

Pull Request resolved: https://github.com/pytorch/pytorch/pull/17725

Pull Request resolved: https://github.com/pytorch/pytorch/pull/17461

Implementing a standalone LSTM Operator in Caffe2 adopted from this Aten implementation: diffusion/FBS/browse/master/fbcode/caffe2/aten/src/ATen/native/RNN.cpp. The most tricky thing in this exercise was that caffe2::Tensor has no copy constructor that made it necessary to implement a custom templated copy constructor for the different Tensor containers used in the code. Also there was no way to use off-the-shelf C2 operators in my code easily so I had to copy some code that is doing basic matmul, cat, split, transpose and linear as utility functions.

Two things missing:

- Profiling this implementation against the current ONNXified LSTM op
- Make this operator available to use in PyTorch

Reviewed By: dzhulgakov

Differential Revision: D14351575

fbshipit-source-id: 3b99b53212cf593c7a49e45580b5a07b90809e64
caffe2/operators/inference_lstm_op.cc [new file with mode: 0644]
caffe2/operators/inference_lstm_op.h [new file with mode: 0644]
caffe2/operators/lstm_utils.h [new file with mode: 0644]
caffe2/python/test/inference_lstm_op_test.py [new file with mode: 0644]