[CPU] Support Qwen3.8 text+video: adding torchcodec, ffmpeg and removing pin_memory (#35492)
This commit is contained in:
@@ -8,6 +8,7 @@ RUN apt-get update && \
|
|||||||
apt-get full-upgrade -y && \
|
apt-get full-upgrade -y && \
|
||||||
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
|
DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \
|
||||||
ca-certificates \
|
ca-certificates \
|
||||||
|
ffmpeg \
|
||||||
git \
|
git \
|
||||||
curl \
|
curl \
|
||||||
wget \
|
wget \
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ dependencies = [
|
|||||||
"timm==1.0.16",
|
"timm==1.0.16",
|
||||||
"torch==2.12.0",
|
"torch==2.12.0",
|
||||||
"torchaudio==2.11.0",
|
"torchaudio==2.11.0",
|
||||||
|
"torchcodec==0.12.0 ; sys_platform != 'linux' or (sys_platform == 'linux' and platform_machine != 'aarch64' and platform_machine != 'arm64' and platform_machine != 'armv7l')",
|
||||||
"torchvision==0.27.0",
|
"torchvision==0.27.0",
|
||||||
"tqdm",
|
"tqdm",
|
||||||
"transformers==5.12.1",
|
"transformers==5.12.1",
|
||||||
|
|||||||
@@ -268,7 +268,8 @@ async def preprocess_video(
|
|||||||
[resized_height, resized_width],
|
[resized_height, resized_width],
|
||||||
interpolation=InterpolationMode.BILINEAR,
|
interpolation=InterpolationMode.BILINEAR,
|
||||||
)
|
)
|
||||||
video = video.pin_memory()
|
if not is_cpu():
|
||||||
|
video = video.pin_memory()
|
||||||
video_metadata = {
|
video_metadata = {
|
||||||
"fps": video_fps,
|
"fps": video_fps,
|
||||||
"duration": total_frames / video_fps,
|
"duration": total_frames / video_fps,
|
||||||
|
|||||||
@@ -33,6 +33,13 @@ def _try_cuda_backend() -> bool:
|
|||||||
return _cuda_backend_enabled
|
return _cuda_backend_enabled
|
||||||
|
|
||||||
|
|
||||||
|
def _is_cpu_engine() -> bool:
|
||||||
|
# Lazy import to avoid circular dependency issues and unnecessary imports on module load
|
||||||
|
from sglang.srt.utils.common import is_cpu
|
||||||
|
|
||||||
|
return is_cpu()
|
||||||
|
|
||||||
|
|
||||||
class VideoDecoderWrapper:
|
class VideoDecoderWrapper:
|
||||||
"""Unified video decoder that uses torchcodec when available, decord as fallback.
|
"""Unified video decoder that uses torchcodec when available, decord as fallback.
|
||||||
|
|
||||||
@@ -140,10 +147,13 @@ class VideoDecoderWrapper:
|
|||||||
|
|
||||||
if _BACKEND == "torchcodec":
|
if _BACKEND == "torchcodec":
|
||||||
batch = self._decoder.get_frames_at(indices)
|
batch = self._decoder.get_frames_at(indices)
|
||||||
|
if _is_cpu_engine():
|
||||||
|
return batch.data
|
||||||
return batch.data if batch.data.is_cuda else batch.data.pin_memory()
|
return batch.data if batch.data.is_cuda else batch.data.pin_memory()
|
||||||
else:
|
else:
|
||||||
arr = self._decoder.get_batch(indices).asnumpy()
|
arr = self._decoder.get_batch(indices).asnumpy()
|
||||||
return torch.from_numpy(arr).pin_memory()
|
output = torch.from_numpy(arr)
|
||||||
|
return output if _is_cpu_engine() else output.pin_memory()
|
||||||
|
|
||||||
def _parallel_decode(self, indices, num_threads):
|
def _parallel_decode(self, indices, num_threads):
|
||||||
"""Decode frames using multiple VideoDecoder instances in parallel threads."""
|
"""Decode frames using multiple VideoDecoder instances in parallel threads."""
|
||||||
@@ -177,6 +187,8 @@ class VideoDecoderWrapper:
|
|||||||
results[idx] = future.result()
|
results[idx] = future.result()
|
||||||
|
|
||||||
output = torch.cat(results, dim=0)
|
output = torch.cat(results, dim=0)
|
||||||
|
if _is_cpu_engine():
|
||||||
|
return output
|
||||||
return output if output.is_cuda else output.pin_memory()
|
return output if output.is_cuda else output.pin_memory()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|||||||
Reference in New Issue
Block a user