brycedrennan/imaginAIry

Catch FileNotFoundError caused by misspelled or incorrect model name

mqudsi opened this issue · 3 comments

mqudsi commented

I'm using imaginairy on a case-sensitive filesystem (zfs) and constantly running into an issue where I accidentally crash aimg by entering the model name with the wrong case. For example, using imagine --model sd-2.0-v ... instead of imagine --model SD-2.0-v ... gives the following traceback:

Loading model sd-2.0-v onto cuda backend...
Traceback (most recent call last):
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\cli\clickshell_mod.py", line 29, in invoke_
    command.main(
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\click\decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\cli\imagine.py", line 144, in imagine_cmd
    return _imagine_cmd(
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\cli\shared.py", line 181, in _imagine_cmd
    filenames = imagine_image_files(
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\api.py", line 61, in imagine_image_files
    for result in imagine(
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\api.py", line 176, in imagine
    result = _generate_single_image(
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\api.py", line 273, in _generate_single_image
    is_controlnet_model = hasattr(model, "control_key")
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\utils\model_cache.py", line 363, in __getattr__
    model = self._mmmw_load_model()
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\utils\model_cache.py", line 349, in _mmmw_load_model
    model = self._mmmw_fn(*self._mmmw_args, **self._mmmw_kwargs)
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\model_manager.py", line 240, in _load_diffusion_model
    model = load_model_from_config(
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\model_manager.py", line 94, in load_model_from_config
    base_model_dict = load_state_dict(weights_location, half_mode=half_mode)
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\model_manager.py", line 68, in load_state_dict
    raise e
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\model_manager.py", line 61, in load_state_dict
    state_dict = load_tensors(ckpt_path, map_location="cpu")
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\model_manager.py", line 41, in load_tensors
    return load_file(tensorfile, device=map_location)
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\safetensors\torch.py", line 98, in load_file
    with safe_open(filename, framework="pt", device=device) as f:
FileNotFoundError: The system cannot find the file specified. (os error 2)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "\\192.168.42.103\general\python\imaginairy\env\Scripts\aimg.exe\__main__.py", line 7, in <module>
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\click_shell\core.py", line 174, in invoke
    return self.shell.cmdloop()
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\click_shell\_cmd.py", line 109, in cmdloop
    stop = self.onecmd(line)
  File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python39_64\lib\cmd.py", line 217, in onecmd
    return func(arg)
  File "\\192.168.42.103\general\python\imaginairy\env\lib\site-packages\imaginairy\cli\clickshell_mod.py", line 46, in invoke_
    traceback.print_exception(e)  # noqa
TypeError: print_exception() missing 2 required positional arguments: 'value' and 'tb'

todo: ensure this kind of error has better handling

its no longer case sensitive in just release 14.0.0

mqudsi commented

Thanks! ♥