Skip to content
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

KeyError: 'state_dict' with HD-18 #27

Closed
Kuroseji opened this issue Dec 25, 2022 · 3 comments
Closed

KeyError: 'state_dict' with HD-18 #27

Kuroseji opened this issue Dec 25, 2022 · 3 comments

Comments

@Kuroseji
Copy link

Kuroseji commented Dec 25, 2022

Not sure if this is an issue with the code for my UI(I use Sygil-Dev) or an issue with the model but I can't run HD-18. Attempting to gives me the following error message. If anyone has any insight it would be greatly appreciated. HD-16 and 17 worked fine so I assume it's a change in how models are handled that my UI hasn't been updated for.

 File "C:\Users\QSDFR\.conda\envs\ldm\lib\threading.py", line 890, in _bootstrap
    self._bootstrap_inner()
    │    └ <function Thread._bootstrap_inner at 0x00000210B3402F70>
    └ <Thread(ScriptRunner.scriptThread, started 16904)>

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
    │    └ <function Thread.run at 0x00000210B3402CA0>
    └ <Thread(ScriptRunner.scriptThread, started 16904)>

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
    │    │        │    │        │    └ {}
    │    │        │    │        └ <Thread(ScriptRunner.scriptThread, started 16904)>
    │    │        │    └ ()
    │    │        └ <Thread(ScriptRunner.scriptThread, started 16904)>
    │    └ <bound method ScriptRunner._run_script_thread of ScriptRunner(_session_id='e090a7d7-971c-4361-bd43-c2bbabe5b345', _main_scrip...
    └ <Thread(ScriptRunner.scriptThread, started 16904)>

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 298, in _run_script_thread
    self._run_script(request.rerun_data)
    │    │           │       └ <property object at 0x00000210BB519F40>
    │    │           └ ScriptRequest(type=<ScriptRequestType.RERUN: 'RERUN'>, _rerun_data=RerunData(query_string='', widget_states=widgets {
    │    │               id: "...
    │    └ <function ScriptRunner._run_script at 0x00000210BB5C4DC0>
    └ ScriptRunner(_session_id='e090a7d7-971c-4361-bd43-c2bbabe5b345', _main_script_path='D:\\StabDiff\\SD-20062022\\stable-diffusi...

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 563, in _run_script
    exec(code, module.__dict__)
         │     │      └ <member '__dict__' of 'module' objects>
         │     └ <module '__main__' from 'D:\\StabDiff\\SD-20062022\\stable-diffusion-webui\\scripts\\webui_streamlit.py'>
         └ <code object <module> at 0x000002128BAEC500, file "D:\StabDiff\SD-20062022\stable-diffusion-webui\scripts\webui_streamlit.py"...

  File "D:\StabDiff\SD-20062022\stable-diffusion-webui\scripts\webui_streamlit.py", line 203, in <module>
    layout()
    └ <function layout at 0x00000210C67565E0>

> File "D:\StabDiff\SD-20062022\stable-diffusion-webui\scripts\webui_streamlit.py", line 136, in layout
    layout()
    └ <function layout at 0x00000210D200E670>

  File "scripts\txt2img.py", line 664, in layout
    load_models(use_LDSR=st.session_state["use_LDSR"], LDSR_model=st.session_state["LDSR_model"],
    │                    │  │                                     │  └ <streamlit.runtime.state.session_state_proxy.SessionStateProxy object at 0x00000210BCFBDDF0>
    │                    │  │                                     └ <module 'hydralit' from 'C:\\Users\\QSDFR\\.conda\\envs\\ldm\\lib\\site-packages\\hydralit\\__init__.py'>
    │                    │  └ <streamlit.runtime.state.session_state_proxy.SessionStateProxy object at 0x00000210BCFBDDF0>
    │                    └ <module 'hydralit' from 'C:\\Users\\QSDFR\\.conda\\envs\\ldm\\lib\\site-packages\\hydralit\\__init__.py'>
    └ <function load_models at 0x00000210D1CBCF70>

  File "scripts\sd_utils\__init__.py", line 458, in load_models
    config, device, model, modelCS, modelFS = load_sd_model(custom_model)
                                              │             └ 'HD-18'
                                              └ <function load_sd_model at 0x00000210D1DACF70>

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           │      │       │        │        └ {}
           │      │       │        └ ('HD-18',)
           │      │       └ ()
           │      └ <function load_sd_model at 0x00000210D1DACEE0>
           └ <function retry.<locals>.retry_decorator at 0x00000210D1DACCA0>

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\site-packages\retry\api.py", line 73, in retry_decorator
    return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter,
           │                │       │   │       │        │           │      │      │          │        └ 0
           │                │       │   │       │        │           │      │      │          └ 1
           │                │       │   │       │        │           │      │      └ None
           │                │       │   │       │        │           │      └ 0
           │                │       │   │       │        │           └ 5
           │                │       │   │       │        └ <class 'Exception'>
           │                │       │   │       └ {}
           │                │       │   └ ('HD-18',)
           │                │       └ <function load_sd_model at 0x00000210D1DACEE0>
           │                └ <class 'functools.partial'>
           └ <function __retry_internal at 0x00000210D0578EE0>

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\site-packages\retry\api.py", line 33, in __retry_internal
    return f()
           └ functools.partial(<function load_sd_model at 0x00000210D1DACEE0>, 'HD-18')

  File "scripts\sd_utils\__init__.py", line 1570, in load_sd_model
    model = load_model_from_config(config, ckpt_path)
            │                      │       └ 'models\\custom\\HD-18.ckpt'
            │                      └ {'model': {'base_learning_rate': 0.0001, 'target': 'ldm.models.diffusion.ddpm.LatentDiffusion', 'params': {'linear_start': 0....
            └ <function load_model_from_config at 0x00000210D1DB5040>

  File "scripts\sd_utils\__init__.py", line 498, in load_model_from_config
    sd = pl_sd["state_dict"]
         └ {'betas': tensor([0.0009, 0.0009, 0.0009, 0.0009, 0.0009, 0.0009, 0.0009, 0.0009, 0.0009,
                   0.0009, 0.0009, 0.0009, 0.0...

KeyError: 'state_dict'
ERROR      @ 2022-12-25 16:12:20 | __main__:<module>:203 - An error has been caught in function '<module>', process 'MainProcess' (7404), thread 'ScriptRunner.scriptThread' (16904):
Traceback (most recent call last):

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\threading.py", line 890, in _bootstrap
    self._bootstrap_inner()
    │    └ <function Thread._bootstrap_inner at 0x00000210B3402F70>
    └ <Thread(ScriptRunner.scriptThread, started 16904)>

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
    │    └ <function Thread.run at 0x00000210B3402CA0>
    └ <Thread(ScriptRunner.scriptThread, started 16904)>

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
    │    │        │    │        │    └ {}
    │    │        │    │        └ <Thread(ScriptRunner.scriptThread, started 16904)>
    │    │        │    └ ()
    │    │        └ <Thread(ScriptRunner.scriptThread, started 16904)>
    │    └ <bound method ScriptRunner._run_script_thread of ScriptRunner(_session_id='e090a7d7-971c-4361-bd43-c2bbabe5b345', _main_scrip...
    └ <Thread(ScriptRunner.scriptThread, started 16904)>

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 298, in _run_script_thread
    self._run_script(request.rerun_data)
    │    │           │       └ <property object at 0x00000210BB519F40>
    │    │           └ ScriptRequest(type=<ScriptRequestType.RERUN: 'RERUN'>, _rerun_data=RerunData(query_string='', widget_states=widgets {
    │    │               id: "...
    │    └ <function ScriptRunner._run_script at 0x00000210BB5C4DC0>
    └ ScriptRunner(_session_id='e090a7d7-971c-4361-bd43-c2bbabe5b345', _main_script_path='D:\\StabDiff\\SD-20062022\\stable-diffusi...

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 563, in _run_script
    exec(code, module.__dict__)
         │     │      └ <member '__dict__' of 'module' objects>
         │     └ <module '__main__' from 'D:\\StabDiff\\SD-20062022\\stable-diffusion-webui\\scripts\\webui_streamlit.py'>
         └ <code object <module> at 0x000002128BAEC500, file "D:\StabDiff\SD-20062022\stable-diffusion-webui\scripts\webui_streamlit.py"...

> File "D:\StabDiff\SD-20062022\stable-diffusion-webui\scripts\webui_streamlit.py", line 203, in <module>
    layout()
    └ <function layout at 0x00000210C67565E0>

  File "D:\StabDiff\SD-20062022\stable-diffusion-webui\scripts\webui_streamlit.py", line 136, in layout
    layout()
    └ <function layout at 0x00000210D200E670>

  File "scripts\txt2img.py", line 664, in layout
    load_models(use_LDSR=st.session_state["use_LDSR"], LDSR_model=st.session_state["LDSR_model"],
    │                    │  │                                     │  └ <streamlit.runtime.state.session_state_proxy.SessionStateProxy object at 0x00000210BCFBDDF0>
    │                    │  │                                     └ <module 'hydralit' from 'C:\\Users\\QSDFR\\.conda\\envs\\ldm\\lib\\site-packages\\hydralit\\__init__.py'>
    │                    │  └ <streamlit.runtime.state.session_state_proxy.SessionStateProxy object at 0x00000210BCFBDDF0>
    │                    └ <module 'hydralit' from 'C:\\Users\\QSDFR\\.conda\\envs\\ldm\\lib\\site-packages\\hydralit\\__init__.py'>
    └ <function load_models at 0x00000210D1CBCF70>

  File "scripts\sd_utils\__init__.py", line 458, in load_models
    config, device, model, modelCS, modelFS = load_sd_model(custom_model)
                                              │             └ 'HD-18'
                                              └ <function load_sd_model at 0x00000210D1DACF70>

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\site-packages\decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
           │      │       │        │        └ {}
           │      │       │        └ ('HD-18',)
           │      │       └ ()
           │      └ <function load_sd_model at 0x00000210D1DACEE0>
           └ <function retry.<locals>.retry_decorator at 0x00000210D1DACCA0>

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\site-packages\retry\api.py", line 73, in retry_decorator
    return __retry_internal(partial(f, *args, **kwargs), exceptions, tries, delay, max_delay, backoff, jitter,
           │                │       │   │       │        │           │      │      │          │        └ 0
           │                │       │   │       │        │           │      │      │          └ 1
           │                │       │   │       │        │           │      │      └ None
           │                │       │   │       │        │           │      └ 0
           │                │       │   │       │        │           └ 5
           │                │       │   │       │        └ <class 'Exception'>
           │                │       │   │       └ {}
           │                │       │   └ ('HD-18',)
           │                │       └ <function load_sd_model at 0x00000210D1DACEE0>
           │                └ <class 'functools.partial'>
           └ <function __retry_internal at 0x00000210D0578EE0>

  File "C:\Users\QSDFR\.conda\envs\ldm\lib\site-packages\retry\api.py", line 33, in __retry_internal
    return f()
           └ functools.partial(<function load_sd_model at 0x00000210D1DACEE0>, 'HD-18')

  File "scripts\sd_utils\__init__.py", line 1570, in load_sd_model
    model = load_model_from_config(config, ckpt_path)
            │                      │       └ 'models\\custom\\HD-18.ckpt'
            │                      └ {'model': {'base_learning_rate': 0.0001, 'target': 'ldm.models.diffusion.ddpm.LatentDiffusion', 'params': {'linear_start': 0....
            └ <function load_model_from_config at 0x00000210D1DB5040>

  File "scripts\sd_utils\__init__.py", line 498, in load_model_from_config
    sd = pl_sd["state_dict"]
         └ {'betas': tensor([0.0009, 0.0009, 0.0009, 0.0009, 0.0009, 0.0009, 0.0009, 0.0009, 0.0009,
                   0.0009, 0.0009, 0.0009, 0.0...
@Delcos
Copy link
Owner

Delcos commented Dec 25, 2022

There are a few things that could cause that, firstly I'd try redownloading the ckpt file, as sometimes it being corrupt from downloading can be the issue.

Second I'd try with a redownload the ui, in a clean folder, and if it loads from that then it's an issue with your original install. I would try redownloading the model file first though.

@Kuroseji
Copy link
Author

Thanks for the tips but neither fix worked. I'm going to assume it's an issue with the code itself and hope it get's fixed eventually. Thanks for trying though and thanks for working on this model.

@linklight2
Copy link

linklight2 commented Dec 28, 2022

I'm having a similar issue with the current model, hckpt-18. The error message I get is this:

KeyError                                  Traceback (most recent call last)
<ipython-input-4-127af4bf47ad> in <module>
    110 opt = config()
    111 config = OmegaConf.load(f"{opt.config}")
--> 112 model = load_model_from_config(config, f"{opt.ckpt}")
    113 model = model.to(device)
    114 batch_idx = 0

<ipython-input-4-127af4bf47ad> in load_model_from_config(config, ckpt, verbose)
     79     if "global_step" in pl_sd:
     80         print(f"Global Step: {pl_sd['global_step']}")
---> 81     sd = pl_sd["state_dict"]
     82     model = instantiate_from_config(config.model)
     83     m, u = model.load_state_dict(sd, strict=False)

KeyError: 'state_dict'

16 and 17 both worked for me, so it's confusing why 18 is showing such an error. As the poster did above, I tried both methods, and even loaded the model into a Google colab. The model failed to work in all these instances due to this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants