""" Patch ComfyUI to work in CPU-only environments This can be imported before ComfyUI to set CPU mode """ import os # Force CPU mode if no CUDA available def force_cpu_mode(): """Force ComfyUI to use CPU mode""" # Set environment variables os.environ["CUDA_VISIBLE_DEVICES"] = "" os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1" # Try to patch torch if available try: import torch if not torch.cuda.is_available(): # Force CPU device os.environ["PYTORCH_NO_CUDA_MEMORY_CACHING"] = "1" except: pass # Auto-apply on import force_cpu_mode()