Repository navigation
[https://nvbugs/6858505][fix] Reject an encoder input longer than one encoder iteration at admission - #21199
Conversation
… 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]>
|
No actionable comments were generated in the recent review. WalkthroughThe 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. ChangesEncoder Budget Validation
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Possibly related issues
Suggested reviewers: Merge Risk:
|
brnguyen2
left a comment
There was a problem hiding this comment.
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.
|
/bot run |
|
PR_Github #81669 [ run ] triggered by Bot. Commit: |
|
PR_Github #81669 [ run ] completed with state
|
JunyiXu-nv
left a comment
There was a problem hiding this comment.
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.
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]>
…-6858505-r101 Signed-off-by: berryz <[email protected]>
|
/bot run |
|
PR_Github #81968 [ run ] triggered by Bot. Commit: |
|
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. |
|
/bot kill |
|
PR_Github #81988 [ kill ] triggered by Bot. Commit: |
|
/bot run |
|
PR_Github #81968 [ run ] completed with state |
|
PR_Github #81988 [ kill ] completed with state |
|
PR_Github #81991 [ run ] triggered by Bot. Commit: |
|
PR_Github #81991 [ run ] completed with state
|
… 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]>
|
/bot run |
|
PR_Github #82144 [ run ] triggered by Bot. Commit: |
|
PR_Github #82144 [ run ] completed with state |
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), byencoder_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_lenof 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:
max_num_tokens, the Python micro-batch scheduler raised anAssertionError, 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.max_seq_lenbut withinmax_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.encoder_max_num_tokens, when it is set belowmax_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_budgetrejects, at admission, a request whose encoder output length exceeds the smallest of these bounds. TheValueErrornames 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 againstmax_num_tokens, against a smallerencoder_max_num_tokens, and against the cross KV cachemax_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 tol0_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:
test_resource_manager.py,test_py_executor.py,test_py_scheduler.py,test_encoder_executor.py,test_kv_connector_initialization.pyandtest_request_utils.pyintests/unittest/_torch/executor/, plusengine/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.pyandtests/unittest/executor/test_forward_error_survival.py;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_v2andtest_t5_v2_decode_beyond_encoder_length(2 cases);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]andtest_mbart_pytorch_generate_encoder_decoder_end_to_end;test_whisper_pytorch_transcribe_end_to_end,test_whisper_pytorch_block_reuse_requested,test_whisper_pytorch_beam_search(2 cases) andtest_whisper_pytorch_feature_combinations(5 single-GPU cases).Dev Engineer Review
PyExecutor._validate_request_budgetnow rejects a request whose known encoder output length exceeds the smallest applicable token or cross-KV-cache sequence limit.QA Engineer Review
test_t5_encoder_input_above_max_num_tokens_fails_alone[kv-v2]. Test execution results are not established by the available evidence.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 thekv-v2selector.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.