Spaces:
Running
Running
Fix model recovery and deployment scripts - add safetensors support and Windows compatibility
Browse files- cloud_deploy.py +9 -6
- quick_deploy.py +72 -0
cloud_deploy.py
CHANGED
|
@@ -7,6 +7,7 @@ Run this directly on your cloud instance to deploy your trained model
|
|
| 7 |
import os
|
| 8 |
import sys
|
| 9 |
import logging
|
|
|
|
| 10 |
from pathlib import Path
|
| 11 |
|
| 12 |
# Setup logging
|
|
@@ -78,18 +79,20 @@ def main():
|
|
| 78 |
|
| 79 |
logger.info(f"Running: {' '.join(cmd)}")
|
| 80 |
|
| 81 |
-
# Run the command
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
if result == 0:
|
| 85 |
logger.info("β
Model deployment completed successfully!")
|
| 86 |
logger.info(f"π View your model at: https://huggingface.co/{REPO_NAME}")
|
| 87 |
logger.info("π Quantized models available at:")
|
| 88 |
logger.info(f" - https://huggingface.co/{REPO_NAME}/int8 (GPU optimized)")
|
| 89 |
logger.info(f" - https://huggingface.co/{REPO_NAME}/int4 (CPU optimized)")
|
| 90 |
return 0
|
| 91 |
-
|
| 92 |
-
logger.error("β Model deployment failed!")
|
|
|
|
|
|
|
|
|
|
| 93 |
return 1
|
| 94 |
|
| 95 |
if __name__ == "__main__":
|
|
|
|
| 7 |
import os
|
| 8 |
import sys
|
| 9 |
import logging
|
| 10 |
+
import subprocess
|
| 11 |
from pathlib import Path
|
| 12 |
|
| 13 |
# Setup logging
|
|
|
|
| 79 |
|
| 80 |
logger.info(f"Running: {' '.join(cmd)}")
|
| 81 |
|
| 82 |
+
# Run the command using subprocess for better argument handling
|
| 83 |
+
try:
|
| 84 |
+
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
|
|
|
|
| 85 |
logger.info("β
Model deployment completed successfully!")
|
| 86 |
logger.info(f"π View your model at: https://huggingface.co/{REPO_NAME}")
|
| 87 |
logger.info("π Quantized models available at:")
|
| 88 |
logger.info(f" - https://huggingface.co/{REPO_NAME}/int8 (GPU optimized)")
|
| 89 |
logger.info(f" - https://huggingface.co/{REPO_NAME}/int4 (CPU optimized)")
|
| 90 |
return 0
|
| 91 |
+
except subprocess.CalledProcessError as e:
|
| 92 |
+
logger.error(f"β Model deployment failed!")
|
| 93 |
+
logger.error(f"Error: {e}")
|
| 94 |
+
logger.error(f"stdout: {e.stdout}")
|
| 95 |
+
logger.error(f"stderr: {e.stderr}")
|
| 96 |
return 1
|
| 97 |
|
| 98 |
if __name__ == "__main__":
|
quick_deploy.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Quick Model Deployment Script
|
| 4 |
+
Direct deployment without argument parsing issues
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import os
|
| 8 |
+
import sys
|
| 9 |
+
import logging
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
# Add src to path for imports
|
| 13 |
+
sys.path.append(os.path.join(os.path.dirname(__file__), 'src'))
|
| 14 |
+
|
| 15 |
+
# Setup logging
|
| 16 |
+
logging.basicConfig(
|
| 17 |
+
level=logging.INFO,
|
| 18 |
+
format='%(asctime)s - %(levelname)s - %(message)s'
|
| 19 |
+
)
|
| 20 |
+
logger = logging.getLogger(__name__)
|
| 21 |
+
|
| 22 |
+
def main():
|
| 23 |
+
"""Direct deployment without argument parsing"""
|
| 24 |
+
|
| 25 |
+
# Configuration
|
| 26 |
+
MODEL_PATH = "/output-checkpoint"
|
| 27 |
+
REPO_NAME = "Tonic/smollm3-finetuned"
|
| 28 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
| 29 |
+
|
| 30 |
+
if not HF_TOKEN:
|
| 31 |
+
logger.error("β HF_TOKEN not set")
|
| 32 |
+
return 1
|
| 33 |
+
|
| 34 |
+
if not Path(MODEL_PATH).exists():
|
| 35 |
+
logger.error(f"β Model path not found: {MODEL_PATH}")
|
| 36 |
+
return 1
|
| 37 |
+
|
| 38 |
+
logger.info("β
Model files validated")
|
| 39 |
+
|
| 40 |
+
# Import and run the recovery pipeline directly
|
| 41 |
+
try:
|
| 42 |
+
from recover_model import ModelRecoveryPipeline
|
| 43 |
+
|
| 44 |
+
# Initialize pipeline
|
| 45 |
+
pipeline = ModelRecoveryPipeline(
|
| 46 |
+
model_path=MODEL_PATH,
|
| 47 |
+
repo_name=REPO_NAME,
|
| 48 |
+
hf_token=HF_TOKEN,
|
| 49 |
+
private=False,
|
| 50 |
+
quantize=True,
|
| 51 |
+
quant_types=["int8_weight_only", "int4_weight_only"],
|
| 52 |
+
author_name="Tonic",
|
| 53 |
+
model_description="A fine-tuned SmolLM3 model for improved text generation and conversation capabilities"
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
# Run the complete pipeline
|
| 57 |
+
success = pipeline.run_complete_pipeline()
|
| 58 |
+
|
| 59 |
+
if success:
|
| 60 |
+
logger.info("β
Model deployment completed successfully!")
|
| 61 |
+
logger.info(f"π View your model at: https://huggingface.co/{REPO_NAME}")
|
| 62 |
+
return 0
|
| 63 |
+
else:
|
| 64 |
+
logger.error("β Model deployment failed!")
|
| 65 |
+
return 1
|
| 66 |
+
|
| 67 |
+
except Exception as e:
|
| 68 |
+
logger.error(f"β Error during deployment: {e}")
|
| 69 |
+
return 1
|
| 70 |
+
|
| 71 |
+
if __name__ == "__main__":
|
| 72 |
+
exit(main())
|