Repository navigation
fix: add tokenizers to no-torch deps and TORCH_CONSTRAINT for arm64 macOS py313+ - #4748
Conversation
… for arm64 macOS py313+ Two installer fixes: 1. Add `tokenizers` to `no-torch-runtime.txt` before `transformers`. Without it, `from transformers import AutoConfig` crashes on startup because `--no-deps` skips transitive dependencies. 2. Add `TORCH_CONSTRAINT` variable to `install.sh`. On arm64 macOS with Python 3.13+, tighten the torch requirement to `>=2.6` since torch <2.6 has no cp313 arm64 wheels. The variable replaces the previously hard-coded constraint in the uv pip install line. Includes 66 tests (42 pytest + 24 bash) covering: - Structural checks on install.sh, install.ps1, no-torch-runtime.txt - Shell snippet tests with mocked python for 13 platform/version combos - Mock uv integration verifying correct constraint string - E2E venv tests on Python 3.12 and 3.13 confirming AutoConfig works - Negative control proving AutoConfig fails without tokenizers - Full no-torch sandbox regression guards (safetensors, huggingface_hub)
There was a problem hiding this comment.
Code Review
This pull request introduces a TORCH_CONSTRAINT variable in install.sh to ensure that Python 3.13+ on arm64 macOS uses torch>=2.6, addressing wheel availability issues. It also adds tokenizers to the no-torch-runtime.txt requirements to prevent crashes during AutoConfig imports. Comprehensive tests, including both shell and Python scripts, have been added to verify these changes. Feedback was provided regarding the portability of sed -i in the new shell tests, suggesting the use of heredocs instead to ensure compatibility across different sed implementations.
| cat > "$TMPDIR_BASE/mock_uv_tight" <<'UVEOF' | ||
| #!/bin/bash | ||
| echo "$@" >> UV_LOG_PLACEHOLDER | ||
| UVEOF | ||
| sed -i "s|UV_LOG_PLACEHOLDER|$_UV_LOG|" "$TMPDIR_BASE/mock_uv_tight" | ||
| chmod +x "$TMPDIR_BASE/mock_uv_tight" |
There was a problem hiding this comment.
The use of sed -i is not portable across different sed implementations. For instance, BSD sed (default on macOS) requires an extension argument (e.g., sed -i ''), whereas GNU sed does not. Since this pull request specifically targets macOS fixes, ensuring test portability is important. Additionally, using | as a delimiter in sed can fail if the path in $_UV_LOG contains that character. A more robust and portable approach is to use an unquoted heredoc to expand the variable directly when creating the mock script.
| cat > "$TMPDIR_BASE/mock_uv_tight" <<'UVEOF' | |
| #!/bin/bash | |
| echo "$@" >> UV_LOG_PLACEHOLDER | |
| UVEOF | |
| sed -i "s|UV_LOG_PLACEHOLDER|$_UV_LOG|" "$TMPDIR_BASE/mock_uv_tight" | |
| chmod +x "$TMPDIR_BASE/mock_uv_tight" | |
| cat > "$TMPDIR_BASE/mock_uv_tight" <<UVEOF | |
| #!/bin/bash | |
| echo "\$@" >> $_UV_LOG | |
| UVEOF | |
| chmod +x "$TMPDIR_BASE/mock_uv_tight" |
| cat > "$TMPDIR_BASE/mock_uv_default" <<'UVEOF' | ||
| #!/bin/bash | ||
| echo "$@" >> UV_LOG_PLACEHOLDER | ||
| UVEOF | ||
| sed -i "s|UV_LOG_PLACEHOLDER|$_UV_LOG2|" "$TMPDIR_BASE/mock_uv_default" | ||
| chmod +x "$TMPDIR_BASE/mock_uv_default" |
There was a problem hiding this comment.
Similar to the previous comment, sed -i is not portable and the delimiter choice is risky. Using an unquoted heredoc is a more robust way to inject the log path into the mock script.
| cat > "$TMPDIR_BASE/mock_uv_default" <<'UVEOF' | |
| #!/bin/bash | |
| echo "$@" >> UV_LOG_PLACEHOLDER | |
| UVEOF | |
| sed -i "s|UV_LOG_PLACEHOLDER|$_UV_LOG2|" "$TMPDIR_BASE/mock_uv_default" | |
| chmod +x "$TMPDIR_BASE/mock_uv_default" | |
| cat > "$TMPDIR_BASE/mock_uv_default" <<UVEOF | |
| #!/bin/bash | |
| echo "\$@" >> $_UV_LOG2 | |
| UVEOF | |
| chmod +x "$TMPDIR_BASE/mock_uv_default" |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6b6b616845
ℹ️ 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".
| self._pip_install( | ||
| venv, | ||
| "tokenizers", "transformers", "huggingface_hub", | ||
| "safetensors", "packaging", "pyyaml", "numpy", | ||
| ) |
There was a problem hiding this comment.
Assert install succeeds before checking torch absence
test_torch_not_importable ignores the result of _pip_install(...), so this test can pass even when dependency installation fails (for example due to resolver/network/index issues) because import torch will still fail in an empty or partially installed venv. That makes this E2E check a false positive and can hide regressions in the no-torch requirements; capture the install result and assert returncode == 0 before asserting torch is unavailable.
Useful? React with 👍 / 👎.
…eps path - Add missing transitive deps to no-torch-runtime.txt that are required under --no-deps: regex, typing_extensions, filelock, httpx, httpcore, certifi, idna, anyio, sniffio, h11. Without these, `from transformers import AutoConfig` still fails after install.sh --no-torch. - Change all E2E tests to use --no-deps (matching what install.sh does) instead of normal dep resolution. Previous tests passed even with an incomplete manifest because uv backfilled transitive deps. - Rewrite negative control to derive from the real no-torch-runtime.txt with tokenizers stripped, proving the specific fix matters. - Replace GNU-only sed -i with heredoc in shell test for macOS compat. - Remove unused os/sys imports from Python test file. - Quote SKIP_TORCH and mock uv paths in bash -c strings.
|
/gemini review |
Address review feedback: test_torch_not_importable and test_tokenizers_directly_importable in Group 3 now assert that uv pip install returns 0 before checking import behavior. This prevents false positives when the install itself fails silently.
There was a problem hiding this comment.
Code Review
This pull request introduces a dynamic TORCH_CONSTRAINT in install.sh to ensure compatibility for arm64 macOS users on Python 3.13+ and adds several transitive dependencies to no-torch-runtime.txt to prevent AutoConfig crashes during --no-deps installations. It also includes a new suite of structural and end-to-end tests. Review feedback highlights the potential need for requests and its dependencies in the requirements file to support remote Hub operations and notes PEP 8 styling inconsistencies regarding keyword argument spacing in the new test code.
| regex | ||
| typing_extensions | ||
| filelock | ||
| httpx | ||
| httpcore | ||
| certifi | ||
| idna | ||
| anyio | ||
| sniffio | ||
| h11 |
There was a problem hiding this comment.
While adding these transitive dependencies helps resolve import issues, requests (and its own dependencies like urllib3 and charset-normalizer) appears to be missing from this list. Since transformers and huggingface_hub are installed with --no-deps in this context, requests is required for most remote operations, such as fetching model configurations from the Hub. Consider adding it to ensure the environment is functional beyond just basic imports.
|
|
||
|
|
||
| def _read(path: pathlib.Path) -> str: | ||
| return path.read_text(encoding = "utf-8") |
There was a problem hiding this comment.
This line uses spaces around the = sign for a keyword argument (encoding = "utf-8"), which violates PEP 8. This style is pervasive throughout the new test file (e.g., lines 160, 185, 392, 514).
| return path.read_text(encoding = "utf-8") | |
| return path.read_text(encoding="utf-8") |
References
- PEP 8: Don’t use spaces around the = sign when used to indicate a keyword argument, or when used to indicate a default value for an unannotated function parameter. (link)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bc6ec6cda3
ℹ️ 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".
| ), | ||
| encoding = "utf-8", | ||
| ) | ||
| self._pip_install(venv, "--no-deps", "-r", str(req_no_tokenizers)) |
There was a problem hiding this comment.
Assert negative-control requirements install succeeds
Capture and check the return code from _pip_install(...) here before asserting AutoConfig import failure. In its current form, this negative-control test can pass when the requirements install fails for unrelated reasons (resolver/network/index issues), because from transformers import AutoConfig then fails simply because transformers was never installed, producing the same ModuleNotFoundError the test expects.
Useful? React with 👍 / 👎.
- Add missing install-success assertion in test_negative_control_no_tokenizers to prevent false positives from network/install failures. - Tighten error message check to look for "tokenizers" in stderr or ModuleNotFoundError, rather than the generic "No module" substring which could match unrelated import failures.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a dynamic TORCH_CONSTRAINT in install.sh to handle specific requirements for macOS arm64 on Python 3.13+, ensuring compatibility where older PyTorch wheels are unavailable. It also updates no-torch-runtime.txt with several transitive dependencies, such as tokenizers and httpx, which are necessary when installing with the --no-deps flag. A comprehensive suite of structural and end-to-end tests has been added to verify these installation fixes. Feedback indicates that additional transitive dependencies like requests, urllib3, and fsspec may still be required to ensure the no-torch environment is fully functional.
| regex | ||
| typing_extensions | ||
| filelock | ||
| httpx | ||
| httpcore | ||
| certifi | ||
| idna | ||
| anyio | ||
| sniffio | ||
| h11 |
There was a problem hiding this comment.
While adding httpx and its dependencies is necessary for newer versions of huggingface_hub, several other critical transitive dependencies for transformers and huggingface_hub appear to be missing from this --no-deps list. Specifically, requests, urllib3, charset-normalizer, and fsspec are required for core functionality like downloading models and managing the cache. Without these, from transformers import AutoConfig or any subsequent from_pretrained call is likely to fail in a clean environment. Consider adding them to ensure the 'no-torch' environment is fully functional.
Review Summary (3 iterations)Ran 3 full review cycles with 5 parallel automated reviewers + 3 independent manual reviews each round (8 reviewers per cycle, 24 total reviews). Round 1 findings (all fixed)
Round 2 findings
Round 3 findings
Gemini review findings
Test resultsAll 66 tests pass consistently (ran 3x for stability):
VerificationManually confirmed in a clean isolated venv that |
…acOS py313+ (unslothai#4748) * fix: add tokenizers to no-torch runtime deps and add TORCH_CONSTRAINT for arm64 macOS py313+ Two installer fixes: 1. Add `tokenizers` to `no-torch-runtime.txt` before `transformers`. Without it, `from transformers import AutoConfig` crashes on startup because `--no-deps` skips transitive dependencies. 2. Add `TORCH_CONSTRAINT` variable to `install.sh`. On arm64 macOS with Python 3.13+, tighten the torch requirement to `>=2.6` since torch <2.6 has no cp313 arm64 wheels. The variable replaces the previously hard-coded constraint in the uv pip install line. Includes 66 tests (42 pytest + 24 bash) covering: - Structural checks on install.sh, install.ps1, no-torch-runtime.txt - Shell snippet tests with mocked python for 13 platform/version combos - Mock uv integration verifying correct constraint string - E2E venv tests on Python 3.12 and 3.13 confirming AutoConfig works - Negative control proving AutoConfig fails without tokenizers - Full no-torch sandbox regression guards (safetensors, huggingface_hub) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Fix incomplete no-torch manifest and align E2E tests with real --no-deps path - Add missing transitive deps to no-torch-runtime.txt that are required under --no-deps: regex, typing_extensions, filelock, httpx, httpcore, certifi, idna, anyio, sniffio, h11. Without these, `from transformers import AutoConfig` still fails after install.sh --no-torch. - Change all E2E tests to use --no-deps (matching what install.sh does) instead of normal dep resolution. Previous tests passed even with an incomplete manifest because uv backfilled transitive deps. - Rewrite negative control to derive from the real no-torch-runtime.txt with tokenizers stripped, proving the specific fix matters. - Replace GNU-only sed -i with heredoc in shell test for macOS compat. - Remove unused os/sys imports from Python test file. - Quote SKIP_TORCH and mock uv paths in bash -c strings. * Assert install succeeds before checking import results in E2E tests Address review feedback: test_torch_not_importable and test_tokenizers_directly_importable in Group 3 now assert that uv pip install returns 0 before checking import behavior. This prevents false positives when the install itself fails silently. * Assert install succeeds in negative control and tighten error check - Add missing install-success assertion in test_negative_control_no_tokenizers to prevent false positives from network/install failures. - Tighten error message check to look for "tokenizers" in stderr or ModuleNotFoundError, rather than the generic "No module" substring which could match unrelated import failures. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: Daniel Han <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…control setup.ps1 is what Windows updates run and it already carries the anyio repair probe this one is modelled on, so the tokenizers probe belongs beside it rather than only in setup.sh. Exercised against real venvs through pwsh: a stranded pair forces the dependency pass, a healthy pair and an unreadable one do not, matching the bash sibling case for case. tests/python/test_tokenizers_and_torch_constraint.py's negative control dropped the tokenizers line by comparing the whole line against "tokenizers". That matched the bare entry #4748 added and matched nothing once #5359 gave it a version bound, so the control installed tokenizers and then asserted an import failure that could not happen. It has been failing on every tree since, unnoticed because the class carries the e2e marker the CI lane filters out. Match by package name instead, which survives the next bound too. The class passes 7/7.
…ort (#10431) * Pin tokenizers with transformers so Apple Silicon keeps Train and Export transformers declares a tokenizers window and enforces it at import, so a venv holding a transformers that rejects its tokenizers cannot 'import transformers' at all. mlx_lm imports transformers, so mlx_stack_blockers() reports a blocker and Studio settles chat-only with Train and Export disabled. A fresh 'install.sh --local' on macOS arm64 produced exactly that pair. The core phase resolves with UV_OVERRIDE=overrides-darwin-arm64.txt and without constraints.txt, and a uv override replaces every requirement on a package, so that file's unbounded 'transformers>=5.5.0' also replaced pyproject's <=5.5.0 cap. Since transformers 5.16.0 (2026-08-26), the first release wanting tokenizers>=0.23.1, that resolve lands transformers 5.16.1 + tokenizers 0.23.2; step 3b of install_python_stack.py then installs extras-no-deps.txt with --no-deps, which pins transformers back to 5.5.0 and leaves tokenizers stranded. No commit here caused it: a third-party release walked into an unbounded override, which is why the new gate checks the resolved pair rather than a version number a diff would show. extras-no-deps.txt now names both halves, which is the file that decides the final versions on every platform and on both fresh install and update. constraints.txt carries the same window globally, for the reason the anyio cap gives: a later with-deps step must not re-resolve it up. no-torch-runtime.txt spells its existing cap as the same full window so one canonical pair exists. setup.sh gets a sibling of the anyio repair probe: an already-broken venv whose unsloth is current takes the fast update path, which never reaches the step that repairs the pair, so 'unsloth studio update' would report 'up to date' and fix nothing. It reads metadata rather than importing transformers, since importing is what is broken. tests/studio/install/test_transformers_tokenizers_pair.py locks the shape: every installing requirements file that pins transformers must bound tokenizers to the window that release declares, no file may admit 0.23.2, and a sequential resolve of the real macOS arm64 install (core phase, then the --no-deps overlay) must end with a pair transformers accepts. On the tree before this commit, four of its six checks fail. * Drop two stale deselects from Backend CI Both named a tokenizers pin no-torch-runtime.txt was missing; #5359 added it and both tests pass now. They were redundant regardless: the -m filter on the same command already excludes their e2e class marker. * Bound the macOS arm64 transformers override to the version it pins against The override existed to raise mlx-vlm/mlx-lm's transformers floor, but an override replaces every requirement on the package, so the bare floor also replaced unsloth's own transformers<=5.5.0 cap on the one uv command that does not pass constraints.txt: install.sh's core install. From transformers 5.16.0 that resolve started landing 5.16.1 with tokenizers 0.23.2 on Apple Silicon, which the later --no-deps pin turned into a stranded pair. Capping at the version constraints.txt already pins makes the core phase resolve consistently on its own rather than being repaired a step later. Verified with uv pip compile for aarch64-apple-darwin / py3.13: transformers 5.5.0, tokenizers 0.22.2, and mlx 0.32.1 / mlx-lm 0.31.3 / mlx-vlm 0.6.17 unchanged from the uncapped resolve. This cannot go unsatisfiable the way the huggingface_hub override once did: that one replaced other packages' requirements on hub while a direct requirement still had to be satisfied, whereas no requirement on transformers survives this override to contradict it. A new test keeps the override and constraints.txt in lockstep. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Give the repair probe a Windows sibling, and restore a dead negative control setup.ps1 is what Windows updates run and it already carries the anyio repair probe this one is modelled on, so the tokenizers probe belongs beside it rather than only in setup.sh. Exercised against real venvs through pwsh: a stranded pair forces the dependency pass, a healthy pair and an unreadable one do not, matching the bash sibling case for case. tests/python/test_tokenizers_and_torch_constraint.py's negative control dropped the tokenizers line by comparing the whole line against "tokenizers". That matched the bare entry #4748 added and matched nothing once #5359 gave it a version bound, so the control installed tokenizers and then asserted an import failure that could not happen. It has been failing on every tree since, unnoticed because the class carries the e2e marker the CI lane filters out. Match by package name instead, which survives the next bound too. The class passes 7/7. * Exclude the pinned release from the override test's excess check * Derive the override's excess candidates from the pin Building on the previous commit, which was right that the pinned release must not count as excess. The remaining half is that a fixed pair of releases goes vacuous once the pin passes them: with 5.16.1 pinned, neither 5.16.1 nor 5.15.1 is above it and the check tests nothing. Derive the next minor and the next major from the pin, keep the two named releases since they are the ones that shipped the tokenizers window change, and the assertion keeps asking its question after every future bump. Verified both ways: passes on this branch, and against an unbounded override it reports ['5.15.1', '5.16.1', '5.6.0', '6.0.0']. * Make the resolver check fail only on a resolver verdict Codex is right that this test runs in the ordinary CPU lane and reaches the index twice plus a urlopen, so it had two ways to turn someone else's PR red for reasons that say nothing about our pins: subprocess.TimeoutExpired was not caught at all, and any uv failure whose stderr missed a four-word list became a hard failure, which a 429 or an index 500 would. Inverted instead of marked. Marking it e2e would take it out of the lane the regression it guards actually reaches, and the e2e marker is registered in tests/python/conftest.py, which does not cover this directory. Now the test fails only when uv returns a resolution verdict (no solution found, unsatisfiable, because, conflict) and skips on everything else, including a timeout, a missing uv, an OSError, and a PyPI reply that is slow, throttled or not JSON. The compile budget drops from 600s to 180s so a hung index cannot hold a job for ten minutes. Verified all three ways against a live uv: an unreachable index skips, an unsatisfiable pair still fails with 'No solution found when resolving dependencies: Because transformers==5.5.0 depends on tokenizers>=0.22.0,<=0.23.0', and a healthy resolve returns. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Nilay Yadav <[email protected]>
Summary
tokenizerstono-torch-runtime.txt(beforetransformers). Without it,from transformers import AutoConfigcrashes on startup because--no-depsskips transitive dependencies.TORCH_CONSTRAINTvariable toinstall.sh. On arm64 macOS with Python 3.13+, tightens torch requirement to>=2.6since torch <2.6 has no cp313 arm64 wheels. Replaces the hard-coded constraint in theuv pip installline.install.ps1is intentionally left unchanged -- Windows/PowerShell does not need the arm64 macOS guard.Changes
studio/backend/requirements/no-torch-runtime.txttokenizersbeforetransformersinstall.shTORCH_CONSTRAINTvariable with arm64+macOS+py313+ tightening; use$TORCH_CONSTRAINTin pip installtests/python/test_tokenizers_and_torch_constraint.pytests/sh/test_torch_constraint.shtests/run_all.shtests/python/conftest.pye2emarkerTest coverage (66 total, all passing)
Structural checks (instant, no network):
tokenizerspresent as standalone line, appears beforetransformers,torchnot in fileTORCH_CONSTRAINTdefault and tightened assignments exist ininstall.sh$TORCH_CONSTRAINTused in pip install line (not hard-coded)torch>=2.4,<2.11.0appears exactly once (default assignment only)SKIP_TORCH=false,arm64, andmacosinstall.ps1unchanged: noTORCH_CONSTRAINTvariable, still has hard-coded constraintShell snippet tests (bash subprocess, mocked python, no network):
13 platform/version combinations:
torch>=2.6,<2.11.0(tightened)E2E tests (real uv venvs, Python 3.12 and 3.13):
from transformers import AutoConfigsucceeds with tokenizers installedtokenizersdirectly importabletorchNOT importable (no-torch scenario maintained)Test plan
Fast tests run in <1s, E2E tests take ~10s (cached) to ~5min (cold):