AUTOMATIC1111 / stable-diffusion-webui

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

[Bug]: 运行提示“RuntimeError: MPS backend out of memory (MPS allocated: 4.06 GB, other allocations: 2.73 GB, max allowed: 6.77 GB). Tried to allocate 5.00 MB on private pool. Use PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 to disable upper limit for memory allocations (may cause system failure).” #11848

Closed tonystjack closed 1 year ago

tonystjack commented 1 year ago

Is there an existing issue for this?

What happened?

在运行“stable-diffusion-webui”时,报错提示 “RuntimeError: MPS backend out of memory (MPS allocated: 4.06 GB, other allocations: 2.73 GB, max allowed: 6.77 GB). Tried to allocate 5.00 MB on private pool. Use PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 to disable upper limit for memory allocations (may cause system failure).”

Steps to reproduce the problem

运行时mac电脑的运行内存还剩下5G左右

What should have happened?

正常渲染图片

Version or Commit where the problem happens

v1.4.1

What Python version are you running on ?

Python 3.10.x

What platforms do you use to access the UI ?

MacOS

What device are you running WebUI on?

CPU

Cross attention optimization

sdp

What browsers do you use to access the UI ?

Google Chrome

Command Line Arguments

List of extensions

Console logs

Last login: Mon Jul 17 22:40:17 on console
(base) tony_jack@zijuyingshideMacBook-Pro stable-diffusion-webui % ./webui.sh

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Running on tony_jack user
################################################################

################################################################
Repo already cloned, using it as install directory
################################################################

################################################################
Create and activate python venv
################################################################

################################################################
Launching launch.py...
################################################################
Python 3.10.9 (main, Mar  1 2023, 12:33:47) [Clang 14.0.6 ]
Version: v1.4.1
Commit hash: f865d3e11647dfd6c7b2cdf90dde24680e58acd8
Installing requirements
Launching Web UI with arguments: --skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate
No module 'xformers'. Proceeding without it.
Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled
Loading weights [a83e25fe5b] from /Users/tony_jack/AI/stable-diffusion-webui/models/Stable-diffusion/3Guofeng3_v34.safetensors
Creating model from config: /Users/tony_jack/AI/stable-diffusion-webui/configs/v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
OMP: Warning #191: Forking a process while a parallel region is active is potentially unsafe.
preload_extensions_git_metadata for 8 extensions took 0.14s
Running on local URL:  http://127.0.0.1:7860
DiffusionWrapper has 859.52 M params.
OMP: Warning #191: Forking a process while a parallel region is active is potentially unsafe.
Running on public URL: https://d7fb85c0a17d5f0b29.gradio.live

This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces
Startup time: 11.7s (import torch: 2.8s, import gradio: 0.9s, import ldm: 0.4s, other imports: 1.3s, load scripts: 0.7s, create ui: 1.0s, gradio launch: 4.4s).
Applying attention optimization: InvokeAI... done.
Textual inversion embeddings loaded(0): 
Model loaded in 10.9s (load weights from disk: 0.8s, create model: 0.8s, apply weights to model: 3.7s, apply half(): 1.9s, move model to device: 2.7s, calculate empty prompt: 0.7s).
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [00:42<00:00,  2.13s/it]
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 20/20 [03:46<00:00, 11.30s/it]
*** Error completing request██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 40/40 [04:45<00:00, 13.83s/it]
*** Arguments: ('task(ahxf7u2cb33h4zm)', 'best quality,masterpiece,highres,1girl,blush,(seductive smile:0.8),star-shaped pupils,red china hanfu,hanfu,chinese clothes,hair ornament,necklace,jewelry,Beautiful face,upon_body,tyndall effect,photorealistic,dark studio,rim lighting,two tone lighting,(high detailed skin:1.2),8k uhd,dslr,soft lighting,high quality,volumetric lighting,candid,Photograph,high resolution,4k,8k,Bokeh,', '', [], 20, 0, True, True, 1, 1, 7, -1.0, -1.0, 0, 0, 0, False, 512, 512, True, 0.7, 2, 'Latent', 0, 0, 0, 0, '', '', [], 0, False, False, 'positive', 'comma', 0, False, False, '', 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0) {}
    Traceback (most recent call last):
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/call_queue.py", line 55, in f
        res = list(func(*args, **kwargs))
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/call_queue.py", line 35, in f
        res = func(*args, **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/txt2img.py", line 57, in txt2img
        processed = processing.process_images(p)
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/processing.py", line 620, in process_images
        res = process_images_inner(p)
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/processing.py", line 741, in process_images_inner
        x_samples_ddim = [decode_first_stage(p.sd_model, samples_ddim[i:i+1].to(dtype=devices.dtype_vae))[0].cpu() for i in range(samples_ddim.size(0))]
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/processing.py", line 741, in <listcomp>
        x_samples_ddim = [decode_first_stage(p.sd_model, samples_ddim[i:i+1].to(dtype=devices.dtype_vae))[0].cpu() for i in range(samples_ddim.size(0))]
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/processing.py", line 525, in decode_first_stage
        x = model.decode_first_stage(x)
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/sd_hijack_utils.py", line 17, in <lambda>
        setattr(resolved_obj, func_path[-1], lambda *args, **kwargs: self(*args, **kwargs))
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/sd_hijack_utils.py", line 26, in __call__
        return self.__sub_func(self.__orig_func, *args, **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/sd_hijack_unet.py", line 76, in <lambda>
        first_stage_sub = lambda orig_func, self, x, **kwargs: orig_func(self, x.to(devices.dtype_vae), **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
        return func(*args, **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/models/diffusion/ddpm.py", line 826, in decode_first_stage
        return self.first_stage_model.decode(z)
      File "/Users/tony_jack/AI/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/models/autoencoder.py", line 90, in decode
        dec = self.decoder(z)
      File "/Users/tony_jack/AI/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/modules/diffusionmodules/model.py", line 641, in forward
        h = self.up[i_level].upsample(h)
      File "/Users/tony_jack/AI/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/modules/diffusionmodules/model.py", line 64, in forward
        x = self.conv(x)
      File "/Users/tony_jack/AI/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/extensions-builtin/Lora/lora.py", line 415, in lora_Conv2d_forward
        return torch.nn.Conv2d_forward_before_lora(self, input)
      File "/Users/tony_jack/AI/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/conv.py", line 463, in forward
        return self._conv_forward(input, self.weight, self.bias)
      File "/Users/tony_jack/AI/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/conv.py", line 456, in _conv_forward
        return F.conv2d(F.pad(input, self._reversed_padding_repeated_twice, mode=self.padding_mode),
    RuntimeError: MPS backend out of memory (MPS allocated: 4.40 GB, other allocations: 1.96 GB, max allowed: 6.77 GB). Tried to allocate 1024.00 MB on private pool. Use PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 to disable upper limit for memory allocations (may cause system failure).

---
 20%|████████████████████████████████████▍                                                                                                                                                 | 4/20 [00:07<00:29,  1.84s/it]
  0%|                                                                                                                                                                                              | 0/20 [00:00<?, ?it/s]
*** Error completing request
*** Arguments: ('task(5d8vgvu7d0xywjs)', 'best quality,masterpiece,highres,1girl,blush,(seductive smile:0.8),star-shaped pupils,red china hanfu,hanfu,chinese clothes,hair ornament,necklace,jewelry,Beautiful face,upon_body,tyndall effect,photorealistic,dark studio,rim lighting,two tone lighting,(high detailed skin:1.2),8k uhd,dslr,soft lighting,high quality,volumetric lighting,candid,Photograph,high resolution,4k,8k,Bokeh,', '', [], 20, 0, True, True, 1, 1, 7, -1.0, -1.0, 0, 0, 0, False, 512, 512, True, 0.7, 2, 'Latent', 0, 0, 0, 0, '', '', [], 0, False, False, 'positive', 'comma', 0, False, False, '', 1, '', [], 0, '', [], 0, '', [], True, False, False, False, 0) {}
    Traceback (most recent call last):
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/call_queue.py", line 55, in f
        res = list(func(*args, **kwargs))
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/call_queue.py", line 35, in f
        res = func(*args, **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/txt2img.py", line 57, in txt2img
        processed = processing.process_images(p)
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/processing.py", line 620, in process_images
        res = process_images_inner(p)
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/processing.py", line 741, in process_images_inner
        x_samples_ddim = [decode_first_stage(p.sd_model, samples_ddim[i:i+1].to(dtype=devices.dtype_vae))[0].cpu() for i in range(samples_ddim.size(0))]
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/processing.py", line 741, in <listcomp>
        x_samples_ddim = [decode_first_stage(p.sd_model, samples_ddim[i:i+1].to(dtype=devices.dtype_vae))[0].cpu() for i in range(samples_ddim.size(0))]
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/processing.py", line 525, in decode_first_stage
        x = model.decode_first_stage(x)
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/sd_hijack_utils.py", line 17, in <lambda>
        setattr(resolved_obj, func_path[-1], lambda *args, **kwargs: self(*args, **kwargs))
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/sd_hijack_utils.py", line 26, in __call__
        return self.__sub_func(self.__orig_func, *args, **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/modules/sd_hijack_unet.py", line 76, in <lambda>
        first_stage_sub = lambda orig_func, self, x, **kwargs: orig_func(self, x.to(devices.dtype_vae), **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
        return func(*args, **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/models/diffusion/ddpm.py", line 826, in decode_first_stage
        return self.first_stage_model.decode(z)
      File "/Users/tony_jack/AI/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/models/autoencoder.py", line 90, in decode
        dec = self.decoder(z)
      File "/Users/tony_jack/AI/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/modules/diffusionmodules/model.py", line 631, in forward
        h = self.mid.attn_1(h)
      File "/Users/tony_jack/AI/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
        return forward_call(*args, **kwargs)
      File "/Users/tony_jack/AI/stable-diffusion-webui/repositories/stable-diffusion-stability-ai/ldm/modules/diffusionmodules/model.py", line 192, in forward
        w_ = w_ * (int(c)**(-0.5))
    RuntimeError: MPS backend out of memory (MPS allocated: 4.55 GB, other allocations: 1.60 GB, max allowed: 6.77 GB). Tried to allocate 1024.00 MB on private pool. Use PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 to disable upper limit for memory allocations (may cause system failure).

---
^CInterrupted with signal 2 in <frame at 0x7f8580794780, file '/Users/tony_jack/anaconda3/lib/python3.10/threading.py', line 324, code wait>

Additional information

我的电脑是mac电脑 型号: MacBook Pro 16-inch, 2019 处理器: 2.3 GHz 八核Intel Core i9 图形卡: Intel UHD Graphics 630 1536 MB 内存 16 GB 2667 MHz DDR4 MacOS: 13.4.1 (c) (22F770820d)

owspace commented 1 year ago

+1

akx commented 1 year ago

You probably shouldn't try to use MPS on a Mac with an Intel GPU. Try --use-cpu=all.

dlnetworks commented 1 year ago

--use-cpu=all means no gpu acceleration... no one has time for that. you may want to try launching with

--no-half --precision full

or as the error states...

Use PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 to disable upper limit for memory allocations (may cause system failure).

i have tried this before. while it didnt cause a system failure, it def impacts system performance significantly. so use at your own risk.