File size: 3,021 Bytes
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
#!/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
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 = "your-username/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", "Your Name",
        "--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
    result = os.system(' '.join(cmd))
    
    if result == 0:
        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
    else:
        logger.error("❌ Model deployment failed!")
        return 1

if __name__ == "__main__":
    exit(main())