Pytorch gradient error: nonetype unsupported operand type(s) for +: 'NoneType' and 'NoneType'
I get the following error message when i run the code given below. The code is a part of a bigger code but essentially i am computing gradients here. The variable displacements and colloc_points are of the type: tensor([[-0.0819,  0.1623,  0.1228]], grad_fn=),
tensor([[-0.0556,  2.2222,  0.1667]], requires_grad=True) respectively. How do i resolve this error?

---&gt; 43   eps_xy = 0.5*(u_y+v_x)


TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'



  u = displacement[0,0]
  v = displacement[0,1]
  w = displacement[0,2]

  print(colloc_point)

  x = colloc_point[0,0]
  y = colloc_point[0,1]
  z = colloc_point[0,2]


  ## Compute gradients

  u_y = torch.autograd.grad(u, y, create_graph=True,allow_unused=True)[0]
  v_x = torch.autograd.grad(v, x, create_graph=True,allow_unused=True)[0]

eps_xy = 0.5*(u_y+v_x)```






It is possible that, even if u, y, v and x require the gradient, u is not a function of y and, similarly v does not depend on x.
You can check this by setting allow_unused=False and see if torch.autograd.grad returns an error.
