Skip to content

Fix KNN neighbor buffer layout bugs - #8619

Merged
rapids-bot[bot] merged 4 commits into
NVIDIA:release/26.10from
csadorf:bug-issue-8362-neighbors-fixes-26.10
Sep 11, 2026
Merged

Fix KNN neighbor buffer layout bugs#8619
rapids-bot[bot] merged 4 commits into
NVIDIA:release/26.10from
csadorf:bug-issue-8362-neighbors-fixes-26.10

Conversation

@csadorf

@csadorf csadorf commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Converts callable weights to C-contiguous float32 CuPy arrays before the KNN kernel reads them.
  • Converts sparse self-edge indices to contiguous int64 before the raw kernel while keeping explicit sparse query results as int32.
  • Adds regressions for non-C-contiguous callable weights and duplicate sparse rows.

Testing

  • 14 passed for the KNN weights test selection.
  • Changed-file pre-commit checks pass.
  • Full CI passes.

Supersedes #8393.
Fixes #8362

Signed-off-by: nethum529 <nethumweerasinghe.nw@gmail.com>
Signed-off-by: nethum529 <nethumweerasinghe.nw@gmail.com>
Signed-off-by: nethum529 <nethumweerasinghe.nw@gmail.com>
Signed-off-by: nethum529 <nethumweerasinghe.nw@gmail.com>
@csadorf
csadorf requested a review from a team as a code owner September 11, 2026 10:40
@csadorf csadorf added bug Something isn't working Cython / Python Cython or Python issue non-breaking Non-breaking change labels Sep 11, 2026
@csadorf
csadorf requested a review from viclafargue September 11, 2026 10:40
@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 29cf9926-1d76-4b2e-b878-497f7f97a327

📥 Commits

Reviewing files that changed from the base of the PR and between dce84ae and 9dff77a.

📒 Files selected for processing (4)
  • python/cuml/cuml/neighbors/nearest_neighbors.pyx
  • python/cuml/cuml/neighbors/weights.py
  • python/cuml/tests/test_kneighbors_regressor.py
  • python/cuml/tests/test_nearest_neighbors.py

Included review availability: Your plan provides up to 12 included reviews per hour; 11 remain after this review.


📝 Summary

Summary by CodeRabbit

  • Bug Fixes

    • Improved nearest-neighbor self-query behavior for sparse inputs, including consistent output formatting and exclusion of self-matches.
    • Fixed callable KNN weighting with non-contiguous GPU distance arrays, providing consistent predictions with standard implementations.
  • Tests

    • Added regression coverage for sparse self-queries and custom callable weighting across varied GPU array layouts.

Walkthrough

The change normalizes sparse nearest-neighbor indices and callable KNN weights before kernel processing. New regression tests cover self-query behavior and non-contiguous callable weight outputs.

Changes

Neighbor handling fixes

Layer / File(s) Summary
Self-query index normalization
python/cuml/cuml/neighbors/nearest_neighbors.pyx, python/cuml/tests/test_nearest_neighbors.py
_drop_self_edges converts indices to contiguous int64 CuPy arrays. Sparse self-query tests validate output types, contiguity, self-index exclusion, and scikit-learn agreement.
Callable weight normalization
python/cuml/cuml/neighbors/weights.py, python/cuml/tests/test_kneighbors_regressor.py
Callable weight outputs convert to contiguous C-order float32 CuPy arrays. Regression tests cover non-contiguous outputs and compare predictions with scikit-learn.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 9dff7

The KNN layout fixes and regressions address the intended prediction and sparse self-query paths; no actionable merge risk remains.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The KNN code and regression tests are within #8362 scope. The SPDX copyright-header change in python/cuml/cuml/neighbors/weights.py is unrelated to callable weight contiguity, sparse index safety, o… Revert the unrelated SPDX copyright-header change, or move it to a separate pull request.
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing KNN neighbor buffer layout bugs.
Description check ✅ Passed The description directly explains the buffer layout fixes, regression tests, test results, and linked issues.
Linked Issues check ✅ Passed The PR satisfies #8362. compute_weights() converts callable results to C-order float32 CuPy arrays before kernel use. _drop_self_edges() converts indices to contiguous int64 buffers for the `l…
Full details: Out of Scope Changes check

Explanation

The KNN code and regression tests are within #8362 scope. The SPDX copyright-header change in python/cuml/cuml/neighbors/weights.py is unrelated to callable weight contiguity, sparse index safety, or regression coverage.

Full details: Docstring Coverage

Explanation

Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@csadorf

csadorf commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

/merge

@rapids-bot
rapids-bot Bot merged commit b496ec5 into NVIDIA:release/26.10 Sep 11, 2026
104 checks passed
@csadorf
csadorf deleted the bug-issue-8362-neighbors-fixes-26.10 branch September 11, 2026 13:06
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

None yet

Development

Successfully merging this pull request may close these issues.

4 participants