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

Add copy_X parameter to LinearRegression #5495

Merged
merged 14 commits into from
Jul 31, 2023

Conversation

viclafargue
Copy link
Contributor

Answers #5482

@viclafargue viclafargue requested a review from a team as a code owner July 10, 2023 09:41
@github-actions github-actions bot added the Cython / Python Cython or Python issue label Jul 10, 2023
@csadorf csadorf added improvement Improvement / enhancement to an existing function breaking Breaking change labels Jul 10, 2023
@csadorf csadorf linked an issue Jul 10, 2023 that may be closed by this pull request
@csadorf csadorf added non-breaking Non-breaking change and removed breaking Breaking change labels Jul 10, 2023
Copy link
Contributor

@csadorf csadorf left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the quick fix! Can we add or extend a unit test that tests this behavior?

python/cuml/linear_model/linear_regression.pyx Outdated Show resolved Hide resolved
python/cuml/linear_model/linear_regression.pyx Outdated Show resolved Hide resolved
Copy link
Member

@dantegd dantegd left a comment

Choose a reason for hiding this comment

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

Couple small comments

python/cuml/tests/test_linear_model.py Outdated Show resolved Hide resolved
python/cuml/linear_model/linear_regression.pyx Outdated Show resolved Hide resolved
@csadorf
Copy link
Contributor

csadorf commented Jul 11, 2023

@dantegd This should be ready for another review from your side.

@csadorf csadorf requested a review from dantegd July 11, 2023 22:25
Copy link
Contributor

@csadorf csadorf left a comment

Choose a reason for hiding this comment

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

I have addressed my own change requests and some other concerns.

Copy link
Member

@dantegd dantegd left a comment

Choose a reason for hiding this comment

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

One super small change

python/cuml/tests/test_linear_model.py Show resolved Hide resolved
python/cuml/tests/test_linear_model.py Show resolved Hide resolved
@@ -303,8 +309,14 @@ class LinearRegression(LinearPredictMixin,

"""
cdef uintptr_t X_ptr, y_ptr, sample_weight_ptr

need_explicit_copy = self.copy_X and hasattr(X, "__cuda_array_interface__") and X.shape[1] == 1
Copy link
Member

Choose a reason for hiding this comment

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

The more I think about it the more I think we should do the default of copy_X to a value like auto, with True always making a copy and False never making a copy. The reasoning behind this deviation from sklearn, is that we want to preserve GPU memory as much as possible by default, otherwise at least we need to chenge the docstring description to reflect that we do a copy only in this case at least.

Copy link
Contributor

Choose a reason for hiding this comment

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

How do you want to deal with the numerous cases where we have to make a copy and the argument is False? Raise an exception? I think the here implemented approach, where copy_X means that we guarantee to make a copy whereas False means we might make a copy is sensible and not a foreign concept to users. I am not rejecting your proposal, I just want to make sure we think it through.

The risk I see with the implemented approach is that the default value is True which is "safer", but poses a performance regression for some cases. Changing it to False avoids that, but bears the risk of users experiencing problems as described in the addressed issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

From offline discussion: We will stick to the implementation, but add an explicit note to the docs and log entry about the minor change in behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Addressed in 7a7ffc2 .

@csadorf csadorf added breaking Breaking change and removed non-breaking Non-breaking change labels Jul 13, 2023
Copy link
Contributor Author

@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, just one question

@@ -303,8 +326,15 @@ class LinearRegression(LinearPredictMixin,

"""
cdef uintptr_t X_ptr, y_ptr, sample_weight_ptr

need_explicit_copy = self.copy_X and hasattr(X, "__cuda_array_interface__") \
and (len(X.shape) < 2 or X.shape[1] == 1)
Copy link
Contributor Author

@viclafargue viclafargue Jul 27, 2023

Choose a reason for hiding this comment

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

Does the issue only appear when the input is a vector?

Copy link
Contributor

Choose a reason for hiding this comment

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

Only when this condition is False do we not already create a copy. So checking this ensures that we only create an explicit copy when copy_X is True and none of the other conditions are met which would have triggered a copy anyways.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I responded to a previous version of your question. Yes, an implicit copy is always created when the input is not a vector.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it not make more sense to have this logic be part of the input_to_cuml_array utility function?

Copy link
Contributor

Choose a reason for hiding this comment

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

In principle yes, but that would potentially change the behavior of many more classes and would require more thorough investigation and testing.

@csadorf csadorf requested a review from dantegd July 27, 2023 23:08
@csadorf csadorf self-requested a review July 31, 2023 15:50
@dantegd
Copy link
Member

dantegd commented Jul 31, 2023

/merge

@rapids-bot rapids-bot bot merged commit 2f85c6a into rapidsai:branch-23.08 Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Breaking change Cython / Python Cython or Python issue improvement Improvement / enhancement to an existing function
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fit modifies X inplace
3 participants