Thanks Victor for the pointers to the new functionality! Is there a concrete example of what pack_hook and unpack_hook should look like? I tried your example here but have no idea why you have inc() and lambda x: x as pack and unpack hooks, and do not really understand why f("cpu") and f("cuda") have seemingly arbitrarily large values between the set and reset hook functions.
Also, in your example
    class SelfClosingTempFile():
        def __init__(self):
            self.fp = tempfile.TemporaryFile()

        def __del__(self):
            self.fp.close()

    def pack_hook(tensor):
        sctf = SelfClosingTempFile()
        torch.save(tensor, sctf.fp)
        return sctf

    def unpack_hook(sctf):
        sctf.fp.seek(0)
        return torch.load(sctf.fp)

what should tempfile.TemporaryFile() be?