Skip to content
Closed
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
20 changes: 20 additions & 0 deletions tests/engine/test_stop.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import pytest

from vllm.engine.arg_utils import EngineArgs
from vllm.engine.llm_engine import LLMEngine
from vllm.sampling_params import SamplingParams

PROMPT = '''def print_prime(n):
"""
Print all primes between 1 and n
"""'''


@pytest.mark.parametrize("model", "meta-llama/Llama-2-7b-hf")
@pytest.mark.parametrize("prompt", PROMPT)
@pytest.mark.parametrize("stop", [' ', 'for'])
def test_generate_stop(model, prompt, stop):
engine_args = EngineArgs(model=model, enable_prefix_caching=True)
engine = LLMEngine.from_engine_args(engine_args)
sampling_params = SamplingParams(stop=stop)
engine.add_request("0", prompt, sampling_params)
9 changes: 4 additions & 5 deletions vllm/engine/llm_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -776,11 +776,10 @@ def _finalize_sequence(self, seq: Sequence,
stop_string: str) -> None:
if sampling_params.include_stop_str_in_output:
return

if stop_string and seq.output_text.endswith(stop_string):
# Truncate the output text so that the stop string is
# not included in the output.
seq.output_text = seq.output_text[:-len(stop_string)]
if stop_string:
index = seq.output_text.find(stop_string)
if index >= 0:
seq.output_text = seq.output_text[:index]

def add_lora(self, lora_request: LoRARequest) -> bool:
return self.model_executor.add_lora(lora_request)
Expand Down