Skip to content

Commit faa80a2

Browse files
Yard1jimpang
authored andcommitted
[Core] Optimize SequenceStatus.is_finished by switching to IntEnum (vllm-project#5974)
1 parent 018cafc commit faa80a2

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

vllm/sequence.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,21 @@ class Logprob:
3939
SampleLogprobs = List[Dict[int, Logprob]]
4040

4141

42-
class SequenceStatus(enum.Enum):
42+
class SequenceStatus(enum.IntEnum):
4343
"""Status of a sequence."""
44-
WAITING = enum.auto()
45-
RUNNING = enum.auto()
46-
SWAPPED = enum.auto()
47-
FINISHED_STOPPED = enum.auto()
48-
FINISHED_LENGTH_CAPPED = enum.auto()
49-
FINISHED_ABORTED = enum.auto()
50-
FINISHED_IGNORED = enum.auto()
44+
WAITING = 0
45+
RUNNING = 1
46+
SWAPPED = 2
47+
# Note: anything after SWAPPED (2) will be considered
48+
# as a finished status.
49+
FINISHED_STOPPED = 3
50+
FINISHED_LENGTH_CAPPED = 4
51+
FINISHED_ABORTED = 5
52+
FINISHED_IGNORED = 6
5153

5254
@staticmethod
5355
def is_finished(status: "SequenceStatus") -> bool:
54-
return status in [
55-
SequenceStatus.FINISHED_STOPPED,
56-
SequenceStatus.FINISHED_LENGTH_CAPPED,
57-
SequenceStatus.FINISHED_ABORTED,
58-
SequenceStatus.FINISHED_IGNORED,
59-
]
56+
return status > SequenceStatus.SWAPPED
6057

6158
@staticmethod
6259
def get_finished_reason(status: "SequenceStatus") -> Union[str, None]:

0 commit comments

Comments
 (0)