File size: 2,464 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 | """
Zero GPU Configuration for Hugging Face Spaces
Optimized for Hugging Face Zero GPU environments to prevent infinite warning loops.
"""
import os
import warnings
def configure_zero_gpu():
"""Configure the environment specifically for Hugging Face Zero GPU."""
print("🌐 Configuring for Hugging Face Zero GPU environment...")
# Suppress all TorchInductor warnings that cause infinite loops
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.*")
# Set environment variables to disable problematic 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"
# Disable PyTorch compilation features that cause issues
os.environ["TORCH_COMPILE"] = "0"
os.environ["TORCH_DYNAMO_DISABLE"] = "1"
# Memory optimization for Zero GPU
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "max_split_size_mb:64"
print("✅ Zero GPU configuration applied")
print("⚠️ Pipeline optimization disabled for compatibility")
print("✅ Ready for inference without compilation warnings")
def is_zero_gpu_environment():
"""Check if running in Hugging Face Zero GPU environment."""
return (
os.environ.get("SPACE_ID") is not None and
"zero" in os.environ.get("SPACE_ID", "").lower()
)
def get_zero_gpu_settings():
"""Get optimized settings for Zero GPU."""
return {
"skip_optimization": True,
"max_inference_steps": 16, # Reduced for Zero GPU
"max_image_size": 512, # Smaller images for memory efficiency
"use_lightning_lora": True, # Essential for speed
"memory_efficient": True
}
if __name__ == "__main__":
if is_zero_gpu_environment():
configure_zero_gpu()
settings = get_zero_gpu_settings()
print(f"Zero GPU settings: {settings}")
else:
print("Not running in Zero GPU environment")
|