You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Approximate nearest neighbours on the GPU of Apple silicon Macs (mlxvs) #762
Approximate nearest neighbours on the GPU of Apple silicon Macs (mlxvs)
On Macs, recommend and similar_items run on the CPU with every ANN wrapper (annoy, nmslib, faiss-cpu), since implicit's GPU code is CUDA-only. mlxvs is an Apache-2.0 library for nearest neighbour search on the Mac's GPU, built on Apple's MLX. It provides a CAGRA graph index (the graph search in NVIDIA cuVS) and exact search, and publishes wheels for macOS 14+ arm64 on Python 3.10 to 3.14.
Proposal
An implicit.ann.mlxvs.MLXVSModel wrapper plus an MLXVSAlternatingLeastSquares factory, following FaissModel:
recommend uses an inner product index over the item factors, with the norm-equalising extra dimension the annoy and nmslib models add (graph search handles maximum inner product poorly otherwise).
similar_items uses an index over normalized factors.
Small item sets, and result counts beyond the graph search's list (1024), fall back to exact search.
The tests follow the existing pattern: a try: import mlxvs block running the shared RecommenderBaseTestMixin. The CI's macos-latest runners are Apple silicon, so a pip install mlxvs step there would run them for real.
Numbers
lastfm-360k (292,385 items, 358,868 users), ALS with 64 factors, recommend for 20,000 users at N=10 and similar_items for 2,000 items. Measured on a MacBook Pro M3 Pro; recall@10 is against the exact results.
recommend
recall@10
similar_items
recall@10
exact (CPU)
4,300 users/s
1.000
FaissModel (nlist 400, nprobe 20)
33,100 users/s
0.613
39,000 items/s
0.989
MLXVSModel (itopk 64)
244,300 users/s
0.973
140,900 items/s
0.986
MLXVSModel (itopk 128)
129,500 users/s
0.989
85,800 items/s
0.990
One caveat from testing: on synthetic factors made of a few hundred tight, well-separated clusters, graph search does much worse than IVF, because its k-NN graph has few edges between clusters. On the real ALS factors above, and on unclustered synthetic ones, it's the other way around.
I have it implemented with tests and will open a PR that closes this issue.
Activity