feffy380 / sd-webui-token-downsampling

Token Downsampling optimization for stable-diffusion-webui
MIT License
24 stars 2 forks source link

Incompatible shapes for attention inputs #2

Open AndreyRGW opened 8 months ago

AndreyRGW commented 8 months ago
    ValueError: Incompatible shapes for attention inputs:
      query.shape: torch.Size([8, 1500, 10, 64])
      key.shape  : torch.Size([2, 1500, 10, 64])
      value.shape: torch.Size([2, 1500, 10, 64])
    HINT: We don't support broadcasting, please use `expand` yourself before calling `memory_efficient_attention` if you need to

Running on sdxl lightning

feffy380 commented 8 months ago

Needs more info, like the full error log

AndreyRGW commented 7 months ago
  0%|                                                                                            | 0/8 [00:00<?, ?it/s]
*** Error completing request
*** Arguments: ('task(3eofx1k8bts0fu1)', <gradio.routes.Request object at 0x00000254978CF070>, 'Playstation 1 Graphics, PS1 Game, N64style\nscifi horror game, a city, early winter, dark blue hues, fog.\n<lora:PS1Redmond-PS1Game-Playstation1Graphics:0.7> <lora:N64style:0.75>', 'bad art, ugly, deformed, ugly, watermark, text, colorful, high contrast', [], 1, 1, 2, 360, 640, True, 0.501, 2.5, 'Latent (nearest-exact)', 4, 0, 0, 'Use same checkpoint', 'DPM++ 2M', 'Use same scheduler', '', '', [], 0, 8, 'Euler a', 'Uniform', False, '', 0.8, 473607612, False, -1, 0, 0, 0, False, False, 20, 4, 4, 0.4, 0.95, 2, 2, 0.4, 0.5, False, 1, False, UiControlNetUnit(enabled=False, module='none', model='None', weight=1, image=None, resize_mode='Crop and Resize', low_vram=False, processor_res=-1, threshold_a=-1, threshold_b=-1, guidance_start=0, guidance_end=1, pixel_perfect=False, control_mode='Balanced', inpaint_crop_input_image=False, hr_option='Both', save_detected_map=True, advanced_weighting=None), UiControlNetUnit(enabled=False, module='none', model='None', weight=1, image=None, resize_mode='Crop and Resize', low_vram=False, processor_res=-1, threshold_a=-1, threshold_b=-1, guidance_start=0, guidance_end=1, pixel_perfect=False, control_mode='Balanced', inpaint_crop_input_image=False, hr_option='Both', save_detected_map=True, advanced_weighting=None), UiControlNetUnit(enabled=False, module='none', model='None', weight=1, image=None, resize_mode='Crop and Resize', low_vram=False, processor_res=-1, threshold_a=-1, threshold_b=-1, guidance_start=0, guidance_end=1, pixel_perfect=False, control_mode='Balanced', inpaint_crop_input_image=False, hr_option='Both', save_detected_map=True, advanced_weighting=None), False, '1.5', 0, False, 0.01, 0.5, -0.13, 0, 0, 0, 0, False, 0, 1, 0, 'Version 2', 1.2, 0.9, 0, 0.5, 0, 1, 1.4, 0.2, 0, 0.5, 0, 1, 1, 1, 0, 0.5, 0, 1, 0, False, 'Default', 'Default', 1, False, 0, False, 0, 0, 0, 0, False, True, 3, 4, 0.15, 0.3, 'bicubic', 1, 2, True, False, None, False, '0', '0', 'inswapper_128.onnx', 'CodeFormer', 1, True, 'None', 1, 1, False, True, 1, 0, 0, False, 0.5, True, False, 'CUDA', False, 0, 'None', '', None, False, False, 0.5, 0, False, 0, 0, False, False, 0, 0, 1, 0, 0, 0, False, False, 'Straight Abs.', 'Flat', False, False, 'positive', 'comma', 0, False, False, 'start', '', 1, '', [], 0, '', [], 0, '', [], True, False, False, False, False, False, False, 0, False, None, None, False, None, None, False, None, None, False, 50, 7, 1.5, True, '16bpc', '.tiff', 1.2) {}
    Traceback (most recent call last):
      File "C:\wbcnvme\stable-diffusion-webui\modules\call_queue.py", line 57, in f
        res = list(func(*args, **kwargs))
      File "C:\wbcnvme\stable-diffusion-webui\modules\call_queue.py", line 36, in f
        res = func(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\modules\txt2img.py", line 109, in txt2img
        processed = processing.process_images(p)
      File "C:\wbcnvme\stable-diffusion-webui\modules\processing.py", line 794, in process_images
        res = process_images_inner(p)
      File "C:\wbcnvme\stable-diffusion-webui\extensions\sd-webui-controlnet\scripts\batch_hijack.py", line 59, in processing_process_images_hijack
        return getattr(processing, '__controlnet_original_process_images_inner')(p, *args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\modules\processing.py", line 930, in process_images_inner
        samples_ddim = p.sample(conditioning=p.c, unconditional_conditioning=p.uc, seeds=p.seeds, subseeds=p.subseeds, subseed_strength=p.subseed_strength, prompts=p.prompts)
      File "C:\wbcnvme\stable-diffusion-webui\modules\processing.py", line 1266, in sample
        samples = self.sampler.sample(self, x, conditioning, unconditional_conditioning, image_conditioning=self.txt2img_image_conditioning(x))
      File "C:\wbcnvme\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 218, in sample
        samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args=self.sampler_extra_args, disable=False, callback=self.callback_state, **extra_params_kwargs))
      File "C:\wbcnvme\stable-diffusion-webui\modules\sd_samplers_common.py", line 272, in launch_sampling
        return func()
      File "C:\wbcnvme\stable-diffusion-webui\modules\sd_samplers_kdiffusion.py", line 218, in <lambda>
        samples = self.launch_sampling(steps, lambda: self.func(self.model_wrap_cfg, x, extra_args=self.sampler_extra_args, disable=False, callback=self.callback_state, **extra_params_kwargs))
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\utils\_contextlib.py", line 115, in decorate_context
        return func(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\repositories\k-diffusion\k_diffusion\sampling.py", line 145, in sample_euler_ancestral
        denoised = model(x, sigmas[i] * s_in, **extra_args)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
        return self._call_impl(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\modules\sd_samplers_cfg_denoiser.py", line 237, in forward
        x_out = self.inner_model(x_in, sigma_in, cond=make_condition_dict(cond_in, image_cond_in))
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
        return self._call_impl(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\repositories\k-diffusion\k_diffusion\external.py", line 112, in forward
        eps = self.get_eps(input * c_in, self.sigma_to_t(sigma), **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\repositories\k-diffusion\k_diffusion\external.py", line 138, in get_eps
        return self.inner_model.apply_model(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\modules\sd_models_xl.py", line 44, in apply_model
        return self.model(x, t, cond)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
        return self._call_impl(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\modules\sd_hijack_utils.py", line 18, in <lambda>
        setattr(resolved_obj, func_path[-1], lambda *args, **kwargs: self(*args, **kwargs))
      File "C:\wbcnvme\stable-diffusion-webui\modules\sd_hijack_utils.py", line 32, in __call__
        return self.__orig_func(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\repositories\generative-models\sgm\modules\diffusionmodules\wrappers.py", line 28, in forward
        return self.diffusion_model(
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
        return self._call_impl(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1568, in _call_impl
        result = forward_call(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\modules\sd_unet.py", line 91, in UNetModel_forward
        return original_forward(self, x, timesteps, context, *args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\repositories\generative-models\sgm\modules\diffusionmodules\openaimodel.py", line 993, in forward
        h = module(h, emb, context)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
        return self._call_impl(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\repositories\generative-models\sgm\modules\diffusionmodules\openaimodel.py", line 100, in forward
        x = layer(x, context)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
        return self._call_impl(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\repositories\generative-models\sgm\modules\attention.py", line 627, in forward
        x = block(x, context=context[i])
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
        return self._call_impl(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1527, in _call_impl
        return forward_call(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\repositories\generative-models\sgm\modules\attention.py", line 459, in forward
        return checkpoint(
      File "C:\wbcnvme\stable-diffusion-webui\repositories\generative-models\sgm\modules\diffusionmodules\util.py", line 165, in checkpoint
        return CheckpointFunction.apply(func, len(inputs), *args)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\autograd\function.py", line 539, in apply
        return super().apply(*args, **kwargs)  # type: ignore[misc]
      File "C:\wbcnvme\stable-diffusion-webui\repositories\generative-models\sgm\modules\diffusionmodules\util.py", line 182, in forward
        output_tensors = ctx.run_function(*ctx.input_tensors)
      File "C:\wbcnvme\stable-diffusion-webui\repositories\generative-models\sgm\modules\attention.py", line 467, in _forward
        self.attn1(
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1518, in _wrapped_call_impl
        return self._call_impl(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\torch\nn\modules\module.py", line 1568, in _call_impl
        result = forward_call(*args, **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\extensions-builtin\hypertile\hypertile.py", line 307, in wrapper
        out = params.forward(x, *args[1:], **kwargs)
      File "C:\wbcnvme\stable-diffusion-webui\modules\sd_hijack_optimizations.py", line 496, in xformers_attention_forward
        out = xformers.ops.memory_efficient_attention(q, k, v, attn_bias=None, op=get_xformers_flash_attention_op(q, k, v))
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\xformers\ops\fmha\__init__.py", line 223, in memory_efficient_attention
        return _memory_efficient_attention(
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\xformers\ops\fmha\__init__.py", line 321, in _memory_efficient_attention
        return _memory_efficient_attention_forward(
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\xformers\ops\fmha\__init__.py", line 334, in _memory_efficient_attention_forward
        inp.validate_inputs()
      File "C:\wbcnvme\stable-diffusion-webui\venv\lib\site-packages\xformers\ops\fmha\common.py", line 197, in validate_inputs
        raise ValueError(
    ValueError: Incompatible shapes for attention inputs:
      query.shape: torch.Size([4, 460, 10, 64])
      key.shape  : torch.Size([2, 220, 10, 64])
      value.shape: torch.Size([2, 220, 10, 64])
    HINT: We don't support broadcasting, please use `expand` yourself before calling `memory_efficient_attention` if you need to

---
AndreyRGW commented 7 months ago

I think it's working with torch sdp

couldnt-find-good-name commented 3 months ago

I think Xformers is causing the issue, Hence in SD forge i dont have this issue but in SD A1111 i have this issue. Both my settings/configs are same in SD forge & A1111 only difference in SD forge , i dont have Xformers installed