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

Avoid large device allocation in UMAP with nndescent #6292

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

jcrist
Copy link
Member

@jcrist jcrist commented Feb 4, 2025

Currently NNDescent returns two arrays:

  • graph.graph(): (n x graph_degree) on host
  • graph.distances(): (n x graph_degree) on device

Downstream, the rest of UMAP wants both of these to be device arrays of shape (n x n_neighbors).

Currently we copy graph.graph() to a temporary device array, then slice and and copy it to the output array out.knn_indices.

Ideally we'd force graph_degree = n_neighbors to avoid the slicing entirely (and reduce the size of the intermediate results). However, it seems like currently there's a bug in NNDescent where reducing graph_degree to n_neighbors causes a significant decrease in result quality. So for now we need to keep the slicing around.

We can avoid allocating the temporary device array though, instead doing the slicing on host. Doing this avoids allocating a (n x graph_degree) device array entirely; for large n this can be a significant savings (47 GiB on one test problem I was trying).

We still should fix the graph_degree issue, but for now this should help unblock running UMAP on very large datasets.

Currently `NNDescent` returns two arrays:

- `graph.graph()`: (n x graph_degree) on host
- `graph.distances()`: (n x graph_degree) on device

Downstream, the rest of UMAP wants both of these to be device arrays of
shape (n x n_neighbors).

Currently we copy `graph.graph()` to a temporary device array, then
slice and and copy it to the output array `out.knn_indices`.

Ideally we'd force `graph_degree = n_neighbors` to avoid the slicing
entirely (and reduce the size of the intermediate results). However,
it seems like currently there's a bug in `NNDescent` where reducing
`graph_degree` to `n_neighbors` causes a significant decrease in result
quality. So for now we need to keep the slicing around.

We can avoid allocating the temporary device array though, instead doing
the slicing on host. Doing this avoids allocating a (n x graph_degree)
device array entirely; for large `n` this can be a significant savings
(47 GiB on one test problem I was trying).

We still should fix the `graph_degree` issue, but for now this should
help unblock running UMAP on very large datasets.
@jcrist jcrist requested a review from a team as a code owner February 4, 2025 20:42
@jcrist jcrist requested review from bdice and wphicks February 4, 2025 20:42
@jcrist jcrist added non-breaking Non-breaking change improvement Improvement / enhancement to an existing function labels Feb 4, 2025
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.06%. Comparing base (f81ff87) to head (97dc85f).
Report is 1 commits behind head on branch-25.02.

Additional details and impacted files
@@               Coverage Diff                @@
##           branch-25.02    #6292      +/-   ##
================================================
- Coverage         68.18%   67.06%   -1.13%     
================================================
  Files               201      202       +1     
  Lines             13055    13065      +10     
================================================
- Hits               8902     8762     -140     
- Misses             4153     4303     +150     

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

@divyegala
Copy link
Member

/merge

@rapids-bot rapids-bot bot merged commit 1bb7f47 into branch-25.02 Feb 5, 2025
73 checks passed
@jcrist jcrist deleted the umap-avoid-large-allocation branch February 5, 2025 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CUDA/C++ improvement Improvement / enhancement to an existing function non-breaking Non-breaking change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants