Commit Graph

175 Commits

Author SHA1 Message Date
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
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
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
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
07d4374239 C++ API: torch::nn::Softmax2d (#27509)
Summary:
Add torch::nn::Softmax2d module support for the C++ API.
Softmax2d only supports module in Python API, so this PR adds only module support as well.

This PR is WIP because it uses the function in https://github.com/pytorch/pytorch/issues/27446 .
After https://github.com/pytorch/pytorch/issues/27446 is merged, I will remove WIP.

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

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

Differential Revision: D17899715

Pulled By: yf225

fbshipit-source-id: bd891bc995f5a92bf4f5405f8bf07d1bd5de2479
2019-10-13 11:00:56 -07:00
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
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
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
2750ea25b2 C++ API parity: Tanh
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27536

Test Plan: Imported from OSS

Differential Revision: D17835411

Pulled By: pbelevich

fbshipit-source-id: c8984aec2f4bae48ff901fafc8c53a4122192ac5
2019-10-13 06:34:18 -07:00
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
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
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
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
9d448099fd C++ API parity: Sigmoid
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27488

Test Plan: Imported from OSS

Differential Revision: D17835405

Pulled By: pbelevich

fbshipit-source-id: 78e13047a2a1f2776c59e778db7ba120716e93d3
2019-10-11 07:45:31 -07:00
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
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
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
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
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
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
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
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
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
a37be201c1 Implement torch.nn.Embedding / EmbeddingBag in PyTorch C++ API (#26358)
Summary:
added more variables to EmbeddingOptions and updated EmbeddingImpl reset, forward functions. Also added EmbeddingBag.

-----

This PR is BC-breaking in the following way:

Previously, `EmbeddingOptions` supports `count` and `dimension` as options arguments. After this PR, they are renamed to `num_embeddings` and `embedding_dim` respectively.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26358

Differential Revision: D17714337

Pulled By: yf225

fbshipit-source-id: f9f969c68e4bece106b92f8e2e02ac39c8455fb7
2019-10-08 22:13:39 -07:00
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
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
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
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
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
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
5005f7bce7 C++ API parity: MaxUnpool3d
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/27027

Test Plan: Imported from OSS

Differential Revision: D17682402

Pulled By: pbelevich

fbshipit-source-id: 2008ce405176c174cdba88b4f25cd77a82bb13ea
2019-10-02 05:40:42 -07:00
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
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
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
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
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
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
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
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
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
b5d15315d8 Improve C++ maxpool and avgpool (#26521)
Summary:
This PR makes the following improvements:
1. Add `forward_with_indices` method to all C++ MaxPool modules, to return the max indices along with the outputs. (We can't make two `forward` methods that return different types based on input, because that will break the type deduction of `torch::detail::return_type_of_forward_t`)
2. Add `max_poolNd_with_indices` to `torch::nn::functional`, to be used when indices of the max values are needed. (We can't merge this with `torch::nn::functional::max_poolNd` because the return type of `max_poolNd` has to be defined statically).
3. Improve `pretty_print` of C++ MaxPoolNd and AvgPoolNd modules to match the Python `extra_repr`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26521

Differential Revision: D17507358

Pulled By: yf225

fbshipit-source-id: b6c0e2b27b38378cdc0c75f4bfc797b3c6b17cd9
2019-09-25 13:52:58 -07:00
5e5b9a9321 Add C++ nn::Identity (#26713)
Summary:
**Summary**:
Adds `torch::nn::Identity` 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/26713

Differential Revision: D17550982

Pulled By: yf225

fbshipit-source-id: f24483846e82d5d276d77a1a0c50884f3bc05112
2019-09-24 16:29:49 -07:00
da8fbe5bf0 Minor improvement to C++ nn::Distance tests (#26539)
Summary:
C++ `nn::Distance` tests can take advantage of the newly released multi-dimensional tensor constructor https://github.com/pytorch/pytorch/pull/26210 to simplify the tensor constructions.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26539

Differential Revision: D17501041

Pulled By: yf225

fbshipit-source-id: 21d5f95ab3ec02227115c823c581218cee2ce458
2019-09-20 12:40:52 -07:00
872ca919a9 Distance module (#26424)
Summary:
Adds `Distance` module parity.
https://github.com/pytorch/pytorch/issues/25883
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26424

Differential Revision: D17487314

Pulled By: yf225

fbshipit-source-id: c7d124cb4afb08a4733e7212af0bb276bf32d172
2019-09-20 07:28:49 -07:00
98ccae09af C++ API parity: at::Tensor::grad
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/26150

Test Plan: Imported from OSS

Differential Revision: D17427579

Pulled By: pbelevich

fbshipit-source-id: 68d012076aa86dee9f23fad71a2d265d75f56d22
2019-09-18 09:20:38 -07:00
28a2dafc15 C++ Average Pool Module (#25800)
Summary:
This PR adds Average Pool module to C++ front-end.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/25800

Differential Revision: D17318094

Pulled By: yf225

fbshipit-source-id: c914c0e802bbe5f1d1f0a21a669c28bc956899db
2019-09-11 16:39:56 -07:00
ba9fda14a7 C++ MaxPool Module
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/24860

Differential Revision: D17260361

Pulled By: yf225

fbshipit-source-id: 4b8c894d3bdf675cfeb9fc84934fe0339a048c1e
2019-09-11 08:56:57 -07:00
e04836004d L1Loss module (#25902)
Summary:
yf225 This is L1Loss module. I don't think that ```_Loss``` and ```_WeightedLoss``` as base Python classes do anything. First one sets reduction type and also takes in ```reduce``` parameter which is deprecated. The second one only registers ```weight``` parameter. I don't think that we should keep this structure. What do you think?
Pull Request resolved: https://github.com/pytorch/pytorch/pull/25902

Differential Revision: D17307045

Pulled By: yf225

fbshipit-source-id: ad3eda2ee8dcf4465054b376c1be89b39d11532f
2019-09-11 07:18:17 -07:00
a88f310151 Simplify header inclusion in test/cpp/api/modules.cpp (#25921)
Summary:
This PR simplifies header inclusion in `test/cpp/api/modules.cpp`, so that when we add a new `torch::nn` module and add the test in `modules.cpp`, we can check that the new module's header is included in `torch/torch.h`.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/25921

Differential Revision: D17303220

Pulled By: yf225

fbshipit-source-id: 327db0ff2f075d52e7b594b3dffc5a59441e0931
2019-09-10 18:37:39 -07:00
3680cef44e C++ Fold nn module
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/24160

Differential Revision: D17260740

Pulled By: yf225

fbshipit-source-id: f0c7769316bed330289ca3d948f2e39c72ec928b
2019-09-10 13:19:37 -07:00