Repository navigation
[serve] Reject target_ongoing_requests=None in AutoscalingConfig - #67675
Conversation
The field was typed Optional[PositiveFloat], so None passed validation, and the default autoscaling policy then raised a TypeError on every controller loop iteration, which also stalled other applications. Type it as PositiveFloat so None is rejected when the config is parsed, and drop a 0.0 proto value in DeploymentConfig.from_proto so the default applies instead of None, as for request_router_config. Signed-off-by: William Guo <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request updates target_ongoing_requests in AutoscalingConfig from Optional[PositiveFloat] to PositiveFloat to prevent None values from causing a TypeError in the autoscaling loop. It also adjusts the proto parsing logic to pop the field when it is unset and adds unit tests to verify validation and default fallback behaviors. There are no review comments, so I have no feedback to provide.
|
Thanks @wguo7. Reproduced on master, and this fixes it for
Agreed the stall is a separate problem. A custom autoscaling policy that raises still blocks apps deployed after it. |
|
Thanks for reproducing it. You are right about config files: the schema keeps |
Jadiouo
left a comment
There was a problem hiding this comment.
Verified 85c4254 by applying the diff to the Serve code of a Ray nightly (master's Serve doesn't import against the nightly wheel here).
- On base,
@serve.deployment(autoscaling_config={"target_ongoing_requests": None, ...})deploys, and the controller then loggedTypeError: unsupported operand type(s) for *: 'NoneType' and 'int'fromautoscaling_policy.py793 times in about 20s. With the PR the decorator fails right away withValidationError ... Input should be a valid number, and so doesAutoscalingConfig(target_ongoing_requests=None). - The default (2) and values like 0.5 are unchanged.
- As noted in the description,
ServeDeploySchemastill parsesnull, and building theAutoscalingConfigfrom it then fails. test_config.py: 91 passed; the two new tests fail on base.
LGTM.
Description
AutoscalingConfig.target_ongoing_requestsis typedOptional[PositiveFloat], soNonepasses validation, both in@serve.deployment(autoscaling_config=...)and astarget_ongoing_requests: nullin a config file. The readers I checked all expect a number: the default policy computesconfig.get_target_ongoing_requests() * num_running_replicas(autoscaling_policy.py:337), the config-file override path comparesmax_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 aTypeErroron every controller loop iteration.The
Optionaltype and theNonemapping infrom_protodate from the rename in #43454, whenNonemeant "fall back totarget_num_ongoing_requests_per_replica". #46392 removed that field and the fallback, soNonehas 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,217TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'errors in about 4 minutes. The second healthy app never showed up in the controller log, andserve.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 raisesValidationErrorwhen the class is decorated, instead of being accepted. Anullin a config file still passes schema parsing, because the schema keepsautoscaling_configas a plain dict, and the app fails when it is built, as it already did on master, now with aValidationErrorfromAutoscalingConfig. One setup that works today would break: a deployment defined in Python with a custom autoscaling policy that never reads this field. The gauge skipsNone, and theapplication_state.pycomparison only runs for config files, so that setup runs withNoneon 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 ofNone. A config object that already holdsNoneand is restored by unpickling is not revalidated (checked withcloudpickle), so it behaves as on master.Changes:
config.py: type the field asPositiveFloat, soNoneis rejected when anAutoscalingConfigis 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_protoreplaced a 0.0target_ongoing_requests, the proto3 default when the field is not set, withNone. It now drops the key so the field default (2) applies, the same way therequest_router_configfields 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.pyor_private/config.py(#67507, #67440, #66855, #66798, #66580, #66512) do not change this field's type or itsfrom_protohandling.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 throughDeploymentConfig, raiseValidationError.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.pyand Pydantic 2.14.2:pytest python/ray/serve/tests/unit/test_config.py -k target_ongoing: 3 passed (the two new tests and the existingtest_target_ongoing_requests). On master 541bd56: the two new tests fail.pytestontest_config.py,test_schema.py,test_autoscaling_policy.py,test_application_state.py,test_deployment_state.pyandtest_autoscaling_metrics_merge.py, all inpython/ray/serve/tests/unit/: 751 passed, 12 skipped.pre-commit runon the changed files: passed.Repro script (run on master)