How to store and access multiple values in a single pt file?

How do I store 7 tensors and load whichever tensor i need? For example, I should be able to load the 5th tensor if I want to.

Hi @ADONAI_TZEVAOT,

You can use torch.save (docs here: torch.save — PyTorch 2.0 documentation) and just pass all your tensors within a dict object and serialize the dictionary, for example,

torch.save({'tensor1':tensor1, 'tensor2':tensor2}, filename)
1 Like

How can I append values to the file at every iteration ?