[4/n] [Serve] Add Node Rank and Local Rank Support to Ray Serve Replica Ranks#58479
[4/n] [Serve] Add Node Rank and Local Rank Support to Ray Serve Replica Ranks#58479abrarsheikh merged 16 commits intomasterfrom
Conversation
Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: abrar <abrar@anyscale.com>
Signed-off-by: abrar <abrar@anyscale.com>
**Summary** Modified replica rank assignment to defer rank allocation until the replica is actually allocated, rather than assigning it during the startup call. This is necessary when we want to add node local rank in future, in order to support node rank and node local rank we need to know the node_id which is only known after replica is allocated. **Changes** - Changed `start()` method signature to accept `assign_rank_callback` instead of a pre-assigned `rank` parameter - Rank is now assigned after `_allocated_obj_ref` is resolved, ensuring the replica is allocated before rank assignment - Pass rank to `initialize_and_get_metadata()` method on the replica actor, allowing rank to be set during initialization - Updated `ReplicaBase.initialize()` to accept rank as a parameter and set it along with the internal replica context - Added `PENDING_INITIALIZATION` status check to handle cases where `_ready_obj_ref` is not yet set Next PR #58479 --------- Signed-off-by: abrar <abrar@anyscale.com>
…roject#58477) **Summary** Modified replica rank assignment to defer rank allocation until the replica is actually allocated, rather than assigning it during the startup call. This is necessary when we want to add node local rank in future, in order to support node rank and node local rank we need to know the node_id which is only known after replica is allocated. **Changes** - Changed `start()` method signature to accept `assign_rank_callback` instead of a pre-assigned `rank` parameter - Rank is now assigned after `_allocated_obj_ref` is resolved, ensuring the replica is allocated before rank assignment - Pass rank to `initialize_and_get_metadata()` method on the replica actor, allowing rank to be set during initialization - Updated `ReplicaBase.initialize()` to accept rank as a parameter and set it along with the internal replica context - Added `PENDING_INITIALIZATION` status check to handle cases where `_ready_obj_ref` is not yet set Next PR ray-project#58479 --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: Aydin Abiar <aydin@anyscale.com>
…roject#58477) **Summary** Modified replica rank assignment to defer rank allocation until the replica is actually allocated, rather than assigning it during the startup call. This is necessary when we want to add node local rank in future, in order to support node rank and node local rank we need to know the node_id which is only known after replica is allocated. **Changes** - Changed `start()` method signature to accept `assign_rank_callback` instead of a pre-assigned `rank` parameter - Rank is now assigned after `_allocated_obj_ref` is resolved, ensuring the replica is allocated before rank assignment - Pass rank to `initialize_and_get_metadata()` method on the replica actor, allowing rank to be set during initialization - Updated `ReplicaBase.initialize()` to accept rank as a parameter and set it along with the internal replica context - Added `PENDING_INITIALIZATION` status check to handle cases where `_ready_obj_ref` is not yet set Next PR ray-project#58479 --------- Signed-off-by: abrar <abrar@anyscale.com>
…roject#58477) **Summary** Modified replica rank assignment to defer rank allocation until the replica is actually allocated, rather than assigning it during the startup call. This is necessary when we want to add node local rank in future, in order to support node rank and node local rank we need to know the node_id which is only known after replica is allocated. **Changes** - Changed `start()` method signature to accept `assign_rank_callback` instead of a pre-assigned `rank` parameter - Rank is now assigned after `_allocated_obj_ref` is resolved, ensuring the replica is allocated before rank assignment - Pass rank to `initialize_and_get_metadata()` method on the replica actor, allowing rank to be set during initialization - Updated `ReplicaBase.initialize()` to accept rank as a parameter and set it along with the internal replica context - Added `PENDING_INITIALIZATION` status check to handle cases where `_ready_obj_ref` is not yet set Next PR ray-project#58479 --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: YK <1811651+ykdojo@users.noreply.github.com>
…roject#58477) **Summary** Modified replica rank assignment to defer rank allocation until the replica is actually allocated, rather than assigning it during the startup call. This is necessary when we want to add node local rank in future, in order to support node rank and node local rank we need to know the node_id which is only known after replica is allocated. **Changes** - Changed `start()` method signature to accept `assign_rank_callback` instead of a pre-assigned `rank` parameter - Rank is now assigned after `_allocated_obj_ref` is resolved, ensuring the replica is allocated before rank assignment - Pass rank to `initialize_and_get_metadata()` method on the replica actor, allowing rank to be set during initialization - Updated `ReplicaBase.initialize()` to accept rank as a parameter and set it along with the internal replica context - Added `PENDING_INITIALIZATION` status check to handle cases where `_ready_obj_ref` is not yet set Next PR ray-project#58479 --------- Signed-off-by: abrar <abrar@anyscale.com>
eicherseiji
left a comment
There was a problem hiding this comment.
LGTM. Thanks @abrarsheikh!
|
|
||
| return self._execute_with_error_handling( | ||
| _get_replica_rank_impl, ReplicaRank(rank=0, node_rank=-1, local_rank=-1) | ||
| _get_replica_rank_impl, ReplicaRank(rank=0, node_rank=0, local_rank=0) |
There was a problem hiding this comment.
For my information, why change the default from -1 -> 0?
There was a problem hiding this comment.
-1 was a placeholder, for a previous stacked diff.
Signed-off-by: abrar <abrar@anyscale.com>
| self._local_rank_managers[node_id].recover_rank(replica_id, rank.local_rank) | ||
|
|
||
| # Track the replica-to-node mapping | ||
| self._replica_to_node[replica_id] = node_id |
There was a problem hiding this comment.
Bug: Inconsistent state on partial failure in recover_rank
The order of operations in _recover_rank_impl is inconsistent with _assign_rank_impl. In _assign_rank_impl, _replica_to_node[replica_id] = node_id is set first (before any rank assignments), but in _recover_rank_impl, it's set last (after all rank recoveries). When _fail_on_rank_error=False and an error occurs after recovering the global rank but before setting _replica_to_node, the system ends up in an inconsistent state where _replica_rank_manager has the replica's global rank but _replica_to_node doesn't have the mapping. This causes has_replica_rank() to return False even though ranks are partially assigned, potentially leading to duplicate assignment errors on retry.
Additional Locations (1)
…roject#58477) **Summary** Modified replica rank assignment to defer rank allocation until the replica is actually allocated, rather than assigning it during the startup call. This is necessary when we want to add node local rank in future, in order to support node rank and node local rank we need to know the node_id which is only known after replica is allocated. **Changes** - Changed `start()` method signature to accept `assign_rank_callback` instead of a pre-assigned `rank` parameter - Rank is now assigned after `_allocated_obj_ref` is resolved, ensuring the replica is allocated before rank assignment - Pass rank to `initialize_and_get_metadata()` method on the replica actor, allowing rank to be set during initialization - Updated `ReplicaBase.initialize()` to accept rank as a parameter and set it along with the internal replica context - Added `PENDING_INITIALIZATION` status check to handle cases where `_ready_obj_ref` is not yet set Next PR ray-project#58479 --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: peterxcli <peterxcli@gmail.com>
…ca Ranks (ray-project#58479) ### Summary This PR extends Ray Serve's replica rank system to track **node rank** and **local rank** in addition to the existing global rank, enabling better distributed serving coordination and multi-node deployment awareness. ### Changes **Core Implementation (`deployment_state.py`)** - Extended `DeploymentRankManager` to maintain three levels of rank tracking: - **Global rank**: Replica-level rank across all nodes (0 to N-1) - **Node rank**: Index assigned to each node (0 to M-1) - **Local rank**: Replica's rank within its node (0 to K-1 per node) - Modified `assign_rank()` to return `ReplicaRank` objects containing all three rank types - Added node rank manager and per-node local rank managers to track replica placement - Updated `get_replica_ranks_mapping()` to return `Dict[str, ReplicaRank]` instead of `Dict[str, int]` ### Backward Compatibility All existing functionality is preserved. The global rank behavior remains unchanged, with node and local ranks added as additional fields in the `ReplicaRank` object. --- --------- Signed-off-by: abrar <abrar@anyscale.com> Signed-off-by: peterxcli <peterxcli@gmail.com>
Summary
This PR extends Ray Serve's replica rank system to track node rank and local rank in addition to the existing global rank, enabling better distributed serving coordination and multi-node deployment awareness.
Changes
Core Implementation (
deployment_state.py)DeploymentRankManagerto maintain three levels of rank tracking:assign_rank()to returnReplicaRankobjects containing all three rank typesget_replica_ranks_mapping()to returnDict[str, ReplicaRank]instead ofDict[str, int]Backward Compatibility
All existing functionality is preserved. The global rank behavior remains unchanged, with node and local ranks added as additional fields in the
ReplicaRankobject.