Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first and second order derivative of gamma samples #1170

Open
MaximilianPi opened this issue May 21, 2024 · 1 comment
Open

first and second order derivative of gamma samples #1170

MaximilianPi opened this issue May 21, 2024 · 1 comment

Comments

@MaximilianPi
Copy link

Hi @dfalbel,

Why can I calculate the first but not the second order derivative of gamma samples? It would be really great if I could .

alpha = torch_tensor(0.5, requires_grad = TRUE)
beta = torch_tensor(0.5, requires_grad = TRUE)

sample = torch::distr_gamma(alpha, beta)$rsample(10L)
loss = sample$sum()
g = torch::autograd_grad(loss, alpha, retain_graph = TRUE, create_graph = TRUE)
gg = torch::autograd_grad(g[[1]], alpha)
Error in cpp_autograd_grad(outputs, inputs, grad_outputs, retain_graph,  : 
  the derivative for '_standard_gamma_grad' is not implemented.
Exception raised from not_implemented_base at /Users/dfalbel/Documents/actions-runner/mlverse-m1/_work/libtorch-mac-m1/libtorch-mac-m1/pytorch/torch/csrc/autograd/FunctionsManual.cpp:110 (most recent call first):
frame #0: at::Tensor torch::autograd::generated::details::not_implemented_base<at::Tensor>(char const*, char const*) + 216 (0x15d348ab0 in libtorch_cpu.dylib)
frame #1: torch::autograd::generated::StandardGammaGradBackward0::apply(std::__1::vector<at::Tensor, std::__1::allocator<at::Tensor>>&&) + 88 (0x15b9b54d4 in libtorch_cpu.dylib)
frame #2: torch::autograd::Node::operator()(std::__1::vector<at::Tensor, std::__1::allocator<at::Tensor>>&&) + 120 (0x15c95b078 in libtorch_cpu.dylib)
frame #3: torch::autograd::Engine::evaluate_function(std::__1::shared_ptr<torch::autograd::GraphTask>&, torch::autograd::Node*, torch::autograd::InputBuffer&, std::__1::shared_ptr<torch::autograd::ReadyQueue> const&) + 2932 (0x1
@MaximilianPi MaximilianPi changed the title first and second order derivative gamma first and second order derivative of gamma samples May 21, 2024
@dfalbel
Copy link
Member

dfalbel commented May 21, 2024

It looks like it's not implemented yet in torch yet, unfortunately:

https://github.com/pytorch/pytorch/blob/980f5ac0499447cd6d39b6241ae30ae30937a3e5/tools/autograd/derivatives.yaml#L1926-L1927

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants