Search code examples
libtorch

Clip the norm of the gradient in libtorch-C++


Is there any API to clip the gradients of a network? Or, I need to develop myself?

Best, Afshin


Solution

  • I found one: Tensorat::clamp(const Tensor &self, c10::optional<Scalar> min = c10::nullopt, c10::optional<Scalar> max = c10::nullopt), though I also implemented myself.