sid-gpt-resume-llm / export_safetensors.py
Sidhartha-Rajput's picture
Upload export_safetensors.py with huggingface_hub
98411bd verified
Raw History Blame
701 Bytes
"""Optional: export the weights as model.safetensors (run on your PC, then upload alongside sft.pt).
pip install safetensors
python export_safetensors.py
"""
import torch
from safetensors.torch import save_file
ck = torch.load("sft.pt", map_location="cpu", weights_only=False)
sd = {k: v.contiguous() for k, v in ck["model"].items()}
# weight tying: drop duplicates that share storage with the token embedding
seen, out = {}, {}
for k, v in sd.items():
ptr = v.data_ptr()
if ptr in seen:
continue
seen[ptr] = k
out[k] = v
save_file(out, "model.safetensors", metadata={"format": "pt", "model": "sid-gpt-92m"})
print(f"Wrote model.safetensors with {len(out)} tensors")