Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[serve] Implement set_options #23265

Merged
merged 4 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions python/ray/serve/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,9 @@ def options(
if version is None:
version = self._version

if prev_version is None:
prev_version = self._prev_version

if init_args is None:
init_args = self._init_args

Expand Down Expand Up @@ -1257,6 +1260,72 @@ def options(
_internal=True,
)

@PublicAPI
shrekris-anyscale marked this conversation as resolved.
Show resolved Hide resolved
def set_options(
self,
func_or_class: Optional[Callable] = None,
name: Optional[str] = None,
version: Optional[str] = None,
prev_version: Optional[str] = None,
init_args: Optional[Tuple[Any]] = None,
init_kwargs: Optional[Dict[Any, Any]] = None,
route_prefix: Union[str, None, DEFAULT] = DEFAULT.VALUE,
num_replicas: Optional[int] = None,
ray_actor_options: Optional[Dict] = None,
user_config: Optional[Any] = None,
max_concurrent_queries: Optional[int] = None,
_autoscaling_config: Optional[Union[Dict, AutoscalingConfig]] = None,
_graceful_shutdown_wait_loop_s: Optional[float] = None,
_graceful_shutdown_timeout_s: Optional[float] = None,
_health_check_period_s: Optional[float] = None,
_health_check_timeout_s: Optional[float] = None,
) -> None:
"""Overwrite this deployment's options. Mutates the deployment.

Only those options passed in will be updated, all others will remain
unchanged.
"""

validated = self.options(
func_or_class=func_or_class,
name=name,
version=version,
prev_version=prev_version,
init_args=init_args,
init_kwargs=init_kwargs,
route_prefix=route_prefix,
num_replicas=num_replicas,
ray_actor_options=ray_actor_options,
user_config=user_config,
max_concurrent_queries=max_concurrent_queries,
_autoscaling_config=_autoscaling_config,
_graceful_shutdown_wait_loop_s=_graceful_shutdown_wait_loop_s,
_graceful_shutdown_timeout_s=_graceful_shutdown_timeout_s,
_health_check_period_s=_health_check_period_s,
_health_check_timeout_s=_health_check_timeout_s,
)

self._config.num_replicas = validated._config.num_replicas
self._config.user_config = validated._config.user_config
self._config.max_concurrent_queries = validated._config.max_concurrent_queries
self._func_or_class = validated._func_or_class
self._name = validated._name
self._version = validated._version
self._prev_version = validated._prev_version
self._init_args = validated._init_args
self._init_kwargs = validated._init_kwargs
self._route_prefix = validated._route_prefix
self._ray_actor_options = validated._ray_actor_options
self._config.autoscaling_config = validated._config.autoscaling_config
self._config.graceful_shutdown_wait_loop_s = (
validated._config.graceful_shutdown_wait_loop_s
)
self._config.graceful_shutdown_timeout_s = (
validated._config.graceful_shutdown_timeout_s
)
self._config.health_check_period_s = validated._config.health_check_period_s
self._config.health_check_timeout_s = validated._config.health_check_timeout_s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just self._config = validated._config?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the rest of stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea– I changed it.


def __eq__(self, other):
return all(
[
Expand Down
38 changes: 38 additions & 0 deletions python/ray/serve/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,44 @@ def __del__(self):
B.delete()


class TestSetOptions:
def test_set_options_basic(self):
@serve.deployment(
num_replicas=4,
max_concurrent_queries=3,
prev_version="abcd",
ray_actor_options={"num_cpus": 2},
_health_check_timeout_s=17,
)
def f():
pass

f.set_options(
num_replicas=9,
prev_version="abcd",
version="efgh",
ray_actor_options={"num_gpus": 3},
)

assert f.num_replicas == 9
assert f.max_concurrent_queries == 3
assert f.prev_version == "abcd"
assert f.version == "efgh"
assert f.ray_actor_options == {"num_gpus": 3}
assert f._config.health_check_timeout_s == 17

def test_set_options_validation(self):
@serve.deployment
def f():
pass

with pytest.raises(TypeError):
f.set_options(init_args=-4)

with pytest.raises(ValueError):
f.set_options(max_concurrent_queries=-4)


if __name__ == "__main__":
import sys

Expand Down