-
Notifications
You must be signed in to change notification settings - Fork 197
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
[WIP] Remove python version specific usage within extensions #1270
Changes from all commits
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 | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,10 +22,14 @@ | |||||||||||||||||||
) | ||||||||||||||||||||
if not _IS_FBCODE: | ||||||||||||||||||||
try: | ||||||||||||||||||||
from . import _C | ||||||||||||||||||||
from importlib.util import find_spec | ||||||||||||||||||||
from pathlib import Path | ||||||||||||||||||||
spec = find_spec("torchao") | ||||||||||||||||||||
assert spec is not None, "torchao python module spec is unexpectedly None" | ||||||||||||||||||||
SO_PATH = Path(spec.origin).parent / "_C.abi3.so" | ||||||||||||||||||||
Comment on lines
+25
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Easiest solution are usually the best one :)
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't work in the pip wheel -e . followed by the pip install *.whl case! In that case the _C.abi3.so will live in site-packages (or wherever the user's install is) so we need a more encompassing way to access the location here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you share an example? And perhaps it talks about some gaps in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh this should indeed work in the pip wheel/pip install case, because the init.py file and the _C.abi3.so are in the same folder under site-packages: It's funny because I actually started off with what you had lol so dang I did some extra work :'/ Do you know where the logic lives to always place the _C under the same folder as init.py? I don't see mention of it in the ao setup.py, so is this a Python guarantee for custom extensions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@janeyx99 I think it's a setuptools thing Lines 114 to 116 in 01dc7da
So it automatically understands that it should put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah thanks for the info @gau-nernst! |
||||||||||||||||||||
torch.ops.load_library(SO_PATH) | ||||||||||||||||||||
from . import ops | ||||||||||||||||||||
except: | ||||||||||||||||||||
_C = None | ||||||||||||||||||||
logging.info("Skipping import of cpp extensions") | ||||||||||||||||||||
|
||||||||||||||||||||
from torchao.quantization import ( | ||||||||||||||||||||
|
This file was deleted.
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.
It's nice to have it, but imo not necessary. At least by default, linker will ignore the dependencies, unless one uses some symbols from that library (unless library is linked with
-Wno-as-needed
)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.
This is necessary only to get python to recognize the extension + therefore the wheel as python agnostic. e.g., for pypi packaging and naming purposes.
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.
This is also for our cppextension to know not to drag in libtorch_python