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 docs/source/FIL.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Deprecated ``load`` Parameters
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
As of RAPIDS 25.04, the following hyperparameters accepted by the ``.load`` method of previous versions of FIL have been deprecated.

- ``threshold`` (will raise a ``DeprecationWarning`` if used; pass to ``.predict`` instead)
- ``threshold`` (will trigger a deprecation warning if used; pass to ``.predict`` instead)
- ``algo`` (ignored, but a warning will be logged)
- ``storage_type`` (ignored, but a warning will be logged)
- ``blocks_per_sm`` (ignored, but a warning will be logged)
Expand Down
38 changes: 24 additions & 14 deletions python/cuml/cuml/fil/fil.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#
import itertools
import pathlib
import warnings
from time import perf_counter

import numpy as np
Expand Down Expand Up @@ -462,7 +463,7 @@ class ForestInference(Base, CMajorInputTagMixin):
"""
_param_names = [
"treelite_model", "handle", "output_type", "verbose", "is_classifier",
"layout", "default_chunk_size", "align_bytes", "precision", "device_id",
"default_threshold", "layout", "default_chunk_size", "align_bytes", "precision", "device_id",
]

def _reload_model(self):
Expand Down Expand Up @@ -614,6 +615,7 @@ class ForestInference(Base, CMajorInputTagMixin):
output_type=None,
verbose=False,
is_classifier=False,
default_threshold=None,
layout='depth_first',
default_chunk_size=None,
align_bytes=None,
Expand All @@ -623,6 +625,8 @@ class ForestInference(Base, CMajorInputTagMixin):
super().__init__(
handle=handle, verbose=verbose, output_type=output_type
)
# TODO(hcho3): 25.10: Remove this parameter; direct users to set `threshold` in predict()
self.default_threshold = default_threshold if default_threshold else 0.5
self.is_classifier = is_classifier
self.default_chunk_size = default_chunk_size
self.align_bytes = align_bytes
Expand Down Expand Up @@ -729,7 +733,7 @@ class ForestInference(Base, CMajorInputTagMixin):
is_classifier : boolean, default=False
True for classification models, False for regressors
threshold : float
Removed in 25.08. Please set `threshold` in `predict()` instead.
Deprecated in 25.08. Please set `threshold` in `predict()` instead.
precision : {'single', 'double', None}, default='single'
Use the given floating point precision for evaluating the model. If
None, use the native precision of the model. Note that
Expand Down Expand Up @@ -771,9 +775,10 @@ class ForestInference(Base, CMajorInputTagMixin):
pool to use during loading and inference.
"""
if threshold is not None:
raise ValueError(
"`load()` no longer accepts `threshold` parameter. "
"Set `threshold` in `predict()` instead."
warnings.warn(
"The `threshold` parameter of `load()` is deprecated and "
"will be removed in 25.10. Please set `threshold` in `predict()` instead.",
FutureWarning
Comment thread
hcho3 marked this conversation as resolved.
)
if model_type is None:
extension = pathlib.Path(path).suffix
Expand Down Expand Up @@ -805,6 +810,7 @@ class ForestInference(Base, CMajorInputTagMixin):
output_type=output_type,
verbose=verbose,
is_classifier=is_classifier,
default_threshold=threshold,
default_chunk_size=default_chunk_size,
align_bytes=align_bytes,
layout=layout,
Expand Down Expand Up @@ -837,7 +843,7 @@ class ForestInference(Base, CMajorInputTagMixin):
is_classifier : boolean, default=False
True for classification models, False for regressors
threshold : float
Removed in 25.08. Please set `threshold` in `predict()` instead.
Deprecated in 25.08. Please set `threshold` in `predict()` instead.
precision : {'single', 'double', None}, default='single'
Use the given floating point precision for evaluating the model. If
None, use the native precision of the model. Note that
Expand Down Expand Up @@ -889,9 +895,10 @@ class ForestInference(Base, CMajorInputTagMixin):
pool to use during loading and inference.
"""
if threshold is not None:
raise ValueError(
"`load_from_sklearn()` no longer accepts `threshold` parameter. "
"Set `threshold` in `predict()` instead."
warnings.warn(
"The `threshold` parameter of `load_from_sklearn()` is deprecated and "
"will be removed in 25.10. Please set `threshold` in `predict()` instead.",
FutureWarning
)
tl_model = treelite.sklearn.import_model(skl_model)
result = cls(
Expand All @@ -900,6 +907,7 @@ class ForestInference(Base, CMajorInputTagMixin):
output_type=output_type,
verbose=verbose,
is_classifier=is_classifier,
default_threshold=threshold,
default_chunk_size=default_chunk_size,
align_bytes=align_bytes,
layout=layout,
Expand Down Expand Up @@ -933,7 +941,7 @@ class ForestInference(Base, CMajorInputTagMixin):
is_classifier : boolean, default=False
True for classification models, False for regressors
threshold : float
Removed in 25.08. Please set `threshold` in `predict()` instead.
Deprecated in 25.08. Please set `threshold` in `predict()` instead.
precision : {'single', 'double', None}, default='single'
Use the given floating point precision for evaluating the model. If
None, use the native precision of the model. Note that
Expand Down Expand Up @@ -985,16 +993,18 @@ class ForestInference(Base, CMajorInputTagMixin):
pool to use during loading and inference.
"""
if threshold is not None:
raise ValueError(
"`load_from_treelite_model()` no longer accepts `threshold` parameter. "
"Set `threshold` in `predict()` instead."
warnings.warn(
"The `threshold` parameter of `load_from_treelite_model()` is deprecated and "
"will be removed in 25.10. Please set `threshold` in `predict()` instead.",
FutureWarning
)
return cls(
treelite_model=tl_model,
handle=handle,
output_type=output_type,
verbose=verbose,
is_classifier=is_classifier,
default_threshold=threshold,
default_chunk_size=default_chunk_size,
align_bytes=align_bytes,
layout=layout,
Expand Down Expand Up @@ -1129,7 +1139,7 @@ class ForestInference(Base, CMajorInputTagMixin):
proba = self.forest.predict(X, chunk_size=chunk_size)
if len(proba.shape) < 2 or proba.shape[1] == 1:
if threshold is None:
threshold = 0.5
threshold = self.default_threshold
result = (
proba.to_output(output_type='array') > threshold
).astype('int')
Expand Down
4 changes: 1 addition & 3 deletions python/cuml/cuml/tests/test_fil.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,9 +561,7 @@ def test_thresholding(is_classifier, small_classifier_and_preds):
else:
assert ((fil_preds != 0.0) & (fil_preds != 1.0)).sum() > 0

with pytest.raises(
ValueError, match=r".*no longer accepts `threshold` parameter.*"
):
with pytest.warns(FutureWarning):
_ = ForestInference.load(
model_path,
model_type=model_type,
Expand Down