From 96c52766c64bbc6feb2655e5471c85b758754bb0 Mon Sep 17 00:00:00 2001 From: jiant <107457950+JadoTu@users.noreply.github.com> Date: Thu, 27 Nov 2025 07:07:16 +0000 Subject: [PATCH 1/2] feat: add eos_token_id in generation_config to SamplingParams._stop_word_ids Signed-off-by: jiant <107457950+JadoTu@users.noreply.github.com> --- tensorrt_llm/sampling_params.py | 40 ++++++++++++++------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/tensorrt_llm/sampling_params.py b/tensorrt_llm/sampling_params.py index c9d6e1f44b2c..97fb399055ac 100644 --- a/tensorrt_llm/sampling_params.py +++ b/tensorrt_llm/sampling_params.py @@ -368,14 +368,6 @@ def _setup( if self.end_id is None: self.end_id = tokenizer.eos_token_id self.pad_id = tokenizer.pad_token_id - # kimi_k2 model uses the eos_token_id in generation config - if ( - hf_model_config is not None - and hf_model_config.model_type == "kimi_k2" - and generation_config is not None - and isinstance(generation_config.eos_token_id, int) - ): - self.end_id = generation_config.eos_token_id if self.pad_id is None: self.pad_id = self.end_id @@ -395,24 +387,26 @@ def _encode(tokenizer, text, add_special_tokens): strs = [self.stop] if isinstance(self.stop, str) else self.stop self._stop_word_ids = [_encode(tokenizer, s, add_special_tokens) for s in strs] - # add generation_config to stop word list, only in qwen3-next now - if ( - hf_model_config is not None - and hf_model_config.model_type == "qwen3_next" - and generation_config is not None - and isinstance(generation_config.eos_token_id, List) - and all(isinstance(i, int) for i in generation_config.eos_token_id) - ): - if self._stop_word_ids: + # Add eos_token_id in generation_config to _stop_word_ids + # Refer to https://huggingface.co/docs/hub/en/transformers#transformers-repository-files and + # https://github.com/huggingface/transformers/blob/1ae4d917ed3badbdb1ffc167e0529f5a6d3c080d/src/transformers/generation/stopping_criteria.py#L451C1-L451C42 + # The eos_token_id in generation_config are really mean to stop the text generation. + if generation_config is not None and generation_config.eos_token_id is not None: + if isinstance(generation_config.eos_token_id, int): + generation_eos_token_ids = [generation_config.eos_token_id] + else: # always List[int] + generation_eos_token_ids = generation_config.eos_token_id + + if self._stop_word_ids is None: + self._stop_word_ids = [generation_eos_token_ids] + else: all_stop_tokens_id = set(i for sublist in self._stop_word_ids for i in sublist) - from_generation_stop_tokens = [ - i for i in generation_config.eos_token_id if i not in all_stop_tokens_id + from_generation_stop_token_ids = [ + i for i in generation_eos_token_ids if i not in all_stop_tokens_id ] - if from_generation_stop_tokens: - self._stop_word_ids.append(from_generation_stop_tokens) - else: - self._stop_word_ids = [generation_config.eos_token_id] + if from_generation_stop_token_ids: + self._stop_word_ids.append(from_generation_stop_token_ids) return self From 3b619dae4a3e85dcb3d07c049460a12ece05bc7c Mon Sep 17 00:00:00 2001 From: jiant <107457950+JadoTu@users.noreply.github.com> Date: Tue, 9 Dec 2025 16:04:55 +0000 Subject: [PATCH 2/2] change prompt of failed test Signed-off-by: jiant <107457950+JadoTu@users.noreply.github.com> --- tests/unittest/llmapi/apps/_test_trtllm_serve_top_logprobs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittest/llmapi/apps/_test_trtllm_serve_top_logprobs.py b/tests/unittest/llmapi/apps/_test_trtllm_serve_top_logprobs.py index d287e5e35eb5..c7a4fc7f1644 100644 --- a/tests/unittest/llmapi/apps/_test_trtllm_serve_top_logprobs.py +++ b/tests/unittest/llmapi/apps/_test_trtllm_serve_top_logprobs.py @@ -110,7 +110,7 @@ async def test_chat_completion_top1_logprobs(async_client: openai.AsyncOpenAI, "content": "You are a helpful assistant." }, { "role": "user", - "content": "What is the capital of France?" + "content": "What is the capital of France? please in detail." }] # Test top_logprobs=1 chat_completion = await async_client.chat.completions.create(