File size: 2,270 Bytes
d842ac6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/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()