11import time
2- from typing import List , Optional
2+ from typing import List , Optional , Union
33
44from vllm .lora .request import LoRARequest
55from vllm .sequence import (PromptLogprobs , RequestMetrics , SampleLogprobs ,
@@ -18,6 +18,9 @@ class CompletionOutput:
1818 logprobs: The log probabilities of the top probability words at each
1919 position if the logprobs are requested.
2020 finish_reason: The reason why the sequence is finished.
21+ stop_reason: The stop string or token id that caused the completion
22+ to stop, None if the completion finished for some other reason
23+ including encountering the EOS token.
2124 lora_request: The LoRA request that was used to generate the output.
2225 """
2326
@@ -29,6 +32,7 @@ def __init__(
2932 cumulative_logprob : float ,
3033 logprobs : Optional [SampleLogprobs ],
3134 finish_reason : Optional [str ] = None ,
35+ stop_reason : Union [int , str , None ] = None ,
3236 lora_request : Optional [LoRARequest ] = None ,
3337 ) -> None :
3438 self .index = index
@@ -37,6 +41,7 @@ def __init__(
3741 self .cumulative_logprob = cumulative_logprob
3842 self .logprobs = logprobs
3943 self .finish_reason = finish_reason
44+ self .stop_reason = stop_reason
4045 self .lora_request = lora_request
4146
4247 def finished (self ) -> bool :
@@ -48,7 +53,8 @@ def __repr__(self) -> str:
4853 f"token_ids={ self .token_ids } , "
4954 f"cumulative_logprob={ self .cumulative_logprob } , "
5055 f"logprobs={ self .logprobs } , "
51- f"finish_reason={ self .finish_reason } )" )
56+ f"finish_reason={ self .finish_reason } , "
57+ f"stop_reason={ self .stop_reason } )" )
5258
5359
5460class RequestOutput :
@@ -111,8 +117,8 @@ def from_seq_group(cls, seq_group: SequenceGroup) -> "RequestOutput":
111117 seq .get_output_token_ids (),
112118 seq .get_cumulative_logprob (),
113119 seq .output_logprobs if include_logprobs else None ,
114- SequenceStatus .get_finished_reason (seq .status ))
115- for seq in top_n_seqs
120+ SequenceStatus .get_finished_reason (seq .status ),
121+ seq . stop_reason ) for seq in top_n_seqs
116122 ]
117123
118124 # Every sequence in the sequence group should have the same prompt.
0 commit comments