Storing a torch tensor without pickle

Hi all,

I want to store a tensor containing my results to disc. However, when using torch.save and torch.load it seems like I have to store the tensor in the same directory as the python file from which I want to load the saved file, otherwise it wont load the file. This seems to come from the fact, that pytorch internally uses pickle.
https://pytorch.org/tutorials/beginner/saving_loading_models.html

I therefore want to store my torch tensor in a different way (I dont need to take care of grad), so which would be the recommended way (simply storing the values from the tensor and the loading it again into a torch tensor)?

However, when using torch.save and torch.load it seems like I have to store the tensor in the same directory as the python file from which I want to load the saved file,

Have you tried to set the path already to something different ?

torch.save(the_model, PATH)
the_model = torch.load(PATH)

So the problem that pickle and torch save and load has is that the directory structure that was present at the time when the tensor was stored, has to be maintained otherwise it cannot be loaded as I understood it. So I really just want to know a simple way to store the data contained in a tensor and how I can make a tensor out of it again when loading it

Yes, when you import torch it will import pickle for you and you don’t need to call pickle.dump() and pickle.load() since torch.save() and torch.load() will wrap pickle.dump() and pickle.load() for you.

So strange your question is.

But isnt it possible to just store it as a CSV or JSON or sth alike? And if so, which is probably the most usefull way?

Maybe this is what You may try.