Upload export_safetensors.py with huggingface_hub
Browse files- export_safetensors.py +20 -0
export_safetensors.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Optional: export the weights as model.safetensors (run on your PC, then upload alongside sft.pt).
|
| 2 |
+
|
| 3 |
+
pip install safetensors
|
| 4 |
+
python export_safetensors.py
|
| 5 |
+
"""
|
| 6 |
+
import torch
|
| 7 |
+
from safetensors.torch import save_file
|
| 8 |
+
|
| 9 |
+
ck = torch.load("sft.pt", map_location="cpu", weights_only=False)
|
| 10 |
+
sd = {k: v.contiguous() for k, v in ck["model"].items()}
|
| 11 |
+
# weight tying: drop duplicates that share storage with the token embedding
|
| 12 |
+
seen, out = {}, {}
|
| 13 |
+
for k, v in sd.items():
|
| 14 |
+
ptr = v.data_ptr()
|
| 15 |
+
if ptr in seen:
|
| 16 |
+
continue
|
| 17 |
+
seen[ptr] = k
|
| 18 |
+
out[k] = v
|
| 19 |
+
save_file(out, "model.safetensors", metadata={"format": "pt", "model": "sid-gpt-92m"})
|
| 20 |
+
print(f"Wrote model.safetensors with {len(out)} tensors")
|