Repository navigation
Handle NIXL abort notifications #30352
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 1 commit
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 |
|---|---|---|
|
|
@@ -631,6 +631,15 @@ def _prefetch_staging_reqs(self, room: int): | |
| def check_status(self, bootstrap_room: int): | ||
| return self.request_status.get(bootstrap_room, KVPoll.WaitingForInput) | ||
|
|
||
| def update_status(self, bootstrap_room: int, status: KVPoll): | ||
| # Keep Failed sticky until the sender clears the room. | ||
| if ( | ||
| bootstrap_room in self.request_status | ||
| and self.request_status[bootstrap_room] == KVPoll.Failed | ||
| ): | ||
| return | ||
| super().update_status(bootstrap_room, status) | ||
|
|
||
| def _prep_equal_tp_dlist( | ||
| self, | ||
| peer_name: str, | ||
|
|
@@ -2316,6 +2325,38 @@ def check_transfer_done(self, room: int): | |
| return False | ||
| return self.transfer_statuses[room].is_done() | ||
|
|
||
| def _handle_abort_notification(self, msg: List[bytes]) -> bool: | ||
| if not msg or msg[0] != b"ABORT": | ||
| return False | ||
|
|
||
| try: | ||
| if len(msg) != 4: | ||
| raise ValueError(f"expected 4 frames, got {len(msg)}") | ||
|
Collaborator
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. This could be covered in the following except block |
||
| room_to_be_aborted = int(msg[1].decode("ascii")) | ||
| except Exception as e: | ||
| logger.debug(f"Ignoring malformed abort notification: {e}") | ||
| return True | ||
|
|
||
| if ( | ||
| room_to_be_aborted in self.request_status | ||
| and self.check_status(room_to_be_aborted) != KVPoll.Success | ||
| ): | ||
| self.update_status(room_to_be_aborted, KVPoll.Failed) | ||
| logger.debug( | ||
| f"Received abort notification for room {room_to_be_aborted}, " | ||
| f"marked as Failed" | ||
| ) | ||
|
Comment on lines
+2343
to
+2347
Collaborator
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. Maybe record failure here
Contributor
Author
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. done |
||
| else: | ||
| logger.debug( | ||
| f"Received abort notification for room {room_to_be_aborted}, " | ||
| f"ignoring (already completed or unknown)" | ||
| ) | ||
|
|
||
| # TODO: Define real ACK/deferred-release semantics if decode-side buffer | ||
| # release needs to wait for prefill-side NIXL transfer quiescence. | ||
|
|
||
| return True | ||
|
|
||
| def _start_bootstrap_thread(self): | ||
| def bootstrap_thread(): | ||
| """This thread recvs transfer info from the decode engine""" | ||
|
|
@@ -2345,6 +2386,9 @@ def bootstrap_thread(): | |
| handle_staging_rsp(waiting_req_bytes, self.transfer_infos) | ||
| continue | ||
|
|
||
| if self._handle_abort_notification(waiting_req_bytes): | ||
| continue | ||
|
|
||
| assert ( | ||
| waiting_req_bytes[0] == GUARD | ||
| ), f"First message should be {GUARD}. Foreign traffic?" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -330,6 +330,174 @@ def test_last_zero_page_chunk_is_sent_for_aux_only_completion(self): | |
| self.assertTrue(sender.should_send_kv_chunk(3, last_chunk=False)) | ||
|
|
||
|
|
||
| class TestNixlAbortHandling(CustomTestCase): | ||
| def _make_manager(self, request_status=None): | ||
| mgr = object.__new__(NixlKVManager) | ||
| mgr.request_status = dict(request_status or {}) | ||
| mgr._connect = MagicMock() | ||
| return mgr | ||
|
|
||
| def test_given_known_incomplete_room_when_abort_arrives_then_room_fails_without_ack( | ||
| self, | ||
| ): | ||
| mgr = self._make_manager({11: KVPoll.WaitingForInput}) | ||
|
|
||
| handled = mgr._handle_abort_notification( | ||
| [b"ABORT", b"11", b"127.0.0.1", b"5555"] | ||
| ) | ||
|
|
||
| self.assertTrue(handled) | ||
| self.assertEqual(mgr.request_status[11], KVPoll.Failed) | ||
| mgr._connect.assert_not_called() | ||
|
|
||
| def test_given_successful_room_when_abort_arrives_then_status_is_preserved(self): | ||
| mgr = self._make_manager({12: KVPoll.Success}) | ||
|
|
||
| handled = mgr._handle_abort_notification( | ||
| [b"ABORT", b"12", b"127.0.0.1", b"5556"] | ||
| ) | ||
|
|
||
| self.assertTrue(handled) | ||
| self.assertEqual(mgr.request_status[12], KVPoll.Success) | ||
| mgr._connect.assert_not_called() | ||
|
|
||
| def test_given_unknown_room_when_abort_arrives_then_status_remains_absent(self): | ||
| mgr = self._make_manager() | ||
|
|
||
| handled = mgr._handle_abort_notification( | ||
| [b"ABORT", b"14", b"127.0.0.1", b"5557"] | ||
| ) | ||
|
|
||
| self.assertTrue(handled) | ||
| self.assertNotIn(14, mgr.request_status) | ||
| mgr._connect.assert_not_called() | ||
|
|
||
| def test_given_malformed_abort_when_handled_then_no_exception_or_ack(self): | ||
| mgr = self._make_manager({13: KVPoll.WaitingForInput}) | ||
|
|
||
| handled = mgr._handle_abort_notification([b"ABORT", b"13"]) | ||
|
|
||
| self.assertTrue(handled) | ||
| self.assertEqual(mgr.request_status[13], KVPoll.WaitingForInput) | ||
|
Comment on lines
+384
to
+391
Collaborator
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. b"13" has poor readability, maybe change it to b"unvalid-room"
Contributor
Author
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. done |
||
| mgr._connect.assert_not_called() | ||
|
|
||
|
|
||
| class TestNixlUpdateStatus(CustomTestCase): | ||
| def _make_manager(self, request_status): | ||
| mgr = object.__new__(NixlKVManager) | ||
| mgr.request_status = dict(request_status) | ||
| return mgr | ||
|
|
||
| def test_given_failed_room_when_status_is_promoted_then_failed_is_preserved(self): | ||
| for status in (KVPoll.Transferring, KVPoll.Success): | ||
| with self.subTest(status=status): | ||
| mgr = self._make_manager({17: KVPoll.Failed}) | ||
|
|
||
| mgr.update_status(17, status) | ||
|
|
||
| self.assertEqual(mgr.request_status[17], KVPoll.Failed) | ||
|
|
||
| def test_given_missing_room_when_failed_update_arrives_then_room_is_not_resurrected( | ||
| self, | ||
| ): | ||
| mgr = self._make_manager({}) | ||
|
|
||
| mgr.update_status(18, KVPoll.Failed) | ||
|
|
||
| self.assertNotIn(18, mgr.request_status) | ||
|
|
||
|
|
||
| class TestNixlTransferWorker(CustomTestCase): | ||
| def _make_manager(self, room): | ||
| mgr = object.__new__(NixlKVManager) | ||
| mgr.request_status = {room: KVPoll.WaitingForInput} | ||
| mgr.transfer_infos = { | ||
| room: { | ||
| "agent": TransferInfo( | ||
| room=room, | ||
| endpoint="127.0.0.1", | ||
| dst_port=5555, | ||
| agent_name="agent", | ||
| dst_kv_indices=np.array([2], dtype=np.int32), | ||
| dst_aux_index=0, | ||
| required_dst_info_num=1, | ||
| dst_state_indices=[], | ||
| ) | ||
| } | ||
| } | ||
| mgr.decode_kv_args_table = { | ||
| "agent": SimpleNamespace( | ||
| decode_tp_size=1, | ||
| dst_kv_ptrs=[0], | ||
| dst_aux_ptrs=[0], | ||
| gpu_id=0, | ||
| staging=None, | ||
| kv_xfer_segments=None, | ||
| dst_homogeneous_mem_kind="VRAM", | ||
| ) | ||
| } | ||
| mgr.req_to_decode_prefix_len = {room: 4} | ||
| mgr.enable_staging = False | ||
| mgr._staging_ctx = None | ||
| mgr.is_mla_backend = False | ||
| mgr.attn_tp_size = 1 | ||
| mgr.kv_args = SimpleNamespace(engine_rank=0) | ||
| mgr.exceptions = {} | ||
| mgr.failure_lock = threading.Lock() | ||
| mgr.failure_records = {} | ||
|
|
||
| def check_xfer_state(_handle): | ||
| mgr.update_status(room, KVPoll.Failed) | ||
| return "DONE" | ||
|
|
||
| mgr.agent = SimpleNamespace(check_xfer_state=check_xfer_state) | ||
| return mgr | ||
|
|
||
| def _make_chunk(self, room, prefill_kv_indices, is_last_chunk): | ||
| return TransferKVChunk( | ||
| room=room, | ||
| prefill_kv_indices=np.array(prefill_kv_indices, dtype=np.int32), | ||
| index_slice=slice(0, len(prefill_kv_indices)), | ||
| is_last_chunk=is_last_chunk, | ||
| chunk_id=0, | ||
| prefill_aux_index=0 if is_last_chunk else None, | ||
| state_indices=None, | ||
| ) | ||
|
|
||
| def _run_worker_once(self, mgr, chunk): | ||
| queue = SimpleNamespace(get=MagicMock(side_effect=[chunk, SystemExit()])) | ||
| with self.assertRaises(SystemExit): | ||
| mgr.transfer_worker(queue) | ||
|
|
||
| def test_given_last_chunk_aborts_mid_transfer_when_worker_finishes_then_failed_status_is_preserved( | ||
| self, | ||
| ): | ||
| room = 21 | ||
| mgr = self._make_manager(room) | ||
| mgr.send_aux = MagicMock(return_value="aux_handle") | ||
| chunk = self._make_chunk(room, [], is_last_chunk=True) | ||
|
|
||
| self._run_worker_once(mgr, chunk) | ||
|
|
||
| self.assertEqual(mgr.request_status[room], KVPoll.Failed) | ||
| self.assertNotIn(room, mgr.transfer_infos) | ||
| self.assertNotIn(room, mgr.req_to_decode_prefix_len) | ||
|
|
||
| def test_given_non_last_chunk_aborts_mid_transfer_when_worker_finishes_then_failed_status_is_preserved( | ||
| self, | ||
| ): | ||
| room = 22 | ||
| mgr = self._make_manager(room) | ||
| mgr.send_kvcache = MagicMock(return_value="kv_handle") | ||
| chunk = self._make_chunk(room, [1], is_last_chunk=False) | ||
|
|
||
| self._run_worker_once(mgr, chunk) | ||
|
|
||
| self.assertEqual(mgr.request_status[room], KVPoll.Failed) | ||
| self.assertIn(room, mgr.transfer_infos) | ||
| self.assertIn(room, mgr.req_to_decode_prefix_len) | ||
|
|
||
|
|
||
| class TestNixlNotifications(CustomTestCase): | ||
| def _make_manager(self, messages, required=None): | ||
| mgr = object.__new__(NixlKVManager) | ||
|
|
||
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.
Can be shorten to
if self.request_status.get(bootstrap_room) == KVPoll.FailedThere 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.
addressed