Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions tensorrt_llm/_torch/pyexecutor/model_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ def __init__(

self.kv_cache_dtype_byte_size = self.get_kv_cache_dtype_byte_size()

self._prepare_inputs_event: Optional[torch.cuda.Event] = None

def register_forward_pass_callable(self, callable: Callable):
self.forward_pass_callable = callable

Expand Down Expand Up @@ -4003,6 +4005,8 @@ def forward(self,
new_tensors_device, cache_indirection_buffer,
num_accepted_tokens_device, req_id_to_old_request,
resource_manager, can_run_graph)
self._prepare_inputs_event = torch.cuda.Event()
self._prepare_inputs_event.record()

with with_shared_pool(self.cuda_graph_runner.get_graph_pool()):
if not can_run_graph:
Expand Down Expand Up @@ -4252,3 +4256,11 @@ def _execute_logit_post_processors(self,
lp(request.py_request_id, logits_row, token_ids, None, None)

logits_tensor[idx] = logits_row.view(-1)

def wait_for_input_copy(self):
"""
Wait for input preparation and H2D copy of previous iteration before modifying host input,
otherwise the input of previous iteration will be overwritten.
"""
if self._prepare_inputs_event is not None:
self._prepare_inputs_event.synchronize()
4 changes: 4 additions & 0 deletions tensorrt_llm/_torch/pyexecutor/py_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2718,6 +2718,10 @@ def _executor_loop_overlap(self):

self._handle_disagg_cache_errors_synced()

# Need to wait for the copy of previous iteration before modifying any host memory copied to GPU,
# and for scheduler V2, it will modify the host page table, so wait before scheduling.
# This wait is also needed for legacy scheduler, but it can be pushed later, e.g. before model_engine._prepare_inputs().
self.model_engine.wait_for_input_copy()
scheduled_batch, iter_stats = self._prepare_and_schedule_batch()
self._handle_control_request()

Expand Down
Loading