Skip to content

[None][fix] Bind explicit DP rank for new conversations - #16815

Merged
pcastonguay merged 3 commits into
NVIDIA:mainfrom
krishung5:krish/fix-conversation-explicit-rank-binding
Jul 31, 2026
Merged

[None][fix] Bind explicit DP rank for new conversations#16815
pcastonguay merged 3 commits into
NVIDIA:mainfrom
krishung5:krish/fix-conversation-explicit-rank-binding

Conversation

@krishung5

@krishung5 krishung5 commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • Fixed ConversationAwareADPRouter explicit first-turn handling so that when a new conversation provides an explicit attention_dp_rank, the conversation→DP-rank affinity binding is recorded (only if the hinted rank has capacity) and then reused on subsequent turns.
  • Refactored explicit conversation-first-turn placement:
    • Introduced _assign_new_conversation_explicit_dp_ranks and updated route_requests() to call it.
    • Conversations already present in _conv_to_rank are skipped during explicit placement, so later conflicting explicit attention_dp_rank hints cannot override an existing binding.
    • If the hinted attention_dp_rank is at capacity, the request is returned for normal affinity/load-balanced routing and is not bound.
    • Requests without a conversation_id keep the existing explicit-placement/fallback behavior but are not recorded into the conversation affinity map.
  • Updated internal routing step comments to reflect conversation-aware affinity precedence.
  • No public API changes or new dependencies introduced. (Note: the previous explicit-rank capability marker referenced in the old summary is not present in the current code.)

QA Engineer Review

  • Updated unit coverage in tests/unittest/_torch/executor/test_adp_router.py under TestConversationAwareADPRouter:
    • test_explicit_target_dp_rank_establishes_binding: verifies an explicit target_dp_rank/attention_dp_rank for a new conversation creates and records a conversation→rank binding, and subsequent turns reuse it when later requests omit the explicit target.
    • test_existing_binding_wins_over_later_explicit_target: verifies a later request with a conflicting explicit target does not override the already-recorded conversation binding.
    • test_no_conversation_id_falls_back_and_is_not_recorded: verifies conversation-less requests are routed without being recorded in _conv_to_rank.
  • No changes to tests/integration/test_lists/ were identified.
  • Verdict: needs follow-up (no CI/manual test-list mapping/coverage data available for these unit tests).

Description

ConversationAwareADPRouter currently honors an explicit
attention_dp_rank before applying conversation-affinity routing. This places
the first request on the requested rank but does not record the resulting
conversation_id -> DP rank binding. Subsequent requests in the same
conversation can therefore be routed to a different DP rank.

This change makes explicit placement establish the conversation binding:

  • A new conversation with an explicit attention_dp_rank is routed to that
    rank and records the affinity binding.
  • Subsequent requests use the recorded binding, even if a later request
    supplies a conflicting explicit rank.
  • If the explicit target rank is full, the request falls back to the existing
    conversation-affinity and load-balancing path.
  • Requests without a conversation ID retain the existing explicit-placement
    behavior.

This enables external orchestrators such as Dynamo to select the initial DP
rank while allowing TensorRT-LLM to preserve that placement for later turns.

Context:
ai-dynamo/dynamo#11609 (comment)

There are no public API changes or new dependencies.

Test Coverage

Added unit coverage for:

  • Establishing a conversation binding from an explicit first-turn DP rank.
  • Reusing the recorded rank for subsequent turns.
  • Preserving an existing binding when a later request supplies a conflicting
    explicit rank.

Local validation completed:

  • pre-commit run --files ...
  • ruff check
  • ruff format --check
  • python3 -m compileall
  • git diff --check
  • Targeted behavior validation covering first placement, repeated requests,
    conflicting later hints, and requests without conversation IDs.

The full pytest suite could not be collected in the local host environment
because its optional mpi4py and nvtx dependencies are unavailable. The
added tests should be exercised by the TensorRT-LLM CI pipeline.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

@krishung5
krishung5 requested a review from a team as a code owner July 23, 2026 23:17
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 79cdbc50-90af-4314-b5d5-d16497544f64

📥 Commits

Reviewing files that changed from the base of the PR and between 445a73f and a7c1ebe.

📒 Files selected for processing (1)
  • tensorrt_llm/_torch/pyexecutor/scheduler/adp_router.py
💤 Files with no reviewable changes (1)
  • tensorrt_llm/_torch/pyexecutor/scheduler/adp_router.py

Walkthrough

Conversation-aware routing now assigns unbound conversations to explicit ranks when capacity allows, records their affinity, reuses it on later turns, and prevents conflicting explicit targets from overriding established bindings.

Changes

Conversation affinity routing

Layer / File(s) Summary
Explicit affinity placement and validation
tensorrt_llm/_torch/pyexecutor/scheduler/adp_router.py, tests/unittest/_torch/executor/test_adp_router.py
The router assigns new conversations to available explicit ranks, preserves existing bindings, and defers unscheduled requests to later routing. Tests verify affinity persistence and protection against conflicting later targets.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: cascade812, mikeiovine

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title follows the required [None][type] format and clearly summarizes the main change.
Description check ✅ Passed The description includes the required Description, Test Coverage, and PR Checklist sections with sufficient detail.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tensorrt_llm/_torch/pyexecutor/scheduler/adp_router.py (1)

862-866: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Prefer Python 3.10 built-in generic annotations.

Use list[...] and dict[...] instead of List/Dict in this new helper.

Suggested change
-        requests: List["RequestQueueItem"],
-        all_ranks_new_requests: Dict[int, List["RequestQueueItem"]],
-        all_ranks_num_active_requests: List[int],
+        requests: list["RequestQueueItem"],
+        all_ranks_new_requests: dict[int, list["RequestQueueItem"]],
+        all_ranks_num_active_requests: list[int],
...
-    ) -> List["RequestQueueItem"]:
+    ) -> list["RequestQueueItem"]:

As per coding guidelines, Python 3.10+ code should prefer built-in generic types and |.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tensorrt_llm/_torch/pyexecutor/scheduler/adp_router.py` around lines 862 -
866, Update the new helper signature around its request and rank parameters to
use Python 3.10 built-in generics: replace List[...] with list[...] and
Dict[...] with dict[...]. Remove any now-unused typing imports if applicable,
without changing the helper’s behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tensorrt_llm/_torch/pyexecutor/scheduler/adp_router.py`:
- Around line 862-866: Update the new helper signature around its request and
rank parameters to use Python 3.10 built-in generics: replace List[...] with
list[...] and Dict[...] with dict[...]. Remove any now-unused typing imports if
applicable, without changing the helper’s behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 91dda924-fc49-423e-ba5d-0a7a1bf75889

📥 Commits

Reviewing files that changed from the base of the PR and between 80b4eb3 and 5d67377.

📒 Files selected for processing (2)
  • tensorrt_llm/_torch/pyexecutor/scheduler/adp_router.py
  • tests/unittest/_torch/executor/test_adp_router.py

Signed-off-by: krishung5 <krish@nvidia.com>
@krishung5
krishung5 force-pushed the krish/fix-conversation-explicit-rank-binding branch from 5d67377 to e83e196 Compare July 27, 2026 21:46
@krishung5

krishung5 commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator Author

Dynamo-side companion PR: ai-dynamo/dynamo#12225. It adds an opt-in Dynamo-owned initial DP-rank source while keeping TensorRT-LLM-owned placement as the default.

Signed-off-by: krishung5 <krish@nvidia.com>
Signed-off-by: krishung5 <krish@nvidia.com>
Comment thread tensorrt_llm/_torch/pyexecutor/scheduler/adp_router.py
@chienchunhung

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62330 [ run ] triggered by Bot. Commit: a7c1ebe Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62330 [ run ] completed with state FAILURE. Commit: a7c1ebe
/LLM/main/L0_MergeRequest_PR pipeline #50498 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@krishung5

Copy link
Copy Markdown
Collaborator Author

@chienchunhung / @pcastonguay I see the CI fails due to some OOM/timeout/slurm issues, could you help rerun if possible?

@pcastonguay

Copy link
Copy Markdown
Collaborator

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62829 [ run ] triggered by Bot. Commit: a7c1ebe Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #62829 [ run ] completed with state FAILURE. Commit: a7c1ebe
/LLM/main/L0_MergeRequest_PR pipeline #50954 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@pcastonguay

Copy link
Copy Markdown
Collaborator

/bot skip --comment "Flaky tests"

@pcastonguay
pcastonguay enabled auto-merge (squash) July 31, 2026 17:29
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63085 [ skip ] triggered by Bot. Commit: a7c1ebe Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #63085 [ skip ] completed with state SUCCESS. Commit: a7c1ebe
Skipping testing for commit a7c1ebe

Link to invocation

@pcastonguay
pcastonguay merged commit b1b8dbd into NVIDIA:main Jul 31, 2026
11 checks passed
yuanjingx87 pushed a commit that referenced this pull request Aug 1, 2026
Signed-off-by: krishung5 <krish@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants