DoYourBest:

  p_land[:, :, 0] = p_land[:, :, 0] / p_land[:, :, 2]
  p_land[:, :, 1] = p_land[:, :, 1] / p_land[:, :, 2]
  pt_land = p_land[:,:,:2]



Hi,
I think your issue with an in-place op might be with these lines as you are technically taking a slice on the Tensor, and the gradients of a Tensor are defined on the whole Tensor and not the individual components thereof.
Reproducing these lines throws the error,
X=torch.randn(64,10,8)
X.requires_grad=True
 
X[:,:,0] = X[:,:,0]/X[:,:,2]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation.

If you don’t specify that p_land requires a gradient, no error appears but the error will reappear when you calculate the gradient of your loss as it has no grad_fn. Try to work out a none-inplace way to calculate p_land and that should solve your problem, unless there’s another inplace op I’ve missed!