Skip to content

feat: make GPT-Image-2 nodes async for parallel execution#11

Open
gioOrchid wants to merge 1 commit into
gateway:mainfrom
gioOrchid:feat/async-parallel-gpt-image2
Open

feat: make GPT-Image-2 nodes async for parallel execution#11
gioOrchid wants to merge 1 commit into
gateway:mainfrom
gioOrchid:feat/async-parallel-gpt-image2

Conversation

@gioOrchid

Copy link
Copy Markdown

ComfyUI's executor (execution.py) detects async node functions via inspect.iscoroutinefunction() and wraps them in asyncio.create_task() instead of awaiting sequentially. This allows multiple API nodes at the same graph depth to fire their HTTP calls simultaneously.

Changes:

  • Add import asyncio to nodes.py
  • KIE_GPTImage2_TextToImage.generate: def → async def
  • KIE_GPTImage2_ImageToImage.generate: def → async def
  • Both now use asyncio.to_thread() to run the blocking HTTP job in a thread pool, allowing true concurrent I/O (GIL released for network)

Result: N independent GPT-Image-2 nodes in a workflow run in parallel instead of sequentially. For 5 ad generation nodes this yields ~5x wall-clock speedup. KIE API supports 100+ concurrent tasks and 20 requests/10s, so the server side is not a bottleneck.

No behaviour change for single-node workflows.

ComfyUI's executor (execution.py) detects async node functions via
inspect.iscoroutinefunction() and wraps them in asyncio.create_task()
instead of awaiting sequentially. This allows multiple API nodes at the
same graph depth to fire their HTTP calls simultaneously.

Changes:
- Add `import asyncio` to nodes.py
- KIE_GPTImage2_TextToImage.generate: def → async def
- KIE_GPTImage2_ImageToImage.generate: def → async def
- Both now use asyncio.to_thread() to run the blocking HTTP job in a
  thread pool, allowing true concurrent I/O (GIL released for network)

Result: N independent GPT-Image-2 nodes in a workflow run in parallel
instead of sequentially. For 5 ad generation nodes this yields ~5x
wall-clock speedup. KIE API supports 100+ concurrent tasks and 20
requests/10s, so the server side is not a bottleneck.

No behaviour change for single-node workflows.
@gioOrchid

Copy link
Copy Markdown
Author

@gateway :) nice project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant