I am writing custom C++ autograd functions, and found several different declarations for undefined gradients in torch::autograd::variable_list
in the pytorch source code. (I.e. for non-differentiable inputs)
torch::Tensor()
incustom_operator/op.cpp
undef
, defined asTensor undef;
, insparse_ops_gpu.cpp
torch::autograd::Variable()
inempedding_backward_dense_host.cpp
My questions:
- What is the difference between ① and ②? Does ② skip initialization of the tensor
- Which of ①-③ is preferable?
- Would it make sense to do
static const Tensor undef;
instead of justTensor undef;
in ②? (I am new to C++)