pydn / ComfyUI-to-Python-Extension

A powerful tool that translates ComfyUI workflows into executable Python code.
MIT License
842 stars 87 forks source link

Feature: enable pre-loading checkpoints into memory and executing workflow with different parameters fast #48

Open vojtajina opened 2 months ago

vojtajina commented 2 months ago

I think it would be useful to be able to run the generated workflow repeatedly, without re-loading everything into memory every single time. For instance, one could use it as API server which is running, the model loaded in memory and thus respond to different prompts (or other parameters) very fast. ComfyUI works that way (I think): it only recomputes nodes that changed.

I tried to change the generated code a bit, ie. wrap it in a class and keep checkpointloadersimple_4 etc as instance variables, and add method to run the workflow using these already instantiated objects, but it seems like every call to KSSampler.sample still re-loads everything into memory and it's not any faster.

Any ideas how to do that? (I would be happy to send a PR)

atmaranto commented 2 months ago

I have this feature implemented as part of command-line options or importable modules in my fork. It's available on the registry for extensions or here: ComfyUI-SaveAsScript