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
52.04k stars 5.47k forks source link

Automatically start workflow with "Auto Queue" during ComfyUI startup #4128

Open Shyryp opened 2 months ago

Shyryp commented 2 months ago

Feature Idea

I would like to be able to specify a parameter in the bat file when running main.py ComfyUI that will force an endless queue for a specific specified workflow. For example, I suggest the following command: ComfyUI\main.py --infinite-queue-at-startup "C:/Workflows/workflow1.json"

--infinite-queue-at-startup is a parameter that will force ComfyUI to start the workflow immediately after ComfyUI is launched. Together with --infinite-queue-at-startup, it is necessary (but can be optional) to pass the path to the workflow that needs to be launched in an infinite loop after ComfyUI is launched - for example "C:/Workflows/workflow1.json".

It would also be useful to add the parameter --ignore-infinite-queues-on-startup, which will ignore the automatic start of the endless queue for previously opened browser tabs with auto-queue enabled. But this parameter should not affect the running workflow, caused by the parameter --infinite-queue-at-startup

This would be incredibly useful for those cases when ComfyUI is launched on servers or on machines that are restarted very often.

If such functionality already exists, I will be glad to receive your tips!

Existing Solutions

I didn't find it, I didn't see such a parameter or functionality in the list of supported parameters of main.py

Other

No response

robinjhuang commented 2 months ago

So you want to start ComfyUI and have it run the workflow automatically and endlessly? What is the use case here? Why would you want to endlessly run the same workflow without changes?

To accomplish this today you could simply call the API with the api workflow JSON endlessly through your own script.

Shyryp commented 2 months ago

@robinjhuang "Why would you want to endlessly run the same workflow without changes?" Answer: There are workflows that rely on external input data (for example, text files or images in the machine's storage, and sometimes external databases). In this case, text files and/or images are changed/replaced during the infinite cycle of the workflow (some files are updated by the workflow itself (and then used by it in the next cycle), for example - the counter of generated images).

Therefore, in fact, the workflow does not change manually at all - all the necessary data automatically comes from external files and affects the workflow. The maximum that can be changed manually is prompts in text files or some other technical things. Such a separation is necessary so that workflows do not depend on data, and data does not depend on workflows, since each machine can have its own set of files/settings, and, in case of updating/replacing the workflow, the user does not have to change anything in the workflow itself.

And I need automatic launch on an infinite cycle for the cases that I described above (frequent restart of the work machine; the need for greater automation, etc.). Overall, there are a lot of situations where this can be used.

Thanks for the tip about the API!

If you have any example of such API usage (with infinite loop), it would be great to see it here. What I'm wondering now is how can I set an infinite loop (Auto Queue) in functions like this queue_prompt? What parameter/command is responsible for this, do you have a simple answer?

Anyway, thanks for the tip, I'll try to study the API and figure it out! If I figure it out, I will share it here with the community.

ltdrdata commented 2 months ago

@robinjhuang "Why would you want to endlessly run the same workflow without changes?" Answer: There are workflows that rely on external input data (for example, text files or images in the machine's storage, and sometimes external databases). In this case, text files and/or images are changed/replaced during the infinite cycle of the workflow (some files are updated by the workflow itself (and then used by it in the next cycle), for example - the counter of generated images).

Therefore, in fact, the workflow does not change manually at all - all the necessary data automatically comes from external files and affects the workflow. The maximum that can be changed manually is prompts in text files or some other technical things. Such a separation is necessary so that workflows do not depend on data, and data does not depend on workflows, since each machine can have its own set of files/settings, and, in case of updating/replacing the workflow, the user does not have to change anything in the workflow itself.

And I need automatic launch on an infinite cycle for the cases that I described above (frequent restart of the work machine; the need for greater automation, etc.). Overall, there are a lot of situations where this can be used.

Thanks for the tip about the API!

If you have any example of such API usage (with infinite loop), it would be great to see it here. What I'm wondering now is how can I set an infinite loop (Auto Queue) in functions like this queue_prompt? What parameter/command is responsible for this, do you have a simple answer?

Anyway, thanks for the tip, I'll try to study the API and figure it out! If I figure it out, I will share it here with the community.

If your workflow depends on external files, the correct approach would be to create and use a custom node that can detect changes in the external files. For this purpose, ComfyUI provide an interface in custom nodes that returns a hash value called IS_CHANGED.

If it's difficult to detect changes, you can use a trick like return float("NaN") inIS_CHANGED to make it always considered as changed.

robertalanbevan commented 1 month ago

Sorry to slightly hijack but I'm looking for a way to queue even just once at startup (although auto queue would be better). I generate images all throughout the day and my GPU is relatively poor, so output is slow. But more importantly, it takes a long time to initialize my workflow the first time I queue, and that initialization slows down the rest of my running processes. I'd just like it to initialize a regular "mono" queue at startup so I'm not incentivized to wait until I'm not busy in Ableton Live or something. Plus it's just nice to know image generation is always ready.

ltdrdata commented 1 month ago

Sorry to slightly hijack but I'm looking for a way to queue even just once at startup (although auto queue would be better). I generate images all throughout the day and my GPU is relatively poor, so output is slow. But more importantly, it takes a long time to initialize my workflow the first time I queue, and that initialization slows down the rest of my running processes. I'd just like it to initialize a regular "mono" queue at startup so I'm not incentivized to wait until I'm not busy in Ableton Live or something. Plus it's just nice to know image generation is always ready.

Handling this is somewhat tricky because the current workflow execution is dependent on the frontend. If we limit the ready state to the default workflow and only up to the point where checkpoint loading is prepared, it might be possible with a little trick. (For this to work, a feature must be provided to set the default checkpoint in the default workflow.) However, if you load a different workflow, the ready state will be invalidated immediately.