[Mini-VLLM] Remove orphan subsystems: snapshot, CPU workers, dead decoders
- Delete the snapshot package, CLI command, and its launch tests - Delete CPU workers, cpu_communicator, and the hw_agnostic layer package - Delete the EC CPU connector, keeping the EC base glue intact - Delete dead composite/triton_flashinfer backends and third_party/flashmla - Delete dead video decoders, video-bound tests, and orphan utils - Remove the deep_gemm_mega_moe option and dead allreduce fusion pair Co-authored-by: Hinata <hinata@idihore.id> Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
@@ -195,7 +195,6 @@ class VideoLoader:
|
||||
|
||||
|
||||
VIDEO_LOADER_REGISTRY = VideoLoaderRegistry()
|
||||
VIDEO_LOADER_REGISTRY.register_gpu_codec("deepstream")
|
||||
|
||||
|
||||
@VIDEO_LOADER_REGISTRY.register("opencv")
|
||||
|
||||
@@ -12,24 +12,15 @@ from .base import (
|
||||
check_frame_pixel_limit,
|
||||
)
|
||||
|
||||
VideoDecoderBackend = Literal["opencv", "torchcodec", "pynvvideocodec", "deepstream"]
|
||||
VideoDecoderBackend = Literal["opencv", "pynvvideocodec"]
|
||||
|
||||
_BACKEND_OPTION_DEFAULTS: dict[str, dict[str, Any]] = {
|
||||
"opencv": {},
|
||||
"torchcodec": {
|
||||
"num_ffmpeg_threads": 0,
|
||||
"seek_mode": "exact",
|
||||
"device": "cpu",
|
||||
},
|
||||
PYNVVIDEOCODEC_VIDEO_BACKEND: {
|
||||
"hw_decoders": PYNVVIDEOCODEC_DEFAULT_HW_DECODERS,
|
||||
"max_width": None,
|
||||
"max_height": None,
|
||||
},
|
||||
"deepstream": {
|
||||
"pool_size": None,
|
||||
"timeout_sec": 120.0,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,151 +0,0 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import threading
|
||||
from typing import Any, ClassVar
|
||||
|
||||
import numpy.typing as npt
|
||||
|
||||
from vllm.logger import init_logger
|
||||
|
||||
from .base import VideoSourceMetadata, VideoTargetMetadata, check_frame_pixel_limit
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
def decode_deepstream(
|
||||
loader_cls,
|
||||
data: bytes,
|
||||
target: VideoTargetMetadata,
|
||||
sampling_kwargs: dict,
|
||||
*,
|
||||
pool_size: int | None = None,
|
||||
timeout_sec: float = 120.0,
|
||||
) -> tuple[npt.NDArray, VideoSourceMetadata, list[int], list[int]]:
|
||||
from nvidia.deepstream_videodecode import probe_metadata
|
||||
|
||||
total_frames, original_fps, duration, _width, _height, codec = probe_metadata(data)
|
||||
check_frame_pixel_limit(_width, _height)
|
||||
source = loader_cls._prepare_source(
|
||||
VideoSourceMetadata(total_frames, original_fps, duration)
|
||||
)
|
||||
frame_idx = loader_cls.compute_frames_index_to_sample(
|
||||
source=source, target=target, **sampling_kwargs
|
||||
)
|
||||
frames, valid = DeepStreamVideoBackendMixin.decode_indices(
|
||||
data,
|
||||
frame_idx,
|
||||
source,
|
||||
codec=codec,
|
||||
pool_size=pool_size,
|
||||
timeout_sec=timeout_sec,
|
||||
)
|
||||
return frames, source, frame_idx, valid
|
||||
|
||||
|
||||
class DeepStreamVideoBackendMixin:
|
||||
"""NVIDIA DeepStream (NVDEC) GPU-decode codec utilities.
|
||||
|
||||
Decoding runs on a shared pool of daemon threads inside one CUDA
|
||||
context (see the ``nvidia-deepstream-videodecode-cu13`` package). The
|
||||
container bytes are pushed into an ``appsrc`` GStreamer pipeline, so no
|
||||
local file path is required — HTTP and base64 sources decode identically
|
||||
to local files.
|
||||
|
||||
Like the OpenCV mixin, this provides only the codec layer.
|
||||
Frame *selection* lives in the loader's
|
||||
``compute_frames_index_to_sample`` and arrives here as an explicit
|
||||
list of frame indices.
|
||||
"""
|
||||
|
||||
# Process-wide lazy decode pool, shared across all DeepStream backends.
|
||||
_pool: ClassVar[Any] = None
|
||||
_pool_lock: ClassVar[Any] = None
|
||||
|
||||
@classmethod
|
||||
def _get_pool(cls, pool_size: int | None = None):
|
||||
"""Lazy-initialize the shared decode pool on first use.
|
||||
|
||||
``pool_size`` (number of decode worker threads) comes from
|
||||
``--media-io-kwargs`` (``{"video": {"pool_size": N}}``); when unset it
|
||||
defaults to the existing ``VLLM_MEDIA_LOADING_THREAD_COUNT`` so no
|
||||
DeepStream-specific env var is needed. The pool is a process-wide
|
||||
singleton, so the first decode's value wins.
|
||||
"""
|
||||
if cls._pool is not None:
|
||||
return cls._pool
|
||||
if cls._pool_lock is None:
|
||||
cls._pool_lock = threading.Lock()
|
||||
with cls._pool_lock:
|
||||
if cls._pool is not None:
|
||||
return cls._pool
|
||||
import os
|
||||
|
||||
from nvidia.deepstream_videodecode import DecodePool
|
||||
|
||||
if pool_size is None:
|
||||
pool_size = int(os.environ.get("VLLM_MEDIA_LOADING_THREAD_COUNT", 8))
|
||||
pool_size = max(1, min(int(pool_size), 16))
|
||||
logger.info(
|
||||
"[DeepStream] initializing decode pool with %d workers",
|
||||
pool_size,
|
||||
)
|
||||
cls._pool = DecodePool(num_workers=pool_size)
|
||||
return cls._pool
|
||||
|
||||
@classmethod
|
||||
def decode_indices(
|
||||
cls,
|
||||
data: bytes,
|
||||
frame_indices: list[int],
|
||||
source: VideoSourceMetadata,
|
||||
codec: str = "",
|
||||
pool_size: int | None = None,
|
||||
timeout_sec: float = 120.0,
|
||||
) -> tuple[npt.NDArray, list[int]]:
|
||||
"""Decode the requested frame indices from raw container bytes.
|
||||
|
||||
The whole stream is decoded; the pool keeps exactly the frames whose
|
||||
decode-order index is in ``frame_indices`` (1:1, frame-exact) and
|
||||
sends EOS once the last one is matched.
|
||||
|
||||
``codec`` (e.g. ``"h264"``/``"hevc"``) lets the pool keep its NVDEC
|
||||
session warm across same-codec streams and rebuild only on a codec
|
||||
change. Frames are returned as a CPU NHWC uint8 array so the
|
||||
upstream multimodal parser sees the same shape as the other
|
||||
backends.
|
||||
"""
|
||||
if not frame_indices:
|
||||
raise ValueError("DeepStream backend received no frame indices")
|
||||
|
||||
result = cls._get_pool(pool_size).decode(
|
||||
data,
|
||||
target_indices=frame_indices,
|
||||
codec=codec,
|
||||
max_frames=len(frame_indices),
|
||||
timeout_sec=timeout_sec,
|
||||
)
|
||||
if result.error:
|
||||
raise ValueError(f"DeepStream decode failed: {result.error}")
|
||||
if result.frames is None or result.n_kept == 0:
|
||||
raise ValueError("DeepStream decode produced no frames")
|
||||
|
||||
valid = frame_indices[: result.n_kept]
|
||||
# GPU -> CPU NHWC uint8 at the codec boundary (one PCIe copy); keeps
|
||||
# the array shape identical to the OpenCV backend. Copy into
|
||||
# PINNED host memory (reused across calls by PyTorch's pinned caching
|
||||
# allocator) so the D2H runs at full PCIe bandwidth (~13 GB/s) rather
|
||||
# than the ~1 GB/s pageable path that plain ``.cpu()`` takes — ~12x
|
||||
# faster for a 1080p x8 frame batch (~46ms -> ~4ms). ``numpy()`` keeps
|
||||
# the pinned tensor alive via the array's base.
|
||||
import torch
|
||||
|
||||
gpu = result.frames
|
||||
if gpu.is_cuda:
|
||||
host = torch.empty(gpu.shape, dtype=gpu.dtype, pin_memory=True)
|
||||
host.copy_(gpu, non_blocking=True)
|
||||
torch.cuda.current_stream().synchronize()
|
||||
arr = host.numpy()
|
||||
else:
|
||||
arr = gpu.numpy()
|
||||
return arr, valid
|
||||
@@ -1,133 +0,0 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from typing import Literal
|
||||
|
||||
import numpy as np
|
||||
import numpy.typing as npt
|
||||
import torch
|
||||
|
||||
from vllm.logger import init_logger
|
||||
from vllm.platforms import current_platform
|
||||
from vllm.utils.import_utils import PlaceholderModule, check_torchcodec_available
|
||||
|
||||
from .base import (
|
||||
VideoSourceMetadata,
|
||||
VideoTargetMetadata,
|
||||
check_frame_pixel_limit,
|
||||
)
|
||||
|
||||
try:
|
||||
from torchcodec.decoders import VideoDecoder
|
||||
except (ImportError, RuntimeError):
|
||||
VideoDecoder = PlaceholderModule("torchcodec").placeholder_attr( # type: ignore[assignment]
|
||||
"decoders.VideoDecoder"
|
||||
)
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
def decode_torchcodec(
|
||||
loader_cls,
|
||||
data: bytes,
|
||||
target: VideoTargetMetadata,
|
||||
sampling_kwargs: dict,
|
||||
*,
|
||||
num_ffmpeg_threads: int = 0,
|
||||
seek_mode: Literal["exact", "approximate"] = "exact",
|
||||
device: str = "cpu",
|
||||
) -> tuple[npt.NDArray | torch.Tensor, VideoSourceMetadata, list[int], list[int]]:
|
||||
check_torchcodec_available()
|
||||
decoder = TorchCodecVideoBackendMixin.make_torchcodec_decoder(
|
||||
data,
|
||||
num_ffmpeg_threads=num_ffmpeg_threads,
|
||||
seek_mode=seek_mode,
|
||||
device=device,
|
||||
)
|
||||
check_frame_pixel_limit(
|
||||
decoder.metadata.width or 0,
|
||||
decoder.metadata.height or 0,
|
||||
)
|
||||
source = loader_cls._prepare_source(
|
||||
TorchCodecVideoBackendMixin.get_torchcodec_metadata(decoder)
|
||||
)
|
||||
frame_idx = loader_cls.compute_frames_index_to_sample(
|
||||
source=source, target=target, **sampling_kwargs
|
||||
)
|
||||
frames, valid = TorchCodecVideoBackendMixin.decode_torchcodec_frames(
|
||||
decoder, frame_idx, device=device
|
||||
)
|
||||
return frames, source, frame_idx, valid
|
||||
|
||||
|
||||
class TorchCodecVideoBackendMixin:
|
||||
"""TorchCodec (FFmpeg-backed, PyTorch-native) codec utilities.
|
||||
|
||||
Builds a :class:`~torchcodec.decoders.VideoDecoder` over the in-memory
|
||||
bytes and extracts the sampled indices with a single batched
|
||||
``get_frames_at`` call, while releasing the GIL during decode.
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def make_torchcodec_decoder(
|
||||
data: bytes,
|
||||
*,
|
||||
num_ffmpeg_threads: int = 0,
|
||||
seek_mode: Literal["exact", "approximate"] = "exact",
|
||||
device: str = "cpu",
|
||||
) -> "VideoDecoder":
|
||||
torch_device = torch.device(device)
|
||||
if torch_device.type == "cuda" and not current_platform.is_cuda():
|
||||
raise ValueError(
|
||||
f"torchcodec video decoding on device {device!r} requires "
|
||||
"a CUDA-capable platform."
|
||||
)
|
||||
elif torch_device.type not in ("cpu", "cuda"):
|
||||
raise ValueError(
|
||||
f"torchcodec video decoding only supports 'cpu' and 'cuda' "
|
||||
f"devices, got {device!r}."
|
||||
)
|
||||
# NHWC matches the (num_frames, H, W, 3) uint8 RGB layout the rest
|
||||
# of the pipeline expects, avoiding a transpose.
|
||||
return VideoDecoder(
|
||||
data,
|
||||
dimension_order="NHWC",
|
||||
num_ffmpeg_threads=num_ffmpeg_threads,
|
||||
seek_mode=seek_mode,
|
||||
device=device,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_torchcodec_metadata(decoder: "VideoDecoder") -> VideoSourceMetadata:
|
||||
md = decoder.metadata
|
||||
total_frames = md.num_frames or 0
|
||||
fps = float(md.average_fps) if md.average_fps else 0.0
|
||||
duration = float(md.duration_seconds) if md.duration_seconds else 0.0
|
||||
if total_frames == 0 and duration > 0 and fps > 0:
|
||||
total_frames = int(duration * fps)
|
||||
return VideoSourceMetadata(total_frames, fps, duration)
|
||||
|
||||
@staticmethod
|
||||
def decode_torchcodec_frames(
|
||||
decoder: "VideoDecoder",
|
||||
frame_indices: list[int],
|
||||
*,
|
||||
device: str = "cpu",
|
||||
) -> tuple[npt.NDArray | torch.Tensor, list[int]]:
|
||||
"""Decode the requested indices in one batched, index-exact call."""
|
||||
if not frame_indices:
|
||||
return np.empty((0,), dtype=np.uint8), []
|
||||
# Note: torchcodec releases the GIL for the entire call
|
||||
batch = decoder.get_frames_at(frame_indices)
|
||||
frames = batch.data
|
||||
if (
|
||||
torch.device(device).type != "cpu"
|
||||
and (status := getattr(decoder, "cpu_fallback", None)) is not None
|
||||
and bool(status)
|
||||
):
|
||||
logger.warning_once(
|
||||
"torchcodec could not use NVDEC for this video and "
|
||||
"decoded on CPU instead; check codec support and "
|
||||
"libnvcuvid."
|
||||
)
|
||||
return frames, list(frame_indices)
|
||||
Reference in New Issue
Block a user