Skip to content

Commit 87d47ff

Browse files
authored
Refactor(regen): drop redundant concurrency Semaphore (vllm-project#718)
## Purpose Remove the `asyncio.Semaphore` from `scripts/response_regeneration/script.py` Why: The semaphore was a no-op. main spawns exactly `args.concurrency` workers, and each worker awaits one request at a time before pulling the next item from the queue. ## Tests Nothing broken. ## Checklist I have filled in: - [x] The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)". - [x] The test plan/results, such as providing test command and pasting the results. - [ ] (Optional) The necessary documentation update. - [x] I (a human) have written or reviewed the code in this pr to the best of my ability. Signed-off-by: Ranran Haoran Zhang <ranzhang@redhat.com>
1 parent 74e30d3 commit 87d47ff

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

scripts/response_regeneration/script.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ async def detect_model(endpoint: str) -> str:
186186

187187

188188
async def _post_chat(
189-
sem: asyncio.Semaphore,
190189
session: aiohttp.ClientSession,
191190
endpoint: str,
192191
payload: dict[str, Any],
@@ -197,15 +196,14 @@ async def _post_chat(
197196
short body; otherwise the caller records a bare ``KeyError('choices')`` and
198197
the real cause is lost.
199198
"""
200-
async with sem, session.post(endpoint, json=payload) as response:
199+
async with session.post(endpoint, json=payload) as response:
201200
if not response.ok:
202201
body = (await response.text())[:500]
203202
raise RuntimeError(f"HTTP {response.status} from {endpoint}: {body}")
204203
return await response.json()
205204

206205

207206
async def worker(
208-
sem: asyncio.Semaphore,
209207
session: aiohttp.ClientSession,
210208
queue: "asyncio.Queue[dict[str, Any]]",
211209
args,
@@ -253,7 +251,7 @@ async def worker(
253251
"messages": prefix,
254252
"max_tokens": args.max_tokens,
255253
}
256-
data = await _post_chat(sem, session, endpoint, payload)
254+
data = await _post_chat(session, endpoint, payload)
257255

258256
choice = data["choices"][0]
259257
message = choice["message"]
@@ -363,7 +361,6 @@ async def main():
363361
dataset = load_dataset(dataset_id, name=subset, split=split, streaming=True)
364362

365363
queue: asyncio.Queue = asyncio.Queue(maxsize=args.concurrency * 4)
366-
semaphore = asyncio.Semaphore(args.concurrency)
367364

368365
timeout = aiohttp.ClientTimeout(total=None, sock_connect=90, sock_read=None)
369366
connector = aiohttp.TCPConnector(
@@ -391,7 +388,6 @@ async def main():
391388
workers = [
392389
asyncio.create_task(
393390
worker(
394-
semaphore,
395391
session,
396392
queue,
397393
args,

0 commit comments

Comments
 (0)