diff --git a/.github/unittest/linux/scripts/run_all.sh b/.github/unittest/linux/scripts/run_all.sh index 0e6b738ae6d..4fb11ce4508 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 \ @@ -240,6 +239,17 @@ else uv_pip_install --no-deps tensordict 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 + printf "* Installing torchrl\n" if [[ "$RELEASE" == 0 ]]; then uv_pip_install -e . --no-build-isolation --no-deps 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: