Pretty printing of C++ modules (#15326)
authorPeter Goldsborough <psag@fb.com>
Thu, 20 Dec 2018 05:38:00 +0000 (21:38 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Thu, 20 Dec 2018 05:55:49 +0000 (21:55 -0800)
commiteb5d28ecefb9d78d4fff5fac099e70e5eb3fbe2e
treeae8990f9de997a23ea97afb949cda9fa6084c3cb
parent2ef0f1222a5eb0e1f4c9a2472d7bec31a3f448c2
Pretty printing of C++ modules (#15326)

Summary:
A long outstanding nicety: pretty printing of C++ modules. E.g.
```
  Sequential sequential(
      Linear(10, 3),
      Conv2d(1, 2, 3),
      Dropout(0.5),
      BatchNorm(5),
      Embedding(4, 10),
      LSTM(4, 5));
std::cout << sequential;
```
prints
```
torch::nn::Sequential(
  (0): torch::nn::Linear(in=10, out=3, with_bias=true)
  (1): torch::nn::Conv2d(input_channels=1, output_channels=2, kernel_size=[3, 3], stride=[1, 1])
  (2): torch::nn::Dropout(rate=0.5)
  (3): torch::nn::BatchNorm(features=5, eps=1e-05, momentum=0.1, affine=true, stateful=true)
  (4): torch::nn::Embedding(count=4, dimension=10)
  (5): torch::nn::LSTM(input_size=4, hidden_size=5, layers=1, dropout=0)
)
```

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

Differential Revision: D13518986

Pulled By: goldsborough

fbshipit-source-id: 63bf753672f0e348951de3645208f263581de5fb
23 files changed:
test/cpp/api/module.cpp
test/cpp/api/modules.cpp
test/cpp/api/rnn.cpp
test/cpp/api/sequential.cpp
torch/csrc/api/include/torch/expanding_array.h
torch/csrc/api/include/torch/nn/module.h
torch/csrc/api/include/torch/nn/modules/batchnorm.h
torch/csrc/api/include/torch/nn/modules/conv.h
torch/csrc/api/include/torch/nn/modules/dropout.h
torch/csrc/api/include/torch/nn/modules/embedding.h
torch/csrc/api/include/torch/nn/modules/functional.h
torch/csrc/api/include/torch/nn/modules/linear.h
torch/csrc/api/include/torch/nn/modules/rnn.h
torch/csrc/api/include/torch/nn/modules/sequential.h
torch/csrc/api/include/torch/nn/pimpl.h
torch/csrc/api/src/nn/module.cpp
torch/csrc/api/src/nn/modules/batchnorm.cpp
torch/csrc/api/src/nn/modules/conv.cpp
torch/csrc/api/src/nn/modules/dropout.cpp
torch/csrc/api/src/nn/modules/embedding.cpp
torch/csrc/api/src/nn/modules/functional.cpp
torch/csrc/api/src/nn/modules/linear.cpp
torch/csrc/api/src/nn/modules/rnn.cpp