[feat] use cachebuffer to store mm feature to speedup hash (#14386)
This commit is contained in:
@@ -325,9 +325,32 @@ class MultimodalInputs:
|
||||
|
||||
assert isinstance(ret.mm_items, list)
|
||||
ret.mm_items = [item for item in ret.mm_items if item.is_valid()]
|
||||
|
||||
if envs.SGLANG_MM_BUFFER_SIZE_MB.get() > 0:
|
||||
from sglang.srt.managers.mm_utils import (
|
||||
init_feature_buffer,
|
||||
is_feature_buffer_initialized,
|
||||
reset_buffer_offset,
|
||||
try_add_to_buffer,
|
||||
)
|
||||
|
||||
device = torch.cuda.current_device() if torch.cuda.is_available() else "cpu"
|
||||
if not is_feature_buffer_initialized():
|
||||
init_feature_buffer(device)
|
||||
reset_buffer_offset()
|
||||
for item in ret.mm_items:
|
||||
if item.feature is not None:
|
||||
if isinstance(item.feature, torch.Tensor):
|
||||
item.feature = try_add_to_buffer(item.feature)
|
||||
|
||||
for item in ret.mm_items:
|
||||
item.set_pad_value()
|
||||
|
||||
if envs.SGLANG_MM_BUFFER_SIZE_MB.get() > 0:
|
||||
for item in ret.mm_items:
|
||||
if item.feature is not None:
|
||||
item.feature = item.feature.to("cpu", non_blocking=True)
|
||||
|
||||
optional_args = [
|
||||
"mrope_positions",
|
||||
"mrope_position_delta",
|
||||
|
||||
Reference in New Issue
Block a user