From 61ff2f432464642761381ef27bb7bbc0ba010c21 Mon Sep 17 00:00:00 2001 From: Vincent Moens Date: Wed, 4 Mar 2026 15:57:33 +0000 Subject: [PATCH 1/5] init --- .github/unittest/linux/scripts/run_all.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/unittest/linux/scripts/run_all.sh b/.github/unittest/linux/scripts/run_all.sh index eb6b6c9266c..83415d68c9f 100755 --- a/.github/unittest/linux/scripts/run_all.sh +++ b/.github/unittest/linux/scripts/run_all.sh @@ -238,6 +238,13 @@ else uv_pip_install --no-deps tensordict fi +# install torchcodec (from source for nightly to match PyTorch ABI) +if [[ "$RELEASE" == 0 ]]; then + uv_pip_install --no-build-isolation git+https://github.com/meta-pytorch/torchcodec.git +else + uv_pip_install torchcodec +fi + printf "* Installing torchrl\n" if [[ "$RELEASE" == 0 ]]; then uv_pip_install -e . --no-build-isolation --no-deps From 9bfc728c77bf6fed9bbb527fdeda2bacf17c5097 Mon Sep 17 00:00:00 2001 From: Vincent Moens Date: Wed, 4 Mar 2026 17:00:18 +0000 Subject: [PATCH 2/5] [CI] Set BUILD_AGAINST_ALL_FFMPEG_FROM_S3 for torchcodec source build torchcodec's setup.py requires this env var when building a wheel to handle FFmpeg bundling. Without it, the build fails with a ValueError about license confirmation. Made-with: Cursor --- .github/unittest/linux/scripts/run_all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/unittest/linux/scripts/run_all.sh b/.github/unittest/linux/scripts/run_all.sh index 83415d68c9f..36b2c713b3c 100755 --- a/.github/unittest/linux/scripts/run_all.sh +++ b/.github/unittest/linux/scripts/run_all.sh @@ -240,7 +240,7 @@ fi # install torchcodec (from source for nightly to match PyTorch ABI) if [[ "$RELEASE" == 0 ]]; then - uv_pip_install --no-build-isolation git+https://github.com/meta-pytorch/torchcodec.git + BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 uv_pip_install --no-build-isolation git+https://github.com/meta-pytorch/torchcodec.git else uv_pip_install torchcodec fi From 3b9d2e8dd19b8dc3ca085d02c008371491f8f2df Mon Sep 17 00:00:00 2001 From: Vincent Moens Date: Wed, 4 Mar 2026 17:19:01 +0000 Subject: [PATCH 3/5] [CI] Fix torchcodec install: remove from pip list, export env var - Remove torchcodec from main pip install list since it's now handled by the dedicated source/release install block below. - Export BUILD_AGAINST_ALL_FFMPEG_FROM_S3 so the env var propagates through the uv_pip_install shell function to the build subprocess. Made-with: Cursor --- .github/unittest/linux/scripts/run_all.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/unittest/linux/scripts/run_all.sh b/.github/unittest/linux/scripts/run_all.sh index a9c44ee8903..4811c4a9174 100755 --- a/.github/unittest/linux/scripts/run_all.sh +++ b/.github/unittest/linux/scripts/run_all.sh @@ -130,7 +130,6 @@ uv_pip_install \ wandb \ mlflow \ av \ - torchcodec \ coverage \ transformers \ ninja \ @@ -242,7 +241,9 @@ fi # install torchcodec (from source for nightly to match PyTorch ABI) if [[ "$RELEASE" == 0 ]]; then - BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 uv_pip_install --no-build-isolation git+https://github.com/meta-pytorch/torchcodec.git + export BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 + uv_pip_install --no-build-isolation git+https://github.com/meta-pytorch/torchcodec.git + unset BUILD_AGAINST_ALL_FFMPEG_FROM_S3 else uv_pip_install torchcodec fi From 172d04f09e23194bf0d7d1dba74f6a22bc5e371b Mon Sep 17 00:00:00 2001 From: Vincent Moens Date: Wed, 4 Mar 2026 17:35:15 +0000 Subject: [PATCH 4/5] [CI] Set Python3_ROOT_DIR for torchcodec CMake build CMake's FindPython3 can't locate Python include headers in uv's standalone Python installation. Setting Python3_ROOT_DIR to the base prefix lets CMake find the development files. Made-with: Cursor --- .github/unittest/linux/scripts/run_all.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/unittest/linux/scripts/run_all.sh b/.github/unittest/linux/scripts/run_all.sh index 4811c4a9174..4fb11ce4508 100755 --- a/.github/unittest/linux/scripts/run_all.sh +++ b/.github/unittest/linux/scripts/run_all.sh @@ -242,8 +242,10 @@ fi # install torchcodec (from source for nightly to match PyTorch ABI) if [[ "$RELEASE" == 0 ]]; then export BUILD_AGAINST_ALL_FFMPEG_FROM_S3=1 + export Python3_ROOT_DIR="$(python -c 'import sys; print(sys.base_prefix)')" uv_pip_install --no-build-isolation git+https://github.com/meta-pytorch/torchcodec.git unset BUILD_AGAINST_ALL_FFMPEG_FROM_S3 + unset Python3_ROOT_DIR else uv_pip_install torchcodec fi From dfd76ce20a90444434b57dfb54c8142c29181a36 Mon Sep 17 00:00:00 2001 From: Vincent Moens Date: Wed, 4 Mar 2026 18:21:52 +0000 Subject: [PATCH 5/5] [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 --- .github/workflows/docs.yml | 5 ++++- test/test_loggers.py | 15 ++++++++++++--- torchrl/record/loggers/common.py | 4 ++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index d4c88a010b4..2ed7fc7222a 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -44,7 +44,8 @@ jobs: # Install system dependencies (Ubuntu-based PyTorch image) apt-get update apt-get install -y libglfw3 libglfw3-dev libgl1-mesa-glx libgl1-mesa-dev libegl1-mesa-dev \ - freeglut3-dev libglu1-mesa libegl1 mesa-utils xvfb wget git cmake + freeglut3-dev libglu1-mesa libegl1 mesa-utils xvfb wget git cmake ffmpeg \ + libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev # 2. upgrade pip, ninja and packaging python -m pip install --upgrade pip @@ -65,10 +66,12 @@ jobs: # Use stable PyTorch for releases (tags and release/* branches) python -m pip install torch torchvision --quiet --root-user-action=ignore python -m pip install tensordict --quiet --root-user-action=ignore + python -m pip install torchcodec --quiet --root-user-action=ignore else # Use nightly PyTorch for main, nightly, and PRs python -m pip install --pre torch torchvision --index-url https://download.pytorch.org/whl/nightly/cpu -U --quiet --root-user-action=ignore python -m pip install git+https://github.com/pytorch/tensordict.git --quiet --root-user-action=ignore + 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 fi # 6. Install doc requirements BEFORE TorchRL to ensure gymnasium is available diff --git a/test/test_loggers.py b/test/test_loggers.py index e9a82c6fcff..ebec8a2d23f 100644 --- a/test/test_loggers.py +++ b/test/test_loggers.py @@ -404,9 +404,18 @@ def test_log_video(self, steps, mlflow_fixture): videos_dir = client.download_artifacts(run_id, "videos", artifacts_dir) for i, video_name in enumerate(os.listdir(videos_dir)): video_path = os.path.join(videos_dir, video_name) - loaded_video, _, _ = torchvision.io.read_video( - video_path, pts_unit="sec", output_format="TCHW" - ) + if _has_torchcodec: + from torchcodec.decoders import VideoDecoder + + loaded_video = ( + VideoDecoder(video_path) + .get_frames_in_range(start=0, stop=128) + .data + ) + else: + loaded_video, _, _ = torchvision.io.read_video( + video_path, pts_unit="sec", output_format="TCHW" + ) if steps: assert torch.allclose(loaded_video.int(), videos[i].int(), rtol=0.1) else: diff --git a/torchrl/record/loggers/common.py b/torchrl/record/loggers/common.py index 80f7dbe3ac9..b0ad414c5e8 100644 --- a/torchrl/record/loggers/common.py +++ b/torchrl/record/loggers/common.py @@ -57,8 +57,8 @@ def _write_video(filename, video_array, **kwargs): # noqa: F811 preset = options.pop("preset", None) pixel_format = options.pop("pixel_format", None) - # VideoEncoder expects (N, C, H, W); callers pass (T, H, W, C) - video_array = video_array.permute(0, 3, 1, 2).contiguous() + # VideoEncoder expects (N, C, H, W) uint8; callers pass (T, H, W, C) + video_array = video_array.permute(0, 3, 1, 2).contiguous().to(torch.uint8) to_file_kwargs = {} if video_codec is not None: