← All articles
Published September 10, 2024by zentrocdot
Save PickleTensor .pt as PickleTensor .bin
65 views0 reactions0 comments on CivitAI0 collected
pickletensortutotialtool guideembedding

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!