Oh, I’ve overlooked it somehow.
C = S.backward(torch.ones_like(S))

is intended to give you None as result, since it modifies the Parameters gradients in-place
you might want to use torch.autograd.grad 102 instead