忘却まとめ

Blenderの中級者・上級者向けの踏み込んだ情報や、アドオン・3DCGに関する情報を記事にします

【Stable Diffusion2.0】WebUI での実行時の生成失敗エラーの解決方法【”RuntimeError: Error(s) in loading state_dict for LatentDiffusion”】

AIアート

投稿日:

Stable Diffusion2.0 を WebUI(Automatic1111版) で実行した場合に、下記のような長いエラーが出て生成失敗する問題がある。
これの解決法を紹介する。

Error Log

Loading weights [2c02b20a] from D:\ml\sd\sdwebui-automatic1111\models\Stable-diffusion\768-v-ema.ckpt
Global Step: 140000
Traceback (most recent call last):
  File "C:\Users\Jan\miniconda3\envs\auto1111\lib\site-packages\gradio\routes.py", line 284, in run_predict
    output = await app.blocks.process_api(
  File "C:\Users\Jan\miniconda3\envs\auto1111\lib\site-packages\gradio\blocks.py", line 982, in process_api
    result = await self.call_function(fn_index, inputs, iterator)
  File "C:\Users\Jan\miniconda3\envs\auto1111\lib\site-packages\gradio\blocks.py", line 824, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "C:\Users\Jan\miniconda3\envs\auto1111\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "C:\Users\Jan\miniconda3\envs\auto1111\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
    return await future
  File "C:\Users\Jan\miniconda3\envs\auto1111\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
    result = context.run(func, *args)
  File "D:\ml\sd\sdwebui-automatic1111\modules\ui.py", line 1661, in <lambda>
    fn=lambda value, k=k: run_settings_single(value, key=k),
  File "D:\ml\sd\sdwebui-automatic1111\modules\ui.py", line 1502, in run_settings_single
    if not opts.set(key, value):
  File "D:\ml\sd\sdwebui-automatic1111\modules\shared.py", line 470, in set
    self.data_labels[key].onchange()
  File "D:\ml\sd\sdwebui-automatic1111\webui.py", line 43, in f
    res = func(*args, **kwargs)
  File "D:\ml\sd\sdwebui-automatic1111\webui.py", line 85, in <lambda>
    shared.opts.onchange("sd_model_checkpoint", wrap_queued_call(lambda: modules.sd_models.reload_model_weights()))
  File "D:\ml\sd\sdwebui-automatic1111\modules\sd_models.py", line 289, in reload_model_weights
    load_model_weights(sd_model, checkpoint_info)
  File "D:\ml\sd\sdwebui-automatic1111\modules\sd_models.py", line 182, in load_model_weights
    model.load_state_dict(sd, strict=False)
  File "C:\Users\Jan\miniconda3\envs\auto1111\lib\site-packages\torch\nn\modules\module.py", line 1604, in load_state_dict
    raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format(
RuntimeError: Error(s) in loading state_dict for LatentDiffusion:
    size mismatch for model.diffusion_model.input_blocks.1.1.proj_in.weight: copying a param with shape torch.Size([320, 320]) from checkpoint, the shape in current model is torch.Size([320, 320, 1, 1]).
    size mismatch for model.diffusion_model.input_blocks.1.1.transformer_blocks.0.attn2.to_k.weight: copying a param with shape torch.Size([320, 1024]) from checkpoint, the shape in current model is torch.Size([320, 768]).
    size mismatch for model.diffusion_model.input_blocks.1.1.transformer_blocks.0.attn2.to_v.weight: copying a param with shape torch.Size([320, 1024]) from checkpoint, the shape in current model is torch.Size([320, 768]).

解決方法

下記リンク先のリンクの.yamlファイルをDLして同名にし、同じ場所に置く。

[Bug]: SD v2.0-768 "RuntimeError: Error(s) in loading state_dict for LatentDiffusion" · Issue #5070 · AUTOMATIC1111/stable-diffusion-webui

SD2.0のモデルである768-v-ema.ckptをDL。

stable-diffusion-2- huggingface

下記の.yamlファイルをDLし、上記でDLした.ckptと同名にして同じ場所に置く。

environment.yaml -github

実行

再起動して生成を実行すると、下記のようになって3.94GのなにかをDLしたあと、画像生成ができるようになった。

-AIアート

Copyright© 忘却まとめ , 2023 All Rights Reserved Powered by STINGER.