Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/cuml/cuml/cluster/agglomerative.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class AgglomerativeClustering(ClusterMixin, CMajorInputTagMixin, Base):

@generate_docstring()
@reflect(reset=True)
def fit(self, X, y=None, *, convert_dtype=True) -> "AgglomerativeClustering":
def fit(self, X, y=None, *, convert_dtype="deprecated") -> "AgglomerativeClustering":
"""
Fit the hierarchical clustering from features.
"""
Expand Down
4 changes: 2 additions & 2 deletions python/cuml/cuml/cluster/dbscan.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class DBSCAN(InteropMixin,
sample_weight=None,
*,
out_dtype="int32",
convert_dtype=True
convert_dtype="deprecated"
) -> "DBSCAN":
"""
Perform DBSCAN clustering from features.
Expand Down Expand Up @@ -487,7 +487,7 @@ class DBSCAN(InteropMixin,
sample_weight=None,
*,
out_dtype="int32",
convert_dtype=True,
convert_dtype="deprecated",
) -> CumlArray:
"""
Performs clustering on X and returns cluster labels.
Expand Down
11 changes: 8 additions & 3 deletions python/cuml/cuml/cluster/hdbscan/hdbscan.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ class HDBSCAN(InteropMixin, ClusterMixin, CMajorInputTagMixin, Base):

@generate_docstring()
@reflect(reset=True)
def fit(self, X, y=None, *, convert_dtype=True) -> "HDBSCAN":
def fit(self, X, y=None, *, convert_dtype="deprecated") -> "HDBSCAN":
"""
Fit HDBSCAN model from features.
"""
Expand Down Expand Up @@ -1184,7 +1184,12 @@ def all_points_membership_vectors(clusterer, int batch_size=4096):


@reflect(model="clusterer", array="points_to_predict")
def membership_vector(clusterer, points_to_predict, int batch_size=4096, convert_dtype=True):
def membership_vector(
clusterer,
points_to_predict,
int batch_size=4096,
convert_dtype="deprecated",
):
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
"""
Predict soft cluster membership. The result produces a vector
for each point in ``points_to_predict`` that gives a probability that
Expand Down Expand Up @@ -1264,7 +1269,7 @@ def membership_vector(clusterer, points_to_predict, int batch_size=4096, convert


@reflect(model="clusterer", array="points_to_predict")
def approximate_predict(clusterer, points_to_predict, convert_dtype=True):
def approximate_predict(clusterer, points_to_predict, convert_dtype="deprecated"):
"""Predict the cluster label of new points. The returned labels
will be those of the original clustering found by ``clusterer``,
and therefore are not (necessarily) the cluster labels that would
Expand Down
22 changes: 12 additions & 10 deletions python/cuml/cuml/cluster/kmeans.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ class KMeans(InteropMixin,

@generate_docstring()
@reflect(reset=True)
def fit(self, X, y=None, sample_weight=None, *, convert_dtype=True) -> "KMeans":
def fit(self, X, y=None, sample_weight=None, *, convert_dtype="deprecated") -> "KMeans":
"""
Compute k-means clustering with X.

Expand Down Expand Up @@ -610,7 +610,7 @@ class KMeans(InteropMixin,
"""
return self.fit(X, sample_weight=sample_weight).labels_

def _predict_labels_inertia(self, X, convert_dtype=True, sample_weight=None):
def _predict_labels_inertia(self, X, convert_dtype="deprecated", sample_weight=None):
"""
Predict the closest cluster each sample in X belongs to.

Expand All @@ -621,10 +621,12 @@ class KMeans(InteropMixin,
Acceptable formats: cuDF DataFrame, NumPy ndarray, Numba device
ndarray, cuda array interface compliant array like CuPy

convert_dtype : bool, optional (default = False)
When set to True, the predict method will, when necessary, convert
the input to the data type which was used to train the model. This
will increase memory used for the method.
convert_dtype : bool, default="deprecated"
.. deprecated:: 26.08
`convert_dtype` was deprecated in version 26.08 and will be
removed in version 26.10. cuML only copies input arrays when
necessary (e.g. to unify dtypes), there is no reason to provide
this keyword going forward.

sample_weight : array-like (device or host) shape = (n_samples,), default=None # noqa
The weights for each observation in X. If None, all observations
Expand Down Expand Up @@ -674,7 +676,7 @@ class KMeans(InteropMixin,
self,
X,
*,
convert_dtype=True,
convert_dtype="deprecated",
) -> CumlArray:
"""
Predict the closest cluster each sample in X belongs to.
Expand All @@ -688,7 +690,7 @@ class KMeans(InteropMixin,
'description': 'Transformed data',
'shape': '(n_samples, n_clusters)'})
@reflect
def transform(self, X, *, convert_dtype=True) -> CumlArray:
def transform(self, X, *, convert_dtype="deprecated") -> CumlArray:
"""
Transform X to a cluster-distance space.

Expand Down Expand Up @@ -784,7 +786,7 @@ class KMeans(InteropMixin,
of X on the K-means \
objective.'})
@run_in_internal_context
def score(self, X, y=None, sample_weight=None, *, convert_dtype=True):
def score(self, X, y=None, sample_weight=None, *, convert_dtype="deprecated"):
"""
Opposite of the value of X on the K-means objective.

Expand All @@ -801,7 +803,7 @@ class KMeans(InteropMixin,
'shape': '(n_samples, n_clusters)'})
@reflect
def fit_transform(
self, X, y=None, sample_weight=None, *, convert_dtype=False
self, X, y=None, sample_weight=None, *, convert_dtype="deprecated"
) -> CumlArray:
"""
Compute clustering and transform X to cluster-distance space.
Expand Down
89 changes: 24 additions & 65 deletions python/cuml/cuml/common/doc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,38 @@

_parameters_docstrings = {
"dense": "{name} : array-like (device or host) shape = {shape}\n"
" Dense matrix. If datatype is other than floats or doubles,\n"
" then the data will be converted to float which increases memory\n"
" utilization. Set the parameter convert_dtype to False to avoid \n"
" this, then the method will throw an error instead. \n"
" Dense matrix with dtype float32 or float64.\n"
" Acceptable formats: CUDA array interface compliant objects like\n"
" CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas\n"
" DataFrame/Series.",
"dense_anydtype": "{name} : array-like (device or host) shape = {shape}\n"
" Dense matrix of any dtype.\n"
" Dense matrix with any dtype.\n"
" Acceptable formats: CUDA array interface compliant objects like\n"
" CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas\n"
" DataFrame/Series.",
"dense_intdtype": "{name} : array-like (device or host) shape = {shape}\n"
" Dense matrix of type np.int32.\n"
" Dense matrix with dtype int32.\n"
" Acceptable formats: CUDA array interface compliant objects like\n"
" CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas\n"
" DataFrame/Series.",
"sparse": "{name} : sparse array-like (device) shape = {shape}\n"
" Dense matrix containing floats or doubles.\n"
" Sparse matrix with dtype float32 or float64.\n"
" Acceptable formats: cupyx.scipy.sparse",
"dense_sparse": "{name} : array-like (device or host) shape = {shape}\n"
" Dense or sparse matrix containing floats or doubles.\n"
" Dense or sparse matrix with dtype float32 or float64.\n"
" Acceptable dense formats: CUDA array interface compliant objects like\n" # noqa
" CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas\n"
" DataFrame/Series.",
"convert_dtype_fit": "convert_dtype : bool, optional (default = {default})\n"
" When set to True, the train method will, when necessary, convert\n"
" y to be the same data type as X if they differ. This\n"
" will increase memory used for the method.",
"convert_dtype_other": "convert_dtype : bool, optional (default = {default})\n"
" When set to True, the {func_name} method will, when necessary,\n"
" convert the input to the data type which was used to train the\n"
" model. This will increase memory used for the method.",
"convert_dtype_single": "convert_dtype : bool, optional (default = {default})\n"
" When set to True, the method will automatically\n"
" convert the inputs to {dtype}.",
"convert_dtype": "convert_dtype : bool, optional (default = 'deprecated')\n"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Here we update the docstring generator for documenting the deprecation of convert_dtype.

I also slightly updated the dtype notes on other arg types. In the future I'd like to do more cleanups here (regarding how we document other parameters), was only trying to do the minimal amount so things weren't definitely incorrect.

" .. deprecated:: 26.08\n"
" `convert_dtype` was deprecated in version 26.08 and will be removed\n"
" in version 26.10. cuML only copies input arrays when necessary\n"
" (e.g. to unify dtypes), there is no reason to provide this keyword\n"
" going forward.\n",
"sample_weight": "sample_weight : array-like (device or host) shape = (n_samples,), default={default}\n" # noqa
" The weights for each observation in X. If None, all observations\n"
" are assigned equal weight.\n"
" Acceptable dense formats: CUDA array interface compliant objects like\n" # noqa
" Acceptable formats: CUDA array interface compliant objects like\n" # noqa
" CuPy, cuDF DataFrame/Series, NumPy ndarray and Pandas\n"
" DataFrame/Series.", # noqa
"return_sparse": "return_sparse : bool, optional (default = {default})\n"
Expand Down Expand Up @@ -114,15 +106,19 @@

_return_values_possible_values = ["name", "type", "shape", "description"]

_simple_params = ["return_sparse", "sparse_tol", "sample_weight"]
_simple_params = [
"convert_dtype",
"return_sparse",
"sparse_tol",
"sample_weight",
]


def generate_docstring(
X="dense",
X_shape="(n_samples, n_features)",
y="dense",
y_shape="(n_samples, 1)",
convert_dtype_cast=False,
skip_parameters=[],
skip_parameters_heading=False,
prepend_parameters=True,
Expand Down Expand Up @@ -152,7 +148,7 @@ def generate_docstring(
# anything, and the decorator auto detects the parameters and defaults

@generate_docstring()
def fit(self, X, y, convert_dtype=True):
def fit(self, X, y):

# for a function that takes X as dense or sparse

Expand All @@ -179,12 +175,6 @@ def fit(self, X, y, sample_weight=None):
dense_anydtype, dense_intdtype, sparse, dense_sparse
y_shape : str (default = '(n_samples, 1)')
Shape of variable y
convert_dtype_cast : Boolean or str (default = False)
If not false, use it to specify when convert_dtype is used to convert
to a single specific dtype (as opposed to converting the dtype of one
variable to the dtype of another for example). Example of this is how
NearestNeighbors and UMAP use convert_dtype to convert inputs to
np.float32.
skip_parameters : list of str (default = [])
Use if you want the decorator to skip generating a docstring entry
for a specific parameter
Expand Down Expand Up @@ -240,36 +230,10 @@ def deco(func):
func.__doc__ += _parameters_docstrings[y].format(
name=par, shape=y_shape
)

# convert_dtype requires some magic to distinguish
# whether we use the fit version or the version
# for the other methods.
elif par == "convert_dtype" and par not in skip_parameters:
if not convert_dtype_cast:
if func.__name__ == "fit":
k = "convert_dtype_fit"
else:
k = "convert_dtype_other"

func.__doc__ += _parameters_docstrings[k].format(
default=params["convert_dtype"].default,
func_name=func.__name__,
)

else:
func.__doc__ += _parameters_docstrings[
"convert_dtype_single"
].format(
default=params["convert_dtype"].default,
dtype=convert_dtype_cast,
)

# All other parameters only take a default (for now).
else:
if par in _simple_params:
func.__doc__ += _parameters_docstrings[par].format(
default=params[par].default
)
elif par in _simple_params:
func.__doc__ += _parameters_docstrings[par].format(
default=params[par].default
)
func.__doc__ += "\n\n"

if skip_parameters_heading and prepend_parameters:
Expand Down Expand Up @@ -324,8 +288,7 @@ def insert_into_docstring(parameters=False, return_values=False):
return_values=[('dense', '(n_samples, n_features)'),
('dense',
'(n_samples, n_features)')])
def kneighbors(self, X=None, n_neighbors=None, return_distance=True,
convert_dtype=True):
def kneighbors(self, X=None, n_neighbors=None, return_distance=True):
\"""
Query the GPU index for the k nearest neighbors of column vectors in X.

Expand All @@ -340,10 +303,6 @@ def kneighbors(self, X=None, n_neighbors=None, return_distance=True,
return_distance: Boolean
If False, distances will not be returned

convert_dtype : bool, optional (default = True)
When set to True, the kneighbors method will automatically
convert the inputs to np.float32.

Returns
-------
distances : {}
Expand Down
12 changes: 9 additions & 3 deletions python/cuml/cuml/covariance/empirical_covariance.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ def __init__(
self.assume_centered = assume_centered

@reflect(reset=True)
def fit(self, X, y=None, *, convert_dtype=True) -> "EmpiricalCovariance":
def fit(
self, X, y=None, *, convert_dtype="deprecated"
) -> "EmpiricalCovariance":
"""Fit the maximum likelihood covariance estimator to X.

Parameters
Expand All @@ -156,8 +158,12 @@ def fit(self, X, y=None, *, convert_dtype=True) -> "EmpiricalCovariance":
and `n_features` is the number of features.
y : Ignored
Not used, present for API consistency.
convert_dtype : bool, default=True
If True, convert the input data to float32.
convert_dtype : bool, default="deprecated"
.. deprecated:: 26.08
`convert_dtype` was deprecated in version 26.08 and will be
removed in version 26.10. cuML only copies input arrays when
necessary (e.g. to unify dtypes), there is no reason to provide
this keyword going forward.

Returns
-------
Expand Down
10 changes: 7 additions & 3 deletions python/cuml/cuml/covariance/ledoit_wolf.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def __init__(
self.block_size = block_size

@reflect(reset=True)
def fit(self, X, y=None, *, convert_dtype=True) -> "LedoitWolf":
def fit(self, X, y=None, *, convert_dtype="deprecated") -> "LedoitWolf":
"""Fit the Ledoit-Wolf shrunk covariance model to X.

Parameters
Expand All @@ -237,8 +237,12 @@ def fit(self, X, y=None, *, convert_dtype=True) -> "LedoitWolf":
and `n_features` is the number of features.
y : Ignored
Not used, present for API consistency.
convert_dtype : bool, default=True
If True, convert the input data to float32.
convert_dtype : bool, default="deprecated"
.. deprecated:: 26.08
`convert_dtype` was deprecated in version 26.08 and will be
removed in version 26.10. cuML only copies input arrays when
necessary (e.g. to unify dtypes), there is no reason to provide
this keyword going forward.

Returns
-------
Expand Down
26 changes: 16 additions & 10 deletions python/cuml/cuml/dask/ensemble/randomforestclassifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def _construct_rf(n_estimators, random_state, **kwargs):
n_estimators=n_estimators, random_state=random_state, **kwargs
)

def fit(self, X, y, convert_dtype=False, broadcast_data=False):
def fit(self, X, y, convert_dtype="deprecated", broadcast_data=False):
"""
Fit the input data with a Random Forest classifier

Expand Down Expand Up @@ -196,10 +196,13 @@ def fit(self, X, y, convert_dtype=False, broadcast_data=False):
y : Dask cuDF dataframe or CuPy backed Dask Array (n_rows, 1)
Labels of training examples.
**y must be partitioned the same way as X**
convert_dtype : bool, optional (default = False)
When set to True, the fit method will, when necessary, convert
y to be of dtype int32. This will increase memory used for
the method.
convert_dtype : bool, default="deprecated"
.. deprecated:: 26.08
`convert_dtype` was deprecated in version 26.08 and will be
removed in version 26.10. cuML only copies input arrays when
necessary (e.g. to unify dtypes), there is no reason to provide
this keyword going forward.

broadcast_data : bool, optional (default = False)
When set to True, the whole dataset is broadcasted
to train the workers, otherwise each worker
Expand Down Expand Up @@ -230,7 +233,7 @@ def predict(
self,
X,
threshold=0.5,
convert_dtype=True,
convert_dtype="deprecated",
layout="depth_first",
default_chunk_size=None,
align_bytes=None,
Expand All @@ -247,10 +250,13 @@ def predict(
(n_samples, n_features).
threshold : float (default = 0.5)
Threshold used for classification.
convert_dtype : bool, optional (default = True)
When set to True, the predict method will, when necessary, convert
the input to the data type which was used to train the model. This
will increase memory used for the method.
convert_dtype : bool, default="deprecated"
.. deprecated:: 26.08
`convert_dtype` was deprecated in version 26.08 and will be
removed in version 26.10. cuML only copies input arrays when
necessary (e.g. to unify dtypes), there is no reason to provide
this keyword going forward.

layout : string (default = 'depth_first')
Specifies the in-memory layout of nodes in FIL forests. Options:
'depth_first', 'layered', 'breadth_first'.
Expand Down
Loading
Loading