Skip to content

[Serve] Replica ranks not reset on redeployment without shutdown #57048

@kouroshHakha

Description

@kouroshHakha

Problem

When running a Ray Serve deployment for the first time, ranks are correctly assigned starting from 0 ... N-1. However, if we redeploy the application without calling serve shutdown -y, the constructor of the replicas sees ranks N ... 2N-1. After construction of the classes, the ranks are reassigned to 0 ... N-1. This behavior is problematic because it requires always calling serve shutdown -y between deployment runs.

Steps to Reproduce

  1. Create a file test_rank_update.py:
# test_rank_update.py
from ray import serve


@serve.deployment(num_replicas=2)
class DPServerSketch:
    
    def __init__(self):
        ctx = serve.get_replica_context()
        print(f"rank: {ctx.rank}")

    def __call__(self):
        return "pong"
    
app = DPServerSketch.bind()

serve.run(app, blocking=True)
  1. Run serve run test_rank_update.py
  2. Exit the process
  3. Run serve run test_rank_update.py again

Expected behavior: Ranks print as 0, 1 both times

Actual behavior: First run prints ranks 0, 1. Second run prints ranks 2, 3.

Desired Behavior

During redeployment, ranks should be reset to start from 0 as if serve shutdown -y had been called.

Note: Attempted to handle this through the reconfigure implementation, but reconfigure does not appear to execute upon rank change events.

Metadata

Metadata

Assignees

Labels

bugSomething that is supposed to be working; but isn'tserveRay Serve Related Issuestability

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions