Skip to content

Commit

Permalink
[Bugfix] fix race condition that leads to wrong order of token returned
Browse files Browse the repository at this point in the history
During the startup of the api server the setup function is called
multiple times (every 5s). So the longer the longer the startup time
(generally for larger models) the more consumers are contending for the
output. This can then lead to race condition where the order of the
answer token is wrong.

Introduce here: vllm-project#9973

References:
vllm-project#10376
vllm-project#10589
vllm-project#10782

Signed-off-by: Jannis Schönleber <[email protected]>
  • Loading branch information
joennlae authored and Jannis Schönleber committed Dec 15, 2024
1 parent 38e599d commit ccdb92f
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions vllm/engine/multiprocessing/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,14 @@ async def setup(self):
"""Setup the client before it starts sending server requests."""

# Start output_loop
self.output_loop = asyncio.create_task(self.run_output_handler_loop())
if self.output_loop is None:
# only generate once to avoid multiple concurrent output_loops
# this will lead to race conditions and wrong orders of tokens
# returned by the engine
# setup will be called multiple times during the startup of
# the engine
self.output_loop = asyncio.create_task(
self.run_output_handler_loop())

with self.get_data_socket() as socket:
# Wait until server is ready.
Expand All @@ -264,8 +271,9 @@ async def setup(self):
self.tracing_flag = response.tracing_enabled

# Start health_loop.
self.health_loop = asyncio.create_task(
self.run_heartbeat_loop(timeout=VLLM_RPC_TIMEOUT))
if self.health_loop is None:
self.health_loop = asyncio.create_task(
self.run_heartbeat_loop(timeout=VLLM_RPC_TIMEOUT))

def close(self):
"""Destroy the ZeroMQ Context."""
Expand Down

0 comments on commit ccdb92f

Please sign in to comment.