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

Plumb metric and metric_kwds through to UMAP with nn_descent #6304

Open
wants to merge 3 commits into
base: branch-25.04
Choose a base branch
from

Conversation

jcrist
Copy link
Member

@jcrist jcrist commented Feb 7, 2025

Previously we were erroneously missing this plumbing, leaving the metric and metric_arg as the defaults when nn_descent is used. In the long run we should redo how the parameters are passed when nn_descent is enabled to avoid this duplication (there's a few other uselessly exposed params like return_distances), but for now fixing the plumbing to be more correct seems fine.

On top of #6303, leaving as draft for now until that's merged.

Also re-enables tests on ARM, fixes #5441.

Copy link

copy-pr-bot bot commented Feb 7, 2025

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@github-actions github-actions bot added the Cython / Python Cython or Python issue label Feb 7, 2025
@jcrist jcrist added bug Something isn't working non-breaking Non-breaking change Cython / Python Cython or Python issue and removed Cython / Python Cython or Python issue labels Feb 7, 2025
@cjnolet
Copy link
Member

cjnolet commented Feb 13, 2025

/ok to test

@jcrist jcrist mentioned this pull request Feb 28, 2025
9 tasks
@jcrist jcrist force-pushed the forward-metric-umap-nndescent branch from f74bc23 to e827f53 Compare March 5, 2025 23:10
jcrist added 2 commits March 5, 2025 23:10
Previously we were erroneously missing this plumbing, leaving the
`metric` and `metric_arg` as the defaults when `nn_descent` is used. In
the long run we should redo how the parameters are passed when
`nn_descent` is enabled to avoid this duplication, but for now fixing
the plumbing to be more correct seems fine.
At least on my aarch64 linux box these aren't failing anymore.
@jcrist jcrist force-pushed the forward-metric-umap-nndescent branch from e827f53 to afcff55 Compare March 5, 2025 23:10
@jcrist jcrist marked this pull request as ready for review March 5, 2025 23:10
@jcrist jcrist requested a review from a team as a code owner March 5, 2025 23:10
@jcrist jcrist requested review from bdice and viclafargue March 5, 2025 23:10
Copy link
Member Author

@jcrist jcrist left a comment

Choose a reason for hiding this comment

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

Rebased on main and marked ready for review.

umap_params.nn_descent_params.n_clusters = <uint64_t> build_kwds.get("nnd_n_clusters", 1)
# Forward metric & metric_kwds to nn_descent
umap_params.nn_descent_params.metric = <RaftDistanceType> umap_params.metric
umap_params.nn_descent_params.metric_arg = umap_params.p
Copy link
Member Author

Choose a reason for hiding this comment

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

The actual fix is here (plumbing through the metric options to nn_descent_params). In the long run we should redesign the C++ layer to remove duplicate options - for now just ensuring they're forwarded correctly seems sufficient.

Everything else here is a simplification of the current pre-existing code.

Copy link
Contributor

@viclafargue viclafargue left a comment

Choose a reason for hiding this comment

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

LGTM, but we would have to make sure that NN Descent is actually compatible with all the metrics we make available. cc @jinsolp

@jcrist
Copy link
Member Author

jcrist commented Mar 6, 2025

A quick browse through the code I believe all metrics are handled fine by nn_descent. Just to be sure I've also updated an existing metrics test to be parametrized on build_algo as well; this test runs fine locally as well.

The behavior before was incorrect (build_algo="nn_descent" would silently ignore the user selected metric), so I consider this PR strictly an improvement even in the off chance some parameter combo will error after this change. I'm fairly confident this won't happen though.

Planning to merge once CI is green.

@jinsolp
Copy link
Contributor

jinsolp commented Mar 6, 2025

Right now NN Descent in cuvs supports L2Expanded, CosineExpanded and InnerProduct, (link)
but in Raft Nn Descent supports only L2Expanded (link)

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.34%. Comparing base (fbcaf12) to head (d275218).

Additional details and impacted files
@@               Coverage Diff                @@
##           branch-25.04    #6304      +/-   ##
================================================
- Coverage         68.50%   67.34%   -1.16%     
================================================
  Files               204      204              
  Lines             13194    13194              
================================================
- Hits               9039     8886     -153     
- Misses             4155     4308     +153     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jcrist
Copy link
Member Author

jcrist commented Mar 6, 2025

/merge (just realized victor's review wasn't an actual approval)

@jcrist
Copy link
Member Author

jcrist commented Mar 6, 2025

but in Raft Nn Descent supports only L2Expanded

Ah! Thanks @jinsolp! I'm curious - right now after plumbing the metric through nn_descent properly here I'm not seeing an error (and the added test passes), but you're right that it doesn't look like the metrics are supported after all. I don't see any validation in the raft code flow that would error on an invalid metric - perhaps the right additional fix here then is:

  • Add validation on the python side for nn_descent to error on unsupported metrics
  • Keep plumbing the args through properly, even though they appear to be mostly ignored on the raft side for now
  • Keep the test, but update it to check for errors on unsupported metrics

Then whenever we get around to moving to cuvs instead we can increase the supported metrics pretty straightforwardly.

@jinsolp
Copy link
Contributor

jinsolp commented Mar 7, 2025

Yes I think that would be great! : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Cython / Python Cython or Python issue non-breaking Non-breaking change
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

[BUG] segfault in UMAP pytests in ARM GHA jobs
5 participants