Stable Diffusion使用新模型时lowvram问题

问题描述

在WebUI上选择从网上下载的*.safetensors新模型后,出现如下报错:

Applying attention optimization: sub-quadratic... done.
Model loaded in 16.2s (load weights from disk: 0.5s, create model: 0.9s, apply weights to model: 13.4s, apply dtype to VAE: 0.2s, move model to device: 0.1s, load textual inversion embeddings: 0.2s, calculate empty prompt: 0.8s).
Reusing loaded model dreamshaper_8.safetensors [879db523c3] to load AnythingXL_xl.safetensors [8421598e93]
Loading weights [8421598e93] from /Users/couldhll/Desktop/stable-diffusion-webui/models/Stable-diffusion/AnythingXL_xl.safetensors
Creating model from config: /Users/couldhll/Desktop/stable-diffusion-webui/repositories/generative-models/configs/inference/sd_xl_base.yaml
changing setting sd_model_checkpoint to AnythingXL_xl.safetensors [8421598e93]: RuntimeError
Traceback (most recent call last):
  File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/options.py", line 165, in set
    option.onchange()
  File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/call_queue.py", line 13, in f
    res = func(*args, **kwargs)
  File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/initialize_util.py", line 181, in <lambda>
    shared.opts.onchange("sd_model_checkpoint", wrap_queued_call(lambda: sd_models.reload_model_weights()), call=False)
  File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/sd_models.py", line 879, in reload_model_weights
    load_model(checkpoint_info, already_loaded_state_dict=state_dict)
  File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/sd_models.py", line 751, in load_model
    send_model_to_device(sd_model)
  File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/sd_models.py", line 681, in send_model_to_device
    m.to(shared.device)
  File "/Users/couldhll/Desktop/stable-diffusion-webui/venv/lib/python3.10/site-packages/lightning_fabric/utilities/device_dtype_mixin.py", line 54, in to
    return super().to(*args, **kwargs)
  File "/Users/couldhll/Desktop/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1160, in to
    return self._apply(convert)
  File "/Users/couldhll/Desktop/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 810, in _apply
    module._apply(fn)
  File "/Users/couldhll/Desktop/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 810, in _apply
    module._apply(fn)
  File "/Users/couldhll/Desktop/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 810, in _apply
    module._apply(fn)
  [Previous line repeated 2 more times]
  File "/Users/couldhll/Desktop/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 833, in _apply
    param_applied = fn(param)
  File "/Users/couldhll/Desktop/stable-diffusion-webui/venv/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1158, in convert
    return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
RuntimeError: MPS backend out of memory (MPS allocated: 6.51 GB, other allocations: 243.82 MB, max allowed: 6.80 GB). Tried to allocate 120.62 MB on private pool. Use PYTORCH_MPS_HIGH_WATERMARK_RATIO=0.0 to disable upper limit for memory allocations (may cause system failure).

*** Error completing request
*** Arguments: ('task(g4jhu75lk3xb84y)', <gradio.routes.Request object at 0x169974070>, 'a muscular female,muscles in the legs, bra,T-back,brown skin, short hair', '', [], 1, 1, 9, 512, 512, False, 0.7, 2, 'Latent', 0, 0, 0, 'Use same checkpoint', 'Use same sampler', 'Use same scheduler', '', '', [], 0, 20, 'DPM++ 2M', 'Automatic', False, '', 0.8, -1, False, -1, 0, 0, 0, False, False, 'positive', 'comma', 0, False, False, 'start', '', 1, '', [], 0, '', [], 0, '', [], True, False, False, False, False, False, False, 0, False) {}
    Traceback (most recent call last):
      File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/call_queue.py", line 57, in f
        res = list(func(*args, **kwargs))
      File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/call_queue.py", line 36, in f
        res = func(*args, **kwargs)
      File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/txt2img.py", line 109, in txt2img
        processed = processing.process_images(p)
      File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/processing.py", line 832, in process_images
        sd_models.reload_model_weights()
      File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/sd_models.py", line 860, in reload_model_weights
        sd_model = reuse_model_from_already_loaded(sd_model, checkpoint_info, timer)
      File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/sd_models.py", line 793, in reuse_model_from_already_loaded
        send_model_to_cpu(sd_model)
      File "/Users/couldhll/Desktop/stable-diffusion-webui/modules/sd_models.py", line 662, in send_model_to_cpu
        if m.lowvram:
    AttributeError: 'NoneType' object has no attribute 'lowvram'

问题解决

运行webui时候带参数lowvram:./webui.sh --lowvram
或者
在webui-user.sh中找到#export COMMANDLINE_ARGS=""行改为:export COMMANDLINE_ARGS="--lowvram --skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate"

PS:因为本机系统是macos,所以需要带有macos特有的参数:--skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate是从webui-macos-env.sh文件中(export COMMANDLINE_ARGS="--skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate")复制过来的

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注