0xbitches / ComfyUI-LCM

Latent Consistency Model for ComfyUI
GNU General Public License v3.0
252 stars 16 forks source link

module diffusers has no attribute LCMScheduler #15

Open moosescap opened 11 months ago

moosescap commented 11 months ago

The Python environment and ConfyUI have been updated to the latest versions. If you need to make changes to the code, please provide detailed instructions, as I am not proficient in programming.

Error occurred when executing LCM_Sampler:

module diffusers has no attribute LCMScheduler

File "F:\comfui\ComfyUI\ComfyUI\execution.py", line 153, in recursive_execute output_data, output_ui = get_output_data(obj, input_data_all) File "F:\comfui\ComfyUI\ComfyUI\execution.py", line 83, in get_output_data return_values = map_node_over_list(obj, input_data_all, obj.FUNCTION, allow_interrupt=True) File "F:\comfui\ComfyUI\ComfyUI\execution.py", line 76, in map_node_over_list results.append(getattr(obj, func)(**slice_dict(input_data_all, i))) File "F:\comfui\ComfyUI\ComfyUI\custom_nodes\ComfyUI-LCM\nodes.py", line 47, in sample self.pipe = LatentConsistencyModelPipeline.from_pretrained( File "F:\comfui\ComfyUI\python_embeded\lib\site-packages\diffusers\pipelines\pipeline_utils.py", line 1098, in from_pretrained maybe_raise_or_warn( File "F:\comfui\ComfyUI\python_embeded\lib\site-packages\diffusers\pipelines\pipeline_utils.py", line 282, in maybe_raise_or_warn class_obj = getattr(library, class_name) File "F:\comfui\ComfyUI\python_embeded\lib\site-packages\diffusers\utils\import_utils.py", line 677, in getattr raise AttributeError(f"module {self.name} has no attribute {name}")

danila-pryamonosov-hypemasters commented 11 months ago

adding this lines fixes this iussue and make it to use old pipeline

self.pipe = LatentConsistencyModelPipeline.from_pretrained(
    ...
    custom_revision="main",
    revision="fb9c5d",
    ...
)
moosescap commented 11 months ago

adding this lines fixes this iussue and make it to use old pipeline添加此行可以修复此 iussue 并使其使用旧管道

self.pipe = LatentConsistencyModelPipeline.from_pretrained(
    ...
    custom_revision="main",
    revision="fb9c5d",
    ...
)

thank you!!

SwannSchilling commented 11 months ago

I am having the same problem, could you please provide more info?

The code you provided is for nodes.py? I tried to fix it but it did not work, so could you post the full code please... I found this two times

def sample(self, seed, steps, prompt_strength, cfg, images, conditioning, height, width, num_images, use_fp16):
        if self.pipe is None:
            self.pipe = LatentConsistencyModelImg2ImgPipeline.from_pretrained(
                pretrained_model_name_or_path="SimianLuo/LCM_Dreamshaper_v7",
                safety_checker=None,
            )

            if use_fp16:
                self.pipe.to(torch_device=get_torch_device(),
                             torch_dtype=torch.float16)
            else:
                self.pipe.to(torch_device=get_torch_device(),
                             torch_dtype=torch.float32)
danila-pryamonosov-hypemasters commented 11 months ago

Shure, here are full example for img2img advanced

class LCM_img2img_Sampler_Advanced:
    def __init__(self):
        self.scheduler = LCMScheduler.from_pretrained(
            path.join(path.dirname(__file__), "scheduler_config.json"))
        self.pipe = None

    @classmethod
    def INPUT_TYPES(s):
        return {"required":
                {
                    "images": ("IMAGE", ),
                    "seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff}),
                    "prompt_strength": ("FLOAT", {"default": 0.5, "min": 0.0, "max": 1.0, "step": 0.05}),
                    "steps": ("INT", {"default": 4, "min": 1, "max": 10000}),
                    "cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step": 0.5, "round": 0.01}),
                    "height": ("INT", {"default": 512, "min": 512, "max": 2048}),
                    "width": ("INT", {"default": 512, "min": 512, "max": 2048}),
                    "num_images": ("INT", {"default": 1, "min": 1, "max": 64}),
                    "use_fp16": ("BOOLEAN", {"default": True}),
                    "conditioning": ("CONDITIONING",),
                }
                }

    RETURN_TYPES = ("IMAGE",)
    FUNCTION = "sample"
    CATEGORY = "sampling"

    def sample(self, seed, steps, prompt_strength, cfg, images, conditioning, height, width, num_images, use_fp16):
        if self.pipe is None:
            self.pipe = LatentConsistencyModelImg2ImgPipeline.from_pretrained(
                pretrained_model_name_or_path="SimianLuo/LCM_Dreamshaper_v7",
                custom_revision="main",
                revision="fb9c5d",
                safety_checker=None,
            )

            if use_fp16:
                self.pipe.to(torch_device=get_torch_device(),
                             torch_dtype=torch.float16)
            else:
                self.pipe.to(torch_device=get_torch_device(),
                             torch_dtype=torch.float32)

        torch.manual_seed(seed)
        start_time = time.time()

        images = np.transpose(images, (0, 3, 1, 2))
        results = []
        for i in range(images.shape[0]):
            image = images[i]
            result = self.pipe(
                image=image,
                prompt_embeds=conditioning[0][0],
                strength=prompt_strength,
                width=width,
                height=height,
                guidance_scale=cfg,
                num_inference_steps=steps,
                num_images_per_prompt=num_images,
                lcm_origin_steps=50,
                output_type="np",
                ).images

            # scale latents with vae factor
            tensor_results = [torch.from_numpy(np_result) for np_result in result]
            results.extend(tensor_results)

        results = torch.stack(results)

        print("LCM img2img inference time: ", time.time() - start_time, "seconds")

        return (results,)
danila-pryamonosov-hypemasters commented 11 months ago

As you can see its just need to add two arguments

custom_revision="main", revision="fb9c5d", to self.pipe = LatentConsistencyModelImg2ImgPipeline.from_pretrained()

this also need to be addet to text2image,text2imageadvanced ans so one

SwannSchilling commented 11 months ago

Thanks a lot for the quick reply! Got it to work now! I would not have been able to figure it out by myself...