-
-
Notifications
You must be signed in to change notification settings - Fork 798
[feat] Add pipeline parallelism and fix batch_run to use ThreadPoolExecutor #1463
Copy link
Copy link
Open
Labels
FEATNew Feature requestNew Feature requestenhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed
Description
Summary
Two related issues with AgentRearrange.batch_run():
- batch_run is not concurrent — The comment says "process batch using concurrent execution" (line 843) but the implementation is a sequential list comprehension. It should use a thread pool.
- No pipeline parallelism — When processing multiple tasks through a sequential flow, agent 2 could start on task 1 while agent 1 works on task 2. Currently each task must fully complete before the next one starts.
Problem
Current implementation (agent_rearrange.py lines 844-852):
# Process batch using concurrent execution <-- comment says concurrent
batch_results = [ # <-- but it's sequential
self.run(task=task, img=img_path)
for task, img_path in zip(batch_tasks, batch_imgs)
]For 5 tasks with 3 agents each taking 2s: current = 30s, with thread pool = ~6s per batch.
Proposed solution
Fix 1: Use ThreadPoolExecutor within batches
with ThreadPoolExecutor(max_workers=min(len(batch_tasks), os.cpu_count())) as executor:
futures = [
executor.submit(self.run, task=task, img=img_path)
for task, img_path in zip(batch_tasks, batch_imgs)
]
batch_results = [f.result() for f in futures]Fix 2: Pipeline parallelism (future enhancement)
For sequential flows, allow task N+1 to enter the pipeline at agent 1 while task N is at agent 2. This requires decoupling per-task conversation state from the shared self.conversation.
Acceptance criteria
-
batch_runusesThreadPoolExecutorto process tasks within each batch concurrently - Each task gets its own conversation copy to avoid shared state corruption
- Batch ordering is preserved in results
- Existing tests pass unchanged
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
FEATNew Feature requestNew Feature requestenhancementNew feature or requestNew feature or requesthelp wantedExtra attention is neededExtra attention is needed