Hi Aerys!



 AerysS:

I need it separately to apply to a tensor and do not need its gradients. So in that case, I can warp it with no_grad and it will be fine right?


Roughly speaking, whether computations are tracked for potential future
gradient computation depends on the tensor being passed through the
function, rather than on the function itself.
In short, I wouldn’t worry about it.  Even if you pass a tensor with
requires_grad = True through your function, your function’s
backward() will only be called if you call backward() on something
that depends on the result of calling your function.
(If you do call your function on a tensor with requires_grad = True
and you know that you won’t be needing the associated gradient,
you can wrap your function call in a  with torch.no_grad(): block
to save on the overhead of building that branch of the computation
graph.  But I would wrap the function call rather than the innards of
the function itself.)
Best.
K. Frank