Run with CPU automatically when GPU is unavailable
- Dominant language
- Python
- Stars
- 133k
- Forks
- 15.7k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 155
Description
### Feature Idea
When running without a GPU or appropriate drivers, I think it would be helpful if ComfyUI runs anyway with the CPU and tells the user to either install GPU drivers or use the --cpu argument.
### Existing Solutions
model_management.py
```
def get_torch_device():
global directml_enabled
global cpu_state
if directml_enabled:
global directml_device
return directml_device
if cpu_state == CPUState.MPS:
return torch.device("mps")
if cpu_state == CPUState.CPU:
return torch.device("cpu")
else:
if is_intel_xpu():
return torch.device("xpu", torch.xpu.current_device())
elif is_ascend_npu():
return torch.device("npu", torch.npu.current_device())
else:
try:
return torch.device(torch.cuda.current_device())
except RuntimeError:
args.cpu = True
cpu_state = CPUState.CPU
logging.warning("Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from http://www.nvidia.com/Download/index.aspx, or use --cpu to run in cpu mode.")
logging.info("Running using CPU...\n")
return torch.device("cpu")
```
### Other
This is my first time doing this, so I'm sorry if this has already been considered or if there is a better way to implement my solution.
It also may be more helpful to show the warning and then stop running, which is what it did before but with a stack trace. I think a simple error message would be clearer and help users understand what they have to do.
Contributor guide
Assessment
This issue has not been assessed yet.