Hi Craig,
Please ignore my example that you linked, that’s a POC of what an incorrect usage of the hooks would be!
You can use the docs at Autograd mechanics — PyTorch 1.10.0 documentation 1 and at Automatic differentiation package - torch.autograd — PyTorch 1.10.0 documentation 1.
To use the example you pasted, you need to import tempfile (tempfile — Generate temporary files and directories — Python 3.9.6 documentation)