Download export_safetensors.py from Sidhartha-Rajput/sid-gpt-resume-llm: direct link, hf CLI and curl.
- Browser
- Download file 701 Bytes
-
https://huggingface.co/Sidhartha-Rajput/sid-gpt-resume-llm/resolve/dbe374a4599524625ecc410fa20d3d5b30ab018b/export_safetensors.py
- Command line
-
hf download hf://Sidhartha-Rajput/sid-gpt-resume-llm@dbe374a4599524625ecc410fa20d3d5b30ab018b/export_safetensors.py
-
curl -L -o export_safetensors.py https://huggingface.co/Sidhartha-Rajput/sid-gpt-resume-llm/resolve/dbe374a4599524625ecc410fa20d3d5b30ab018b/export_safetensors.py
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") | |