Skip to content

Commit dfd76ce

Browse files
committed
[CI] Fix torchcodec VideoEncoder uint8 requirement and docs build
- Convert video frames to uint8 in _write_video before passing to VideoEncoder, which requires uint8 input. - Update MLFlow test_log_video to use torchcodec VideoDecoder for read-back verification when available. - Install torchcodec in docs build environment to fix sphinx gallery failures when torchvision >= 0.22. Made-with: Cursor
1 parent 172d04f commit dfd76ce

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

.github/workflows/docs.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ jobs:
4444
# Install system dependencies (Ubuntu-based PyTorch image)
4545
apt-get update
4646
apt-get install -y libglfw3 libglfw3-dev libgl1-mesa-glx libgl1-mesa-dev libegl1-mesa-dev \
47-
freeglut3-dev libglu1-mesa libegl1 mesa-utils xvfb wget git cmake
47+
freeglut3-dev libglu1-mesa libegl1 mesa-utils xvfb wget git cmake ffmpeg \
48+
libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev
4849
4950
# 2. upgrade pip, ninja and packaging
5051
python -m pip install --upgrade pip
@@ -65,10 +66,12 @@ jobs:
6566
# Use stable PyTorch for releases (tags and release/* branches)
6667
python -m pip install torch torchvision --quiet --root-user-action=ignore
6768
python -m pip install tensordict --quiet --root-user-action=ignore
69+
python -m pip install torchcodec --quiet --root-user-action=ignore
6870
else
6971
# Use nightly PyTorch for main, nightly, and PRs
7072
python -m pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu -U --quiet --root-user-action=ignore
7173
python -m pip install git+https://github.com/pytorch/tensordict.git --quiet --root-user-action=ignore
74+
BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 python -m pip install --no-build-isolation git+https://github.com/meta-pytorch/torchcodec.git --quiet --root-user-action=ignore
7275
fi
7376
7477
# 6. Install doc requirements BEFORE TorchRL to ensure gymnasium is available

test/test_loggers.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,18 @@ def test_log_video(self, steps, mlflow_fixture):
404404
videos_dir = client.download_artifacts(run_id, "videos", artifacts_dir)
405405
for i, video_name in enumerate(os.listdir(videos_dir)):
406406
video_path = os.path.join(videos_dir, video_name)
407-
loaded_video, _, _ = torchvision.io.read_video(
408-
video_path, pts_unit="sec", output_format="TCHW"
409-
)
407+
if _has_torchcodec:
408+
from torchcodec.decoders import VideoDecoder
409+
410+
loaded_video = (
411+
VideoDecoder(video_path)
412+
.get_frames_in_range(start=0, stop=128)
413+
.data
414+
)
415+
else:
416+
loaded_video, _, _ = torchvision.io.read_video(
417+
video_path, pts_unit="sec", output_format="TCHW"
418+
)
410419
if steps:
411420
assert torch.allclose(loaded_video.int(), videos[i].int(), rtol=0.1)
412421
else:

torchrl/record/loggers/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ def _write_video(filename, video_array, **kwargs): # noqa: F811
5757
preset = options.pop("preset", None)
5858
pixel_format = options.pop("pixel_format", None)
5959

60-
# VideoEncoder expects (N, C, H, W); callers pass (T, H, W, C)
61-
video_array = video_array.permute(0, 3, 1, 2).contiguous()
60+
# VideoEncoder expects (N, C, H, W) uint8; callers pass (T, H, W, C)
61+
video_array = video_array.permute(0, 3, 1, 2).contiguous().to(torch.uint8)
6262

6363
to_file_kwargs = {}
6464
if video_codec is not None:

0 commit comments

Comments
 (0)