laksjdjf / IPAdapter-ComfyUI

experimental
GNU General Public License v3.0
217 stars 13 forks source link

Fix KSampler `dtype` bug #44

Closed undrash closed 1 year ago

undrash commented 1 year ago

Convert ip_k and ip_v to the same type as q

laksjdjf commented 1 year ago

Please provide details of the bug.

undrash commented 1 year ago

Please provide details of the bug.

@laksjdjf after updating ComfyUI and all the nodes with the manager this dtype error appears: image

Complete log below:

got prompt
model_type EPS
adm 0
Using xformers attention in VAE
Working with z of shape (1, 4, 32, 32) = 4096 dimensions.
Using xformers attention in VAE
missing {'cond_stage_model.clip_l.text_projection', 'cond_stage_model.clip_l.logit_scale'}
left over keys: dict_keys(['model_ema.decay', 'model_ema.num_updates', 'cond_stage_model.clip_l.transformer.text_model.embeddings.position_ids'])
Requested to load CLIPVisionModelWithProjection
Loading 1 new model
Requested to load SD1ClipModel
Loading 1 new model
/home/undrash/.local/lib/python3.10/site-packages/torch/functional.py:504: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3483.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
Requested to load BaseModel
Loading 1 new model
  0%|                                                                                                                                                                                                     | 0/24 [00:00<?, ?it/s]
ERROR:root:!!! Exception during processing !!!
ERROR:root:Traceback (most recent call last):
  File "/home/undrash/comfy-ui/execution.py", line 153, in recursive_execute
    output_data, output_ui = get_output_data(obj, input_data_all)
  File "/home/undrash/comfy-ui/execution.py", line 83, in get_output_data
    return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True)
  File "/home/undrash/comfy-ui/execution.py", line 76, in map_node_over_list
    results.append(getattr(obj, func)(**slice_dict(input_data_all, i)))
  File "/home/undrash/comfy-ui/nodes.py", line 1237, in sample
    return common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)
  File "/home/undrash/comfy-ui/nodes.py", line 1207, in common_ksampler
    samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
  File "/home/undrash/comfy-ui/custom_nodes/ComfyUI-AnimateDiff-Evolved/animatediff/sampling.py", line 116, in animatediff_sample
    return orig_comfy_sample(model, *args, **kwargs)
  File "/home/undrash/comfy-ui/custom_nodes/ComfyUI-Impact-Pack/modules/impact/sample_error_enhancer.py", line 9, in informative_sample
    return original_sample(*args, **kwargs)
  File "/home/undrash/comfy-ui/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 "/home/undrash/comfy-ui/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 "/home/undrash/comfy-ui/comfy/samplers.py", line 633, in sample
    samples = sampler.sample(model_wrap, sigmas, extra_args, callback, noise, latent_image, denoise_mask, disable_pbar)
  File "/home/undrash/comfy-ui/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 "/home/undrash/.local/lib/python3.10/site-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "/home/undrash/comfy-ui/comfy/k_diffusion/sampling.py", line 738, in sample_ddpm
    return generic_step_sampler(model, x, sigmas, extra_args, callback, disable, noise_sampler, DDPMSampler_step)
  File "/home/undrash/comfy-ui/comfy/k_diffusion/sampling.py", line 727, in generic_step_sampler
    denoised = model(x, sigmas[i] * s_in, **extra_args)
  File "/home/undrash/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/undrash/comfy-ui/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 "/home/undrash/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/undrash/comfy-ui/comfy/k_diffusion/external.py", line 129, in forward
    eps = self.get_eps(input * c_in, self.sigma_to_t(sigma), **kwargs)
  File "/home/undrash/comfy-ui/comfy/k_diffusion/external.py", line 155, in get_eps
    return self.inner_model.apply_model(*args, **kwargs)
  File "/home/undrash/comfy-ui/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 "/home/undrash/comfy-ui/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 "/home/undrash/comfy-ui/comfy/samplers.py", line 229, in calc_cond_uncond_batch
    output = model_function(input_x, timestep_, **c).chunk(batch_chunks)
  File "/home/undrash/comfy-ui/comfy/model_base.py", line 66, in apply_model
    return self.diffusion_model(xc, t, context=context, control=control, transformer_options=transformer_options, **extra_conds).float()
  File "/home/undrash/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/undrash/comfy-ui/comfy/ldm/modules/diffusionmodules/openaimodel.py", line 619, in forward
    h = forward_timestep_embed(module, h, emb, context, transformer_options)
  File "/home/undrash/comfy-ui/comfy/ldm/modules/diffusionmodules/openaimodel.py", line 56, in forward_timestep_embed
    x = layer(x, context, transformer_options)
  File "/home/undrash/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/undrash/comfy-ui/comfy/ldm/modules/attention.py", line 573, in forward
    x = block(x, context=context[i], transformer_options=transformer_options)
  File "/home/undrash/.local/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1501, in _call_impl
    return forward_call(*args, **kwargs)
  File "/home/undrash/comfy-ui/comfy/ldm/modules/attention.py", line 403, in forward
    return checkpoint(self._forward, (x, context, transformer_options), self.parameters(), self.checkpoint)
  File "/home/undrash/comfy-ui/comfy/ldm/modules/diffusionmodules/util.py", line 123, in checkpoint
    return func(*inputs)
  File "/home/undrash/comfy-ui/comfy/ldm/modules/attention.py", line 502, in _forward
    n = attn2_replace_patch[block_attn2](n, context_attn2, value_attn2, extra_options)
  File "/home/undrash/comfy-ui/custom_nodes/IPAdapter-ComfyUI/ip_adapter.py", line 374, in __call__
    ip_out = optimized_attention(q, ip_k, ip_v, extra_options["n_heads"])
  File "/home/undrash/comfy-ui/comfy/ldm/modules/attention.py", line 306, in attention_xformers
    out = xformers.ops.memory_efficient_attention(q, k, v, attn_bias=None)
  File "/home/undrash/.local/lib/python3.10/site-packages/xformers/ops/fmha/__init__.py", line 192, in memory_efficient_attention
    return _memory_efficient_attention(
  File "/home/undrash/.local/lib/python3.10/site-packages/xformers/ops/fmha/__init__.py", line 290, in _memory_efficient_attention
    return _memory_efficient_attention_forward(
  File "/home/undrash/.local/lib/python3.10/site-packages/xformers/ops/fmha/__init__.py", line 303, in _memory_efficient_attention_forward
    inp.validate_inputs()
  File "/home/undrash/.local/lib/python3.10/site-packages/xformers/ops/fmha/common.py", line 73, in validate_inputs
    raise ValueError(
ValueError: Query/Key/Value should all have the same dtype
  query.dtype: torch.float16
  key.dtype  : torch.float32
  value.dtype: torch.float32

You can find the workflow file here to reproduce the issue.


System Info: Ubuntu 22.04.3 LTS GeForce RTX 3080 Ti Mobile Conda

laksjdjf commented 1 year ago

thx! i merged it!