All skills
Skillintermediate

cuML Reference

cuML is NVIDIA's GPU-accelerated machine learning library within the RAPIDS ecosystem. It provides scikit-learn-compatible APIs for 50+ algorithms, delivering 10-50x faster performance on average, with some algorithms (HDBSCAN, t-SNE, UMAP, KNN) reaching 60-600x speedup. It follows the familiar fit/predict/transform pattern from sklearn.

Claude Code Knowledge Pack7/10/2026

Overview

cuML Reference

cuML is NVIDIA's GPU-accelerated machine learning library within the RAPIDS ecosystem. It provides scikit-learn-compatible APIs for 50+ algorithms, delivering 10-50x faster performance on average, with some algorithms (HDBSCAN, t-SNE, UMAP, KNN) reaching 60-600x speedup. It follows the familiar fit/predict/transform pattern from sklearn.

Full documentation: https://docs.rapids.ai/api/cuml/stable/

Table of Contents

  1. Installation and Setup
  2. Two Usage Modes
  3. cuml.accel Accelerator Mode
  4. Direct cuML API
  5. Algorithm Catalog
  6. Input/Output Type Handling
  7. Preprocessing
  8. Feature Extraction
  9. Model Selection and Tuning
  10. Forest Inference Library (FIL)
  11. Multi-GPU with Dask
  12. Model Serialization
  13. Memory Management
  14. Performance Optimization
  15. Interoperability
  16. Key Differences from sklearn
  17. Common Migration Patterns

Installation and Setup

Always use uv add (never pip install or conda install) in all install instructions, docstrings, comments, and error messages.

uv add --extra-index-url=https://pypi.nvidia.com cuml-cu12    # For CUDA 12.x

Platform: Linux and WSL2 only (no native macOS or Windows). Requires: scikit-learn >= 1.4, NVIDIA GPU with CUDA 12.x support.

Verify:


print(cuml.__version__)

from cuml.datasets import make_blobs
X, y = make_blobs(n_samples=1000, n_features=10)
print(f"Generated {X.shape[0]} samples on GPU")

Two Usage Modes

1. cuml.accel (Zero-Code-Change)

Transparently intercepts sklearn, umap-learn, and hdbscan calls and routes them to GPU. Falls back to CPU for unsupported operations. Best for: quick acceleration of existing sklearn code, mixed codebases, prototyping.

2. Direct cuML API

Replace from sklearn with from cuml. Maximum performance, explicit control over GPU execution. Best for: production pipelines, maximum performance, new GPU-first code.


cuml.accel Accelerator Mode

The fastest path from sklearn to GPU — no code changes required. Similar to cudf.pandas for pandas.

Activation

# Jupyter/IPython (MUST be the first cell, before any sklearn import)
%load_ext cuml.accel

from sklearn.cluster import KMeans  # Runs on GPU transparently
# Command line
python -m cuml.accel script.py
python -m cuml.accel -v script.py     # With info logging
python -m cuml.accel -vv script.py    # With debug logging
# Programmatic (call BEFORE importing sklearn)

cuml.accel.install()

from sklearn.cluster import KMeans  # Now GPU-accelerated
# Environment variable
CUML_ACCEL_ENABLED=1 python script.py

How It Works

  • Intercepts sklearn/umap-learn/hdbscan imports and replaces estimators with GPU versions.
  • If an operation isn't supported on GPU, it silently falls back to CPU sklearn.
  • Uses managed memory by default — host RAM augments GPU VRAM.
  • Models pickled under cuml.accel load as standard sklearn objects in non-GPU environments.
  • Accelerates 30+ algorithms across sklearn, umap-learn, and hdbscan.
  • Compatible with scikit-learn versions 1.4-1.7.

Known Fallback Triggers (Runs on CPU Instead)

  • Sparse input data (most algorithms)
  • Callable parameters (e.g., callable init for KMeans)
  • Certain parameter values: n_components="mle" for PCA, positive=True for linear models, warm starts
  • Unsupported distance metrics for neighbors algorithms
  • Multi-output targets for Random Forest
  • String/object dtypes — must pre-encode with LabelEncoder first

Numerical Precision

GPU results are numerically equivalent but may differ at floating-point precision level due to parallel reduction order. Compare model quality via scores (accuracy, R2, etc.), not raw coefficient values.


Direct cuML API

Replace sklearn imports with cuml imports. The API is identical — fit/predict/transform.

from cuml.cluster import DBSCAN
from cuml.datasets import make_blobs

# Create data directly on GPU
X, y = make_blobs(n_samples=100_000, centers=5, n_features=10, random_state=42)

# Fit — runs on GPU
model = DBSCAN(eps=1.0, min_samples=5)
model.fit(X)
print(model.labels_)
from cuml import LinearRegression
from cuml.datasets import make_regression
from cuml.model_selection import train_test_split

X, y = make_regression(n_samples=100_000, n_features=50, noise=0.1)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)

model = LinearRegression()
model.fit(X_train, y_train)
predictions = model.predict(X_test)
score = model.score(X_test, y_test)
print(f"R2 score: {score:.4f}")

Algorithm Catalog

Clustering

cuMLsklearn EquivalentMulti-GPU
cuml.KMeanssklearn.cluster.KMeansYes
cuml.DBSCANsklearn.cluster.DBSCANYes
cuml.AgglomerativeClusteringsklearn.cluster.AgglomerativeClusteringNo
cuml.cluster.hdbscan.HDBSCANhdbscan.HDBSCANNo
cuml.cluster.SpectralClusteringsklearn.cluster.SpectralClusteringNo

Regression

cuMLsklearn EquivalentMulti-GPU
cuml.LinearRegressionsklearn.linear_model.LinearRegressionYes
cuml.Ridgesklearn.linear_model.RidgeYes
cuml.Lassosklearn.linear_model.LassoYes
cuml.ElasticNetsklearn.linear_model.ElasticNetYes
cuml.SVRsklearn.svm.SVRNo
cuml.KernelRidgesklearn.kernel_ridge.KernelRidgeNo
cuml.ensemble.RandomForestRegressorsklearn.ensemble.RandomForestRegressorYes
cuml.MBSGDRegressorsklearn.linear_model.SGDRegressorNo

Classification

cuMLsklearn EquivalentMulti-GPU
cuml.LogisticRegressionsklearn.linear_model.LogisticRegressionNo
cuml.ensemble.RandomForestClassifiersklearn.ensemble.RandomForestClassifierYes
cuml.svm.SVCsklearn.svm.SVCNo
cuml.svm.LinearSVCsklearn.svm.LinearSVCNo
cuml.naive_bayes.GaussianNBsklearn.naive_bayes.GaussianNBNo
cuml.naive_bayes.MultinomialNBsklearn.naive_bayes.MultinomialNBYes
cuml.naive_bayes.BernoulliNBsklearn.naive_bayes.BernoulliNBNo
cuml.naive_bayes.CategoricalNBsklearn.naive_bayes.CategoricalNBNo
cuml.naive_bayes.ComplementNBsklearn.naive_bayes.ComplementNBNo
cuml.neighbors.KNeighborsClassifiersklearn.neighbors.KNeighborsClassifierYes
cuml.neighbors.KNeighborsRegressorsklearn.neighbors.KNeighborsRegressorYes
cuml.MBSGDClassifiersklearn.linear_model.SGDClassifierNo
cuml.multiclass.OneVsOneClassifiersklearn.multiclass.OneVsOneClassifierNo
cuml.multiclass.OneVsRestClassifiersklearn.multiclass.OneVsRestClassifierNo

Dimensionality Reduction and Manifold Learning

cuMLsklearn/Library EquivalentMulti-GPU
cuml.PCAsklearn.decomposition.PCAYes
cuml.IncrementalPCAsklearn.decomposition.IncrementalPCANo
cuml.TruncatedSVDsklearn.decomposition.TruncatedSVDYes
cuml.UMAPumap.UMAPYes (inference)
cuml.TSNEsklearn.manifold.TSNENo
cuml.random_projection.GaussianRandomProjectionsklearn.random_projection.GaussianRandomProjectionNo
cuml.random_projection.SparseRandomProjectionsklearn.random_projection.SparseRandomProjectionNo

Nearest Neighbors

cuMLsklearn EquivalentMulti-GPU
cuml.neighbors.NearestNeighborssklearn.neighbors.NearestNeighborsYes
cuml.neighbors.KNeighborsClassifiersklearn.neighbors.KNeighborsClassifierYes
cuml.neighbors.KNeighborsRegressorsklearn.neighbors.KNeighborsRegressorYes
cuml.neighbors.KernelDensitysklearn.neighbors.KernelDensityNo

Time Series

cuMLDescription
cuml.ExponentialSmoothingHolt-Winters exponential smoothing
cuml.tsa.ARIMAARIMA/SARIMA models (batched — fits multiple series simultaneously)
cuml.tsa.auto_arima.AutoARIMAAutomatic ARIMA order selection

Metrics (GPU-Accelerated)

Regression: r2_score, mean_squared_error, mean_absolute_error, mean_squared_log_error, median_absolute_error

Classification: accuracy_score, log_loss, roc_auc_score, precision_recall_curve, confusion_matrix

Clustering: adjusted_rand_score, silhouette_score, silhouette_samples, homogeneity_score, completeness_score, v_measure_score, mutual_info_score

Other: trustworthiness, pairwise_distances, pairwise_kernels

Model Explainability

cuMLDescription
cuml.explainer.KernelExplainerSHAP Kernel Explainer
cuml.explainer.PermutationExplainerSHAP Permutation Explainer
cuml.explainer.TreeExplainerSHAP Tree Explainer

Input/Output Type Handling

Supported Input Types

cuML accepts: NumPy arrays, CuPy arrays, cuDF DataFrames/Series, pandas DataFrames/Series, Numba device arrays, PyTorch tensors (via __cuda_array_interface__).

NumPy and pandas inputs are automatically transferred to GPU. For best performance, pass CuPy arrays or cuDF DataFrames to avoid transfers.

Controlling Output Type


# Global setting
cuml.set_global_output_type('cupy')  # Options: 'input', 'cupy', 'numpy', 'cudf', 'pandas'

# Context manager
with cuml.using_output_type('cudf'):
    result = model.predict(X)  # Returns cudf Series

# Per-estimator
model = cuml.KMeans(output_type='cupy')

Performance ranking (fastest to slowest output type):

  1. cupy — no host transfers, most efficient
  2. cudf — slight overhead for some shapes
  3. numpy / pandas — device-to-host transfer cost

Best practice: Use cupy or cudf for intermediate results. Only convert to numpy/pandas at the end for visualization or export.


Preprocessing

cuML provides GPU-accelerated versions of all common sklearn preprocessors.

Scalers and Transformers

from cuml.preprocessing import StandardScaler, MinMaxScaler, RobustScaler
from cuml.preprocessing import Normalizer, PowerTransformer, QuantileTransformer
from cuml.preprocessing import Binarizer, PolynomialFeatures, KBinsDiscretizer

scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

Encoders

from cuml.preprocessing import LabelEncoder, OneHotEncoder, LabelBinarizer, TargetEncoder

le = LabelEncoder()
y_encoded = le.fit_transform(y)

ohe = OneHotEncoder(sparse_output=False)
X_encoded = ohe.fit_transform(X_categorical)

Imputers

from cuml.preprocessing import SimpleImputer, MissingIndicator

imputer = SimpleImputer(strategy='mean')
X_imputed = imputer.fit_transform(X)

Pipeline and Composition

from cuml.compose import ColumnTransformer, make_column_transformer
from cuml.preprocessing import StandardScaler, OneHotEncoder

preprocessor = make_column_transformer(
    (StandardScaler(), ['age', 'income']),
    (OneHotEncoder(), ['category', 'region']),
)
X_processed = preprocessor.fit_transform(df)

Preprocessing Functions

scale(), minmax_scale(), maxabs_scale(), robust_scale(), normalize(), binarize(), add_dummy_feature(), label_binarize()


Feature Extraction

from cuml.feature_extraction.text import TfidfVectorizer, CountVectorizer, HashingVectorizer

tfidf = TfidfVectorizer(max_features=10000)
X_tfidf = tfidf.fit_transform(corpus)

Model Selection and Tuning

Train/Test Split

from cuml.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

Cross-Validation

from cuml.model_selection import KFold

kf = KFold(n_splits=5, shuffle=True, random_state=42)
for train_idx, test_idx in kf.split(X):
    X_train, X_test = X[train_idx], X[test_idx]
    # ...

Hyperparameter Tuning

For GPU-efficient hyperparameter search, use dask-ml's GridSearchCV/RandomizedSearchCV rather than sklearn's — sklearn's version causes excessive CPU-GPU data transfers per fold.

from dask_ml.model_selection import RandomizedSearchCV
from cuml.ensemble import RandomForestClassifier

param_distributions = {
    'max_depth': [8, 12, 16, 20],
    'n_estimators': [100, 200, 500],
    'max_features': [0.5, 0.75, 1.0],
}

search = RandomizedSearchCV(
    RandomForestClassifier(),
    param_distributions,
    n_iter=25,
    cv=5,
    random_state=42,
)
search.fit(X_train, y_train)
print(f"Best score: {search.best_score_:.4f}")
print(f"Best params: {search.best_params_}")

Dataset Generators

from cuml.datasets import make_blobs, make_classification, make_regression

X, y = make_blobs(n_samples=100_000, centers=5, n_features=20, random_state=42)
X, y = make_classification(n_samples=100_000, n_features=50, n_informative=25)
X, y = make_regression(n_samples=100_000, n_features=50, noise=0.1)

Forest Inference Library

FIL provides high-performance GPU inference for tree-based models trained in any framework — 80x+ faster than sklearn inference.

from cuml.fil import ForestInference

# Load from XGBoost, LightGBM, or sklearn saved models
fil_model = ForestInference.load("xgboost_model.ubj", is_classifier=True)

# Optional: optimize for specific batch size
fil_model.optimize()

# Predict (80x+ faster than sklearn)
predictions = fil_model.predict(X_test)
probas = fil_model.predict_proba(X_test)

Supports: XGBoost, LightGBM, sklearn Random Forests, any Treelite-compatible model.

This is especially valuable when you have a model already trained on CPU and want to speed up inference without retraining.


Multi-GPU with Dask

For datasets too large for a single GPU or when you want to use multiple GPUs.

from dask.distributed import Client
from dask_cuda import LocalCUDACluster

# One Dask worker per GPU
cluster = LocalCUDACluster(
    rmm_pool_size="12GB",
    enable_cudf_spill=True,
)
client = Client(cluster)

# Create distributed data
from cuml.dask.datasets import make_blobs
X, y = make_blobs(
    n_samples=1_000_000,
    n_features=20,
    centers=5,
    n_parts=len(client.scheduler_info()['workers']) * 2,  # 2 partitions per worker
)

# Use