PyTorch clip_grad_norm vs clip_grad_norm_, what is the differece when it has underline?
Asked Answered
O

1

6

When coding PyTorch in torch.nn.utils I see two functions, clip_grad_norm and clip_grad_norm_.

I want to know the difference so I went to check the documentation but when I searched I only found the clip_grad_norm_ and not clip_grad_norm.

So I'm here to ask if anyone knows the difference.

Owen answered 24/3, 2022 at 18:57 Comment(0)
A
5

Pytorch uses the trailing underscore convention for in-place operations. So the difference is that the one with an underscore modifies the tensor in place and the other one leaves the original tensor unmodified and returns a new tensor.

Ave answered 24/3, 2022 at 19:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.