Skip to content

Commit 405c8d7

Browse files
simon-mofishbone
authored andcommitted
Revert "[Serve] Fix ServeHandle serialization (ray-project#13695)" (ray-project#13753)
This reverts commit 202fbdf.
1 parent c1f9c0d commit 405c8d7

3 files changed

Lines changed: 8 additions & 68 deletions

File tree

python/ray/serve/api.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ def check(self, *args, **kwargs):
6666

6767
class ThreadProxiedRouter:
6868
def __init__(self, controller_handle, sync: bool):
69-
self.controller_handle = controller_handle
70-
self.sync = sync
7169
self.router = Router(controller_handle)
7270

7371
if sync:
@@ -94,11 +92,6 @@ def _remote(self, endpoint_name, handle_options, request_data,
9492
**kwargs)
9593
return coro
9694

97-
def __reduce__(self):
98-
deserializer = ThreadProxiedRouter
99-
serialized_data = (self.controller_handle, self.sync)
100-
return deserializer, serialized_data
101-
10295

10396
class Client:
10497
def __init__(self,

python/ray/serve/handle.py

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from typing import Any, Dict, Optional, Union
55
from enum import Enum
66

7+
from ray.serve.router import Router
8+
79

810
@dataclass(frozen=True)
911
class HandleOptions:
@@ -38,11 +40,10 @@ class RayServeHandle:
3840
# raises RayTaskError Exception
3941
"""
4042

41-
def __init__(
42-
self,
43-
router, # ThreadProxiedRouter
44-
endpoint_name,
45-
handle_options: Optional[HandleOptions] = None):
43+
def __init__(self,
44+
router: Router,
45+
endpoint_name,
46+
handle_options: Optional[HandleOptions] = None):
4647
self.router = router
4748
self.endpoint_name = endpoint_name
4849
self.handle_options = handle_options or HandleOptions()
@@ -77,7 +78,7 @@ def options(self,
7778
async def remote(self,
7879
request_data: Optional[Union[Dict, Any]] = None,
7980
**kwargs):
80-
"""Issue an asynchronous request to the endpoint.
81+
"""Issue an asynchrounous request to the endpoint.
8182
8283
Returns a Ray ObjectRef whose results can be waited for or retrieved
8384
using ray.wait or ray.get (or ``await object_ref``), respectively.
@@ -97,12 +98,6 @@ async def remote(self,
9798
def __repr__(self):
9899
return f"{self.__class__.__name__}(endpoint='{self.endpoint_name}')"
99100

100-
def __reduce__(self):
101-
deserializer = RayServeHandle
102-
serialized_data = (self.router, self.endpoint_name,
103-
self.handle_options)
104-
return deserializer, serialized_data
105-
106101

107102
class RayServeSyncHandle(RayServeHandle):
108103
def remote(self, request_data: Optional[Union[Dict, Any]] = None,
@@ -128,9 +123,3 @@ def remote(self, request_data: Optional[Union[Dict, Any]] = None,
128123
future: concurrent.futures.Future = asyncio.run_coroutine_threadsafe(
129124
coro, self.router.async_loop)
130125
return future.result()
131-
132-
def __reduce__(self):
133-
deserializer = RayServeSyncHandle
134-
serialized_data = (self.router, self.endpoint_name,
135-
self.handle_options)
136-
return deserializer, serialized_data

python/ray/serve/tests/test_handle.py

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,9 @@
11
import requests
2-
import pytest
2+
33
import ray
44
from ray import serve
55

66

7-
@pytest.mark.asyncio
8-
async def test_async_handle_serializable(serve_instance):
9-
client = serve_instance
10-
11-
def f(_):
12-
return "hello"
13-
14-
client.create_backend("f", f)
15-
client.create_endpoint("f", backend="f")
16-
17-
@ray.remote
18-
class TaskActor:
19-
async def task(self, handle):
20-
ref = await handle.remote()
21-
output = await ref
22-
return output
23-
24-
handle = client.get_handle("f", sync=False)
25-
26-
task_actor = TaskActor.remote()
27-
result = await task_actor.task.remote(handle)
28-
assert result == "hello"
29-
30-
31-
def test_sync_handle_serializable(serve_instance):
32-
client = serve_instance
33-
34-
def f(_):
35-
return "hello"
36-
37-
client.create_backend("f", f)
38-
client.create_endpoint("f", backend="f")
39-
40-
@ray.remote
41-
def task(handle):
42-
return ray.get(handle.remote())
43-
44-
handle = client.get_handle("f", sync=True)
45-
result_ref = task.remote(handle)
46-
assert ray.get(result_ref) == "hello"
47-
48-
497
def test_handle_in_endpoint(serve_instance):
508
client = serve_instance
519

0 commit comments

Comments
 (0)