Commit Graph

128 Commits

Author SHA1 Message Date
Pavel Belevich
27afac2134 C++ API parity: Dropout, Dropout2d, Dropout3d
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/29761

Test Plan: Imported from OSS

Differential Revision: D18530820

Pulled By: pbelevich

fbshipit-source-id: 9d351561692f7de099d7c6aaf2ecb930b5c867e9
2019-11-15 20:32:06 -08:00
Will Feng
a68c52494c Use F::*FuncOptions for embedding/embeddingbag functionals (#29673)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/29673

Following https://github.com/pytorch/pytorch/pull/29364 and https://github.com/pytorch/pytorch/pull/29404, this PR makes `F::EmbeddingFuncOptions` and `F::EmbeddingBagFuncOptions` separate classes from `torch::nn::EmbeddingOptions` and `torch::nn::EmbeddingBagOptions`, so that it's easier to enforce that arguments such as `num_embeddings` and `embedding_dim` are required for `torch::nn::EmbeddingOptions` and `torch::nn::EmbeddingBagOptions`.

Test Plan: Imported from OSS

Differential Revision: D18462540

Pulled By: yf225

fbshipit-source-id: f2abf431e48675b0a9d7f6f398cdb90ff9037c35
2019-11-13 18:47:22 -08:00
Will Feng
2bcac59a30 Use default dtype for torch::tensor(floating_point_values) and torch::tensor(empty braced-init-list) when dtype is not specified (#29632)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/29632

This PR is BC-breaking in the following way:

Previously, C++ `torch::tensor` with a floating-point literal with no suffix (e.g. `torch::tensor(1.1)`) or a (nested) braced-init-list of
floating-point literals with no suffix (e.g. `torch::tensor({{1.1, 2.2}})` produces a tensor with dtype `at::kDouble`. After this PR, it produces a tensor with dtype `torch::get_default_dtype()`, matching Python `torch.tensor` behavior.

Test Plan: Imported from OSS

Differential Revision: D18465819

Pulled By: yf225

fbshipit-source-id: 6834fe50335c677bc3832f2a5e9cf8d1ede9f665
2019-11-13 15:17:11 -08:00
Will Feng
b37c235d86 C++/Python API parity for Conv{1,2,3}d layers, and add F::conv{1,2,3}d functionals (#28917)
Summary:
This PR changes the implementation of C++ Conv{1,2,3}d layers to exactly match the Python version, and add F::conv{1,2,3}d functionals. For more thorough testing, I will rely on the parity test mechanism which uses values from `common_nn.py` to generate the inputs and options that we are interested in testing.

This PR is BC-breaking in the following way:

In `Conv{1,2,3}dOptions`:
- `with_bias` is renamed to `bias`.
- `input_channels` is renamed to `in_channels`.
- `output_channels` is renamed to `out_channels`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28917

Differential Revision: D18471526

Pulled By: yf225

fbshipit-source-id: 7a33f60654ad93cc2e043245e7ff9e0ef9da15b3
2019-11-13 12:53:31 -08:00
Will Feng
65bfcde05e Use c10::variant-based enums for SmoothL1Loss module and functional
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/29536

Test Plan: Imported from OSS

Differential Revision: D18432272

Pulled By: yf225

fbshipit-source-id: fa355145962e93025b7de98b99b0a4fc82e8c871
2019-11-12 16:05:31 -08:00
Will Feng
57eab22c6a Use c10::variant-based enums for F::grid_sample
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/29535

Test Plan: Imported from OSS

Differential Revision: D18432273

Pulled By: yf225

fbshipit-source-id: 11476f0431a9b544dfb62bc7a89bab84399f9b83
2019-11-12 16:05:26 -08:00
Will Feng
9f879ef532 Make all non-input arguments to functionals part of its options (#29404)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/29404

This PR makes all non-input arguments to functionals part of its options parameters, so that we won't break backward compatibility even if we add or reorder some of the non-input arguments to functionals in the future.

Test Plan: Imported from OSS

Differential Revision: D18378526

Pulled By: yf225

fbshipit-source-id: f5cf6bdfb844e75bf94fdee58c121e0955631b6e
2019-11-12 16:05:22 -08:00
Anjali Chourdia
604fc9ec41 F::embedding, F::embedding_bag, moved Embedding and EmbeddingBag options to embedding.h in options
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/28669

Differential Revision: D18377609

Pulled By: anjali411

fbshipit-source-id: 6a2c547368849ebd1a2f8828cfbe7252152b26a2
2019-11-11 11:51:26 -08:00
eellison
e01fc56ecb move type inference for arange into c++ (#27629)
Summary:
Fixes https://github.com/pytorch/pytorch/issues/17662

I'm not sure if `arange` needs to be in python_arg_parser at all, given the schemas in native_functions.yaml. In any case this at least fixes the dytpe mismatch.

In follow up PRs I will try to handle some of the other ops that do type inference at the python level, like randint.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27629

Differential Revision: D17885939

Pulled By: eellison

fbshipit-source-id: f97a8bc722b7ab77de1c42a992e49a4a3175ad60
2019-11-11 11:26:21 -08:00
Will Feng
cb74ede59e Pass F::*FuncOptions instead of torch::nn::*Options to functionals, and make F::*FuncOptions a different class when necessary (#29364)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/29364

Currently, we use `torch::nn::*Options` both as module options and functional options. However, this makes it very hard to manage the parameters in `torch::nn::*Options`, because a module's constructor can take a different set of arguments than the module's equivalent functional (e.g. `torch.nn.BatchNorm1d` takes `num_features, eps=1e-5, momentum=0.1, affine=True,
track_running_stats=True`, while `F::batch_norm` takes `running_mean, running_var, weight=None, bias=None, training=False, momentum=0.1, eps=1e-5`).

This PR resolves the above problem by making `F::*FuncOptions` a different class from `torch::nn::*Options` when necessary (i.e. when a module's constructor takes a different set of arguments than the module's equivalent functional). In the rest of the cases where the module constructor takes the same set of arguments as the module's equivalent functional, `F::*FuncOptions` is an alias of `torch::nn::*Options`.

Also as part of this PR, we change all functional options to pass-by-value, to make the semantics consistent across all functionals.

Test Plan: Imported from OSS

Differential Revision: D18376977

Pulled By: yf225

fbshipit-source-id: 8d9c240d93bfd5af0165b6884fdc912476b1d06b
2019-11-08 22:38:21 -08:00
Pavel Belevich
69f845cb77 C++ API parity: MarginRankingLoss
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/29000

Test Plan: Imported from OSS

Differential Revision: D18271855

Pulled By: pbelevich

fbshipit-source-id: cbafc7f059173306c83673d7be374c2d3700911f
2019-11-05 05:41:40 -08:00
Xiaomeng Yang
2460dced8f Add torch.nn.GELU for GELU activation (#28944)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28944

Add torch.nn.GELU for GELU activation

Test Plan: buck test mode/dev-nosan //caffe2/test:nn -- "GELU"

Reviewed By: hl475, houseroad

Differential Revision: D18240946

fbshipit-source-id: 6284b30def9bd4c12bf7fb2ed08b1b2f0310bb78
2019-11-03 21:55:05 -08:00
nuka137
a68c1e109e C++ API: torch::nn::BatchNorm{2,3}d (#28936)
Summary:
Add torch::nn::BatchNorm{2,3}d module and functional support for the C++ API.

Related Issue: https://github.com/pytorch/pytorch/issues/25883 #28176

Reviewer: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28936

Differential Revision: D18274584

Pulled By: yf225

fbshipit-source-id: 3784eee9f8947f6c7c9f1699544a3d36a1a019b7
2019-11-01 17:50:33 -07:00
Pavel Belevich
4a94eaa60b C++ API parity: PoissonNLLLoss
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/28755

Test Plan: Imported from OSS

Differential Revision: D18202436

Pulled By: pbelevich

fbshipit-source-id: a7a27d5f3cdbcbbd9bbbffa02b576609d5fdc9b3
2019-11-01 12:35:59 -07:00
Edward Yang
bbea34f283 Revert D18266918: C++ API: torch::nn::BatchNorm{2,3}d
Test Plan: revert-hammer

Differential Revision:
D18266918

Original commit changeset: f432904c7298

fbshipit-source-id: 0e1c596b2e2f13b59082ff422c67ba025df4be07
2019-11-01 10:46:49 -07:00
nuka137
b7c5b3d398 C++ API: torch::nn::BatchNorm{2,3}d (#28936)
Summary:
Add torch::nn::BatchNorm{2,3}d module and functional support for the C++ API.

Related Issue: https://github.com/pytorch/pytorch/issues/25883 #28176

Reviewer: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28936

Differential Revision: D18266918

Pulled By: yf225

fbshipit-source-id: f432904c72985d52ec52cb992cceb372b6ff0244
2019-11-01 09:28:58 -07:00
Carlos Miranda
72b9bda9e5 Smooth L1 loss (#27661)
Summary:
In accordance with https://github.com/pytorch/pytorch/issues/25883, I added the `SmoothL1Loss` module and `smooth_l1_loss` functional.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27661

Differential Revision: D18002332

Pulled By: yf225

fbshipit-source-id: b382df8becb0de14986ec16ee0dc953d7b10e917
2019-10-31 23:41:35 -07:00
Will Feng
595209bddc Fix bugs in torch::tensor constructor (#28523)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28523

New features:
1. Previously, `torch::tensor({true, false, true})` throws `"tensor_cpu" not implemented for 'Bool'`. After this PR, it produces the correct bool tensor, matching the Python API behavior.
2. Tensors with zero-size dimensions are now supported, e.g. `torch::tensor({{}, {}})` produces a tensor with sizes `{2, 0}`, matching the Python API behavior.

BC-breaking bug fixes:
1. Previously, `torch::tensor({{1}, {2}})` produces a tensor of sizes `{2}`. After this PR, it produces a tensor of sizes `{2, 1}`, matching the Python API behavior.
2. Fixed semantics of `torch::tensor(1.1)`: it now returns a 0-dim tensor instead of a 1-dim tensor, matching the Python API behavior.
3. Previously, when passed a non-dtype `TensorOptions` to the `torch::tensor` constructor, it always produces a tensor of dtype `float`. After this PR, it produces tensor of different dtypes based on the dtype of the braced-init-list, matching the behavior of the no-options case.
```cpp
// Previously:
torch::tensor({1, 2, 3}, torch::TensorOptions(/*non-dtype-options*/)).dtype() -> float
torch::tensor({{1, 2, 3}}, torch::TensorOptions(/*non-dtype-options*/)).dtype() -> float
torch::tensor({1., 2., 3.}, torch::TensorOptions(/*non-dtype-options*/)).dtype() -> float
torch::tensor({{1., 2., 3.}}, torch::TensorOptions(/*non-dtype-options*/)).dtype() -> float

// Now:
torch::tensor({1, 2, 3}, torch::TensorOptions(/*non-dtype-options*/)).dtype() -> int
torch::tensor({{1, 2, 3}}, torch::TensorOptions(/*non-dtype-options*/)).dtype() -> int
torch::tensor({1., 2., 3.}, torch::TensorOptions(/*non-dtype-options*/)).dtype() -> double
torch::tensor({{1., 2., 3.}}, torch::TensorOptions(/*non-dtype-options*/)).dtype() -> double

// As comparison, currently:
torch::tensor({1, 2, 3}).dtype() -> int
torch::tensor({{1, 2, 3}}).dtype() -> int
torch::tensor({1., 2., 3.}).dtype() -> double
torch::tensor({{1., 2., 3.}}).dtype() -> double
```

Notes:
1. From now on, the behavior of `at::tensor(scalar_value)` (which produces a 1-dim tensor) would be different from `torch::tensor(scalar_value)` (which produces a 0-dim tensor). I will fix the behavior of `at::tensor(scalar_value)` in a follow-up PR.
2. From now on, the behavior of `at::tensor({1, 2, 3}, torch::TensorOptions(/*non-dtype-options*/))` (which produces a `float` tensor) would be different from `torch::tensor({1, 2, 3}, torch::TensorOptions(/*non-dtype-options*/))` (which produces a an `int` tensor). I will fix this behavior of `at::tensor` constructor in a follow-up PR.

Context for the changes in this PR:

The motivation comes from fixing the "`torch::tensor({{1}, {2}})` gives tensor of wrong sizes" bug - in order to fix it, I have to move the handling of `at::ArrayRef` and `std::vector` into `InitListTensor` (see below on why we need to do this) and renamed `InitListTensor` to `TensorDataContainer`. After such changes, support for bool values comes out of the box without extra effort, and support for tensors with zero-size dimensions only requires adding a default constructor for `TensorDataContainer`, so I added those two in this PR.

For the semantic change of `torch::tensor(1.1)`, it's actually more effort to preserve the original wrong behavior (i.e. we need to check the sizes of the tensor converted from `TensorDataContainer` and reshape any scalar tensor to a 1-D tensor). I think preserving the original wrong behavior doesn't give us much value, and since the above changes naturally fix the problem, we should just start using the right behavior instead.

For the "constructor with non-dtype options behavior" fix, the code looks simpler and easier to reason about with the fix, so I included it in this PR.

--------

Why we need to move the handling of `at::ArrayRef` and `std::vector` into `TensorDataContainer`:

`torch::tensor({{1}, {2}})` can match this function overload:
`torch::tensor(at::ArrayRef<int> values)`, because `{1}` and `{2}` can be treated as
a list-initialization of an `int` value. However, this will produce a Tensor with sizes `{2}`,
but we actually want a Tensor with sizes `{2, 1}`. In order to avoid matching this function overload,
we removed the function overload and moved the ability to convert `at::ArrayRef<T>`
(and similarly `std::vector<T>`) into `TensorDataContainer`, and since for braced-init-list the
`TensorDataContainer(std::initializer_list<TensorDataContainer>)` constructor is always preferred over all other constructors, it will take the `std::initializer_list` path, and all is good.

Test Plan: Imported from OSS

Differential Revision: D18234625

Pulled By: yf225

fbshipit-source-id: 0f3f6912e82e2117d2103e31b74e7e97baaa8693
2019-10-31 12:53:06 -07:00
Pavel Belevich
d6f1e49c4a C++ API parity: CTCLoss
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/28654

Test Plan: Imported from OSS

Differential Revision: D18202437

Pulled By: pbelevich

fbshipit-source-id: a4b80a57e65da84f3988002a026c648fa52a0fde
2019-10-30 14:35:02 -07:00
jon-tow
1d3d9ec7d4 C++ API Parity: functional::fold and Fold::pretty_print (#28732)
Summary:
Adds `torch::nn::functional::fold` support and updates `Fold::pretty_print` in the C++ API for more thorough Python parity.

Note: Small updates in source files to maintain consistency elsewhere.

Reviewer: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28732

Differential Revision: D18219955

Pulled By: yf225

fbshipit-source-id: fd2e9be8f17db77c1b1f384c0d2e16cc34858c0c
2019-10-30 11:37:39 -07:00
mansoorcheema
a465b033fd Local response norm (#28759)
Summary:
Implemented LocalResponseNorm and some initial tests for modules and functional. Reference https://github.com/pytorch/pytorch/issues/25883
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28759

Differential Revision: D18219745

Pulled By: yf225

fbshipit-source-id: e6aad568a8b1e81f54752decaefd4f9044029da9
2019-10-30 11:31:00 -07:00
nuka137
cbc234bceb C++ API: torch::nn::BatchNorm1d (#28176)
Summary:
Add torch::nn::BatchNorm1d function/module support for the C++ API.
torch::nn::BatchNorm{2,3}d will be added after this PR is merged.

Related Issue: https://github.com/pytorch/pytorch/issues/25883

Reviewer: yf225

I would like to discuss about below items.

* Necessity of `num_batches_tracked` in `BatchNormImplBase`
  * `num_batches_tracked` is needed to calculate `momentum` when we do not feed `momentum` argument in Python API. But in C++ API, `momentum` argument has a default value.
  * `num_batches_tracked` is only used for counting up `BatchNorm1d::foward()` call. I think it is no necessary for user anymore.
* The design of `BatchNorm{1,2,3}dOptions`
  * We have already `BatchNormOptions` used for deprecated `BatchNorm` module. However, it is hard to use it for `BatchNorm{1,2,3}dOptions` because of the arguments disagreement of each modules.
  * In this PR, I introduce `BatchNormOptionsv2` template class for the `BatchNorm{1,2,3}dOptions`. But I'm not sure this design is good or not.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28176

Differential Revision: D18196843

Pulled By: yf225

fbshipit-source-id: 667e2b5de4150d5776c41b9088c9e6c2ead24cd4
2019-10-29 17:29:42 -07:00
Will Feng
e33b4b6761 Use c10::variant-based enums for Reduction
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27942

Test Plan: Imported from OSS

Differential Revision: D18202857

Pulled By: yf225

fbshipit-source-id: 0303ce2508e3b7665c6a91ae270a7d0ef0e45900
2019-10-29 14:15:48 -07:00
jon-tow
52dd587123 C++ API parity: Upsample (#28413)
Summary:
Adds `interpolate` functional and `Upsample` module support for the C++ API.

**Issue**: https://github.com/pytorch/pytorch/issues/25883

**Reviewer**: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28413

Differential Revision: D18165014

Pulled By: yf225

fbshipit-source-id: ecae2f432a301b1f4afa7c038b2d104cbad139f2
2019-10-28 21:34:44 -07:00
nuka137
648749b203 C++ API: torch::nn::LPPool2d (#28492)
Summary:
Add torch::nn::LPPool2d module and functional support for the C++ API.

Related Issue: https://github.com/pytorch/pytorch/issues/25883 #27800

Reviewer: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28492

Differential Revision: D18109401

Pulled By: yf225

fbshipit-source-id: 5cedecb895d9d44c2167cdb3f6f758f3426b3497
2019-10-28 12:28:25 -07:00
anjali411
dc17a2ecc5 Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/28433
Differential Revision: D18138240

Pulled By: anjali411

fbshipit-source-id: 314e5902f103be1feb4cacde47c90204b3d353cc
2019-10-25 11:44:28 -07:00
lsrock1
e885ce6130 C++ parity, grid_sample functional (#28354)
Summary:
https://github.com/pytorch/pytorch/issues/25883
I put grid_sample in vision.h with affine grid.

I have a question in string argument(interpolation mode, padding mode)
I reuse torch::native::detail::GridSamplerInterpolation in GridSampler.h instead of using string.
It follows the way that uses reduction enum in loss functions.
I am not sure this is right.

yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28354

Differential Revision: D18109333

Pulled By: yf225

fbshipit-source-id: 1bf972b671b107464f73b937bbe0de76fb259fbf
2019-10-24 15:14:37 -07:00
Pavel Belevich
dd277e9086 C++ API parity: Linear
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27382

Test Plan: Imported from OSS

Differential Revision: D17766735

Pulled By: pbelevich

fbshipit-source-id: c7a66daeb17550eb9a5d26944427723d4ebdc6c8
2019-10-24 07:11:51 -07:00
Anjali Chourdia
7b59174882 torch::nn::LayerNorm
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/28032

Differential Revision: D18047371

Pulled By: anjali411

fbshipit-source-id: fb61aea52d6622a67ec1d84950e17e85686461ae
2019-10-22 12:50:22 -07:00
Will Feng
079b3cc02c Add C++ nn::functional pad
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26601

Test Plan: Imported from OSS

Differential Revision: D17517468

Pulled By: yf225

fbshipit-source-id: 9ee8b93b88a60f91f2ae78c242f9eaa246b3293c
2019-10-21 22:20:38 -07:00
nuka137
9ea42f8d7c C++ API: torch::nn::LPPool1d (#27800)
Summary:
Add torch::nn::LPPool1d module and functional support for the C++ API.

Related Issue: https://github.com/pytorch/pytorch/issues/25883

Reviewer: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27800

Differential Revision: D18045040

Pulled By: yf225

fbshipit-source-id: e61fefe9efec3423f7a93dd1e946f3e380122927
2019-10-21 15:33:51 -07:00
Carlos Miranda
a1e14a6626 PixelShuffle module and functional (#28140)
Summary:
Added `PixelShuffle` module and functional https://github.com/pytorch/pytorch/issues/25883
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28140

Differential Revision: D18008474

Pulled By: yf225

fbshipit-source-id: f482495bb56998701c79a61ef065a121bf5a5154
2019-10-18 15:54:14 -07:00
naresh
bd6f9e1d6c torch.nn.functional.gumbel_softmax #27078 (#28121)
Summary:
**Comments:**
* Grad check from 848d1ba13a/test/test_nn.py (L8898) not added
* Double data type as seen in     848d1ba13a/test/test_nn.py (L8916) not tested

**Issue:**
https://github.com/pytorch/pytorch/issues/27078
Pull Request resolved: https://github.com/pytorch/pytorch/pull/28121

Differential Revision: D18008515

Pulled By: yf225

fbshipit-source-id: 9363fe9430df0f2bfd337cc788b11ac93adaa360
2019-10-18 09:41:40 -07:00
Shahriar
91a260cef9 Adding MSELoss, KLDivLoss and BCELoss to C++ front-end (#27156)
Summary:
This PR adds ```MSELoss```, ```KLDivLoss``` and ```BCELoss```. The tests for ```BCELoss``` fail with the following error:
```
unknown file: Failure
C++ exception with description "autograd_meta() INTERNAL ASSERT FAILED at /home/shahriar/Contrib/pytorch/c10/core/TensorImpl.h:533, please report a bug to PyTorch. set_requires_grad is not implemented for Tensor (set_requires_grad at /home/shahriar/Contrib/pytorch/c10/core/TensorImpl.h:533)
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27156

Differential Revision: D17960323

Pulled By: yf225

fbshipit-source-id: 84b8431064f2f573679c03a8d7994e3e2f81a4d1
2019-10-17 22:07:01 -07:00
Carlos Miranda
7d277b0670 Multi Label Margin loss (#27659)
Summary:
In accordance with https://github.com/pytorch/pytorch/issues/25883, I added the `MultiLabelMarginLoss` module and `multilabel_margin_loss` functional.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27659

Differential Revision: D17931905

Pulled By: yf225

fbshipit-source-id: 3642f75c79843dda55ac38de9f6f970f3e237847
2019-10-16 15:44:38 -07:00
Carlos Miranda
9540f6c3fe Soft Margin loss (#27660)
Summary:
In accordance with https://github.com/pytorch/pytorch/issues/25883, I added the `SoftMarginLoss` module and `soft_margin_loss` functional.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27660

Differential Revision: D17958325

Pulled By: yf225

fbshipit-source-id: c14422765e6e1fdabf6c9687080e6d5ff490d300
2019-10-16 12:04:08 -07:00
Moksh Jain
f38beff800 Add nn.Bilinear to C++ Frontend (#26082)
Summary:
Adds support for the Bilinear layer to the C++ frontend
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26082

Differential Revision: D17954148

Pulled By: yf225

fbshipit-source-id: 5e746bdea29b00e25969cd7a22044b8059b53687
2019-10-16 09:54:01 -07:00
Divyansh Singhvi
3397d41b8a Wrapping namespace Reduction in namespace at (#26606) (#27422)
Summary:
1) Wrapped namespace `Reduction` in namespace `at`
2) Prefixed `at::` wherever `Reduction::` is used
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27422

Differential Revision: D17913759

Pulled By: yf225

fbshipit-source-id: 8f00ca01cad2e7f673d316b128abf59c026e216c
2019-10-15 11:05:40 -07:00
Will Feng
11172c19be codemod at::ArrayRef and torch::IntArrayRef to std::vector in C++ API tests (#27884)
Summary:
`at::ArrayRef` / `torch::IntArrayRef` should be discouraged in user code, because users might not be aware of the fact that it doesn't own the underlying data, which already leads to memory access bugs when they try to write the following:
```cpp
auto expected_sizes = torch::IntArrayRef({2, 16, 6});  // The memory that represents `{2, 16, 6}` is released after this line
ASSERT_EQ(output.sizes(), expected_sizes);  // `expected_sizes` is pointing to invalid memory region
```
This PR changes all usage of `at::ArrayRef` and `torch::IntArrayRef` to the corresponding `std::vector` version, so that users won't pick up the habit of using `ArrayRef` by looking at the test code.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27884

Differential Revision: D17921646

Pulled By: yf225

fbshipit-source-id: 461e79fc22b598aac230d36cc028085ce6cbe937
2019-10-14 18:00:30 -07:00
Carlos Miranda
2cae3928b0 Multi-Label Soft Margin loss (#27669)
Summary:
In accordance with https://github.com/pytorch/pytorch/issues/25883, I added the `MultiLabelSoftMarginLoss` module and `multilabel_soft_margin_loss` functional.

It looks like there isn't a C++ ATen implementation of `multilabel_soft_margin_loss`, so I translated the python version, which does not rely on a C/C++ backend either.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27669

Differential Revision: D17907608

Pulled By: yf225

fbshipit-source-id: ccb02951e009973c2adbe604593ce929f10c39eb
2019-10-14 13:29:45 -07:00
jon-tow
0003771423 C++ API parity: Unfold (#27809)
Summary:
Adds `unfold` functional and module support for the C++ API.

Issue: https://github.com/pytorch/pytorch/issues/25883

Reviewer: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27809

Differential Revision: D17901792

Pulled By: yf225

fbshipit-source-id: ff58a1866bf240f37ebc589463c60593b8931f51
2019-10-14 13:21:59 -07:00
Gaurav Tamba
cc5c34a0d0 Add nn::functional::normalize() to C++ Frontend (#27280)
Summary:
Addresses https://github.com/pytorch/pytorch/issues/27048

PR Summary:

Files Added:

_torch/csrc/api/include/torch/nn/options/normalization.h
torch/csrc/api/include/torch/nn/functional/normalization.h_

Files Modified:

_test/cpp/api/functional.cpp
torch/csrc/api/include/torch/nn/functional.h_

 ---

yf225 : I couldn't find a C++ equivalent of gradcheck(), is there such a function or is it sufficient to call .backward() in the test body? I don't think any solutions are checked for the Python tests.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27280

Differential Revision: D17902109

Pulled By: yf225

fbshipit-source-id: 1bce1a88103d0f1848633fec90fde95ea8f3d1ed
2019-10-14 08:39:02 -07:00
PyExtreme
52528c041a - TripletMarginLoss (#27713)
Summary:
Hi yf225 , I had to create a new branch to tackle merge conflict since I am using cloud due to some limitations on my PC. Therefore, I don't have enough command there.

Also, I have incorporated the changes you have put before here
https://github.com/pytorch/pytorch/pull/27613

Also, it would be great if you could recommend me some resources to work smmothly on GCP..:-D

Thank you
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27713

Differential Revision: D17899695

Pulled By: yf225

fbshipit-source-id: eb6643223148774a5cbbd093bdcc5623872e5bba
2019-10-13 10:57:37 -07:00
Pavel Belevich
446a79b959 C++ API parity: Threshold
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27538

Test Plan: Imported from OSS

Differential Revision: D17835415

Pulled By: pbelevich

fbshipit-source-id: 2a887704655be79ee458081c46a7eea31eca51dc
2019-10-13 09:38:31 -07:00
Pavel Belevich
cbdd55c669 C++ API parity: Tanhshrink
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27537

Test Plan: Imported from OSS

Differential Revision: D17835409

Pulled By: pbelevich

fbshipit-source-id: ad4120cfe01ea2508bf3ce1054022a2da649ac74
2019-10-13 08:12:13 -07:00
Pavel Belevich
96aafc3cdc C++ API parity: Softsign
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27535

Test Plan: Imported from OSS

Differential Revision: D17835408

Pulled By: pbelevich

fbshipit-source-id: 8548deab91f6fe0f7285fdd919c25129ed042181
2019-10-12 08:30:10 -07:00
Pavel Belevich
fcb6dd079e C++ API parity: Softshrink
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27534

Test Plan: Imported from OSS

Differential Revision: D17835404

Pulled By: pbelevich

fbshipit-source-id: 7b9f3d3ea793f82840496912f248b0c48bb7463e
2019-10-12 06:36:20 -07:00
nuka137
abaa44122d C++ API: torch::nn::Softmin (#27459)
Summary:
Add torch::nn::Softmin module and functional support for the C++ API.

Related Issue: https://github.com/pytorch/pytorch/issues/25883

Reviewer: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27459

Differential Revision: D17892852

Pulled By: yf225

fbshipit-source-id: db15b06e8ad33947e7d65995df700f5e90c3b6a8
2019-10-11 23:03:55 -07:00
Pavel Belevich
c79d3a4a98 C++ API parity: Softplus
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27489

Test Plan: Imported from OSS

Differential Revision: D17835410

Pulled By: pbelevich

fbshipit-source-id: 51a8c4ab2ff4b860c96eda1ed8f073017b8cf9ae
2019-10-11 09:00:32 -07:00
Pavel Belevich
795c913636 C++ API parity: CELU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27487

Test Plan: Imported from OSS

Differential Revision: D17835406

Pulled By: pbelevich

fbshipit-source-id: a8282ae65d8996efcc8b8d846cfa637c3f89eda6
2019-10-11 06:23:57 -07:00
Pavel Belevich
6294a9a877 C++ API parity: RReLU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27437

Test Plan: Imported from OSS

Differential Revision: D17835413

Pulled By: pbelevich

fbshipit-source-id: 5d943fdac4fd2633e7f7ca13db1a7fed5636ca50
2019-10-10 19:14:48 -07:00
Pavel Belevich
352092ca95 C++ API parity: ReLU6
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27436

Test Plan: Imported from OSS

Differential Revision: D17835414

Pulled By: pbelevich

fbshipit-source-id: 77e743d2f6b71fb3ba5643f9d676f2bb8f236cfa
2019-10-10 17:12:17 -07:00
nuka137
6711969dd8 C++ API: torch::nn::LogSoftmax (#27462)
Summary:
Add torch::nn::LogSoftmax module and functional support for the C++ API.

Related Issue: https://github.com/pytorch/pytorch/issues/25883

Reviewer: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27462

Differential Revision: D17867121

Pulled By: yf225

fbshipit-source-id: dae8ac981c1c6ccdef013cd2d886ad4a043f6243
2019-10-10 16:18:15 -07:00
Pavel Belevich
8515650c2b C++ API parity: ReLU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27435

Test Plan: Imported from OSS

Differential Revision: D17835407

Pulled By: pbelevich

fbshipit-source-id: b8ee86c7a76674bc88d8e995424dad22d3caab59
2019-10-10 13:34:38 -07:00
jon-tow
f3df6b8ede Add C++ torch::nn::functional::affine_grid (#27263)
Summary:
Adds`torch::nn::functional::affine_grid` functional support for the C++ API.

Issue: https://github.com/pytorch/pytorch/issues/25883, https://github.com/pytorch/pytorch/issues/27196

Reviewer: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27263

Differential Revision: D17802350

Pulled By: yf225

fbshipit-source-id: e823ee53da4a4cc6a1650d2dfc09b0ef6a74e249
2019-10-09 23:17:49 -07:00
Pavel Belevich
1fec1441a1 C++ API parity: PReLU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27429

Test Plan: Imported from OSS

Differential Revision: D17835412

Pulled By: pbelevich

fbshipit-source-id: e678d5920dad1293bb0ba3de28e2da3087d19bde
2019-10-09 16:31:54 -07:00
Carlos Miranda
3246fddfd6 Implement C++ API torch::nn::MultiMarginLoss. (#27424)
Summary:
Hi yf225 , here is the C++ frontend API MultiMarginLoss implementation and tests https://github.com/pytorch/pytorch/issues/27198. Could you review it and tell me if it is okay?

I am not entirely sure I used `c10::optional` correctly, but `options.weight()` resulted in a compilation error, so I went with `options.weight().value()` instead of `value_or()` to follow the logic in `torch.nn._WeightedLoss.register_buffer` (where one can pass a `None` value).

Oh, and are the tests supposed to be skipped or did I do something wrong? I ran `pytest test/test_cpp_api_parity.py -k Loss -v` , and the `L1Loss` test passed but the others were skipped...

Thank you for the review in any case!
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27424

Differential Revision: D17839963

Pulled By: yf225

fbshipit-source-id: f4b6012590cf22d56d42751c214df80cce717cb8
2019-10-09 14:44:41 -07:00
jon-tow
0fed4756d0 C++ API parity: SELU (#27434)
Summary:
Adds `SELU` functional and module support for the C++ API.

Issue: https://github.com/pytorch/pytorch/issues/25883
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27434

Differential Revision: D17782762

Pulled By: yf225

fbshipit-source-id: 96c7ce84b9baf9e219a63e631929b8997ba6f3f0
2019-10-09 14:39:28 -07:00
nuka137
28a1806cbc C++ API: torch::nn::Softmax (#27446)
Summary:
Add torch::nn::Softmax module support for the C++ API

Related Issue: https://github.com/pytorch/pytorch/issues/25883

Reviewer: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27446

Differential Revision: D17839546

Pulled By: yf225

fbshipit-source-id: 7c7fb55111b261614de7c3a75fa1019fbde93c67
2019-10-09 14:19:47 -07:00
Jonathan Tow
3b5d40c339 Add C++ torch::nn::CosineEmbeddingLoss (#27345)
Summary:
Adds `torch::nn::CosineEmbeddingLoss`  module and functional support for the C++ API.

Issue: https://github.com/pytorch/pytorch/issues/25883

Reviewer: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27345

Differential Revision: D17801402

Pulled By: yf225

fbshipit-source-id: 0eabe80d7d36397e6667b331c3fa2f56d7a15962
2019-10-08 10:52:05 -07:00
Pavel Belevich
2cc1e69cc9 C++ API parity: LogSigmoid
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27060

Test Plan: Imported from OSS

Differential Revision: D17682404

Pulled By: pbelevich

fbshipit-source-id: d60d64cd4caf1f56a2e05c516f91321d46ec9624
2019-10-05 06:18:25 -07:00
Pavel Belevich
8b61a220c0 C++ API parity: LeakyReLU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27059

Test Plan: Imported from OSS

Differential Revision: D17682407

Pulled By: pbelevich

fbshipit-source-id: 2a4f42e9438799ba8de7282ac7a6fd3ff97ee048
2019-10-04 14:18:03 -07:00
Pavel Belevich
192ca9730f C++ API parity: Hardtanh
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27038

Test Plan: Imported from OSS

Differential Revision: D17682405

Pulled By: pbelevich

fbshipit-source-id: f65e76696e0041c3518f56da94f2e3b800305234
2019-10-04 12:53:33 -07:00
Zino Benaissa
803f7bfaac Implement C++ API version of torch.nn.functional.one_hot (#27081) (#27177)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27177

Add support for F::one_hot C++ function.

Test Plan:
Added 3 new tests to verify API is working

Imported from OSS

Differential Revision: D17697934

fbshipit-source-id: a8127fb87c00daa119bb92a5702bc4bbba48290d
2019-10-02 17:28:39 -07:00
Pavel Belevich
515e3b85da C++ API parity: Hardshrink
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27035

Test Plan: Imported from OSS

Differential Revision: D17682403

Pulled By: pbelevich

fbshipit-source-id: 186377fe577abfdd53acc95751a7ed845b51af95
2019-10-02 08:30:20 -07:00
Pavel Belevich
c864454a8f C++ API parity: ELU
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27028

Test Plan: Imported from OSS

Differential Revision: D17682406

Pulled By: pbelevich

fbshipit-source-id: 9c313237cb93b9870c6fcf8d01b3dbe4af4c6f2a
2019-10-02 07:12:08 -07:00
Pavel Belevich
5cac738713 C++ API parity: MaxUnpool2d
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26915

Test Plan: Imported from OSS

Differential Revision: D17627826

Pulled By: pbelevich

fbshipit-source-id: 04a5a7e7d19b1610cafaaa0bd329d4d228ab4be5
2019-10-01 19:29:15 -07:00
Pavel Belevich
d125a83f98 C++ API parity: MaxUnpool1d
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26896

Test Plan: Imported from OSS

Differential Revision: D17627825

Pulled By: pbelevich

fbshipit-source-id: 369d0080412467d0259eb5e692a0778c71b12343
2019-10-01 14:53:40 -07:00
jon-tow
18eea8269a Add C++ torch::nn::functional::pdist (#27122)
Summary:
Adds `torch::nn::functional::pdist` module support for the C++ API.

Issue: https://github.com/pytorch/pytorch/issues/25883, https://github.com/pytorch/pytorch/issues/27082

Reviewer: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27122

Differential Revision: D17685823

Pulled By: yf225

fbshipit-source-id: f8ceb09635385ef2e16a002e5fc255be8eb2ebf4
2019-10-01 07:05:25 -07:00
jon-tow
209dc4c4ba Add C++ torch::nn::HingeEmbeddingLoss (#27101)
Summary:
Adds `torch::nn::HingeEmbeddingLoss` module support for the C++ API.

**Issue**: https://github.com/pytorch/pytorch/issues/25883

**Reviewer**: yf225
Pull Request resolved: https://github.com/pytorch/pytorch/pull/27101

Differential Revision: D17680489

Pulled By: yf225

fbshipit-source-id: 1f8f41775a9e1272a98232c8f899418b2b907eca
2019-09-30 19:29:24 -07:00
Pavel Belevich
1a3997e0b8 C++ API parity: AdaptiveAvgPool3d
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26819

Test Plan: Imported from OSS

Differential Revision: D17627829

Pulled By: pbelevich

fbshipit-source-id: be4d803c7d4ba2c59e54d154eeebc63794465191
2019-09-28 22:32:21 -07:00
Pavel Belevich
a31fd5ea68 C++ API parity: AdaptiveAvgPool2d
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26818

Test Plan: Imported from OSS

Differential Revision: D17627822

Pulled By: pbelevich

fbshipit-source-id: 0e1dea1c3ff2650dbc7902ce704ac6b47588d0bb
2019-09-28 10:45:03 -07:00
Pavel Belevich
7d58060f49 C++ API parity: AdaptiveAvgPool1d
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26808

Test Plan: Imported from OSS

Differential Revision: D17627827

Pulled By: pbelevich

fbshipit-source-id: 13ad1d0414e7b62f4fc2f6573332bb2c07b16b53
2019-09-28 10:23:31 -07:00
Pavel Belevich
5aa01fd89a C++ API parity: AdaptiveMaxPool3d
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26775

Test Plan: Imported from OSS

Differential Revision: D17627824

Pulled By: pbelevich

fbshipit-source-id: c4ae077ea5575c5d1df795e74a0dcb74a695ad06
2019-09-27 15:31:37 -07:00
Pavel Belevich
bb7a415bcc C++ API parity: AdaptiveMaxPool2d
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26772

Test Plan: Imported from OSS

Differential Revision: D17627823

Pulled By: pbelevich

fbshipit-source-id: 195f1edabbbbe245de3568beb0c7925eb347118a
2019-09-27 12:41:38 -07:00
Pavel Belevich
0a393f6ef5 C++ API parity: AdaptiveMaxPool1d
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26755

Test Plan: Imported from OSS

Differential Revision: D17627828

Pulled By: pbelevich

fbshipit-source-id: f898a4d2c269b98eb5905291914caa25bca87ce0
2019-09-27 09:10:39 -07:00
Will Feng
3cae3021e5 Add tests for C++ functional cosine_similarity and pairwise_distance, and clean up functional test code (#26559)
Summary:
This ensures that `F::cosine_similarity` and `F::pairwise_distance` can be used simply by including `torch/torch.h` and set `namespace F = torch::nn::functional`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26559

Differential Revision: D17507421

Pulled By: yf225

fbshipit-source-id: f895dde3634d5c8ca66ee036903e327e5cdab6b1
2019-09-24 09:10:42 -07:00
Will Feng
57a4b7c55d Re-organize C++ API torch::nn folder structure (#26262)
Summary:
This PR aims to re-organize C++ API `torch::nn` folder structure in the following way:
- Every module in `torch/csrc/api/include/torch/nn/modules/` (except `any.h`, `named_any.h`, `modulelist.h`, `sequential.h`, `embedding.h`) has a strictly equivalent Python file in `torch/nn/modules/`. For  example:
`torch/csrc/api/include/torch/nn/modules/pooling.h` -> `torch/nn/modules/pooling.py`
`torch/csrc/api/include/torch/nn/modules/conv.h` -> `torch/nn/modules/conv.py`
`torch/csrc/api/include/torch/nn/modules/batchnorm.h` -> `torch/nn/modules/batchnorm.py`
`torch/csrc/api/include/torch/nn/modules/sparse.h` -> `torch/nn/modules/sparse.py`
- Containers such as  `any.h`, `named_any.h`, `modulelist.h`, `sequential.h` are moved into `torch/csrc/api/include/torch/nn/modules/container/`, because their implementations are too long to be combined into one file (like `torch/nn/modules/container.py` in Python API)
- `embedding.h` is not renamed to `sparse.h` yet, because we have another work stream that works on API parity for Embedding and EmbeddingBag, and renaming the file would cause conflict. After the embedding API parity work is done, we will rename `embedding.h` to  `sparse.h` to match the Python file name, and move the embedding options out to options/ folder.
- `torch/csrc/api/include/torch/nn/functional/` is added, and the folder structure mirrors that of `torch/csrc/api/include/torch/nn/modules/`. For example, `torch/csrc/api/include/torch/nn/functional/pooling.h` contains the functions for pooling, which are then used by the pooling modules in `torch/csrc/api/include/torch/nn/modules/pooling.h`.
- `torch/csrc/api/include/torch/nn/options/` is added, and the folder structure mirrors that of `torch/csrc/api/include/torch/nn/modules/`. For example, `torch/csrc/api/include/torch/nn/options/pooling.h` contains MaxPoolOptions, which is used by both MaxPool modules in `torch/csrc/api/include/torch/nn/modules/pooling.h`, and max_pool functions in `torch/csrc/api/include/torch/nn/functional/pooling.h`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26262

Differential Revision: D17422426

Pulled By: yf225

fbshipit-source-id: c413d2a374ba716dac81db31516619bbd879db7f
2019-09-17 10:07:29 -07:00