Ok I see. Now I’m still not sure if I’m doing it correctly. When I do something like this:
temp = Variable(XYZ[0].data, requires_grad=True)
if XYZ[0] > 0.008856:
    XYZ[0] = temp ** 1/3
else:
    XYZ[0] = (7.787 * temp) + (16 / 116)

then I get another error:
RuntimeError: Jacobian mismatch for output 0 with respect to input 0,
numerical:tensor([[ 0.0297,  0.1332,  0.0469],
        [ 0.0084, -0.0171,  0.0123],
        [ 0.0104,  0.0730, -0.1986]], dtype=torch.float64)
analytical:tensor([[0., 0., 0.],
        [0., 0., 0.],
        [0., 0., 0.]], dtype=torch.float64)

Whereas when I do this the gradcheck returns True:
temp = XYZ[0].clone()
if temp > 0.008856:
    XYZ[0] = temp ** 1 / 3
else:
    XYZ[0] = (7.787 * temp) + (16 / 116)

What exactly is the difference between the two? And is the second one correct?