Repository navigation
Conversation
Apply target_capacity to the number of gangs rather than to the raw replica count when gang scheduling is enabled. Capacity-adjusting the replica count directly can produce a value that isn't a multiple of gang_size, which the gang scheduler rejects, leaving the deployment in DEPLOY_FAILED or flapping. Two paths are fixed: - Autoscaling bounds are capacity-adjusted in gang units, so apply_bounds() can no longer clip a gang-aligned decision back to an unaligned count. - Non-autoscaling targets are capacity-adjusted in gang units before the replica delta is computed. Scale-to-zero is preserved, and behavior is unchanged when gang scheduling is disabled or target_capacity is None. Signed-off-by: YidaWeng <[email protected]>
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit ebdc1d3. Configure here.
Contributor
|
Check out #67507 (review). |
An unaligned min_replicas or initial_replicas (including the default min_replicas=1, which is explicitly allowed with gang scheduling) was floored to zero gangs, and the capacity-up lower bound could sit below the target that register() rounds up to. Lower bounds now round the gang count up, upper bounds still round down, and a positive replica count always maps to at least one gang. Only target_capacity=0 or num_replicas=0 yield zero, preserving scale-to-zero. Signed-off-by: YidaWeng <[email protected]>
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Why are these changes needed?
With gang scheduling,
GangSchedulingAutoscalingPolicyrounds autoscaling decisions up to whole gangs, buttarget_capacityis still applied to the raw replica counts:AutoscalingState.apply_bounds()clamps to bounds computed frommin_replicas/max_replicas, so it can clip an aligned decision back to an unaligned count. E.g.max_replicas=8,gang_size=4,target_capacity=75-> upper bound 6.num_replicas=8,gang_size=4,target_capacity=30-> 2.The gang scheduler then rejects the delta (
num_replicas_to_add N is not divisible by gang_size M), and the deployment ends up inDEPLOY_FAILEDor flaps.What is the change?
Apply
target_capacityin gang units instead of replica units:This reuses the existing
ROUND_HALF_UP+max(1, ...)semantics, keeps the result aligned by construction, preserves scale-to-zero (0 capacity or 0 replicas still yields 0), and is invariant to whether bounds are eventually expressed in replicas or in gangs (relevant to the API discussion in #67507).get_capacity_adjusted_gang_replicas()in_private/utils.py;get_capacity_adjusted_num_replicas()is unchanged.DeploymentAutoscalingStateuses it for the capacity-adjusted lower/upper bounds, and rounds a configuredinitial_replicas(or a target carried over from a pre-gang config) up to a whole gang.DeploymentStateuses it for the target replica count.target_capacityisNone/100.For unaligned legacy values, lower bounds round the gang count up (so
initial_replicas=6, gang_size=4yields 8, matching the registered target) and upper bounds round down (so a bound is never exceeded). A positive replica count always maps to at least one gang, so the defaultmin_replicas=1gives 4 rather than 0; onlytarget_capacity=0ornum_replicas=0yield 0.Note on the rounding choice:
8 replicas / gang_size=4 / target_capacity=75is2 gangs * 75% = 1.5 -> 2 gangs(8 replicas, half-up) rather than 6 or 4. This matches the existing half-up behavior ofget_capacity_adjusted_num_replicas. If maintainers prefer to never exceed the capacity target, switching to floor-in-gang-units is a one-line change (still floored at one gang for non-zero capacity).Related issue number
Part of #67494. This is the runtime half that #67507 leaves as a follow-up; it doesn't depend on that PR's API validation and touches different files.
Tests
python/ray/serve/tests/unit/test_autoscaling_policy.py- 62 passedpython/ray/serve/tests/unit/test_deployment_state.py -k TargetCapacity- 47 passedpython/ray/serve/tests/test_gang_scheduling.py -k TestGangTargetCapacity- 2 passedThe two new gang integration tests fail on master without the fix (verified by reverting the
_private/changes while keeping the tests) and pass with it. Unit tests run in a Linux container with the repo'spython/ray/serveoverlaid on a nightly Ray install;ruffandblack==22.10.0pass.Review follow-up
18a66d0addresses the Cursor Bugbot finding about floored lower bounds: lower bounds now round gangs up (round_gangs_up=True) and always map a positive replica count to at least one gang, so an unalignedmin_replicas/initial_replicascan no longer fall to zero or below the registered target. Added regression tests for both cases.