Actor creation causes serve.deployment to error with ray.init twice

Creating a ray.remote Actor along with a serve deployment binding prevents serve run from executing properly. It errors with ray.init being called twice. I can use serve build to create a configuration yaml. That configuration does allow serve deploy to work as intended but is not useful during development.

From what I can tell, the creation of the actor_handle starts up a ray cluster and that cluster is not honored with the serve deployment binding. Hence the error when attempting to create a second cluster.

A minimal script that exhibits the issue:

import ray
from ray import serve

class Actor:
    def __init__(self):

print("Creating actor")
actor_handle = Actor.remote()
print("After creating actor")

class SimpleDeployment:
    async def __call__(self):
        # use actor_handle here
graph = SimpleDeployment.bind()


% serve run deployment:graph 
2023-07-10 10:09:23,638 INFO -- Deploying from import path: "deployment:graph".
Creating actor
2023-07-10 10:09:25,702 INFO -- Started a local Ray instance. View the dashboard at 
After creating actor
Traceback (most recent call last):
RuntimeError: Maybe you called ray.init twice by accident? This error can be suppressed by passing in 'ignore_reinit_error=True' or by calling 'ray.shutdown()' prior to 'ray.init()'.

This issue is possibly fixed by Can you try to use nightly build and see if you still got the error?

You can find nightly wheels at Installing Ray — Ray 3.0.0.dev0

Installing the 3.0.0.dev0 wheel seems to have fixed that particular issue. Thank you.

% serve run deployment:graph
2023-07-11 08:18:24,965 INFO -- Running import path: 'deployment:graph'.
Creating actor
Usage stats collection is enabled. To disable this, run the following command: `ray disable-usage-stats` before starting Ray. See for more details.
2023-07-11 08:18:27,483 INFO -- Started a local Ray instance. View the dashboard at 
After creating actor
(HTTPProxyActor pid=79971) INFO:     Started server process [79971]
(ServeController pid=79968) INFO 2023-07-11 08:18:29,857 controller 79968 - Deploying new version of deployment default_SimpleDeployment.
(ServeController pid=79968) INFO 2023-07-11 08:18:29,960 controller 79968 - Adding 1 replica to deployment default_SimpleDeployment.
2023-07-11 08:18:30,864 INFO -- Using PowerOfTwoChoicesReplicaScheduler.
2023-07-11 08:18:30,872 INFO -- Got updated replicas for deployment default_SimpleDeployment: {'default_SimpleDeployment#zJpbqa'}.
2023-07-11 08:18:30,873 SUCC -- Deployed Serve app successfully.