-
Notifications
You must be signed in to change notification settings - Fork 31.7k
handle torch version edge cases #37399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the |
ArthurZucker
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 🫡
vasqu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of manually parsing strings tbh.
I'd prefer something like
transformers/src/transformers/utils/import_utils.py
Lines 1060 to 1075 in e032d12
| @lru_cache() | |
| def is_torch_greater_or_equal(library_version: str, accept_dev: bool = False): | |
| """ | |
| Accepts a library version and returns True if the current version of the library is greater than or equal to the | |
| given version. If `accept_dev` is True, it will also accept development versions (e.g. 2.7.0.dev20250320 matches | |
| 2.7.0). | |
| """ | |
| if not _is_package_available("torch"): | |
| return False | |
| if accept_dev: | |
| return version.parse(version.parse(importlib.metadata.version("torch")).base_version) >= version.parse( | |
| library_version | |
| ) | |
| else: | |
| return version.parse(importlib.metadata.version("torch")) >= version.parse(library_version) |
This should catch the +cuXXX versions as well (i think). Wdyt?
What does this PR do?
If torch is installed as
torch==2.6.0+cu126, then this check fails to detect it as 2.6.0Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@ArthurZucker @SunMarc
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.