Skip to content

Implement Ridge .solver_ estimated attribute#6415

Merged
rapids-bot[bot] merged 4 commits intorapidsai:branch-25.04from
csadorf:fix/rename-ridge-solver-attribute
Mar 31, 2025
Merged

Implement Ridge .solver_ estimated attribute#6415
rapids-bot[bot] merged 4 commits intorapidsai:branch-25.04from
csadorf:fix/rename-ridge-solver-attribute

Conversation

@csadorf
Copy link
Copy Markdown
Contributor

@csadorf csadorf commented Mar 10, 2025

Adds the .solver_ estimated attribute in addition to the .solver hyperparameter.

Switches the default cuml solver hyperparameter from "eig" to "auto" (backwards-compatible).

@copy-pr-bot
Copy link
Copy Markdown

copy-pr-bot Bot commented Mar 10, 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 Mar 10, 2025
@csadorf csadorf added bug Something isn't working non-breaking Non-breaking change labels Mar 10, 2025
@csadorf
Copy link
Copy Markdown
Contributor Author

csadorf commented Mar 10, 2025

/ok to test

@csadorf csadorf self-assigned this Mar 11, 2025
@csadorf csadorf force-pushed the fix/rename-ridge-solver-attribute branch from 1074686 to 0b70832 Compare March 11, 2025 16:50
@csadorf
Copy link
Copy Markdown
Contributor Author

csadorf commented Mar 11, 2025

/ok to test

@csadorf csadorf force-pushed the fix/rename-ridge-solver-attribute branch from 0b70832 to 3e91f72 Compare March 12, 2025 19:40
@csadorf csadorf changed the title Rename Ridge solver attribute to solver_. Implement Ridge .solver_ estimated attribute Mar 12, 2025
@csadorf
Copy link
Copy Markdown
Contributor Author

csadorf commented Mar 12, 2025

/ok to test

@csadorf csadorf marked this pull request as ready for review March 12, 2025 21:34
@csadorf csadorf requested a review from a team as a code owner March 12, 2025 21:34
@csadorf csadorf requested review from betatim and dantegd March 12, 2025 21:34
@csadorf
Copy link
Copy Markdown
Contributor Author

csadorf commented Mar 13, 2025

@dantegd @betatim There are some potentially unrelated test failures, but this is ready for initial review.

Copy link
Copy Markdown
Member

@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.

2 general comments:

  • Presumably this is fixing a bug/increasing compatibility within cuml.accel. Can you add a test for this behavior?
  • From the comments in this PR alone I cannot tell what issue this PR resolves or why it's being made. In the future can you try and include comments about why a PR is being made, why the approach you took solves the issue, etc...? This helps immensely with reviewing PRs and disseminating knowledge about why things are the way they are across the team. It also helps when future us run git blame to find out why this code was written :)

@csadorf
Copy link
Copy Markdown
Contributor Author

csadorf commented Mar 13, 2025

I just implemented a few additional basic tests and it turns out that the cd solver is apparently not actually implemented. This was also noted in #6066 . I think we should remove that option for 25.04.

The cd solver maps to algo=2

which then triggers this error:

cuml/cpp/src/glm/ridge.cuh

Lines 214 to 215 in 3a8ea8c

} else if (algo == 2) {
ASSERT(false, "ridgeFit: no algorithm with this id has been implemented");

@dantegd Do you have more context for this?

@csadorf csadorf force-pushed the fix/rename-ridge-solver-attribute branch from 3e91f72 to c88113e Compare March 14, 2025 15:42
"""Test that the solver attribute is translated correctly."""
model = Ridge(solver=solver, random_state=42)
assert (
model.solver == expected
Copy link
Copy Markdown
Member

@betatim betatim Mar 17, 2025

Choose a reason for hiding this comment

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

The fact that the attribute isn't equal to the value the user passed in is a curiosity of the current proxying implementation. How can we note that in the test so that when we change the implementation we know to modify this test/delete it? Leave a comment for people from the future?

Copy link
Copy Markdown
Contributor Author

@csadorf csadorf Mar 17, 2025

Choose a reason for hiding this comment

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

It is and it isn't. The skl implementation will also have a deviation in case that the default "auto" value is selected.

I further do not think that this is an artifact of our proxy implementation, but an artifact of the fundamental function of the acceleration mode. We can decide that the acceleration mode must faithfully obey all parameters 100%, including the solver selection in which case we would have to fall-back to CPU mode in case that a solver is selected that is not supported on the GPU. However, if we deem that selecting an equivalent suitable solver is acceptable then I don't think we should pretend that a specific skl-solver was used, when – in fact – it wasn't.

To be clear, I am not arguing that this is the right approach, but I am arguing that the deviation is not just an artifact of the current proxy layer implementation. I don't think that we need any further comment to remind us here, because this test will fail if we make an engineering decision to change the behavior.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The solver attribute will be set to "auto" in scikit-learn. The solver_ attribute will contain the name of the solver that was actually used.

In [20]: from sklearn.linear_model import Ridge

In [21]: r = Ridge()

In [22]: from sklearn.datasets import make_classification, make_regression

In [23]: X, y = make_regression()

In [24]: r.fit(X, y)
Out[24]: Ridge()

In [25]: r.solver
Out[25]: 'auto'

In [26]: r.solver_
Out[26]: 'cholesky'

I don't think we need to select the same solver, but I do think we should work towards passing the scikit-learn common tests which require that all constructor arguments are stored in attributes and that those remain unchanged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't understand your point, that is the exact behavior I was describing:

The skl implementation will also have a deviation in case that the default "auto" value is selected.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I somehow missed the first line/mixed it with the second of the test parametrisation :-/ so I thought that you pass "auto" but then the attribute is set to "eig".

Comment thread python/cuml/cuml/linear_model/ridge.pyx
@csadorf csadorf force-pushed the fix/rename-ridge-solver-attribute branch from 8596029 to 66529e3 Compare March 17, 2025 17:41
csadorf added 3 commits March 19, 2025 12:33
- Changed default solver from 'eig' to 'auto', allowing automatic selection of 'eig'.
- Updated documentation to reflect new solver options: 'auto', 'eig', 'svd', and 'cd'.
- Refactored solver selection logic into a new method `_select_solver` for better clarity and maintainability.
@csadorf csadorf force-pushed the fix/rename-ridge-solver-attribute branch from f18df58 to 2d10d1b Compare March 19, 2025 17:33
@csadorf
Copy link
Copy Markdown
Contributor Author

csadorf commented Mar 31, 2025

/merge

@rapids-bot rapids-bot Bot merged commit 077d951 into rapidsai:branch-25.04 Mar 31, 2025
75 of 76 checks passed
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.

3 participants