Raise ImportError on stable torch/torchvision mismatch#4065
Conversation
Summary of ChangesHello @danielhanchen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the torchvision compatibility check by transitioning from a warning to an ImportError for stable torch and torchvision version mismatches. This change ensures that incompatible stable setups are identified and reported immediately at import time, preventing obscure runtime errors and providing clearer guidance to users. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
The pull request introduces a new test file tests/test_import_fixes_torchvision_compat.py to cover the torchvision_compatibility_check function. The main change in unsloth/import_fixes.py is to make stable torch/torchvision mismatches raise an ImportError instead of just a warning, while still allowing custom/prerelease builds to only warn. This is a good change to prevent runtime errors from incompatible versions. The new tests adequately cover the intended behavior of the compatibility check, including stable mismatches, environment variable skipping, and prerelease warnings.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 333810210c
ℹ️ 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".
|
|
||
| import pytest | ||
|
|
||
| os.environ.setdefault("UNSLOTH_SKIP_TORCHVISION_CHECK", "1") |
There was a problem hiding this comment.
Remove module-level env mutation from test module
Setting UNSLOTH_SKIP_TORCHVISION_CHECK at module import time makes this test file mutate process-wide state during pytest collection, and that state is never restored; when this file is imported before other tests that import unsloth, those tests will silently skip the torchvision compatibility guard and can miss real regressions. This creates order-dependent behavior in full-suite runs, so the env override should be scoped inside individual tests/fixtures (e.g., via monkeypatch).
Useful? React with 👍 / 👎.
* Raise ImportError for stable torchvision mismatches * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Remove torchvision compatibility tests from PR scope --------- Co-authored-by: Daniel Hanchen <danielhanchen@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Summary
torchvision_compatibility_check()fail fast for stable version mismatches, including inferred mappings for newer stable torch releasesImportErrorWhy
A warning on stable mismatches can defer failure until runtime with errors like
operator torchvision::nms does not exist. This change surfaces the incompatibility at import-time with a clear actionable message.Validation
torch==2.10.0+cu130,torchvision==0.24.1) confirmstorchvision_compatibility_check()now raisesImportError