Skip to content

[https://nvbugs/6858505][fix] Reject an encoder input longer than one encoder iteration at admission - #21199

Merged
BoyueZ merged 5 commits into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-v2/nvbug-6858505-r101
Nov 3, 2026
Merged

BoyueZ merged 5 commits into
NVIDIA:mainfrom
tensorrt-cicd:repair-bot-v2/nvbug-6858505-r101

Conversation

@trtllm-agent

@trtllm-agent trtllm-agent commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Description

An encoder-decoder request (T5, BART, mBART, Whisper) runs its whole encoder input in one iteration: the encoder input is never chunked. That iteration is bounded by max_num_tokens (the micro-batch schedulers), by encoder_max_num_tokens (the encoder step), and by the per-sequence capacity of the cross-attention KV cache that holds the encoder output (max_seq_len of the cross KV cache manager).

Before this change, request admission did not compare the encoder length with these bounds. A request with a longer encoder input was admitted and then failed later:

  • Above max_num_tokens, the Python micro-batch scheduler raised an AssertionError, the C++ micro-batch scheduler raised a check failure, and the KV cache V2 scheduler left the request unscheduled until it raised its scheduler-deadlock error. Each of these errors ended the executor loop.
  • Above the cross KV cache's max_seq_len but within max_num_tokens, the attention metadata check raised in the forward step, and the error counted against the executor's error budget. With the KV cache V2 manager, a longer input instead made the manager raise while resizing the cross KV cache, which ended the executor loop.
  • Above encoder_max_num_tokens, when it is set below max_num_tokens, the encoder step raised for the whole encoder batch, and the error counted against the error budget.

With this change, PyExecutor._validate_request_budget rejects, at admission, a request whose encoder output length exceeds the smallest of these bounds. The ValueError names the length and each bound. The request fails on its own, like a request rejected by the existing KV block budget check, without counting against the error budget, and the executor keeps serving the other requests. Requests within the bounds, and decoder-only requests, are admitted as before.

This check bounds one request at a time. The schedulers still pack encoder requests against max_num_tokens only, so when encoder_max_num_tokens is set below max_num_tokens, several encoder requests that each pass this check can together exceed encoder_max_num_tokens in one encoder step. A follow-up fix for nvbug6858551 will add an encoder token budget to the schedulers and have the schedulers, the encoder step and this check read their bounds from one shared helper.

Test Coverage

  • tests/unittest/_torch/executor/test_resource_manager.py: the encoder length is checked against max_num_tokens, against a smaller encoder_max_num_tokens, and against the cross KV cache max_seq_len; decoder-only prompt length is not checked here.
  • tests/unittest/_torch/executor/test_py_executor.py::test_encoder_input_above_max_num_tokens_fails_only_that_request: through _fetch_and_activate_new_requests, only the request over the limit fails, and the error budget is not charged.
  • tests/integration/defs/llmapi/test_llm_api_pytorch_t5.py::test_t5_encoder_input_above_max_num_tokens_fails_alone (KV cache V2, V1 with the Python scheduler, V1 with the C++ scheduler; added to l0_h100.yml): an encoder input one token over the limit fails with the new error, then the longest encoder input that fits and the reference prompt are served.

Ran on H100: the new unit tests and all three integration cases fail without the source change and pass with it. With the change, these also pass:

  • the unit-test files test_resource_manager.py, test_py_executor.py, test_py_scheduler.py, test_encoder_executor.py, test_kv_connector_initialization.py and test_request_utils.py in tests/unittest/_torch/executor/, plus engine/test_encoder_decoder.py, kv_cache/test_dual_pool_kv_cache.py, kv_cache/test_kv_cache_v2_scheduler.py, tests/unittest/disaggregated/test_chunked_transfer.py and tests/unittest/executor/test_forward_error_survival.py;
  • T5: test_t5_pytorch_generate_encoder_decoder_end_to_end (bf16 t5-small greedy, beam search, greedy with the overlap scheduler), test_t5_pytorch_generate_encoder_decoder_mixed_encoder_lengths_batch (4 cases), test_t5_pytorch_continuous_admission_replays_encoder_and_mixed_cuda_graphs, test_t5_pytorch_block_reuse_is_disabled_for_v2 and test_t5_v2_decode_beyond_encoder_length (2 cases);
  • BART: test_bart_pytorch_generate_encoder_decoder_end_to_end (7 single-GPU bart-large-cnn cases), test_bart_pytorch_generate_encoder_decoder_mixed_encoder_lengths_batch, test_bart_pytorch_continuous_admission_replays_encoder_and_mixed_cuda_graphs[tp1] and test_mbart_pytorch_generate_encoder_decoder_end_to_end;
  • Whisper: test_whisper_pytorch_transcribe_end_to_end, test_whisper_pytorch_block_reuse_requested, test_whisper_pytorch_beam_search (2 cases) and test_whisper_pytorch_feature_combinations (5 single-GPU cases).

Dev Engineer Review

  • PyExecutor._validate_request_budget now rejects a request whose known encoder output length exceeds the smallest applicable token or cross-KV-cache sequence limit.
  • The change adds a per-request admission check. It does not limit the combined length of encoder requests packed into a batch. That case needs follow-up.
  • Review finding severity counts are unavailable because no current review findings were supplied.

QA Engineer Review

  • Unit tests cover token limits, boundary acceptance, unknown encoder length, decoder-only requests, cross-KV-cache limits, and rejection without charging the error budget.
  • T5 integration tests cover oversized-input rejection and continued generation for valid requests across KV-cache versions and scheduler types.
  • The H100 CI list contains one matching T5 entry: test_t5_encoder_input_above_max_num_tokens_fails_alone[kv-v2]. Test execution results are not established by the available evidence.
  • Coverage verdict: needs follow-up. Tests cover individual request limits, but not the packed-batch limitation.

Per-File QA Perspective

  • tensorrt_llm/_torch/pyexecutor/py_executor.py — Verify admission against the applicable limits, including requests with unknown encoder output length and decoder-only requests. Verify that rejection does not charge the executor’s error budget.
  • tests/integration/defs/llmapi/test_llm_api_pytorch_t5.py — Covers oversized-input rejection and generation for valid requests across KV-cache versions and scheduler types. The H100 CI list includes the kv-v2 selector.
  • tests/integration/test_lists/test-db/l0_h100.yml — Adds the T5 oversized-input test with the [kv-v2] selector to the H100 CI list.
  • tests/unittest/_torch/pyexecutor/test_py_executor.py — Covers oversized encoder input rejection, admission at the limit, unknown encoder length, and rejection without charging the error budget. Integration test-list inclusion does not apply.
  • tests/unittest/_torch/pyexecutor/test_resource_manager.py — Covers encoder token limits, cross-KV-cache limits, boundary acceptance, and decoder-only behavior. Integration test-list inclusion does not apply.

… encoder iteration at admission

An encoder input is never chunked: it runs whole in one iteration,
which is bounded by max_num_tokens (the micro-batch schedulers),
encoder_max_num_tokens (the encoder step) and the per-sequence capacity
of the cross-attention KV cache that holds the encoder output.

Admission did not compare the encoder length with these bounds, so a
longer request was admitted and then failed inside the executor loop.
The micro-batch schedulers raised for it (the Python assertion, the C++
check, the KV cache V2 scheduler's deadlock error), the KV cache V2
manager raised while resizing the cross KV cache, or the forward or
encoder step raised for the whole batch and the error counted against
the executor's error budget.

PyExecutor._validate_request_budget now rejects such a request with a
ValueError that names the encoder length and each bound. The request
fails on its own, without counting against the error budget, and the
executor keeps serving the other requests. Requests within the bounds
and decoder-only requests are admitted as before.

Signed-off-by: trtllm-agent <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Walkthrough

The executor now checks known encoder output lengths against applicable token limits before KV-cache block budget checks. Unit and T5 integration tests cover oversized request rejection and accepted inputs.

Changes

Encoder Budget Validation

Layer / File(s) Summary
Validate encoder output length
tensorrt_llm/_torch/pyexecutor/py_executor.py
_validate_request_budget checks known encoder output lengths before KV-cache block budget checks. It compares lengths against applicable model, encoder, and cross-KV-cache limits.
Verify admission and cache limits
tests/unittest/_torch/pyexecutor/test_py_executor.py, tests/unittest/_torch/pyexecutor/test_resource_manager.py
Unit tests cover request admission, model and encoder token limits, cross-cache sequence limits, and requests without encoder output.
Verify T5 request behavior
tests/integration/defs/llmapi/test_llm_api_pytorch_t5.py, tests/integration/test_lists/test-db/l0_h100.yml
Integration tests check oversized T5 inputs and subsequent accepted inputs across KV manager and scheduler configurations. The H100 test list includes the KV-v2 case.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related issues

  • Issue 19514: The issue describes Whisper encoder output exceeding the cross-attention KV-cache maximum. This change rejects inputs above the cross-KV-cache limit but does not resize the cache.

Suggested reviewers: lori-ren, brnguyen2, litaotju

Merge Risk: Minimal · up to 62902

No blocking defect was established. The reported CI failures do not identify a cause.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description explains the issue, the admission-time fix, affected limits, expected behavior, known scope limitation, and relevant unit and integration test coverage. It does not explicitly complete…
Title check Passed The title clearly identifies the main change: rejecting encoder inputs that exceed the single encoder-iteration limit at admission. It follows the required ticket and type format.
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.
Full details: Description check

Explanation

The description explains the issue, the admission-time fix, affected limits, expected behavior, known scope limitation, and relevant unit and integration test coverage. It does not explicitly complete the PR checklist, but the required technical information is mostly present.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files. (2 skipped: 1 unsupported, 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

ast-grep (0.51.1)

ast-grep could not parse rule config: /ast-grep-rules/ast-grep-essentials/rules/typescript/security/xss-vulnerability-typescript.yml

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.
Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between d772645 and 62902ce.

Files selected for processing: 5
  • tensorrt_llm/_torch/pyexecutor/py_executor.py
  • tests/integration/defs/llmapi/test_llm_api_pytorch_t5.py
  • tests/integration/test_lists/test-db/l0_h100.yml
  • tests/unittest/_torch/pyexecutor/test_py_executor.py
  • tests/unittest/_torch/pyexecutor/test_resource_manager.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

@brnguyen2 brnguyen2 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving — the comments below are optional touch-ups, not blockers.

The check sits at the right point: an encoder input that can never fit now fails only its own request at admission, and doesn't reach the scheduler or forward step. Decoder-only and VLM requests return None from try_get_encoder_output_len(), so they skip it. The tests cover each bound plus the "error budget not charged" path.

One gap for a follow-up. The check bounds one request, but encoder_max_num_tokens also caps the packed encoder batch (encoder_decoder.py:173 / :205 compare the summed length). When a user sets encoder_max_num_tokens < max_num_tokens, the micro-batch scheduler budgets only against max_num_tokens. It can then co-schedule several encoder requests that each pass this check but whose sum is above encoder_max_num_tokens, and the encoder step fails the whole batch. I couldn't find an enc-dec scheduler bound on this (_apply_mm_encoder_admission covers only MM item scheduling). Please either add an encoder token budget to the enc-dec scheduling path, or say in the description that only the single-request case is covered.

Design note, non-blocking: this method keeps its own copy of the limits that the scheduler, encoder runner, and cross KV manager each enforce. If one of them changes its bound, admission will fall out of sync again. A small accessor on each component (or one helper that the scheduler assert and this check both call) would keep them in sync.

@BowenFu

BowenFu commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81669 [ run ] triggered by Bot. Commit: 5f41cab Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81669 [ run ] completed with state FAILURE. Commit: 5f41cab
/LLM/main/L0_MergeRequest_PR pipeline #67333 completed with status: 'UNSTABLE'

CI Report

⚠️ Multi-GPU Label Required:
Multi-GPU tests require the ci: full pre-merge approved label on this PR. Either:

  • Wait for the PR to be fully approved — the label is added automatically once approval is complete. Having unresolved open comments is fine, or
  • If needed, ask a member of NVIDIA/trt-llm-ci-approvers to add the label manually.
    Then re-trigger CI with the same bot command (no rebase needed).

⚠️ 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

@JunyiXu-nv JunyiXu-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Runtime part LGTM: the admission check fails only the offending encoder request, and its bounds match what the encoder stage and cross KV cache enforce.

@BoyueZ

BoyueZ commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

Approving — the comments below are optional touch-ups, not blockers.

The check sits at the right point: an encoder input that can never fit now fails only its own request at admission, and doesn't reach the scheduler or forward step. Decoder-only and VLM requests return None from try_get_encoder_output_len(), so they skip it. The tests cover each bound plus the "error budget not charged" path.

One gap for a follow-up. The check bounds one request, but encoder_max_num_tokens also caps the packed encoder batch (encoder_decoder.py:173 / :205 compare the summed length). When a user sets encoder_max_num_tokens < max_num_tokens, the micro-batch scheduler budgets only against max_num_tokens. It can then co-schedule several encoder requests that each pass this check but whose sum is above encoder_max_num_tokens, and the encoder step fails the whole batch. I couldn't find an enc-dec scheduler bound on this (_apply_mm_encoder_admission covers only MM item scheduling). Please either add an encoder token budget to the enc-dec scheduling path, or say in the description that only the single-request case is covered.

Design note, non-blocking: this method keeps its own copy of the limits that the scheduler, encoder runner, and cross KV manager each enforce. If one of them changes its bound, admission will fall out of sync again. A small accessor on each component (or one helper that the scheduler assert and this check both call) would keep them in sync.

Agreed: this PR covers only the single-request case, and the description now says so. The packed-batch case is tracked in https://nvbugs/6858551.

…r admission test

In this test max_num_tokens, encoder_max_num_tokens and the cross KV
cache max_seq_len are all 64, so the limit value alone does not show
which bound is reported. Also match the start of the bound list,
max_num_tokens=64.

Signed-off-by: berryz <[email protected]>
@BoyueZ

BoyueZ commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81968 [ run ] triggered by Bot. Commit: d772645 Link to invocation

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements.

@BoyueZ

BoyueZ commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

/bot kill

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81988 [ kill ] triggered by Bot. Commit: d772645 Link to invocation

@BoyueZ

BoyueZ commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81968 [ run ] completed with state ABORTED. Commit: d772645

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81991 [ run ] triggered by Bot. Commit: d772645 Link to invocation

@BoyueZ BoyueZ self-assigned this Nov 2, 2026
@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

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

… admission test in CI

KV cache V1 is deprecated, so drop the two kv-v1 entries of
test_t5_encoder_input_above_max_num_tokens_fails_alone from l0_h100.yml.
The test keeps its kv-v1 parameters for local runs.

Signed-off-by: berryz <[email protected]>
@BoyueZ

BoyueZ commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

/bot run

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82144 [ run ] triggered by Bot. Commit: 62902ce Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #82144 [ run ] completed with state SUCCESS. Commit: 62902ce
/LLM/main/L0_MergeRequest_PR pipeline #67785 completed with status: 'SUCCESS'
Pipeline passed with automatic retried tests. Check the rerun report for details.

CI Report

Link to invocation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants