Sign In

Save PickleTensor .pt as PickleTensor .bin

0

Sep 10, 2024

(Updated: 5 months ago)

tool guide
Save PickleTensor .pt as PickleTensor .bin

Introductory Words

I have taken another step forward on my journey to understanding model creation.

PickleTensor as .pt File or .bin File

When dealing with Embedding models one will find, that there are .pt files and .bin files. The question arose, how can a currently more common .pt file converted into a uncommon .bin file.

Load .pt File and Save a .pt File as well as a .bin File

I started loading a .pt file and writing back a .pt file, to see, if this is working. It did. Then I used the information from the resource from below, and added _use_new_zipfile_serialization=False to the function call for saving a file.

Et voila the saved file is in bin format.

How it Works

The main two steps to do this are as follows.

# Get the 'model' data from the .pt file.
data = torch.load(pt_filename.pt, map_location="cpu", weights_only=False)
# Save the 'model' data as legacy .bin file.
torch.save(data, bin_filename.bin, _use_new_zipfile_serialization=False)

I attached a full working version of a Python3 script to this article.

Finally

Have a nice day! Have fun! Be inspired!

Reference:

https://pytorch.org/docs/stable/generated/torch.save.html

0