Я экспериментирую с разными функциями потерь для модели. Когда я пытаюсь использовать функции loggamma и digamma, я получаю сообщение «RuntimeError: polygamma (n, x) не реализована для n> = 2, но была ошибка 2». Вот пример кода, воспроизводящего ошибку:
import torch
init_var = torch.randn([1,2], requires_grad = True)
x = torch.randn([1,2])
y = (init_var*x)
gt = torch.randn([1,2])
log_gamma_res = torch.digamma(y) #y
loss = (gt - log_gamma_res).sum()
grad = torch.autograd.grad(loss,init_var, create_graph = True)[0]
loss2 = (y - grad).sum()
loss2.backward()
Сообщение об ошибке:
RuntimeError: polygamma(n,x) is not implemented for n>=2, but was 2 (polygamma_kernel at /opt/conda/conda-bld/pytorch_1587428398394/work/build/aten/src/ATen/native/cpu/UnaryOpsKernel.cpp.AVX2.cpp:217)
frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x4e (0x7f2a8c4b0b5e in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libc10.so)
frame #1: <unknown function> + 0x113eff0 (0x7f2a6a7f2ff0 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #2: <unknown function> + 0xbed703 (0x7f2a6a2a1703 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #3: at::native::polygamma_out(at::Tensor&, long, at::Tensor const&) + 0x5b (0x7f2a6a294d1b in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #4: <unknown function> + 0xe9bf88 (0x7f2a6a54ff88 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #5: at::native::polygamma(long, at::Tensor const&) + 0x11a (0x7f2a6a29bf2a in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #6: <unknown function> + 0xe9c028 (0x7f2a6a550028 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #7: <unknown function> + 0xee7e30 (0x7f2a6a59be30 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #8: <unknown function> + 0x2955ef5 (0x7f2a6c009ef5 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #9: <unknown function> + 0xee7e30 (0x7f2a6a59be30 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #10: torch::autograd::generated::PolygammaBackward::apply(std::vector<at::Tensor, std::allocator<at::Tensor> >&&) + 0x189 (0x7f2a6bcb6629 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #11: <unknown function> + 0x2ae8215 (0x7f2a6c19c215 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #12: torch::autograd::Engine::evaluate_function(std::shared_ptr<torch::autograd::GraphTask>&, torch::autograd::Node*, torch::autograd::InputBuffer&) + 0x16f3 (0x7f2a6c199513 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #13: torch::autograd::Engine::thread_main(std::shared_ptr<torch::autograd::GraphTask> const&, bool) + 0x3d2 (0x7f2a6c19a2f2 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #14: torch::autograd::Engine::thread_init(int) + 0x39 (0x7f2a6c192969 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_cpu.so)
frame #15: torch::autograd::python::PythonEngine::thread_init(int) + 0x38 (0x7f2a6f2d7558 in /home/deep/anaconda3/lib/python3.7/site-packages/torch/lib/libtorch_python.so)
frame #16: <unknown function> + 0xc819d (0x7f2ab33d619d in /home/deep/anaconda3/lib/python3.7/site-packages/matplotlib/../../../libstdc++.so.6)
frame #17: <unknown function> + 0x76db (0x7f2ac7ef96db in /lib/x86_64-linux-gnu/libpthread.so.0)
frame #18: clone + 0x3f (0x7f2ac7c2288f in /lib/x86_64-linux-gnu/libc.so.6)