Skip to content

Commit 9054099

Browse files
committed
cap batching to 16
1 parent 413c373 commit 9054099

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎rlm/core/lm_handler.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,14 @@ def _handle_batched(self, request: LMRequest, handler: "LMHandler") -> LMRespons
8585

8686
start_time = time.perf_counter()
8787

88+
sem = asyncio.Semaphore(handler.batch_max_concurrent)
89+
90+
async def run_one(prompt: str):
91+
async with sem:
92+
return await client.acompletion(prompt)
93+
8894
async def run_all():
89-
tasks = [client.acompletion(prompt) for prompt in request.prompts]
95+
tasks = [run_one(prompt) for prompt in request.prompts]
9096
return await asyncio.gather(*tasks)
9197

9298
results = asyncio.run(run_all())
@@ -132,6 +138,7 @@ def __init__(
132138
host: str = "127.0.0.1",
133139
port: int = 0, # auto-assign available port
134140
other_backend_client: BaseLM | None = None,
141+
batch_max_concurrent: int = 16,
135142
):
136143
self.default_client = client
137144
self.other_backend_client = other_backend_client
@@ -140,6 +147,7 @@ def __init__(
140147
self._server: ThreadingLMServer | None = None
141148
self._thread: Thread | None = None
142149
self._port = port
150+
self.batch_max_concurrent = batch_max_concurrent
143151

144152
self.register_client(client.model_name, client)
145153

0 commit comments

Comments
 (0)