Repository navigation
Description
System Info
Current main (486bf35). The validation part needs no GPU; the sampler behavior below is from reading the code, not from a GPU run.
Who can help?
LLM API / sampling (code owners of the touched files).
Reproduction
from tensorrt_llm.sampling_params import SamplingParams
SamplingParams(stop="") # accepted
SamplingParams(stop=[""]) # accepted
SamplingParams(stop=["a", ""]) # acceptedCompletionRequest(model="m", prompt="hi", stop=[""]).to_sampling_params(backend="pytorch") and the same for ChatCompletionRequest also pass the empty string through.
Expected behavior
A clear ValueError when the request is built (HTTP 400 on the serve routes). vLLM rejects it ("stop cannot contain an empty string").
actual behavior
SamplingParams._setup encodes the empty string to [], so _get_stop_words() hands the executor a stop word with no tokens. FinishReasonsHandler.prepare_for_new_request (_torch/pyexecutor/sampler/finish_reasons.py) raises ValueError("Stop words must contain at least one token") while the sampler sets up the new request. PyExecutor._sample_async catches the error and calls _handle_errors(error_msg) without a request list (_setup_sampler_step does the same for disaggregated generation requests), which fails every active request and charges the executor's error budget (an exhausted budget is treated as fatal). The raise was added by #20679; TorchSampler.validate_request, which runs at admission and fails only the offending request, does not check stop words. So one request with stop: "" can take other users' in-flight requests down with it.
additional notes
#21614 changes how stop strings are tokenized when end_id is explicit, in _setup, not in _validate. With ignore_eos=True the stop words are not sent to the engine, but the detokenizing result handler still searches the text for each stop string and "" matches at position 0, so such a request returns an empty completion with finish_reason: "stop" (code reading). Strings that a tokenizer encodes to no tokens are not covered by a check in SamplingParams._validate; the admission hook would be the engine-side place. I have a fix with a test and can open a PR.
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
[#22232][fix] Reject an empty stop string in SamplingParams (#22237)