-
Notifications
You must be signed in to change notification settings - Fork 7.4k
[Serve] Replica ranks not reset on redeployment without shutdown #57048
Description
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
- 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)- Run
serve run test_rank_update.py - Exit the process
- Run
serve run test_rank_update.pyagain
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.