Gradient clipping in Pytorch c++ libtorch

I am trying to invoke a gradient clipping in C++ similar to this line of code in Python :

torch.nn.utils.clip_grad_norm_(Net.parameters(),0.2)

In C++ I am calling

torch::nn::utils::clip_grad_norm_(Net->parameters(), 0.2);

Can anyone kindly verify that this is the right call ?

The usage look correct and is also used in this way in this test.

1 Like