Comfy-Org / Comfy-Org/ComfyUI

CPU cores are not fully utilized when using standalone build for Windows (torch)

Open
#5,178 7 comments 1 reaction 0 assignees View on GitHub
Feature
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 6h
Merged PRs (30d)
155

Description

### Feature Idea

When running comfyui standalone build for windows cpu version, the utilization of all cpu cores are not implemented for torch. Adding few lines of code to ComfyUI/comfy/utils.py or main.py will help a lot of users who don't have GPU to fully utilize comfyui.

First option to just add the below lines without checking if gpu is used
import os #######
cpuCount = os.cpu_count() ###########
torch.set_num_threads(cpuCount) ############
torch.set_num_interop_threads(cpuCount) ############

or adding the below lines to main.py line 82 or any other location you think it is better.
if args.windows_standalone_build:
try:
import fix_torch
if args.cpu: ###########
import torch #############
cpuCount = os.cpu_count() ###########
torch.set_num_threads(cpuCount) ############
torch.set_num_interop_threads(cpuCount) ############

Also adding this option in --use-split-cross-attention in the run_cpu.bat

.\python_embeded\python.exe -s ComfyUI\main.py --cpu --windows-standalone-build --use-split-cross-attention

pause

### Existing Solutions

_No response_

### Other

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.