bash-j / mikey_nodes

comfy nodes from mikey
MIT License
118 stars 16 forks source link

[Possible improvement] PresetRatioSelector not cached when all parameters are unchanged #16

Closed Guillaume-Fgt closed 8 months ago

Guillaume-Fgt commented 11 months ago

Even if you don't change any settings in a workflow, this node will always trigger at each generation, initiating a new K sampler cycle.

After studying the code, I discovered it was this part at the origin of this behavior:

    def calculate(....)
        ......
        prompt.get(str(unique_id))['inputs']['output_latent_w'] = str(latent_width)
        prompt.get(str(unique_id))['inputs']['output_latent_h'] = str(latent_height)
        prompt.get(str(unique_id))['inputs']['output_cte_w'] = str(cte_w)
        prompt.get(str(unique_id))['inputs']['output_cte_h'] = str(cte_h)
        prompt.get(str(unique_id))['inputs']['output_target_w'] = str(target_w)
        prompt.get(str(unique_id))['inputs']['output_target_h'] = str(target_h)
        prompt.get(str(unique_id))['inputs']['output_crop_w'] = str(crop_w)
        prompt.get(str(unique_id))['inputs']['output_crop_h'] = str(crop_h)
        .....

If I comment out those lines, I've got the expected behavior: if I type "Queue Prompt" with seed set to "fixed", nothing happens and the console print got prompt Prompt executed in 0.01 seconds until I change one of the value of the PresetRatioSelector. But if seed is on random or increment, it will trigger.

I don't have the bigger picture of all your nodes so I don't know how useful it is to change those value in the prompt dict. But to me, it doesn't seem to be needed on this particular node. Do you think we can delete them?

bash-j commented 11 months ago

Thanks for pointing out what is causing the node to trigger even when the widgets aren't changed. I put these lines of code in so that you could get the values using the search and replace feature. e.g. %Prompt With Style V3.output_latent_h%

I use this myself for adding the metadata to the image so you can post images to civitai without having to enter the parameters used to generate the image.

I'll see if there is some other way to do this without triggering the node unnecessarily.

bash-j commented 9 months ago

I decided to disable this code which adds inputs to the prompt json, which can then be retrieved with the search and replace syntax. I can't figure out a way to stop it from triggering the node, so I disabled it.