Repository navigation
Add MLXVSModel: approximate nearest neighbours on Apple silicon GPUs with mlxvs - #763
Open
mikepapadim wants to merge 1 commit into
Open
mikepapadim wants to merge 1 commit into
mikepapadim wants to merge 1 commit into
Conversation
…licon Macs with mlxvs
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #762
Adds
implicit.ann.mlxvs.MLXVSModeland anMLXVSAlternatingLeastSquaresfactory. With them,recommendandsimilar_itemsrun on the GPU of Apple silicon Macs through mlxvs, a CAGRA graph index on Apple's MLX. The wrapper followsFaissModel:recommend: an inner product index over the item factors. It adds the norm-equalising extra dimension fromaugment_inner_product_matrix, as the annoy and nmslib models do.similar_items: an index over the normalized item factors.intermediate_graph_degree) and on result counts above 1024. Exact search runs on the GPU up to 256 results and in NumPy beyond that.save/load/similar_usersraiseNotImplementedError, likeFaissModel.Tests and CI
tests/approximate_als_test.py: anMLXVSALSTestinsidetry: import mlxvs. It runs the sharedRecommenderBaseTestMixin, plustest_large_recommend(falling back past 1024 results) andtest_graph_index(graph results match the exact model).build.yml: installsmlxvson the macOS test runners, which are Apple silicon, for Python 3.10 and later. That way the tests run for real in CI. Linux and Windows are unaffected.main: the 5AnnoyALSTestfailures there happen without this change too.Benchmark
lastfm-360k (292,385 items), ALS with 64 factors, N=10. Recall@10 is measured against the exact results, on an M3 Pro.
Building the index takes about 5 s for the two indices, against 0.5 s for faiss IVF.
Usage
Install:
pip install mlxvs(macOS 14+, Apple silicon).Disclosure: I maintain mlxvs.