Skip to content

[Bug]: SamplingParams with an explicit end_id fails when stop or bad strings are set #21613

Closed

Description

@Anshtyagi1729

System Info

  • TensorRT-LLM main, commit fac0f14 (1.4.0rc3), PyTorch backend
  • Not GPU or model specific: the failure is in the LLM API before the request reaches the engine

Who can help?

No response

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

from tensorrt_llm import LLM, SamplingParams

llm = LLM(model="Qwen/Qwen2.5-0.5B-Instruct")
params = SamplingParams(max_tokens=32, end_id=-1, stop=["\n"])
llm.generate("The capital of France is", params)

Fails with:

SamplingParams.stop (['\n']) is not processed by tokenizer, please call the setup method.

The same happens with bad=[...], and with stop=[], whenever end_id is set.

Expected behavior

Stop and bad strings are applied whether or not end_id is set explicitly.

actual behavior

The request fails with the error above.

additional notes

BaseLLM._prepare_sampling_params (tensorrt_llm/llmapi/llm.py) only calls SamplingParams._setup when end_id is None:

if sampling_params.end_id is None:
    ...
    sampling_params._setup(self.tokenizer, self._hf_model_config, self._generation_config)

_setup fills in the default end_id/pad_id, but it is also the only place that tokenizes stop and bad into _stop_word_ids / _bad_word_ids. With an explicit end_id that tokenization never runs, and _get_stop_words() raises when the worker builds the request.

I have a fix ready: move the stop/bad tokenization into its own method and call it for an explicit end_id too, while the end_id/pad_id/EOS defaults keep applying only when end_id is unset.

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and checked the documentation and examples for answers to frequently asked questions.

Activity

  1. added
    bug
    on Nov 4, 2026
  2. added
    LLM API
    on Nov 4, 2026
  3. added 2 commits that reference this issue on Nov 4, 2026
  4. added a commit that references this issue on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    LLM APIbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions