Skip to content

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

Closed
lancelly wants to merge 1 commit into
NVIDIA:feat/deepseek_v4_benchfrom
lancelly:perf/adp-router-cheap-token-count-bench
Closed

[None][perf] avoid full input_token_ids copy in ADP router token count#15362
lancelly wants to merge 1 commit into
NVIDIA:feat/deepseek_v4_benchfrom
lancelly:perf/adp-router-cheap-token-count-bench

Conversation

@lancelly

Copy link
Copy Markdown
Collaborator

Summary

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.

On DeepSeek-V4 disaggregated generation at high concurrency (avg ISL ~39k), the
per-iteration _fetch_new_requests host path is a known rank-0 GIL hotspot.

Change

  • 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 nanobind property.
  • Route the DefaultADPRouter / KVCacheAwareADPRouter token-count reads
    through a small _num_input_tokens() helper backed by that accessor.

Test

  • TestNumInputTokens covers the helper (None request, prefers the accessor
    without touching input_token_ids).
  • Router unit tests use a _MockRequest whose num_input_tokens mirrors
    len(input_token_ids).

Notes

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 requested a review from a team as a code owner June 15, 2026 05:20
@lancelly
lancelly requested review from HuiGao-NV and removed request for a team June 15, 2026 05:20
@lancelly

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54222 [ run ] triggered by Bot. Commit: bcc18b7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54222 [ run ] completed with state SUCCESS. Commit: bcc18b7
/LLM/main/L0_MergeRequest_PR pipeline #43299 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 #54255 [ run ] triggered by Bot. Commit: bcc18b7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54255 [ run ] completed with state SUCCESS. Commit: bcc18b7
/LLM/main/L0_MergeRequest_PR pipeline #43329 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 #54287 [ run ] triggered by Bot. Commit: bcc18b7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

Link to invocation

@lancelly

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54422 [ run ] triggered by Bot. Commit: bcc18b7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54422 [ run ] completed with state FAILURE. Commit: bcc18b7
/LLM/main/L0_MergeRequest_PR pipeline #43485 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 #54536 [ run ] triggered by Bot. Commit: bcc18b7 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@longlee0622

Copy link
Copy Markdown
Collaborator

We no longer use the ds v4 side branch. Closing this PR. Please prepare PR against main.

@longlee0622 longlee0622 closed this Jul 9, 2026
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.

3 participants