AUTOMATIC1111 / stable-diffusion-webui

Stable Diffusion web UI
GNU Affero General Public License v3.0
144.22k stars 27.09k forks source link

[Bug]: Mac更新1.6.0后无法使用TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead. #12907

Open owspace opened 1 year ago

owspace commented 1 year ago

Is there an existing issue for this?

What happened?

启动webui后无法生成图像

Steps to reproduce the problem

1.启动webui

  1. 输入提示词 3.开始生成图片

What should have happened?

正常生成图片

Sysinfo

{ "date": "Thu Aug 31 22:36:37 2023", "timestamp": "22:36:52", "uptime": "Thu Aug 31 22:18:16 2023", "version": { "app": "stable-diffusion-webui", "updated": "2023-08-31", "hash": "5ef669de", "url": "https://github.com/AUTOMATIC1111/stable-diffusion-webui/tree/master" }, "torch": "2.0.1 autocast half", "gpu": {}, "state": { "started": "Thu Aug 31 22:36:52 2023", "step": "0 / 0", "jobs": "0 / 0", "flags": "", "job": "", "text-info": "" }, "memory": { "ram": { "free": 29.98, "used": 2.02, "total": 32 } }, "optimizations": [ "none" ], "libs": { "xformers": "", "diffusers": "", "transformers": "4.30.2" }, "repos": { "Stable Diffusion": "[cf1d67a] 2023-03-25", "Stable Diffusion XL": "[45c443b] 2023-07-26", "CodeFormer": "[c5b4593] 2022-09-09", "BLIP": "[48211a1] 2022-06-07", "k_diffusion": "[ab527a9] 2023-08-12" }, "device": { "active": "mps", "dtype": "torch.float16", "vae": "torch.float32", "unet": "torch.float16" },

}

What browsers do you use to access the UI ?

Google Chrome

Console logs

Loading weights [0b9e46a0b0] from /Users/alyears/stable-diffusion-webui/models/Stable-diffusion/人物/墨幽人造人_v1040.safetensors
Traceback (most recent call last):
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/routes.py", line 488, in run_predict
    output = await app.get_blocks().process_api(
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/blocks.py", line 1431, in process_api
    result = await self.call_function(
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/blocks.py", line 1103, in call_function
    prediction = await anyio.to_thread.run_sync(
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/to_thread.py", line 33, in run_sync
    return await get_asynclib().run_sync_in_worker_thread(
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 877, in run_sync_in_worker_thread
    return await future
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "/Users/alyears/stable-diffusion-webui/modules/ui_extra_networks.py", line 392, in pages_html
    return refresh()
  File "/Users/alyears/stable-diffusion-webui/modules/ui_extra_networks.py", line 398, in refresh
    pg.refresh()
  File "/Users/alyears/stable-diffusion-webui/modules/ui_extra_networks_textual_inversion.py", line 13, in refresh
    sd_hijack.model_hijack.embedding_db.load_textual_inversion_embeddings(force_reload=True)
  File "/Users/alyears/stable-diffusion-webui/modules/textual_inversion/textual_inversion.py", line 255, in load_textual_inversion_embeddings
    self.expected_shape = self.get_expected_shape()
  File "/Users/alyears/stable-diffusion-webui/modules/textual_inversion/textual_inversion.py", line 154, in get_expected_shape
    vec = shared.sd_model.cond_stage_model.encode_embedding_init_text(",", 1)
AttributeError: 'NoneType' object has no attribute 'cond_stage_model'
Creating model from config: /Users/alyears/stable-diffusion-webui/configs/v1-inference.yaml
loading stable diffusion model: TypeError
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/python@3.10/3.10.12_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 973, in _bootstrap
    self._bootstrap_inner()
  File "/opt/homebrew/Cellar/python@3.10/3.10.12_1/Frameworks/Python.framework/Versions/3.10/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/anyio/_backends/_asyncio.py", line 807, in run
    result = context.run(func, *args)
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/gradio/utils.py", line 707, in wrapper
    response = f(*args, **kwargs)
  File "/Users/alyears/stable-diffusion-webui/modules/ui.py", line 1298, in <lambda>
    update_image_cfg_scale_visibility = lambda: gr.update(visible=shared.sd_model and shared.sd_model.cond_stage_key == "edit")
  File "/Users/alyears/stable-diffusion-webui/modules/shared_items.py", line 110, in sd_model
    return modules.sd_models.model_data.get_sd_model()
  File "/Users/alyears/stable-diffusion-webui/modules/sd_models.py", line 499, in get_sd_model
    load_model()
  File "/Users/alyears/stable-diffusion-webui/modules/sd_models.py", line 626, in load_model
    load_model_weights(sd_model, checkpoint_info, state_dict, timer)
  File "/Users/alyears/stable-diffusion-webui/modules/sd_models.py", line 353, in load_model_weights
    model.load_state_dict(state_dict, strict=False)
  File "/Users/alyears/stable-diffusion-webui/modules/sd_disable_initialization.py", line 223, in <lambda>
    module_load_state_dict = self.replace(torch.nn.Module, 'load_state_dict', lambda *args, **kwargs: load_state_dict(module_load_state_dict, *args, **kwargs))
  File "/Users/alyears/stable-diffusion-webui/modules/sd_disable_initialization.py", line 221, in load_state_dict
    original(module, state_dict, strict=strict)
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 2027, in load_state_dict
    load(self, state_dict)
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 2015, in load
    load(child, child_state_dict, child_prefix)
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 2015, in load
    load(child, child_state_dict, child_prefix)
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 2015, in load
    load(child, child_state_dict, child_prefix)
  [Previous line repeated 3 more times]
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 2009, in load
    module._load_from_state_dict(
  File "/Users/alyears/stable-diffusion-webui/modules/sd_disable_initialization.py", line 226, in <lambda>
    conv2d_load_from_state_dict = self.replace(torch.nn.Conv2d, '_load_from_state_dict', lambda *args, **kwargs: load_from_state_dict(conv2d_load_from_state_dict, *args, **kwargs))
  File "/Users/alyears/stable-diffusion-webui/modules/sd_disable_initialization.py", line 191, in load_from_state_dict
    module._parameters[name] = torch.nn.parameter.Parameter(torch.zeros_like(param, device=device, dtype=dtype), requires_grad=param.requires_grad)
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/_meta_registrations.py", line 1780, in zeros_like
    return aten.empty_like.default(
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/_ops.py", line 287, in __call__
    return self._op(*args, **kwargs or {})
  File "/Users/alyears/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/_refs/__init__.py", line 4254, in empty_like
    return torch.empty_strided(
TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.

Stable diffusion model failed to load

Additional information

No response

YuuLinz commented 1 year ago

我跳到你的讨论:)我面临着与nicklansley提到的同样的问题,我已遵循你的指示并确保仅使用 venv。Stacktrace 与最终消息非常相似。

TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.

我注意到,如果我从 UI 下拉列表中在两个模型之间切换,那么它就可以工作

yes 我遇到了同样的问题 但是在切换模型后能够正常使用,每次启动的第一个模型都会保存,我很难理解这是为什么

andymove commented 1 year ago

I tried the solutions given

This works for me. 2 steps:

  1. check the option here: Settings->Stable Diffusion->Upcast cross attention layer to float32
  2. ./webui.sh --no-half

More Info: When using other checkpoint, may still cause the error: TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.

Work·around: Switch Stable Diffusion checkpoint to 'v1-5-pruned-emaonly.ckpt [cc6cb27103]'; and then switch back. The error disappear.

FYI. I got the solution base on this hint when I click 'Generate' button in the 'txt2img' tab : NansException: A tensor with all NaNs was produced in Unet. This could be either because there's not enough precision to represent the picture, or because your video card does not support half type. Try setting the "Upcast cross attention layer to float32" option in Settings > Stable Diffusion or using the --no-half commandline argument to fix this. Use --disable-nan-check commandline argument to disable this check.

luffy2025 commented 1 year ago

I also encountered the same issue, and I believe it was caused by loading the model during the initial startup. Here's how I resolved it:

  1. In the "models/Stable-diffusion" folder, I kept only one reliable "safetensors" file, such as "AnythingV5V3_v5PrtRE.safetensors" or "v1-5-pruned.safetensors."
  2. I restarted the ./webui.sh, and there were no error messages.
  3. I placed the other models back into their original folder.
  4. I started the ./webui.sh again, and there were still no error messages. The problem was resolved. My environment is M3 Max. Hope this can help you out.
ShinChven commented 11 months ago

I also encountered the same issue, and I believe it was caused by loading the model during the initial startup. Here's how I resolved it:

  1. In the "models/Stable-diffusion" folder, I kept only one reliable "safetensors" file, such as "AnythingV5V3_v5PrtRE.safetensors" or "v1-5-pruned.safetensors."
  2. I restarted the ./webui.sh, and there were no error messages.
  3. I placed the other models back into their original folder.
  4. I started the ./webui.sh again, and there were still no error messages. The problem was resolved. My environment is M3 Max. Hope this can help you out.

Switching the models can also solve this problem temporarily.

esonhon commented 9 months ago

我跳到你的讨论:)我面临着与nicklansley提到的同样的问题,我已遵循你的指示并确保仅使用 venv。Stacktrace 与最终消息非常相似。

TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.

我注意到,如果我从 UI 下拉列表中在两个模型之间切换,那么它就可以工作

yes 我遇到了同样的问题 但是在切换模型后能够正常使用,每次启动的第一个模型都会保存,我很难理解这是为什么

Yes, it works for me.

leemax commented 9 months ago

这是有些模型加载的时候,出现的错误,导致无法加载。 我的解决方案: 升级pytorh到2.2.1,会提示torchvision0.15.2对torch 2.0.1有依赖关系,把torchvision升级到0.17.1 现在可以成功加载chilloutrealistic_v21.safetensors模型

andupotorac commented 7 months ago

Tried to use --disable-model-loading-ram-optimization and can workaround this error.

BASED AND GOATED

Worked for me too. The error is gone.

bytqq07 commented 6 months ago

I had the same issue and at least for me it was related to a messed up virtualenv. I had to do this:

  1. Clone a new copy of a1111
  2. cd to the new cloned directory.
  3. Run virtualenv venv -p python3 source venv/bin/activate
  4. Then in the same shell window run webui.sh and let it repull all the dependencies.

After this the issue with certain older models went away.

hey, but if I get this error?

"source venv/bin/activate zsh: command not found: virtualenv"

DDxxgg commented 4 months ago

--disable-model-loading-ram-optimization

it works for me too, thanks.

ghost commented 4 months ago

I had the same issue and at least for me it was related to a messed up virtualenv. I had to do this:

  1. Clone a new copy of a1111
  2. cd to the new cloned directory.
  3. Run virtualenv venv -p python3 source venv/bin/activate
  4. Then in the same shell window run webui.sh and let it repull all the dependencies.

After this the issue with certain older models went away.

Mey I ask what is a1111?

smlbiobot commented 3 months ago

@ukateki a1111 = Automatic1111 = this repo