aszc-dev / ComfyUI-CoreMLSuite

A set of custom nodes for ComfyUI that allow you to use Core ML models in your ComfyUI workflows.
GNU General Public License v3.0
131 stars 12 forks source link

TypeError: Expected shape (2, 320, 64, 64), got (1, 320, 64, 64) for input: additional_residual_0 #4

Closed bvndls closed 1 year ago

bvndls commented 1 year ago

How to reproduce:

Device - Base model M1 Air (7 Core GPU, 8GB RAM)

  1. Install ComfyUI
  2. Install CoreMLSuite
  3. Install ComfyUI Manager Start ComfyUI with FP16
    python main.py --force-fp16
  4. Load the workflow

  1. Load the snake image

SCR-20231031-ojgt-2

Error log:

(comfy) ➜  ComfyUI git:(master) ✗ python3 main.py --force-fp16
** ComfyUI start up time: 2023-10-31 16:27:25.261506

Prestartup times for custom nodes:
   0.0 seconds: /Users/bvndls/ComfyUI/ComfyUI/custom_nodes/ComfyUI-Manager

Total VRAM 8192 MB, total RAM 8192 MB
Forcing FP16.
/Users/bvndls/ComfyUI/comfy/lib/python3.9/site-packages/urllib3/__init__.py:34: NotOpenSSLWarning: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020
  warnings.warn(
Set vram state to: SHARED
Device: mps
VAE dtype: torch.float32
Using sub quadratic optimization for cross attention, if you have memory or speed issues try using: --use-split-cross-attention
### Loading: ComfyUI-Manager (V0.36)
### ComfyUI Revision: 1631 [c837a173] | Released on '2023-10-30'
Registered sys.path: ['/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/comfyui_controlnet_aux/src/custom_pycocotools', '/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/comfyui_controlnet_aux/src/custom_oneformer', '/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/comfyui_controlnet_aux/src/__init__.py', '/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/comfyui_controlnet_aux/src/custom_mmpkg', '/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/comfyui_controlnet_aux/src/custom_midas_repo', '/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/comfyui_controlnet_aux/src/custom_detectron2', '/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/comfyui_controlnet_aux/src/controlnet_aux', '/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/comfyui_controlnet_aux/src', '/Users/bvndls/ComfyUI/ComfyUI/comfy', '/Users/bvndls/ComfyUI/comfy/lib/python3.9/site-packages/git/ext/gitdb', '/Users/bvndls/ComfyUI/ComfyUI', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python39.zip', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/lib-dynload', '/Users/bvndls/ComfyUI/comfy/lib/python3.9/site-packages', '/var/folders/dq/k_8x61qj6zgg60mnx259fyqh0000gn/T/tmp1wzcun6i', '../..']
/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/comfyui_controlnet_aux/node_wrappers/dwpose.py:26: UserWarning: DWPose: Onnxruntime not found or doesn't come with acceleration providers, switch to OpenCV with CPU device. DWPose might run very slowly
  warnings.warn("DWPose: Onnxruntime not found or doesn't come with acceleration providers, switch to OpenCV with CPU device. DWPose might run very slowly")
scikit-learn version 1.3.2 is not supported. Minimum required version: 0.17. Maximum required version: 1.1.2. Disabling scikit-learn conversion API.
Torch version 2.2.0.dev20231030 has not been tested with coremltools. You may run into unexpected errors. Torch 2.0.0 is the most recent version that has been tested.

Import times for custom nodes:
   0.1 seconds: /Users/bvndls/ComfyUI/ComfyUI/custom_nodes/ComfyUI-Manager
   0.3 seconds: /Users/bvndls/ComfyUI/ComfyUI/custom_nodes/comfyui_controlnet_aux
   0.4 seconds: /Users/bvndls/ComfyUI/ComfyUI/custom_nodes/ComfyUI-CoreMLSuite

Starting server

To see the GUI go to: http://127.0.0.1:8188
FETCH DATA from: /Users/bvndls/ComfyUI/ComfyUI/custom_nodes/ComfyUI-Manager/extension-node-map.json
got prompt
INFO:coreml_suite.logger:Loading ControlledUnet.mlmodelc to CPU_AND_NE
INFO:python_coreml_stable_diffusion.coreml_model:Loading /Users/bvndls/ComfyUI/ComfyUI/models/unet/ControlledUnet.mlmodelc
INFO:python_coreml_stable_diffusion.coreml_model:Done. Took 3.8 seconds.
clip unexpected: ['text_model.embeddings.position_ids']
Requested to load SD1ClipModel
Loading 1 new model
[] []
model_type EPS
adm 0
WARNING:coreml_suite.logger:No latent image provided, using empty tensor.
Requested to load CoreMLModelWrapper
Requested to load ControlNet
Loading 2 new models
  0%|                                                                                                                                                                                                           | 0/20 [00:00<?, ?it/s]
ERROR:root:!!! Exception during processing !!!
ERROR:root:Traceback (most recent call last):
  File "/Users/bvndls/ComfyUI/ComfyUI/execution.py", line 153, in recursive_execute
    output_data, output_ui = get_output_data(obj, input_data_all)
  File "/Users/bvndls/ComfyUI/ComfyUI/execution.py", line 83, in get_output_data
    return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
  File "/Users/bvndls/ComfyUI/ComfyUI/execution.py", line 76, in map_node_over_list
    results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
  File "/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/ComfyUI-CoreMLSuite/coreml_suite/nodes.py", line 52, in sample
    return super().sample(
  File "/Users/bvndls/ComfyUI/ComfyUI/nodes.py", line 1237, in sample
    return common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)
  File "/Users/bvndls/ComfyUI/ComfyUI/nodes.py", line 1207, in common_ksampler
    samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
  File "/Users/bvndls/ComfyUI/ComfyUI/comfy/sample.py", line 100, in sample
    samples = sampler.sample(noise, positive_copy, negative_copy, cfg=cfg, latent_image=latent_image, start_step=start_step, last_step=last_step, force_full_denoise=force_full_denoise, denoise_mask=noise_mask, sigmas=sigmas, callback=callback, disable_pbar=disable_pbar, seed=seed)
  File "/Users/bvndls/ComfyUI/ComfyUI/comfy/samplers.py", line 728, in sample
    return sample(self.model, noise, positive, negative, cfg, self.device, sampler(), sigmas, self.model_options, latent_image=latent_image, denoise_mask=denoise_mask, callback=callback, disable_pbar=disable_pbar, seed=seed)
  File "/Users/bvndls/ComfyUI/ComfyUI/comfy/samplers.py", line 633, in sample
    samples = sampler.sample(model_wrap, sigmas, extra_args, callback, noise, latent_image, denoise_mask, disable_pbar)
  File "/Users/bvndls/ComfyUI/ComfyUI/comfy/samplers.py", line 589, in sample
    samples = getattr(k_diffusion_sampling, "sample_{}".format(sampler_name))(model_k, noise, sigmas, extra_args=extra_args, callback=k_callback, disable=disable_pbar, **extra_options)
  File "/Users/bvndls/ComfyUI/comfy/lib/python3.9/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/Users/bvndls/ComfyUI/ComfyUI/comfy/k_diffusion/sampling.py", line 580, in sample_dpmpp_2m
    denoised = model(x, sigmas[i] * s_in, **extra_args)
  File "/Users/bvndls/ComfyUI/comfy/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1519, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/Users/bvndls/ComfyUI/comfy/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1528, in _call_impl
    return forward_call(*args, **kwargs)
  File "/Users/bvndls/ComfyUI/ComfyUI/comfy/samplers.py", line 287, in forward
    out = self.inner_model(x, sigma, cond=cond, uncond=uncond, cond_scale=cond_scale, model_options=model_options, seed=seed)
  File "/Users/bvndls/ComfyUI/comfy/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1519, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
  File "/Users/bvndls/ComfyUI/comfy/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1528, in _call_impl
    return forward_call(*args, **kwargs)
  File "/Users/bvndls/ComfyUI/ComfyUI/comfy/k_diffusion/external.py", line 129, in forward
    eps = self.get_eps(input * c_in, self.sigma_to_t(sigma), **kwargs)
  File "/Users/bvndls/ComfyUI/ComfyUI/comfy/k_diffusion/external.py", line 155, in get_eps
    return self.inner_model.apply_model(*args, **kwargs)
  File "/Users/bvndls/ComfyUI/ComfyUI/comfy/samplers.py", line 275, in apply_model
    out = sampling_function(self.inner_model.apply_model, x, timestep, uncond, cond, cond_scale, model_options=model_options, seed=seed)
  File "/Users/bvndls/ComfyUI/ComfyUI/comfy/samplers.py", line 253, in sampling_function
    cond, uncond = calc_cond_uncond_batch(model_function, cond, uncond, x, timestep, max_total_area, model_options)
  File "/Users/bvndls/ComfyUI/ComfyUI/comfy/samplers.py", line 229, in calc_cond_uncond_batch
    output = model_function(input_x, timestep_, **c).chunk(batch_chunks)
  File "/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/ComfyUI-CoreMLSuite/coreml_suite/models.py", line 43, in apply_model
    chunked_out = [
  File "/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/ComfyUI-CoreMLSuite/coreml_suite/models.py", line 44, in <listcomp>
    self._apply_model(
  File "/Users/bvndls/ComfyUI/ComfyUI/custom_nodes/ComfyUI-CoreMLSuite/coreml_suite/models.py", line 83, in _apply_model
    np_out = self.diffusion_model(**model_input_kwargs)["noise_pred"]
  File "/Users/bvndls/ComfyUI/comfy/lib/python3.9/site-packages/python_coreml_stable_diffusion/coreml_model.py", line 97, in __call__
    self._verify_inputs(**kwargs)
  File "/Users/bvndls/ComfyUI/comfy/lib/python3.9/site-packages/python_coreml_stable_diffusion/coreml_model.py", line 90, in _verify_inputs
    raise TypeError(
TypeError: Expected shape (2, 320, 64, 64), got (1, 320, 64, 64) for input: additional_residual_0

Prompt executed in 11.72 seconds

Resorces Used:

  1. ControlNet from here
  2. ControlledUnet.mlmodelc from here
  3. CLIP from runwayml/stable-diffusion-v1-5 model.fp16.safetensors
  4. VAE from runwayml/stable-diffusion-v1-5 diffusion_pytorch_model.fp16.safetensors

Tried with various combinations of UNets, ControlNets, CLIPs, VAEs and images, either throws this error, or generates an image without following the LoadImage connected to ApplyControlNet, exmaple below

image
aszc-dev commented 1 year ago

Hello. Thanks again for your input, this helps a lot. I think I managed to fix the issue with controlnet data chunking and padding, please check if you're still getting this error.

rovo79 commented 1 year ago

Hello, incase the additional testing is helpful. I pulled the latest and still getting the same error.

got prompt
model_type EPS
adm 0
WARNING:coreml_suite.logger:No latent image provided, using empty tensor.
Requested to load CoreMLModelWrapper
Requested to load ControlNet
Loading 2 new models
  0%|                                                                                                                                                          | 0/30 [00:00<?, ?it/s]
ERROR:root:!!! Exception during processing !!!
ERROR:root:Traceback (most recent call last):
  File "/Users/abc/ComfyUI/execution.py", line 153, in recursive_execute
    output_data, output_ui = get_output_data(obj, input_data_all)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/execution.py", line 83, in get_output_data
    return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/execution.py", line 76, in map_node_over_list
    results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/custom_nodes/ComfyUI-CoreMLSuite/coreml_suite/nodes.py", line 52, in sample
    return super().sample(
           ^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/nodes.py", line 1237, in sample
    return common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/nodes.py", line 1207, in common_ksampler
    samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/custom_nodes/ComfyUI-Impact-Pack/modules/impact/sample_error_enhancer.py", line 9, in informative_sample
    return original_sample(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/comfy/sample.py", line 100, in sample
    samples = sampler.sample(noise, positive_copy, negative_copy, cfg=cfg, latent_image=latent_image, start_step=start_step, last_step=last_step, force_full_denoise=force_full_denoise, denoise_mask=noise_mask, sigmas=sigmas, callback=callback, disable_pbar=disable_pbar, seed=seed)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/comfy/samplers.py", line 728, in sample
    return sample(self.model, noise, positive, negative, cfg, self.device, sampler(), sigmas, self.model_options, latent_image=latent_image, denoise_mask=denoise_mask, callback=callback, disable_pbar=disable_pbar, seed=seed)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/comfy/samplers.py", line 633, in sample
    samples = sampler.sample(model_wrap, sigmas, extra_args, callback, noise, latent_image, denoise_mask, disable_pbar)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/comfy/samplers.py", line 589, in sample
    samples = getattr(k_diffusion_sampling, "sample_{}".format(sampler_name))(model_k, noise, sigmas, extra_args=extra_args, callback=k_callback, disable=disable_pbar, **extra_options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/.pyenv/versions/3.11.5/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/comfy/k_diffusion/sampling.py", line 580, in sample_dpmpp_2m
    denoised = model(x, sigmas[i] * s_in, **extra_args)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/.pyenv/versions/3.11.5/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/.pyenv/versions/3.11.5/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/comfy/samplers.py", line 287, in forward
    out = self.inner_model(x, sigma, cond=cond, uncond=uncond, cond_scale=cond_scale, model_options=model_options, seed=seed)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/.pyenv/versions/3.11.5/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/.pyenv/versions/3.11.5/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/comfy/k_diffusion/external.py", line 129, in forward
    eps = self.get_eps(input * c_in, self.sigma_to_t(sigma), **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/comfy/k_diffusion/external.py", line 155, in get_eps
    return self.inner_model.apply_model(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/comfy/samplers.py", line 275, in apply_model
    out = sampling_function(self.inner_model.apply_model, x, timestep, uncond, cond, cond_scale, model_options=model_options, seed=seed)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/comfy/samplers.py", line 253, in sampling_function
    cond, uncond = calc_cond_uncond_batch(model_function, cond, uncond, x, timestep, max_total_area, model_options)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/comfy/samplers.py", line 229, in calc_cond_uncond_batch
    output = model_function(input_x, timestep_, **c).chunk(batch_chunks)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/ComfyUI/custom_nodes/ComfyUI-CoreMLSuite/coreml_suite/models.py", line 43, in apply_model
    chunked_out = [
                  ^
  File "/Users/abc/ComfyUI/custom_nodes/ComfyUI-CoreMLSuite/coreml_suite/models.py", line 44, in <listcomp>
    self._apply_model(
  File "/Users/abc/ComfyUI/custom_nodes/ComfyUI-CoreMLSuite/coreml_suite/models.py", line 83, in _apply_model
    np_out = self.diffusion_model(**model_input_kwargs)["noise_pred"]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/abc/.pyenv/versions/3.11.5/lib/python3.11/site-packages/python_coreml_stable_diffusion/coreml_model.py", line 97, in __call__
    self._verify_inputs(**kwargs)
  File "/Users/abc/.pyenv/versions/3.11.5/lib/python3.11/site-packages/python_coreml_stable_diffusion/coreml_model.py", line 90, in _verify_inputs
    raise TypeError(
TypeError: Expected shape (2, 320, 64, 64), got (1, 320, 64, 64) for input: additional_residual_0

Prompt executed in 2.48 seconds

workflow-2

bvndls commented 1 year ago

Hello. Thanks again for your input, this helps a lot. I think I managed to fix the issue with controlnet data chunking and padding, please check if you're still getting this error.

Still getting the same error, ignore the image in the Save Image node, it was produced using sd15 mlpackage converted using coremltools and it doesn't seem to use the image from the LoadImage node at all

image
aszc-dev commented 1 year ago

Ok, I have found the cause of this issue. Hopefully this resolves all problems related to controlnet parameters. Thanks for your input.

bvndls commented 1 year ago

Ok, I have found the cause of this issue. Hopefully this resolves all problems related to controlnet parameters. Thanks for your input.

Just tested, works now. Thank you so much!