Skip to content

Overlap: Skip last iter on length #5211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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
50 changes: 27 additions & 23 deletions tensorrt_llm/_torch/pyexecutor/py_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,30 +1051,32 @@ def _executor_loop_overlap(self):
# the generation requests always have batch_idx.
scheduled_batch.generation_requests = sorted( # stable sort
scheduled_batch.generation_requests,
key=lambda req: int(req.py_batch_idx is not None),
key=lambda req:
int(req.py_batch_idx is not None and req.
py_decoding_iter + 1 < req.py_max_new_tokens),
)
if scheduled_batch.batch_size > 0:
if self.kv_cache_transceiver:
# For generation requests which have completed KV cache transfer
self._prepare_disagg_gen_transmission_complete(
scheduled_batch)

if self.kv_cache_transceiver:
# For generation requests which have completed KV cache transfer
self._prepare_disagg_gen_transmission_complete(
scheduled_batch)
# Return the first token to the client
self._handle_first_token_response(scheduled_batch)

# Return the first token to the client
self._handle_first_token_response(scheduled_batch)

previous_tensors_device = self.previous_batch and self.previous_batch.sample_state.device
previous_tensors_device = self.previous_batch and self.previous_batch.sample_state.device

batch_outputs = self._forward_step(scheduled_batch,
previous_tensors_device)
batch_outputs = self._forward_step(
scheduled_batch, previous_tensors_device)

sample_state = self._sample_async(scheduled_batch,
batch_outputs)
sample_state = self._sample_async(
scheduled_batch, batch_outputs)

self._update_request_states(scheduled_batch)
self._update_request_states(scheduled_batch)

ctx_transmission_reqs = self._send_disagg_ctx_cache(
scheduled_batch.context_requests
) if self.kv_cache_transceiver else []
ctx_transmission_reqs = self._send_disagg_ctx_cache(
scheduled_batch.context_requests
) if self.kv_cache_transceiver else []

has_previous_batch = self.previous_batch is not None
if has_previous_batch:
Expand All @@ -1097,12 +1099,14 @@ def _executor_loop_overlap(self):
if self.enable_iter_perf_stats:
iter_stats.inflight_batching_stats.num_ctx_tokens = self.model_engine.iter_states[
'num_ctx_tokens']

self.previous_batch = BatchState(
sample_state=sample_state,
iter_start_time=iter_start_time,
iter_stats=iter_stats,
ctx_transmission_reqs=ctx_transmission_reqs)
if scheduled_batch.batch_size > 0:
self.previous_batch = BatchState(
sample_state=sample_state,
iter_start_time=iter_start_time,
iter_stats=iter_stats,
ctx_transmission_reqs=ctx_transmission_reqs)
else:
self.previous_batch = None

if self.kv_cache_transceiver and self.ctx_in_transmission_requests:
self._terminate_ctx_finished_requests()
Expand Down