253 lines
15 KiB
Plaintext
253 lines
15 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "EMMJtIPXknKr"
|
|
},
|
|
"source": [
|
|
"# GPU TreeExplainer Tests\n",
|
|
"\n",
|
|
"This notebook runs the GPU TreeExplainer test suite on Google Colab.\n",
|
|
"\n",
|
|
"**Requirements:** Select a GPU runtime before running:\n",
|
|
"- Go to **Runtime > Change runtime type > T4 GPU**"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "k4Y-UQH_knKt"
|
|
},
|
|
"source": [
|
|
"## 1. Verify GPU availability"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "BfUaPMpUknKu",
|
|
"outputId": "6b269fdf-ba81-4d61-a502-dc9aa506c1ee"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stdout",
|
|
"text": [
|
|
"Thu Feb 19 19:44:50 2026 \n",
|
|
"+-----------------------------------------------------------------------------------------+\n",
|
|
"| NVIDIA-SMI 580.82.07 Driver Version: 580.82.07 CUDA Version: 13.0 |\n",
|
|
"+-----------------------------------------+------------------------+----------------------+\n",
|
|
"| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |\n",
|
|
"| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |\n",
|
|
"| | | MIG M. |\n",
|
|
"|=========================================+========================+======================|\n",
|
|
"| 0 Tesla T4 Off | 00000000:00:04.0 Off | 0 |\n",
|
|
"| N/A 39C P8 15W / 70W | 0MiB / 15360MiB | 0% Default |\n",
|
|
"| | | N/A |\n",
|
|
"+-----------------------------------------+------------------------+----------------------+\n",
|
|
"\n",
|
|
"+-----------------------------------------------------------------------------------------+\n",
|
|
"| Processes: |\n",
|
|
"| GPU GI CI PID Type Process name GPU Memory |\n",
|
|
"| ID ID Usage |\n",
|
|
"|=========================================================================================|\n",
|
|
"| No running processes found |\n",
|
|
"+-----------------------------------------------------------------------------------------+\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"!nvidia-smi"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "IT52P6XCknKw"
|
|
},
|
|
"source": [
|
|
"## 2. Clone and install SHAP from source with CUDA support"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"source": [
|
|
"!git clone https://github.com/shap/shap.git"
|
|
],
|
|
"metadata": {
|
|
"id": "8vz1-tzJZVcg",
|
|
"outputId": "1e94d76c-9ba7-4d70-8b93-53ce997b5289",
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
}
|
|
},
|
|
"execution_count": 2,
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stdout",
|
|
"text": [
|
|
"fatal: destination path 'shap' already exists and is not an empty directory.\n"
|
|
]
|
|
}
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "J8phKJJnknKy",
|
|
"outputId": "f16e6294-f17d-45b4-8d79-f444c904b548"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stdout",
|
|
"text": [
|
|
" Installing build dependencies ... \u001b[?25l\u001b[?25hdone\n",
|
|
" Checking if build backend supports build_editable ... \u001b[?25l\u001b[?25hdone\n",
|
|
" Getting requirements to build editable ... \u001b[?25l\u001b[?25hdone\n",
|
|
" Preparing editable metadata (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n",
|
|
" Building editable for shap (pyproject.toml) ... \u001b[?25l\u001b[?25hdone\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"!cd shap && CUDA_PATH=/usr/local/cuda pip install -e \".[test-core]\" -q"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {
|
|
"id": "lfbrKaqRknKz"
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"!pip install xgboost==3.0.5 lightgbm -q"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {
|
|
"id": "xybTgkUPknK3"
|
|
},
|
|
"source": [
|
|
"## 3. Run GPU TreeExplainer tests"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {
|
|
"colab": {
|
|
"base_uri": "https://localhost:8080/"
|
|
},
|
|
"id": "1Jp71Z5HknK4",
|
|
"outputId": "12ad7bca-65b1-448b-ed65-12d705d9a75b"
|
|
},
|
|
"outputs": [
|
|
{
|
|
"output_type": "stream",
|
|
"name": "stdout",
|
|
"text": [
|
|
"\u001b[1m============================= test session starts ==============================\u001b[0m\n",
|
|
"platform linux -- Python 3.12.12, pytest-8.4.2, pluggy-1.6.0 -- /usr/bin/python3\n",
|
|
"cachedir: .pytest_cache\n",
|
|
"Matplotlib: 3.10.0\n",
|
|
"Freetype: 2.6.1\n",
|
|
"rootdir: /content/shap\n",
|
|
"configfile: pyproject.toml\n",
|
|
"plugins: mpl-0.18.0, cov-7.0.0, anyio-4.12.1, langsmith-0.7.3, typeguard-4.5.0\n",
|
|
"collected 37 items \u001b[0m\n",
|
|
"\n",
|
|
"tests/explainers/test_gpu_tree.py::test_front_page_xgboost \u001b[32mPASSED\u001b[0m\u001b[33m [ 2%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_xgboost_cat_unsupported \u001b[32mPASSED\u001b[0m\u001b[33m [ 5%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[interventional-xgboost.core.Booster] \u001b[32mPASSED\u001b[0m\u001b[33m [ 8%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[interventional-xgboost.sklearn.XGBRegressor] \u001b[32mPASSED\u001b[0m\u001b[33m [ 10%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[interventional-xgboost.sklearn.XGBClassifier0] \u001b[32mPASSED\u001b[0m\u001b[33m [ 13%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[interventional-xgboost.sklearn.XGBClassifier1] \u001b[32mPASSED\u001b[0m\u001b[33m [ 16%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[interventional-lightgbm.basic.Booster] \u001b[32mPASSED\u001b[0m\u001b[33m [ 18%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[interventional-lightgbm.sklearn.LGBMRegressor] \u001b[32mPASSED\u001b[0m\u001b[33m [ 21%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[interventional-lightgbm.sklearn.LGBMClassifier0] \u001b[32mPASSED\u001b[0m\u001b[33m [ 24%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[interventional-lightgbm.sklearn.LGBMClassifier1] \u001b[32mPASSED\u001b[0m\u001b[33m [ 27%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[interventional-sklearn.ensemble._forest.RandomForestClassifier0] \u001b[32mPASSED\u001b[0m\u001b[33m [ 29%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[interventional-sklearn.ensemble._forest.RandomForestRegressor] \u001b[32mPASSED\u001b[0m\u001b[33m [ 32%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[interventional-sklearn.ensemble._forest.RandomForestClassifier1] \u001b[32mPASSED\u001b[0m\u001b[33m [ 35%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[tree_path_dependent-xgboost.core.Booster] \u001b[32mPASSED\u001b[0m\u001b[33m [ 37%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[tree_path_dependent-xgboost.sklearn.XGBRegressor] \u001b[32mPASSED\u001b[0m\u001b[33m [ 40%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[tree_path_dependent-xgboost.sklearn.XGBClassifier0] \u001b[32mPASSED\u001b[0m\u001b[33m [ 43%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[tree_path_dependent-xgboost.sklearn.XGBClassifier1] \u001b[32mPASSED\u001b[0m\u001b[33m [ 45%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[tree_path_dependent-lightgbm.basic.Booster] \u001b[32mPASSED\u001b[0m\u001b[33m [ 48%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[tree_path_dependent-lightgbm.sklearn.LGBMRegressor] \u001b[32mPASSED\u001b[0m\u001b[33m [ 51%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[tree_path_dependent-lightgbm.sklearn.LGBMClassifier0] \u001b[32mPASSED\u001b[0m\u001b[33m [ 54%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[tree_path_dependent-lightgbm.sklearn.LGBMClassifier1] \u001b[32mPASSED\u001b[0m\u001b[33m [ 56%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[tree_path_dependent-sklearn.ensemble._forest.RandomForestClassifier0] \u001b[32mPASSED\u001b[0m\u001b[33m [ 59%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[tree_path_dependent-sklearn.ensemble._forest.RandomForestRegressor] \u001b[32mPASSED\u001b[0m\u001b[33m [ 62%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap[tree_path_dependent-sklearn.ensemble._forest.RandomForestClassifier1] \u001b[32mPASSED\u001b[0m\u001b[33m [ 64%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap_interactions[tree_path_dependent-xgboost.core.Booster] \u001b[32mPASSED\u001b[0m\u001b[33m [ 67%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap_interactions[tree_path_dependent-xgboost.sklearn.XGBRegressor] \u001b[32mPASSED\u001b[0m\u001b[33m [ 70%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap_interactions[tree_path_dependent-xgboost.sklearn.XGBClassifier0] \u001b[32mPASSED\u001b[0m\u001b[33m [ 72%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap_interactions[tree_path_dependent-xgboost.sklearn.XGBClassifier1] \u001b[32mPASSED\u001b[0m\u001b[33m [ 75%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap_interactions[tree_path_dependent-lightgbm.basic.Booster] \u001b[32mPASSED\u001b[0m\u001b[33m [ 78%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap_interactions[tree_path_dependent-lightgbm.sklearn.LGBMRegressor] \u001b[32mPASSED\u001b[0m\u001b[33m [ 81%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap_interactions[tree_path_dependent-lightgbm.sklearn.LGBMClassifier0] \u001b[32mPASSED\u001b[0m\u001b[33m [ 83%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap_interactions[tree_path_dependent-lightgbm.sklearn.LGBMClassifier1] \u001b[32mPASSED\u001b[0m\u001b[33m [ 86%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap_interactions[tree_path_dependent-sklearn.ensemble._forest.RandomForestClassifier0] \u001b[32mPASSED\u001b[0m\u001b[33m [ 89%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap_interactions[tree_path_dependent-sklearn.ensemble._forest.RandomForestRegressor] \u001b[32mPASSED\u001b[0m\u001b[33m [ 91%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_gpu_tree_explainer_shap_interactions[tree_path_dependent-sklearn.ensemble._forest.RandomForestClassifier1] \u001b[32mPASSED\u001b[0m\u001b[33m [ 94%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_lightgbm_categorical_split[False] \u001b[33mXFAIL\u001b[0m\u001b[33m [ 97%]\u001b[0m\n",
|
|
"tests/explainers/test_gpu_tree.py::test_lightgbm_categorical_split[True] \u001b[33mXFAIL\u001b[0m\u001b[33m [100%]\u001b[0m\n",
|
|
"\n",
|
|
"\u001b[33m=============================== warnings summary ===============================\u001b[0m\n",
|
|
"../../usr/local/lib/python3.12/dist-packages/sklearn/utils/validation.py:2739\n",
|
|
"../../usr/local/lib/python3.12/dist-packages/sklearn/utils/validation.py:2739\n",
|
|
" /usr/local/lib/python3.12/dist-packages/sklearn/utils/validation.py:2739: UserWarning: X does not have valid feature names, but LGBMRegressor was fitted with feature names\n",
|
|
" warnings.warn(\n",
|
|
"\n",
|
|
"../../usr/local/lib/python3.12/dist-packages/sklearn/utils/validation.py:2739\n",
|
|
"../../usr/local/lib/python3.12/dist-packages/sklearn/utils/validation.py:2739\n",
|
|
" /usr/local/lib/python3.12/dist-packages/sklearn/utils/validation.py:2739: UserWarning: X does not have valid feature names, but LGBMClassifier was fitted with feature names\n",
|
|
" warnings.warn(\n",
|
|
"\n",
|
|
"tests/explainers/test_gpu_tree.py::test_front_page_xgboost\n",
|
|
" /content/shap/tests/explainers/test_gpu_tree.py:42: FutureWarning: The NumPy global RNG was seeded by calling `np.random.seed`. In a future version this function will no longer use the global RNG. Pass `rng` explicitly to opt-in to the new behaviour and silence this warning.\n",
|
|
" shap.summary_plot(shap_values, X, show=False)\n",
|
|
"\n",
|
|
"-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html\n",
|
|
"\u001b[33m================== \u001b[32m35 passed\u001b[0m, \u001b[33m\u001b[1m2 xfailed\u001b[0m, \u001b[33m\u001b[1m5 warnings\u001b[0m\u001b[33m in 21.04s\u001b[0m\u001b[33m ==================\u001b[0m\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"!cd shap && python -m pytest tests/explainers/test_gpu_tree.py -v"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"accelerator": "GPU",
|
|
"colab": {
|
|
"gpuType": "T4",
|
|
"provenance": []
|
|
},
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"name": "python",
|
|
"version": "3.10.0"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 0
|
|
}
|