Skip to content

Conversation

@winglian
Copy link
Contributor

@winglian winglian commented Apr 9, 2025

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.0

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

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.

@github-actions github-actions bot marked this pull request as draft April 9, 2025 19:28
@github-actions
Copy link
Contributor

github-actions bot commented Apr 9, 2025

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 Ready for review button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@winglian winglian marked this pull request as ready for review April 9, 2025 19:31
@github-actions github-actions bot requested review from MekkCyber and SunMarc April 9, 2025 19:31
Copy link
Collaborator

@ArthurZucker ArthurZucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks 🫡

@ArthurZucker ArthurZucker merged commit 9cda426 into huggingface:main Apr 9, 2025
7 checks passed
Copy link
Contributor

@vasqu vasqu left a 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

@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?

@Kh4L
Copy link
Contributor

Kh4L commented Apr 9, 2025

@vasqu you're right, using that helper func in #37400

LysandreJik pushed a commit that referenced this pull request Apr 14, 2025
cyr0930 pushed a commit to cyr0930/transformers that referenced this pull request Apr 18, 2025
zucchini-nlp pushed a commit to zucchini-nlp/transformers that referenced this pull request May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants