No project description provided
Project description
comfy-executors
Run ComfyUI workflows conveniently on different execution backends, including local ComfyUI servers and serverless execution on RunPod or Modal. Supports workflow templating, asynchronous execution and transparent batching.
Usage
Installation
pip install comfy-executors
Export ComfyUI workflow in API format
ComfyUI has two different workflow formats. The standard format for which contains additional meta data for the UI and a reduced API version which corresponds to the actual execution graph that is send to the backend. Exporting workflows in API format has to be enabled in the developer settings first.
API format export instructions
Afterwards, a separate button for API format export should appear below the normal "Save" button:
Prepare workflow for use with comfy-executors
The ComfyUI does not support parameterization of workflows out-of-the-box, i.e. a submitted workflow (in JSON format) will be executed as it is. To allow flexible parameterization of workflows, e.g. replacing prompts and the random seeds, comfy-executors
uses workflow templating via the Jinja templating engine.
To prepare a workflow for use with comfy-executors
, first append the .jinja
suffix to the filename, e.g. workflow.json
becomes workflow.json.jinja
. The nodes for loading input images and supplying the empty latent image need to be templated to obtain their value from the input_images_dir
and batch_size
variables respectively. This should generally as follows:
{
"1": {
"inputs": {
"directory": "{{ input_images_dir }}",
"image_load_cap": 0,
"start_index": 0,
"load_always": false
},
"class_type": "LoadImagesFromDir",
"_meta": {
"title": "Load Reference Images"
}
},
"2": {
"inputs": {
"width": 896,
"height": 1152,
{# Batch sizes need to be templated as it will be determined by comfy-executors #}
"batch_size": {{ batch_size|int }}
},
"class_type": "EmptyLatentImage",
"_meta": {
"title": "Empty Latent Image"
}
},
}
Additional variables can, of course, be introduced as well which then have to be passed to the workflow rendering function.
Submitting a workflow an execution backend
comfy-executors
supports different execution backends, including local or remote ComfyUI servers and execution on serverless GPUs on RunPod or Modal.
The RunpodComfyWorkflowExecutor
class provides functionality to submit a workflow template to RunPod and handle the results.
ComfyUI server
from comfy_api_client import create_client
from comfy_executors import ComfyServerWorkflowExecutor, WorkflowTemplate
comfyui_server = "localhost:8188"
workflow_template = WorkflowTemplate.from_file("workflow.json.jinja")
async with ComfyServerWorkflowExecutor.create(
comfyui_server,
batch_size=8,
) as executor:
async for item in executor.submit_workflow_async(
workflow_template=workflow_template,
num_samples=16
):
print(item)
RunPod
Coming soon.
Modal
Coming soon.
A few notes on the example above:
- The executor can be configured to use a certain batch size. The value can also be overwritten by providing a
batch_size
to thesubmit_workflow
method. - A value for
num_samples
can be provided to generate approximatelynum_samples / batch_size
batches within a single RunPod job. While multiple jobs could be submitted to achieve the same results, generating multiple batches within a single job will generally make better use of node results caching and thus improve efficiency and latency. - The result is a list of
WorkflowOutputImage
objects. These provide the output image, the filename as set by ComfyUI and optionally the subfolder to which the image has been saved originally.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file comfy_executors-0.1.0.tar.gz
.
File metadata
- Download URL: comfy_executors-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/24.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e5d1dc37ce56d701abc8f2fb93cf16c64366fed18cf00b1fbea361562d598529 |
|
MD5 | 2ec9eac96672f7cf259ef449f287f250 |
|
BLAKE2b-256 | cce17d813888b5d4f896720ba78d9768ead20f44f01d727ec7956b2aefc4a3d2 |
File details
Details for the file comfy_executors-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: comfy_executors-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.9 Darwin/24.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c968a3035c294fb47064b57670af412ff747185f97722b923f7b8e1db99fbf5e |
|
MD5 | f38facf1da7a6012286ecbd72bd96e70 |
|
BLAKE2b-256 | c0a2aa1d6b1fc9b04d767cbd0ba9ed1f44bb340343a82608d80a4536cab0cc99 |