attashe / ComfyUI-FluxRegionAttention

Implement Region Attention for Flux model
Apache License 2.0
75 stars 3 forks source link

Ksampler ValueError: Invalid shape for attention bias: torch.Size #1

Open eokoo opened 2 weeks ago

eokoo commented 2 weeks ago

As long as you run this process, and then run with other Flux Ksampler is bound to report an error, you can only restart comfyui, guessing that may be this node and flux's own boot conditions have conflicts 屏幕截图 2024-11-08 123548

loaded completely 0.0 11350.048889160156 True 100%|██████████████████████████████████████████████████████████████████████████████████| 30/30 [00:29<00:00, 1.03it/s] Requested to load AutoencodingEngine Loading 1 new model loaded completely 0.0 159.87335777282715 True Prompt executed in 56.67 seconds got prompt Requested to load FluxClipModel_ Loading 1 new model loaded completely 0.0 9319.23095703125 True model weight dtype torch.float8_e4m3fn, manual cast: torch.bfloat16 model_type FLUX Requested to load Flux Loading 1 new model loaded completely 0.0 11350.048889160156 True 0%| | 0/30 [00:00<?, ?it/s] !!! Exception during processing !!! Invalid shape for attention bias: torch.Size([1, 24, 5056, 5056]) (expected (1, 24, 4288, 4288)) query.shape: torch.Size([1, 4288, 24, 128]) key.shape : torch.Size([1, 4288, 24, 128]) value.shape: torch.Size([1, 4288, 24, 128]) Traceback (most recent call last): File "E:\ComfyUI\execution.py", line 323, in execute output_data, output_ui, has_subgraph = get_output_data(obj, input_data_all, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb) File "E:\ComfyUI\execution.py", line 198, in get_output_data return_values = _map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True, execution_block_cb=execution_block_cb, pre_execute_cb=pre_execute_cb) File "E:\ComfyUI\execution.py", line 169, in _map_node_over_list process_inputs(input_dict, i) File "E:\ComfyUI\execution.py", line 158, in process_inputs results.append(getattr(obj, func)(inputs)) File "E:\ComfyUI\nodes.py", line 1448, in sample return common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise) File "E:\ComfyUI\nodes.py", line 1415, in common_ksampler samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, File "E:\ComfyUI\custom_nodes\Comfyui-StableSR\nodes.py", line 75, in hook_sample return original_sample(*args, *kwargs) File "E:\ComfyUI\custom_nodes\ComfyUI-Impact-Pack\modules\impact\sample_error_enhancer.py", line 9, in informative_sample return original_sample(args, kwargs) # This code helps interpret error messages that occur within exceptions but does not have any impact on other operations. File "E:\ComfyUI\custom_nodes\ComfyUI-AnimateDiff-Evolved\animatediff\sampling.py", line 420, in motion_sample return orig_comfy_sample(model, noise, *args, kwargs) File "E:\ComfyUI\custom_nodes\ComfyUI-Advanced-ControlNet\adv_control\sampling.py", line 116, in acn_sample return orig_comfy_sample(model, *args, *kwargs) File "E:\ComfyUI\custom_nodes\ComfyUI-Advanced-ControlNet\adv_control\utils.py", line 117, in uncond_multiplier_check_cn_sample return orig_comfy_sample(model, args, kwargs) File "E:\ComfyUI\comfy\sample.py", line 43, in sample samples = sampler.sample(noise, positive, negative, 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 "E:\ComfyUI\custom_nodes\ComfyUI_smZNodes\smZNodes.py", line 104, in KSampler_sample return orig_fn(*args, kwargs) File "E:\ComfyUI\comfy\samplers.py", line 855, 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 "E:\ComfyUI\custom_nodes\ComfyUI_smZNodes\smZNodes.py", line 122, in sample return orig_fn(*args, *kwargs) File "E:\ComfyUI\comfy\samplers.py", line 753, in sample return cfg_guider.sample(noise, latent_image, sampler, sigmas, denoise_mask, callback, disable_pbar, seed) File "E:\ComfyUI\comfy\samplers.py", line 740, in sample output = self.inner_sample(noise, latent_image, device, sampler, sigmas, denoise_mask, callback, disable_pbar, seed) File "E:\ComfyUI\comfy\samplers.py", line 719, in inner_sample samples = sampler.sample(self, sigmas, extra_args, callback, noise, latent_image, denoise_mask, disable_pbar) File "E:\ComfyUI\custom_nodes\ComfyUI_smZNodes\smZNodes.py", line 87, in KSAMPLER_sample return orig_fn(args, kwargs) File "E:\ComfyUI\comfy\samplers.py", line 624, in sample samples = self.sampler_function(model_k, noise, sigmas, extra_args=extra_args, callback=k_callback, disable=disable_pbar, self.extra_options) File "E:\ComfyUI\venv\lib\site-packages\torch\utils_contextlib.py", line 116, in decorate_context return func(*args, *kwargs) File "E:\ComfyUI\comfy\k_diffusion\sampling.py", line 155, in sample_euler denoised = model(x, sigma_hat s_in, extra_args) File "E:\ComfyUI\comfy\samplers.py", line 299, in call out = self.inner_model(x, sigma, model_options=model_options, seed=seed) File "E:\ComfyUI\comfy\samplers.py", line 706, in call return self.predict_noise(*args, kwargs) File "E:\ComfyUI\comfy\samplers.py", line 709, in predict_noise return sampling_function(self.inner_model, x, timestep, self.conds.get("negative", None), self.conds.get("positive", None), self.cfg, model_options=model_options, seed=seed) File "E:\ComfyUI\custom_nodes\ComfyUI_smZNodes\smZNodes.py", line 162, in sampling_function out = orig_fn(args, kwargs) File "E:\ComfyUI\comfy\samplers.py", line 279, in sampling_function out = calc_cond_batch(model, conds, x, timestep, model_options) File "E:\ComfyUI\comfy\samplers.py", line 228, in calc_cond_batch output = model.apply_model(inputx, timestep, c).chunk(batch_chunks) File "E:\ComfyUI\custom_nodes\ComfyUI-Advanced-ControlNet\adv_control\utils.py", line 69, in apply_model_uncond_cleanup_wrapper return orig_apply_model(self, args, kwargs) File "E:\ComfyUI\comfy\model_base.py", line 144, in apply_model model_output = self.diffusion_model(xc, t, context=context, control=control, transformer_options=transformer_options, extra_conds).float() File "E:\ComfyUI\venv\lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl return self._call_impl(*args, *kwargs) File "E:\ComfyUI\venv\lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl return forward_call(args, kwargs) File "E:\ComfyUI\comfy\ldm\flux\model.py", line 159, in forward out = self.forward_orig(img, img_ids, context, txt_ids, timestep, y, guidance, control) File "E:\ComfyUI\comfy\ldm\flux\model.py", line 118, in forward_orig img, txt = block(img=img, txt=txt, vec=vec, pe=pe) File "E:\ComfyUI\venv\lib\site-packages\torch\nn\modules\module.py", line 1553, in _wrapped_call_impl return self._call_impl(*args, *kwargs) File "E:\ComfyUI\venv\lib\site-packages\torch\nn\modules\module.py", line 1562, in _call_impl return forward_call(args, **kwargs) File "E:\ComfyUI\comfy\ldm\flux\layers.py", line 164, in forward attn = attention(torch.cat((txt_q, img_q), dim=2), File "E:\ComfyUI\custom_nodes\ComfyUI-FluxRegionAttention\node.py", line 30, in xformers_attention x = xattention(q, k, v, attn_bias=attn_mask) File "E:\ComfyUI\venv\lib\site-packages\xformers\ops\fmha__init.py", line 301, in memory_efficient_attention return _memory_efficient_attention( File "E:\ComfyUI\venv\lib\site-packages\xformers\ops\fmha__init__.py", line 462, in _memory_efficient_attention return _memory_efficient_attention_forward( File "E:\ComfyUI\venv\lib\site-packages\xformers\ops\fmha\init__.py", line 478, in _memory_efficient_attention_forward inp.validate_inputs() File "E:\ComfyUI\venv\lib\site-packages\xformers\ops\fmha\common.py", line 185, in validate_inputs raise ValueError( ValueError: Invalid shape for attention bias: torch.Size([1, 24, 5056, 5056]) (expected (1, 24, 4288, 4288)) query.shape: torch.Size([1, 4288, 24, 128]) key.shape : torch.Size([1, 4288, 24, 128]) value.shape: torch.Size([1, 4288, 24, 128])

Prompt executed in 14.72 seconds

nistvan86 commented 6 days ago

I have the same error, but what do you mean at "with other Flux Ksampler" @eokoo?

whitepapercg commented 3 days ago

This error occurs if you are trying to use a normal Flux workflow without Regional Prompting

Restart Comfy to fix it. In any case, we need a solution that will work fully, I don't have an answer why this is happening