TubeGenius / modal_deployments /cache_model.py
Shreyashgupta5's picture
Remove cache_model.py script and update references in README.md and performance-optimization.md to reflect the new path for model caching. This change ensures consistency in instructions for initializing the SDXL model cache using Modal storage.
1a92033
Raw History Blame Contribute Delete
2.3 kB
#!/usr/bin/env python3
"""
Utility script to initialize the SDXL model cache for faster thumbnail generation.
Run this script once to download and cache the base SDXL model to Modal storage.
After running this, all future thumbnail generations will be much faster since
the model won't need to be downloaded from HuggingFace each time.
Usage:
python modal_deployments/cache_model.py
"""
import modal
import sys
def main():
"""Initialize the SDXL model cache"""
print("πŸš€ Starting SDXL model cache initialization...")
print("⏰ This will take about 5-10 minutes but only needs to be done once.")
print("πŸ’‘ After this completes, all future thumbnail generations will be much faster!\n")
try:
# Use Modal CLI to call the function directly
import subprocess
print("πŸ”§ Calling Modal function via CLI...")
result = subprocess.run([
"modal", "run",
"modal_deployments.modal_functions::initialize_model_cache"
], capture_output=True, text=True, timeout=1800)
if result.returncode == 0:
print("βœ… SUCCESS!")
print("SDXL model cached successfully! Future generations will be much faster.")
print("\nπŸŽ‰ Your SDXL model is now cached! Future thumbnail generations will be much faster.")
print("πŸ“ˆ Expected speedup: ~30-40 seconds saved per generation")
else:
print("❌ ERROR!")
print("Failed to cache SDXL model.")
print(f"Error output: {result.stderr}")
return 1
except subprocess.TimeoutExpired:
print("⏰ Cache initialization is taking longer than expected (30 minutes).")
print("This is normal for the first download. Please check Modal dashboard for progress.")
return 1
except Exception as e:
print(f"❌ Failed to initialize model cache: {e}")
print("\nπŸ”§ Troubleshooting:")
print("1. Make sure you have Modal CLI installed and configured")
print("2. Ensure your Modal app is deployed: modal deploy modal_deployments/modal_functions.py")
print("3. Check your internet connection")
return 1
return 0
if __name__ == "__main__":
sys.exit(main())