mirror of
https://github.com/wassname/ray.git
synced 2026-07-02 02:42:52 +08:00
Use RAY_ADDRESS to connect to an existing Ray cluster if present (#7977)
This commit is contained in:
@@ -5,8 +5,6 @@ import logging
|
||||
from ray.util.multiprocessing.pool import Pool
|
||||
import ray
|
||||
|
||||
RAY_ADDRESS_ENV = "RAY_ADDRESS"
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -34,15 +32,13 @@ class RayBackend(MultiprocessingBackend):
|
||||
if n_jobs == -1:
|
||||
if not ray.is_initialized():
|
||||
import os
|
||||
if RAY_ADDRESS_ENV in os.environ:
|
||||
ray_address = os.environ[RAY_ADDRESS_ENV]
|
||||
if "RAY_ADDRESS" in os.environ:
|
||||
logger.info(
|
||||
"Connecting to ray cluster at address='{}'".format(
|
||||
ray_address))
|
||||
ray.init(address=ray_address)
|
||||
os.environ["RAY_ADDRESS"]))
|
||||
else:
|
||||
logger.info("Starting local ray cluster")
|
||||
ray.init()
|
||||
ray.init()
|
||||
ray_cpus = int(ray.state.cluster_resources()["CPU"])
|
||||
n_jobs = ray_cpus
|
||||
|
||||
|
||||
@@ -349,11 +349,12 @@ class Pool:
|
||||
# Else, the priority is:
|
||||
# ray_address argument > RAY_ADDRESS > start new local cluster.
|
||||
if not ray.is_initialized():
|
||||
if ray_address is None and RAY_ADDRESS_ENV in os.environ:
|
||||
ray_address = os.environ[RAY_ADDRESS_ENV]
|
||||
|
||||
# Cluster mode.
|
||||
if ray_address is not None:
|
||||
if ray_address is None and RAY_ADDRESS_ENV in os.environ:
|
||||
logger.info("Connecting to ray cluster at address='{}'".format(
|
||||
os.environ[RAY_ADDRESS_ENV]))
|
||||
ray.init()
|
||||
elif ray_address is not None:
|
||||
logger.info("Connecting to ray cluster at address='{}'".format(
|
||||
ray_address))
|
||||
ray.init(address=ray_address)
|
||||
|
||||
Reference in New Issue
Block a user