Sanster / IOPaint

Image inpainting tool powered by SOTA AI Model. Remove any unwanted object, defect, people from your pictures or erase and replace(powered by stable diffusion) any thing on your pictures.
https://www.iopaint.com/
Apache License 2.0
17.35k stars 1.75k forks source link

[BUG] Using a symlink for the model dir causes fatal error on startup #494

Open Tophness opened 1 month ago

Tophness commented 1 month ago

Model Which model are you using? Lykon/dreamshaper-8-inpainting (although any model will fail)

Describe the bug Using a symlink for the model dir will result in error.

Screenshots

(venv) C:\Users\chris\AppData\Local\IOPaint>iopaint start --model=Lykon/dreamshaper-8-inpainting --device=cuda --port=8080 --model-dir=./models
2024-03-24 17:27:36.523 | INFO     | iopaint.runtime:setup_model_dir:82 - Model directory: C:\Users\chris\AppData\Local\IOPaint\models
- Platform: Windows-10-10.0.22621-SP0
- Python version: 3.10.6
- torch: 2.2.1+cu121
- torchvision: 0.17.1+cu121
- Pillow: 9.5.0
- diffusers: 0.26.3
- transformers: 4.39.1
- opencv-python: 4.9.0.80
- accelerate: 0.28.0
- iopaint: 1.2.2
- rembg: N/A
- realesrgan: N/A
- gfpgan: N/A

In this conversion only the non-EMA weights are extracted. If you want to instead extract the EMA weights (usually better for inference), please make sure to add the `--extract_ema` flag.
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ C:\Users\chris\AppData\Local\IOPaint\venv\lib\site-packages\typer_config\decorators.py:92 in     │
│ wrapped                                                                                          │
│                                                                                                  │
│ C:\Users\chris\AppData\Local\IOPaint\venv\lib\site-packages\iopaint\cli.py:166 in start          │
│                                                                                                  │
│   163 │                                                                                          │
│   164 │   from iopaint.download import cli_download_model, scan_models                           │
│   165 │                                                                                          │
│ ❱ 166 │   scanned_models = scan_models()                                                         │
│   167 │   if model not in [it.name for it in scanned_models]:                                    │
│   168 │   │   logger.info(f"{model} not found in {model_dir}, try to downloading")               │
│   169 │   │   cli_download_model(model)                                                          │
│                                                                                                  │
│ C:\Users\chris\AppData\Local\IOPaint\venv\lib\site-packages\iopaint\download.py:291 in           │
│ scan_models                                                                                      │
│                                                                                                  │
│   288 │   model_dir = os.getenv("XDG_CACHE_HOME", DEFAULT_MODEL_DIR)                             │
│   289 │   available_models = []                                                                  │
│   290 │   available_models.extend(scan_inpaint_models(model_dir))                                │
│ ❱ 291 │   available_models.extend(scan_single_file_diffusion_models(model_dir))                  │
│   292 │   available_models.extend(scan_diffusers_models())                                       │
│   293 │   available_models.extend(scan_converted_diffusers_models(model_dir))                    │
│   294 │   return available_models                                                                │
│                                                                                                  │
│ C:\Users\chris\AppData\Local\IOPaint\venv\lib\site-packages\iopaint\download.py:153 in           │
│ scan_single_file_diffusion_models                                                                │
│                                                                                                  │
│   150 │   │   model_abs_path = str(it.absolute())                                                │
│   151 │   │   model_type = sdxl_model_type_cache.get(it.name)                                    │
│   152 │   │   if model_type is None:                                                             │
│ ❱ 153 │   │   │   model_type = get_sdxl_model_type(model_abs_path)                               │
│   154 │   │   sdxl_model_type_cache[it.name] = model_type                                        │
│   155 │   │   if stable_diffusion_xl_dir.exists():                                               │
│   156 │   │   │   with open(sdxl_cache_file, "w", encoding="utf-8") as fw:                       │
│                                                                                                  │
│ C:\Users\chris\AppData\Local\IOPaint\venv\lib\site-packages\iopaint\download.py:98 in            │
│ get_sdxl_model_type                                                                              │
│                                                                                                  │
│    95 │   │   │   if "Trying to set a tensor of shape torch.Size([320, 4, 3, 3])" in str(e):     │
│    96 │   │   │   │   model_type = ModelType.DIFFUSERS_SDXL                                      │
│    97 │   │   │   else:                                                                          │
│ ❱  98 │   │   │   │   raise e                                                                    │
│    99 │   return model_type                                                                      │
│   100                                                                                            │
│   101                                                                                            │
│                                                                                                  │
│ C:\Users\chris\AppData\Local\IOPaint\venv\lib\site-packages\iopaint\download.py:83 in            │
│ get_sdxl_model_type                                                                              │
│                                                                                                  │
│    80 │   │   from diffusers import StableDiffusionXLInpaintPipeline                             │
│    81 │   │                                                                                      │
│    82 │   │   try:                                                                               │
│ ❱  83 │   │   │   model = StableDiffusionXLInpaintPipeline.from_single_file(                     │
│    84 │   │   │   │   model_abs_path,                                                            │
│    85 │   │   │   │   load_safety_checker=False,                                                 │
│    86 │   │   │   │   num_in_channels=9,                                                         │
│                                                                                                  │
│ C:\Users\chris\AppData\Local\IOPaint\venv\lib\site-packages\huggingface_hub\utils\_validators.py │
│ :118 in _inner_fn                                                                                │
│                                                                                                  │
│   115 │   │   if check_use_auth_token:                                                           │
│   116 │   │   │   kwargs = smoothly_deprecate_use_auth_token(fn_name=fn.__name__, has_token=ha   │
│   117 │   │                                                                                      │
│ ❱ 118 │   │   return fn(*args, **kwargs)                                                         │
│   119 │                                                                                          │
│   120 │   return _inner_fn  # type: ignore                                                       │
│   121                                                                                            │
│                                                                                                  │
│ C:\Users\chris\AppData\Local\IOPaint\venv\lib\site-packages\diffusers\loaders\single_file.py:253 │
│ in from_single_file                                                                              │
│                                                                                                  │
│   250 │   │   │   if name in passed_class_obj:                                                   │
│   251 │   │   │   │   init_kwargs[name] = passed_class_obj[name]                                 │
│   252 │   │   │   else:                                                                          │
│ ❱ 253 │   │   │   │   components = build_sub_model_components(                                   │
│   254 │   │   │   │   │   init_kwargs,                                                           │
│   255 │   │   │   │   │   class_name,                                                            │
│   256 │   │   │   │   │   name,                                                                  │
│                                                                                                  │
│ C:\Users\chris\AppData\Local\IOPaint\venv\lib\site-packages\diffusers\loaders\single_file.py:58  │
│ in build_sub_model_components                                                                    │
│                                                                                                  │
│    55 │                                                                                          │
│    56 │   if component_name == "unet":                                                           │
│    57 │   │   num_in_channels = kwargs.pop("num_in_channels", None)                              │
│ ❱  58 │   │   unet_components = create_diffusers_unet_model_from_ldm(                            │
│    59 │   │   │   pipeline_class_name, original_config, checkpoint, num_in_channels=num_in_cha   │
│    60 │   │   )                                                                                  │
│    61 │   │   return unet_components                                                             │
│                                                                                                  │
│ C:\Users\chris\AppData\Local\IOPaint\venv\lib\site-packages\diffusers\loaders\single_file_utils. │
│ py:1173 in create_diffusers_unet_model_from_ldm                                                  │
│                                                                                                  │
│   1170 │                                                                                         │
│   1171 │   if is_accelerate_available():                                                         │
│   1172 │   │   for param_name, param in diffusers_format_unet_checkpoint.items():                │
│ ❱ 1173 │   │   │   set_module_tensor_to_device(unet, param_name, "cpu", value=param)             │
│   1174 │   else:                                                                                 │
│   1175 │   │   unet.load_state_dict(diffusers_format_unet_checkpoint)                            │
│   1176                                                                                           │
│                                                                                                  │
│ C:\Users\chris\AppData\Local\IOPaint\venv\lib\site-packages\accelerate\utils\modeling.py:348 in  │
│ set_module_tensor_to_device                                                                      │
│                                                                                                  │
│    345 │                                                                                         │
│    346 │   if value is not None:                                                                 │
│    347 │   │   if old_value.shape != value.shape:                                                │
│ ❱  348 │   │   │   raise ValueError(                                                             │
│    349 │   │   │   │   f'Trying to set a tensor of shape {value.shape} in "{tensor_name}" (whic  │
│    350 │   │   │   )                                                                             │
│    351                                                                                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ValueError: Trying to set a tensor of shape torch.Size([320, 8, 3, 3]) in "weight" (which has shape torch.Size([320, 9,
3, 3])), this look incorrect.

System Info Software version used