Repository navigation
Fix deadlock for in_place/retract in pause_generation #22211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+640
to
648
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the change in
Suggested change
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation introduces a race condition. By releasing
is_pause_condbefore performing the weight update withnullcontext(), it's possible forcontinue_generationto be called in the interim. This would setis_pause = False, allowing new inference requests to proceed and the scheduler to unpause. This leads to concurrent weight updates and inference, which can cause data corruption or crashes.To fix this, the weight update should be performed while holding the
is_pause_condlock if the engine is paused, ensuring thatcontinue_generationcannot unpause the scheduler until the update is complete.