-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Extend import utils to cover "editable" torch versions #29000
Conversation
Why formatting error we have? it isn't clear from the CI log |
The repository uses double quotes for string literals. You can format your code by running 'make style' (see contributor guideline). |
Done, who can review this? |
@bhack Thanks for opening this PR! For anyone who's coming to this PR in the future, could you share the torch version in your environment i.e. when running I've requested a review from @ydshieh as he is the king of all things version and package handling. I'd like to get his opinion before we merge. He's off for a for days, so would next week when this can get merged in. |
Gently ping |
It is in the mentioned ticket in the description. This is for the |
@bhack Yes, I understand it's for the dev version, what I'm asking for is how that appears in your env when running |
These are the nightly releases.. you can find the patterns at https://download.pytorch.org/whl/nightly/torch/ |
Hi @bhack Thank you for the PR. I am up to have this, but I am worried about the fact that the dev version might cause problem in the ecosystem.
Would they fail? Would they give the correct results? ect. |
Are we not working with this on |
Well, I might lack some context, but my understanding is if So Hope the above make my concern a bit more clear |
Yes but I don't understand your example. Where we are using this? version.parse(_torch_version)
and
version.parse(_torch_version) >= version.parse("2.1.1") |
If you meant here:
We can add the 'dev` version as it has the date as a fake version and control the date. |
E.g just tested the PR code today and the ``` 2.3.0.dev20240314` import importlib
from importlib import metadata
package_exists = importlib.util.find_spec("torch") is not None
pkg_name="torch"
try:
# Primary method to get the package version
package_version = importlib.metadata.version(pkg_name)
package_exists = True
except importlib.metadata.PackageNotFoundError:
# Fallback method: Only for "torch" and versions containing "dev"
if pkg_name == "torch":
try:
package = importlib.import_module(pkg_name)
temp_version = getattr(package, "__version__", "N/A")
# Check if the version contains "dev"
if "dev" in temp_version:
package_version = temp_version
package_exists = True
else:
package_exists = False
except ImportError:
# If the package can't be imported, it's not available
package_exists = False
else:
# For packages other than "torch", don't attempt the fallback and set as not available
package_exists = False
print(f"Detected version {package_version}")
print(f"Detected version: {package_version}")
from packaging import version
assert(version.parse(package_version) >= version.parse("2.1.1")) |
Very nice! Thank you for checking, that's exactly what I am looking for. @amyeroberts I tried to do the same (install torch editable version, but it took forever). The changes in this PR LGTM however. |
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.
Thank you
BTW, @bhack could you rebase the PR on the latest main branch? Thanks. |
Done |
Strange, follow the official mentiond pytorch contributing markdown for rightly It is quite fast to prepare. |
well, I was trying to use |
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Co-authored-by: Yih-Dar <2521628+ydshieh@users.noreply.github.com>
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 for working on this!
Just one comment
Still good to me, but we don't need the last commit I will leave @amyeroberts to make the final decision however. |
I think the same but it was explicitly requested. So, as you like. |
Sure :-) (but you can still express you thought instead of just following the request 😃 ) |
This reverts commit 66fd2cd.
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 for enabling this @bhack!
* Extend import utils to cover "editable" torch versions * Re-add type hint * Remove whitespaces * Double quote strings * Update comment Co-authored-by: Yih-Dar <2521628+ydshieh@users.noreply.github.com> * Restore package_exists * Revert "Restore package_exists" This reverts commit 66fd2cd. --------- Co-authored-by: Yih-Dar <2521628+ydshieh@users.noreply.github.com>
What does this PR do?
Fixes #28999
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
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.