Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 39 additions & 2 deletions tensorrt_llm/_torch/pyexecutor/scheduler/adp_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,42 @@ def _record_target_rank(self, conv_id: str, rank: int) -> None:
while len(self._conv_to_rank) > self._max_sessions:
self._conv_to_rank.popitem(last=False)

def _assign_new_conversation_explicit_dp_ranks(
self,
requests: List["RequestQueueItem"],
all_ranks_new_requests: Dict[int, List["RequestQueueItem"]],
all_ranks_num_active_requests: List[int],
max_num_active_requests: int,
) -> List["RequestQueueItem"]:
"""Place explicit first turns and establish their affinity binding.

Once a conversation is bound, its recorded rank takes precedence over
later explicit rank hints. Requests whose explicit target is full remain
eligible for the normal affinity/load-balanced path below.
"""
remaining: List["RequestQueueItem"] = []
for req_item in requests:
conv_id = self._conversation_id(req_item)
Comment thread
krishung5 marked this conversation as resolved.
Resolved
if conv_id is not None and conv_id in self._conv_to_rank:
remaining.append(req_item)
continue

scheduling_params = getattr(req_item.request, "py_scheduling_params", None)
target_dp_rank = (
scheduling_params.attention_dp_rank if scheduling_params is not None else None
)
if (
target_dp_rank is not None
and all_ranks_num_active_requests[target_dp_rank] < max_num_active_requests
):
all_ranks_num_active_requests[target_dp_rank] += 1
all_ranks_new_requests[target_dp_rank].append(req_item)
if conv_id is not None:
self._record_target_rank(conv_id, target_dp_rank)
else:
remaining.append(req_item)
return remaining

def route_requests(
self,
all_rank_states: list[RankState],
Expand All @@ -877,8 +913,9 @@ def get_relax_value(req_item):

sorted_requests = sorted(new_requests, key=get_relax_value)

# 1) Honour an explicit attention_dp_rank first (strict placement).
remaining_unscheduled = self._assign_explicit_dp_ranks(
# 1) Honour an explicit attention_dp_rank for a new conversation and
# record that placement. Existing conversations keep their binding.
remaining_unscheduled = self._assign_new_conversation_explicit_dp_ranks(
sorted_requests,
all_ranks_new_requests,
all_ranks_num_active_requests,
Expand Down
20 changes: 16 additions & 4 deletions tests/unittest/_torch/executor/test_adp_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -1207,11 +1207,23 @@ def test_lru_eviction_bounds_map(self):
assert len(router._conv_to_rank) == 2
assert set(router._conv_to_rank) == {"c3", "c4"}

def test_explicit_target_dp_rank_respected(self):
def test_explicit_target_dp_rank_establishes_binding(self):
router = self._router(tp_size=4)
item = _make_conv_request_item(1, "A", target_dp_rank=2, attention_dp_relax=False)
pos = self._route(router, self._states(4), [item])
assert pos[1] == 2
first = _make_conv_request_item(1, "A", target_dp_rank=2, attention_dp_relax=False)
assert self._route(router, self._states(4), [first])[1] == 2
assert router._conv_to_rank["A"] == 2

second = _make_conv_request_item(2, "A")
assert self._route(router, self._states(4), [second])[2] == 2

def test_existing_binding_wins_over_later_explicit_target(self):
router = self._router(tp_size=4)
first = _make_conv_request_item(1, "A", target_dp_rank=2, attention_dp_relax=False)
self._route(router, self._states(4), [first])

second = _make_conv_request_item(2, "A", target_dp_rank=1, attention_dp_relax=False)
assert self._route(router, self._states(4), [second])[2] == 2
assert router._conv_to_rank["A"] == 2

def test_sticky_overflow_keeps_mapping(self):
"""When the home rank is saturated at the HARD cap (max_num_active_requests),
Expand Down
Loading