Skip to content

Validate precomputed pairwise kernel shapes - #8441

Open
fallintoplace wants to merge 5 commits into
NVIDIA:mainfrom
fallintoplace:fix/precomputed-kernel-shape
Open

Validate precomputed pairwise kernel shapes#8441
fallintoplace wants to merge 5 commits into
NVIDIA:mainfrom
fallintoplace:fix/precomputed-kernel-shape

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

Summary

  • Validate that precomputed self-kernels are square.
  • Validate that precomputed cross-kernels have matching indexed-sample counts.
  • Add regression coverage for valid and invalid precomputed shapes.

The previous validation compared feature widths before recognizing metric="precomputed", allowing malformed kernel matrices through or rejecting valid cross-kernel shapes with misleading errors.

Testing

  • pre-commit run --files python/cuml/cuml/metrics/pairwise_kernels.py python/cuml/tests/test_kernel_ridge.py
  • python3 -m py_compile python/cuml/cuml/metrics/pairwise_kernels.py python/cuml/tests/test_kernel_ridge.py

@fallintoplace
fallintoplace requested a review from a team as a code owner August 3, 2026 23:00
@fallintoplace
fallintoplace requested a review from csadorf August 3, 2026 23:00
@copy-pr-bot

copy-pr-bot Bot commented Aug 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the Cython / Python Cython or Python issue label Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: b1b6cc15-e022-473f-b80e-cfbde49fce15

📥 Commits

Reviewing files that changed from the base of the PR and between fc9b3ac and a1c4d90.

📒 Files selected for processing (1)
  • python/cuml/tests/test_kernel_ridge.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • python/cuml/tests/test_kernel_ridge.py

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation for precomputed pairwise kernels with clear error messages.
    • Dimensional mismatches between kernel matrices now raise descriptive errors.
    • Valid cross-kernel inputs are accepted and returned unchanged.
  • Documentation

    • Added shape requirements documentation for precomputed kernels.
  • Tests

    • Added coverage for valid and invalid precomputed kernel scenarios.

Walkthrough

pairwise_kernels now validates precomputed kernel dimensions against Y. Non-precomputed metrics retain feature-dimension validation. Kernel ridge tests cover valid and invalid shapes.

Changes

Precomputed kernel validation

Layer / File(s) Summary
Precomputed shape validation
python/cuml/cuml/metrics/pairwise_kernels.py
Documentation defines precomputed input shapes. Precomputed kernels validate indexed dimensions before returning X. Non-precomputed metrics retain feature-dimension validation.
Shape validation regression tests
python/cuml/tests/test_kernel_ridge.py
Tests cover non-square inputs, valid cross-kernels, incompatible indexed dimensions, and mismatched linear-kernel feature dimensions.

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

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: validating precomputed pairwise kernel shapes.
Description check ✅ Passed The description accurately explains the shape validation changes, validation order correction, regression tests, and testing performed.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@python/cuml/cuml/metrics/pairwise_kernels.py`:
- Around line 286-297: Update the pairwise_kernels docstring’s
metric="precomputed" section to document that omitted Y requires square X, while
supplied Y permits X shaped (n_queries, n_indexed) with X.shape[1] equal to
Y.shape[0]. State that validation uses only Y.shape[0], and remove the claim
that Y is ignored.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: a671fdde-4a64-44e3-8a30-283d4c5d88b8

📥 Commits

Reviewing files that changed from the base of the PR and between ee20b3d and edccc6b.

📒 Files selected for processing (2)
  • python/cuml/cuml/metrics/pairwise_kernels.py
  • python/cuml/tests/test_kernel_ridge.py

Comment thread python/cuml/cuml/metrics/pairwise_kernels.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@python/cuml/cuml/metrics/pairwise_kernels.py`:
- Around line 209-220: Update the Y parameter documentation in the
pairwise-kernel API to state that the feature-array restriction applies only to
non-precomputed metrics; for metric="precomputed", document that Y is used only
for its first dimension to validate rectangular X inputs, without constraining
its values or second dimension.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: c49d188f-692d-4e4b-91e3-0007f2a67d0b

📥 Commits

Reviewing files that changed from the base of the PR and between edccc6b and 11b250e.

📒 Files selected for processing (1)
  • python/cuml/cuml/metrics/pairwise_kernels.py

Comment thread python/cuml/cuml/metrics/pairwise_kernels.py Outdated

@viclafargue viclafargue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks! Just one non-blocking request. Otherwise looks good to me.

Comment on lines +304 to +305
if X.shape[1] != Y.shape[1]:
raise ValueError("X and Y have different dimensions.")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we add a regression test confirming that non-precomputed kernels still reject X and Y with different feature dimensions? This check was moved by the PR and isn’t currently covered.

@csadorf

csadorf commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

@viclafargue Can you add appropriate labels, please?

@csadorf
csadorf removed their request for review August 4, 2026 13:56

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@python/cuml/tests/test_kernel_ridge.py`:
- Line 139: Update the pytest.raises match pattern in the kernel ridge test to
escape the final period, using a raw regular-expression string so the assertion
matches the literal error message.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 9b31ff4c-8857-485b-95c1-f086292a7bf1

📥 Commits

Reviewing files that changed from the base of the PR and between 52104bb and fc9b3ac.

📒 Files selected for processing (1)
  • python/cuml/tests/test_kernel_ridge.py

Comment thread python/cuml/tests/test_kernel_ridge.py Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Cython / Python Cython or Python issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants