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

Make KernelRidge inherit from UniversalBase #6327

Merged
merged 4 commits into from
Feb 20, 2025

Conversation

betatim
Copy link
Member

@betatim betatim commented Feb 17, 2025

Support for zero code change acceleration. With the accelerator turned on, the scikit-learn example ./examples/miscellaneous/plot_kernel_ridge_regression.py fails because it returns a cupy array from

X_plot = np.linspace(0, 5, 100000)[:, None]

kr = GridSearchCV(
    KernelRidge(kernel="rbf", gamma=0.1),
    param_grid={"alpha": [1e0, 0.1, 1e-2, 1e-3], "gamma": np.logspace(-2, 2, 5)},
)

kr.fit(...)

kr.predict(X_plot)

This fixes this.

@betatim betatim requested a review from a team as a code owner February 17, 2025 12:44
@betatim betatim requested review from csadorf and divyegala February 17, 2025 12:44
@github-actions github-actions bot added the Cython / Python Cython or Python issue label Feb 17, 2025
@betatim betatim added improvement Improvement / enhancement to an existing function non-breaking Non-breaking change labels Feb 18, 2025
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 for the most part, but I would add a test in the test_device_selection.py file to ensure that training and inference can be done on both CPU or GPU and the conversion between the two is seamless.

@@ -247,6 +255,7 @@ class KernelRidge(Base, RegressorMixin):
filter_params=True, **params)

@generate_docstring()
@enable_device_interop
def fit(self, X, y, sample_weight=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, small detail, but it is always nice to use the self.n_features_in_ attribute instead of local variable n_rows when ingesting data. This gives one more thing to replicate sklearn's behavior.

Copy link
Member Author

Choose a reason for hiding this comment

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

You mean we should set self.n_features_in_ instead of using a local variable? Can do that. One question, n_features_in_ is the number of features, so shouldn't it be set to n_cols instead?

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right meant the number of columns.

@csadorf
Copy link
Contributor

csadorf commented Feb 20, 2025

/merge

@rapids-bot rapids-bot bot merged commit d7b4d68 into rapidsai:branch-25.04 Feb 20, 2025
68 checks passed
@betatim betatim deleted the kernelridge-0cc branch February 20, 2025 15:49
dantegd added a commit to dantegd/cuml that referenced this pull request Feb 20, 2025
rapids-bot bot pushed a commit that referenced this pull request Feb 23, 2025
Previously this wasn't handled correctly, but was _sometimes_ masked by `GridSearchCV` in the old test fixing things behind the scenes.

This fixes the bug, adds a test that doesn't require the accelerator, and changes the accelerator test to be both simpler (matching the smoketests in the rest of the file) and much faster (the `GridSearchCV` in the test made the test quite slow on my machine).

Fixup to the fix applied in #6327.

Authors:
  - Jim Crist-Harif (https://github.com/jcrist)

Approvers:
  - Dante Gama Dessavre (https://github.com/dantegd)

URL: #6354
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuml-cpu Cython / Python Cython or Python issue 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