Skip to content

[None][perf] avoid full input_token_ids copy in ADP router token count - #15199

Merged
lancelly merged 1 commit into
NVIDIA:feat/deepseek_v4from
lancelly:perf/adp-router-cheap-token-count
Jun 16, 2026
Merged

[None][perf] avoid full input_token_ids copy in ADP router token count#15199
lancelly merged 1 commit into
NVIDIA:feat/deepseek_v4from
lancelly:perf/adp-router-cheap-token-count

Conversation

@lancelly

Copy link
Copy Markdown
Collaborator

Summary

Follow-on to #15133. The ADP request router only needs the input length to
load-balance new requests across attention-DP ranks, but it read
ExecutorRequest.input_token_ids and called len() on it.

Request::getInputTokenIds() returns VecTokens by value, so each access
materializes a fresh ~ISL-sized Python list (one PyObject per token) — under the
GIL, redundantly on every rank (routing is symmetric), for every new
request
. #15133 reduced the access from 2→1 per request; this removes the
copy entirely by counting the tokens without materializing the list.

Change

  • Add a cheap num_input_tokens accessor to the Request nanobind binding
    (returns getInputTokenIds().size() — no Python list is built).
  • Route the DefaultADPRouter / KVCacheAwareADPRouter token-count reads
    through a _num_input_tokens() helper. It falls back to
    len(input_token_ids) when the accessor is absent (a Python-only deploy whose
    C++ bindings predate it, or test mocks), so routing results are unchanged.

Why it matters

On DeepSeek-V4-Pro disaggregated generation @ 2880 concurrency (avg ISL ~39k),
the per-iteration _fetch_new_requests host path is a known rank-0 GIL
hotspot. Each new request previously triggered a full ~39k-element Python list
build on all 8 ranks just to obtain its length.

Test

Adds TestNumInputTokens: prefers the accessor (and asserts input_token_ids
is not materialized), falls back to len() when absent, ignores a non-int
accessor, and handles a None request.

Notes

  • Draft: the C++ binding needs a rebuild to exercise the fast path; the Python
    fallback keeps behavior/CI unchanged without it.
  • Possible follow-up: a true O(1) Request::getNumInputTokens() on the C++ side
    would avoid even the (cheap) internal VecTokens copy that .size() incurs.

@lancelly
lancelly force-pushed the perf/adp-router-cheap-token-count branch 7 times, most recently from 21d8e77 to 9b5ca6f Compare June 15, 2026 05:07
The ADP router only needs the input length to load-balance new requests, but
it read ExecutorRequest.input_token_ids and called len() on it. That C++
getter returns VecTokens by value, so every access materializes a fresh
~ISL-sized Python list (one PyObject per token) under the GIL -- redundantly
on every rank (routing is symmetric) for every new request. At high
concurrency with long context (e.g. DeepSeek-V4 disagg generation, avg ISL
~39k) this is a measurable rank-0 host cost.

Add an O(1) Request::getNumInputTokens() that reads mInputTokenIds.size()
directly -- no VecTokens copy and no Python list -- and bind it as the
num_input_tokens property. Route the Default/KVCacheAware token-count reads
through a _num_input_tokens() helper backed by that accessor.

Signed-off-by: Lance Liao <108499334+lancelly@users.noreply.github.com>
@lancelly
lancelly force-pushed the perf/adp-router-cheap-token-count branch from 9b5ca6f to cca1ca0 Compare June 15, 2026 05:13
@lancelly
lancelly marked this pull request as ready for review June 15, 2026 05:14
@lancelly
lancelly requested a review from a team as a code owner June 15, 2026 05:14
@lancelly
lancelly requested review from joyang-nv and removed request for a team June 15, 2026 05:14
@lancelly

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54220 [ run ] triggered by Bot. Commit: cca1ca0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54220 [ run ] completed with state FAILURE. Commit: cca1ca0
/LLM/main/L0_MergeRequest_PR pipeline #43297 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

@lancelly

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54242 [ run ] triggered by Bot. Commit: cca1ca0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54242 [ run ] completed with state SUCCESS. Commit: cca1ca0
/LLM/main/L0_MergeRequest_PR pipeline #43317 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

@lancelly

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

1 similar comment
@lancelly

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54278 [ run ] triggered by Bot. Commit: cca1ca0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54279 [ run ] triggered by Bot. Commit: cca1ca0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54278 [ run ] completed with state ABORTED. Commit: cca1ca0

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54279 [ run ] completed with state SUCCESS. Commit: cca1ca0
/LLM/main/L0_MergeRequest_PR pipeline #43351 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

@lancelly

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54424 [ run ] triggered by Bot. Commit: cca1ca0 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54424 [ run ] completed with state SUCCESS. Commit: cca1ca0
/LLM/main/L0_MergeRequest_PR pipeline #43487 completed with status: 'SUCCESS'

CI Report

Link to invocation

@lancelly
lancelly merged commit e0a773b into NVIDIA:feat/deepseek_v4 Jun 16, 2026
7 checks passed
lfr-0531 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 26, 2026
NVIDIA#15199)

Signed-off-by: Lance Liao <108499334+lancelly@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Shixiaowei02 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 29, 2026
NVIDIA#15199)

Signed-off-by: Lance Liao <108499334+lancelly@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
lancelly added a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 29, 2026
NVIDIA#15199)

Signed-off-by: Lance Liao <108499334+lancelly@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Signed-off-by: Liao Lanyu <108499334+lancelly@users.noreply.github.com>
Shixiaowei02 pushed a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jun 30, 2026
NVIDIA#15199)

Signed-off-by: Lance Liao <108499334+lancelly@users.noreply.github.com>
Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Signed-off-by: Liao Lanyu <108499334+lancelly@users.noreply.github.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.

2 participants