From: vishwakftw Date: Fri, 14 Dec 2018 04:30:40 +0000 (-0800) Subject: Fix derivative for mvlgamma (#15049) X-Git-Tag: accepted/tizen/6.5/unified/20211028.231830~2247 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=81644ed9abbc1690833ea4466a938c04ca584e65;p=platform%2Fupstream%2Fpytorch.git Fix derivative for mvlgamma (#15049) Summary: Fixes #15015. Added tests to validate derivative. Pull Request resolved: https://github.com/pytorch/pytorch/pull/15049 Reviewed By: soumith Differential Revision: D13434117 Pulled By: zou3519 fbshipit-source-id: 4a292600af9eb08b67c0f8b5482e9512aac95e72 --- diff --git a/test/common_methods_invocations.py b/test/common_methods_invocations.py index 043e874..c4e2d9e 100644 --- a/test/common_methods_invocations.py +++ b/test/common_methods_invocations.py @@ -458,6 +458,10 @@ method_tests = [ NO_ARGS, [skipIfNoLapack]), ('matrix_power', lambda: random_fullrank_matrix_distinct_singular_value(S, S), [-2], "n=-2", NO_ARGS, [skipIfNoLapack]), + ('mvlgamma', torch.empty(S,).uniform_(0.5, 1), [1], "p=1"), + ('mvlgamma', torch.empty(S,).uniform_(1, 2), [2], "p=2"), + ('mvlgamma', torch.empty(S, S).uniform_(1.5, 3), [3], "p=3"), + ('mvlgamma', torch.empty(S, S).uniform_(2.5, 5), [5], "p=5"), ('addcmul', (S, S), ((S, S), (S, S))), ('addcmul', (S, S), ((S, 1), (1, S)), 'broadcast_rhs'), ('addcmul', (1,), ((S, S, 1), (1, S)), 'broadcast_all'), diff --git a/test/test_jit.py b/test/test_jit.py index 1c76d68..ae6ba8d 100644 --- a/test/test_jit.py +++ b/test/test_jit.py @@ -10822,7 +10822,6 @@ def add_autograd_test( args_variable, kwargs_variable = create_input(args, requires_grad=not is_inplace, call_kwargs=kwargs) self_tensor = deepcopy(self_variable.data) args_tensor = deepcopy(unpack_variables(args_variable)) - output_variable = getattr(self_variable, name)(*args_variable, **kwargs_variable) def fn(*inputs, **kwargs): output = getattr(inputs[0], name)(*inputs[1:], **kwargs) diff --git a/tools/autograd/templates/Functions.cpp b/tools/autograd/templates/Functions.cpp index 8d71ba6..308865f 100644 --- a/tools/autograd/templates/Functions.cpp +++ b/tools/autograd/templates/Functions.cpp @@ -144,9 +144,9 @@ Tensor pow_backward_exponent(Tensor grad, const Scalar & base, const Tensor & ex } Tensor mvlgamma_backward(Tensor grad, const Tensor & self, int64_t p) { - Tensor args = at::arange(-p + 1, 1, -1, self.options()).div_(2.); + Tensor args = at::arange(-p / 2. + 0.5, 0.5, 0.5, self.options()); args = args.add(self.unsqueeze(-1)); - return grad * args.digamma_().sum(-1).add_(p * (p - 1) * std::log(M_PI) / 4.); + return grad * args.digamma_().sum(-1); } Tensor permute_backwards(const Tensor & grad, IntList fwd_dims) {