Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
9c71c97a
Unverified
Commit
9c71c97a
authored
Aug 27, 2024
by
Jonathan Berkhahn
Committed by
GitHub
Aug 28, 2024
Browse files
[mypy] Enable mypy type checking for `vllm/core` (#7229)
parent
5340a2dc
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
31 additions
and
18 deletions
+31
-18
.github/workflows/mypy.yaml
.github/workflows/mypy.yaml
+0
-1
format.sh
format.sh
+0
-1
pyproject.toml
pyproject.toml
+1
-0
vllm/block.py
vllm/block.py
+7
-2
vllm/core/block/cpu_gpu_block_allocator.py
vllm/core/block/cpu_gpu_block_allocator.py
+1
-1
vllm/core/block_manager_v1.py
vllm/core/block_manager_v1.py
+4
-3
vllm/core/block_manager_v2.py
vllm/core/block_manager_v2.py
+6
-2
vllm/core/embedding_model_block_manager.py
vllm/core/embedding_model_block_manager.py
+2
-2
vllm/core/scheduler.py
vllm/core/scheduler.py
+10
-6
No files found.
.github/workflows/mypy.yaml
View file @
9c71c97a
...
@@ -35,7 +35,6 @@ jobs:
...
@@ -35,7 +35,6 @@ jobs:
mypy
mypy
mypy tests --follow-imports skip
mypy tests --follow-imports skip
mypy vllm/attention --follow-imports skip
mypy vllm/attention --follow-imports skip
mypy vllm/core --follow-imports skip
mypy vllm/distributed --follow-imports skip
mypy vllm/distributed --follow-imports skip
mypy vllm/engine --follow-imports skip
mypy vllm/engine --follow-imports skip
mypy vllm/executor --follow-imports skip
mypy vllm/executor --follow-imports skip
...
...
format.sh
View file @
9c71c97a
...
@@ -99,7 +99,6 @@ echo 'vLLM mypy:'
...
@@ -99,7 +99,6 @@ echo 'vLLM mypy:'
mypy
--follow-imports
skip
# Note that this is less strict than CI
mypy
--follow-imports
skip
# Note that this is less strict than CI
mypy tests
--follow-imports
skip
mypy tests
--follow-imports
skip
mypy vllm/attention
--follow-imports
skip
mypy vllm/attention
--follow-imports
skip
mypy vllm/core
--follow-imports
skip
mypy vllm/distributed
--follow-imports
skip
mypy vllm/distributed
--follow-imports
skip
mypy vllm/engine
--follow-imports
skip
mypy vllm/engine
--follow-imports
skip
mypy vllm/executor
--follow-imports
skip
mypy vllm/executor
--follow-imports
skip
...
...
pyproject.toml
View file @
9c71c97a
...
@@ -58,6 +58,7 @@ files = [
...
@@ -58,6 +58,7 @@ files = [
"vllm/adapter_commons"
,
"vllm/adapter_commons"
,
"vllm/assets"
,
"vllm/assets"
,
"vllm/entrypoints"
,
"vllm/entrypoints"
,
"vllm/core"
,
"vllm/inputs"
,
"vllm/inputs"
,
"vllm/logging"
,
"vllm/logging"
,
"vllm/multimodal"
,
"vllm/multimodal"
,
...
...
vllm/block.py
View file @
9c71c97a
"""Token blocks."""
"""Token blocks."""
from
typing
import
List
,
Optional
from
typing
import
TYPE_CHECKING
,
Iterator
,
List
,
Optional
from
vllm.utils
import
Device
from
vllm.utils
import
Device
DEFAULT_LAST_ACCESSED_TIME
=
-
1
DEFAULT_LAST_ACCESSED_TIME
:
float
=
-
1
class
PhysicalTokenBlock
:
class
PhysicalTokenBlock
:
...
@@ -59,6 +59,11 @@ class BlockTable:
...
@@ -59,6 +59,11 @@ class BlockTable:
def
__getitem__
(
self
,
key
):
def
__getitem__
(
self
,
key
):
return
self
.
_blocks
[
key
]
return
self
.
_blocks
[
key
]
if
TYPE_CHECKING
:
def
__iter__
(
self
)
->
Iterator
[
PhysicalTokenBlock
]:
raise
RuntimeError
(
"Method should be automatically generated"
)
def
__setitem__
(
self
,
key
,
value
):
def
__setitem__
(
self
,
key
,
value
):
if
isinstance
(
key
,
slice
):
if
isinstance
(
key
,
slice
):
blocks
=
value
blocks
=
value
...
...
vllm/core/block/cpu_gpu_block_allocator.py
View file @
9c71c97a
...
@@ -132,7 +132,7 @@ class CpuGpuBlockAllocator(DeviceAwareBlockAllocator):
...
@@ -132,7 +132,7 @@ class CpuGpuBlockAllocator(DeviceAwareBlockAllocator):
def
allocate_immutable_blocks
(
self
,
prev_block
:
Optional
[
Block
],
def
allocate_immutable_blocks
(
self
,
prev_block
:
Optional
[
Block
],
block_token_ids
:
List
[
List
[
int
]],
block_token_ids
:
List
[
List
[
int
]],
device
:
Optional
[
Device
]
)
->
List
[
Block
]:
device
:
Device
)
->
List
[
Block
]:
"""Allocates a new group of immutable blocks with the provided block
"""Allocates a new group of immutable blocks with the provided block
token IDs on the specified device.
token IDs on the specified device.
...
...
vllm/core/block_manager_v1.py
View file @
9c71c97a
...
@@ -278,7 +278,7 @@ class BlockSpaceManagerV1(BlockSpaceManager):
...
@@ -278,7 +278,7 @@ class BlockSpaceManagerV1(BlockSpaceManager):
# request ID
# request ID
self
.
cross_block_tables
:
Dict
[
str
,
BlockTable
]
=
{}
self
.
cross_block_tables
:
Dict
[
str
,
BlockTable
]
=
{}
def
_get_seq_num_required_blocks
(
self
,
seq
:
Sequence
)
->
int
:
def
_get_seq_num_required_blocks
(
self
,
seq
:
Optional
[
Sequence
]
)
->
int
:
return
0
if
seq
is
None
else
seq
.
n_blocks
return
0
if
seq
is
None
else
seq
.
n_blocks
def
can_allocate
(
self
,
seq_group
:
SequenceGroup
)
->
AllocStatus
:
def
can_allocate
(
self
,
seq_group
:
SequenceGroup
)
->
AllocStatus
:
...
@@ -310,13 +310,14 @@ class BlockSpaceManagerV1(BlockSpaceManager):
...
@@ -310,13 +310,14 @@ class BlockSpaceManagerV1(BlockSpaceManager):
return
AllocStatus
.
LATER
return
AllocStatus
.
LATER
def
_allocate_sequence
(
self
,
\
def
_allocate_sequence
(
self
,
\
seq
:
Sequence
,
\
seq
:
Optional
[
Sequence
]
,
\
ref_count
:
int
,
\
ref_count
:
int
,
\
is_encoder_decoder
:
bool
=
True
)
->
BlockTable
:
is_encoder_decoder
:
bool
=
True
)
->
BlockTable
:
# Allocate new physical token blocks that will store the prompt tokens.
# Allocate new physical token blocks that will store the prompt tokens.
num_prompt_blocks
=
se
q
.
n
_blocks
num_prompt_blocks
=
se
lf
.
_get_seq_num_required
_blocks
(
seq
)
block_table
:
BlockTable
=
BlockTable
()
block_table
:
BlockTable
=
BlockTable
()
assert
seq
is
not
None
for
logical_idx
in
range
(
num_prompt_blocks
):
for
logical_idx
in
range
(
num_prompt_blocks
):
if
(
self
.
block_sliding_window
is
not
None
if
(
self
.
block_sliding_window
is
not
None
and
logical_idx
>=
self
.
block_sliding_window
):
and
logical_idx
>=
self
.
block_sliding_window
):
...
...
vllm/core/block_manager_v2.py
View file @
9c71c97a
...
@@ -120,8 +120,10 @@ class BlockSpaceManagerV2(BlockSpaceManager):
...
@@ -120,8 +120,10 @@ class BlockSpaceManagerV2(BlockSpaceManager):
)
)
if
seq_group
.
is_encoder_decoder
():
if
seq_group
.
is_encoder_decoder
():
encoder_seq
=
seq_group
.
get_encoder_seq
()
assert
encoder_seq
is
not
None
num_required_blocks
+=
BlockTable
.
get_num_required_blocks
(
num_required_blocks
+=
BlockTable
.
get_num_required_blocks
(
seq_group
.
get_
encoder_seq
()
.
get_token_ids
(),
encoder_seq
.
get_token_ids
(),
block_size
=
self
.
block_size
,
block_size
=
self
.
block_size
,
)
)
...
@@ -189,7 +191,9 @@ class BlockSpaceManagerV2(BlockSpaceManager):
...
@@ -189,7 +191,9 @@ class BlockSpaceManagerV2(BlockSpaceManager):
check_no_caching_or_swa_for_blockmgr_encdec
(
self
,
seq_group
)
check_no_caching_or_swa_for_blockmgr_encdec
(
self
,
seq_group
)
if
seq_group
.
is_encoder_decoder
():
if
seq_group
.
is_encoder_decoder
():
block_table
=
self
.
_allocate_sequence
(
seq_group
.
get_encoder_seq
())
encoder_seq
=
seq_group
.
get_encoder_seq
()
assert
encoder_seq
is
not
None
block_table
=
self
.
_allocate_sequence
(
encoder_seq
)
self
.
cross_block_tables
[
request_id
]
=
block_table
self
.
cross_block_tables
[
request_id
]
=
block_table
def
can_append_slots
(
self
,
seq_group
:
SequenceGroup
,
def
can_append_slots
(
self
,
seq_group
:
SequenceGroup
,
...
...
vllm/core/embedding_model_block_manager.py
View file @
9c71c97a
...
@@ -77,8 +77,8 @@ class EmbeddingModelBlockSpaceManager(BlockSpaceManager):
...
@@ -77,8 +77,8 @@ class EmbeddingModelBlockSpaceManager(BlockSpaceManager):
pass
pass
def
get_common_computed_block_ids
(
self
,
def
get_common_computed_block_ids
(
self
,
seq_group
:
Sequence
Group
)
->
List
[
int
]:
seq_group
:
List
[
Sequence
]
)
->
List
[
int
]:
return
None
# type: ignore
return
[]
def
mark_blocks_as_computed
(
self
,
seq_group
:
SequenceGroup
):
def
mark_blocks_as_computed
(
self
,
seq_group
:
SequenceGroup
):
pass
pass
...
...
vllm/core/scheduler.py
View file @
9c71c97a
...
@@ -221,10 +221,10 @@ class SchedulerSwappedInOutputs:
...
@@ -221,10 +221,10 @@ class SchedulerSwappedInOutputs:
"""
"""
# Selected sequences that are going to be swapped in and is in a
# Selected sequences that are going to be swapped in and is in a
# decoding phase.
# decoding phase.
decode_seq_groups
:
List
[
SequenceGroup
]
decode_seq_groups
:
List
[
Scheduled
SequenceGroup
]
# Selected sequences that are going to be swapped in and in a prefill
# Selected sequences that are going to be swapped in and in a prefill
# phase. I.e., it means the prefill has been chunked.
# phase. I.e., it means the prefill has been chunked.
prefill_seq_groups
:
List
[
SequenceGroup
]
prefill_seq_groups
:
List
[
Scheduled
SequenceGroup
]
# The blocks to swap in.
# The blocks to swap in.
blocks_to_swap_in
:
List
[
Tuple
[
int
,
int
]]
blocks_to_swap_in
:
List
[
Tuple
[
int
,
int
]]
# The blocks to copy.
# The blocks to copy.
...
@@ -254,7 +254,7 @@ class SchedulerPrefillOutputs:
...
@@ -254,7 +254,7 @@ class SchedulerPrefillOutputs:
to be recomputed from scratch.
to be recomputed from scratch.
"""
"""
# Selected sequences for prefill.
# Selected sequences for prefill.
seq_groups
:
List
[
SequenceGroup
]
seq_groups
:
List
[
Scheduled
SequenceGroup
]
# Ignored sequence groups.
# Ignored sequence groups.
ignored_seq_groups
:
List
[
SequenceGroup
]
ignored_seq_groups
:
List
[
SequenceGroup
]
num_lookahead_slots
:
int
num_lookahead_slots
:
int
...
@@ -289,7 +289,9 @@ def scheduler_running_outputs_builder():
...
@@ -289,7 +289,9 @@ def scheduler_running_outputs_builder():
def
scheduled_seq_group_builder
():
def
scheduled_seq_group_builder
():
return
ScheduledSequenceGroup
(
seq_group
=
None
,
token_chunk_size
=
0
)
return
ScheduledSequenceGroup
(
SequenceGroup
(
""
,
[],
-
1
),
token_chunk_size
=
0
)
# return ScheduledSequenceGroup(seq_group=None, token_chunk_size=0)
class
Scheduler
:
class
Scheduler
:
...
@@ -791,7 +793,7 @@ class Scheduler:
...
@@ -791,7 +793,7 @@ class Scheduler:
SchedulerPrefillOutputs.
SchedulerPrefillOutputs.
"""
"""
ignored_seq_groups
:
List
[
SequenceGroup
]
=
[]
ignored_seq_groups
:
List
[
SequenceGroup
]
=
[]
seq_groups
:
List
[
SequenceGroup
]
=
[]
seq_groups
:
List
[
Scheduled
SequenceGroup
]
=
[]
waiting_queue
=
self
.
waiting
waiting_queue
=
self
.
waiting
...
@@ -1130,7 +1132,9 @@ class Scheduler:
...
@@ -1130,7 +1132,9 @@ class Scheduler:
if
seq_group
.
is_encoder_decoder
():
if
seq_group
.
is_encoder_decoder
():
# Encoder associated with SequenceGroup
# Encoder associated with SequenceGroup
encoder_seq_data
=
seq_group
.
get_encoder_seq
().
data
encoder_seq
=
seq_group
.
get_encoder_seq
()
assert
encoder_seq
is
not
None
encoder_seq_data
=
encoder_seq
.
data
# Block table for cross-attention
# Block table for cross-attention
# Also managed at SequenceGroup level
# Also managed at SequenceGroup level
cross_block_table
=
self
.
block_manager
.
get_cross_block_table
(
cross_block_table
=
self
.
block_manager
.
get_cross_block_table
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment