Skip to content

[BUG] Cannot Run Any Hugging Face Model #629

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
santi961 opened this issue Mar 17, 2025 · 4 comments
Open

[BUG] Cannot Run Any Hugging Face Model #629

santi961 opened this issue Mar 17, 2025 · 4 comments
Labels
bug Something isn't working stale

Comments

@santi961
Copy link

santi961 commented Mar 17, 2025

Model
Sanster/PowerPaint-V1-stable-diffusion-inpainting

Describe the bug
Cannot run "Sanster/PowerPaint-V1-stable-diffusion-inpainting" or any other downloaded model from Hugging Face.
This is the error:
RuntimeError: Failed to import diffusers.pipelines.onnx_utils because of the following error (look up to see its
traceback):
DLL load failed while importing onnxruntime_pybind11_state: A dynamic link library (DLL) initialization routine failed.

Error Log
C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1>win_start.bat
2025-03-17 06:45:07.254 | INFO | iopaint.runtime:setup_model_dir:80 - Model directory: C:\Users\Jimbo.cache

  • Platform: Windows-10-10.0.19045-SP0
  • Python version: 3.10.6
  • torch: 2.1.2+cu118
  • torchvision: 0.16.2+cu118
  • Pillow: 9.5.0
  • diffusers: 0.27.2
  • transformers: 4.48.3
  • opencv-python: 4.11.0.86
  • accelerate: 1.5.2
  • iopaint: 1.5.4
  • rembg: 2.0.64

2025-03-17 06:45:08.361 | INFO | iopaint.cli:start:166 - Image will be saved to C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\output
2025-03-17 06:45:09.841 | INFO | iopaint.download:get_sd_model_type:68 - Ignore non sdxl file: C:\Users\Jimbo.cache\stable_diffusion\sd3.5_large.safetensors
{
"host": "127.0.0.1",
"port": 8080,
"inbrowser": true,
"model": "Sanster/PowerPaint-V1-stable-diffusion-inpainting",
"no_half": false,
"low_mem": false,
"cpu_offload": false,
"disable_nsfw_checker": false,
"local_files_only": false,
"cpu_textencoder": false,
"device": "cuda",
"input": "C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\images",
"mask_dir": "C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\masks",
"output_dir": "C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\output",
"quality": 95,
"enable_interactive_seg": true,
"interactive_seg_model": "sam2_1_base",
"interactive_seg_device": "cuda",
"enable_remove_bg": false,
"remove_bg_device": "cpu",
"remove_bg_model": "briaai/RMBG-1.4",
"enable_anime_seg": false,
"enable_realesrgan": false,
"realesrgan_device": "cpu",
"realesrgan_model": "realesr-general-x4v3",
"enable_gfpgan": false,
"gfpgan_device": "cpu",
"enable_restoreformer": false,
"restoreformer_device": "cpu"
}
2025-03-17 06:45:09.903 | INFO | iopaint.api:_build_file_manager:374 - Input is directory, initialize file manager C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\images
2025-03-17 06:45:09.907 | INFO | iopaint.plugins:build_plugins:33 - Initialize InteractiveSeg plugin
2025-03-17 06:45:09.907 | INFO | iopaint.plugins.interactive_seg:_init_session:96 - SegmentAnything model path: C:\Users\Jimbo.cache\torch\hub\checkpoints\sam2.1_hiera_base_plus.pt
2025-03-17 06:45:10.670 | INFO | iopaint.model_manager:init_model:46 - Loading model: Sanster/PowerPaint-V1-stable-diffusion-inpainting
Loading pipeline components...: 0%| | 0/7 [00:01<?, ?it/s]
┌───────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────┐
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\diffusers\utils\import_utils.py:718 │
│ in _get_module │
│ │
│ 715 │ │
│ 716 │ def get_module(self, module_name: str): │
│ 717 │ │ try: │
│ > 718 │ │ │ return importlib.import_module("." + module_name, self.name) │
│ 719 │ │ except Exception as e: │
│ 720 │ │ │ raise RuntimeError( │
│ 721 │ │ │ │ f"Failed to import {self.name}.{module_name} because of the followin │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\importlib_init
.py:126 in import_module │
│ │
│ 123 │ │ │ if character != '.': │
│ 124 │ │ │ │ break │
│ 125 │ │ │ level += 1 │
│ > 126 │ return _bootstrap._gcd_import(name[level:], package, level) │
│ 127 │
│ 128 │
│ 129 _RELOADING = {} │
│ :1050 in _gcd_import │
│ :1027 in _find_and_load │
│ :1006 in _find_and_load_unlocked │
│ :688 in load_unlocked │
│ :883 in exec_module │
│ :241 in call_with_frames_removed │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\diffusers\pipelines\onnx_utils.py:31 │
│ in │
│ │
│ 28 │
│ 29 │
│ 30 if is_onnx_available(): │
│ > 31 │ import onnxruntime as ort │
│ 32 │
│ 33 │
│ 34 logger = logging.get_logger(name) │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\onnxruntime_init
.py:61 in │
│ │
│ │
│ 58 from onnxruntime.capi import onnxruntime_validation │
│ 59 │
│ 60 if import_capi_exception: │
│ > 61 │ raise import_capi_exception │
│ 62 │
│ 63 from onnxruntime.capi.onnxruntime_inference_collection import ( │
│ 64 │ AdapterFormat, # noqa: F401 │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\onnxruntime_init
.py:24 in │
│ │
│ │
│ 21 # meaningful messages to the user. │
│ 22 # the saved exception is raised after device version validation. │
│ 23 try: │
│ > 24 │ from onnxruntime.capi._pybind_state import ( │
│ 25 │ │ ExecutionMode, # noqa: F401 │
│ 26 │ │ ExecutionOrder, # noqa: F401 │
│ 27 │ │ GraphOptimizationLevel, # noqa: F401 │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\onnxruntime\capi_pybind_state.py:32 │
│ in │
│ │
│ 29 │
│ 30 │
│ 31 │
│ > 32 from .onnxruntime_pybind11_state import * # noqa │
│ 33 │
│ 34 │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
ImportError: DLL load failed while importing onnxruntime_pybind11_state: A dynamic link library (DLL) initialization
routine failed.

The above exception was the direct cause of the following exception:

┌───────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────┐
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\typer_config\decorators.py:92 in │
│ wrapped │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\iopaint\cli.py:229 in start │
│ │
│ 226 │ │ restoreformer_device=restoreformer_device, │
│ 227 │ ) │
│ 228 │ print(api_config.model_dump_json(indent=4)) │
│ > 229 │ api = Api(app, api_config) │
│ 230 │ api.launch() │
│ 231 │
│ 232 │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\iopaint\api.py:158 in init
│ │
│ 155 │ │ │
│ 156 │ │ self.file_manager = self._build_file_manager() │
│ 157 │ │ self.plugins = self._build_plugins() │
│ > 158 │ │ self.model_manager = self._build_model_manager() │
│ 159 │ │ │
│ 160 │ │ # fmt: off │
│ 161 │ │ self.add_api_route("/api/v1/gen-info", self.api_geninfo, methods=["POST"], respo │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\iopaint\api.py:406 in │
│ _build_model_manager │
│ │
│ 403 │ │ ) │
│ 404 │ │
│ 405 │ def _build_model_manager(self): │
│ > 406 │ │ return ModelManager( │
│ 407 │ │ │ name=self.config.model, │
│ 408 │ │ │ device=torch.device(self.config.device), │
│ 409 │ │ │ no_half=self.config.no_half, │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\iopaint\model_manager.py:39 in │
init
│ │
│ 36 │ │ │
│ 37 │ │ self.enable_powerpaint_v2 = kwargs.get("enable_powerpaint_v2", False) │
│ 38 │ │ │
│ > 39 │ │ self.model = self.init_model(name, device, **kwargs) │
│ 40 │ │
│ 41 │ @Property
│ 42 │ def current_model(self) -> ModelInfo: │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\iopaint\model_manager.py:72 in │
│ init_model │
│ │
│ 69 │ │ │ return PowerPaintV2(device, **kwargs) │
│ 70 │ │ │
│ 71 │ │ if model_info.name in models: │
│ > 72 │ │ │ return models[name](device, **kwargs) │
│ 73 │ │ │
│ 74 │ │ if model_info.model_type in [ │
│ 75 │ │ │ ModelType.DIFFUSERS_SD_INPAINT, │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\iopaint\model\base.py:277 in init
│ │
│ 274 │ def init(self, device, **kwargs): │
│ 275 │ │ self.model_info = kwargs["model_info"] │
│ 276 │ │ self.model_id_or_path = self.model_info.path │
│ > 277 │ │ super().init(device, **kwargs) │
│ 278 │ │
│ 279 │ @torch.no_grad() │
│ 280 │ def call(self, image, mask, config: InpaintRequest): │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\iopaint\model\base.py:35 in init
│ │
│ 32 │ │ """ │
│ 33 │ │ device = switch_mps_device(self.name, device) │
│ 34 │ │ self.device = device │
│ > 35 │ │ self.init_model(device, **kwargs) │
│ 36 │ │
│ 37 │ @abc.abstractmethod │
│ 38 │ def init_model(self, device, **kwargs): ... │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\iopaint\model\power_paint\power_paint │
│ .py:42 in init_model │
│ │
│ 39 │ │ │ │ ) │
│ 40 │ │ │ ) │
│ 41 │ │ │
│ > 42 │ │ self.model = handle_from_pretrained_exceptions( │
│ 43 │ │ │ StableDiffusionInpaintPipeline.from_pretrained, │
│ 44 │ │ │ pretrained_model_name_or_path=self.name, │
│ 45 │ │ │ variant="fp16", │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\iopaint\model\utils.py:1006 in │
│ handle_from_pretrained_exceptions │
│ │
│ 1003 │ │ │ exit(-1) │
│ 1004 │ │ raise e │
│ 1005 │ except Exception as e: │
│ > 1006 │ │ raise e │
│ 1007 │
│ 1008 │
│ 1009 def get_torch_dtype(device, no_half: bool): │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\iopaint\model\utils.py:982 in │
│ handle_from_pretrained_exceptions │
│ │
│ 979 │
│ 980 def handle_from_pretrained_exceptions(func, **kwargs): │
│ 981 │ try: │
│ > 982 │ │ return func(**kwargs) │
│ 983 │ except ValueError as e: │
│ 984 │ │ if "You are trying to load the model files of the variant=fp16" in str(e): │
│ 985 │ │ │ logger.info("variant=fp16 not found, try revision=fp16") │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\huggingface_hub\utils_validators.py: │
│ 114 in _inner_fn │
│ │
│ 111 │ │ if check_use_auth_token: │
│ 112 │ │ │ kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.name, has_token=ha │
│ 113 │ │ │
│ > 114 │ │ return fn(*args, **kwargs) │
│ 115 │ │
│ 116 │ return inner_fn # type: ignore │
│ 117 │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\diffusers\pipelines\pipeline_utils.py │
│ :819 in from_pretrained │
│ │
│ 816 │ │ │ │ loaded_sub_model = passed_class_obj[name] │
│ 817 │ │ │ else: │
│ 818 │ │ │ │ # load sub model │
│ > 819 │ │ │ │ loaded_sub_model = load_sub_model( │
│ 820 │ │ │ │ │ library_name=library_name, │
│ 821 │ │ │ │ │ class_name=class_name, │
│ 822 │ │ │ │ │ importable_classes=importable_classes, │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\diffusers\pipelines\pipeline_loading

│ utils.py:422 in load_sub_model │
│ │
│ 419 │ loading_kwargs = {} │
│ 420 │ if issubclass(class_obj, torch.nn.Module): │
│ 421 │ │ loading_kwargs["torch_dtype"] = torch_dtype │
│ > 422 │ if issubclass(class_obj, diffusers_module.OnnxRuntimeModel): │
│ 423 │ │ loading_kwargs["provider"] = provider │
│ 424 │ │ loading_kwargs["sess_options"] = sess_options │
│ 425 │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\diffusers\utils\import_utils.py:709 │
│ in getattr
│ │
│ 706 │ │ │ value = self._get_module(name) │
│ 707 │ │ elif name in self._class_to_module.keys(): │
│ 708 │ │ │ module = self._get_module(self._class_to_module[name]) │
│ > 709 │ │ │ value = getattr(module, name) │
│ 710 │ │ else: │
│ 711 │ │ │ raise AttributeError(f"module {self.name} has no attribute {name}") │
│ 712 │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\diffusers\utils\import_utils.py:708 │
│ in getattr
│ │
│ 705 │ │ if name in self._modules: │
│ 706 │ │ │ value = self._get_module(name) │
│ 707 │ │ elif name in self._class_to_module.keys(): │
│ > 708 │ │ │ module = self._get_module(self._class_to_module[name]) │
│ 709 │ │ │ value = getattr(module, name) │
│ 710 │ │ else: │
│ 711 │ │ │ raise AttributeError(f"module {self.name} has no attribute {name}") │
│ │
│ C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\diffusers\utils\import_utils.py:720 │
│ in _get_module │
│ │
│ 717 │ │ try: │
│ 718 │ │ │ return importlib.import_module("." + module_name, self.name) │
│ 719 │ │ except Exception as e: │
│ > 720 │ │ │ raise RuntimeError( │
│ 721 │ │ │ │ f"Failed to import {self.name}.{module_name} because of the followin │
│ 722 │ │ │ │ f" traceback):\n{e}" │
│ 723 │ │ │ ) from e │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
RuntimeError: Failed to import diffusers.pipelines.onnx_utils because of the following error (look up to see its
traceback):
DLL load failed while importing onnxruntime_pybind11_state: A dynamic link library (DLL) initialization routine failed.
Press any key to continue . . .

System Info
Software version used

  • iopaint: 1.5.4
  • pytorch: 2.1.2+cu118
  • CUDA: CUDA Version: 12.8

IOPaint_Error_Log.txt

@santi961 santi961 added the bug Something isn't working label Mar 17, 2025
@Sanster
Copy link
Owner

Sanster commented Mar 18, 2025

It seems to be a bug in the new version of onnxruntime, which is only used by the remove_bg plugin. I noticed that your configuration does not use this plugin. You can manually modify lines 30/31 of the onnx_utils.py file:

C:\Users\Jimbo\Documents\Python_Apps\IOPaint-v1.1\installer\lib\site-packages\diffusers\pipelines\onnx_utils.py

 if is_onnx_available():
    import onnxruntime as ort

Change it to

 if False:
    import onnxruntime as ort

@Sanster
Copy link
Owner

Sanster commented Mar 18, 2025

Tested the lower version of onnxruntime works, can roll back to 1.19.2.

You can create a new bat script in the same directory as win_start.bat to install the specified version of onnxruntime.

@echo off

set PATH=C:\Windows\System32;%PATH%

@call installer\Scripts\activate.bat

@call pip3 install onnxruntime==1.19.2

PAUSE

@Sanster
Copy link
Owner

Sanster commented Mar 18, 2025

fix the onnxruntime version in iopaint==1.6.0

Copy link

This issue is stale because it has been open for 30 days with no activity.

@github-actions github-actions bot added the stale label Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working stale
Projects
None yet
Development

No branches or pull requests

2 participants