Skip to content

[serve] rename target num ongoing requests per replica - #43454

Merged
edoakes merged 1 commit into
ray-project:masterfrom
zcin:pr43454
Mar 4, 2024
Merged

edoakes merged 1 commit into
ray-project:masterfrom
zcin:pr43454

Conversation

@zcin

@zcin zcin commented Feb 27, 2024 •

Copy link
Copy Markdown
Contributor

[serve] rename target num ongoing requests per replica

Rename target_num_ongoing_requests_per_replica -> target_ongoing_requests.

Signed-off-by: Cindy Zhang [email protected]

@zcin
zcin force-pushed the pr43454 branch 9 times, most recently from 0c45fcd to eb2706c Compare February 29, 2024 04:31
@akshay-anyscale akshay-anyscale added release-blocker P0 Issue that blocks the release ray 2.10 labels Feb 29, 2024
@zcin
zcin force-pushed the pr43454 branch 3 times, most recently from 66ebe56 to 7fbcfd1 Compare March 1, 2024 01:52
@zcin
zcin marked this pull request as ready for review March 1, 2024 02:58
@zcin zcin assigned edoakes and zcin Mar 1, 2024

def test_replicas_delayed_startup(self):
@pytest.mark.parametrize(
"use_target_ongoing_requests,use_target_num_ongoing_requests_per_replica",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lol!

@@ -9,15 +9,22 @@


class TestCalculateDesiredNumReplicas:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AFAICT these are all unit tests, let's make sure there's at least one test that's a full e2e integration test setting the deprecated name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added setting deprecated name in e2e test test_autoscaling_policy::test_autoscaling_metrics!

# DEPRECATED: replaced by target_ongoing_requests
target_num_ongoing_requests_per_replica: PositiveFloat = Field(
default=1.0,
description="[DEPRECATED] Please use `target_ongoing_requests` instead.",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Let's make sure to add a warning for this as well please

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup sorry forgot about the warnings. Added warnings in api.py and deployment.py.

@zcin
zcin force-pushed the pr43454 branch 3 times, most recently from c42ca3e to ea8ebf6 Compare March 1, 2024 16:25

@GeneDer GeneDer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Some minor comments and suggestions, mostly looks good :)

Comment thread doc/source/serve/autoscaling-guide.md Resolved
Comment thread python/ray/serve/api.py Resolved
Comment thread python/ray/serve/config.py Resolved
Comment thread python/ray/serve/deployment.py Resolved
Comment thread python/ray/serve/tests/test_deploy_2.py Resolved
@zcin
zcin force-pushed the pr43454 branch 7 times, most recently from 50eab0c to 58a977e Compare March 1, 2024 21:17

@GeneDer GeneDer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM! Thanks for addressing all the comments!

@zcin

zcin commented Mar 1, 2024

Copy link
Copy Markdown
Contributor Author

@edoakes Tests are passing!

@edoakes

edoakes commented Mar 1, 2024

Copy link
Copy Markdown
Collaborator

@zcin need codeowner

@angelinalg angelinalg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just some nits.

Comment thread doc/source/serve/autoscaling-guide.md Resolved
Comment thread doc/source/serve/autoscaling-guide.md Resolved
Comment thread src/ray/protobuf/serve.proto Resolved
Comment thread src/ray/protobuf/serve.proto Resolved
Comment thread src/ray/protobuf/serve.proto Resolved
Rename `target_num_ongoing_requests_per_replica` -> `target_ongoing_requests`.

Signed-off-by: Cindy Zhang <[email protected]>
@edoakes
edoakes merged commit f0cf85b into ray-project:master Mar 4, 2024
abrarsheikh pushed a commit that referenced this pull request Nov 5, 2026
)

## Description

`AutoscalingConfig.target_ongoing_requests` is typed
`Optional[PositiveFloat]`, so `None` passes validation, both in
`@serve.deployment(autoscaling_config=...)` and as
`target_ongoing_requests: null` in a config file. The readers I checked
all expect a number: the default policy computes
`config.get_target_ongoing_requests() * num_running_replicas`
(`autoscaling_policy.py:337`), the config-file override path compares
`max_ongoing_requests < get_target_ongoing_requests()`
(`application_state.py:2087`), and the autoscaling state sets a gauge to
it (`autoscaling_state.py:662`). The first raises a `TypeError` on every
controller loop iteration.

The `Optional` type and the `None` mapping in `from_proto` date from the
rename in #43454, when `None` meant "fall back to
`target_num_ongoing_requests_per_replica`". #46392 removed that field
and the fallback, so `None` has had no meaning since.

The failure is not limited to the misconfigured app. I deployed a
healthy app, then an app with `target_ongoing_requests=None`, then a
second healthy app, on a local cluster on master. The controller logged
2,217 `TypeError: unsupported operand type(s) for *: 'NoneType' and
'int'` errors in about 4 minutes. The second healthy app never showed up
in the controller log, and `serve.status()` did not return before the
script was stopped after 4 minutes. This was one run, with the script
below. Why one deployment's policy exception stalls the whole loop is a
separate question that this PR does not change.

Behavior change: `@serve.deployment(autoscaling_config={...,
"target_ongoing_requests": None})` now raises `ValidationError` when the
class is decorated, instead of being accepted. A `null` in a config file
still passes schema parsing, because the schema keeps
`autoscaling_config` as a plain dict, and the app fails when it is
built, as it already did on master, now with a `ValidationError` from
`AutoscalingConfig`. One setup that works today would break: a
deployment defined in Python with a custom autoscaling policy that never
reads this field. The gauge skips `None`, and the `application_state.py`
comparison only runs for config files, so that setup runs with `None` on
master. A proto with 0.0, which a client cannot set on purpose because
the field must be positive, now gets the default of 2 instead of `None`.
A config object that already holds `None` and is restored by unpickling
is not revalidated (checked with `cloudpickle`), so it behaves as on
master.

Changes:
- `config.py`: type the field as `PositiveFloat`, so `None` is rejected
when an `AutoscalingConfig` is built (when the class is decorated, or
when a config-file app is built): `target_ongoing_requests: Input should
be a valid number [type=float_type, input_value=None,
input_type=NoneType]`.
- `_private/config.py`: `from_proto` replaced a 0.0
`target_ongoing_requests`, the proto3 default when the field is not set,
with `None`. It now drops the key so the field default (2) applies, the
same way the `request_router_config` fields above it are handled.

## Related issues

None. I searched issues and PRs for "target_ongoing_requests None",
"target_ongoing_requests null" and "autoscaling NoneType" and found no
report. Open PRs that edit `serve/config.py` or `_private/config.py`
(#67507, #67440, #66855, #66798, #66580, #66512) do not change this
field's type or its `from_proto` handling.

## Additional information

Tests added to `python/ray/serve/tests/unit/test_config.py`:
- `test_target_ongoing_requests_none_rejected`:
`AutoscalingConfig(target_ongoing_requests=None)`, and the same value
passed through `DeploymentConfig`, raise `ValidationError`.
- `test_target_ongoing_requests_proto_default`: a proto without the
field gives the default of 2, and a value of 7 survives a proto round
trip.

Commands, run locally on macOS arm64 with the nightly wheel,
`setup-dev.py` and Pydantic 2.14.2:
- `pytest python/ray/serve/tests/unit/test_config.py -k target_ongoing`:
3 passed (the two new tests and the existing
`test_target_ongoing_requests`). On master 541bd56: the two new tests
fail.
- `pytest` on `test_config.py`, `test_schema.py`,
`test_autoscaling_policy.py`, `test_application_state.py`,
`test_deployment_state.py` and `test_autoscaling_metrics_merge.py`, all
in `python/ray/serve/tests/unit/`: 751 passed, 12 skipped.
- `pre-commit run` on the changed files: passed.

<details><summary>Repro script (run on master)</summary>

```python
import time, ray
from ray import serve
from ray.serve.api import _run
ray.init(num_cpus=8, include_dashboard=False, log_to_driver=False)

@serve.deployment(ray_actor_options={"num_cpus": 0})
class Ok:
    def __call__(self): return "ok"

@serve.deployment(autoscaling_config={"min_replicas": 1, "max_replicas": 3, "target_ongoing_requests": None}, ray_actor_options={"num_cpus": 0})
class Bad:
    def __call__(self): return "bad"

serve.run(Ok.bind(), name="ok1", route_prefix="/ok1")
_run(Bad.bind(), name="bad", route_prefix="/bad", _blocking=False)
time.sleep(3)
_run(Ok.bind(), name="ok2", route_prefix="/ok2", _blocking=False)
time.sleep(15)
st = serve.status().applications
print({k: str(v.status) for k, v in st.items()})
serve.shutdown(); ray.shutdown()
```

</details>

Signed-off-by: William Guo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-blocker P0 Issue that blocks the release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants