|
44 | 44 | ) |
45 | 45 | from sglang.srt.environ import envs |
46 | 46 | from sglang.srt.layers.dp_attention import initialize_dp_attention |
47 | | -from sglang.srt.managers.io_struct import ProfileReq, ProfileReqInput, ProfileReqType |
| 47 | +from sglang.srt.managers.io_struct import ( |
| 48 | + ProfileReq, |
| 49 | + ProfileReqInput, |
| 50 | + ProfileReqType, |
| 51 | + async_sock_recv, |
| 52 | + async_sock_send, |
| 53 | + sock_send, |
| 54 | +) |
48 | 55 | from sglang.srt.managers.schedule_batch import Modality, MultimodalDataItem |
49 | 56 | from sglang.srt.mem_cache.multimodal_cache import EmbeddingResult, MultiModalStaticCache |
50 | 57 | from sglang.srt.model_loader import get_model |
@@ -2390,13 +2397,14 @@ async def _dispatch_group( |
2390 | 2397 | requests = [p.request for p in group] |
2391 | 2398 | start = time.time() |
2392 | 2399 | for sock in self.send_sockets: |
2393 | | - sock.send_pyobj( |
| 2400 | + sock_send( |
| 2401 | + sock, |
2394 | 2402 | { |
2395 | 2403 | "type": "batch_encode", |
2396 | 2404 | "modality": modality.name, |
2397 | 2405 | "requests": requests, |
2398 | 2406 | "enter_time": start, |
2399 | | - } |
| 2407 | + }, |
2400 | 2408 | ) |
2401 | 2409 |
|
2402 | 2410 | logger.info(f"Dispatching batch of {len(group)} {modality.name} requests") |
@@ -2442,7 +2450,7 @@ async def _dispatch_per_request( |
2442 | 2450 | req = p.request |
2443 | 2451 | try: |
2444 | 2452 | for sock in self.send_sockets: |
2445 | | - sock.send_pyobj(req) |
| 2453 | + sock_send(sock, req) |
2446 | 2454 | result = await self.encoder.encode_request(req, modality) |
2447 | 2455 | if not p.future.done(): |
2448 | 2456 | p.future.set_result(result) |
@@ -2731,7 +2739,7 @@ async def dispatch(self, request: dict) -> dict: |
2731 | 2739 | ) |
2732 | 2740 |
|
2733 | 2741 | try: |
2734 | | - await self.dispatch_sockets[rank].send_pyobj(request) |
| 2742 | + await async_sock_send(self.dispatch_sockets[rank], request) |
2735 | 2743 | # An alive-but-stuck worker (NCCL deadlock etc.) wouldn't trip |
2736 | 2744 | # the watchdog, so bound the wait explicitly. |
2737 | 2745 | return await asyncio.wait_for(future, timeout=ENCODER_REQ_TIMEOUT) |
@@ -2780,7 +2788,7 @@ async def dispatch_send(self, request: dict) -> dict: |
2780 | 2788 | f"dp_rank={rank}, pending={self.pending_counts}" |
2781 | 2789 | ) |
2782 | 2790 | try: |
2783 | | - await self.dispatch_sockets[rank].send_pyobj(request) |
| 2791 | + await async_sock_send(self.dispatch_sockets[rank], request) |
2784 | 2792 | return await asyncio.wait_for(future, timeout=ENCODER_REQ_TIMEOUT) |
2785 | 2793 | except asyncio.TimeoutError: |
2786 | 2794 | self.pending_futures[rank].pop(key, None) |
@@ -2821,7 +2829,7 @@ async def broadcast( |
2821 | 2829 | self.req_id_to_rank[req_id] = rank |
2822 | 2830 | rank_keys.append((rank, req_id)) |
2823 | 2831 | request_copy = {**request, "req_id": req_id} |
2824 | | - await self.dispatch_sockets[rank].send_pyobj(request_copy) |
| 2832 | + await async_sock_send(self.dispatch_sockets[rank], request_copy) |
2825 | 2833 | futures.append(future) |
2826 | 2834 | # Concurrent wait → total bounded by eff_timeout, not |
2827 | 2835 | # dp_size × eff_timeout. |
@@ -2901,7 +2909,7 @@ async def _result_listener(self) -> None: |
2901 | 2909 | consecutive_errors = 0 |
2902 | 2910 | while True: |
2903 | 2911 | try: |
2904 | | - msg = await self.result_socket.recv_pyobj() |
| 2912 | + msg = await async_sock_recv(self.result_socket) |
2905 | 2913 | consecutive_errors = 0 |
2906 | 2914 | except asyncio.CancelledError: |
2907 | 2915 | raise |
@@ -3051,10 +3059,10 @@ async def _dp_worker_handle_request( |
3051 | 3059 | "_error_code": err_code, |
3052 | 3060 | } |
3053 | 3061 |
|
3054 | | - # pyzmq async send_pyobj isn't safe for concurrent senders. |
| 3062 | + # pyzmq async send isn't safe for concurrent senders. |
3055 | 3063 | try: |
3056 | 3064 | async with send_lock: |
3057 | | - await send_sock.send_pyobj(envelope) |
| 3065 | + await async_sock_send(send_sock, envelope) |
3058 | 3066 | except Exception: |
3059 | 3067 | logger.error( |
3060 | 3068 | f"DP worker {dp_rank} failed to send envelope for " |
@@ -3113,7 +3121,7 @@ async def run_dp_worker( |
3113 | 3121 | spawned = False |
3114 | 3122 | try: |
3115 | 3123 | try: |
3116 | | - request = await recv_sock.recv_pyobj() |
| 3124 | + request = await async_sock_recv(recv_sock) |
3117 | 3125 | except asyncio.CancelledError: |
3118 | 3126 | raise |
3119 | 3127 | except Exception: |
@@ -3197,7 +3205,7 @@ async def run_encoder( |
3197 | 3205 | ): |
3198 | 3206 | encoder = MMEncoder(server_args, schedule_path, dist_init_method, rank) |
3199 | 3207 | while True: |
3200 | | - request = await encoder.schedule_socket.recv_pyobj() |
| 3208 | + request = await async_sock_recv(encoder.schedule_socket) |
3201 | 3209 | if isinstance(request, ProfileReq): |
3202 | 3210 | if request.type == ProfileReqType.START_PROFILE: |
3203 | 3211 | if encoder.profiler is None: |
@@ -3601,7 +3609,7 @@ def start_background_send(req_id): |
3601 | 3609 | ) |
3602 | 3610 | else: |
3603 | 3611 | for socket in send_sockets: |
3604 | | - socket.send_pyobj(request) |
| 3612 | + sock_send(socket, request) |
3605 | 3613 | nbytes, embedding_len, embedding_dim, error_msg, error_code = ( |
3606 | 3614 | await encoder.encode_request(request, modality) |
3607 | 3615 | ) |
@@ -3822,7 +3830,7 @@ async def health_generate(): |
3822 | 3830 |
|
3823 | 3831 | # Broadcast to other TP ranks so distributed ops stay in sync |
3824 | 3832 | for socket in send_sockets: |
3825 | | - socket.send_pyobj(dummy_request) |
| 3833 | + sock_send(socket, dummy_request) |
3826 | 3834 |
|
3827 | 3835 | # Run encode on rank 0 with timeout |
3828 | 3836 | _, _, _, error_msg, _ = await asyncio.wait_for( |
@@ -3900,7 +3908,7 @@ async def start_profile_async(obj: Optional[ProfileReqInput] = None): |
3900 | 3908 | profile_stages=obj.profile_stages, |
3901 | 3909 | ) |
3902 | 3910 | for socket in send_sockets: |
3903 | | - socket.send_pyobj(req) |
| 3911 | + sock_send(socket, req) |
3904 | 3912 | if encoder.profiler is None: |
3905 | 3913 | encoder.profiler = EncoderProfiler(encoder.rank) |
3906 | 3914 | ok, msg = encoder.profiler.start(req) |
@@ -3931,7 +3939,7 @@ async def stop_profile_async(): |
3931 | 3939 | ) |
3932 | 3940 | req = ProfileReq(ProfileReqType.STOP_PROFILE) |
3933 | 3941 | for socket in send_sockets: |
3934 | | - socket.send_pyobj(req) |
| 3942 | + sock_send(socket, req) |
3935 | 3943 | ok, msg = encoder.profiler.stop() |
3936 | 3944 | if ok: |
3937 | 3945 | return Response(content="Stop profiling.\n", status_code=200) |
|
0 commit comments