Repository: stable-diffusion-webui
Issue: [Bug]: webui faills when loading weights, and a 'butch of module not found'
Labels: bug-report

### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

Once it gets the Loading weights it fails giveing `OSError: [Errno 5] Input/output error`


### Steps to reproduce the problem

1. launch launch.py
2. wait for loading


### What should have happened?

shold load weights then become useable

### Commit where the problem happens

a0ef416aa769022ce9e97dcc87f88a0ae9e6cc58

### What platforms do you use to access UI ?

Linux

### What browsers do you use to access the UI ?

_No response_

### Command Line Arguments

```Shell
--opt-split-attention --medvram --deepdanbooru
```


### Additional information, context and logs

`Python 3.10.9 (main, Dec 20 2022, 00:00:00) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)]
Commit hash: a0ef416aa769022ce9e97dcc87f88a0ae9e6cc58
Installing requirements for Web UI
Error running install.py for extension extensions/sd-dynamic-prompts.
Command: "/usr/bin/python3.10" "extensions/sd-dynamic-prompts/install.py"
Error code: 1
stdout: <empty>
stderr: Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/extensions/sd-dynamic-prompts/install.py", line 13, in <module>
    import launch
ModuleNotFoundError: No module named 'launch'


Error running install.py for extension extensions/sd_dreambooth_extension.
Command: "/usr/bin/python3.10" "extensions/sd_dreambooth_extension/install.py"
Error code: 1
stdout: <empty>
stderr: Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/extensions/sd_dreambooth_extension/install.py", line 10, in <module>
    from launch import run
ModuleNotFoundError: No module named 'launch'


Error running install.py for extension extensions/seed_travel.
Command: "/usr/bin/python3.10" "extensions/seed_travel/install.py"
Error code: 1
stdout: <empty>
stderr: Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/extensions/seed_travel/install.py", line 1, in <module>
    import launch
ModuleNotFoundError: No module named 'launch'


Error running install.py for extension extensions/stable-diffusion-webui-Prompt_Generator.
Command: "/usr/bin/python3.10" "extensions/stable-diffusion-webui-Prompt_Generator/install.py"
Error code: 1
stdout: <empty>
stderr: Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/extensions/stable-diffusion-webui-Prompt_Generator/install.py", line 1, in <module>
    import launch
ModuleNotFoundError: No module named 'launch'


Error running install.py for extension extensions/ABG_extension.
Command: "/usr/bin/python3.10" "extensions/ABG_extension/install.py"
Error code: 1
stdout: <empty>
stderr: Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/extensions/ABG_extension/install.py", line 1, in <module>
    import launch
ModuleNotFoundError: No module named 'launch'


Error running install.py for extension extensions/multi-subject-render.
Command: "/usr/bin/python3.10" "extensions/multi-subject-render/install.py"
Error code: 1
stdout: <empty>
stderr: Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/extensions/multi-subject-render/install.py", line 1, in <module>
    import launch
ModuleNotFoundError: No module named 'launch'


Error running install.py for extension extensions/sd_smartprocess.
Command: "/usr/bin/python3.10" "extensions/sd_smartprocess/install.py"
Error code: 1
stdout: <empty>
stderr: Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/extensions/sd_smartprocess/install.py", line 4, in <module>
    from launch import run, git_clone, repo_dir
ModuleNotFoundError: No module named 'launch'


Launching Web UI with arguments: --opt-split-attention --medvram --deepdanbooru
No module 'xformers'. Proceeding without it.
Loading booru2prompt settings
Installing openmim
Installing mmcv-full
Installing mmdet
Error loading script: ddetailer.py
Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/modules/scripts.py", line 205, in load_scripts
    module = script_loading.load_module(scriptfile.path)
  File "/home/USER/stable-diffusion-webui/modules/script_loading.py", line 13, in load_module
    exec(compiled, module.__dict__)
  File "/home/USER/stable-diffusion-webui/extensions/ddetailer/scripts/ddetailer.py", line 61, in <module>
    startup()
  File "/home/USER/stable-diffusion-webui/extensions/ddetailer/scripts/ddetailer.py", line 50, in startup
    run(f'"{python}" -m pip install mmdet', desc=f"Installing mmdet", errdesc=f"Couldn't install mmdet")
  File "/home/USER/stable-diffusion-webui/launch.py", line 65, in run
    raise RuntimeError(message)
RuntimeError: Couldn't install mmdet.
Command: "/usr/bin/python3.10" -m pip install mmdet
Error code: 1
stdout: Defaulting to user installation because normal site-packages is not writeable
Collecting mmdet
  Using cached mmdet-2.27.0-py3-none-any.whl (1.5 MB)
Requirement already satisfied: six in /home/USER/.local/lib/python3.10/site-packages (from mmdet) (1.16.0)
Collecting terminaltables
  Using cached terminaltables-3.1.10-py2.py3-none-any.whl (15 kB)
Requirement already satisfied: scipy in /home/USER/.local/lib/python3.10/site-packages (from mmdet) (1.9.3)
Collecting pycocotools
  Using cached pycocotools-2.0.6.tar.gz (24 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
  Preparing metadata (pyproject.toml): started
  Preparing metadata (pyproject.toml): finished with status 'done'
Requirement already satisfied: numpy in /home/USER/.local/lib/python3.10/site-packages (from mmdet) (1.23.3)
Requirement already satisfied: matplotlib in /home/USER/.local/lib/python3.10/site-packages (from mmdet) (3.6.2)
Requirement already satisfied: packaging>=20.0 in /home/USER/.local/lib/python3.10/site-packages (from matplotlib->mmdet) (22.0)
Requirement already satisfied: pillow>=6.2.0 in /home/USER/.local/lib/python3.10/site-packages (from matplotlib->mmdet) (9.4.0)
Requirement already satisfied: cycler>=0.10 in /home/USER/.local/lib/python3.10/site-packages (from matplotlib->mmdet) (0.11.0)
Requirement already satisfied: pyparsing>=2.2.1 in /home/USER/.local/lib/python3.10/site-packages (from matplotlib->mmdet) (3.0.9)
Requirement already satisfied: contourpy>=1.0.1 in /home/USER/.local/lib/python3.10/site-packages (from matplotlib->mmdet) (1.0.6)
Requirement already satisfied: fonttools>=4.22.0 in /home/USER/.local/lib/python3.10/site-packages (from matplotlib->mmdet) (4.38.0)
Requirement already satisfied: python-dateutil>=2.7 in /home/USER/.local/lib/python3.10/site-packages (from matplotlib->mmdet) (2.8.2)
Requirement already satisfied: kiwisolver>=1.0.1 in /home/USER/.local/lib/python3.10/site-packages (from matplotlib->mmdet) (1.4.4)
Building wheels for collected packages: pycocotools
  Building wheel for pycocotools (pyproject.toml): started
  Building wheel for pycocotools (pyproject.toml): finished with status 'error'
Failed to build pycocotools

stderr:   error: subprocess-exited-with-error
  
  × Building wheel for pycocotools (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [62 lines of output]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.linux-x86_64-cpython-310
      creating build/lib.linux-x86_64-cpython-310/pycocotools
      copying pycocotools/__init__.py -> build/lib.linux-x86_64-cpython-310/pycocotools
      copying pycocotools/coco.py -> build/lib.linux-x86_64-cpython-310/pycocotools
      copying pycocotools/cocoeval.py -> build/lib.linux-x86_64-cpython-310/pycocotools
      copying pycocotools/mask.py -> build/lib.linux-x86_64-cpython-310/pycocotools
      running build_ext
      cythoning pycocotools/_mask.pyx to pycocotools/_mask.c
      /tmp/pip-build-env-i0dr3y4u/overlay/lib64/python3.10/site-packages/Cython/Compiler/Main.py:369: FutureWarning: Cython directive 'language_level' not set, using 2 for now (Py2). This will change in a later release! File: /tmp/pip-install-8l2rz233/pycocotools_1a693565c94a48f98bb872000f55912c/pycocotools/_mask.pyx
        tree = Parsing.p_module(s, pxd, full_module_name)
      building 'pycocotools._mask' extension
      creating build/temp.linux-x86_64-cpython-310
      creating build/temp.linux-x86_64-cpython-310/common
      creating build/temp.linux-x86_64-cpython-310/pycocotools
      gcc -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/tmp/pip-build-env-i0dr3y4u/overlay/lib64/python3.10/site-packages/numpy/core/include -I./common -I/usr/include/python3.10 -c ./common/maskApi.c -o build/temp.linux-x86_64-cpython-310/./common/maskApi.o -Wno-cpp -Wno-unused-function -std=c99
      ./common/maskApi.c: In function ‘rleToBbox’:
      ./common/maskApi.c:151:32: warning: unused variable ‘xp’ [-Wunused-variable]
        151 |     uint h, w, xs, ys, xe, ye, xp, cc; siz j, m;
            |                                ^~
      ./common/maskApi.c: In function ‘rleFrPoly’:
      ./common/maskApi.c:197:3: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
        197 |   for(j=0; j<k; j++) x[j]=(int)(scale*xy[j*2+0]+.5); x[k]=x[0];
            |   ^~~
      ./common/maskApi.c:197:54: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
        197 |   for(j=0; j<k; j++) x[j]=(int)(scale*xy[j*2+0]+.5); x[k]=x[0];
            |                                                      ^
      ./common/maskApi.c:198:3: warning: this ‘for’ clause does not guard... [-Wmisleading-indentation]
        198 |   for(j=0; j<k; j++) y[j]=(int)(scale*xy[j*2+1]+.5); y[k]=y[0];
            |   ^~~
      ./common/maskApi.c:198:54: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘for’
        198 |   for(j=0; j<k; j++) y[j]=(int)(scale*xy[j*2+1]+.5); y[k]=y[0];
            |                                                      ^
      ./common/maskApi.c: In function ‘rleToString’:
      ./common/maskApi.c:243:7: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
        243 |       if(more) c |= 0x20; c+=48; s[p++]=c;
            |       ^~
      ./common/maskApi.c:243:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
        243 |       if(more) c |= 0x20; c+=48; s[p++]=c;
            |                           ^
      ./common/maskApi.c: In function ‘rleFrString’:
      ./common/maskApi.c:251:3: warning: this ‘while’ clause does not guard... [-Wmisleading-indentation]
        251 |   while( s[m] ) m++; cnts=malloc(sizeof(uint)*m); m=0;
            |   ^~~~~
      ./common/maskApi.c:251:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘while’
        251 |   while( s[m] ) m++; cnts=malloc(sizeof(uint)*m); m=0;
            |                      ^~~~
      ./common/maskApi.c:259:5: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
        259 |     if(m>2) x+=(long) cnts[m-2]; cnts[m++]=(uint) x;
            |     ^~
      ./common/maskApi.c:259:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’
        259 |     if(m>2) x+=(long) cnts[m-2]; cnts[m++]=(uint) x;
            |                                  ^~~~
      gcc -Wno-unused-result -Wsign-compare -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DNDEBUG -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -O2 -fexceptions -g -grecord-gcc-switches -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I/tmp/pip-build-env-i0dr3y4u/overlay/lib64/python3.10/site-packages/numpy/core/include -I./common -I/usr/include/python3.10 -c pycocotools/_mask.c -o build/temp.linux-x86_64-cpython-310/pycocotools/_mask.o -Wno-cpp -Wno-unused-function -std=c99
      pycocotools/_mask.c:6:10: fatal error: Python.h: No such file or directory
          6 | #include "Python.h"
            |          ^~~~~~~~~~
      compilation terminated.
      error: command '/usr/bin/gcc' failed with exit code 1
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for pycocotools
ERROR: Could not build wheels for pycocotools, which is required to install pyproject.toml-based projects



Error loading script: simple_depthmap.py
Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/modules/scripts.py", line 205, in load_scripts
    module = script_loading.load_module(scriptfile.path)
  File "/home/USER/stable-diffusion-webui/modules/script_loading.py", line 13, in load_module
    exec(compiled, module.__dict__)
  File "/home/USER/stable-diffusion-webui/extensions/multi-subject-render/scripts/simple_depthmap.py", line 11, in <module>
    from repositories.midas.midas.dpt_depth import DPTDepthModel
ModuleNotFoundError: No module named 'repositories.midas'

Error loading script: dynamic_prompting.py
Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/modules/scripts.py", line 205, in load_scripts
    module = script_loading.load_module(scriptfile.path)
  File "/home/USER/stable-diffusion-webui/modules/script_loading.py", line 13, in load_module
    exec(compiled, module.__dict__)
  File "/home/USER/stable-diffusion-webui/extensions/sd-dynamic-prompts/scripts/dynamic_prompting.py", line 17, in <module>
    from dynamicprompts.wildcardmanager import WildcardManager
ModuleNotFoundError: No module named 'dynamicprompts'

SD-Webui API layer loaded
Error loading script: main.py
Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/modules/scripts.py", line 205, in load_scripts
    module = script_loading.load_module(scriptfile.path)
  File "/home/USER/stable-diffusion-webui/modules/script_loading.py", line 13, in load_module
    exec(compiled, module.__dict__)
  File "/home/USER/stable-diffusion-webui/extensions/sd_dreambooth_extension/scripts/main.py", line 8, in <module>
    from extensions.sd_dreambooth_extension.dreambooth.db_webhook import save_and_test_webhook
  File "/home/USER/stable-diffusion-webui/extensions/sd_dreambooth_extension/dreambooth/db_webhook.py", line 9, in <module>
    import discord_webhook
ModuleNotFoundError: No module named 'discord_webhook'

Error loading script: randomize.py
Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/modules/scripts.py", line 205, in load_scripts
    module = script_loading.load_module(scriptfile.path)
  File "/home/USER/stable-diffusion-webui/modules/script_loading.py", line 11, in load_module
    compiled = compile(text, path, 'exec')
ValueError: source code string cannot contain null bytes

LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Loading weights [925997e9] from /home/USER/stable-diffusion-webui/models/Stable-diffusion/animefinal-full-pruned.ckpt
loading stable diffusion model: OSError
Traceback (most recent call last):
  File "/home/USER/stable-diffusion-webui/webui.py", line 74, in initialize
    modules.sd_models.load_model()
  File "/home/USER/stable-diffusion-webui/modules/sd_models.py", line 324, in load_model
    load_model_weights(sd_model, checkpoint_info)
  File "/home/USER/stable-diffusion-webui/modules/sd_models.py", line 205, in load_model_weights
    sd = read_state_dict(checkpoint_file)
  File "/home/USER/stable-diffusion-webui/modules/sd_models.py", line 182, in read_state_dict
    pl_sd = torch.load(checkpoint_file, map_location=map_location or shared.weight_load_location)
  File "/home/USER/stable-diffusion-webui/extensions/sd_smartprocess/reallysafe.py", line 117, in load
    return load_with_extra(filename, *args, **kwargs)
  File "/home/USER/stable-diffusion-webui/extensions/sd_smartprocess/reallysafe.py", line 164, in load_with_extra
    return unsafe_torch_load(filename, *args, **kwargs)
  File "/home/USER/stable-diffusion-webui/extensions/sd_dreambooth_extension/reallysafe.py", line 117, in load
    return load_with_extra(filename, *args, **kwargs)
  File "/home/USER/stable-diffusion-webui/extensions/sd_dreambooth_extension/reallysafe.py", line 164, in load_with_extra
    return unsafe_torch_load(filename, *args, **kwargs)
  File "/home/USER/stable-diffusion-webui/modules/safe.py", line 106, in load
    return load_with_extra(filename, extra_handler=global_extra_handler, *args, **kwargs)
  File "/home/USER/stable-diffusion-webui/modules/safe.py", line 151, in load_with_extra
    return unsafe_torch_load(filename, *args, **kwargs)
  File "/home/USER/.local/lib/python3.10/site-packages/torch/serialization.py", line 712, in load
    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)
  File "/home/USER/.local/lib/python3.10/site-packages/torch/serialization.py", line 1049, in _load
    result = unpickler.load()
  File "/home/USER/.local/lib/python3.10/site-packages/torch/serialization.py", line 1019, in persistent_load
    load_tensor(dtype, nbytes, key, _maybe_decode_ascii(location))
  File "/home/USER/.local/lib/python3.10/site-packages/torch/serialization.py", line 997, in load_tensor
    storage = zip_file.get_storage_from_record(name, numel, torch._UntypedStorage).storage()._untyped()
OSError: [Errno 5] Input/output error


Stable diffusion model failed to load, exiting`