Update upload_directly_to_hf.py
Browse files- upload_directly_to_hf.py +17 -16
upload_directly_to_hf.py
CHANGED
|
@@ -1,21 +1,19 @@
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
Create and upload SafeTensors DIRECTLY to Hugging Face
|
| 4 |
-
|
| 5 |
"""
|
| 6 |
|
| 7 |
import torch
|
| 8 |
import json
|
| 9 |
from safetensors.torch import save_file
|
| 10 |
-
from huggingface_hub import HfApi
|
| 11 |
import tempfile
|
| 12 |
-
import math
|
| 13 |
from pathlib import Path
|
| 14 |
|
| 15 |
-
# ============ CONFIGURE THIS ============
|
| 16 |
-
REPO_NAME = "
|
| 17 |
-
|
| 18 |
-
# ========================================
|
| 19 |
|
| 20 |
def initialize_weights(shape, init_type="normal", std=0.02):
|
| 21 |
"""Initialize tensor with proper initialization"""
|
|
@@ -164,15 +162,15 @@ def create_mineral_nano_weights():
|
|
| 164 |
|
| 165 |
return state_dict
|
| 166 |
|
| 167 |
-
def upload_to_huggingface(state_dict, repo_name
|
| 168 |
-
"""Upload SafeTensors directly to Hugging Face"""
|
| 169 |
|
| 170 |
print(f"\n{'='*60}")
|
| 171 |
print(f"Uploading to Hugging Face: {repo_name}")
|
| 172 |
print(f"{'='*60}")
|
| 173 |
|
| 174 |
-
# Initialize HF API
|
| 175 |
-
api = HfApi(
|
| 176 |
|
| 177 |
# Create temporary directory for files
|
| 178 |
with tempfile.TemporaryDirectory() as temp_dir:
|
|
@@ -268,16 +266,19 @@ if __name__ == "__main__":
|
|
| 268 |
print("="*60)
|
| 269 |
|
| 270 |
# Verify configuration
|
| 271 |
-
if "your-username" in REPO_NAME
|
| 272 |
print("\n❌ ERROR: Please configure the script first!")
|
| 273 |
-
print("\nEdit
|
| 274 |
print(f' REPO_NAME = "your-username/mineral-nano-1"')
|
| 275 |
-
print(
|
| 276 |
-
print("\
|
|
|
|
| 277 |
exit(1)
|
| 278 |
|
| 279 |
print(f"\nTarget repository: {REPO_NAME}")
|
| 280 |
print("This will take 10-20 minutes...")
|
|
|
|
|
|
|
| 281 |
|
| 282 |
# Create weights
|
| 283 |
print("\n" + "="*60)
|
|
@@ -289,6 +290,6 @@ if __name__ == "__main__":
|
|
| 289 |
print("\n" + "="*60)
|
| 290 |
print("STEP 2: Uploading to Hugging Face")
|
| 291 |
print("="*60)
|
| 292 |
-
upload_to_huggingface(state_dict, REPO_NAME
|
| 293 |
|
| 294 |
print("\n✅ All done! Your model is live on Hugging Face!")
|
|
|
|
| 1 |
#!/usr/bin/env python3
|
| 2 |
"""
|
| 3 |
Create and upload SafeTensors DIRECTLY to Hugging Face
|
| 4 |
+
Uses secure login - NO TOKEN IN CODE!
|
| 5 |
"""
|
| 6 |
|
| 7 |
import torch
|
| 8 |
import json
|
| 9 |
from safetensors.torch import save_file
|
| 10 |
+
from huggingface_hub import HfApi
|
| 11 |
import tempfile
|
|
|
|
| 12 |
from pathlib import Path
|
| 13 |
|
| 14 |
+
# ============ CONFIGURE ONLY THIS ============
|
| 15 |
+
REPO_NAME = "Luke-Bergen/mineral-nano-1" # CHANGE THIS to your HF username!
|
| 16 |
+
# =============================================
|
|
|
|
| 17 |
|
| 18 |
def initialize_weights(shape, init_type="normal", std=0.02):
|
| 19 |
"""Initialize tensor with proper initialization"""
|
|
|
|
| 162 |
|
| 163 |
return state_dict
|
| 164 |
|
| 165 |
+
def upload_to_huggingface(state_dict, repo_name):
|
| 166 |
+
"""Upload SafeTensors directly to Hugging Face using saved credentials"""
|
| 167 |
|
| 168 |
print(f"\n{'='*60}")
|
| 169 |
print(f"Uploading to Hugging Face: {repo_name}")
|
| 170 |
print(f"{'='*60}")
|
| 171 |
|
| 172 |
+
# Initialize HF API (uses saved token from huggingface-cli login)
|
| 173 |
+
api = HfApi()
|
| 174 |
|
| 175 |
# Create temporary directory for files
|
| 176 |
with tempfile.TemporaryDirectory() as temp_dir:
|
|
|
|
| 266 |
print("="*60)
|
| 267 |
|
| 268 |
# Verify configuration
|
| 269 |
+
if "your-username" in REPO_NAME:
|
| 270 |
print("\n❌ ERROR: Please configure the script first!")
|
| 271 |
+
print("\nEdit this line at the top of the script:")
|
| 272 |
print(f' REPO_NAME = "your-username/mineral-nano-1"')
|
| 273 |
+
print("\nChange 'your-username' to YOUR HuggingFace username")
|
| 274 |
+
print("\nThen run: huggingface-cli login")
|
| 275 |
+
print("(Paste your token when prompted)")
|
| 276 |
exit(1)
|
| 277 |
|
| 278 |
print(f"\nTarget repository: {REPO_NAME}")
|
| 279 |
print("This will take 10-20 minutes...")
|
| 280 |
+
print("\nMake sure you ran: huggingface-cli login")
|
| 281 |
+
input("\nPress ENTER to continue or Ctrl+C to cancel...")
|
| 282 |
|
| 283 |
# Create weights
|
| 284 |
print("\n" + "="*60)
|
|
|
|
| 290 |
print("\n" + "="*60)
|
| 291 |
print("STEP 2: Uploading to Hugging Face")
|
| 292 |
print("="*60)
|
| 293 |
+
upload_to_huggingface(state_dict, REPO_NAME)
|
| 294 |
|
| 295 |
print("\n✅ All done! Your model is live on Hugging Face!")
|