Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,29 @@ def _compute_port_offset(self) -> int:
Uses data_parallel_rank if DP case, otherwise falls back to
the replica rank assigned by Ray Serve (TP/PP case).

For TP/PP cases, multiply by tensor_parallel_size to reserve
sufficient port space, since each TP worker adds its tp_rank
(0, 1, ..., tp_size-1) to the base port at bind time.

Returns:
Non-negative integer offset to add to a base port.
"""
tp_size = self.llm_config.engine_kwargs.get("tensor_parallel_size", 1)

# Prefer explicit DP rank when available
dp_rank = self.llm_config.engine_kwargs.get("data_parallel_rank")
if isinstance(dp_rank, int) and dp_rank >= 0:
# vLLM already accounts for TP spacing in DP offset calculation
# (data_parallel_rank × tp_size), don't multiply here
return dp_rank

# Fall back to Serve replica rank for TP/PP cases
try:
rc = serve.get_replica_context()
if rc and hasattr(rc, "rank"):
return rc.rank
# Multiply by tp_size to reserve ports for all TP workers
# Each TP worker will add its tp_rank (0, 1, ..., tp_size-1)
return rc.rank * tp_size
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to offset by tp * pp . Effectively you should use llm_config.get_engine_config().num_devices

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

except Exception:
# Best-effort fallback; avoid introducing failures in setup paths
pass
Expand Down