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

Remove NumPy as a hard dependency #204

Merged
merged 23 commits into from
Jul 5, 2024
Merged

Remove NumPy as a hard dependency #204

merged 23 commits into from
Jul 5, 2024

Conversation

dgasmith
Copy link
Owner

@dgasmith dgasmith commented Nov 3, 2022

Description

This PR removes NumPy from opt_einsum as a runtime dependency. The change has little effect on the opt_einsum code base but significantly effects the testing infrastructure. Several testing strategies are currently employed to help understand the most effective one. Currently, these are:

  • Move all NumPy functions to a testing.py module with pytest.skip
  • Various pytest.skip functions wrapped in decorators
  • Local NumPy imports.

Feedback welcome!

Todos

Notable points that this PR has either accomplished or will accomplish.

  • Remove unused custom tensordot code
  • Fix ssa_to_linear with a proper implementation
  • possibly_convert_to_numpy is used throughout, primarily to give objects a shape attribute if they do not have one. Setting attributes on root types is difficult and would require subclassing int/float/etc to provide a shape. I'm kicking around possible solutions here.
  • Fully differentiating GenericArrayType (without a shape attribute) compared to ArrayType (with a shape attribute) throughout the code base.
  • We need a torch-based only test case.

Questions

  • Question1

Status

  • Ready to go

@dgasmith dgasmith requested a review from jcmgray November 3, 2022 04:40
Copy link
Collaborator

@jcmgray jcmgray left a comment

Choose a reason for hiding this comment

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

LGTM so far! Do you understand the test failures, is that just an env thing?

@dgasmith
Copy link
Owner Author

I didn't get to every test yet. I'll hack a bit this weekend.

@dgasmith
Copy link
Owner Author

dgasmith commented Jan 4, 2023

@janeyx99 Is this still of interest to Torch? I think we're relatively close on removing that last of the NumPy dependancies.

@janeyx99
Copy link
Contributor

janeyx99 commented Jan 4, 2023

Yes! Removing the last dependencies would be awesome!

@dgasmith
Copy link
Owner Author

Apologies- I started a new job. This is in my mind and I hope to hack a little tomorrow night!

@dgasmith
Copy link
Owner Author

dgasmith commented May 5, 2024

@janeyx99 I'm looking to push another release shortly, is this still a requested feature?

@janeyx99
Copy link
Contributor

@dgasmith yes, torch still doesn't have a hard dependency on numpy (our tests do) so this is still desirable! Sorry it took a week to get back to you--this fell in my personal inbox.

@dgasmith
Copy link
Owner Author

I'll get in #232 first and then finalize this PR. It will be quite tidy to have no formal dependancies.

Copy link

codecov bot commented Jun 26, 2024

Codecov Report

Attention: Patch coverage is 92.68293% with 12 lines in your changes missing coverage. Please review.

Project coverage is 93.77%. Comparing base (1a984b7) to head (8211264).
Report is 5 commits behind head on master.

Additional details and impacted files

@dgasmith
Copy link
Owner Author

@jcmgray I think this is getting much closer. I updated the outstanding items in the OP.

@dgasmith dgasmith marked this pull request as ready for review June 29, 2024 20:13
@dgasmith
Copy link
Owner Author

dgasmith commented Jun 29, 2024

@jcmgray and @janeyx99 This is ready for review, but likely has a few bugs to still iron out. In particular @janeyx99 is there any tests you would recommend for PyTorch only envs?

Copy link
Collaborator

@jcmgray jcmgray left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@janeyx99
Copy link
Contributor

janeyx99 commented Jul 1, 2024

@jcmgray and @janeyx99 This is ready for review, but likely has a few bugs to still iron out. In particular @janeyx99 is there any tests you would recommend for PyTorch only envs?

Thanks for furthering this effort! The main reason this would be nice for PyTorch is so that we allow opt-einsum to be a more accessible dependency vs one the user has to specify when pip installing torch.

To that end, we have a few test commands written in bash to ensure that we don't accidentally depend on numpy:
https://github.com/pytorch/pytorch/blob/ca5d13c67287efe78a09dcf9b06f7e4fba898689/.ci/pytorch/test.sh#L742-L752

I don't think it's crucial for opt-einsum to have similar tests, because we will test these as a downstream library, but I'm mentioning in case you were looking for similar sanity checks.

@dgasmith
Copy link
Owner Author

dgasmith commented Jul 1, 2024

@janeyx99 I do have a torch-only env explicitly for testing non-numpy evaluations. I like adding the check to ensure that NumPy is not present.

@dgasmith dgasmith merged commit 94c62a0 into master Jul 5, 2024
9 checks passed
@dgasmith dgasmith deleted the numpy_removal branch July 5, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants