Download zero_gpu_config.py from sunny1997/Qwen-Image-Edit-Fast: direct link, hf CLI and curl.
- Browser
- Download file 2.46 kB
-
https://huggingface.co/spaces/sunny1997/Qwen-Image-Edit-Fast/resolve/main/zero_gpu_config.py
- Command line
-
hf download hf://spaces/sunny1997/Qwen-Image-Edit-Fast/zero_gpu_config.py
-
curl -L -o zero_gpu_config.py https://huggingface.co/spaces/sunny1997/Qwen-Image-Edit-Fast/resolve/main/zero_gpu_config.py
2.46 kB
| """ | |
| 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") | |