Repository navigation
Tell users to upgrade the dependency, not transformers, when a --no-deps install leaves a floor unmet - #8212
Conversation
…eps install leaves a floor unmet Notebooks that need a bleeding-edge model install transformers from git with --no-deps on purpose so pip cannot re-resolve torch. pip then never enforces what that transformers requires; it prints a warning and the install succeeds, and the break lands later at import. transformers' own message points at the wrong remedy for that situation. Read the requirement set from the installed distribution's metadata, compare with packaging, and warn naming the dependency to upgrade.
|
Codex Review: Didn't find any major issues. Bravo. 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: 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". |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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 problem
Notebooks that need a bleeding-edge model install transformers from git with
--no-deps, deliberately, so pip cannot re-resolve torch:--no-depsalso means pip never enforces what that transformers actually requires. pip prints a warning and the install "succeeds":The failure lands two cells later, at import:
This killed
Liquid_LFM2-ConversationalandKaggle-Liquid_LFM2_(1.2B)-Conversationalon Kaggle T4. Kaggle ships safetensors 0.7.0; transformers main wants 0.8.0.The load-bearing part is the remedy transformers suggests.
pip install transformers -Uis exactly the wrong move for someone who is deliberately on main: it either downgrades them off the model support they installed main for, or it loops. What they actually need ispip install -U safetensors. The notebooks were patched to floor hub, safetensors and tokenizers, but that only covers the notebooks we already know broke.What this adds
check_transformers_dependency_versions()inunsloth/import_fixes.py, called from_gpu_init.pybefore anything imports transformers. It compares the installed versions of transformers' own declared requirements against what transformers declares, and reports the shortfalls with the correct remedy:Design notes:
importlib.metadata.requires("transformers")), never a hardcoded table and never the network. A table would rot into a second copy of the bug. It also has to be metadata: the base requirements genuinely differ across the supported range, 4.57.6 declareshuggingface-hub<1.0,>=0.34.0andsafetensors>=0.4.3, 5.14.1 declareshuggingface-hub<2.0,>=1.5.0andsafetensors>=0.8.0and dropsfilelockandrequestswhile addingtyper.packaging, not strings, so0.10.0against>=0.8.0is a pass and not a false report.extra = "", so extras (extra == "torch",extra == "ja") and inapplicablepython_version/sys_platformgates are skipped. Otherwise the check would nag about packages the user is right not to have.import unsloth.importlib.metadatapluspackaging, so no shelling out and no path assumptions; correct on Linux, macOS, Windows and WSL.Warn, not raise
It warns. By the time transformers is imported the mismatch is already fatal and the user sees transformers' own message anyway, so a warning landing just before it adds the correct remedy rather than replacing an error with another error. The floors are also read generically, and a given floor may be advisory for the code path a particular user is on, so turning any of them into a hard import failure would break environments that work today. This matches
check_fbgemm_gpu_version, which degrades rather than stops;torchvision_compatibility_checkraises, but only because it checks a curated (torch, torchvision) table where a stable mismatch guarantees broken operators.Verification
tests/test_transformers_dependency_floor.pydrive the real functions: satisfied sets for both 4.57.6 and 5.14.1 metadata (silent), the Kaggle violation (reported, naming safetensors as the thing to upgrade, and contradictingpip install transformers -U), the0.10.0vs0.8.0string-comparison trap, multiple violations in one command, prereleases, inapplicable markers skipped, applicable markers still checked, absent optional packages not reported, five flavours of unparseable input, missing transformers metadata, the skip env var, a live run against the real environment, and a guard that the check is actually wired into_gpu_init.py.packagingcomparison to a string compare turns 5 of the new tests red (exit 1); removing the_gpu_init.pycall turns the registration test red (exit 1). Restored, the file is 22 passed, exit 0.import unslothstill works. The check costs about 22 ms, against a 14.5 s import; median wall time with and without it is 14.55 s and 15.02 s, so it is under the run-to-run noise.