Spaces:
Running
Running
File size: 3,262 Bytes
d0d19b2 22bb04c d0d19b2 fff73fc d0d19b2 fff73fc d0d19b2 22bb04c d0d19b2 22bb04c d0d19b2 |
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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
#!/usr/bin/env python3
"""
Cloud Model Deployment Script
Run this directly on your cloud instance to deploy your trained model
"""
import os
import sys
import logging
import subprocess
from pathlib import Path
# Setup logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)
def main():
"""Main deployment function"""
# Configuration - CHANGE THESE VALUES
MODEL_PATH = "/output-checkpoint"
REPO_NAME = "Tonic/smollm3-finetuned" # Change to your HF username and desired repo name
HF_TOKEN = os.getenv('HF_TOKEN')
PRIVATE = False # Set to True for private repository
# Validate configuration
if not HF_TOKEN:
logger.error("β HF_TOKEN environment variable not set")
logger.info("Please set your Hugging Face token:")
logger.info("export HF_TOKEN=your_token_here")
return 1
if not Path(MODEL_PATH).exists():
logger.error(f"β Model path not found: {MODEL_PATH}")
return 1
# Check for required files
required_files = ['config.json', 'model.safetensors.index.json', 'tokenizer.json']
for file in required_files:
if not (Path(MODEL_PATH) / file).exists():
logger.error(f"β Required file not found: {file}")
return 1
logger.info("β
Model files validated")
# Install dependencies if needed
try:
import torchao
logger.info("β
torchao available")
except ImportError:
logger.info("π¦ Installing torchao...")
os.system("pip install torchao")
try:
import huggingface_hub
logger.info("β
huggingface_hub available")
except ImportError:
logger.info("π¦ Installing huggingface_hub...")
os.system("pip install huggingface_hub")
# Run the recovery script
logger.info("π Starting model deployment...")
cmd = [
sys.executable, "recover_model.py",
MODEL_PATH,
REPO_NAME,
"--hf-token", HF_TOKEN,
"--quant-types", "int8_weight_only", "int4_weight_only",
"--author-name", "Tonic",
"--model-description", "A fine-tuned SmolLM3 model for improved text generation and conversation capabilities"
]
if PRIVATE:
cmd.append("--private")
logger.info(f"Running: {' '.join(cmd)}")
# Run the command using subprocess for better argument handling
try:
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
logger.info("β
Model deployment completed successfully!")
logger.info(f"π View your model at: https://huggingface.co/{REPO_NAME}")
logger.info("π Quantized models available at:")
logger.info(f" - https://huggingface.co/{REPO_NAME}/int8 (GPU optimized)")
logger.info(f" - https://huggingface.co/{REPO_NAME}/int4 (CPU optimized)")
return 0
except subprocess.CalledProcessError as e:
logger.error(f"β Model deployment failed!")
logger.error(f"Error: {e}")
logger.error(f"stdout: {e.stdout}")
logger.error(f"stderr: {e.stderr}")
return 1
if __name__ == "__main__":
exit(main()) |