pytorch/test/cpp/api
Peter Goldsborough 153e2e96d4 Make Sequential ref-counted (#9151)
Summary:
In the C++ API, `Sequential` currently was not refcounted itself, but stored `shared_ptr<AnyModule>` to get the reference semantics. This is unfortunate because most modules in the API are accessed via `->`, e.g. `Linear l(1, 2); l->forward(...);`. `Sequential` was different in that it had value semantics itself, thus was accessed via `.`.

This PR makes `Sequential` store `AnyModule` (without extra indirection), and uses the same pImpl mechanism we use for all other modules to make `Sequential` have reference semantics itself. This makes it consistent with the rest of the library. It also removes one level of indirection inside of `Sequential`, which is cool.

One thing I had to change was that the `ModuleHolder` with which the whole pImpl thing is implemented previously did some tricks to make `Linear(3, 4)` actually construct `Linear(LinearOptions(3, 4))`. This doesn't work well with `Sequential` since it takes a variadic parameter pack. Instead, I made `ModuleHolder` forward all arguments to the underlying module, and then further pushed the trick to forward parameters to modules' options types into the actual Modules. This adds one constructor per Module in the library. This is not something user modules have to do (unless they want this nice forwarding themselves). It makes the code simpler overall.

ezyang ebetica apaszke
Pull Request resolved: https://github.com/pytorch/pytorch/pull/9151

Reviewed By: ezyang

Differential Revision: D8809298

Pulled By: goldsborough

fbshipit-source-id: da68452c3de912fbc67af330ba93b5220de6909f
2018-07-11 17:24:59 -07:00
..
any.cpp Make Sequential ref-counted (#9151) 2018-07-11 17:24:59 -07:00
cursor.cpp Set random seed at the start of C++ tests (#8903) 2018-06-27 20:09:46 -07:00
integration.cpp Move _cudnn_init_dropout_state to TensorOptions and enable cuDNN dropout in C++ API RNNs (#9012) 2018-06-29 17:25:23 -07:00
main.cpp Split up detail.h (#7836) 2018-05-30 08:55:34 -07:00
misc.cpp Set random seed at the start of C++ tests (#8903) 2018-06-27 20:09:46 -07:00
module.cpp Make Sequential ref-counted (#9151) 2018-07-11 17:24:59 -07:00
modules.cpp Make Sequential ref-counted (#9151) 2018-07-11 17:24:59 -07:00
optim_baseline.h Use torch:: instead of at:: (#8911) 2018-06-27 14:42:01 -07:00
optim_baseline.py Use torch:: instead of at:: (#8911) 2018-06-27 14:42:01 -07:00
optim.cpp Make Sequential ref-counted (#9151) 2018-07-11 17:24:59 -07:00
README.md Update C++ API tests to use Catch2 (#7108) 2018-04-30 21:36:35 -04:00
rnn.cpp Move _cudnn_init_dropout_state to TensorOptions and enable cuDNN dropout in C++ API RNNs (#9012) 2018-06-29 17:25:23 -07:00
sequential.cpp Make Sequential ref-counted (#9151) 2018-07-11 17:24:59 -07:00
serialization.cpp Make Sequential ref-counted (#9151) 2018-07-11 17:24:59 -07:00
static.cpp Make Sequential ref-counted (#9151) 2018-07-11 17:24:59 -07:00
tensor_cuda.cpp Make at::tensor faster (#8709) 2018-06-20 14:46:58 -07:00
tensor_options_cuda.cpp Created DefaultTensorOptions in ATen (#8647) 2018-06-24 21:15:09 -07:00
tensor_options.cpp Created DefaultTensorOptions in ATen (#8647) 2018-06-24 21:15:09 -07:00
tensor.cpp [C++ API] Bag of fixes (#8843) 2018-06-25 21:11:49 -07:00
util.h [C++ API] Better forward methods (#8739) 2018-06-26 13:23:16 -07:00

C++ API Tests

In this folder live the tests for PyTorch's C++ API (formerly known as autogradpp). They use the Catch2 test framework.

CUDA Tests

The way we handle CUDA tests is by separating them into a separate TEST_CASE (e.g. we have optim and optim_cuda test cases in optim.cpp), and giving them the [cuda] tag. Then, inside main.cpp we detect at runtime whether CUDA is available. If not, we disable these CUDA tests by appending ~[cuda] to the test specifications. The ~ disables the tag.

One annoying aspect is that Catch only allows filtering on test cases and not sections. Ideally, one could have a section like LSTM inside the RNN test case, and give this section a [cuda] tag to only run it when CUDA is available. Instead, we have to create a whole separate RNN_cuda test case and put all these CUDA sections in there.

Integration Tests

Integration tests use the MNIST dataset. You must download it by running the following command from the PyTorch root folder:

$ python tools/download_mnist.py -d test/cpp/api/mnist