From 2df4810eeae82b33d8df1b0350bcca290870904f Mon Sep 17 00:00:00 2001 From: Antoni Baum Date: Fri, 28 Jun 2024 15:58:59 -0700 Subject: [PATCH] Optimize SequenceStatus.is_finished by switching to IntEnum --- vllm/sequence.py | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/vllm/sequence.py b/vllm/sequence.py index 13746cef21064..22cb26dc08ef7 100644 --- a/vllm/sequence.py +++ b/vllm/sequence.py @@ -39,24 +39,21 @@ class Logprob: SampleLogprobs = List[Dict[int, Logprob]] -class SequenceStatus(enum.Enum): +class SequenceStatus(enum.IntEnum): """Status of a sequence.""" - WAITING = enum.auto() - RUNNING = enum.auto() - SWAPPED = enum.auto() - FINISHED_STOPPED = enum.auto() - FINISHED_LENGTH_CAPPED = enum.auto() - FINISHED_ABORTED = enum.auto() - FINISHED_IGNORED = enum.auto() + WAITING = 0 + RUNNING = 1 + SWAPPED = 2 + # Note: anything after SWAPPED (2) will be considered + # as a finished status. + FINISHED_STOPPED = 3 + FINISHED_LENGTH_CAPPED = 4 + FINISHED_ABORTED = 5 + FINISHED_IGNORED = 6 @staticmethod def is_finished(status: "SequenceStatus") -> bool: - return status in [ - SequenceStatus.FINISHED_STOPPED, - SequenceStatus.FINISHED_LENGTH_CAPPED, - SequenceStatus.FINISHED_ABORTED, - SequenceStatus.FINISHED_IGNORED, - ] + return status > SequenceStatus.SWAPPED @staticmethod def get_finished_reason(status: "SequenceStatus") -> Union[str, None]: