【ComfyUI】RuntimeError: CUDA error: operation not supported

前言

最近好不容易,安装好ComfyUI后,启动也OK,点击生成图片时,报错了

got prompt
model_type EPS
adm 0
making attention of type 'vanilla-pytorch' with 512 in_channels
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
making attention of type 'vanilla-pytorch' with 512 in_channels
missing {
    
    'cond_stage_model.text_projection', 'cond_stage_model.logit_scale'}
left over keys: dict_keys(['cond_stage_model.transformer.text_model.embeddings.position_ids', 'model_ema.decay', 'model_ema.num_updates'])
loading new
loading new
loading in lowvram mode 1842.6899042129517
!!! Exception during processing !!!
Traceback (most recent call last):
  File "E:\openai\project\ComfyUI\execution.py", line 152, in recursive_execute
    output_data, output_ui = get_output_data(obj, input_data_all)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\openai\project\ComfyUI\execution.py", line 82, in get_output_data
    return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\openai\project\ComfyUI\execution.py", line 75, in map_node_over_list
    results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\openai\project\ComfyUI\nodes.py", line 1236, in sample
    return common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\openai\project\ComfyUI\nodes.py", line 1206, in common_ksampler
    samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\openai\project\ComfyUI\comfy\sample.py", line 81, in sample
    comfy.model_management.load_models_gpu([model] + models, comfy.model_management.batch_area_memory(noise.shape[0] * noise.shape[2] * noise.shape[3]) + inference_memory)
  File "E:\openai\project\ComfyUI\comfy\model_management.py", line 394, in load_models_gpu
    cur_loaded_model = loaded_model.model_load(lowvram_model_memory)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "E:\openai\project\ComfyUI\comfy\model_management.py", line 288, in model_load
    accelerate.dispatch_model(self.real_model, device_map=device_map, main_device=self.device)
  File "D:\Program Files\Python\Lib\site-packages\accelerate\big_modeling.py", line 391, in dispatch_model
    attach_align_device_hook_on_blocks(
  File "D:\Program Files\Python\Lib\site-packages\accelerate\hooks.py", line 532, in attach_align_device_hook_on_blocks
    add_hook_to_module(module, hook)
  File "D:\Program Files\Python\Lib\site-packages\accelerate\hooks.py", line 155, in add_hook_to_module
    module = hook.init_hook(module)
             ^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Program Files\Python\Lib\site-packages\accelerate\hooks.py", line 253, in init_hook
    set_module_tensor_to_device(module, name, self.execution_device)
  File "D:\Program Files\Python\Lib\site-packages\accelerate\utils\modeling.py", line 307, in set_module_tensor_to_device
    new_value = old_value.to(device)
                ^^^^^^^^^^^^^^^^^^^^
RuntimeError: CUDA error: operation not supported
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.

这个问题查了挺久的资料的,特意记录下解决方案。

解决办法

官方提供了两种解决策略。

方式一:黑名单策略

在这里插入图片描述

在这里插入图片描述

加完后,再重启。发现还是不行。

方式二:启动时添加–disable-cuda-malloc

# 注意--disable-cuda-malloc
E:\openai\project\ComfyUI>python main.py --disable-cuda-malloc

最后,通过方式二,得以解决。


其实,在启动的时候,它已经告诉我们可能会遇到的问题;

在这里插入图片描述

有两段提示:

  1. 第一段提示:
Trying to enable lowvram mode because your GPU seems to have 4GB or less. If you don't want this use: --normalvram
Set vram state to: LOW_VRAM

说,由于我的GPU<=4G,所以它尝试开启了lowvram模式。如果我想使用正常模式,就在启动命令行后面添加--normalvram

  1. 第二段提示:
WARNING: this card most likely does not support cuda-malloc, if you get "CUDA error" please run ComfyUI with: --disable-cuda-malloc

就是,发现我的GPU卡,并不支持cuda-malloc函数或接口。如果在后续的运行中遇到了CUDA error错误,那么就在启动命令行后面,添加:--disable-cuda-malloc


参考地址:

CUDA error: operation not supported, in KSampler

https://github.com/comfyanonymous/ComfyUI/issues/940#issuecomment-1691327437

https://github.com/comfyanonymous/ComfyUI/issues/940#issuecomment-1642586085

猜你喜欢

转载自blog.csdn.net/u013066244/article/details/133052534