[CPU] Support Qwen3.8 text+video: adding torchcodec, ffmpeg and removing pin_memory (#35492)
This commit is contained in:
@@ -62,6 +62,7 @@ dependencies = [
|
||||
"timm==1.0.16",
|
||||
"torch==2.12.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",
|
||||
"tqdm",
|
||||
"transformers==5.12.1",
|
||||
|
||||
@@ -268,7 +268,8 @@ async def preprocess_video(
|
||||
[resized_height, resized_width],
|
||||
interpolation=InterpolationMode.BILINEAR,
|
||||
)
|
||||
video = video.pin_memory()
|
||||
if not is_cpu():
|
||||
video = video.pin_memory()
|
||||
video_metadata = {
|
||||
"fps": video_fps,
|
||||
"duration": total_frames / video_fps,
|
||||
|
||||
@@ -33,6 +33,13 @@ def _try_cuda_backend() -> bool:
|
||||
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:
|
||||
"""Unified video decoder that uses torchcodec when available, decord as fallback.
|
||||
|
||||
@@ -140,10 +147,13 @@ class VideoDecoderWrapper:
|
||||
|
||||
if _BACKEND == "torchcodec":
|
||||
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()
|
||||
else:
|
||||
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):
|
||||
"""Decode frames using multiple VideoDecoder instances in parallel threads."""
|
||||
@@ -177,6 +187,8 @@ class VideoDecoderWrapper:
|
||||
results[idx] = future.result()
|
||||
|
||||
output = torch.cat(results, dim=0)
|
||||
if _is_cpu_engine():
|
||||
return output
|
||||
return output if output.is_cuda else output.pin_memory()
|
||||
|
||||
@property
|
||||
|
||||
Reference in New Issue
Block a user