[Feature] Add VidCom2 video token pruning (#47750)
Signed-off-by: Benedikt Falk <bfalk@nvidia.com>
This commit is contained in:
@@ -376,6 +376,7 @@ class ModelConfig:
|
||||
interleave_mm_strings: InitVar[bool | None] = None
|
||||
skip_mm_profiling: InitVar[bool | None] = None
|
||||
video_pruning_rate: InitVar[float | None] = None
|
||||
video_pruning_method: InitVar[str | None] = None
|
||||
mm_tensor_ipc: InitVar[MMTensorIPC] = None
|
||||
mm_ipc_gpu_memory_gb: InitVar[float | None] = None
|
||||
|
||||
@@ -504,6 +505,7 @@ class ModelConfig:
|
||||
interleave_mm_strings: bool | None,
|
||||
skip_mm_profiling: bool | None,
|
||||
video_pruning_rate: float | None,
|
||||
video_pruning_method: str | None,
|
||||
mm_tensor_ipc: MMTensorIPC,
|
||||
mm_ipc_gpu_memory_gb: float | None,
|
||||
) -> None:
|
||||
@@ -735,6 +737,7 @@ class ModelConfig:
|
||||
interleave_mm_strings=interleave_mm_strings,
|
||||
skip_mm_profiling=skip_mm_profiling,
|
||||
video_pruning_rate=video_pruning_rate,
|
||||
video_pruning_method=video_pruning_method,
|
||||
mm_tensor_ipc=mm_tensor_ipc,
|
||||
mm_ipc_gpu_memory_gb=mm_ipc_gpu_memory_gb,
|
||||
)
|
||||
@@ -745,6 +748,19 @@ class ModelConfig:
|
||||
|
||||
self.multimodal_config = MultiModalConfig(**mm_config_kwargs) # type: ignore[arg-type]
|
||||
|
||||
pruning_spec = self.multimodal_config.get_video_pruning_spec()
|
||||
supported_pruning = self._model_info.supported_video_pruning_methods
|
||||
if (
|
||||
pruning_spec is not None
|
||||
and supported_pruning
|
||||
and pruning_spec[0] not in supported_pruning
|
||||
):
|
||||
raise ValueError(
|
||||
f"Video pruning method '{pruning_spec[0]}' is not "
|
||||
f"supported by {self._model_info.architecture} "
|
||||
f"(supported methods: {supported_pruning})."
|
||||
)
|
||||
|
||||
if (
|
||||
self.renderer_num_workers > 1
|
||||
and self.multimodal_config.mm_processor_cache_gb > 0
|
||||
|
||||
@@ -61,6 +61,7 @@ class MultiModalDummyOptionsBuiltins(TypedDict, total=False):
|
||||
|
||||
MMEncoderTPMode = Literal["weights", "data"]
|
||||
MMCacheType = Literal["shm", "lru"]
|
||||
VideoPruningMethod = Literal["evs", "vidcom2"]
|
||||
MMTensorIPC = Literal["direct_rpc", "torch_shm"]
|
||||
MMDummyOptions: TypeAlias = dict[str, BaseDummyOptions]
|
||||
"""
|
||||
@@ -189,9 +190,14 @@ class MultiModalConfig:
|
||||
estimating the peak memory usage of the activation of multimodal encoder and
|
||||
embedding cache."""
|
||||
video_pruning_rate: float | None = Field(default=None, ge=0.0, lt=1.0)
|
||||
"""Sets pruning rate for video pruning via Efficient Video Sampling.
|
||||
Value sits in range [0;1) and determines fraction of media tokens
|
||||
from each video to be pruned.
|
||||
"""Fraction of video tokens to prune from each video. Value sits in range
|
||||
[0;1); pruning is enabled when it is greater than 0. The pruning algorithm
|
||||
is selected by `video_pruning_method`.
|
||||
"""
|
||||
video_pruning_method: VideoPruningMethod = "evs"
|
||||
"""Video token pruning algorithm applied when `video_pruning_rate` > 0:
|
||||
- "evs": Efficient Video Sampling.
|
||||
- "vidcom2": Video Compression Commander.
|
||||
"""
|
||||
mm_tensor_ipc: MMTensorIPC = "direct_rpc"
|
||||
"""IPC (inter-process communication) method for multimodal tensors.
|
||||
@@ -360,4 +366,11 @@ class MultiModalConfig:
|
||||
)
|
||||
|
||||
def is_multimodal_pruning_enabled(self):
|
||||
return self.video_pruning_rate is not None and self.video_pruning_rate > 0
|
||||
return self.get_video_pruning_spec() is not None
|
||||
|
||||
def get_video_pruning_spec(self) -> tuple[VideoPruningMethod, float] | None:
|
||||
"""Return `(method, rate)` when video pruning is enabled, else None.
|
||||
`rate` is the fraction of video tokens to prune."""
|
||||
if self.video_pruning_rate is not None and self.video_pruning_rate > 0:
|
||||
return (self.video_pruning_method, float(self.video_pruning_rate))
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user