1
1
import time
2
- from typing import List , Optional
2
+ from typing import List , Optional , Union
3
3
4
4
from vllm .lora .request import LoRARequest
5
5
from vllm .sequence import (PromptLogprobs , RequestMetrics , SampleLogprobs ,
@@ -18,6 +18,9 @@ class CompletionOutput:
18
18
logprobs: The log probabilities of the top probability words at each
19
19
position if the logprobs are requested.
20
20
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.
21
24
lora_request: The LoRA request that was used to generate the output.
22
25
"""
23
26
@@ -29,6 +32,7 @@ def __init__(
29
32
cumulative_logprob : float ,
30
33
logprobs : Optional [SampleLogprobs ],
31
34
finish_reason : Optional [str ] = None ,
35
+ stop_reason : Union [int , str , None ] = None ,
32
36
lora_request : Optional [LoRARequest ] = None ,
33
37
) -> None :
34
38
self .index = index
@@ -37,6 +41,7 @@ def __init__(
37
41
self .cumulative_logprob = cumulative_logprob
38
42
self .logprobs = logprobs
39
43
self .finish_reason = finish_reason
44
+ self .stop_reason = stop_reason
40
45
self .lora_request = lora_request
41
46
42
47
def finished (self ) -> bool :
@@ -48,7 +53,8 @@ def __repr__(self) -> str:
48
53
f"token_ids={ self .token_ids } , "
49
54
f"cumulative_logprob={ self .cumulative_logprob } , "
50
55
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 } )" )
52
58
53
59
54
60
class RequestOutput :
@@ -111,8 +117,8 @@ def from_seq_group(cls, seq_group: SequenceGroup) -> "RequestOutput":
111
117
seq .get_output_token_ids (),
112
118
seq .get_cumulative_logprob (),
113
119
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
116
122
]
117
123
118
124
# Every sequence in the sequence group should have the same prompt.
0 commit comments