I don’t fully understand your use case, but in case you are not using custom autograd.Functions, you are already breaking the computation graph, so



 Arta_A:

And I believe keeping the grad of torch tensor is crucial, So please consider this.


might not be important (assuming your current code works fine)?
In any case, I would try to use PyTorch tensors and operations only, as it would also allow you to use the GPU without moving the data back and forth between the GPU and CPU.