Skip to content

Commit

Permalink
Revert "[Serve] Fix ServeHandle serialization (#13695)" (#13753)
Browse files Browse the repository at this point in the history
This reverts commit 202fbdf.
  • Loading branch information
simon-mo authored Jan 28, 2021
1 parent 2e01d5d commit c10abbb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 68 deletions.
7 changes: 0 additions & 7 deletions python/ray/serve/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ def check(self, *args, **kwargs):

class ThreadProxiedRouter:
def __init__(self, controller_handle, sync: bool):
self.controller_handle = controller_handle
self.sync = sync
self.router = Router(controller_handle)

if sync:
Expand All @@ -94,11 +92,6 @@ def _remote(self, endpoint_name, handle_options, request_data,
**kwargs)
return coro

def __reduce__(self):
deserializer = ThreadProxiedRouter
serialized_data = (self.controller_handle, self.sync)
return deserializer, serialized_data


class Client:
def __init__(self,
Expand Down
25 changes: 7 additions & 18 deletions python/ray/serve/handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from typing import Any, Dict, Optional, Union
from enum import Enum

from ray.serve.router import Router


@dataclass(frozen=True)
class HandleOptions:
Expand Down Expand Up @@ -38,11 +40,10 @@ class RayServeHandle:
# raises RayTaskError Exception
"""

def __init__(
self,
router, # ThreadProxiedRouter
endpoint_name,
handle_options: Optional[HandleOptions] = None):
def __init__(self,
router: Router,
endpoint_name,
handle_options: Optional[HandleOptions] = None):
self.router = router
self.endpoint_name = endpoint_name
self.handle_options = handle_options or HandleOptions()
Expand Down Expand Up @@ -77,7 +78,7 @@ def options(self,
async def remote(self,
request_data: Optional[Union[Dict, Any]] = None,
**kwargs):
"""Issue an asynchronous request to the endpoint.
"""Issue an asynchrounous request to the endpoint.
Returns a Ray ObjectRef whose results can be waited for or retrieved
using ray.wait or ray.get (or ``await object_ref``), respectively.
Expand All @@ -97,12 +98,6 @@ async def remote(self,
def __repr__(self):
return f"{self.__class__.__name__}(endpoint='{self.endpoint_name}')"

def __reduce__(self):
deserializer = RayServeHandle
serialized_data = (self.router, self.endpoint_name,
self.handle_options)
return deserializer, serialized_data


class RayServeSyncHandle(RayServeHandle):
def remote(self, request_data: Optional[Union[Dict, Any]] = None,
Expand All @@ -128,9 +123,3 @@ def remote(self, request_data: Optional[Union[Dict, Any]] = None,
future: concurrent.futures.Future = asyncio.run_coroutine_threadsafe(
coro, self.router.async_loop)
return future.result()

def __reduce__(self):
deserializer = RayServeSyncHandle
serialized_data = (self.router, self.endpoint_name,
self.handle_options)
return deserializer, serialized_data
44 changes: 1 addition & 43 deletions python/ray/serve/tests/test_handle.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,9 @@
import requests
import pytest

import ray
from ray import serve


@pytest.mark.asyncio
async def test_async_handle_serializable(serve_instance):
client = serve_instance

def f(_):
return "hello"

client.create_backend("f", f)
client.create_endpoint("f", backend="f")

@ray.remote
class TaskActor:
async def task(self, handle):
ref = await handle.remote()
output = await ref
return output

handle = client.get_handle("f", sync=False)

task_actor = TaskActor.remote()
result = await task_actor.task.remote(handle)
assert result == "hello"


def test_sync_handle_serializable(serve_instance):
client = serve_instance

def f(_):
return "hello"

client.create_backend("f", f)
client.create_endpoint("f", backend="f")

@ray.remote
def task(handle):
return ray.get(handle.remote())

handle = client.get_handle("f", sync=True)
result_ref = task.remote(handle)
assert ray.get(result_ref) == "hello"


def test_handle_in_endpoint(serve_instance):
client = serve_instance

Expand Down

0 comments on commit c10abbb

Please sign in to comment.