mirror of
https://github.com/vale981/ray
synced 2025-03-06 10:31:39 -05:00
[serve] Avoid exporting actor class for every replica (#15788)
This commit is contained in:
parent
b3428bd09e
commit
cd32a92edc
4 changed files with 12 additions and 11 deletions
|
@ -99,7 +99,7 @@ class ActorReplicaWrapper:
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.debug("Starting replica '{}' for backend '{}'.".format(
|
logger.debug("Starting replica '{}' for backend '{}'.".format(
|
||||||
self._replica_tag, self._backend_tag))
|
self._replica_tag, self._backend_tag))
|
||||||
self._actor_handle = ray.remote(backend_info.worker_class).options(
|
self._actor_handle = backend_info.actor_def.options(
|
||||||
name=self._actor_name,
|
name=self._actor_name,
|
||||||
lifetime="detached" if self._detached else None,
|
lifetime="detached" if self._detached else None,
|
||||||
placement_group=self._placement_group,
|
placement_group=self._placement_group,
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Dict, List, Optional
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
|
from ray.actor import ActorClass
|
||||||
from ray.serve.config import BackendConfig, ReplicaConfig
|
from ray.serve.config import BackendConfig, ReplicaConfig
|
||||||
|
|
||||||
BackendTag = str
|
BackendTag = str
|
||||||
|
@ -24,9 +25,7 @@ class EndpointInfo:
|
||||||
|
|
||||||
|
|
||||||
class BackendInfo(BaseModel):
|
class BackendInfo(BaseModel):
|
||||||
# TODO(architkulkarni): Add type hint for worker_class after upgrading
|
actor_def: Optional[ActorClass]
|
||||||
# cloudpickle and adding types to RayServeWrappedReplica
|
|
||||||
worker_class: Any
|
|
||||||
version: Optional[str]
|
version: Optional[str]
|
||||||
backend_config: BackendConfig
|
backend_config: BackendConfig
|
||||||
replica_config: ReplicaConfig
|
replica_config: ReplicaConfig
|
||||||
|
|
|
@ -212,8 +212,9 @@ class ServeController:
|
||||||
"""Register a new backend under the specified tag."""
|
"""Register a new backend under the specified tag."""
|
||||||
async with self.write_lock:
|
async with self.write_lock:
|
||||||
backend_info = BackendInfo(
|
backend_info = BackendInfo(
|
||||||
worker_class=create_backend_replica(
|
actor_def=ray.remote(
|
||||||
backend_tag, replica_config.serialized_backend_def),
|
create_backend_replica(
|
||||||
|
backend_tag, replica_config.serialized_backend_def)),
|
||||||
version=RESERVED_VERSION_TAG,
|
version=RESERVED_VERSION_TAG,
|
||||||
backend_config=backend_config,
|
backend_config=backend_config,
|
||||||
replica_config=replica_config)
|
replica_config=replica_config)
|
||||||
|
@ -244,7 +245,7 @@ class ServeController:
|
||||||
raise ValueError(f"Backend {backend_tag} is not registered.")
|
raise ValueError(f"Backend {backend_tag} is not registered.")
|
||||||
|
|
||||||
backend_info = BackendInfo(
|
backend_info = BackendInfo(
|
||||||
worker_class=existing_info.worker_class,
|
actor_def=existing_info.actor_def,
|
||||||
version=existing_info.version,
|
version=existing_info.version,
|
||||||
backend_config=existing_info.backend_config.copy(
|
backend_config=existing_info.backend_config.copy(
|
||||||
update=config_options.dict(exclude_unset=True)),
|
update=config_options.dict(exclude_unset=True)),
|
||||||
|
@ -279,8 +280,9 @@ class ServeController:
|
||||||
|
|
||||||
async with self.write_lock:
|
async with self.write_lock:
|
||||||
backend_info = BackendInfo(
|
backend_info = BackendInfo(
|
||||||
worker_class=create_backend_replica(
|
actor_def=ray.remote(
|
||||||
name, replica_config.serialized_backend_def),
|
create_backend_replica(
|
||||||
|
name, replica_config.serialized_backend_def)),
|
||||||
version=version,
|
version=version,
|
||||||
backend_config=backend_config,
|
backend_config=backend_config,
|
||||||
replica_config=replica_config)
|
replica_config=replica_config)
|
||||||
|
|
|
@ -95,7 +95,7 @@ def backend_info(version: Optional[str] = None,
|
||||||
num_replicas: Optional[int] = 1,
|
num_replicas: Optional[int] = 1,
|
||||||
**config_opts) -> BackendInfo:
|
**config_opts) -> BackendInfo:
|
||||||
return BackendInfo(
|
return BackendInfo(
|
||||||
worker_class=None,
|
actor_def=None,
|
||||||
version=version,
|
version=version,
|
||||||
backend_config=BackendConfig(num_replicas=num_replicas, **config_opts),
|
backend_config=BackendConfig(num_replicas=num_replicas, **config_opts),
|
||||||
replica_config=ReplicaConfig(lambda x: x))
|
replica_config=ReplicaConfig(lambda x: x))
|
||||||
|
|
Loading…
Add table
Reference in a new issue