Add tensor IPC transfer mechanism for multimodal data (#32104)
Signed-off-by: Brandon Pelfrey <bpelfrey@nvidia.com> Signed-off-by: Brandon Pelfrey <brandonpelfrey@gmail.com> Signed-off-by: Nick Hill <nickhill123@gmail.com> Co-authored-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
co-authored by
Nick Hill
parent
61e381dcf0
commit
80b70884eb
+25
-1
@@ -14,7 +14,12 @@ import vllm.envs as envs
|
||||
from vllm.config.model_arch import (
|
||||
ModelArchitectureConfig,
|
||||
)
|
||||
from vllm.config.multimodal import MMCacheType, MMEncoderTPMode, MultiModalConfig
|
||||
from vllm.config.multimodal import (
|
||||
MMCacheType,
|
||||
MMEncoderTPMode,
|
||||
MMTensorIPC,
|
||||
MultiModalConfig,
|
||||
)
|
||||
from vllm.config.pooler import PoolerConfig
|
||||
from vllm.config.scheduler import RunnerType
|
||||
from vllm.config.utils import config, getattr_iter
|
||||
@@ -310,6 +315,7 @@ class ModelConfig:
|
||||
interleave_mm_strings: InitVar[bool | None] = None
|
||||
skip_mm_profiling: InitVar[bool | None] = None
|
||||
video_pruning_rate: InitVar[float | None] = None
|
||||
mm_tensor_ipc: InitVar[MMTensorIPC] = None
|
||||
|
||||
def compute_hash(self) -> str:
|
||||
"""
|
||||
@@ -430,6 +436,7 @@ class ModelConfig:
|
||||
interleave_mm_strings: bool | None,
|
||||
skip_mm_profiling: bool | None,
|
||||
video_pruning_rate: float | None,
|
||||
mm_tensor_ipc: MMTensorIPC,
|
||||
) -> None:
|
||||
# Keep set served_model_name before maybe_model_redirect(self.model)
|
||||
self.served_model_name = get_served_model_name(
|
||||
@@ -612,6 +619,7 @@ class ModelConfig:
|
||||
interleave_mm_strings=interleave_mm_strings,
|
||||
skip_mm_profiling=skip_mm_profiling,
|
||||
video_pruning_rate=video_pruning_rate,
|
||||
mm_tensor_ipc=mm_tensor_ipc,
|
||||
)
|
||||
|
||||
mm_config_kwargs = {
|
||||
@@ -1112,6 +1120,22 @@ class ModelConfig:
|
||||
f"({parallel_config.decode_context_parallel_size})."
|
||||
)
|
||||
|
||||
# torch_shm uses a single IPC queue to rank 0; DP>1 is
|
||||
# incompatible because API servers can't know which
|
||||
# CoreEngine the scheduler will assign work to. TP>1 is
|
||||
# also not supported because this requires broadcasting
|
||||
# MM tensors between all TP ranks.
|
||||
if (
|
||||
self.multimodal_config is not None
|
||||
and self.multimodal_config.mm_tensor_ipc == "torch_shm"
|
||||
and parallel_config.world_size_across_dp > 1
|
||||
):
|
||||
raise ValueError(
|
||||
"mm_tensor_ipc='torch_shm' is not supported with "
|
||||
"data_parallel_size > 1 or tensor_parallel_size > 1 "
|
||||
"or pipeline_parallel_size > 1."
|
||||
)
|
||||
|
||||
def get_sliding_window(self) -> int | None:
|
||||
"""Get the sliding window size from the HF text config if present."""
|
||||
return getattr(self.hf_text_config, "sliding_window", None)
|
||||
|
||||
@@ -59,6 +59,7 @@ class MultiModalDummyOptionsBuiltins(TypedDict, total=False):
|
||||
|
||||
MMEncoderTPMode = Literal["weights", "data"]
|
||||
MMCacheType = Literal["shm", "lru"]
|
||||
MMTensorIPC = Literal["direct_rpc", "torch_shm"]
|
||||
MMDummyOptions: TypeAlias = dict[str, BaseDummyOptions]
|
||||
"""
|
||||
A dictionary containing an entry for each modality type of dummy data.
|
||||
@@ -172,6 +173,11 @@ class MultiModalConfig:
|
||||
Value sits in range [0;1) and determines fraction of media tokens
|
||||
from each video to be pruned.
|
||||
"""
|
||||
mm_tensor_ipc: MMTensorIPC = "direct_rpc"
|
||||
"""IPC (inter-process communication) method for multimodal tensors.
|
||||
- "direct_rpc": Use msgspec serialization via RPC
|
||||
- "torch_shm": Use torch.multiprocessing shared memory for zero-copy IPC
|
||||
Defaults to "direct_rpc". """
|
||||
|
||||
@field_validator("limit_per_prompt", mode="before")
|
||||
@classmethod
|
||||
|
||||
@@ -766,6 +766,17 @@ class VllmConfig:
|
||||
else:
|
||||
self.parallel_config.disable_nccl_for_dp_synchronization = False
|
||||
|
||||
if (
|
||||
self.model_config is not None
|
||||
and self.model_config.multimodal_config is not None
|
||||
and self.model_config.multimodal_config.mm_tensor_ipc == "torch_shm"
|
||||
and os.environ.get("VLLM_WORKER_MULTIPROC_METHOD") != "spawn"
|
||||
):
|
||||
raise ValueError(
|
||||
"torch_shm is known to fail without "
|
||||
"VLLM_WORKER_MULTIPROC_METHOD set to spawn"
|
||||
)
|
||||
|
||||
from vllm.platforms import current_platform
|
||||
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user