Skip to content

[None][feat] DSA: adaptive indexer prefill chunk size for long sequences#15459

Merged
lfr-0531 merged 4 commits into
NVIDIA:feat/deepseek_v4from
lfr-0531:user/fanrongl/dsv4-indexer-chunk-heuristic
Jun 26, 2026
Merged

[None][feat] DSA: adaptive indexer prefill chunk size for long sequences#15459
lfr-0531 merged 4 commits into
NVIDIA:feat/deepseek_v4from
lfr-0531:user/fanrongl/dsv4-indexer-chunk-heuristic

Conversation

@lfr-0531

Copy link
Copy Markdown
Collaborator

Background / Motivation

The DSA indexer's fp8_fp4_mqa_logits / fp8_mqa_logits activation memory
scales with indexer_max_chunk_size * K_compressed (the compressed KV length
of the current request). For very long sequences this can OOM — e.g. a
~500K-token request with the default 32K chunk size needs ~16GB of activation
memory.

The current workaround is to uniformly lower indexer_max_chunk_size (e.g. to
8K). That avoids the OOM but costs prefill throughput for the common case,
where the vast majority of requests are far below these lengths — a blunt
one-size-fits-all setting for what is really a long-tail problem.

Summary

Select the indexer prefill chunk size per-batch based on the largest
compressed KV length (K_compressed) among the context requests, instead of
always using the statically-configured value:

max K_compressed in batch effective chunk size
> 512K 8K
[256K, 512K] 16K
< 256K configured (default 32K, unchanged)

Implementation:

  • New helper select_indexer_chunk_size(configured_chunk_size, max_k_compressed)
    in dsa.py. It only ever reduces the configured chunk size (never
    increases it), so any explicitly-configured value still acts as an upper
    bound.
  • Wired into Indexer.prepare_for_chunked_prefill, on the indexer's own
    chunking path only. The MLA chunked-prefill path is untouched (it already
    bounds the chunk to the MLA chunk).
  • max K_compressed is read from indexer_params.kv_lens (already host-side
    during prefill prepare).

Impact

  • Long requests (>256K): smaller chunk → lower indexer activation memory,
    avoids the OOM without manual tuning.
  • Common case (<256K): behavior unchanged — keeps the larger,
    higher-throughput chunk size.
  • Safe to vary per-batch because the prefill path does not use CUDA graphs.
  • No API/config changes; existing indexer_max_chunk_size continues to act as
    the upper bound.

Notes

  • Draft for early review / discussion. Thresholds (256K / 512K) and chunk
    sizes (8K / 16K / 32K) are centralized in _INDEXER_CHUNK_SIZE_HEURISTIC for
    easy tuning.
  • TODO before un-drafting: add a unit test for select_indexer_chunk_size
    boundaries and validate end-to-end memory/perf on a long-sequence workload.

🤖 Generated with Claude Code

The indexer's fp8_fp4_mqa_logits / fp8_mqa_logits activation memory scales
with indexer_max_chunk_size * K_compressed (the compressed KV length of the
current request). For very long sequences this can OOM: e.g. a ~500K-token
request with the default 32K chunk size needs ~16GB of activation memory.

The previous workaround was to uniformly lower indexer_max_chunk_size (e.g.
to 8K), but that costs prefill throughput for the common case where the vast
majority of requests are far below these lengths.

Instead, select the indexer prefill chunk size per-batch based on the largest
compressed KV length among the context requests:

  - max K_compressed >  512K          -> 8K  chunk
  - 256K <= max K_compressed <= 512K  -> 16K chunk
  - max K_compressed <  256K          -> configured chunk size (unchanged)

The heuristic only ever reduces the configured chunk size (never increases
it), so the common case keeps its larger, higher-throughput chunk. It is
applied only on the indexer's own chunking path (not the MLA chunked-prefill
path, which already bounds chunk size) and is safe to vary per-batch because
the prefill path does not use CUDA graphs.

Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #54853 [ run ] triggered by Bot. Commit: ff0e8a5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55123 [ run ] triggered by Bot. Commit: ff0e8a5 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55185 [ run ] triggered by Bot. Commit: ff0e8a5 Link to invocation

@lfr-0531
lfr-0531 marked this pull request as ready for review June 23, 2026 13:36
@lfr-0531
lfr-0531 requested a review from a team as a code owner June 23, 2026 13:36
@lfr-0531
lfr-0531 requested review from QiJune and removed request for a team June 23, 2026 13:36
@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot kill

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55350 [ kill ] triggered by Bot. Commit: de2a206 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55185 [ run ] completed with state ABORTED. Commit: ff0e8a5

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55350 [ kill ] completed with state SUCCESS. Commit: de2a206
Successfully killed previous jobs for commit de2a206

Link to invocation

The Pre-commit Check CI runs `bandit -r tensorrt_llm`, which flags 8
B105 (hardcoded_password_string) false positives: string literals compared
against `token_back_*` variables (the name contains "token", which bandit
treats as a secret). These are plain mode/schedule comparisons, not secrets.

Annotate the 8 lines with `# nosec B105`. scripts/bandit.yaml is intentionally
left untouched (its header asks not to modify it).

Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
@lfr-0531
lfr-0531 requested review from a team as code owners June 24, 2026 01:55
@lfr-0531
lfr-0531 requested review from liji-nv and removed request for a team June 24, 2026 01:55
@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55371 [ run ] triggered by Bot. Commit: fa80aee Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55380 [ run ] triggered by Bot. Commit: fa80aee Link to invocation

@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55393 [ run ] triggered by Bot. Commit: fa80aee Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

hyukn added a commit to hyukn/TensorRT-LLM that referenced this pull request Jun 24, 2026
…ock pre-commit

The repo-wide `bandit -r tensorrt_llm` gate in scripts/release_check.py
flags B105 (hardcoded_password_string) on token_back_mode string
comparisons (e.g. token_back_mode != "epi_warps") in the megamoe files
because the variable name contains "token". These are false positives.
Add targeted `# nosec B105` suppressions (the test-scoped form, which the
gate permits since it does not increment "Total lines skipped (#nosec)").
Mirrors the same suppressions in PR NVIDIA#15459 so this PR's Pre-commit Check
passes without waiting for that PR to land.

Signed-off-by: Yukun He <23156053+hyukn@users.noreply.github.com>
@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55505 [ run ] triggered by Bot. Commit: fa80aee Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55633 [ run ] triggered by Bot. Commit: fa80aee Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55717 [ run ] triggered by Bot. Commit: fa80aee Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #55934 [ run ] triggered by Bot. Commit: fa80aee Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

Work around the gb200-x4 CI infra issue by requesting the -split node pool
for the GB200-4_GPUs-PyTorch-DS-1 test, mirroring PR NVIDIA#15548 (which did the
same for the GB200 perf-sanity stages).

Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
@lfr-0531
lfr-0531 requested a review from a team June 26, 2026 06:33
@lfr-0531
lfr-0531 requested a review from a team as a code owner June 26, 2026 06:33
@lfr-0531
lfr-0531 requested review from mlefeb01 and niukuo and removed request for a team June 26, 2026 06:33
@lfr-0531

Copy link
Copy Markdown
Collaborator Author

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56016 [ run ] triggered by Bot. Commit: c97a259 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #56016 [ run ] completed with state SUCCESS. Commit: c97a259
/LLM/main/L0_MergeRequest_PR pipeline #44890 completed with status: 'SUCCESS'

CI Report

Link to invocation

@lfr-0531
lfr-0531 merged commit acbcb93 into NVIDIA:feat/deepseek_v4 Jun 26, 2026
6 checks passed
lfr-0531 added a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jul 7, 2026
…ces (NVIDIA#15459)

Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Co-authored-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Signed-off-by: Fanrong Li <23290157+lfr-0531@users.noreply.github.com>
lfr-0531 added a commit to lfr-0531/TensorRT-LLM that referenced this pull request Jul 7, 2026
…ces (NVIDIA#15459)

Signed-off-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Co-authored-by: Fanrong Li <lfr-0531@users.noreply.github.com>
Signed-off-by: Fanrong Li <23290157+lfr-0531@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