comfyanonymous / ComfyUI

The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface.
https://www.comfy.org/
GNU General Public License v3.0
57.76k stars 6.12k forks source link

module 'comfy.sample' has no attribute 'prepare_mask' #3247

Closed cardenluo closed 7 months ago

cardenluo commented 7 months ago

Error occurred when executing KSampler:

module 'comfy.sample' has no attribute 'prepare_mask'

File "F:\ComfyUI_Windows_portable\ComfyUI\execution.py", line 151, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "F:\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 "F:\ComfyUI_Windows_portable\ComfyUI\custom_nodes\ComfyUI-0246\utils.py", line 381, in new_func res_value = old_func(final_args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "F:\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 "F:\ComfyUI_Windows_portable\ComfyUI\nodes.py", line 1344, in sample return common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "F:\ComfyUI_Windows_portable\ComfyUI\nodes.py", line 1314, in common_ksampler samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "F:\ComfyUI_Windows_portable\ComfyUI\custom_nodes\cardenc_input\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 "F:\ComfyUI_Windows_portable\ComfyUI\custom_nodes\ComfyUI-AnimateDiff-Evolved\animatediff\sampling.py", line 292, in motion_sample function_injections.inject_functions(model, params) File "F:\ComfyUI_Windows_portable\ComfyUI\custom_nodes\ComfyUI-AnimateDiff-Evolved\animatediff\sampling.py", line 217, in inject_functions self.orig_prepare_mask = comfy.sample.prepare_mask

cardenluo commented 7 months ago

image copy from all def…… into sample ,can run ok

Zakutu commented 7 months ago

Could you please send me the improved sample.py code just to be sure?

Zakutu commented 7 months ago

import torch import comfy.model_management import comfy.samplers import comfy.utils import numpy as np import logging

def prepare_noise(latent_image, seed, noise_inds=None): """ creates random noise given a latent image and a seed. optional arg skip can be used to skip and discard x number of noise generations for a given seed """ generator = torch.manual_seed(seed) if noise_inds is None: return torch.randn(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, generator=generator, device="cpu")

unique_inds, inverse = np.unique(noise_inds, return_inverse=True)
noises = []
for i in range(unique_inds[-1]+1):
    noise = torch.randn([1] + list(latent_image.size())[1:], dtype=latent_image.dtype, layout=latent_image.layout, generator=generator, device="cpu")
    if i in unique_inds:
        noises.append(noise)
noises = [noises[i] for i in inverse]
noises = torch.cat(noises, axis=0)
return noises

def prepare_sampling(model, noise_shape, positive, negative, noise_mask): logging.warning("Warning: comfy.sample.prepare_sampling isn't used anymore and can be removed") return model, positive, negative, noise_mask, []

def cleanup_additional_models(models): logging.warning("Warning: comfy.sample.cleanup_additional_models isn't used anymore and can be removed")

def sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=1.0, disable_noise=False, start_step=None, last_step=None, force_full_denoise=False, noise_mask=None, sigmas=None, callback=None, disable_pbar=False, seed=None): sampler = comfy.samplers.KSampler(model, steps=steps, device=model.load_device, sampler=sampler_name, scheduler=scheduler, denoise=denoise, model_options=model.model_options)

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)
samples = samples.to(comfy.model_management.intermediate_device())
return samples

def sample_custom(model, noise, cfg, sampler, sigmas, positive, negative, latent_image, noise_mask=None, callback=None, disable_pbar=False, seed=None): samples = comfy.samplers.sample(model, noise, positive, negative, cfg, model.load_device, sampler, sigmas, model_options=model.model_options, latent_image=latent_image, denoise_mask=noise_mask, callback=callback, disable_pbar=disable_pbar, seed=seed) samples = samples.to(comfy.model_management.intermediate_device()) return samples

def common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=1.0, disable_noise=False, start_step=None, last_step=None, force_full_denoise=False, noise_mask=None, sigmas=None, callback=None, disable_pbar=False, custom=None): noise = prepare_noise(latent_image, seed) return sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise, disable_noise, start_step, last_step, force_full_denoise, noise_mask, sigmas, callback, disable_pbar, seed)

def process_sample_state(pipe, samp_model, samp_clip, samp_samples, samp_vae, samp_seed, samp_positive, samp_negative, steps, start_step, last_step, cfg, sampler_name, scheduler, denoise, image_output, link_id, save_prefix, tile_size, prompt, extra_pnginfo, my_unique_id, preview_latent, force_full_denoise, disable_noise, samp_custom): return common_ksampler(samp_model, samp_seed, steps, cfg, sampler_name, scheduler, samp_positive, samp_negative, samp_samples, denoise, disable_noise, start_step, last_step, force_full_denoise, samp_custom)

def prepare_mask(): logging.warning("Warning: comfy.sample.prepare_mask isn't used anymore and can be removed")

def prepare_additional_models(models): logging.warning("Warning: comfy.sample.prepare_additional_models isn't used anymore and can be removed")

def get_additional_models(): logging.warning("Warning: comfy.sample.get_additional_models isn't used anymore and can be removed")

Zakutu commented 7 months ago

In my case, the above code worked fine.

cardenluo commented 7 months ago

@Zakutu the error is : module 'comfy.sample' has no attribute 'prepare_mask' ; so ,I find there is def prepare_mask() in the sampler_helpers.py, I just copy the code into comfy.sample.py.

However, I update latest comfyui ,there's no need to copy again.

sauceruney commented 5 months ago

I did all this above and I'm still getting the error. I'm running a new install of ComfyUI in StabilityMatrix. This happens whether I use Ksampler or the Advanced version.

Error occurred when executing KSamplerAdvanced:

module 'comfy.sample' has no attribute 'prepare_mask'

File "C:\Users\sauce\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\execution.py", line 151, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) File "C:\Users\sauce\AppData\Roaming\StabilityMatrix\Packages\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 "C:\Users\sauce\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\execution.py", line 74, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) File "C:\Users\sauce\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\nodes.py", line 1378, in sample return common_ksampler(model, noise_seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise, disable_noise=disable_noise, start_step=start_at_step, last_step=end_at_step, force_full_denoise=force_full_denoise) File "C:\Users\sauce\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\nodes.py", line 1314, in common_ksampler samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, File "C:\Users\sauce\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\custom_nodes\ComfyUI-AnimateLCM\animatediff\sampling.py", line 264, in motion_sample function_injections.inject_functions(model, params) File "C:\Users\sauce\AppData\Roaming\StabilityMatrix\Packages\ComfyUI\custom_nodes\ComfyUI-AnimateLCM\animatediff\sampling.py", line 198, in inject_functions self.orig_prepare_mask = comfy.sample.prepare_mask

I deleted and reinstalled AnimateDiffEvo and I'm still getting a ton of lora key not loaded warnings before all this happens. And a "UserWarning: 1Torch was not compiled with flash attention. (Triggered internally at ..\aten\src\ATen\native\transformers\cuda\sdp_utils.cpp:455.)"

ltdrdata commented 5 months ago

prepare_mask

ComfyUI-AnimateLCM is so much outdated. And it isn't patched yet.