From e3b247679301849b8bc05acbb3ad5de6ec2bd66e Mon Sep 17 00:00:00 2001 From: maocheng23 Date: Mon, 6 Apr 2026 15:19:25 -0700 Subject: [PATCH] [fix] Fix deadlock for in_place/retract in pause_generation --- .../managers/tokenizer_communicator_mixin.py | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/python/sglang/srt/managers/tokenizer_communicator_mixin.py b/python/sglang/srt/managers/tokenizer_communicator_mixin.py index 321cc467bb158..077369b7394b5 100644 --- a/python/sglang/srt/managers/tokenizer_communicator_mixin.py +++ b/python/sglang/srt/managers/tokenizer_communicator_mixin.py @@ -602,8 +602,20 @@ async def update_weights_from_ipc( self.server_args.dp_size == 1 or self.server_args.enable_dp_attention ), "dp_size must be 1 or dp attention must be enabled for update weights from IPC" logger.info("Starting IPC weight update") - # This means that weight sync cannot run while requests are in progress. - async with self.model_update_lock.writer_lock: + + # Skip the writer lock when paused: readers are blocked on + # is_pause_cond so no concurrent inference can race, and + # waiting for the writer lock would deadlock because existing + # readers are stuck waiting on the paused scheduler. + async with self.is_pause_cond: + is_paused = self.is_pause + + lock_context = ( + self.model_update_lock.writer_lock + if not is_paused + else nullcontext() + ) + async with lock_context: result = (await self.update_weights_from_ipc_communicator(obj))[0] success, message = result.success, result.message except Exception as e: @@ -624,7 +636,14 @@ async def post_process_weights( ) -> Tuple[bool, str]: """Trigger post-processing hooks for weights after loading (e.g., Marlin conversion).""" self.auto_create_handle_loop() - async with self.model_update_lock.writer_lock: + + async with self.is_pause_cond: + is_paused = self.is_pause + + lock_context = ( + self.model_update_lock.writer_lock if not is_paused else nullcontext() + ) + async with lock_context: results = await self.post_process_weights_communicator(obj) return _Communicator.merge_results(results)