Skip to main content

xgboost-webgpu

Universal, blazing-fast, and memory-efficient XGBoost (Gradient Boosted Decision Trees) library in Rust, powered by WebGPU (wgpu) compute acceleration.

Standard XGBoost only supports GPU acceleration via NVIDIA CUDA (device='cuda' or tree_method='gpu_hist'). xgboost-webgpu breaks this hardware lock-in, enabling hardware-accelerated model training and inference across any modern GPU:

  • AMD Radeon GPUs (via Vulkan on Linux / Windows)
  • Apple Silicon M1/M2/M3/M4 (via Metal on macOS / iOS)
  • Intel Arc & Integrated GPUs (via Vulkan / DirectX 12)
  • NVIDIA GPUs (via Vulkan / DirectX 12)
  • Web Browsers & WebAssembly (via native WebGPU WGSL)
  • Multi-threaded CPU Fallback (via Rayon)

📖 Documentation & Wiki: Full architectural guides, mathematical formulations, and API manuals are available on the Project Wiki or offline in docs/wiki/.


Why WebGPU Instead of WebGL or CUDA?

Feature CUDA (Standard XGBoost) WebGL 2.0 WebGPU (xgboost-webgpu)
Vendor Support NVIDIA Only Universal Universal (AMD, Apple, Intel, NVIDIA)
Compute Shaders Yes No (Graphics raster only) Yes (@compute, WGSL)
Memory Buffers Direct VRAM buffers Textures only (2D ping-pong) Storage Buffers (read_write)
Atomic Operations Yes No atomic arbitrary writes Yes (atomicAdd, workgroup atomics)
Headless / Server Yes Cumbersome / requires X11/EGL Native headless execution
Browser Deployment No Slow emulation Native WebGPU Wasm support

Complete Feature Matrix

1. Objectives & Loss Functions

  • Regression: reg:squarederror (squared error loss).
  • Binary Classification: binary:logistic with scale_pos_weight support.
  • Multi-Class Classification: multi:softprob (probabilities) and multi:softmax (hard labels).
  • Count & Deviance: count:poisson (Poisson regression for count data).
  • Dispersion Models: reg:gamma (Gamma deviance) and reg:tweedie (compound Poisson-Gamma).
  • Quantile Loss: reg:quantileerror (pinball loss for arbitrary conditional quantiles).
  • Ranking: rank:pairwise (LambdaMART-style pairwise ranking with query groups).

2. Data Formats & Preprocessing

  • Dense Data: Row-major dense buffers (DMatrix::from_dense).
  • Sparse CSR Format: Compressed Sparse Row matrices (DMatrix::from_csr).
  • Quantization: 256 discrete bins (u8) for 75% memory reduction and packed 4-bins-per-u32 GPU storage buffer reads.
  • Categorical Features: FeatureType::Categorical with dedicated category indexing.
  • Missing Value Handling: Automatic routing according to optimal split gain (default_left).

3. Tree Growth & Regularization

  • Growth Policies:
    • GrowPolicy::DepthWise: Level-by-level recursive growth.
    • GrowPolicy::LossGuide: Leaf-wise best-first growth (LightGBM style) up to max_leaves.
  • Regularization: $L_1$ (reg_alpha), $L_2$ (reg_lambda), gamma (min split loss), min_child_weight, and max_delta_step.
  • Subsampling:
    • subsample: Row subsampling (bagging) per round.
    • colsample_bytree: Feature subsampling per tree.
    • colsample_bylevel & colsample_bynode: Feature subsampling per level and per split node.
  • Constraints:
    • monotone_constraints: Enforces strict $+1$ (non-decreasing) or $-1$ (non-increasing) monotonic outputs.
    • interaction_constraints: Constrains allowed feature interaction groups.

4. Advanced Boosting & Training Controls

  • DART Booster (booster_type = BoosterType::DART): Dropouts meet Multiple Additive Regression Trees with drop rate, skip drop, and weight normalization.
  • Early Stopping: early_stopping_rounds monitors validation metrics and automatically stops training when progress plateaus.
  • Training Continuation: booster.train_continue(...) appends additional boosting rounds to an existing model.

5. Interpretability & Model Analysis

  • Feature Importance: Scores features by Weight (split frequency), Gain (average or total gain), and Cover (Hessian coverage).
  • Leaf Index Prediction: booster.predict_leaf(...) returns the exact leaf node IDs where samples terminate across all trees.
  • Tree SHAP (predict_contributions): Exact implementation of TreeSHAP (Lundberg & Lee) returning feature attributions satisfying additive efficiency: $$\sum_{j=0}^{M-1} \phi_{i, j} + \phi_{\text{bias}} = \hat{y}_i$$

6. Interoperability

  • XGBoost JSON Format: Direct export and import matching the official XGBoost JSON schema (to_xgboost_json, from_xgboost_json, save_model, load_model).

Quickstart

Add xgboost-webgpu to your Cargo.toml:

[dependencies]
xgboost-webgpu = "0.1.0"

Multi-Class Classification with Advanced Features

use xgboost_webgpu::{BoosterParams, DeviceType, DMatrix, GrowPolicy, ImportanceType, train};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let x = vec![/* features: N x M */];
    let y = vec![/* labels: 0.0, 1.0, 2.0 */];

    let dtrain = DMatrix::from_dense(&x, 1000, 6, Some(&y), 256)?;

    let params = BoosterParams::new()
        .with_objective("multi:softprob")
        .with_num_class(3)
        .with_grow_policy(GrowPolicy::LossGuide)
        .with_max_leaves(16)
        .with_subsample(0.8)
        .with_colsample_bytree(0.8)
        .with_early_stopping(5)
        .with_device(DeviceType::WebGPU); // Accelerate on AMD, Apple, Intel, Nvidia

    let booster = train(params, &dtrain, 30, &[])?;

    // Feature Importance
    let importance = booster.feature_importance(ImportanceType::Gain);
    println!("Feature Importance: {:?}", importance);

    // TreeSHAP Feature Contributions
    let shap_values = booster.predict_contributions(&dtrain)?;
    println!("Sample 0 SHAP values: {:?}", shap_values[0]);

    // Save to official XGBoost JSON
    booster.save_model("model.json")?;

    Ok(())
}


Python Bindings & Scikit-Learn API

xgboost-webgpu includes high-performance Python bindings built with PyO3 and the Python Stable ABI (abi3). It provides drop-in Scikit-Learn estimators (XGBRegressor, XGBClassifier) and the core xgb.train() functional API with hardware acceleration.

Installation

# Build and install locally using pip
pip install .

# Or develop with maturin
maturin develop --release

Scikit-Learn API Example

import numpy as np
import xgboost_webgpu as xgb

# Generate sample data
X = np.random.randn(1000, 10).astype(np.float32)
y = (X[:, 0] + X[:, 1] > 0).astype(np.float32)

# Train with WebGPU acceleration
clf = xgb.XGBClassifier(
    n_estimators=50,
    max_depth=4,
    learning_rate=0.1,
    subsample=0.8,
    colsample_bytree=0.8,
    device="webgpu",  # Accelerate on AMD, Apple Silicon, Intel, or NVIDIA
)
clf.fit(X, y)

# Predictions & Probabilities
preds = clf.predict(X)
probs = clf.predict_proba(X)
print("Accuracy:", clf.score(X, y))

# Feature Importances & Exact TreeSHAP
print("Feature Importances:", clf.feature_importances_)
shap_values = clf.predict_contributions(X)
print("TreeSHAP shape:", np.array(shap_values).shape)

# Save and load model in XGBoost JSON format
clf.save_model("model.json")

Low-Level Functional API

import xgboost_webgpu as xgb

# Ingest data into quantized DMatrix
dtrain = xgb.DMatrix(X_train, labels=y_train)
deval = xgb.DMatrix(X_val, labels=y_val)

# Hyperparameters
params = {
    "objective": "multi:softprob",
    "num_class": 3,
    "max_depth": 5,
    "grow_policy": "lossguide",
    "max_leaves": 31,
    "early_stopping_rounds": 10,
    "eval_metric": "error",
    "device": "webgpu",
}

# Train Booster
bst = xgb.train(params, dtrain, num_boost_round=100, evals=[(deval, "val")])
preds = bst.predict(deval)

Running Benchmarks & Examples

# California Housing regression benchmark
cargo run --release --example california_housing

# Non-linear binary classification benchmark
cargo run --release --example binary_classification

# Multi-class, LossGuide, Subsampling, and TreeSHAP demonstration
cargo run --release --example advanced_features

# Automated tests (17 comprehensive tests)
cargo test

# Python test suite
python3 -m unittest python/tests/test_python_bindings.py

License

Licensed under the MIT License. See LICENSE for details.

Metadata

Release files for xgboost-webgpu 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xgboost-webgpu 0.1.0
File Size Uploaded Provenance Actions
xgboost_webgpu-0.1.0.tar.gz 73.5 kB Without provenance Details for xgboost_webgpu-0.1.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for xgboost-webgpu 0.1.0
File Actions
xgboost_webgpu-0.1.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for xgboost_webgpu-0.1.0-cp310-abi3-win_amd64.whl
xgboost_webgpu-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for xgboost_webgpu-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
xgboost_webgpu-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for xgboost_webgpu-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
xgboost_webgpu-0.1.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for xgboost_webgpu-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
xgboost_webgpu-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for xgboost_webgpu-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 13.4 MB

Release files / xgboost_webgpu-0.1.0.tar.gz

Download URL xgboost_webgpu-0.1.0.tar.gz
Size 73.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0ba787e5a5100ef1a6cd5da6dee98eb1e4dfd91ce373affe3bd171dfb4b5ada4
BLAKE2b-256 checksum
How to use checksums
00f5e278705b2056111527ca5c5f446fbfaaacb8aee01fcee94b5776dce7545a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / xgboost_webgpu-0.1.0-cp310-abi3-win_amd64.whl

Download URL xgboost_webgpu-0.1.0-cp310-abi3-win_amd64.whl
Size 2.8 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
41091635a6fbf3c13f807e665e58bc93e6dc3dd88f5e438a5bfcdf2c6075261f
BLAKE2b-256 checksum
How to use checksums
60e1564f4b8e8bdc8bb8b2331e7031677b279a61f0c23af1beb57ec15dddc144
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / xgboost_webgpu-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL xgboost_webgpu-0.1.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.9 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
d2963c8ad9ca8b28574ac2358a520e70db770b49ad5288555a490284326b23a1
BLAKE2b-256 checksum
How to use checksums
3e880728759760799e231eb785e82349e5643c8726b077ceeedcfbe6144f4160
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / xgboost_webgpu-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL xgboost_webgpu-0.1.0-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 3.0 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
cb47ee11f4be7f716d4ab2c87c0633a79f2deb9e38ca25b8133fde2842b4c334
BLAKE2b-256 checksum
How to use checksums
0648edb1e094521db8ba27e509d21aef979b21b9b2f8dbdf32e018a8af780923
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / xgboost_webgpu-0.1.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL xgboost_webgpu-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
Size 2.2 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
509193d87155a5ae22580cf7886183a8eb7dc8703edadf9c3115c61000d1ee2e
BLAKE2b-256 checksum
How to use checksums
7c89934d3ae1a4d68dbfea5b74ae3df72f3f58fa53edfc9784a0aa24d4fc1c8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / xgboost_webgpu-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL xgboost_webgpu-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 2.3 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
d07b520fa72a48b1150cdce8dffff1123f69f97db77c3ab999926f51f319ac78
BLAKE2b-256 checksum
How to use checksums
c29c95e689d1db17b03bf235f9e63a7b7f56c0e8b9858d77a83f6480713d262a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for xgboost-webgpu 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

6 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page