Skip to content
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

Dependency and Build Fixes #171

Merged
merged 14 commits into from
Jan 7, 2022
Merged

Dependency and Build Fixes #171

merged 14 commits into from
Jan 7, 2022

Conversation

mmuckley
Copy link
Contributor

@mmuckley mmuckley commented Jan 5, 2022

This is a potpourri of fixes.

Dependencies
Currently, we require very specific package versions for any install. This is too restrictive for a research package where researchers may have a variety of reasons to carefully tailor their environment. This PR resolves the issue by allowing general installation to have flexible packages. To maintain CI stability and functionality, the fixed version requirements have been moved to dev.

Build
We build our CPP extension using load instead of setup.py. This removes PyTorch as a dependency at install time and removes the need for us to distribute binaries. This required adding ninja as a dependency. Hopefully we can get rid of it eventually, but this temporarily should fix distribution.

CI testing
isort was misconfigured and missed a lot of import changes. I fixed the config and ran it on all files to update import sorting.

Other
While implementing this I also found a few other minor issues with respect to versioning, tests, and formatting that I resolved.

This PR makes NeuralCompression require Python 3.8 due to its usage of importlib.

Testing
Testing done via CI.

@facebook-github-bot facebook-github-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 Jan 5, 2022
@mmuckley mmuckley changed the title Fix package dependencies Dependency and Build Fixes Jan 5, 2022
@mmuckley mmuckley marked this pull request as ready for review January 5, 2022 23:07
@mmuckley mmuckley requested a review from 0x00b1 January 5, 2022 23:08

from torch.utils.cpp_extension import load

print(str(Path(__file__).resolve().parent / "pmf_to_quantized_cdf_py.cc"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: factorize of Path(__file__).resolve().parent into extension_folder and reuse below. If you plan to load more extensions like this, you might create a function load_extension :

def load_extension(extension_name: str, file_names: List[str]):
   extension_folder = Path(__file__).resolve().parent
   return load(
     name=extension_name,
     sources=[str(Path(__file__).resolve().parent / file_name) for file_name in file_names],
     verbose=True,
   )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay let me try it :).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@QuentinDuval I updated this to try to follow your suggested format. Does it fit what you were thinking?

Copy link
Contributor

Choose a reason for hiding this comment

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

Lovely.

Copy link
Contributor

Choose a reason for hiding this comment

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

@QuentinDuval I am more than happy about @mmuckley's change but I am also open to other ideas for managing extensions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the main question I would be curious to have an answer for is "on what platform does the CppExtension work" and what to do to make it work on all of them. I know that torchvision does have a lot of extensions, but for instance, I never tried to install it on windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My current solution follows this thread. Based on this I think it will fail on Windows. The nice thing is with this new implementation we localize it to only this function.

The better thing later would be to figure out a multi-platform distribution framework and move this back to setup.py or to remove the C++ code.

Copy link
Contributor

Choose a reason for hiding this comment

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

@mmuckley Frankly, in retrospect, it was overkill on my behalf. But, in my defense, I didn't have a strong grasp of what did and did not work with @torch.jit.script at the time (e.g., a Python implementation should be easily compilable).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@0x00b1 I'm open to any implementation in any format! My only requirement is that if we have C++ code we pay the cost of distributing it.

@mmuckley
Copy link
Contributor Author

mmuckley commented Jan 7, 2022

@QuentinDuval @0x00b1 any actionable requests on this PR? Otherwise I need one of you to approve so we can merge. It's not a perfect fix but I think it allows distribution.

@QuentinDuval
Copy link
Contributor

@QuentinDuval @0x00b1 any actionable requests on this PR? Otherwise I need one of you to approve so we can merge. It's not a perfect fix but I think it allows distribution.

LGTM, I approved it :)

@0x00b1
Copy link
Contributor

0x00b1 commented Jan 7, 2022

@mmuckley LGTM. I apologize for the delay. I wanted to read up on torch.utils.cpp_extension.load before approving.

@mmuckley
Copy link
Contributor Author

mmuckley commented Jan 7, 2022

No worries @0x00b1!

@mmuckley mmuckley merged commit 375cd13 into main Jan 7, 2022
@mmuckley mmuckley deleted the mmuckley/separate_package_reqs branch January 7, 2022 23:55
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants