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

Enable torch #35

Merged
merged 35 commits into from
Jan 11, 2024
Merged

Enable torch #35

merged 35 commits into from
Jan 11, 2024

Conversation

dobraczka
Copy link
Owner

@dobraczka dobraczka commented Jan 4, 2024

Since Faiss has torch support with tensors that are on the GPU, it is desirable to avoid moving these to and from the GPU.
This PR adds the ability to have an entire pipeline for hubness reduced nearest neighbor search on the GPU.
For some hubness reduced methods it is not feasible to do this (probably only MP-empiric).

TODO:

  • Adapt TypeHints
  • Try DisSimLocal adaptation

@dobraczka
Copy link
Owner Author

Since it seems to be more or less impossible to provide type hints for a library (torch), that may or may not be available at runtime, I've given up and used T = TypeVar("T") to at least show that specific output tuples have the same types. I did not do this for inputs, since mypy will complain that T does not have this or that function or that a specific numpy function expects an ArrayLike etc. There may be a way to get around this with instance checks and asserts, but at the moment it is too much effort with little reward.

On the upside: All HubnessReduction classes now can use torch tensors. Some more cleverly than others. All NNAlgorithm classes except Faiss will complain if they do not get numpy arrays.

@dobraczka dobraczka merged commit 23f2667 into main Jan 11, 2024
4 checks passed
@dobraczka dobraczka deleted the enable-torch branch January 11, 2024 16:43
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.

1 participant