Skip to content

Remove deprecated handle argument - #7751

Merged
rapids-bot[bot] merged 12 commits into
NVIDIA:mainfrom
jcrist:remove-handle
Feb 5, 2026
Merged

Remove deprecated handle argument#7751
rapids-bot[bot] merged 12 commits into
NVIDIA:mainfrom
jcrist:remove-handle

Conversation

@jcrist

@jcrist jcrist commented Feb 3, 2026

Copy link
Copy Markdown
Member

This removes the deprecated handle argument/attributes on all relevant models and functions.

Note that for now the (mostly private) *MG classes retain their handle argument and attribute since the multi-gpu comms are currently attached to the handles. Some care has been taken to ensure the proper handle is utilized for multi-gpu APIs. All other APIs now make use of the get_handle function exclusively.

This is a follow-up to #7628. Fixes #7722.

@jcrist jcrist self-assigned this Feb 3, 2026
@jcrist jcrist added the improvement Improvement / enhancement to an existing function label Feb 3, 2026
@jcrist
jcrist requested a review from a team as a code owner February 3, 2026 00:28
@jcrist jcrist added the non-breaking Non-breaking change label Feb 3, 2026
@jcrist
jcrist requested a review from dantegd February 3, 2026 00:28
@github-actions github-actions Bot added the Cython / Python Cython or Python issue label Feb 3, 2026
@coderabbitai

coderabbitai Bot commented Feb 4, 2026

Copy link
Copy Markdown
📝 Walkthrough

Summary by CodeRabbit

  • Refactor
    • Removed the deprecated "handle" parameter from many public APIs; resource/stream management is now automatic.
    • Multi‑GPU variants now use instance-managed handles or accept explicit handles where applicable.
  • Documentation
    • Removed deprecated handle docs across modules; updated docstrings to match new signatures.
  • Chores
    • Updated copyright years.
  • Tests
    • Removed legacy tests covering deprecated handle behavior.

Walkthrough

Removed the deprecated handle exposure and deprecation scaffolding across the codebase. Constructors and function signatures no longer accept handle; internal handle access now uses get_handle() (no model arg) or instance self.handle for MG variants. Related docs and tests were updated/removed.

Changes

Cohort / File(s) Summary
Core infra & exports
python/cuml/cuml/__init__.py, python/cuml/cuml/internals/base.py, python/cuml/cuml/_thirdparty/sklearn/utils/skl_dependencies.py
Deleted DeprecatedHandleDescriptor and lazy Handle exposure; simplified get_handle() signature and Base.__init__ to only verbose/output_type; removed deprecated handle branching.
Cluster algorithms
python/cuml/cuml/cluster/...
agglomerative.pyx, dbscan.pyx, dbscan_mg.py, hdbscan/hdbscan.pyx, kmeans.pyx, kmeans_mg.py, spectral_clustering.pyx
Removed handle from public constructors and docstrings; updated super() calls; MG variants store self.handle; internal handle retrieval now uses get_handle() or conditional self.handle for multi‑GPU.
Decomposition
python/cuml/cuml/decomposition/...
base_mg.py, pca.pyx, pca_mg.pyx, tsvd.pyx, tsvd_mg.pyx, incremental_pca.py
Removed handle from constructors; MG classes accept/store handle; non‑MG code replaced get_handle(model=self) with get_handle(); super() calls updated.
Ensemble & FIL
python/cuml/cuml/ensemble/..., python/cuml/cuml/fil/fil.pyx
Dropped handle from RandomForest and shared utilities; ForestInference and ForestInference_impl no longer accept raft_handle externally and obtain handles internally; param exposure updated.
Linear models & solvers
python/cuml/cuml/linear_model/..., python/cuml/cuml/solvers/...
Removed handle from many constructors and fit helpers (QN, CD, SGD); replaced get_handle(model=self) with get_handle() or self.handle in MG code; signatures updated accordingly.
SVM & linear SVM infra
python/cuml/cuml/svm/...
Removed handle from public APIs; added/propagated n_streams where applicable; fit/predict paths obtain handles internally or use n_streams.
Neighbors & indices
python/cuml/cuml/neighbors/...
Removed handle from NearestNeighbors and index APIs; RBCIndex/ApproxIndex build/kneighbors signatures now create handles internally; NearestNeighborsMG/other MG classes accept and store handle.
Manifold & metrics
python/cuml/cuml/manifold/..., python/cuml/cuml/metrics/...
Removed handle from spectral_embedding/TSNE/UMAP and numerous metric functions; replaced get_handle(handle=...) with get_handle(); cleaned docstrings and multiline signature formatting.
Preprocessing & feature extraction
python/cuml/cuml/preprocessing/*, python/cuml/cuml/feature_extraction/_tfidf.py
Dropped handle from encoders, LabelEncoder, TargetEncoder, LabelBinarizer and TFIDF transformer; removed handle propagation when instantiating internal encoders; super() calls updated.
Naive Bayes, multiclass & misc estimators
many files (e.g., python/cuml/cuml/naive_bayes/naive_bayes.py, multiclass/multiclass.py, kernel_ridge, covariance, random_projection, kernel_density...)
Removed handle from many constructors and removed deprecation docblocks; super() calls updated throughout.
Explainer & experimental
python/cuml/cuml/explainer/*, python/cuml/cuml/experimental/*
Removed handle from SHAP/Kernel/Permutation explainers and experimental modules; eliminated DeprecatedHandleDescriptor usage; internal handle acquisition standardized.
Time series & datasets
python/cuml/cuml/tsa/*, python/cuml/cuml/datasets/*
Removed handle from ARIMA/AutoARIMA/HoltWinters and dataset factories; internal get_handle(model=self)get_handle().
Dask wiring & factories
python/cuml/cuml/dask/...
Removed deprecated handle docs; switched to direct MG class imports (no aliases) and adjusted factory instantiation to pass handle only where MG constructors require it.
Tests & utilities
python/cuml/cuml/testing/utils.py, python/cuml/tests/*
Removed or updated tests covering deprecated handle behavior and Handle exposure; examples updated to new signatures; some tests deleted or simplified.
Formatting & metadata
multiple files
SPDX copyright year bumps (2025→2026) and minor multiline signature reformatting across many modules.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • divyegala
  • csadorf
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly and concisely summarizes the main change: removing deprecated handle argument from the codebase.
Description check ✅ Passed Description is directly related to the changeset, explaining the removal of deprecated handle argument and MG class retention with clear rationale.
Linked Issues check ✅ Passed The PR fully addresses the linked issue #7722 by removing handle from public APIs while preserving it in private MG classes as required.
Out of Scope Changes check ✅ Passed All changes are directly related to removing the deprecated handle argument across models and functions, with copyright year updates as consistent metadata changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (6)
python/cuml/cuml/tsa/stationarity.pyx (1)

35-54: ⚠️ Potential issue | 🟡 Minor

Document convert_dtype in the public docstring.

Line 35 introduces convert_dtype, but the Parameters section stops at pval_threshold, which makes the signature/docstring inconsistent for users. Please add a short description for convert_dtype.

✏️ Suggested docstring update
@@
     pval_threshold : float
         The p-value threshold above which a series is considered stationary.
+    convert_dtype : bool, default=True
+        Whether to convert inputs to float32 when possible.
python/cuml/cuml/metrics/trustworthiness.pyx (1)

80-84: ⚠️ Potential issue | 🟡 Minor

Duplicate validation check.

The same validation for n_neighbors > X.shape[0] is performed twice with identical error messages. One of these checks should be removed.

Proposed fix
     if n_neighbors > X.shape[0]:
         raise ValueError("n_neighbors must be <= the number of rows.")

-    if n_neighbors > X.shape[0]:
-        raise ValueError("n_neighbors must be <= the number of rows.")
-
     cdef uintptr_t d_X_ptr
python/cuml/cuml/svm/linear.pyx (2)

105-127: ⚠️ Potential issue | 🟡 Minor

Minor: Docstring mentions removed handle parameter.

The docstring at line 109-110 still references a handle : pylibraft.common.Handle parameter that no longer exists in the function signature.

📝 Proposed fix to remove stale docstring
     """Perform a Linear SVR or SVC fit.

     Parameters
     ----------
-    handle : pylibraft.common.Handle
-        The handle to use.
     X : CumlArray, shape = (n_samples, n_features)
         Training vectors

85-127: ⚠️ Potential issue | 🟡 Minor

Update docstring to remove stale handle parameter documentation.

The API change is correctly implemented and all callers have been properly updated. However, the docstring still documents a handle parameter (line 109) that no longer exists in the function signature. The handle is now created internally via get_handle(n_streams=n_streams) at line 224. Remove the stale parameter documentation from the docstring:

handle : pylibraft.common.Handle
    The handle to use.

Both LinearSVC.fit() and LinearSVR.fit() correctly call the underlying cuml.svm.linear.fit() function without passing a handle, so no downstream changes are required.

python/cuml/cuml/tsa/holtwinters.pyx (1)

87-91: ⚠️ Potential issue | 🟡 Minor

Minor: Stale handle reference in docstring.

The Known Differences section at lines 87-91 still mentions handle as a parameter that differs from statsmodels:

"this version can take additional parameters eps, start_periods, ts_num, and handle"

Since handle is no longer a parameter, this documentation should be updated.

📝 Proposed fix to update stale docstring
     * this version can take additional parameters `eps`,
-      `start_periods`, `ts_num`, and `handle`
+      `start_periods`, and `ts_num`
python/cuml/cuml/explainer/base.pyx (1)

344-344: ⚠️ Potential issue | 🟠 Major

Remove .order from the attribute access on line 344.

Line 344 incorrectly accesses self.masker.order.dtype. Line 338 shows that self.masker.order is a string ("C" in this case), not an array. Attempting to access .dtype on a string will raise an AttributeError at runtime.

The check should access self.masker.dtype instead, which is the dtype of the background data array (as evidenced by line 355 where the masker is cast with .astype(cp.float32)).

Fix
-        if self.masker.order.dtype == cp.float32:
+        if self.masker.dtype == cp.float32:
🤖 Fix all issues with AI agents
In `@python/cuml/cuml/cluster/kmeans.pyx`:
- Line 658: _update both _predict_labels_inertia and transform so they use the
instance MG handle when appropriate: replace direct calls to get_handle() with
the conditional pattern used in fit — use self.handle if self._multi_gpu else
get_handle() — ensuring _predict_labels_inertia, transform, and any local
variable named handle follow this pattern; this keeps KMeansMG (which sets
_multi_gpu = True) using its multi-GPU handle rather than a new default handle.

In `@python/cuml/cuml/datasets/arima.pyx`:
- Around line 53-56: The make_arima function signature currently defaults
dtype='double' while its docstring claims the default is 'single'; update either
the function signature or the docstring so they match. Locate the make_arima
definition and either change the signature dtype default to 'single' or edit the
docstring text to state 'double' (whichever is correct for expected behavior),
and ensure any tests or callers expecting the previous default are adjusted
accordingly.

In `@python/cuml/cuml/metrics/pairwise_distances.pyx`:
- Line 329: The call to sparse_pairwise_distances is missing the metric_arg
captured by the wrapper, so when X is sparse the user-specified metric_arg is
dropped; update the return call in the pairwise_distances wrapper to forward
metric_arg (e.g., call sparse_pairwise_distances(X, Y, metric, convert_dtype,
metric_arg=metric_arg, **kwds)) so the provided metric_arg reaches
sparse_pairwise_distances and controls metrics like Minkowski.

In `@python/cuml/cuml/testing/utils.py`:
- Around line 268-270: The docstring for the parameter custom_constructors
currently shows a mismatched example key and constructor; update the example so
the dictionary key and instantiated class match (e.g., use {'LinearSVC': lambda:
cuml.LinearSVC(n_streams=2)} or {'LogisticRegression': lambda:
cuml.LogisticRegression(...)}), editing the docstring near the
custom_constructors description in utils.py to keep names consistent and clear.
🧹 Nitpick comments (2)
python/cuml/cuml/cluster/dbscan_mg.py (1)

20-22: Optional: fail fast on a missing handle.

Line 20 makes handle required, but a None value will fail later. Consider a small guard for a clearer error.

💡 Suggested guard
 def __init__(self, *, handle, **kwargs):
+    if handle is None:
+        raise ValueError("DBSCANMG requires a valid handle for MG comms")
     self.handle = handle
     super().__init__(**kwargs)
python/cuml/cuml/manifold/umap/umap.pyx (1)

1238-1242: LGTM!

The handle acquisition via get_handle(device_ids=self.device_ids) correctly preserves multi-device capability. Note: Line 1242 appears redundant as handle_ is already assigned on line 1239.

🔧 Minor: Remove redundant handle assignment
         handle = get_handle(device_ids=self.device_ids)
         cdef handle_t * handle_ = <handle_t*> <size_t> handle.getHandle()
         cdef unique_ptr[device_buffer] embeddings_buffer
         cdef lib.HostCOO fss_graph = lib.HostCOO()
-        handle_ = <handle_t*> <size_t> handle.getHandle()

Comment thread python/cuml/cuml/cluster/kmeans.pyx
Comment thread python/cuml/cuml/datasets/arima.pyx
Comment thread python/cuml/cuml/metrics/pairwise_distances.pyx Outdated
Comment thread python/cuml/cuml/testing/utils.py Outdated

@viclafargue viclafargue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, LGTM!

Comment thread python/cuml/cuml/metrics/pairwise_distances.pyx
Comment thread python/cuml/cuml/svm/linear.pyx
rapids-bot Bot pushed a commit that referenced this pull request Feb 4, 2026
This removes almost all the remaining deprecations (outside of #7751). The only one I didn't handle was deprecations in `TargetEncoder` since I couldn't figure out what the intended behavior was. Will leave that for others.

Summary:

- Removes deprecated `cuml.internals.memory_utils` module
- Removes deprecated `TotalIters` for `cuml.svm`
- Removes deprecated `y` parameter in `train_test_split`
- Removes deprecated parameters to `UMAP` (fixes #7709)

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

Approvers:
  - Simon Adorf (https://github.com/csadorf)

URL: #7761
@jcrist

jcrist commented Feb 5, 2026

Copy link
Copy Markdown
Member Author

/merge

@rapids-bot
rapids-bot Bot merged commit ed56125 into NVIDIA:main Feb 5, 2026
165 of 172 checks passed
@jcrist
jcrist deleted the remove-handle branch February 5, 2026 14:31
@betatim betatim mentioned this pull request Feb 5, 2026
rapids-bot Bot pushed a commit that referenced this pull request Feb 5, 2026
I think what happened is that #7751 fixed something that used to lead to the `check_do_not_raise_errors_in_init_or_set_params` check failing. The reason we ended up seeing it in #7632 is that #7751 was merged before #7753 (and we didnt rerun the CI for that PR).

Authors:
  - Tim Head (https://github.com/betatim)

Approvers:
  - Jim Crist-Harif (https://github.com/jcrist)
  - Simon Adorf (https://github.com/csadorf)

URL: #7768
dantegd added a commit to dantegd/cuml that referenced this pull request Feb 17, 2026
This removes almost all the remaining deprecations (outside of NVIDIA#7751). The only one I didn't handle was deprecations in `TargetEncoder` since I couldn't figure out what the intended behavior was. Will leave that for others.

Summary:

- Removes deprecated `cuml.internals.memory_utils` module
- Removes deprecated `TotalIters` for `cuml.svm`
- Removes deprecated `y` parameter in `train_test_split`
- Removes deprecated parameters to `UMAP` (fixes NVIDIA#7709)

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

Approvers:
  - Simon Adorf (https://github.com/csadorf)

URL: NVIDIA#7761
dantegd added a commit to dantegd/cuml that referenced this pull request Feb 17, 2026
This removes the deprecated `handle` argument/attributes on all relevant models and functions.

Note that for now the (_mostly_ private) `*MG` classes retain their `handle` argument and attribute since the multi-gpu comms are currently attached to the handles. Some care has been taken to ensure the proper handle is utilized for multi-gpu APIs. All other APIs now make use of the `get_handle` function exclusively.

This is a follow-up to NVIDIA#7628. Fixes NVIDIA#7722.

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

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

URL: NVIDIA#7751
dantegd added a commit to dantegd/cuml that referenced this pull request Feb 17, 2026
I think what happened is that NVIDIA#7751 fixed something that used to lead to the `check_do_not_raise_errors_in_init_or_set_params` check failing. The reason we ended up seeing it in NVIDIA#7632 is that NVIDIA#7751 was merged before NVIDIA#7753 (and we didnt rerun the CI for that PR).

Authors:
  - Tim Head (https://github.com/betatim)

Approvers:
  - Jim Crist-Harif (https://github.com/jcrist)
  - Simon Adorf (https://github.com/csadorf)

URL: NVIDIA#7768
@coderabbitai coderabbitai Bot mentioned this pull request Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Remove handle from public API

6 participants