Gourieff / comfyui-reactor-node

Fast and Simple Face Swap Extension Node for ComfyUI
GNU General Public License v3.0
1.09k stars 114 forks source link

[SOLVED] AttributeError: module 'onnxruntime' has no attribute 'InferenceSession' #236

Closed ProtoBelisarius closed 4 months ago

ProtoBelisarius commented 4 months ago

First, confirm

What happened?

Installed and Reinstalled and it still gets stuck when Im trying to run it. Insisting on wanting to use a cuda device instead of switching to cpu. How do I make it ignore the gpu and just use cpu?

Steps to reproduce the problem

basic default workflow + (try to) use ReActor with default settings after adding the node

Sysinfo

Linux(Arch), Firefox, RX 6800XT, nightly torch 2.3.0(rocm6), default nodes

Relevant console log

Error occurred when executing ReActorFaceSwap:

/onnxruntime_src/onnxruntime/python/onnxruntime_pybind_state.cc:857 std::unique_ptr onnxruntime::python::CreateExecutionProviderInstance(const onnxruntime::SessionOptions&, const string&, const ProviderOptionsMap&) CUDA_PATH is set but CUDA wasnt able to be loaded. Please install the correct version of CUDA andcuDNN as mentioned in the GPU requirements page (https://onnxruntime.ai/docs/execution-providers/CUDA-ExecutionProvider.html#requirements), make sure they're in the PATH, and that your GPU is supported.

File "/home/user/Git/ComfyUI/execution.py", line 152, in recursive_execute
output_data, output_ui = get_output_data(obj, input_data_all)
File "/home/user/Git/ComfyUI/execution.py", line 82, in get_output_data
return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
File "/home/user/Git/ComfyUI/execution.py", line 75, in map_node_over_list
results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
File "/home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node/nodes.py", line 240, in execute
script.process(
File "/home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node/scripts/reactor_faceswap.py", line 86, in process
result = swap_face(
File "/home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node/scripts/reactor_swapper.py", line 195, in swap_face
source_faces = analyze_faces(source_img)
File "/home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node/scripts/reactor_swapper.py", line 114, in analyze_faces
face_analyser = copy.deepcopy(getAnalysisModel())
File "/home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node/scripts/reactor_swapper.py", line 69, in getAnalysisModel
ANALYSIS_MODEL = insightface.app.FaceAnalysis(
File "/home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node/reactor_log_patch.py", line 48, in patched_faceanalysis_init
model = model_zoo.get_model(onnx_file, **kwargs)
File "/home/user/Git/ComfyUI/venv/lib/python3.10/site-packages/insightface/model_zoo/model_zoo.py", line 96, in get_model
model = router.get_model(providers=providers, provider_options=provider_options)
File "/home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node/reactor_log_patch.py", line 21, in patched_get_model
session = PickableInferenceSession(self.onnx_file, **kwargs)
File "/home/user/Git/ComfyUI/venv/lib/python3.10/site-packages/insightface/model_zoo/model_zoo.py", line 25, in __init__
super().__init__(model_path, **kwargs)
File "/home/user/Git/ComfyUI/venv/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 432, in __init__
raise fallback_error from e
File "/home/user/Git/ComfyUI/venv/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 427, in __init__
self._create_inference_session(self._fallback_providers, None)
File "/home/user/Git/ComfyUI/venv/lib/python3.10/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 483, in _create_inference_session
sess.initialize_session(providers, provider_options, disabled_optimizers)

Additional information

Idk if relevant, but when I uninstall the onnxruntime-gpu it fails to import the node and throws this error:

[ReActor] - STATUS - Running v0.4.1-b11 in ComfyUI
Traceback (most recent call last):
  File "/home/user/Git/ComfyUI/nodes.py", line 1887, in load_custom_node
    module_spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node/__init__.py", line 23, in <module>
    from .nodes import NODE_CLASS_MAPPINGS, NODE_DISPLAY_NAME_MAPPINGS
  File "/home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node/nodes.py", line 15, in <module>
    from scripts.reactor_faceswap import (
  File "/home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node/scripts/reactor_faceswap.py", line 13, in <module>
    from scripts.reactor_logger import logger
  File "/home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node/scripts/reactor_logger.py", line 6, in <module>
    from reactor_utils import addLoggingLevel
  File "/home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node/reactor_utils.py", line 8, in <module>
    from insightface.app.common import Face
  File "/home/user/Git/ComfyUI/venv/lib/python3.10/site-packages/insightface/__init__.py", line 16, in <module>
    from . import model_zoo
  File "/home/user/Git/ComfyUI/venv/lib/python3.10/site-packages/insightface/model_zoo/__init__.py", line 1, in <module>
    from .model_zoo import get_model
  File "/home/user/Git/ComfyUI/venv/lib/python3.10/site-packages/insightface/model_zoo/model_zoo.py", line 22, in <module>
    class PickableInferenceSession(onnxruntime.InferenceSession):
AttributeError: module 'onnxruntime' has no attribute 'InferenceSession'

Cannot import /home/user/Git/ComfyUI/custom_nodes/comfyui-reactor-node module for custom nodes: module 'onnxruntime' has no attribute 'InferenceSession'

`

Gourieff commented 4 months ago

Try to pip uninstall onnxruntime onnxruntime-gpu and pip install onnxruntime onnxruntime-gpu - is only usable for CUDA ReActor installs onnxruntime if no CUDA is detected Perhaps you have some other node that requires onnxruntime-gpu and that's why you have it installed

ProtoBelisarius commented 4 months ago

Try to pip uninstall onnxruntime onnxruntime-gpu and pip install onnxruntime onnxruntime-gpu - is only usable for CUDA ReActor installs onnxruntime if no CUDA is detected Perhaps you have some other node that requires onnxruntime-gpu and that's why you have it installed

I refer to my provided additional information, and say that this wont help, I have the packages onnx onnxruntime onnxruntime-gpu installed. If I uninstall gpu it wont even load/import the node when starting comfy.

ProtoBelisarius commented 4 months ago

Using the tip from this comment: https://github.com/Gourieff/comfyui-reactor-node/issues/119#issuecomment-1869038663 made it work, so the node works fine. Even with -gpu installed. It just doesnt switch correctly/at all. idk

Gourieff commented 4 months ago

onnxruntime onnxruntime-gpu It just doesnt switch correctly/at all. idk

Because only one package of ORT must be installed, they won't work together properly (they use one folder "onnxruntime" inside the "site-packages" directory, the latest installed overwrites some files of the previous one)

Using the tip from this comment: https://github.com/Gourieff/comfyui-reactor-node/issues/119#issuecomment-1869038663

Yes, this is one of the ways to solve it (for AMD), you forced ORT-GPU to use only CPU EP

ProtoBelisarius commented 4 months ago

Wasnt really solved, still needs a hacky patch by the user to work at all on RoCM.

if cuda is not None:
    if cuda.is_available():
        providers = ["ROCMExecutionProvider"] #["CUDAExecutionProvider"]

for other people stumbling upon this problem, if you change it to ROCMExecutionProvider, it works with an AMD GPU, at least on linux. (dont use window)

Go to the reactor_swapper.py file in the node directory ../ComfyUI/custom_nodes/comfyui-reactor-node/scripts/reactor_swapper.py and change line 29.