cuML
Train XGBoost and a scikit-learn random forest on GPU against the same CPU run, and check the scores before you trust the speed-up.
Lab 1 built the account features. This lab trains a model on them. Two paths, both timed on the same split: XGBoost with device="cuda", and a scikit-learn random forest left unchanged under cuml.accel. The GPU is faster. The model is not bit-identical. Compare scores, not coefficients and not tree dumps.
The stack is the one in the overview: cuML from RAPIDS 26.10, Python 3.12, XGBoost 3.4, an A2 with 16 GB. Run it in the same rapidsai/notebooks:26.10-cuda13-py3.12 container or OpenShift job as the cuDF lab.
Prerequisites
pip install --extra-index-url=https://pypi.nvidia.com \
"cuml-cu13==26.10.*" "xgboost==3.4.*" scikit-learn
The notebooks image already has these. Confirm the import sees the card:
python -c "import xgboost, cuml; print(xgboost.__version__, cuml.__version__)"
nvidia-smi -L
You need a feature table with one row per account: spend, transactions, segment, and a review label. Lab 1's monthly frame is the source; aggregate it to accounts before training so the matrix is a few million rows, not the 32 million monthly rows. If you do not have that file yet, the script below builds a stand-in with a fixed seed so the CPU and GPU runs still share an input. Replace it with the real aggregate when you have one. Do not publish the stand-in score as a result about transactions.
One split, two devices
Save train_xgb.py. The label is a column in the file, not a rule computed after the split.
import time
import numpy as np
import pandas as pd
from sklearn.metrics import roc_auc_score
from sklearn.model_selection import train_test_split
import xgboost as xgb
rng = np.random.default_rng(0)
n = 2_000_000
df = pd.DataFrame({
"spend": rng.exponential(20_000, n),
"transactions": rng.integers(1, 400, n),
"segment": rng.integers(0, 4, n),
})
# A fixed label, not something to brag about. Swap this frame for Lab 1's aggregate.
df["review"] = ((df["spend"] > 40_000) & (df["transactions"] > 30)).astype(np.int32)
flip = rng.random(n) < 0.02
df.loc[flip, "review"] = 1 - df.loc[flip, "review"]
X = df[["spend", "transactions", "segment"]]
y = df["review"]
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=0)
def fit(device):
model = xgb.XGBClassifier(
n_estimators=100,
max_depth=6,
learning_rate=0.1,
tree_method="hist",
device=device,
random_state=0,
)
t = time.perf_counter()
model.fit(X_train, y_train)
elapsed = time.perf_counter() - t
auc = roc_auc_score(y_test, model.predict_proba(X_test)[:, 1])
return elapsed, auc, model
cpu_s, cpu_auc, _ = fit("cpu")
fit("cuda") # warm-up: the first GPU call compiles kernels
gpu_s, gpu_auc, gpu_model = fit("cuda")
print(f"cpu {cpu_s:.2f}s auc {cpu_auc:.4f}")
print(f"gpu {gpu_s:.2f}s auc {gpu_auc:.4f}")
gpu_model.save_model("high_spend.json")
tree_method="hist" with device="cuda" is the GPU trainer in XGBoost 3. device="cpu" is the comparison. Write down both lines. The AUCs should be close. If they diverge in the second decimal, look at the data (a cuDF index that was not reset, a column order that changed) before you look at the booster.
Passing a cuDF frame avoids a host copy on the GPU run. Build the aggregate in cuDF, then:
import cudf
X_train_gpu = cudf.from_pandas(X_train)
y_train_gpu = cudf.Series(y_train.to_numpy())
gpu_model.fit(X_train_gpu, y_train_gpu)
Use that form when the feature job already ran on the GPU. Keep the CPU run on pandas so you are not timing a transfer inside the CPU number.
The same forest, with and without the accelerator
cuml.accel does not wrap XGBoost. XGBoost has its own device parameter. The accelerator is for scikit-learn, UMAP and HDBSCAN. The script must import those libraries after the accelerator is loaded, which python -m cuml.accel does for you.
rf.py:
import time
import numpy as np
from sklearn.datasets import make_classification
from sklearn.ensemble import RandomForestClassifier
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import roc_auc_score
from sklearn.model_selection import train_test_split
X, y = make_classification(
n_samples=500_000, n_features=20, n_informative=8, random_state=0)
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.2, random_state=0)
def bench(name, model):
t = time.perf_counter()
model.fit(X_train, y_train)
auc = roc_auc_score(y_test, model.predict_proba(X_test)[:, 1])
print(f"{name:16} {time.perf_counter() - t:7.2f}s auc {auc:.4f}")
bench("forest", RandomForestClassifier(
n_estimators=100, max_depth=8, n_jobs=-1, random_state=0))
bench("logistic", LogisticRegression(max_iter=200))
python rf.py
python -m cuml.accel rf.py
In a notebook, %load_ext cuml.accel and then re-import the estimators. cuML's forest accepts n_jobs and ignores it; the GPU is the parallelism. The accelerator is tested with scikit-learn 1.6 to 1.9. Outside that range it warns. Heed the warning before you compare scores.
A large gap in AUC means the estimator fell back, or the implementation differs more than you can accept for this model. python -m cuml.accel --line-profile rf.py shows which fit ran on the GPU. Logistic regression and the forest are both in the supported list; an estimator that is not on that list stays on the CPU with no error.
A search that is too slow on one core
Eighty trees times a handful of depths is the kind of loop people leave overnight. On the GPU it is the same RandomizedSearchCV you already know. This example uses XGBoost's device, not cuml.accel:
from sklearn.model_selection import RandomizedSearchCV
search = RandomizedSearchCV(
xgb.XGBClassifier(tree_method="hist", device="cuda", random_state=0),
{"max_depth": [4, 6, 8], "learning_rate": [0.05, 0.1, 0.2],
"n_estimators": [50, 100]},
n_iter=6, cv=3, scoring="roc_auc", random_state=0, n_jobs=1)
search.fit(X_train, y_train)
print(search.best_params_, round(search.best_score_, 4))
n_jobs stays 1. The card is already the parallel part; several CUDA trainings in one process fight over the same memory. Time one search and keep best_params_ next to the model file.
Clusters, only if you need them
UMAP and HDBSCAN are supported by the same accelerator, inside umap-learn 0.5.7 to 0.5.12 and hdbscan 0.8.39 to 0.8.44. Outside those ranges, treat a GPU run as untested. Fit on a sample first. A few hundred thousand rows is enough to see whether the clusters mean anything; the full account table can wait until the plot looks right.
python -m cuml.accel clusters.py
import umap
import hdbscan
embedding = umap.UMAP(n_neighbors=15, min_dist=0.1, random_state=0).fit_transform(X_train[:200_000])
labels = hdbscan.HDBSCAN(min_cluster_size=50).fit_predict(embedding)
print("clusters", len(set(labels)) - (1 if -1 in labels else 0))
Save it and leave the GPU
mkdir -p models
python -c 'import json; json.dump(["spend","transactions","segment"], open("models/features.json","w"))'
mv high_spend.json models/
high_spend.json is the booster. features.json is the column order the scoring code has to repeat. Those two files are the hand-off to model serving. A NIM does not load this JSON. Serving is a small Python runtime with the same XGBoost version, which the OpenShift AI series covers. Copy the directory to the project bucket; do not bake it into the training image.
To run the training as a job rather than a workbench, reuse the Job from the cuDF lab. Change the command to python train_xgb.py and keep nvidia.com/gpu: 1.
What's next
The overview lists where this pattern lands: daily feature rebuilds with cuDF, then a booster retrained on the GPU. The Spark estate uses the plugin for the SQL, and XGBoost's Spark API when the training itself has to be distributed. One A2 is enough to prove the scores match. It is not the card you size a nightly 200-million-row training for.