Skip to content

fix incorrect torch version test #2786

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

namgyu-youn
Copy link
Contributor

@namgyu-youn namgyu-youn commented Aug 18, 2025

Summary:
PyTorch pre-release/dev versions have a0/dev in their name. Therefore, the right order is the following:

2.4.0 (stable) < 2.5.0.dev / 2.5.0.git < 2.5.0 (stable)

For correct order, this PR applies true order within stable and pre-release/dev.

Test plan: CI

Copy link

pytorch-bot bot commented Aug 18, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/2786

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 18, 2025
@namgyu-youn namgyu-youn changed the title fix torch version detector fix incorrect torch version test Aug 18, 2025
torchao/utils.py Outdated

# Parser for local identifiers
current_version = re.sub(r"\+.*$", "", torch.__version__)
return parse_version(current_version) >= parse_version(min_version)
Copy link
Contributor

@jerryzh168 jerryzh168 Aug 18, 2025

Choose a reason for hiding this comment

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

I have some impression that we don't want to do this, but @msaroufim would have more context here

Copy link
Member

Choose a reason for hiding this comment

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

seems fine to merge altho we probably want to delete the compare_versions function

Copy link
Contributor Author

@namgyu-youn namgyu-youn Aug 19, 2025

Choose a reason for hiding this comment

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

compare_versions & parse_version are unavailable to used here because parse_version only extracts \d+\.\d+\.\d+ (e.g., 2.5.0→[2, 5, 0]). Therefore, we can inject more parsers (e.g., a0, dev) into parse_version, but I am not certain because check_cpu_version & check_xpu_version are chained with them.

@jerryzh168 jerryzh168 requested a review from msaroufim August 18, 2025 22:48
@msaroufim msaroufim requested a review from andrewor14 August 19, 2025 00:00
@andrewor14 andrewor14 added the topic: improvement Use this tag if this PR is an improvement (doesn't fit into any of the other categories) label Aug 19, 2025
@andrewor14
Copy link
Contributor

Hi @namgyu-youn, thanks for fixing this. I think we should actually fix compare_versions and parse_version instead, since they are used in a few different places. I'm actually wondering if we can express the comparisons like this:

# parse_version
2.5.0+cu126 -> [2, 5, 0]
2.5.0 -> [2, 5, 0]
2.5.0a0+git9f17037 -> [2, 5, -1]
2.5.0.dev20240708+cu121 -> [2, 5, -1]
2.4.0 -> [2, 4, 0]

Basically always return a list of 3 numbers, and -1 represents a pre-release. Then we can just compare as follows:

# don't need compare_versions anymore
parse_version(x) >= parse_version(y)

# These are True
[2, 5, -1] < [2, 5, 0]
[2, 5, -1] > [2, 4, 99]

To me this is simpler than the existing compare_versions logic, which I think is a bit unintuitive to understand. What do you think?

@namgyu-youn
Copy link
Contributor Author

namgyu-youn commented Aug 19, 2025

Hi @namgyu-youn, thanks for fixing this. I think we should actually fix compare_versions and parse_version instead, since they are used in a few different places. I'm actually wondering if we can express the comparisons like this:

# parse_version
2.5.0+cu126 -> [2, 5, 0]
2.5.0 -> [2, 5, 0]
2.5.0a0+git9f17037 -> [2, 5, -1]
2.5.0.dev20240708+cu121 -> [2, 5, -1]
2.4.0 -> [2, 4, 0]

Basically always return a list of 3 numbers, and -1 represents a pre-release. Then we can just compare as follows:

# don't need compare_versions anymore
parse_version(x) >= parse_version(y)

# These are True
[2, 5, -1] < [2, 5, 0]
[2, 5, -1] > [2, 4, 99]

To me this is simpler than the existing compare_versions logic, which I think is a bit unintuitive to understand. What do you think?

Sounds good to me. Customized parse_version was just a careful suggestion, and I also agree with -1 for better logic. Let me fix it with co-authoring; thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. topic: improvement Use this tag if this PR is an improvement (doesn't fit into any of the other categories)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

torch_version_at_least semantics are incorrect
4 participants