invoke-ai / InvokeAI

InvokeAI is a leading creative engine for Stable Diffusion models, empowering professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry leading WebUI, supports terminal use through a CLI, and serves as the foundation for multiple commercial products.
https://invoke-ai.github.io/InvokeAI/
Apache License 2.0
22.83k stars 2.36k forks source link

[bug]: If folder exists legacy model migration crashes #2324

Closed mickr777 closed 1 year ago

mickr777 commented 1 year ago

Is there an existing issue for this?

OS

Linux

GPU

cuda

VRAM

12

What happened?

Instead of skipping folder if it exists, the legacy model migration errors out and exits

Occurs when doing a manual update with git pull to new diffusers and If you happen to run configure_invokeai.py first before invoke.py

Screenshots

No response

Additional context

No response

Contact Details

No response

asmaloney commented 1 year ago

Confirming this on macOS 12.6.2 as well.

Commit: 5b35fa53a7a056548c81131f641006c8276eccfd

I did:

% conda env update
% python scripts/configure_invokeai.py
% python scripts/invoke.py --web

Result:

* Initializing, be patient...
>> Initialization file /<path>/invokeai-install/invokeai.init found. Loading...
>> Internet connectivity is True
>> InvokeAI, version 2.3.0+a0
>> InvokeAI runtime directory is "/<path>/invokeai-install"
>> GFPGAN Initialized
>> CodeFormer Initialized
>> ESRGAN Initialized
** Legacy version <= 2.2.5 model directory layout detected. Reorganizing.
** This is a quick one-time operation.
DEBUG: Moving /<path>/invokeai-install/models/CompVis/stable-diffusion-safety-checker/models--CompVis--stable-diffusion-safety-checker into hub
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /<path>/InvokeAI/scripts/invoke.py:9 in <module>                                      │
│                                                                                                  │
│    6 │   os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"                                         │
│    7                                                                                             │
│    8 import ldm.invoke.CLI                                                                       │
│ ❱  9 ldm.invoke.CLI.main()                                                                       │
│   10                                                                                             │
│   11                                                                                             │
│                                                                                                  │
│ /<path>/InvokeAI/ldm/invoke/CLI.py:84 in main                                         │
│                                                                                                  │
│     81 │   │   embedding_path = None                                                             │
│     82 │                                                                                         │
│     83 │   # migrate legacy models                                                               │
│ ❱   84 │   ModelManager.migrate_models()                                                         │
│     85 │                                                                                         │
│     86 │   # load the infile as a list of lines                                                  │
│     87 │   if opt.infile:                                                                        │
│                                                                                                  │
│ /<path>/InvokeAI/ldm/invoke/model_manager.py:765 in migrate_models                    │
│                                                                                                  │
│   762 │   │   │   source = models_dir /model                                                     │
│   763 │   │   │   if source.exists():                                                            │
│   764 │   │   │   │   print(f'DEBUG: Moving {models_dir / model} into hub')                      │
│ ❱ 765 │   │   │   │   move(models_dir / model, hub)                                              │
│   766 │   │                                                                                      │
│   767 │   │   # anything else gets moved into the diffusers directory                            │
│   768 │   │   diffusers = models_dir / 'diffusers'                                               │
│                                                                                                  │
│ /<path>/invokeai/lib/python3.10/shutil.py:813 in move    │
│                                                                                                  │
│    810 │   │   real_dst = os.path.join(dst, _basename(src))                                      │
│    811 │   │                                                                                     │
│    812 │   │   if os.path.exists(real_dst):                                                      │
│ ❱  813 │   │   │   raise Error("Destination path '%s' already exists" % real_dst)                │
│    814 │   try:                                                                                  │
│    815 │   │   os.rename(src, real_dst)                                                          │
│    816 │   except OSError:                                                                       │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
Error: Destination path '<path>/invokeai-install/models/hub/models--CompVis--stable-diffusion-safety-checker' already exists
mickr777 commented 1 year ago

The quick fix that I found to get it working at the moment, is delete everything in the models/hub/ folder and and then run invoke and let it do its migration and it will work from then on.

It trying to convert legacy files into the hub folder but there already there, so deleting them lets it do the conversion