Skip to content

Declare torch as a runtime dependency#4189

Open
abondarev84 wants to merge 1 commit intopytorch:mainfrom
abondarev84:declare-torch-dependency
Open

Declare torch as a runtime dependency#4189
abondarev84 wants to merge 1 commit intopytorch:mainfrom
abondarev84:declare-torch-dependency

Conversation

@abondarev84
Copy link
Copy Markdown

Summary

torchaudio 2.11.0 ships with install_requires=[], so pip install torchaudio no longer pulls torch. Since torchaudio/__init__.py imports torch unconditionally, any clean install into an environment without a separate pip install torch fails with:

ModuleNotFoundError: No module named 'torch'

Fix

Restore the _get_pytorch_version() call that was commented out in #4171. This matches the pattern already used in pytorch/vision and pytorch/text:

  • Local / dev builds (no PYTORCH_VERSION env var): install_requires=["torch"] — pip pulls the latest torch.
  • Release builds (PYTORCH_VERSION set by the release builder): install_requires=["torch==X.Y.Z"] — pinned to the matching torch release, preserving the ABI guarantee historical torchaudio releases shipped with.

The _get_pytorch_version() function itself is already defined at line 41 — this just re-enables its use.

Context

The pre-2.11.0 behavior (torch==X.Y.Z pinned in release wheels) was removed in #4171 to avoid version pinning. @adamjstewart flagged in-thread that listing torch unpinned would achieve the stated goal (no version pin) while still keeping pip's resolver correct. This PR takes that further by restoring the env-var-controlled dependency expression, which gives maintainers back the ability to pin in release builds without forcing a pin on local/dev installs.

Observed externally

The arm64-python-wheel-tester — an aarch64 wheel-install smoke test — has shown torchaudio failing since the 2.11.0 release, because the tester installs each wheel in isolation and torch is no longer pulled as a dep.

Diff

Two chunks: uncomment the _get_pytorch_version() call and associated print, and pass the result to install_requires. Also removes the now-stale TODO comment.

Tests

No tests added. The change is to packaging metadata (setup.py install_requires); exercising it would require a full install-into-clean-env integration test, which is outside the scope of the existing test suite. The fix can be verified by inspecting the resulting wheel's METADATA / requires_dist after building, or by pip install torchaudio into a fresh venv without a separate torch install.

torchaudio imports torch unconditionally at package init, so
pip install torchaudio into an environment without a separate
pip install torch fails with ModuleNotFoundError.

Restore the _get_pytorch_version() call that was commented out in pytorch#4171.
This matches the pattern used in pytorch/vision and pytorch/text:

  - Local / dev builds: install_requires = ["torch"] (unpinned).
  - Release builds (PYTORCH_VERSION env var set by the release builder):
    install_requires = ["torch==X.Y.Z"], preserving the ABI-match
    guarantee that historical torchaudio releases shipped with.

The in-thread comment on pytorch#4171 flagged that an unpinned dep would be
enough to keep pip's resolver correct:
pytorch#4171 (comment)
@abondarev84 abondarev84 requested a review from a team as a code owner April 21, 2026 20:38
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Apr 21, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/audio/4189

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed label Apr 21, 2026
@abondarev84
Copy link
Copy Markdown
Author

@malfet any suggestions who can help with reviewing this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant