[V1][Misc] Shorten FinishReason enum and use constant strings (#12760)

This commit is contained in:
Nick Hill
2025-02-04 22:43:02 -08:00
committed by GitHub
parent fcf2e3d7fc
commit 3d09e592a8
5 changed files with 25 additions and 21 deletions
+9 -3
View File
@@ -14,11 +14,17 @@ if TYPE_CHECKING:
from vllm.multimodal.inputs import PlaceholderRange
from vllm.sampling_params import SamplingParams
# These are possible values of RequestOutput.finish_reason,
# so form part of the external API.
FINISH_REASON_STRINGS = ("stop", "length", "abort")
class RequestFinishedReason(enum.IntEnum):
class FinishReason(enum.IntEnum):
"""
Reason a request finished - stop, length, or abort.
Int rather than Str for more compact serialization.
stop - a stop string was emitted
length - max_tokens was consumed, or max_model_len was reached
abort - aborted for another reason
@@ -29,7 +35,7 @@ class RequestFinishedReason(enum.IntEnum):
ABORT = 2
def __str__(self):
return self.name.lower()
return FINISH_REASON_STRINGS[self.value]
@dataclass
@@ -62,7 +68,7 @@ class EngineCoreOutput(
request_id: str
new_token_ids: List[int]
finished: bool
finish_reason: Optional[RequestFinishedReason] = None
finish_reason: Optional[FinishReason] = None
stop_reason: Union[int, str, None] = None