Repository navigation
torchcodec: cover torch 2.11 in the compatibility guard and pin per torch minor - #7474
Conversation
…orch minor install.sh's CUDA branch allows torch>=2.4,<2.12.0 and the cu12x/cu13x wheel indexes top out at torch 2.11.0, so a fresh NVIDIA install lands on torch 2.11. studio/backend/requirements/extras-no-deps.txt pinned torchcodec==0.10.0, which upstream pairs with torch 2.10 exactly, and torchcodec publishes no Requires-Dist: torch, so pip cannot notice. The guard that exists to catch this, _torchcodec_version_mismatch_hint, looks the torch minor up in _TORCH_TORCHCODEC_MINORS and returns None on a miss, and the table had no "2.11" row: it was silent on precisely the version where the mismatch now happens. Add the 2.11 row (mirrored into scripts/notebook_validator.py), add an audio-torch211 extra pinning the 0.11 line, and select torchcodec at install time from the venv's torch minor instead of a flat pin. A requirements file cannot branch on the installed torch version, so _select_torchcodec_spec follows the existing _select_torchao_spec pattern. It runs after the final torch repair, which can still move torch onto another minor. torchcodec 0.11 is the release upstream pairs with torch 2.11 exactly and the newest one published on the cu128 index install.sh resolves torch 2.11.0 from, since 0.12 dropped CUDA 12.8. From 0.12 torchcodec is ABI stable against torch >= 2.11, so that half of the matrix is open ended and cannot be written as a finite set of minors; both checkers now exempt torchcodec >= 0.12 on torch >= 2.11 rather than flagging a combination upstream supports, and torch 2.12+ installs take the open >=0.12.0 floor instead of the 2.11-only 0.11 line. Also bump the installer step total for the new step and keep torchcodec inside the security audit set now that it no longer comes from a requirements file.
The ABI-stable branch clears torch >= 2.11 paired with torchcodec >= 0.12, but everything else fell through to the lockstep matrix, which has no row past torch 2.11. So torch 2.12 or 2.13 with torchcodec 0.10 or 0.11 hit `allowed is None` and returned no hint at all, even though upstream pins 0.11 to torch 2.11 exactly and 0.10 to torch 2.10 exactly. torchcodec ships no `Requires-Dist: torch`, so pip cannot catch it either and the user only sees a raw "Could not load libtorchcodec" at first use. Split the lookup into three cases: a torch minor below the table stays silent as before, a torch minor with a row keeps the existing per-minor pin and audio-torch2xx extra hint, and a torch minor at or past the ABI-stable floor with no row now points at `torchcodec>=0.12.0`. Mirror the same three-way split in scripts/notebook_validator.py's R-INST-004 so the two stay in step, and cover both with tests plus a regression test that torch below the table still produces no finding.
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. 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". |
# Conflicts: # pyproject.toml # studio/install_python_stack.py # tests/python/test_torchcodec_torch_compat.py
|
Merged main. Three conflicts, and two of them needed a decision rather than a pick, so recording both.
The third,
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e79d61fb7
ℹ️ 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".
| # torchcodec is no longer pinned in extras-no-deps.txt (the installer | ||
| # picks the line matching the venv's torch minor), so pull the newest | ||
| # audio extra in to keep torchcodec inside the audited set. | ||
| audio = d["project"]["optional-dependencies"]["audio-torch211"] |
There was a problem hiding this comment.
Audit the ABI-stable torchcodec line
When Studio updates an environment running torch 2.12 or newer, the new selector installs torchcodec>=0.12.0, but both workflow input builders add only audio-torch211, whose declaration is capped at torchcodec<0.12.0. Consequently pip-audit and scan_packages.py resolve and inspect the 0.11 line rather than any version from the ABI-stable line that this change explicitly supports and installs. Add a separate, non-conflicting audit input for torchcodec>=0.12.0 so that path remains covered.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one. The torchcodec>=0.12.0 arm of _select_torchcodec_spec is
unreachable on every route the installer takes: _CUDA_TORCH_PKG_SPEC and
_CPU_TORCH_PKG_SPEC are torch>=2.4,<2.12.0, _TORCH_FLAVOR_REPAIR_PKG_SPEC is
torch>=2.4,<2.11.0, and install.sh's TORCH_CONSTRAINT is torch>=2.4,<2.12.0. The
selector never sees a torch minor that reaches that row. It exists so a future torch does
not clamp onto the 2.11-only <0.12.0 line, not because anything installs from it today.
A second input would also have to be a separate generated file rather than an extra spec:
torchcodec>=0.11.0,<0.12.0 and torchcodec>=0.12.0 in one requirements set is
unsatisfiable, so pip-audit would fail to resolve instead of auditing both. Worth adding
when a torch 2.12 route actually ships.
Two conflicts, both resolved by keeping each side's intent. studio/backend/requirements/extras-no-deps.txt: main pinned the audio extras to exact versions; this branch removed the flat torchcodec pin because the wheel is torch-ABI specific and a requirements file cannot branch on the installed torch minor. Kept main's exact pins for every other entry and kept the torchcodec line removed, with the comment that points at _select_torchcodec_spec. studio/install_python_stack.py: both sides added at the same anchor. Main replaced the standalone torch probe with a memoized _probe_torch_runtime and kept _probe_installed_torch_version as a thin wrapper over it; this branch added the torchcodec spec table and _select_torchcodec_spec just above. Kept both blocks. Step 13b keeps calling _probe_installed_torch_version, so it now shares main's single probe instead of spawning its own. base_total stays at 13/14: main did not add or drop a progress step, and the three torchcodec sites are mutually exclusive, so exactly one extra step runs. tests/studio/install/test_diffusers_pin.py: the ordering check scanned the raw install_python_stack.py source for requirements filenames, so the torchcodec step's comment explaining why the spec cannot live in extras-no-deps.txt read as an install after the diffusers pin and failed the test. The check is about where `uv pip install -r` runs, so it now scans with comments blanked out and offsets preserved. A real later install still trips it.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b96c786738
ℹ️ 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".
| if ( | ||
| torch_release >= _TORCHCODEC_ABI_STABLE_TORCH | ||
| and codec_release >= _TORCHCODEC_ABI_STABLE_CODEC | ||
| ): | ||
| return None # ABI-stable pairing, not locked to one torch minor |
There was a problem hiding this comment.
Reject CUDA 13 codecs for cu128 torch
When a user has torch==2.11+cu128 and manually installs torchcodec>=0.12, this return treats the pair as compatible solely because of the stable PyTorch ABI. However, studio/install_python_stack.py explicitly keeps 2.11 on torchcodec 0.11 because 0.12 dropped CUDA 12.8 and its PyPI wheel targets CUDA 13. If that wheel consequently fails to load, disable_torchcodec_if_broken() silently disables it because mismatch_hint is None, leaving the user without the matching-build remediation. Account for the CUDA/local build when applying this early return.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one, the premise does not hold. torchcodec publishes no +cuXXX build on
PyPI, and the 0.12 and 0.13 wheels there link no CUDA library at all. On
torchcodec-0.12.0-cp312-cp312-manylinux_2_28_x86_64.whl:
$ readelf -d torchcodec/libtorchcodec_core7.so | grep NEEDED
libtorch.so libc10.so libavutil.so.59 libavcodec.so.61 libavformat.so.61
libavdevice.so.61 libavfilter.so.10 libswscale.so.8 libswresample.so.5
libtorch_cpu.so libstdc++.so.6 libm.so.6 libgcc_s.so.1 libc.so.6
No libcudart, no libtorch_cuda. Same for 0.10.0, 0.11.1 and 0.13.0. The CUDA 13 link
starts at 0.14.0, which adds libcudart.so.13, libnvrtc.so.13, libtorch_cuda.so and
libc10_cuda.so. So torch 2.11+cu128 with torchcodec 0.12 or 0.13 loads, and the early
return is right for it.
The 0.14+ pairing is a real hole, but it is not one this branch opens. origin/main has
no 2.11 row at all, so _torchcodec_version_mismatch_hint() is silent there too:
torch codec main this branch
2.11.0+cu128 0.14.0 silent silent
2.11.0+cu128 0.16.0 silent silent
2.11.0+cu128 0.10.0 silent reported <- what this PR fixes
Closing it means encoding which torchcodec release links which CUDA major, and that has
already moved once inside the 0.12 to 0.16 range. It also needs a hand-installed torchcodec:
_select_torchcodec_spec puts a cu128 torch 2.11 on torchcodec>=0.11.0,<0.12.0, so
nothing here installs 0.14+ next to it.
|
Confirmed the table in unsloth/import_fixes.py still stops at 2.10, so torch 2.11 with the pinned torchcodec 0.10 goes unreported and audio decoding just turns itself off. Will get this reviewed. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d27b961978
ℹ️ 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".
| audio-torch211 = [ | ||
| "torchcodec>=0.11.0,<0.12.0 ; python_version >= '3.10' and (((sys_platform == 'linux' or sys_platform == 'win32') and (platform_machine == 'x86_64' or platform_machine == 'AMD64')) or (sys_platform == 'darwin' and platform_machine == 'arm64'))", | ||
| ] |
There was a problem hiding this comment.
Include the 2.11 audio extra in the Intel XPU bundle
When users install the existing unsloth[intel-gpu-torch2110] umbrella for torch 2.11.0, its definition at pyproject.toml:1305-1307 pulls only unsloth[intelgputorch2110], so this new extra is never selected and those installations still lack torchcodec/audio support. The corresponding torch 2.10 umbrella already includes unsloth[audio-torch210]; add unsloth[audio-torch211] to the 2.11 umbrella as well.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one. audio-torch2xx is wired into the torch 2.10 umbrellas only.
intel-gpu-torch260, -torch270, -torch271, -torch280, -torch290, -torch291,
cu126/cu128/cu130-torch280, -torch290 and -torch291, rocm702-torch280,
rocm72-torch291 and rocm711-torch291 all omit it, including the 2.8 and 2.9 families
where audio-torch280 and audio-torch290 already exist to be pulled in. So
intel-gpu-torch2110 matches every umbrella except the 2.10 ones, and wiring audio into
this one alone would leave the other eight inconsistent in the other direction.
The gap is real, but it is a question about how the bundles compose across all of them,
not part of the guard and per-minor pin here.
| """ | ||
| if not torch_version: | ||
| return _TORCHCODEC_DEFAULT_SPEC | ||
| release = str(torch_version).split("+", 1)[0] # drop +cu128/+rocm7.2/+cpu |
There was a problem hiding this comment.
Preserve the CUDA flavor when selecting torchcodec
On a CUDA 13 Studio install, the final torch repair can resolve torch==2.11.0+cu130 because _CUDA_TORCH_PKG_SPEC allows 2.11, but this discards +cu130 and selects the 0.11 line solely from the minor. The surrounding compatibility rationale identifies 0.11 as the CUDA 12.8 line and 0.12+ as the CUDA 13 build, so this automatically installs a CUDA-mismatched native library and audio decoding is subsequently disabled. Branch on the local CUDA tag, as _select_torchao_spec already does, so cu130 torch 2.11 selects the ABI-stable CUDA 13 line.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one: the wheel this describes is not the one that gets installed. The
torchcodec step runs pip_install("Installing torchcodec", "--no-deps", "--no-cache-dir", _codec_spec) with no --index-url, and _install_env_for_cmd returns None for a
command that pins no index, so it resolves from PyPI. PyPI carries no +cu128 or +cu130
torchcodec, since PEP 440 local versions are not accepted there; those builds exist only
on download.pytorch.org, which this step never reads.
The PyPI 0.11.1 wheel links no CUDA library:
$ readelf -d torchcodec/libtorchcodec_core7.so | grep NEEDED
libtorch.so libc10.so libavutil.so.59 libavcodec.so.61 libavformat.so.61
libavdevice.so.61 libavfilter.so.10 libswscale.so.8 libswresample.so.5
libtorch_cpu.so libstdc++.so.6 libm.so.6 libgcc_s.so.1 libc.so.6
There is nothing in it to mismatch against a +cu130 torch, and the same holds for the
rocm, xpu and cpu builds. That is the difference from _select_torchao_spec: torchao's
cpp extensions do link libcudart, which is why that one has to branch on the CUDA major.
|
Codex Review: Didn't find any major issues. Nice work! 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". |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e72196ab9a
ℹ️ 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".
| _codec_torch_ver = _probe_installed_torch_version() | ||
| _codec_spec = _select_torchcodec_spec(_codec_torch_ver) |
There was a problem hiding this comment.
Recheck the codec pairing on the update fast path
When an otherwise-current managed venv is moved from torch 2.11 to 2.10 without changing its torch flavor—for example, a user pins an older torch release from the same CUDA family—the install manifest still verifies because it records core-package and requirements state, not the torch minor or torchcodec version. Both setup fast paths can therefore skip install_python_stack() entirely, so this new selector never runs and the 0.11 codec left by the prior install remains beside torch 2.10 even though torchcodec declares no dependency that would expose the mismatch. Record enough compatibility state in the manifest or add a fast-path mismatch probe that forces this step.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not taking this one. The manifest records expected_torch_tag, the flavor, so a same-flavor
minor move does not invalidate it and the fast path does skip the step. But that is true of
every version-sensitive selector on that path, _select_torchao_spec included, and reaching
the state needs a hand-installed torch inside the managed venv. Recording compatibility
state in the manifest is a change to its schema and to both fast paths, and it would have to
cover torchao, xFormers and triton to be coherent rather than singling torchcodec out.
The pairing is also not silent, which is what this PR is for. torch 2.10 next to torchcodec
0.11 reaches the guard at import:
torchcodec 0.11.0 is incompatible with torch 2.10.0+cu128; install a matching build with
`pip install 'torchcodec>=0.10,<0.11.0'` or `pip install 'unsloth[audio-torch210]'`.
test_torch210_rejects_torchcodec_011 holds that. Before this PR the reverse case, a
hand-upgrade to torch 2.11 leaving 0.10 in place, had no row at all and reported nothing.
- The per-command scanner replayed the right side of `||`, which runs only when the left FAILS. The rules read a cell as the shell runs it on a working host, so `install codec==0.10 || install codec==0.12` now ends on 0.10. `&&` and `;` both still run. - Attribution used substring membership, so `pip install torch && pip uninstall -y torchaudio` put torch in the uninstall span and read it as removed. Each span is tokenised now. - The provenance remedy suggested a bare `torchcodec`. The accelerator indexes carry the whole line, so on torch 2.9 that installs 0.11 and trades a wrong-accelerator build for a wrong-version one. It now pins the window the table allows, or the ABI-stable floor past the table. - torchcodec's CUDA build dlopens libnppicc and libnppc, and NPP is not in torch's dependency set, so the --no-deps install from a cuNNN index reported success and then failed to import. docker/Dockerfile pairs nvidia-npp-cu12 with the same wheel; the installer now does too, with the major taken from the index leaf so cu13x asks for cu13. Fail-soft, like the codec install itself. Each of the four new tests is red at the parent commit.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f78c3ce05b
ℹ️ 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".
| for requirement in _requirements: | ||
| if ";" in requirement: | ||
| continue |
There was a problem hiding this comment.
Distinguish shell separators from requirement markers
When a quoted requirement is immediately followed by a shell semicolon, shlex leaves the separator attached to the token, so this check mistakes it for a PEP 508 marker and discards the install. For example, !pip install "torchcodec>=0.12"; pip install torch==2.12.0 is modeled as torch 2.12 with the original 0.11 codec and produces a false R-INST-004 error, although the shell actually installs an ABI-compatible 0.12+ codec first. Strip shell punctuation or identify actual marker expressions rather than skipping every token containing ;.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not reproducing at the head. The premise is that shlex leaves the separator attached, and that was true before #10376 landed on this branch: _split_chained now cuts on an unquoted ; before any token reaches shlex, so the separator is gone by then.
Checked six shapes against 4dc370824, all with a resident torch 2.11.0 / torchcodec 0.11.0 Colab oracle:
pip install "torchcodec>=0.12"; pip install torch==2.12.0
pip install "torchcodec>=0.12" ; pip install torch==2.12.0
pip install "torchcodec>=0.12";pip install torch==2.12.0
pip install torchcodec>=0.12;pip install torch==2.12.0
(pip install "torchcodec>=0.12"; pip install torch==2.12.0)
{ pip install "torchcodec>=0.12"; pip install torch==2.12.0; }
Every one gives codec 0.12 and torch 2.12.0, and R-INST-004 emits nothing. The one shape where a ; really is inside the token, pip install "torchcodec>=0.12; python_version>='3.9'", is a genuine PEP 508 marker, evaluates true on 3.12, and is applied rather than skipped.
If you have a shape that still discards the install I will take it, but I am not changing the marker check on this evidence.
…way bash does (#10376) * notebook_validator: read shell prefixes, backticks and case arms the way bash does Split out of #7474. That PR is a torchcodec/torch 2.11 pin; this parser rewrite rode along with it and has since driven every one of its nine review rounds while sharing no code with the pin. Separating them makes each reviewable and revertable on its own. Carries the rewrite as it stood at 75a808c plus fixes for the three P1 defects from the 2026-09-02 round, which were still open. Each one let R-INST-001 miss a `git+` install that bash really would run, and in each case the neighbouring form was already caught, which is what makes them defects rather than gaps. A prefix operand can be spelled like the command. `env -u pip pip install git+...` unsets the variable `pip` and runs the second one, but the executable was located by searching for the first pip-looking word, which selected the operand and produced `pip pip install ...` -- rejected by PIP_LINE_RE, so nothing was collected at all. Prefixes now consume their own options and operands positionally, per a small per-prefix table of the flags that take a separate argument, so the executable is whatever word survives. Backticks were not tracked as substitutions. `_split_chained` knew about quotes and `(`/`{` but never a backtick, so the `;` in ``echo `pip install git+...; echo ok` `` split the line and handed `_substitution_bodies` an unmatched fragment it cannot read. The `$( )` form was handled correctly throughout, which isolates it. There is now a backtick state folded into `in_sub()`, checked before the quote branch because backticks expand inside double quotes. `zip(out, commands)` was not one-to-one. `commands` dropped pieces that unwrapped to empty while `out` kept them, so every later pair slid by one and `zip` stopped at the shorter list. A `case` emits an empty piece per `;;` and its `esac` unwraps to "", so a two-arm `case` left `out` at 5 against `commands` at 2 and the arm holding the substitution was never scanned. Empty pieces are now carried through the pairing and filtered after it. One adjacent defect the same trace exposed: `_unwrap_shell_group` ended with `rstrip(")}")`, which also ate the `)` closing a `$( )` when no `(` had been stripped. Only a grouping bracket is stripped now; a lone `}` from a group that spanned a separator still is, which `_final_bracket_closes_substitution` tells apart. Five tests, all red against the parser at 75a808c and green here, each paired with the control form that already passed. tests/notebooks is 119 passed / 2 skipped; ruff clean. The `"2.11": {"0.11"}` torchcodec row appears here too, because `rule_inst_004_torchcodec_torch` lives in this file and its update depends on `_effective_version` and `_marker_environment` from this rewrite. #7474 adds the same row on its side to keep `test_torchcodec_matrix_matches_notebook_validator` green, so that one line will conflict trivially, with identical content, whichever merges second. * Move the parser's own tests across with it The git+ allowlist, install-cell discovery and pip-skip cases exercise the rewritten parser rather than the torchcodec pin, so they belong here too, along with the _one_cell_notebook helper they share. #7474 keeps only the 24 that are actually about torchcodec, import_fixes and install_python_stack. tests/notebooks: 131 passed, 2 skipped. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Keep parameter expansions literal, land a cap-only install, refresh both oracles Three from the first Codex round on this branch. All three reproduce, and the first is the one that matters most: it is a false positive, so it rejects a clean notebook rather than missing a dirty one. ${X:-a||pip install git+...} is one word to bash. `${` was pushed onto the groupings stack as a plain brace group, so the `||` inside the fallback word was read as a control operator and _split_chained manufactured a conditional pip command that never runs. R-INST-001 then failed the notebook over an echo. `${` is now tracked the way `$(` already was. A $( ) inside an expansion does run and is still read; a real { } group still splits on its own separators. pip install "x<=V" on an absent package installs V. _effective_version treated a cap-only requirement as leaving the package absent, so uninstall followed by a capped reinstall came back None and R-INST-004 said nothing about exactly the downgrade it exists to catch. A cap now names the landing version, since pip takes the highest release the requirement allows. An exclusive ceiling still names nothing, because which release sits below it depends on the index. os-info stopped being human-only when this rewrite gave _marker_environment its Python version, but notebooks-ci.yml still refreshed pip-freeze alone. On a Colab Python rotation that judges a fresh package set against the previous image's Python. The pre-lint step now refreshes both with --all, which writes nothing unless it fetched every oracle, so the fallback is the committed pair and is at least self-consistent. The comment above COLAB_STRICT_ORACLE claimed os-info feeds no rule; it does now, and says so. Three tests, red at the parent, green here. tests/notebooks: 134 passed, 2 skipped. ruff clean, workflow YAML parses. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Drop the duplicate ABI constants left by the restack My conflict resolution when rebasing onto #7474 kept both sides of the constants block, so TORCHCODEC_ABI_STABLE_TORCH and _CODEC were each defined twice. The values are identical, so the later pair wins and nothing misbehaves -- which is exactly why the test suite stayed green and only the duplicate-definition lint caught it. Deleted the second copy. Also escaped the backslash in the escaped-separator test's literal. `"\;"` is not a valid Python escape, so it raised a SyntaxWarning; `"\;"` is the same string with the intent stated. * Treat a top-level extra marker as false, and a pip mention as not an install Two review findings, both false positives on R-INST-004 / R-INST-003, which are error severity and so fail notebook CI on clean notebooks. `extra` is only bound while resolving a selected extra's dependency metadata. A requirement handed straight to pip has the known empty value, so `extra == "foo"` is definitively false and pip drops the requirement. Confirmed against pip: $ pip install --dry-run --no-deps "certifi; extra == 'foo'" Ignoring certifi: markers 'extra == "foo"' don't match your environment Omitting it from the marker environment made _requirement_applies conservatively replay such requirements, so `pip install "torch==2.12.0; extra == 'foo'"` was judged against the Colab baseline and reported a mismatch. A cell can also look like an install and run none: `!echo "pip install foo"` matches the install-cell regex but executes no pip. The compat rules then resolved nothing and compared the oracle against itself, so R-INST-003 reported Colab's own peft/torchao pair as an error in the notebook. A notebook with no install cell at all was always skipped; the lookalike now behaves the same. The cell stays discovered, so the per-cell forbid-pattern rules still inspect it. * Drop the narrow codec-range helper this PR's replay supersedes #7474 fixes R-INST-004's range handling with _effective_requested_version, which re-reads the cell text and takes the highest floor it finds. This PR replaces that with _effective_version, a full replay that walks the invocations in order and tracks whether the version it lands on is exactly known. The rebase kept both, so the replay ran and the narrower helper then overwrote its answer, losing invocation order: `torchcodec>=0.12` followed by `torchcodec==0.11.1` resolved back to 0.12 and the real mismatch went unreported. Three of this PR's own tests caught it. Removed the superseded helper and its bounds parser; _effective_version covers every case they did, which the torchcodec compat suite asserts. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Run notebooks CI when the marker oracle rotates _marker_environment reads the image's Python out of colab_os_info.gpu.txt, which makes that snapshot rule-bearing: an OS-only refresh changes which requirements the validator replays. The pull_request path filter listed only the pip freeze, so such a PR skipped the lint and smoke jobs its change affects. Added the OS snapshot beside it. * Pair the marker oracle with the pip snapshot it is judging Both halves of one mismatch, introduced when _marker_environment started reading the image's Python out of colab_os_info.gpu.txt. The path was hard-coded to scripts/data, so `lint --colab-pin` pointing at a snapshot captured anywhere else evaluated markers against this repo's committed os-info: a different image's interpreter than the packages being judged. The oracle directory now follows the pin. The scheduled job had the same split from the other side. It refreshed only colab_pip_freeze.gpu.txt and then linted, so after a Colab Python rotation it judged freshly refreshed packages with the previous image's interpreter, skipping requirements that apply or replaying ones that do not. The PR-time step already refreshes both with --all --snapshot-dir; the cron now matches it. * Match the repo's kwarg spacing in the new oracle test pre-commit's ruff-format-with-kwargs hook writes `encoding = "utf-8"`; the test I added used the tight form, which is what turned the hook red. * Parse python -m pip, gate compat replay on unconditional installs Three fixes: - PIP_LINE_RE now accepts pip's own recommended `python -m pip` form. The cell regex already selected such a cell, so the invocation list came back empty and R-INST-001 missed a prohibited `git+` install outright. The unused _PIP_WORD_RE that recognised the prefix but was wired to nothing goes away with it. - The whole-notebook compatibility rules now run only when the merged cell has an UNCONDITIONAL pip invocation. `!command -v uv || pip install foo` parses to a conditional one, so the rules replayed nothing and compared the Colab oracle against itself, reporting the base image's own peft/torchao pair against an unrelated notebook. R-INST-001 still sees the conditional path: it runs per cell, before this gate. - os-info drift in its Python line now fails `colab-diff --strict`. _marker_environment reads that line, so it is rule-bearing, but with only the pip freeze named strict a Colab interpreter bump behind an unchanged package set left the cron green and the committed version stale. The rest of os-info, and all of apt-list, stay advisory. Each of the three new tests is red at the parent commit. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Recognise expanded interpreter forms, and gate exception coverage on a real pip run - PIP_LINE_RE only accepted a literal `python*` executable, so `!{sys.executable} -m pip install ...` and `!/usr/bin/python3 -m pip ...` matched _PIP_CELL_RE, yielded no invocation, and slipped past R-INST-001 and every compatibility replay. The interpreter alternatives are now kept in step with docker/unsloth_nb_pip_magic.py, which rewrites the same spellings at runtime. _unwrap_shell_group also stripped a leading `{` unconditionally, leaving `sys.executable}` as the executable. `{` opens a shell group only as its own token, so it is stripped only when whitespace follows; a real `{ pip install x; }` group still unwraps. - rule_l12_exceptions_coverage consumed the raw cells install_cells returns, with no parsed-invocation gate. A documentation-only line such as `!echo "pip install peft"` therefore drew a blocking R-EXC-001 for a policy clause the notebook has no install to carry. cmd_lint already gates on an invocation; this path now does too. Also carries the base branch's PEP 440 zero-padding fix for cmp_versions and its pinned-mirror fix for the torchcodec index, with tests against this branch's API. Each new test is red at the parent commit. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Parse python -m uv pip, and give the cron lint the packaging it needs - The interpreter alternative only accepted `-m pip`, but unsloth_nb_pip_magic rewrites `(pip|uv)` after the module flag and uv's pip-compatible interface is spelled `uv pip <action>`. So `!python -m uv pip install git+...` matched _PIP_CELL_RE, yielded no invocation, and R-INST-001 missed a prohibited source the notebook runs. The tool is now decided by matching `uv pip` as a word pair, so an interpreter path containing "uv" is still plain pip. - The static-with-pypi job installed only pip, and _requirement_applies falls back to "applies" when it cannot import Marker. The daily lint was therefore replaying every environment-marked requirement, including the ones Colab's pip skips, which is the question the refreshed Python-version oracle exists to answer. packaging is now declared there. Also merges the base branch and carries its torch-replay, provenance and Windows-shell tests against this branch's API. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Name the encoding on the workflow reads in the new tests tests/test_source_read_encoding.py forbids reading a checked-in file with the platform default encoding, since it breaks on Windows the moment that file gains a non-ASCII byte. The four notebooks-ci.yml reads added by this PR were missing it. * Tighten the comments added by this PR Compress the explanatory blocks to their load-bearing content: 331 added comment lines down to 287 across the files this PR owns. No behaviour change; the full suite still passes. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
|
Codex Review: Didn't find any major issues. Another round soon, please! 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". |
…g it An unloadable wheel usually raises while torchcodec/__init__ imports its decoders, and Python drops a module whose initialisation raised, so importing it again in the hint just repeated the exception and returned None. The accelerator mismatch went undiagnosed in exactly the case the hint exists to name. The installer's metadata carries the version and needs no native library; an import is still the fallback for a layout the metadata cannot describe.
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! 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". |
# Conflicts: # .github/workflows/notebooks-ci.yml # scripts/notebook_validator.py # tests/notebooks/test_notebook_validator_shell_parsing.py # tests/python/test_torchcodec_torch_compat.py # unsloth/import_fixes.py
|
Merged main now that #10414 has landed, and the diff is down to what this PR actually owns.
The validator work that used to ride along here is in main, so Merge resolutionFive files conflicted. Verification
What that run does not answer: it is the installer's decision functions and the guard's helpers, which import no torch, so it exercises no ROCm stack. The wheel-level question, whether a ROCm torch plus a torchcodec wheel loads on that host, is not something this can reach, since torchcodec publishes no ROCm build. |
|
@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". |
The module asserted the same shape ten times over for the runtime guard, parsed the audio extras' markers twice, and repeated the wheel-gate scaffolding across four platform tests. Every fact it checked is kept, now as case tables: - one parametrized guard test over 19 (torch, torchcodec) pairs, replacing ten near-identical bodies - one gate table for the audio extras covering both the platform and the Python ceiling, plus a check that a newly added extra cannot slip through untested - one anchor table for the wheel gate's documented transitions - an autouse fixture clearing the index environment, so a developer's own UNSLOTH_TORCH_INDEX_URL cannot decide what the suite asserts Also drops test_select_torchcodec_spec_matches_compat_matrix, which loops the guard matrix that test_compat_matrix_matches_the_published_upstream_table already pins to the literal the stronger installer test below it loops. 1,261 lines to 1,132, 76 tests. Verified by breaking each collapsed behaviour in turn (the ABI floor, the ABI codec floor, the aarch64 marker, the Python ceiling, the macOS 14 floor, the 0.1 Python window, and adding an ungated extra) and confirming the tables still fail.
The bug
A fresh NVIDIA install on
mainends up with a torchcodec that does not match its torch, and the guard built to catch that stays quiet.install.sh:3190setsTORCH_CONSTRAINT="torch>=2.4,<2.12.0"for the CUDA branch.download.pytorch.org/whl/cu128tops out attorch-2.11.0+cu128, so the install resolves torch 2.11.0.studio/backend/requirements/extras-no-deps.txt:5pinnedtorchcodec==0.10.0.0.10with torch2.10and0.11with torch2.11. torchcodec publishes noRequires-Dist: torch(its metadata lists onlydevextras), so pip has nothing to resolve against and the mismatch installs cleanly.unsloth/import_fixes.py::_TORCH_TORCHCODEC_MINORShad no"2.11"row. The checker doesallowed = _TORCH_TORCHCODEC_MINORS.get(torch_minor)and thenif allowed is None or codec_minor in allowed: return None, so on torch 2.11 the lookup missed and the function returnedNone. The guard was silent on exactly the version where the mismatch now happens.The user-visible result is a torchcodec whose native libs fail to load against torch 2.11.
disable_torchcodec_if_brokencatches the dlopen failure and quietly disables audio decoding, with no hint about why.The fix
unsloth/import_fixes.py: add"2.11": {"0.11"}, and replace the hardcodedtorch_minor == "2.10"branch ininstall_hintwith a_TORCH_TORCHCODEC_EXTRASlookup so the 2.11 hint points at the new extra.scripts/notebook_validator.py: mirror the row (the two tables are asserted equal bytest_torchcodec_matrix_matches_notebook_validator).pyproject.toml: addaudio-torch211 = ["torchcodec>=0.11.0,<0.12.0 ; python_version >= '3.10'"], alongside the existingaudio-torch210/audio-torch290/audio-torch280.studio/backend/requirements/extras-no-deps.txt+studio/install_python_stack.py: drop the flat pin and select the spec from the venv's torch minor. A flat pin cannot serve both torch lines (install.sh:2207still carries atorch>=2.4,<2.11.0default for some routes while:3190allows 2.11 for CUDA), and pip environment markers cannot see the installed torch version._select_torchcodec_specmirrors the existing_select_torchao_specpattern.Why 0.11 for torch 2.11
Both from upstream's matrix and from the live indexes:
0.11is the release upstream pairs with torch2.11exactly, and it is the newest one on the cu128 index thatinstall.shresolves torch 2.11.0 from: torchcodec 0.12 dropped CUDA 12.8. Pinning wider would resolve differently per index and reintroduce the split, and a 0.12+ wheel pulled from PyPI onto a+cu128torch is a CUDA 13 build.Not flagging combinations upstream supports
torchcodec 0.12 onwards is ABI stable against torch
>= 2.11(its build setsTORCH_TARGET_VERSIONto 2.11), so that half of the matrix is open ended and cannot be expressed as a finite set of minors. Adding only the"2.11": {"0.11"}row would have made both checkers flag torch 2.11 with torchcodec 0.12 through 0.15, which upstream supports, andrule_inst_004_torchcodec_torchis anerror-severity rule. Both checkers now short circuit ontorch >= 2.11 and torchcodec >= 0.12before the table lookup. For the same reason_select_torchcodec_specsends torch 2.12+ to an opentorchcodec>=0.12.0floor rather than clamping onto the 2.11-only<0.12.0line, which is unsatisfiable on the cu132 index.Resulting behaviour:
Ordering
The new install step runs after the final torch repair (step 13), not next to the other extras. That repair force reinstalls torch from the pinned CUDA index and can move it onto another minor, so a torchcodec chosen before it would go stale again, which is the original bug.
Two smaller follow ons from moving the install: the installer's
base_totalis bumped for the new step (TestProgressStepCountMatchesTotalcatches this), andsecurity-audit.ymlnow pullsaudio-torch211into the generated dependency set so torchcodec stays audited now that no requirements file declares it.Tests
New cases in
tests/python/test_torchcodec_torch_compat.py. The load bearing one istest_torch211_rejects_torchcodec_010, which asserts the guard is not silent. On unpatchedmain:After:
Also covered: the ABI stable exemption on both checkers,
_select_torchcodec_specagainst every torch minor and against the pyproject extras, that torch above 2.11 never lands on the capped 0.11 line, and thatextras-no-deps.txtcarries no unconditional torchcodec pin.tests/python/andtests/studio/install/show no new failures againstorigin/mainon the same box, andtests/notebooks/is unchanged.install.shis untouched.