kijai / ComfyUI-SUPIR

SUPIR upscaling wrapper for ComfyUI
Other
1.2k stars 66 forks source link

SUPIR Sampler Error: RuntimeError: The size of tensor a (128) must match the size of tensor b (92) at non-singleton dimension 3 #92

Closed camoody1 closed 3 months ago

camoody1 commented 3 months ago

This is a new error as of today. I ran my workflow once and it was successful. I made a change to the control_scale_start and control_scale_end values, and it failed. I then set the parameters back to their original values, and it still failed. I made no changes in between and ran no other workflows. 🤷🏼

got prompt
sampler_config:  {'target': '.sgm.modules.diffusionmodules.sampling.TiledRestoreDPMPP2MSampler', 'params': {'num_steps': 10, 'restore_cfg': -1, 's_churn': 5, 's_noise': 1.0030000000000001, 'discretization_config': {'target': '.sgm.modules.diffusionmodules.discretizer.LegacyDDPMDiscretization'}, 'guider_config': {'target': '.sgm.modules.diffusionmodules.guiders.LinearCFG', 'params': {'scale': 2.0, 'scale_min': 2.0}}, 'tile_size': 128, 'tile_stride': 64, 'eta': 1.0}}
Using random noise
Image divided into 6 tiles
Conds received:  3
!!! Exception during processing !!!
Traceback (most recent call last):
  File "H:\ComfyUI\ComfyUI_windows_portable\ComfyUI\execution.py", line 151, in recursive_execute
    output_data, output_ui = get_output_data(obj, input_data_all)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\ComfyUI\execution.py", line 81, in get_output_data
    return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\ComfyUI\execution.py", line 74, in map_node_over_list
    results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-SUPIR\nodes_v2.py", line 440, in sample
    _samples = self.sampler(denoiser, noised_z, cond=positive[i], uc=negative[i], x_center=sample.unsqueeze(0), control_scale=control_scale_end,
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-SUPIR\sgm\modules\diffusionmodules\sampling.py", line 726, in __call__
    _x, _old_denoised = self.sampler_step(
                        ^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-SUPIR\sgm\modules\diffusionmodules\sampling.py", line 606, in sampler_step
    denoised = self.denoise(x, denoiser, sigma, cond, uc, control_scale=control_scale)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-SUPIR\sgm\modules\diffusionmodules\sampling.py", line 570, in denoise
    denoised = denoiser(*self.guider.prepare_inputs(x, sigma, cond, uc), control_scale)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-SUPIR\nodes_v2.py", line 414, in <lambda>
    denoiser = lambda input, sigma, c, control_scale: SUPIR_model.denoiser(SUPIR_model.model, input, sigma, c, control_scale)
                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-SUPIR\sgm\modules\diffusionmodules\denoiser.py", line 73, in __call__
    return network(input * c_in, c_noise, cond, control_scale) * c_out + input * c_skip
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-SUPIR\sgm\modules\diffusionmodules\wrappers.py", line 91, in forward
    control = self.control_model(x=c.get("control", None), timesteps=t, xt=x,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
    return self._call_impl(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\python_embeded\Lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
    return forward_call(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "H:\ComfyUI\ComfyUI_windows_portable\ComfyUI\custom_nodes\ComfyUI-SUPIR\SUPIR\modules\SUPIR_v0.py", line 532, in forward
    h += guided_hint
RuntimeError: The size of tensor a (128) must match the size of tensor b (92) at non-singleton dimension 3

Prompt executed in 0.31 seconds
camoody1 commented 3 months ago

Follow-up: I just added a single word to the prompt (just to change something earlier in the workflow) and it ran successfully one more time. I tried running it a second time with these same settings, and it failed again. Any ideas on what this error message is indicating?

rainTL commented 3 months ago

Hello author, I also encountered the same problem, which has been bothering me for a few days. I found that this error occurred when I selected the TiledRestoreEDMSampler or TiledRestoreDPM2MSampler sampler. The size of the imported image can be 128, 64, 32 Divisible image size, but this error will still appear. When the error is reported, the same error will be reported when switching back to RestoreEDMSampler. Only by changing the large model and re-running it can it run normally. Sometimes it still does not work after changing the large model. Sometimes RestoreEDMSampler runs After the completion, switching to TiledRestoreEDMSampler can succeed again, but this is random and not guaranteed to succeed. After successfully running TiledRestoreEDMSampler once, slightly changing the number of steps or CFG will report an error again, so this problem confused me, completely I haven't found its error reporting pattern, so I hope the author can take a look at the problem. Thank you very much for your efforts. The error is reported as follows: Error occurred when executing SUPIR_sample:

The size of tensor a (84) must match the size of tensor b (44) at non-singleton dimension 2

camoody1 commented 3 months ago

I, too, am using the TiledRestoreDPM2MSampler if that makes any difference.

kijai commented 3 months ago

Follow-up: I just added a single word to the prompt (just to change something earlier in the workflow) and it ran successfully one more time. I tried running it a second time with these same settings, and it failed again. Any ideas on what this error message is indicating?

I was actually aware of this one, just didn't know what caused it. Looking closer it seems that the tiled sampler modifies the controlnet hint images permanently, so subsequential runs will fail as they are already tiled. Running the conditioner node resets it so it works.

I made it copy the conditions instead now and work on those, might have slight increase in memory use when using Tiled samplers, but it does allow consequential runs now.

camoody1 commented 3 months ago

Thank you! I appreciate your quick responses.