Repository navigation
fix: pin torchcodec for torch 2.10 and warn on ABI mismatch - #7299
danielhanchen merged 10 commits into
Conversation
Add unsloth[audio] extra with torchcodec>=0.10.0,<0.11.0 and emit a clear warning when installed torchcodec minors disagree with torch (unslothai#7225).
There was a problem hiding this comment.
Code Review
This pull request introduces compatibility checks and warnings for mismatched torch and torchcodec versions, including adding an audio extra to pyproject.toml and corresponding unit tests. A review comment identifies a bug in the warning message's version calculation where the major version is dropped (e.g., suggesting <11.0 instead of <0.11.0 for pin = 0.10), and provides a suggestion to fix it.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| pin = sorted(allowed)[-1] | ||
| return ( | ||
| f"torchcodec {torchcodec_version} is incompatible with torch {torch.__version__}; " | ||
| f"install a matching build with " | ||
| f"`pip install 'torchcodec>={pin},<{int(pin.split('.')[1]) + 1}.0'` " | ||
| f"or `pip install 'unsloth[audio]'`." | ||
| ) |
There was a problem hiding this comment.
The current implementation of the upper bound version calculation drops the major version (e.g., 0), resulting in an incorrect pin suggestion like <11.0 instead of <0.11.0 when pin is 0.10. This can lead to users installing incompatible versions of torchcodec.
We should split the pin into major and minor components to correctly construct the upper bound version limit.
| pin = sorted(allowed)[-1] | |
| return ( | |
| f"torchcodec {torchcodec_version} is incompatible with torch {torch.__version__}; " | |
| f"install a matching build with " | |
| f"`pip install 'torchcodec>={pin},<{int(pin.split('.')[1]) + 1}.0'` " | |
| f"or `pip install 'unsloth[audio]'`." | |
| ) | |
| pin = sorted(allowed)[-1] | |
| major, minor = pin.split('.') | |
| next_minor = int(minor) + 1 | |
| return ( | |
| f"torchcodec {torchcodec_version} is incompatible with torch {torch.__version__}; " | |
| f"install a matching build with " | |
| f"`pip install 'torchcodec>={pin},<{major}.{next_minor}.0'` " | |
| f"or `pip install 'unsloth[audio]'`." | |
| ) |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c8d27a7cfd
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| } | ||
|
|
||
|
|
||
| def _torchcodec_version_mismatch_hint() -> str | None: |
There was a problem hiding this comment.
Use a Python 3.9-compatible annotation
Because pyproject.toml still declares support for Python 3.9 and this module does not enable postponed annotations, Python 3.9 evaluates str | None while defining the function and raises TypeError before Unsloth can import. Use Optional[str]/Union or add from __future__ import annotations so supported 3.9 installs keep working.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in 9f766e9 — all 5 Codex items:
P1 — Python 3.9 annotation: Added from __future__ import annotations to import_fixes.py so str | None does not break 3.9 imports.
P2 — remediation pin upper bound: _torchcodec_exclusive_upper() now emits <0.11.0 (not <11.0); mismatch hints only suggest unsloth[audio-torch210] on torch 2.10.
P2 — scope audio extra to torch 2.10: Replaced generic audio with per-minor extras (audio-torch210, audio-torch290, audio-torch280); bundled audio-torch210 only in *-torch2100 install extras so cu128-torch290,audio no longer forces torchcodec 0.10.
P2 — align matrix with upstream: TORCH_TORCHCODEC / _TORCH_TORCHCODEC_MINORS now match TorchCodec README — 2.9: {0.8, 0.9}, 2.8: {0.6, 0.7}.
P2 — gate audio off Python 3.9: audio-torch210 / audio-torch290 require python_version >= '3.10'; audio-torch280 allows 3.9+.
Tests: tests/python/test_torchcodec_torch_compat.py (9 passed).
| f"`pip install 'torchcodec>={pin},<{int(pin.split('.')[1]) + 1}.0'` " | ||
| f"or `pip install 'unsloth[audio]'`." |
There was a problem hiding this comment.
Make the torchcodec remediation pin the right minor
When the detected mismatch is torch 2.10 with torchcodec 0.11, this formats the suggested fix as torchcodec>=0.10,<11.0, which still admits the incompatible 0.11+ releases the warning is trying to avoid; for older torch minors, the adjacent unsloth[audio] suggestion also installs the hard-coded 0.10 pin rather than the matrix's allowed minor. The warning should emit a range that preserves the 0. major (for example <0.11.0 for 0.10) and only suggest the extra when it actually matches the detected torch minor.
Useful? React with 👍 / 👎.
| # Gemma audio / datasets>=4 torchcodec backend. Pin <0.11 for torch 2.10 wheels | ||
| # (unslothai/unsloth#7225); see scripts/notebook_validator.py TORCH_TORCHCODEC. | ||
| audio = [ | ||
| "torchcodec>=0.10.0,<0.11.0", |
There was a problem hiding this comment.
Scope the audio extra to torch 2.10
When users combine this new extra with existing supported torch-minor extras such as unsloth[cu128-torch290,audio], pip is forced to install torchcodec 0.10 even though the compatibility table added in import_fixes.py only permits 0.7-0.9 for torch 2.9 (and different minors for 2.8 and below). That makes the advertised audio extra recreate the same ABI mismatch for non-2.10 install paths, so the dependency needs to be scoped to torch 2.10 or split per supported torch minor.
Useful? React with 👍 / 👎.
| "2.9": {"0.7", "0.8", "0.9"}, | ||
| "2.8": {"0.6"}, |
There was a problem hiding this comment.
Align the torchcodec matrix with upstream
The copied runtime matrix does not match TorchCodec's published compatibility table: TorchCodec lists 0.7 with torch 2.8 and only 0.8/0.9 with torch 2.9, so this guard now silently accepts a known-bad torch 2.9 + torchcodec 0.7 install while warning users away from the valid torch 2.8 + torchcodec 0.7 combination. Please update the rows before using this table for import-time guidance.
Useful? React with 👍 / 👎.
| # Gemma audio / datasets>=4 torchcodec backend. Pin <0.11 for torch 2.10 wheels | ||
| # (unslothai/unsloth#7225); see scripts/notebook_validator.py TORCH_TORCHCODEC. | ||
| audio = [ | ||
| "torchcodec>=0.10.0,<0.11.0", |
There was a problem hiding this comment.
Gate the audio extra off Python 3.9
pyproject.toml still advertises Python 3.9 support, but torchcodec 0.10 declares Requires-Python >=3.10 and publishes only cp310+ wheels, so pip install 'unsloth[audio]' on a supported Python 3.9 environment fails resolution before Unsloth can run. Add a python_version >= '3.10' marker or otherwise avoid exposing this extra on 3.9.
Useful? React with 👍 / 👎.
…nslothai#7299) - Postpone annotations so import_fixes loads on Python 3.9 - Align TORCH_TORCHCODEC matrix with upstream (2.9: 0.8/0.9, 2.8: 0.6/0.7) - Fix mismatch hint upper bound (<0.11.0) and gate audio-torch210 suggestion - Split audio extra per torch minor; gate torch210 pin behind python>=3.10 - Bundle audio-torch210 only in *-torch2100 install extras
|
Fixed in 9f766e9. P1 — Python 3.9-compatible annotation: Valid. Added P2 — Torchcodec remediation pin / matrix / audio extra scoping / Python 3.9 gate: All addressed in the same commit — aligned |
|
Ready for review — re-verified locally:
|
…i#7299) openai package code drift reopened five CRITICAL findings in the extras pip-scan-packages shard (C2 loop body hashes + IMDS/network evidence). Update the reviewed allowlist evidence/hashes so CI gates on new findings only, not benign SDK churn.
Follow-up:
|
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de28b2fbf8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "unsloth[huggingface]", | ||
| "bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0", | ||
| "unsloth[cu126onlytorch2100]", | ||
| "unsloth[audio-torch210]", |
There was a problem hiding this comment.
Include the Intel torch 2.10 extra in the codec pin
Users installing the public unsloth[intel-gpu-torch210] extra still receive torch 2.10.0 but no torchcodec dependency: its underlying intelgputorch210 extra (pyproject.toml:1110) only includes the no-torch Hugging Face dependencies and XPU wheels. Thus Gemma audio remains unavailable for that supported torch-2.10 installation path, while the CUDA and ROCm paths added here get the pin. Add unsloth[audio-torch210] to the Intel torch-2.10 extra as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b041c05: intel-gpu-torch210 now bundles unsloth[audio-torch210].
| mismatch_hint = _torchcodec_version_mismatch_hint() | ||
| if mismatch_hint is not None: | ||
| import warnings | ||
| warnings.warn(mismatch_hint, stacklevel = 2) |
There was a problem hiding this comment.
Prevent warning filters from aborting the fallback
When callers run with warnings promoted to errors (for example, PYTHONWARNINGS=error or pytest's -W error), this warnings.warn raises UserWarning during import unsloth and prevents the subsequent broken-torchcodec disable path from running. This turns the intended compatibility warning into an import failure precisely for environments that enforce warning-free imports; emit the notice without allowing warning filters to interrupt the fallback, or perform the disabling before warning.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in b041c05: the mismatch warning is wrapped so promoted-to-error warning filters cannot abort the disable fallback.
|
@codex review |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Reviewed and verified. torchcodec was unpinned for torch 2.10, which allowed an ABI mismatched wheel to install and break audio loading. This pins the compatible torchcodec and warns on an ABI mismatch, with version parsing guarded so a nonstandard torch version string cannot raise. Simulated the mismatch path and the guarded parse. Codex review has no open items. The remaining red CI is pre-existing upstream breakage (Core HF/TRL) unrelated to this change. Good to merge. |
Fixes #7225
Problem
pip install unslothresolves to torch 2.10, but a barepip install torchcodecpulls torchcodec ≥0.11, which torch 2.10 rejects at import time. Users hit opaque failures in Gemma audio notebooks without knowing they needtorchcodec==0.10.0.Fix
unsloth[audio]optional extra pinningtorchcodec>=0.10.0,<0.11.0for torch 2.10 wheels.TORCH_TORCHCODECcompatibility matrix fromscripts/notebook_validator.pyinimport_fixes.py.warnings.warnfromdisable_torchcodec_if_broken()when installed torch/torchcodec minors disagree, pointing users to the correct pin orpip install 'unsloth[audio]'.Verification
All 4 tests pass (pyproject pin, matrix parity, mismatch hint for 0.11 vs 2.10, accept 0.10 vs 2.10).
Compatibility
unslothinstall (torchcodec remains optional).