mirror of
https://github.com/wassname/ray.git
synced 2026-06-29 16:48:51 +08:00
Add ray.util package and move libraries from experimental (#7100)
This commit is contained in:
@@ -96,6 +96,7 @@ import ray.actor # noqa: F401
|
||||
from ray.actor import method # noqa: E402
|
||||
from ray.runtime_context import _get_runtime_context # noqa: E402
|
||||
from ray.cross_language import java_function, java_actor_class # noqa: E402
|
||||
from ray import util # noqa: E402
|
||||
|
||||
# Ray version string.
|
||||
__version__ = "0.9.0.dev0"
|
||||
@@ -140,6 +141,7 @@ __all__ = [
|
||||
"Language",
|
||||
"java_function",
|
||||
"java_actor_class",
|
||||
"util",
|
||||
]
|
||||
|
||||
# ID types
|
||||
|
||||
+3
-3
@@ -483,14 +483,14 @@ class ActorClass:
|
||||
# Check whether the name is already taken.
|
||||
if name is not None:
|
||||
try:
|
||||
ray.experimental.get_actor(name)
|
||||
ray.util.get_actor(name)
|
||||
except ValueError: # name is not taken, expected.
|
||||
pass
|
||||
else:
|
||||
raise ValueError(
|
||||
"The name {name} is already taken. Please use "
|
||||
"a different name or get existing actor using "
|
||||
"ray.experimental.get_actor('{name}')".format(name=name))
|
||||
"ray.util.get_actor('{name}')".format(name=name))
|
||||
|
||||
# Set the actor's default resources if not already set. First three
|
||||
# conditions are to check that no resources were specified in the
|
||||
@@ -585,7 +585,7 @@ class ActorClass:
|
||||
original_handle=True)
|
||||
|
||||
if name is not None:
|
||||
ray.experimental.register_actor(name, actor_handle)
|
||||
ray.util.register_actor(name, actor_handle)
|
||||
|
||||
return actor_handle
|
||||
|
||||
|
||||
@@ -1,28 +1,8 @@
|
||||
from .gcs_flush_policy import (set_flushing_policy, GcsFlushPolicy,
|
||||
SimpleGcsFlushPolicy)
|
||||
from .named_actors import get_actor, register_actor
|
||||
from .api import get, wait
|
||||
from .actor_pool import ActorPool
|
||||
from .dynamic_resources import set_resource
|
||||
from . import iter
|
||||
|
||||
|
||||
def TensorFlowVariables(*args, **kwargs):
|
||||
raise DeprecationWarning(
|
||||
"'ray.experimental.TensorFlowVariables' is deprecated. Instead, please"
|
||||
" do 'from ray.experimental.tf_utils import TensorFlowVariables'.")
|
||||
|
||||
|
||||
__all__ = [
|
||||
"TensorFlowVariables",
|
||||
"get_actor",
|
||||
"register_actor",
|
||||
"get",
|
||||
"wait",
|
||||
"set_flushing_policy",
|
||||
"GcsFlushPolicy",
|
||||
"SimpleGcsFlushPolicy",
|
||||
"set_resource",
|
||||
"ActorPool",
|
||||
"iter",
|
||||
]
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
import ray
|
||||
import ray.cloudpickle as pickle
|
||||
|
||||
|
||||
class GcsFlushPolicy:
|
||||
"""Experimental: a policy to control GCS flushing.
|
||||
|
||||
Used by Monitor to enable automatic control of memory usage.
|
||||
"""
|
||||
|
||||
def should_flush(self, redis_client):
|
||||
"""Returns a bool, whether a flush request should be issued."""
|
||||
pass
|
||||
|
||||
def num_entries_to_flush(self):
|
||||
"""Returns an upper bound for number of entries to flush next."""
|
||||
pass
|
||||
|
||||
def record_flush(self):
|
||||
"""Must be called after a flush has been performed."""
|
||||
pass
|
||||
|
||||
|
||||
class SimpleGcsFlushPolicy(GcsFlushPolicy):
|
||||
"""A simple policy with constant flush rate, after a warmup period.
|
||||
|
||||
Example policy values:
|
||||
|
||||
flush_when_at_least_bytes 2GB
|
||||
|
||||
flush_period_secs 10s
|
||||
|
||||
flush_num_entries_each_time 10k
|
||||
|
||||
This means: (1) If the GCS shard uses less than 2GB of memory,
|
||||
no flushing would take place. This should cover most Ray runs. (2) The
|
||||
GCS shard will only honor a flush request, if it's issued after 10
|
||||
seconds since the last processed flush. In particular this means it's
|
||||
okay for the Monitor to issue requests more frequently than this param.
|
||||
(3) When processing a flush, the shard will flush at most 10k entries.
|
||||
This is to control the latency of each request.
|
||||
|
||||
Note, flush rate == (flush period) * (num entries each time). So
|
||||
applications that have a heavier GCS load can tune these params.
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
flush_when_at_least_bytes=(1 << 31),
|
||||
flush_period_secs=10,
|
||||
flush_num_entries_each_time=10000):
|
||||
self.flush_when_at_least_bytes = flush_when_at_least_bytes
|
||||
self.flush_period_secs = flush_period_secs
|
||||
self.flush_num_entries_each_time = flush_num_entries_each_time
|
||||
self.last_flush_timestamp = time.time()
|
||||
|
||||
def should_flush(self, redis_client):
|
||||
if time.time() - self.last_flush_timestamp < self.flush_period_secs:
|
||||
return False
|
||||
|
||||
used_memory = redis_client.info("memory")["used_memory"]
|
||||
assert used_memory > 0
|
||||
|
||||
return used_memory >= self.flush_when_at_least_bytes
|
||||
|
||||
def num_entries_to_flush(self):
|
||||
return self.flush_num_entries_each_time
|
||||
|
||||
def record_flush(self):
|
||||
self.last_flush_timestamp = time.time()
|
||||
|
||||
def serialize(self):
|
||||
return pickle.dumps(self)
|
||||
|
||||
|
||||
def set_flushing_policy(flushing_policy):
|
||||
"""Serialize this policy for Monitor to pick up."""
|
||||
if "RAY_USE_NEW_GCS" not in os.environ:
|
||||
raise Exception(
|
||||
"set_flushing_policy() is only available when environment "
|
||||
"variable RAY_USE_NEW_GCS is present at both compile and run time."
|
||||
)
|
||||
ray.worker.global_worker.check_connected()
|
||||
redis_client = ray.worker.global_worker.redis_client
|
||||
|
||||
serialized = pickle.dumps(flushing_policy)
|
||||
redis_client.set("gcs_flushing_policy", serialized)
|
||||
@@ -1,4 +0,0 @@
|
||||
from ray.experimental.sgd.pytorch import PyTorchTrainer
|
||||
from ray.experimental.sgd.tf import TFTrainer
|
||||
|
||||
__all__ = ["PyTorchTrainer", "TFTrainer"]
|
||||
@@ -1,3 +0,0 @@
|
||||
from ray.experimental.sgd.tf.tf_trainer import (TFTrainer, TFTrainable)
|
||||
|
||||
__all__ = ["TFTrainer", "TFTrainable"]
|
||||
@@ -5,11 +5,8 @@ import time
|
||||
import traceback
|
||||
import json
|
||||
|
||||
import redis
|
||||
|
||||
import ray
|
||||
from ray.autoscaler.autoscaler import LoadMetrics, StandardAutoscaler
|
||||
import ray.cloudpickle as pickle
|
||||
import ray.gcs_utils
|
||||
import ray.utils
|
||||
import ray.ray_constants as ray_constants
|
||||
@@ -54,34 +51,6 @@ class Monitor:
|
||||
self.autoscaler = None
|
||||
self.autoscaling_config = None
|
||||
|
||||
# Experimental feature: GCS flushing.
|
||||
self.issue_gcs_flushes = "RAY_USE_NEW_GCS" in os.environ
|
||||
self.gcs_flush_policy = None
|
||||
if self.issue_gcs_flushes:
|
||||
# Data is stored under the first data shard, so we issue flushes to
|
||||
# that redis server.
|
||||
addr_port = self.redis.lrange("RedisShards", 0, -1)
|
||||
if len(addr_port) > 1:
|
||||
logger.warning(
|
||||
"Monitor: "
|
||||
"TODO: if launching > 1 redis shard, flushing needs to "
|
||||
"touch shards in parallel.")
|
||||
self.issue_gcs_flushes = False
|
||||
else:
|
||||
addr_port = addr_port[0].split(b":")
|
||||
self.redis_shard = redis.StrictRedis(
|
||||
host=addr_port[0],
|
||||
port=addr_port[1],
|
||||
password=redis_password)
|
||||
try:
|
||||
self.redis_shard.execute_command("HEAD.FLUSH 0")
|
||||
except redis.exceptions.ResponseError as e:
|
||||
logger.info(
|
||||
"Monitor: "
|
||||
"Turning off flushing due to exception: {}".format(
|
||||
str(e)))
|
||||
self.issue_gcs_flushes = False
|
||||
|
||||
def __del__(self):
|
||||
"""Destruct the monitor object."""
|
||||
# We close the pubsub client to avoid leaking file descriptors.
|
||||
@@ -288,37 +257,6 @@ class Monitor:
|
||||
ip_address += ":" + str(raylet_info["NodeManagerPort"])
|
||||
self.raylet_id_to_ip_map[node_id] = ip_address
|
||||
|
||||
def _maybe_flush_gcs(self):
|
||||
"""Experimental: issue a flush request to the GCS.
|
||||
|
||||
The purpose of this feature is to control GCS memory usage.
|
||||
|
||||
To activate this feature, Ray must be compiled with the flag
|
||||
RAY_USE_NEW_GCS set, and Ray must be started at run time with the flag
|
||||
as well.
|
||||
"""
|
||||
if not self.issue_gcs_flushes:
|
||||
return
|
||||
if self.gcs_flush_policy is None:
|
||||
serialized = self.redis.get("gcs_flushing_policy")
|
||||
if serialized is None:
|
||||
# Client has not set any policy; by default flushing is off.
|
||||
return
|
||||
self.gcs_flush_policy = pickle.loads(serialized)
|
||||
|
||||
if not self.gcs_flush_policy.should_flush(self.redis_shard):
|
||||
return
|
||||
|
||||
max_entries_to_flush = self.gcs_flush_policy.num_entries_to_flush()
|
||||
num_flushed = self.redis_shard.execute_command(
|
||||
"HEAD.FLUSH {}".format(max_entries_to_flush))
|
||||
logger.info("Monitor: num_flushed {}".format(num_flushed))
|
||||
|
||||
# This flushes event log and log files.
|
||||
ray.experimental.flush_redis_unsafe(self.redis)
|
||||
|
||||
self.gcs_flush_policy.record_flush()
|
||||
|
||||
def _run(self):
|
||||
"""Run the monitor.
|
||||
|
||||
@@ -346,8 +284,6 @@ class Monitor:
|
||||
if self.autoscaler:
|
||||
self.autoscaler.update()
|
||||
|
||||
self._maybe_flush_gcs()
|
||||
|
||||
# Process a round of messages.
|
||||
self.process_messages()
|
||||
|
||||
|
||||
@@ -977,7 +977,7 @@ cli.add_command(project_cli)
|
||||
cli.add_command(session_cli)
|
||||
|
||||
try:
|
||||
from ray.experimental.serve.scripts import serve_cli
|
||||
from ray.serve.scripts import serve_cli
|
||||
cli.add_command(serve_cli)
|
||||
except Exception as e:
|
||||
logger.debug(
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from ray.experimental.serve.backend_config import BackendConfig
|
||||
from ray.experimental.serve.policy import RoutePolicy
|
||||
from ray.experimental.serve.api import (
|
||||
from ray.serve.backend_config import BackendConfig
|
||||
from ray.serve.policy import RoutePolicy
|
||||
from ray.serve.api import (
|
||||
init, create_backend, create_endpoint, link, split, get_handle, stat,
|
||||
set_backend_config, get_backend_config, accept_batch, route) # noqa: E402
|
||||
|
||||
@@ -7,18 +7,17 @@ from multiprocessing import cpu_count
|
||||
import numpy as np
|
||||
|
||||
import ray
|
||||
from ray.experimental.serve.constants import (
|
||||
DEFAULT_HTTP_HOST, DEFAULT_HTTP_PORT, SERVE_NURSERY_NAME)
|
||||
from ray.experimental.serve.global_state import (GlobalState,
|
||||
start_initial_state)
|
||||
from ray.experimental.serve.kv_store_service import SQLiteKVStore
|
||||
from ray.experimental.serve.task_runner import RayServeMixin, TaskRunnerActor
|
||||
from ray.experimental.serve.utils import (block_until_http_ready,
|
||||
get_random_letters, expand)
|
||||
from ray.experimental.serve.exceptions import RayServeException
|
||||
from ray.experimental.serve.backend_config import BackendConfig
|
||||
from ray.experimental.serve.policy import RoutePolicy
|
||||
from ray.experimental.serve.queues import Query
|
||||
from ray.serve.constants import (DEFAULT_HTTP_HOST, DEFAULT_HTTP_PORT,
|
||||
SERVE_NURSERY_NAME)
|
||||
from ray.serve.global_state import (GlobalState, start_initial_state)
|
||||
from ray.serve.kv_store_service import SQLiteKVStore
|
||||
from ray.serve.task_runner import RayServeMixin, TaskRunnerActor
|
||||
from ray.serve.utils import (block_until_http_ready, get_random_letters,
|
||||
expand)
|
||||
from ray.serve.exceptions import RayServeException
|
||||
from ray.serve.backend_config import BackendConfig
|
||||
from ray.serve.policy import RoutePolicy
|
||||
from ray.serve.queues import Query
|
||||
global_state = None
|
||||
|
||||
|
||||
@@ -114,7 +113,7 @@ def init(kv_store_connector=None,
|
||||
|
||||
# Try to get serve nursery if there exists
|
||||
try:
|
||||
ray.experimental.get_actor(SERVE_NURSERY_NAME)
|
||||
ray.util.get_actor(SERVE_NURSERY_NAME)
|
||||
global_state = GlobalState()
|
||||
return
|
||||
except ValueError:
|
||||
@@ -440,7 +439,7 @@ def get_handle(endpoint_name, relative_slo_ms=None, absolute_slo_ms=None):
|
||||
global_state.route_table.list_service(include_headless=True).values())
|
||||
|
||||
# Delay import due to it's dependency on global_state
|
||||
from ray.experimental.serve.handle import RayServeHandle
|
||||
from ray.serve.handle import RayServeHandle
|
||||
|
||||
return RayServeHandle(global_state.init_or_get_router(), endpoint_name,
|
||||
relative_slo_ms, absolute_slo_ms)
|
||||
@@ -1,6 +1,6 @@
|
||||
from enum import IntEnum
|
||||
|
||||
from ray.experimental.serve.exceptions import RayServeException
|
||||
from ray.serve.exceptions import RayServeException
|
||||
|
||||
|
||||
class TaskContext(IntEnum):
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
from ray.experimental import serve
|
||||
from ray.experimental.serve.constants import DEFAULT_HTTP_ADDRESS
|
||||
from ray import serve
|
||||
from ray.serve.constants import DEFAULT_HTTP_ADDRESS
|
||||
import requests
|
||||
import time
|
||||
import pandas as pd
|
||||
@@ -6,8 +6,8 @@ import time
|
||||
|
||||
import requests
|
||||
|
||||
from ray.experimental import serve
|
||||
from ray.experimental.serve.utils import pformat_color_json
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def echo(flask_request):
|
||||
+2
-2
@@ -10,8 +10,8 @@ import time
|
||||
import requests
|
||||
|
||||
import ray
|
||||
from ray.experimental import serve
|
||||
from ray.experimental.serve.utils import pformat_color_json
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
class MagicCounter:
|
||||
+3
-3
@@ -10,9 +10,9 @@ import time
|
||||
import requests
|
||||
|
||||
import ray
|
||||
from ray.experimental import serve
|
||||
from ray.experimental.serve.utils import pformat_color_json
|
||||
from ray.experimental.serve import BackendConfig
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
from ray.serve import BackendConfig
|
||||
|
||||
|
||||
class MagicCounter:
|
||||
+2
-2
@@ -3,8 +3,8 @@ This example has backend which has batching functionality enabled.
|
||||
"""
|
||||
|
||||
import ray
|
||||
from ray.experimental import serve
|
||||
from ray.experimental.serve import BackendConfig
|
||||
from ray import serve
|
||||
from ray.serve import BackendConfig
|
||||
|
||||
|
||||
class MagicCounter:
|
||||
+2
-2
@@ -18,8 +18,8 @@ import time
|
||||
import requests
|
||||
|
||||
import ray
|
||||
from ray.experimental import serve
|
||||
from ray.experimental.serve.utils import pformat_color_json
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def echo(_):
|
||||
+2
-2
@@ -10,8 +10,8 @@ import time
|
||||
|
||||
import requests
|
||||
|
||||
from ray.experimental import serve
|
||||
from ray.experimental.serve.utils import pformat_color_json
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def echo_v1(_):
|
||||
+2
-2
@@ -7,8 +7,8 @@ import time
|
||||
import requests
|
||||
|
||||
import ray
|
||||
import ray.experimental.serve as serve
|
||||
from ray.experimental.serve.utils import pformat_color_json
|
||||
import ray.serve as serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
# initialize ray serve system.
|
||||
# blocking=True will wait for HTTP server to be ready to serve request.
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
Ray serve pipeline example
|
||||
"""
|
||||
import ray
|
||||
import ray.experimental.serve as serve
|
||||
import ray.serve as serve
|
||||
import time
|
||||
|
||||
# initialize ray serve system.
|
||||
+2
-2
@@ -6,8 +6,8 @@ import time
|
||||
|
||||
import requests
|
||||
|
||||
from ray.experimental import serve
|
||||
from ray.experimental.serve.utils import pformat_color_json
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def echo_v1(_):
|
||||
+1
-1
@@ -7,7 +7,7 @@ import time
|
||||
import requests
|
||||
|
||||
import ray
|
||||
import ray.experimental.serve as serve
|
||||
import ray.serve as serve
|
||||
|
||||
# initialize ray serve system.
|
||||
# blocking=True will wait for HTTP server to be ready to serve request.
|
||||
+2
-2
@@ -6,8 +6,8 @@ import time
|
||||
|
||||
import requests
|
||||
|
||||
from ray.experimental import serve
|
||||
from ray.experimental.serve.utils import pformat_color_json
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def echo_v1(_):
|
||||
@@ -1,19 +1,18 @@
|
||||
import ray
|
||||
from ray.experimental.serve.constants import (
|
||||
BOOTSTRAP_KV_STORE_CONN_KEY, DEFAULT_HTTP_HOST, DEFAULT_HTTP_PORT,
|
||||
SERVE_NURSERY_NAME, ASYNC_CONCURRENCY)
|
||||
from ray.experimental.serve.kv_store_service import (
|
||||
BackendTable, RoutingTable, TrafficPolicyTable)
|
||||
from ray.experimental.serve.metric import (MetricMonitor,
|
||||
start_metric_monitor_loop)
|
||||
from ray.serve.constants import (BOOTSTRAP_KV_STORE_CONN_KEY,
|
||||
DEFAULT_HTTP_HOST, DEFAULT_HTTP_PORT,
|
||||
SERVE_NURSERY_NAME, ASYNC_CONCURRENCY)
|
||||
from ray.serve.kv_store_service import (BackendTable, RoutingTable,
|
||||
TrafficPolicyTable)
|
||||
from ray.serve.metric import (MetricMonitor, start_metric_monitor_loop)
|
||||
|
||||
from ray.experimental.serve.policy import RoutePolicy
|
||||
from ray.experimental.serve.server import HTTPActor
|
||||
from ray.serve.policy import RoutePolicy
|
||||
from ray.serve.server import HTTPActor
|
||||
|
||||
|
||||
def start_initial_state(kv_store_connector):
|
||||
nursery_handle = ActorNursery.remote()
|
||||
ray.experimental.register_actor(SERVE_NURSERY_NAME, nursery_handle)
|
||||
ray.util.register_actor(SERVE_NURSERY_NAME, nursery_handle)
|
||||
|
||||
ray.get(
|
||||
nursery_handle.store_bootstrap_state.remote(
|
||||
@@ -92,8 +91,7 @@ class GlobalState:
|
||||
def __init__(self, actor_nursery_handle=None):
|
||||
# Get actor nursery handle
|
||||
if actor_nursery_handle is None:
|
||||
actor_nursery_handle = ray.experimental.get_actor(
|
||||
SERVE_NURSERY_NAME)
|
||||
actor_nursery_handle = ray.util.get_actor(SERVE_NURSERY_NAME)
|
||||
self.actor_nursery_handle = actor_nursery_handle
|
||||
|
||||
# Connect to all the table
|
||||
@@ -126,7 +124,7 @@ class GlobalState:
|
||||
return_policy = default_policy
|
||||
# check if there is already a queue_actor running
|
||||
# with policy as p.name for the case where
|
||||
# serve nursery exists: ray.experimental.get_actor(SERVE_NURSERY_NAME)
|
||||
# serve nursery exists: ray.util.get_actor(SERVE_NURSERY_NAME)
|
||||
for p in RoutePolicy:
|
||||
queue_actor_tag = "queue_actor::" + p.name
|
||||
if queue_actor_tag in self.actor_handle_cache:
|
||||
@@ -1,8 +1,8 @@
|
||||
from ray.experimental import serve
|
||||
from ray.experimental.serve.context import TaskContext
|
||||
from ray.experimental.serve.exceptions import RayServeException
|
||||
from ray.experimental.serve.constants import DEFAULT_HTTP_ADDRESS
|
||||
from ray.experimental.serve.request_params import RequestMetadata
|
||||
from ray import serve
|
||||
from ray.serve.context import TaskContext
|
||||
from ray.serve.exceptions import RayServeException
|
||||
from ray.serve.constants import DEFAULT_HTTP_ADDRESS
|
||||
from ray.serve.request_params import RequestMetadata
|
||||
|
||||
|
||||
class RayServeHandle:
|
||||
+3
-4
@@ -1,13 +1,12 @@
|
||||
import json
|
||||
import sqlite3
|
||||
from abc import ABC
|
||||
from typing import Union
|
||||
|
||||
from ray import cloudpickle as pickle
|
||||
|
||||
import ray.experimental.internal_kv as ray_kv
|
||||
from ray.experimental.serve.utils import logger
|
||||
from typing import Union
|
||||
from ray.experimental.serve.constants import NO_ROUTE_KEY
|
||||
from ray.serve.utils import logger
|
||||
from ray.serve.constants import NO_ROUTE_KEY
|
||||
|
||||
|
||||
class NamespacedKVStore(ABC):
|
||||
@@ -4,8 +4,8 @@ import itertools
|
||||
import numpy as np
|
||||
|
||||
import ray
|
||||
from ray.experimental.serve.queues import (CentralizedQueues)
|
||||
from ray.experimental.serve.utils import logger
|
||||
from ray.serve.queues import (CentralizedQueues)
|
||||
from ray.serve.utils import logger
|
||||
|
||||
|
||||
class RandomPolicyQueue(CentralizedQueues):
|
||||
@@ -13,7 +13,7 @@ import pickle
|
||||
import blist
|
||||
|
||||
import ray
|
||||
from ray.experimental.serve.utils import logger
|
||||
from ray.serve.utils import logger
|
||||
|
||||
|
||||
class Query:
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
import time
|
||||
from ray.experimental.serve.constants import DEFAULT_LATENCY_SLO_MS
|
||||
from ray.serve.constants import DEFAULT_LATENCY_SLO_MS
|
||||
|
||||
|
||||
class RequestMetadata:
|
||||
@@ -3,7 +3,7 @@ import json
|
||||
import click
|
||||
|
||||
import ray
|
||||
import ray.experimental.serve as serve
|
||||
import ray.serve as serve
|
||||
|
||||
|
||||
@click.group("serve", help="Commands working with ray serve")
|
||||
@@ -5,10 +5,10 @@ import uvicorn
|
||||
|
||||
import ray
|
||||
from ray.experimental.async_api import _async_init
|
||||
from ray.experimental.serve.constants import HTTP_ROUTER_CHECKER_INTERVAL_S
|
||||
from ray.experimental.serve.context import TaskContext
|
||||
from ray.experimental.serve.utils import BytesEncoder
|
||||
from ray.experimental.serve.request_params import RequestMetadata
|
||||
from ray.serve.constants import HTTP_ROUTER_CHECKER_INTERVAL_S
|
||||
from ray.serve.context import TaskContext
|
||||
from ray.serve.utils import BytesEncoder
|
||||
from ray.serve.request_params import RequestMetadata
|
||||
|
||||
from urllib.parse import parse_qs
|
||||
|
||||
@@ -62,7 +62,7 @@ class HTTPProxy:
|
||||
assert ray.is_initialized()
|
||||
|
||||
# Delay import due to GlobalState depends on HTTP actor
|
||||
from ray.experimental.serve.global_state import GlobalState
|
||||
from ray.serve.global_state import GlobalState
|
||||
self.serve_global_state = GlobalState()
|
||||
self.route_table_cache = dict()
|
||||
|
||||
@@ -2,11 +2,11 @@ import time
|
||||
import traceback
|
||||
|
||||
import ray
|
||||
from ray.experimental.serve import context as serve_context
|
||||
from ray.experimental.serve.context import FakeFlaskRequest
|
||||
from ray.serve import context as serve_context
|
||||
from ray.serve.context import FakeFlaskRequest
|
||||
from collections import defaultdict
|
||||
from ray.experimental.serve.utils import parse_request_item
|
||||
from ray.experimental.serve.exceptions import RayServeException
|
||||
from ray.serve.utils import parse_request_item
|
||||
from ray.serve.exceptions import RayServeException
|
||||
|
||||
|
||||
class TaskRunner:
|
||||
+1
-1
@@ -4,7 +4,7 @@ import tempfile
|
||||
import pytest
|
||||
|
||||
import ray
|
||||
from ray.experimental import serve
|
||||
from ray import serve
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
+3
-3
@@ -2,10 +2,10 @@ import time
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from ray.experimental import serve
|
||||
from ray.experimental.serve import BackendConfig
|
||||
from ray import serve
|
||||
from ray.serve import BackendConfig
|
||||
import ray
|
||||
from ray.experimental.serve.constants import NO_ROUTE_KEY
|
||||
from ray.serve.constants import NO_ROUTE_KEY
|
||||
|
||||
|
||||
def test_e2e(serve_instance):
|
||||
+1
-1
@@ -2,7 +2,7 @@ import numpy as np
|
||||
import pytest
|
||||
|
||||
import ray
|
||||
from ray.experimental.serve.metric import MetricMonitor
|
||||
from ray.serve.metric import MetricMonitor
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
+2
-2
@@ -3,7 +3,7 @@ import subprocess
|
||||
import tempfile
|
||||
|
||||
import ray
|
||||
from ray.experimental import serve
|
||||
from ray import serve
|
||||
|
||||
|
||||
def test_new_driver(serve_instance):
|
||||
@@ -11,7 +11,7 @@ def test_new_driver(serve_instance):
|
||||
import ray
|
||||
ray.init(address="auto")
|
||||
|
||||
from ray.experimental import serve
|
||||
from ray import serve
|
||||
serve.init()
|
||||
|
||||
@serve.route("/driver")
|
||||
+2
-2
@@ -3,10 +3,10 @@ import asyncio
|
||||
import pytest
|
||||
import ray
|
||||
|
||||
from ray.experimental.serve.policy import (
|
||||
from ray.serve.policy import (
|
||||
RandomPolicyQueue, RandomPolicyQueueActor, RoundRobinPolicyQueueActor,
|
||||
PowerOfTwoPolicyQueueActor, FixedPackingPolicyQueueActor)
|
||||
from ray.experimental.serve.request_params import RequestMetadata
|
||||
from ray.serve.request_params import RequestMetadata
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
+2
-2
@@ -1,8 +1,8 @@
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
from ray.experimental.serve.kv_store_service import (
|
||||
InMemoryKVStore, RayInternalKVStore, SQLiteKVStore)
|
||||
from ray.serve.kv_store_service import (InMemoryKVStore, RayInternalKVStore,
|
||||
SQLiteKVStore)
|
||||
|
||||
|
||||
def test_default_in_memory_kv():
|
||||
+5
-5
@@ -1,11 +1,11 @@
|
||||
import pytest
|
||||
|
||||
import ray
|
||||
import ray.experimental.serve.context as context
|
||||
from ray.experimental.serve.policy import RoundRobinPolicyQueueActor
|
||||
from ray.experimental.serve.task_runner import (
|
||||
RayServeMixin, TaskRunner, TaskRunnerActor, wrap_to_ray_error)
|
||||
from ray.experimental.serve.request_params import RequestMetadata
|
||||
import ray.serve.context as context
|
||||
from ray.serve.policy import RoundRobinPolicyQueueActor
|
||||
from ray.serve.task_runner import (RayServeMixin, TaskRunner, TaskRunnerActor,
|
||||
wrap_to_ray_error)
|
||||
from ray.serve.request_params import RequestMetadata
|
||||
|
||||
pytestmark = pytest.mark.asyncio
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
import json
|
||||
|
||||
from ray.experimental.serve.utils import BytesEncoder
|
||||
from ray.serve.utils import BytesEncoder
|
||||
|
||||
|
||||
def test_bytes_encoder():
|
||||
@@ -8,8 +8,8 @@ import os
|
||||
|
||||
import requests
|
||||
from pygments import formatters, highlight, lexers
|
||||
from ray.experimental.serve.context import FakeFlaskRequest, TaskContext
|
||||
from ray.experimental.serve.http_util import build_flask_request
|
||||
from ray.serve.context import FakeFlaskRequest, TaskContext
|
||||
from ray.serve.http_util import build_flask_request
|
||||
import itertools
|
||||
|
||||
|
||||
@@ -628,22 +628,22 @@ def test_register_and_get_named_actors(ray_start_regular):
|
||||
|
||||
f1 = Foo.remote()
|
||||
# Test saving f.
|
||||
ray.experimental.register_actor("f1", f1)
|
||||
ray.util.register_actor("f1", f1)
|
||||
# Test getting f.
|
||||
f2 = ray.experimental.get_actor("f1")
|
||||
f2 = ray.util.get_actor("f1")
|
||||
assert f1._actor_id == f2._actor_id
|
||||
|
||||
# Test same name register shall raise error.
|
||||
with pytest.raises(ValueError):
|
||||
ray.experimental.register_actor("f1", f2)
|
||||
ray.util.register_actor("f1", f2)
|
||||
|
||||
# Test register with wrong object type.
|
||||
with pytest.raises(TypeError):
|
||||
ray.experimental.register_actor("f3", 1)
|
||||
ray.util.register_actor("f3", 1)
|
||||
|
||||
# Test getting a nonexistent actor.
|
||||
with pytest.raises(ValueError):
|
||||
ray.experimental.get_actor("nonexistent")
|
||||
ray.util.get_actor("nonexistent")
|
||||
|
||||
# Test method
|
||||
assert ray.get(f1.method.remote()) == 1
|
||||
@@ -682,7 +682,7 @@ ray.get(actor.ping.remote())
|
||||
""".format(redis_address, actor_name)
|
||||
|
||||
run_string_as_driver(driver_script)
|
||||
detached_actor = ray.experimental.get_actor(actor_name)
|
||||
detached_actor = ray.util.get_actor(actor_name)
|
||||
assert ray.get(detached_actor.ping.remote()) == "pong"
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import time
|
||||
import pytest
|
||||
|
||||
import ray
|
||||
from ray.experimental import ActorPool
|
||||
from ray.util import ActorPool
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -2,7 +2,7 @@ import time
|
||||
from collections import Counter
|
||||
|
||||
import ray
|
||||
from ray.experimental.iter import from_items, from_iterators, from_range, \
|
||||
from ray.util.iter import from_items, from_iterators, from_range, \
|
||||
from_actors, ParallelIteratorWorker
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ from sklearn.linear_model import LogisticRegression
|
||||
from sklearn.neural_network import MLPClassifier
|
||||
from sklearn.model_selection import cross_val_score
|
||||
|
||||
from ray.experimental.joblib import register_ray
|
||||
from ray.util.joblib import register_ray
|
||||
import ray
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ def test_register_ray():
|
||||
|
||||
def test_ray_backend(shutdown_only):
|
||||
register_ray()
|
||||
from ray.experimental.joblib.ray_backend import RayBackend
|
||||
from ray.util.joblib.ray_backend import RayBackend
|
||||
with joblib.parallel_backend("ray"):
|
||||
assert type(joblib.parallel.get_active_backend()[0]) == RayBackend
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ class Counter:
|
||||
self.count += 1
|
||||
return self.count
|
||||
counter = Counter.remote()
|
||||
ray.experimental.register_actor("Counter", counter)
|
||||
ray.util.register_actor("Counter", counter)
|
||||
time.sleep(100)
|
||||
""".format(address)
|
||||
|
||||
@@ -199,7 +199,7 @@ import time
|
||||
ray.init(address="{}")
|
||||
while True:
|
||||
try:
|
||||
counter = ray.experimental.get_actor("Counter")
|
||||
counter = ray.util.get_actor("Counter")
|
||||
break
|
||||
except ValueError:
|
||||
time.sleep(1)
|
||||
|
||||
@@ -61,7 +61,6 @@ def setup_monitor(address):
|
||||
monitor.subscribe(ray.gcs_utils.XRAY_HEARTBEAT_BATCH_CHANNEL)
|
||||
monitor.subscribe(ray.gcs_utils.XRAY_JOB_CHANNEL) # TODO: Remove?
|
||||
monitor.update_raylet_map(_append_port=True)
|
||||
monitor._maybe_flush_gcs()
|
||||
return monitor
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
from .named_actors import get_actor, register_actor
|
||||
from .actor_pool import ActorPool
|
||||
from . import iter
|
||||
|
||||
__all__ = [
|
||||
"ActorPool",
|
||||
"iter",
|
||||
"get_actor",
|
||||
"register_actor",
|
||||
]
|
||||
|
||||
@@ -112,7 +112,7 @@ class ParallelIterator(Generic[T]):
|
||||
|
||||
Examples:
|
||||
>>> # Applying a function over items in parallel.
|
||||
>>> it = ray.experimental.iter.from_items([1, 2, 3], num_shards=2)
|
||||
>>> it = ray.util.iter.from_items([1, 2, 3], num_shards=2)
|
||||
... <__main__.ParallelIterator object>
|
||||
>>> it = it.for_each(lambda x: x * 2).gather_sync()
|
||||
... <__main__.LocalIterator object>
|
||||
@@ -120,13 +120,13 @@ class ParallelIterator(Generic[T]):
|
||||
... [2, 4, 6]
|
||||
|
||||
>>> # Creating from generators.
|
||||
>>> it = ray.experimental.iter.from_iterators([range(3), range(3)])
|
||||
>>> it = ray.util.iter.from_iterators([range(3), range(3)])
|
||||
... <__main__.ParallelIterator object>
|
||||
>>> print(list(it.gather_sync()))
|
||||
... [0, 0, 1, 1, 2, 2]
|
||||
|
||||
>>> # Accessing the individual shards of an iterator.
|
||||
>>> it = ray.experimental.iter.from_range(10, num_shards=2)
|
||||
>>> it = ray.util.iter.from_range(10, num_shards=2)
|
||||
... <__main__.ParallelIterator object>
|
||||
>>> it0 = it.get_shard(0)
|
||||
... <__main__.LocalIterator object>
|
||||
@@ -138,7 +138,7 @@ class ParallelIterator(Generic[T]):
|
||||
... [5, 6, 7, 8, 9]
|
||||
|
||||
>>> # Gathering results from actors synchronously in parallel.
|
||||
>>> it = ray.experimental.iter.from_actors(workers)
|
||||
>>> it = ray.util.iter.from_actors(workers)
|
||||
... <__main__.ParallelIterator object>
|
||||
>>> it = it.batch_across_shards()
|
||||
... <__main__.LocalIterator object>
|
||||
@@ -4,7 +4,7 @@ from joblib.parallel import register_parallel_backend
|
||||
def register_ray():
|
||||
""" Register Ray Backend to be called with parallel_backend("ray"). """
|
||||
try:
|
||||
from ray.experimental.joblib.ray_backend import RayBackend
|
||||
from ray.util.joblib.ray_backend import RayBackend
|
||||
register_parallel_backend("ray", RayBackend)
|
||||
except ImportError:
|
||||
msg = ("To use the ray backend you must install ray."
|
||||
+2
-2
@@ -2,7 +2,7 @@ from joblib._parallel_backends import MultiprocessingBackend
|
||||
from joblib.pool import PicklingPool
|
||||
import logging
|
||||
|
||||
from ray.experimental.multiprocessing.pool import Pool
|
||||
from ray.util.multiprocessing.pool import Pool
|
||||
import ray
|
||||
|
||||
RAY_ADDRESS_ENV = "RAY_ADDRESS"
|
||||
@@ -24,7 +24,7 @@ class RayBackend(MultiprocessingBackend):
|
||||
"""Make Ray Pool the father class of PicklingPool. PicklingPool is a
|
||||
father class that inherits Pool from multiprocessing.pool. The next
|
||||
line is a patch, which changes the inheritance of Pool to be from
|
||||
ray.experimental.multiprocessing.pool.
|
||||
ray.util.multiprocessing.pool.
|
||||
"""
|
||||
PicklingPool.__bases__ = (Pool, )
|
||||
"""Use all available resources when n_jobs == -1. Must set RAY_ADDRESS
|
||||
@@ -0,0 +1,4 @@
|
||||
from ray.util.sgd.pytorch import PyTorchTrainer
|
||||
from ray.util.sgd.tf import TFTrainer
|
||||
|
||||
__all__ = ["PyTorchTrainer", "TFTrainer"]
|
||||
+2
-2
@@ -7,8 +7,8 @@ PyTorchTrainable = None
|
||||
try:
|
||||
import torch # noqa: F401
|
||||
|
||||
from ray.experimental.sgd.pytorch.pytorch_trainer import (PyTorchTrainer,
|
||||
PyTorchTrainable)
|
||||
from ray.util.sgd.pytorch.pytorch_trainer import (PyTorchTrainer,
|
||||
PyTorchTrainable)
|
||||
|
||||
__all__ = ["PyTorchTrainer", "PyTorchTrainable"]
|
||||
except ImportError:
|
||||
+1
-1
@@ -7,7 +7,7 @@ import torch.distributed as dist
|
||||
import torch.utils.data
|
||||
from torch.nn.parallel import DistributedDataParallel
|
||||
|
||||
from ray.experimental.sgd.pytorch.pytorch_runner import PyTorchRunner
|
||||
from ray.util.sgd.pytorch.pytorch_runner import PyTorchRunner
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
+3
-3
@@ -8,9 +8,9 @@ import torchvision
|
||||
import torchvision.transforms as transforms
|
||||
|
||||
import ray
|
||||
from ray.experimental.sgd.pytorch import (PyTorchTrainer, PyTorchTrainable)
|
||||
from ray.experimental.sgd.pytorch.resnet import ResNet18
|
||||
from ray.experimental.sgd.pytorch.utils import TEST_MODE
|
||||
from ray.util.sgd.pytorch import (PyTorchTrainer, PyTorchTrainable)
|
||||
from ray.util.sgd.pytorch.resnet import ResNet18
|
||||
from ray.util.sgd.pytorch.utils import TEST_MODE
|
||||
|
||||
|
||||
def initialization_hook(runner):
|
||||
+3
-4
@@ -15,8 +15,8 @@ from torch.nn import functional as F
|
||||
from scipy.stats import entropy
|
||||
|
||||
import ray
|
||||
from ray.experimental.sgd import PyTorchTrainer
|
||||
from ray.experimental.sgd.pytorch.utils import TEST_MODE
|
||||
from ray.util.sgd import PyTorchTrainer
|
||||
from ray.util.sgd.pytorch.utils import TEST_MODE
|
||||
|
||||
# Training parameters
|
||||
TRAIN_BATCHES = 5
|
||||
@@ -256,8 +256,7 @@ if __name__ == "__main__":
|
||||
ray.init(address=args.address)
|
||||
|
||||
path = os.path.dirname(ray.__file__)
|
||||
model_path = os.path.join(
|
||||
path, "experimental/sgd/pytorch/examples/mnist_cnn.pt")
|
||||
model_path = os.path.join(path, "util/sgd/pytorch/examples/mnist_cnn.pt")
|
||||
# load the pretrained mnist classification model for inception_score
|
||||
|
||||
trainer = train_example(
|
||||
+1
-1
@@ -13,7 +13,7 @@ import numpy as np
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
from ray.experimental.sgd import PyTorchTrainer
|
||||
from ray.util.sgd import PyTorchTrainer
|
||||
|
||||
|
||||
class LinearDataset(torch.utils.data.Dataset):
|
||||
+1
-1
@@ -14,7 +14,7 @@ import torch.nn as nn
|
||||
|
||||
import ray
|
||||
from ray import tune
|
||||
from ray.experimental.sgd.pytorch.pytorch_trainer import PyTorchTrainable
|
||||
from ray.util.sgd.pytorch.pytorch_trainer import PyTorchTrainable
|
||||
|
||||
|
||||
class LinearDataset(torch.utils.data.Dataset):
|
||||
+2
-2
@@ -8,8 +8,8 @@ import torch.utils.data
|
||||
from torch.utils.data import Dataset
|
||||
|
||||
import ray
|
||||
from ray.experimental.sgd.pytorch import utils as pytorch_utils
|
||||
from ray.experimental.sgd import utils
|
||||
from ray.util.sgd.pytorch import utils as pytorch_utils
|
||||
from ray.util.sgd import utils
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
amp = None
|
||||
+4
-4
@@ -11,11 +11,11 @@ import ray
|
||||
|
||||
from ray.tune import Trainable
|
||||
from ray.tune.trial import Resources
|
||||
from ray.experimental.sgd.pytorch.distributed_pytorch_runner import (
|
||||
from ray.util.sgd.pytorch.distributed_pytorch_runner import (
|
||||
DistributedPyTorchRunner)
|
||||
from ray.experimental.sgd import utils
|
||||
from ray.experimental.sgd.pytorch.pytorch_runner import PyTorchRunner
|
||||
from ray.experimental.sgd.pytorch import utils as pytorch_utils
|
||||
from ray.util.sgd import utils
|
||||
from ray.util.sgd.pytorch.pytorch_runner import PyTorchRunner
|
||||
from ray.util.sgd.pytorch import utils as pytorch_utils
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
RESIZE_COOLDOWN_S = 10
|
||||
@@ -2,7 +2,7 @@ import collections
|
||||
import time
|
||||
import torch
|
||||
|
||||
from ray.experimental.sgd.utils import TimerStat
|
||||
from ray.util.sgd.utils import TimerStat
|
||||
|
||||
amp = None
|
||||
|
||||
+5
-5
@@ -11,12 +11,12 @@ import torch.distributed as dist
|
||||
import ray
|
||||
from ray import tune
|
||||
from ray.tests.conftest import ray_start_2_cpus # noqa: F401
|
||||
from ray.experimental.sgd.pytorch import PyTorchTrainer, PyTorchTrainable
|
||||
from ray.experimental.sgd.pytorch.utils import (train, BATCH_COUNT, TEST_MODE,
|
||||
SCHEDULER_STEP)
|
||||
from ray.experimental.sgd.utils import check_for_failure
|
||||
from ray.util.sgd.pytorch import PyTorchTrainer, PyTorchTrainable
|
||||
from ray.util.sgd.pytorch.utils import (train, BATCH_COUNT, TEST_MODE,
|
||||
SCHEDULER_STEP)
|
||||
from ray.util.sgd.utils import check_for_failure
|
||||
|
||||
from ray.experimental.sgd.pytorch.examples.train_example import (
|
||||
from ray.util.sgd.pytorch.examples.train_example import (
|
||||
model_creator, optimizer_creator, data_creator, LinearDataset)
|
||||
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ import torch.nn as nn
|
||||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from ray.experimental.sgd.pytorch.pytorch_runner import PyTorchRunner
|
||||
from ray.util.sgd.pytorch.pytorch_runner import PyTorchRunner
|
||||
|
||||
|
||||
class LinearDataset(torch.utils.data.Dataset):
|
||||
+3
-3
@@ -6,10 +6,10 @@ import shutil
|
||||
|
||||
from ray import tune
|
||||
from ray.tests.conftest import ray_start_2_cpus # noqa: F401
|
||||
from ray.experimental.sgd.tf import TFTrainer, TFTrainable
|
||||
from ray.util.sgd.tf import TFTrainer, TFTrainable
|
||||
|
||||
from ray.experimental.sgd.tf.examples.tensorflow_train_example import (
|
||||
simple_model, simple_dataset)
|
||||
from ray.util.sgd.tf.examples.tensorflow_train_example import (simple_model,
|
||||
simple_dataset)
|
||||
|
||||
SIMPLE_CONFIG = {
|
||||
"batch_size": 128,
|
||||
@@ -0,0 +1,3 @@
|
||||
from ray.util.sgd.tf.tf_trainer import (TFTrainer, TFTrainable)
|
||||
|
||||
__all__ = ["TFTrainer", "TFTrainable"]
|
||||
+1
-1
@@ -16,7 +16,7 @@ import os
|
||||
from filelock import FileLock
|
||||
|
||||
import ray
|
||||
from ray.experimental.sgd.tf.tf_trainer import TFTrainer
|
||||
from ray.util.sgd.tf.tf_trainer import TFTrainer
|
||||
|
||||
num_classes = 10
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import numpy as np
|
||||
|
||||
import ray
|
||||
from ray import tune
|
||||
from ray.experimental.sgd.tf.tf_trainer import TFTrainer, TFTrainable
|
||||
from ray.util.sgd.tf.tf_trainer import TFTrainer, TFTrainable
|
||||
|
||||
NUM_TRAIN_SAMPLES = 1000
|
||||
NUM_TEST_SAMPLES = 400
|
||||
@@ -5,7 +5,7 @@ import numpy as np
|
||||
|
||||
import ray
|
||||
import ray.services
|
||||
from ray.experimental.sgd import utils
|
||||
from ray.util.sgd import utils
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -7,7 +7,7 @@ import ray
|
||||
|
||||
from ray.tune import Trainable
|
||||
from ray.tune.resources import Resources
|
||||
from ray.experimental.sgd.tf.tf_runner import TFRunner
|
||||
from ray.util.sgd.tf.tf_runner import TFRunner
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
Reference in New Issue
Block a user