From e9ecaf25b01c505a38bb6fcad6cc2e0f51ff5b80 Mon Sep 17 00:00:00 2001 From: trtllm-agent <296075020+trtllm-agent@users.noreply.github.com> Date: Wed, 8 Jul 2026 12:15:42 -0700 Subject: [PATCH] [nvbugs/6428087][fix] Propagate use_host_stop_criteria across PP ranks The greedy host stop-criteria optimization (PR #15920) added a per-batch flag `use_host_stop_criteria` on `SampleStateTorch` that gates whether `update_requests` uses the host fast path or calls `process_draft_tokens`. In the PP execution loop, `SampleStateTorch` is constructed on non-last PP ranks via `_forward_step_inter_pp` without setting this flag, and only `sample_state.host` and per-request result diffs are shipped via ring send/recv from the last PP rank. Consequently, when the last PP rank determined `use_host_stop_criteria=True` and therefore skipped writing finish_reasons, earlier PP ranks still saw the default False and entered `process_draft_tokens`, which then indexed an empty finish_reasons list and raised `IndexError: list index out of range` from `finish_if_reason`. Extend the PP send payload with the flag (backward-compatible: recv accepts both 2- and 3-tuple payloads, and send only appends the flag when the sampler exposes the attribute) so that all ranks pick the same branch. Also remove the associated waiver. Signed-off-by: trtllm-agent <296075020+trtllm-agent@users.noreply.github.com> --- tensorrt_llm/_torch/pyexecutor/py_executor.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tensorrt_llm/_torch/pyexecutor/py_executor.py b/tensorrt_llm/_torch/pyexecutor/py_executor.py index 4f0fac787c03..78b314b0a065 100644 --- a/tensorrt_llm/_torch/pyexecutor/py_executor.py +++ b/tensorrt_llm/_torch/pyexecutor/py_executor.py @@ -3264,10 +3264,15 @@ def _ring_broadcast_sample_state( if not self.dist.is_last_pp_rank: # Receive tokens from previous pp rank (w.r.t model forward direction) with nvtx_range("recv_sample_state"): - sample_state.host, py_result_diffs = self.dist.recv_object( + # SampleStateTorch carries a ``use_host_stop_criteria`` flag + # decided on the last PP rank; propagate it so ``update_requests`` + # picks the same branch on all ranks. Other samplers ship None. + sample_state.host, py_result_diffs, use_host_stop_criteria = self.dist.recv_object( src=self.dist.prev_pp_rank, tag=tag, ) + if use_host_stop_criteria is not None: + sample_state.use_host_stop_criteria = use_host_stop_criteria for request, py_result_diff in zip(requests, py_result_diffs): request.py_result.apply_diff(py_result_diff) @@ -3285,7 +3290,8 @@ def _ring_broadcast_sample_state( self.wait_on_pp_send_handles(self.send_handles, microbatch_id) with nvtx_range("send_sample_state"): self.send_handles[microbatch_id] = self.dist.isend_object( - (sample_state.host, py_result_diffs), + (sample_state.host, py_result_diffs, + getattr(sample_state, "use_host_stop_criteria", None)), dest=self.dist.next_pp_rank, tag=tag, )