Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
db521b8
[None][fix] Gracefully fit token budget at prep boundary (#13318)
thorjohnsen Jun 10, 2026
389dffb
[#13318][fix] Re-bin re-chunked context requests in token-budget fall…
thorjohnsen Jun 10, 2026
69c3786
[#13318][fix] Only re-chunk token-budget fallback when chunked prefil…
thorjohnsen Jun 12, 2026
9266f94
[#13318][feat] Make the token-budget fallback an opt-out flag
thorjohnsen Jun 13, 2026
1b0276c
[#13318][fix] Run token-budget fallback before all resource managers
thorjohnsen Jun 15, 2026
84f5094
[#13318][feat] Terminate server on token-budget overshoot when fallba…
thorjohnsen Jun 15, 2026
7acc549
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 15, 2026
1a48dd2
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 16, 2026
1b54bdc
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 16, 2026
d5ced25
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 16, 2026
acdf6d8
[#13318][fix] Keep disagg gen-init requests cost-free in token-budget…
thorjohnsen Jun 16, 2026
608ed30
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 17, 2026
e4b942e
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 18, 2026
0f8bdbc
[#13318][fix] Use correct sparse_attention_config kwarg in cross KV pool
thorjohnsen Jun 18, 2026
e284dd5
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 19, 2026
0b12c82
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 20, 2026
7b89d49
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 21, 2026
691ad29
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 22, 2026
2428bb6
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 25, 2026
6ffec45
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 26, 2026
1737174
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 29, 2026
7322cff
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 29, 2026
29a819a
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jun 30, 2026
8f24266
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jul 6, 2026
705017d
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jul 17, 2026
90e3f5d
[#13318][test] Stub enable_attention_dp in fatal-shutdown unit test
thorjohnsen Jul 17, 2026
65f1ff0
[#13318][chore] Add enable_token_budget_fallback to telemetry golden …
thorjohnsen Jul 17, 2026
84292d5
[#13318][fix] Drop the token-budget opt-out flag and its fatal-shutdo…
thorjohnsen Jul 29, 2026
35d98e7
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jul 31, 2026
9b974fb
[#13318][fix] Drive token-budget fallback from the executor loop
thorjohnsen Jul 31, 2026
db2bd31
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Jul 31, 2026
1a2942c
[#13318][fix] Guard resource_manager in _prepare_and_schedule_batch
thorjohnsen Jul 31, 2026
1e3f516
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Aug 4, 2026
dfd0b6e
[#13318][fix] Move token-budget trim after resource preparation
thorjohnsen Aug 6, 2026
5c63043
[#13318][chore] Correct stale comment on enable_chunked_prefill
thorjohnsen Aug 6, 2026
0cf9cdc
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Aug 6, 2026
b026f50
[#13318][fix] Report the trimmed batch to the KV connector
thorjohnsen Aug 6, 2026
32a5f36
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Aug 10, 2026
9e4b36e
Merge branch 'main' into fix/token-budget-prep-fallback
thorjohnsen Aug 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tensorrt_llm/_torch/pyexecutor/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2554,6 +2554,16 @@ def _create_kv_cache_manager(
# via cache_layer_idx — shared layers use target layer's index for
# get_buffers(). No layer_offsets remapping needed here.

# Propagate the finalized chunked-prefill flag so KVCacheManager.fit_token_budget
# only shrinks context chunks when the attention backend can consume a
# partial context chunk. The flag is read from attn_runtime_features, which
# py_executor_creator finalizes (including the SM-version /
# attention-backend overrides) before build_managers runs.
if isinstance(kv_cache_manager,
KVCacheManager) and model_engine is not None:
kv_cache_manager.enable_chunked_prefill = bool(
model_engine.attn_runtime_features.chunked_prefill)

return kv_cache_manager


Expand Down
45 changes: 36 additions & 9 deletions tensorrt_llm/_torch/pyexecutor/py_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6288,6 +6288,16 @@ def _prepare_disagg_gen_init(self, fitting_disagg_gen_init_requests):
resource_mgr_type].prepare_resources(
disagg_gen_init_to_prepare)

# Reporting this mini-batch to the KV connector used to happen
# inside KVCacheManager.prepare_resources; it now runs after the
# token-budget trim, which this path does not go through. Kept here
# so the connector's per-request state advances exactly as before.
kv_cache_manager = self.resource_manager.resource_managers.get(
ResourceManagerType.KV_CACHE_MANAGER)
if hasattr(kv_cache_manager, "publish_connector_scheduler_output"):
kv_cache_manager.publish_connector_scheduler_output(
disagg_gen_init_to_prepare)

# Trigger KV cache exchange for new disagg_gen_init_requests
self._recv_disagg_gen_cache(fitting_disagg_gen_init_requests)

Expand Down Expand Up @@ -7471,30 +7481,47 @@ def _add_inflight_ids(self, scheduled_requests: ScheduledRequests):
Only requests that sample new tokens should be added to the inflight set since their next iteration depends
on these new tokens, so they should be skipped in the scheduler until the new tokens are generated.
This includes context requests that finish context phase and generation requests.

The inserted ids are recorded on ``scheduled_requests`` so the paired
``_remove_inflight_ids`` erases exactly what was added, rather than
re-deriving the set from a batch that has changed in between. An id left
behind is not recoverable: the scheduler skips inflight ids, so the
request is never scheduled again while still holding its KV blocks and
sequence slot.

This is load-bearing, not defensive. In this loop the next step is
``resource_manager.prepare_resources``, which runs
``ResourceManager.maybe_fit_token_budget`` at its end -- and that can
shrink a context request out of ``context_requests_last_chunk``. By
removal time the batch no longer agrees with what was inserted here.
"""
added: List[int] = []
for req in scheduled_requests.context_requests_last_chunk:
logger.debug(
f"Context request with ID {req.request_id} added to DECODER model inflight set"
)
self.inflight_req_ids.insert(req.request_id)
added.append(req.request_id)
for req in scheduled_requests.generation_requests:
logger.debug(
f"Generation request with ID {req.request_id} added to DECODER model inflight set"
)
self.inflight_req_ids.insert(req.request_id)
added.append(req.request_id)
scheduled_requests.added_inflight_req_ids = added

def _remove_inflight_ids(self, scheduled_requests: ScheduledRequests):
"""Remove request IDs of current sampling requests from self.inflight_req_ids."""
for req in scheduled_requests.context_requests_last_chunk:
logger.debug(
f"Context request with ID {req.request_id} removed from DECODER model inflight set"
)
self.inflight_req_ids.erase(req.request_id)
for req in scheduled_requests.generation_requests:
"""Remove the request IDs this batch added to self.inflight_req_ids.

Erases the ids recorded by ``_add_inflight_ids`` rather than re-deriving
them from the batch, which may have been trimmed since (see there).
"""
for req_id in scheduled_requests.added_inflight_req_ids:
logger.debug(
f"Generation request with ID {req.request_id} removed from DECODER model inflight set"
f"Request with ID {req_id} removed from DECODER model inflight set"
)
self.inflight_req_ids.erase(req.request_id)
self.inflight_req_ids.erase(req_id)
scheduled_requests.added_inflight_req_ids = []

def _handle_speculative_decoding(
self, scheduled_batch, previous_tensors, target_inputs
Expand Down
Loading
Loading