Trouter-Library commited on
Commit
b1fc14b
·
verified ·
1 Parent(s): 41b81a7

Create upload_safetensors.py

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