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
This commit is contained in:
Will Feng
2019-10-29 14:13:37 -07:00
committed by Facebook Github Bot
parent d8c368bd62
commit e33b4b6761
13 changed files with 196 additions and 56 deletions
+3 -3
View File
@@ -131,7 +131,7 @@ TEST_F(FunctionalTest, SoftMarginLossNoReduction) {
auto input = torch::tensor({2., 4., 1., 3.}, torch::requires_grad());
auto target = torch::tensor({-1., 1., 1., -1.}, torch::kFloat);
auto output =
F::soft_margin_loss(input, target, torch::Reduction::None);
F::soft_margin_loss(input, target, torch::kNone);
auto expected = torch::tensor({2.1269281, 0.01814993, 0.3132617, 3.0485873}, torch::kFloat);
auto s = output.sum();
s.backward();
@@ -144,7 +144,7 @@ TEST_F(FunctionalTest, MultiLabelSoftMarginLossWeightedNoReduction) {
auto input = torch::tensor({{0., 2., 2., 0.}, {2., 1., 0., 1.}}, torch::requires_grad());
auto target = torch::tensor({{0., 0., 1., 0.}, {1., 0., 1., 1.}}, torch::kFloat);
auto weight = torch::tensor({0.1, 0.6, 0.4, 0.8}, torch::kFloat);
auto options = MultiLabelSoftMarginLossOptions().reduction(torch::Reduction::None).weight(weight);
auto options = MultiLabelSoftMarginLossOptions().reduction(torch::kNone).weight(weight);
auto output =
F::multilabel_soft_margin_loss(input, target, options);
auto expected = torch::tensor({0.4876902, 0.3321295}, torch::kFloat);
@@ -491,7 +491,7 @@ TEST_F(FunctionalTest, MultiLabelMarginLossNoReduction) {
auto input = torch::tensor({{0.1, 0.2, 0.4, 0.8}}, torch::requires_grad());
auto target = torch::tensor({{3, 0, -1, 1}}, torch::kLong);
auto output = F::multilabel_margin_loss(
input, target, torch::Reduction::None);
input, target, torch::kNone);
auto expected = torch::tensor({0.8500}, torch::kFloat);
auto s = output.sum();
s.backward();