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
b9821967
Unverified
Commit
b9821967
authored
Sep 18, 2025
by
Lukas Geiger
Committed by
GitHub
Sep 17, 2025
Browse files
[Core][MM] Cleanup `MultiModalCache` (#25006)
Signed-off-by:
Lukas Geiger
<
lukas.geiger94@gmail.com
>
parent
32baf1d0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
19 deletions
+6
-19
vllm/multimodal/cache.py
vllm/multimodal/cache.py
+6
-19
No files found.
vllm/multimodal/cache.py
View file @
b9821967
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import
operator
import
sys
import
sys
from
abc
import
ABC
,
abstractmethod
from
abc
import
ABC
,
abstractmethod
from
collections.abc
import
Mapping
,
Sequence
from
collections.abc
import
Mapping
,
Sequence
...
@@ -91,26 +92,15 @@ _V = TypeVar("_V", bound=MultiModalCacheValue)
...
@@ -91,26 +92,15 @@ _V = TypeVar("_V", bound=MultiModalCacheValue)
class
MultiModalCache
:
class
MultiModalCache
:
@
classmethod
@
classmethod
def
get_leaf_size
(
def
get_leaf_size
(
cls
,
leaf
:
object
)
->
int
:
cls
,
leaf
:
object
,
*
,
debug
:
bool
=
False
,
)
->
int
:
if
isinstance
(
leaf
,
MultiModalProcessorCacheItem
):
if
isinstance
(
leaf
,
MultiModalProcessorCacheItem
):
return
cls
.
get_leaf_size
(
leaf
.
item
)
return
cls
.
get_leaf_size
(
leaf
.
item
)
if
isinstance
(
leaf
,
MultiModalProcessorCacheItemMetadata
):
if
isinstance
(
leaf
,
MultiModalProcessorCacheItemMetadata
):
return
leaf
.
item_size
return
leaf
.
item_size
# These are not subclasses of dict
# These are not subclasses of dict
if
isinstance
(
leaf
,
MultiModalKwargsItems
):
if
isinstance
(
leaf
,
(
MultiModalKwargs
,
MultiModalKwargsItems
,
return
cls
.
get_item_size
(
leaf
.
data
)
# type: ignore
MultiModalKwargsItem
,
MultiModalFieldElem
)):
if
isinstance
(
leaf
,
MultiModalKwargsItem
):
return
cls
.
get_item_size
(
leaf
.
data
)
# type: ignore
if
isinstance
(
leaf
,
MultiModalKwargs
):
return
cls
.
get_item_size
(
leaf
.
data
)
# type: ignore
if
isinstance
(
leaf
,
MultiModalFieldElem
):
return
cls
.
get_item_size
(
leaf
.
data
)
# type: ignore
return
cls
.
get_item_size
(
leaf
.
data
)
# type: ignore
# sys.getsizeof doesn't work for tensors
# sys.getsizeof doesn't work for tensors
...
@@ -126,11 +116,8 @@ class MultiModalCache:
...
@@ -126,11 +116,8 @@ class MultiModalCache:
*
,
*
,
debug
:
bool
=
False
,
debug
:
bool
=
False
,
)
->
int
:
)
->
int
:
size
=
json_reduce_leaves
(
size
=
json_reduce_leaves
(
operator
.
add
,
lambda
a
,
b
:
a
+
b
,
json_map_leaves
(
cls
.
get_leaf_size
,
value
))
json_map_leaves
(
lambda
x
:
cls
.
get_leaf_size
(
x
,
debug
=
debug
),
value
),
)
if
debug
:
if
debug
:
leaf_count
=
json_count_leaves
(
value
)
leaf_count
=
json_count_leaves
(
value
)
...
...
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