Hi,
the basic idea is to switch the backward of a function from operating on Tensors to working with Variables.
You can see this in the files in the autograd/_functions directory 137 and keep track of them via the autograd Variable mechanism. That way, the second derivative is just the derivative of the derivative, as it should be.
As far as I understand, the thing with the functions you linked is that it is either not so simple or not so efficient to do this directly by between the python-coded bits, the bits implemented in C, and the backend implementations.
Best regards
Thomas