Memory mapped Tensor?

Hello,

I was wondering whether something like numpy.memmap exists in PyTorch? Or should I just save as a numpy array and use numpy.memmap instead, because conversion to torch tensors is cheap?

Numpy: https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.memmap.html

2 Likes

You can use torch.Storage.from_file (docs):

e.g.

x = torch.IntTensor(torch.IntStorage.from_file('file.bin', size=100))
1 Like

Is there a way to store the data to memory mapped files as well. Does Pytorch have a method for this?

Check this feature from TorchRL if you’re interested in it: