Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements/cuda.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ torchaudio==2.9.1
torchvision==0.24.1 # Required for phi3v processor. See https://github.com/pytorch/vision?tab=readme-ov-file#installation for corresponding version
# FlashInfer should be updated together with the Dockerfile
flashinfer-python==0.5.3
PyNvVideoCodec
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The PyNvVideoCodec dependency is added without a specific version. This can lead to non-reproducible builds if a new version of the library is released with breaking changes. To ensure stability and reproducibility, it's recommended to pin this dependency to a specific version, for example: PyNvVideoCodec==X.Y.Z.

129 changes: 129 additions & 0 deletions test_video_backend.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
#!/usr/bin/env python3
"""Test script to check which video backend is being used."""

import sys
import os
from pathlib import Path

# Test video codec detection
def test_codec_detection(video_path, video_io=None):
print(f"\n{'='*60}")
print(f"Testing video: {video_path}")
print(f"{'='*60}")

if not Path(video_path).exists():
print(f"❌ File does not exist: {video_path}")
return

print(f"✓ File exists (size: {Path(video_path).stat().st_size / 1024 / 1024:.2f} MB)")

Check failure on line 19 in test_video_backend.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E501)

test_video_backend.py:19:89: E501 Line too long (90 > 88)
# Read video bytes
with open(video_path, 'rb') as f:
video_bytes = f.read()

# Test codec detection using actual VideoMediaIO if provided
if video_io:
try:
is_hw_accel = video_io.is_video_code_hw_accelerated(video_bytes)
codec, containers = video_io.get_video_codec_and_container_from_bytes(video_bytes)

Check failure on line 29 in test_video_backend.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E501)

test_video_backend.py:29:89: E501 Line too long (94 > 88)
print(f"Codec: {codec}")
print(f"Containers: {containers}")
print(f"HW accelerated codecs: {video_io.hw_video_loader.hardware_accelerated_codecs()}")
print(f"HW accelerated containers: {video_io.hw_video_loader.hardware_accelerated_containers()}")

Check failure on line 33 in test_video_backend.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E501)

test_video_backend.py:33:89: E501 Line too long (101 > 88)

Check failure on line 34 in test_video_backend.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E501)

test_video_backend.py:34:89: E501 Line too long (109 > 88)
if is_hw_accel:
print("✅ This video WILL use PyNvVideoCodec backend")
else:
print("⚠️ This video will use OpenCV backend")

except Exception as e:
print(f"❌ Error checking codec: {e}")
import traceback
traceback.print_exc()
else:
# Fallback to manual check
try:
import io
import av

bio = io.BytesIO(video_bytes)
with av.open(bio, mode='r') as c:
vstreams = [s for s in c.streams if s.type == 'video']
if not vstreams:
print("❌ No video streams found")
return

s = vstreams[0]
format_name = getattr(c.format, 'name', '')
codec_name = getattr(s.codec_context, 'name', None)

print(f"Codec: {codec_name}")
print(f"Container: {format_name}")

except Exception as e:
print(f"❌ Error checking codec: {e}")
import traceback
traceback.print_exc()

# Test VideoMediaIO initialization
def test_video_io():
print(f"\n{'='*60}")
print("Testing VideoMediaIO initialization")
print(f"{'='*60}")

from vllm import envs
from vllm.multimodal.video import VideoMediaIO, VIDEO_LOADER_REGISTRY, PyNVVideoBackend
from vllm.multimodal.image import ImageMediaIO

print(f"VLLM_VIDEO_LOADER_BACKEND env: {os.getenv('VLLM_VIDEO_LOADER_BACKEND', 'NOT SET')}")
print(f"envs.VLLM_VIDEO_LOADER_BACKEND: {envs.VLLM_VIDEO_LOADER_BACKEND}")

image_io = ImageMediaIO()
video_io = VideoMediaIO(image_io, num_frames=10)

Check failure on line 83 in test_video_backend.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E501)

test_video_backend.py:83:89: E501 Line too long (96 > 88)

print(f"video_io.video_loader: {video_io.video_loader}")
print(f"video_io.hw_video_loader: {video_io.hw_video_loader}")

print(f"\nBoth paths point to PyNVVideoBackend: {video_io.video_loader.__class__.__name__ == 'PyNVVideoBackend'}")

if __name__ == "__main__":
# Test initialization
test_video_io()

Check failure on line 92 in test_video_backend.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E501)

test_video_backend.py:92:89: E501 Line too long (118 > 88)

# Create VideoMediaIO instance for testing
from vllm.multimodal.video import VideoMediaIO
from vllm.multimodal.image import ImageMediaIO

image_io = ImageMediaIO()
video_io = VideoMediaIO(image_io, num_frames=10)

# Test video files
if len(sys.argv) > 1:
for video_path in sys.argv[1:]:
test_codec_detection(video_path, video_io)
else:
# Try to find a sample video
import json
dataset_path = "/workspace/data/sharegpt/llava_v1_5_mix665k_with_video_chatgpt72k_share4video28k.json"

if Path(dataset_path).exists():
with open(dataset_path, 'r') as f:
data = json.load(f)

Check failure on line 112 in test_video_backend.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E501)

test_video_backend.py:112:89: E501 Line too long (110 > 88)

# Get first video
for item in data[:5]:
if 'video' in item:
video_rel_path = item['video']
# Try different base paths
for base in ['/workflow/vllm-exp', '/workspace/data', '.']:
video_path = Path(base) / video_rel_path
if video_path.exists():
test_codec_detection(str(video_path), video_io)
break
else:
print(f"\n⚠️ Could not find video: {video_rel_path}")
print(f" Tried paths:")
for base in ['/workflow/vllm-exp', '/workspace/data', '.']:
print(f" - {Path(base) / video_rel_path}")

46 changes: 46 additions & 0 deletions test_video_loading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env python3
"""Test script to trigger video loading and see the logs."""

import logging
import os
from pathlib import Path

# Set up logging to see INFO level messages
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)

# Set the environment variable
os.environ['VLLM_VIDEO_LOADER_BACKEND'] = 'pynvvideocodec'

from vllm.multimodal.video import VideoMediaIO

Check failure on line 17 in test_video_loading.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E402)

test_video_loading.py:17:1: E402 Module level import not at top of file
from vllm.multimodal.image import ImageMediaIO

Check failure on line 18 in test_video_loading.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E402)

test_video_loading.py:18:1: E402 Module level import not at top of file

print("=" * 70)
print("Step 1: Initializing VideoMediaIO")
print("=" * 70)

image_io = ImageMediaIO()
video_io = VideoMediaIO(image_io, num_frames=10)

print("\n" + "=" * 70)
print("Step 2: Loading a video file")
print("=" * 70)

# Try to load a video
video_path = Path('sharegpt4video/panda/PN77MQRGJDs.mp4')
if video_path.exists():
print(f"\nLoading: {video_path}")
try:
frames, metadata = video_io.load_file(video_path)
print(f"\n✅ Video loaded successfully!")
print(f" Frames shape: {frames.shape if hasattr(frames, 'shape') else 'N/A'}")
print(f" Metadata: {metadata}")
except Exception as e:
print(f"\n❌ Expected exception caught: {type(e).__name__}: {e}")
print(" (This is the test exception at line 351)")
else:
print(f"\n⚠️ Video not found: {video_path}")
print(" Make sure you're running from /workflow/vllm-exp where the symlink exists")

Check failure on line 45 in test_video_loading.py

View workflow job for this annotation

GitHub Actions / pre-commit

Ruff (E501)

test_video_loading.py:45:89: E501 Line too long (89 > 88)

Loading