-
Notifications
You must be signed in to change notification settings - Fork 368
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
Changes from 1 commit
0ada4b5
de7a877
3818cbf
747026b
37b7089
05edf52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -368,7 +368,14 @@ def is_fbcode(): | |||||
|
|
||||||
|
|
||||||
| def torch_version_at_least(min_version): | ||||||
| return is_fbcode() or compare_versions(torch.__version__, min_version) >= 0 | ||||||
| from packaging.version import parse as parse_version | ||||||
|
|
||||||
| if is_fbcode(): | ||||||
| return True | ||||||
|
|
||||||
| # Parser for local identifiers | ||||||
| current_version = re.sub(r"\+.*$", "", torch.__version__) | ||||||
| return parse_version(current_version) >= parse_version(min_version) | ||||||
|
||||||
| def is_package_at_least(package_name: str, min_version: str): |
I vaguely remember at some point that we don't want to use parse version, but don't remember why though
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.
btw we also have
Line 1002 in 43b4106
def is_package_at_least(package_name: str, min_version: str): , should we just reuse that? not sure if this works for pre-releases as well, could you check?
I vaguely remember at some point that we don't want to use parse version, but don't remember why though
Installation
# 2.8.0 stable
pip install torch --index-url https://download.pytorch.org/whl/cpu
# 2.9.0 pre-release (nighty)
pip install torch --index-url https://download.pytorch.org/whl/nightly/cpuTest code
test_cases = ["2.8.0a0+git9f17037", "2.8.0", "2.9.0a0+git9f17037", "2.9.0", "2.10.0a0+git9f17037", "2.10.0"]
print(torch.__version__)
print(torch.version)
for test in test_cases:
print(torch_version_at_least(test), is_package_at_least(package_name="torch", min_version=test))
Result
# stable
2.8.0+cpu
<module 'torch.version' from 'ao/.venv/lib/python3.12/site-packages/torch/version.py'>
True False
True True
False False
False False
False True
False True
# pre-release (nighty)
2.9.0.dev20250821+cpu
<module 'torch.version' from 'ao/.venv/lib/python3.12/site-packages/torch/version.py'>
True True
True True
True False
False True
False True
False TrueIt seems that is_package_at_least() doesn't work for both stable/pre-release becauseversion() returns the module object; __version__() returns the actual version string. In my naive guess, torch_version_at_least and is_package_at_least can be consolidated because they share "return true if installed <package/torch> is higher than required" (with PyTorch pre-release detection). How about consolidating them?
Uh oh!
There was an error while loading. Please reload this page.