-
-
Save rvkwi/2df007fa3d6249474e18a7aa47d42507 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# trims safetensors file of addtional data rewriting only tensors | |
# CAREFUL, this will remove all metadata as well | |
# requires safetensors==0.2.7, torch==2.0.0, numpy==1.24.2 | |
import sys | |
import safetensors | |
from safetensors.torch import save_file | |
files = [] | |
try: | |
for a in sys.argv: | |
if a.endswith(".safetensors"): files.append(a) | |
except: | |
print("no path. quitting") | |
sys.exit() | |
for file in files: | |
print("Processing %s" %(file)) | |
tensors = {} | |
with safetensors.safe_open(file, framework="pt", device=0) as f: | |
for k in f.keys(): tensors[k] = f.get_tensor(k) | |
save_file(tensors, file.replace(".safetensors", "_trim.safetensors")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment