Thank you! I have tried this method. It will not solve my problem.
I finally solve it by adding .clone() to output.
output = cos_theta * 1.0 
output1 = output.clone()
output[index] = output1[index]-cos_theta[index]*(1.0+0)/(1+self.lamb)
output[index] = output1[index] phi_theta[index]*(1.0+0)/(1+self.lamb)

It seems that x = x+1 is not in_place operation, but x[index] = x[index]+1 is in_place operation.
To be honest, I don’t quite understand why.