Skip to content

chore: replace decord2 with torchvision/torchaudio for media loading - #3107

Merged
kajalj22 merged 27 commits into
mainfrom
replace-decord-torchvision
Jul 18, 2026
Merged

chore: replace decord2 with torchvision/torchaudio for media loading#3107
kajalj22 merged 27 commits into
mainfrom
replace-decord-torchvision

Conversation

@kajalj22

@kajalj22 kajalj22 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces `decord2` with `torchvision`/`torchaudio` and removes bundled codec libraries from the shipped container.

Video/audio decoding

  • Replace `load_video(backend="decord")` with `load_video(backend="torchvision")` in `multimodal_utils.py` and `processors.py`
  • Replace `decord.AudioReader` fallback with `torchaudio.load` + `torchaudio.functional.resample` in `multimodal_utils.py`
  • Replace `import decord` in `datasets/utils.py` (`load_audio_from_file`) with `torchaudio`

Container changes

  • Block `decord2` via `"decord2; sys_platform == 'never'"` uv override — removes its bundled codec libs from the container (pulled transitively by `sglang → qwen-vl-utils[decord]` on aarch64)
  • Block `av` (PyAV) via `"av; sys_platform == 'never'"` uv override — removes its bundled codec libs (only needed by MB's optional WAN diffusion path, installed at test time via `scripts/install_diffusion_deps.sh`)
  • Remove `torchaudio` and `torchcodec` from `[project.dependencies]` and drop the `pytorch-cu130` sources entry — the container receives the PyPI torchaudio stub (no bundled FFmpeg) via sglang/vllm; the full pytorch-cu130 build is not shipped
  • Add `torchaudio.*` to `pyrefly.toml` `replace-imports-with-any` so lazy imports are not flagged by the type checker

Audio install script

  • Add `scripts/install_audio_deps.sh` — installs `torchaudio==2.11.0` (pytorch-cu130 build) + `torchcodec` before audio tests. Idempotent: checks for bundled FFmpeg libs rather than just importability. Uses `--reinstall-package torchaudio` to upgrade from the PyPI stub.
  • Single hook in `tests/test_suites/llm/common.env` with a name-based check (`[[ "${BASH_SOURCE[1]:-}" =~ (omni|audio|avqa) ]]`) — covers all audio/omni VLM test scripts via the shared `common.env` (which `vlm/common.env` symlinks to); also added directly to `tests/functional/audio_grpo_megatron.sh`, `eval_audio.sh`, and `eval_daily_omni.sh`. LLM tests are unaffected.
  • Add prerequisite note to `docs/guides/grpo-audio.md`

Motivation

`decord2` and `av` (PyAV) bundle codec libraries as hard dynamic link dependencies that cannot be stripped without breaking the import.

Supersedes #2922, which attempted to delete codec `.so` files at Docker build time but broke `import decord`.

Test plan

  • CI pipeline 57825799: all 10 tests passed (~2h 52m)
  • Audio/omni tests self-install torchaudio via `scripts/install_audio_deps.sh` before running
  • LLM tests unaffected: `torchaudio` is lazily imported inside audio functions, never called by LLM training paths

🤖 Generated with Claude Code

decord2 bundles libx264, libx265, libopenh264, and libmp3lame as hard
dynamic dependencies of its core shared library. These codec libs carry
MPEG LA / HEVC Advance royalty obligations on distribution.

Replace the two decord usages in multimodal_utils.py:
- Video loading: load_video backend="decord" → backend="torchvision"
  (torchvision==0.26.0 is already a project dependency)
- Audio fallback: decord.AudioReader → torchaudio.load + functional.resample
  (torchaudio==2.11.0 is already a project dependency)

Remove decord2 from pyproject.toml dependencies.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Kajal Jain <kajalj@nvidia.com>
@kajalj22
kajalj22 requested review from a team as code owners July 7, 2026 21:54
@copy-pr-bot

copy-pr-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Kajal Jain <kajalj@nvidia.com>
@kajalj22 kajalj22 added CI:L1 Run doctests, unit tests, and functional tests r0.7.0 labels Jul 7, 2026
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Kajal Jain <kajalj@nvidia.com>
@kajalj22

kajalj22 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 25b19e2

kajalj22 and others added 2 commits July 9, 2026 09:45
- Replace decord.AudioReader in load_audio_from_file with torchaudio
- Add torchaudio.* to pyrefly replace-imports-with-any to suppress
  import-error for the lazy torchaudio import in multimodal_utils.py

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Kajal Jain <kajalj@nvidia.com>
@kajalj22

kajalj22 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 029b9ee

kajalj22 and others added 2 commits July 9, 2026 10:14
av bundles libx264, libx265, libopenh264, and libmp3lame — the same
royalty-obligating codec libs we removed with decord2. It is pulled in
transitively by qwen-vl-utils (a megatron-bridge dep) but is only
actually needed by megatron-bridge's optional WAN diffusion path, which
installs it at test time via scripts/install_diffusion_deps.sh.

Add "av; sys_platform == 'never'" to override-dependencies, mirroring
the same approach already taken in Megatron-Bridge's own pyproject.toml
(commit f4b34b4).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Kajal Jain <kajalj@nvidia.com>
…d2 via uv override

- Switch processors.py video loading from backend="decord" to backend="torchvision"
  (missed in the initial decord→torchvision pass)
- Add decord2 to override-dependencies with sys_platform=='never' so sglang's
  transitive pull of qwen-vl-utils[decord] on aarch64 Linux doesn't land it
  in the container

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Kajal Jain <kajalj@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@kajalj22

kajalj22 commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 3e21f62

chtruong814
chtruong814 previously approved these changes Jul 9, 2026
torchaudio was only in override-dependencies (which pins version but
doesn't install the package). Moving it to [project.dependencies]
alongside torchvision so it's actually installed in the container.

Without this, load_audio_from_file raises ModuleNotFoundError on torchaudio.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Kajal Jain <kajalj@nvidia.com>
kajalj22 and others added 2 commits July 11, 2026 22:35
torchaudio 2.11.0 defaults to torchcodec as its first audio backend.
torchcodec's native .so files were already present in the container (via
ray worker venvs) but the Python package wasn't in the main venv, causing
ModuleNotFoundError when load_audio_from_file is called from the dataloader.

torchcodec links against system FFmpeg (LGPL-only) rather than bundling
its own copy, so it carries no royalty-bearing codec libs (no libx264/
libx265/libmp3lame).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Kajal Jain <kajalj@nvidia.com>
…ll script

- Remove torchaudio and torchcodec from [project.dependencies] and drop
  the pytorch-cu130 sources entry so the container receives only the PyPI
  torchaudio stub (~1.7 MB, no bundled FFmpeg) via sglang/vllm transitive
  deps. The pytorch-cu130 build (bundled FFmpeg with H.264/AAC decoders)
  is no longer shipped.
- Add scripts/install_audio_deps.sh: installs torchaudio==2.11.0
  (pytorch-cu130, with FFmpeg) + torchcodec at test time. Uses
  --reinstall-package torchaudio to upgrade from the PyPI stub. Check
  is idempotent (looks for bundled libav* in torchaudio/lib/, not just
  import success, so the PyPI stub does not falsely suppress the install).
- Hook install_audio_deps.sh into all audio/omni test scripts
  (tests/test_suites/vlm/*omni*.sh, tests/functional/audio_grpo_megatron.sh,
  eval_audio.sh, eval_daily_omni.sh). LLM tests are unaffected.
- Add prerequisite callout to docs/guides/grpo-audio.md.

Signed-off-by: Kajal Jain <kajalj@nvidia.com>
@kajalj22
kajalj22 requested a review from a team as a code owner July 13, 2026 19:47
@kajalj22

Copy link
Copy Markdown
Contributor Author

/ok to test 2fe5480

@kajalj22
kajalj22 requested a review from chtruong814 July 16, 2026 03:19
chtruong814
chtruong814 previously approved these changes Jul 16, 2026
@yuekaizhang

Copy link
Copy Markdown
Contributor

@kajalj22 Could you help update the audio dependency install methods in https://github.com/NVIDIA-NeMo/RL/blob/main/docs/guides/grpo-audio-visual.md and the related nightly tests?

… guide

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Kajal Jain <kajalj@nvidia.com>
@kajalj22

Copy link
Copy Markdown
Contributor Author

/ok to test bf18ead

@kajalj22
kajalj22 enabled auto-merge (squash) July 16, 2026 07:38
@kajalj22
kajalj22 requested a review from chtruong814 July 16, 2026 07:38
Comment thread tools/install_audio_deps.sh
Comment thread tools/install_audio_deps.sh
Comment thread pyproject.toml
Also fix two stale comments in pyproject.toml:
- drop torchaudio from the uv.sources index comment
- update script path reference from scripts/ to tools/

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Signed-off-by: Kajal Jain <kajalj@nvidia.com>
@kajalj22

Copy link
Copy Markdown
Contributor Author

/ok to test 3a0d641

@chtruong814

Copy link
Copy Markdown
Contributor

/ok to test

@copy-pr-bot

copy-pr-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

/ok to test

@chtruong814, there was an error processing your request: E1

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/1/

@chtruong814

Copy link
Copy Markdown
Contributor

/ok to test 0af12fe

@kajalj22
kajalj22 merged commit 52be987 into main Jul 18, 2026
176 of 179 checks passed
@kajalj22
kajalj22 deleted the replace-decord-torchvision branch July 18, 2026 01:46
yuki-97 pushed a commit that referenced this pull request Jul 18, 2026
…ing (#3107) (#3277)

Signed-off-by: Kajal Jain <kajalj@nvidia.com>
Signed-off-by: Charlie Truong <chtruong@nvidia.com>
Co-authored-by: kajalj22 <kajalj@nvidia.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
ashors1 pushed a commit that referenced this pull request Jul 22, 2026
…3107)

Signed-off-by: Kajal Jain <kajalj@nvidia.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI:L1 Run doctests, unit tests, and functional tests Documentation Improvements or additions to documentation r0.7.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants