def f (x, u):
    return x.pow(2)+u.pow(2)
y = f(x,u)
yx = grad(y, x, create_graph=True)[0]
print(yx)
yxu = grad(yx,u,allow_unused=True)[0]
print(yxu)

output:
        tensor([4.], grad_fn=<ThMulBackward>)
        None

Mathematically the above second derivative should be zero, right?