File size: 784 Bytes
b1fc14b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# upload_safetensors.py
from huggingface_hub import HfApi
from safetensors.torch import save_file
import torch
import io
# Replace with your HF token and repo
token = "hf_your_token_here"
repo_id = "yourname/Trouter-20b"
api = HfApi(token=token)
# Loop to create and upload 5 in-memory safetensors
for i in range(1, 6):
# Create dummy tensor
weights = {f"layer{i}.weight": torch.randn(2, 2)}
# Save tensor to in-memory buffer
buffer = io.BytesIO()
save_file(weights, buffer)
buffer.seek(0)
# Upload directly to Hugging Face
api.upload_file(
path_or_fileobj=buffer,
path_in_repo=f"part{i}.safetensors",
repo_id=repo_id,
repo_type="model"
)
print(f"✅ Uploaded part{i}.safetensors directly to Hugging Face")
|