#!/usr/bin/env python3 """ Startup script for Hugging Face Zero GPU environments Prevents infinite TorchInductor warning loops and ensures proper startup. """ import os import sys import warnings def setup_zero_gpu_environment(): """Setup environment variables and warnings for Zero GPU.""" print("🌐 Setting up Hugging Face Zero GPU environment...") # Disable all problematic PyTorch features os.environ["TORCH_LOGS"] = "off" os.environ["TORCH_COMPILE_DEBUG"] = "0" os.environ["TORCH_SHOW_CPP_STACKTRACES"] = "0" os.environ["TORCH_USE_CUDA_DSA"] = "0" os.environ["CUDA_LAUNCH_BLOCKING"] = "0" os.environ["TORCH_COMPILE"] = "0" os.environ["TORCH_DYNAMO_DISABLE"] = "1" # Memory optimization os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:64" # Suppress all problematic warnings warnings.filterwarnings("ignore", category=UserWarning, module="torch._inductor") warnings.filterwarnings("ignore", message=".*aten.unsqueeze.default is missing a c-shim implementation.*") warnings.filterwarnings("ignore", message=".*using proxy executor as fallback.*") warnings.filterwarnings("ignore", message=".*Torchinductor.*") warnings.filterwarnings("ignore", message=".*cudagraphs.*") warnings.filterwarnings("ignore", message=".*Not enough SMs.*") print("āœ… Zero GPU environment configured") print("āœ… TorchInductor warnings suppressed") print("āœ… Ready to start application") def main(): """Main startup function.""" # Check if we're in Zero GPU environment if not (os.environ.get("SPACE_ID") and "zero" in os.environ.get("SPACE_ID", "").lower()): print("āš ļø Not running in Zero GPU environment") print("Starting with standard configuration...") os.system("python app.py") return # Setup Zero GPU environment setup_zero_gpu_environment() # Start the application print("\nšŸš€ Starting Qwen Face Infusion application...") try: os.system("python app.py") except KeyboardInterrupt: print("\nšŸ›‘ Application stopped by user") except Exception as e: print(f"\nāŒ Error starting application: {e}") if __name__ == "__main__": main()