Skip to content

About

GPU-accelerated gradient boosting for Apple silicon with the XGBoost Python API

Resources

Contributing

Stars

16 stars

Watchers

1 watching

Forks

Repository files navigation

xgboost-metal

GPU-accelerated gradient boosting for Apple silicon, with the XGBoost Python API. The native C++20 and Metal backend runs model training, prediction, evaluation metrics, and feature contributions on the Apple GPU.

The package provides DMatrix, QuantileDMatrix, train, cv, and scikit-learn estimators through the xgboost import. The distribution name is xgboost-metal, but use import xgboost as xgb in Python; xgboost_metal is not an import name.

Origin

The initial prototype of xgboost-metal was generated by INT21's swarm.

Features

  • Histogram tree training for regression, classification, ranking, and survival analysis.
  • Numeric and categorical features, native GPU sparse (CSR/CSC/COO) matrices, missing values, row weights, and sampling.
  • Multioutput regression, quantile regression, tree dropout, and linear boosting.
  • Early stopping, callbacks, continued training, and feature contributions.
  • Zero-copy Apple unified-memory (MetalArray, PEP 3118, Arrow, DLPack) ingestion with zero required Python dependencies.
  • JSON and UBJSON model exchange with XGBoost.

See compatibility for supported workflows and limitations.

Requirements

Component Requirement
Hardware Apple silicon Mac
Operating system macOS 14 or later
Python 3.10 or later
Source build Xcode with the Metal compiler; CMake 3.24 or later
Python runtime Zero required dependencies (optional NumPy, pandas, PyArrow, SciPy, scikit-learn)

Metal is the execution backend. CPU and CUDA execution are not supported.

Installation

Releases are published as wheels on GitHub. The wheel includes the compiled Metal kernels, so it does not need Xcode. Install it into a separate virtual environment, because this distribution and upstream XGBoost provide the same xgboost package:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install "xgboost-metal[sklearn] @ https://github.com/tabulai/xgboost-metal/releases/download/v0.1.1/xgboost_metal-0.1.1-py3-none-macosx_14_0_arm64.whl"

The sklearn extra installs the dependencies for the example below; remove [sklearn] to install only the core Python API. Installing from PyPI with pip install xgboost-metal is deprecated. See the installation guide for source builds and wheel builds.

Quick start

Import xgboost, the same module name used by upstream XGBoost:

import xgboost as xgb
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split

X, y = make_classification(
    n_samples=10_000, n_features=32, n_informative=16, random_state=42
)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, stratify=y, random_state=42
)

model = xgb.XGBClassifier(
    device="metal",
    tree_method="hist",
    n_estimators=100,
    max_depth=6,
)
model.fit(X_train, y_train)
print(f"Accuracy: {model.score(X_test, y_test):.3f}")
model.save_model("model.ubj")

Metal is selected by default. The explicit device="metal" parameter makes the execution target clear in shared application code.

Benchmarks

Controlled regression: Metal GPU vs stock CPU

Measured November 12, 2026 on an M5 Ultra (80-core GPU, 36 CPU cores, 512 GiB), M4 Max (16 CPU cores, 128 GiB), and M1 Ultra (20 CPU cores, 128 GiB). The Metal libraries were built in Release mode on each machine from commit 69a31a0; CPU runs used the same OpenMP-enabled xgboost 3.4.1 wheel and OpenMP runtime. All used Python 3.13.11 and NumPy 2.5.4. CPU thread counts used the available cores: 36, 16, and 20, respectively.

Each synthetic reg:squarederror workload uses 100 rounds, 256 bins, eta=0.3, and seed 42. Inputs use NumPy's generator with seed 1337; the missing-value case replaces 15% of feature values with NaN. Times are medians of three fits in separate processes with CPU and GPU order alternated; matrix construction and prediction are excluded. Inputs, labels, and predictions were bitwise identical across all three machines and both backends within each workload. The final column is the ratio of median CPU time to median GPU time.

Workload Machine Metal GPU Stock CPU CPU / GPU time
Dense 100,000 × 32, depth 6 M5 Ultra 107.4 ms 785.5 ms 7.32×
M4 Max 121.2 ms 293.0 ms 2.42×
M1 Ultra 276.4 ms 784.6 ms 2.84×
Dense 262,144 × 64, depth 8 M5 Ultra 222.8 ms 1,227.8 ms 5.51×
M4 Max 332.0 ms 949.8 ms 2.86×
M1 Ultra 666.0 ms 2,440.6 ms 3.66×
15% missing, 100,000 × 32, depth 6 M5 Ultra 111.2 ms 804.6 ms 7.24×
M4 Max 127.0 ms 356.9 ms 2.81×
M1 Ultra 266.9 ms 973.9 ms 3.65×

These runs control the source, inputs, and model settings, but are not a pure hardware-only comparison: CPU thread counts, operating systems, and compilers differ. Metal validation was disabled; power, clocks, and background activity were not independently controlled. Three fits per setting do not establish confidence intervals. The M5 figures are from a repeat run, so they differ slightly from the earlier M5-only measurements. Training RMSE for the three workloads was 0.1234, 0.1055, and 0.7558, respectively.

The benchmark runner and reproduction instructions and original per-fit results are included in the repository.

Thread settings on M5 Ultra

Stock CPU XGBoost scaled poorly beyond 8–12 threads on these workloads. In a separate thread sweep, the fastest tested CPU settings were 4 threads for the smaller dense case (253.7 ms), 12 threads for the larger dense case (825.1 ms), and 8 threads for the missing-value case (327.1 ms). Compared with the GPU medians in the table, those exploratory CPU / GPU ratios are approximately 2.36×, 3.70×, and 2.94×. The 36-thread CPU figures above are therefore not tuned CPU baselines. These settings were selected on the same workloads and are starting points for measurement, not universal defaults.

For the Metal GPU, the existing default metal_split_threads=256 is supported by the measurements. On the smaller dense case, 256 split threads took 99.3 ms versus 151.1 ms with 32 threads, at nthread=1. The other two workloads selected the 256-thread compact kernel even when 32 were requested. CPU-side nthread values from 1 to 36 did not yield a consistently faster GPU fit; nthread=1 is a reasonable setting to test when limiting CPU-side parallelism. Five fits per configuration were measured in a separate sweep with a different warmup, so its absolute times should not be directly compared with the three-machine table. Across 315 thread and histogram grouping fits, models and predictions remained identical within each workload. No GPU defaults were changed; the histogram grouping measurements did not establish a reliable improvement over them.

M5 Ultra: MNIST and bandwidth

The M5 MNIST comparison used the same 36-thread stock CPU release and the Metal build described above, on macOS 27.2. System load and GPU frequency were not independently monitored.

For MNIST (float64, 60,000 training and 10,000 test images, 100 depth-6 classifier rounds), median fit time was 3.88 s on Metal and 15.15 s on CPU (3.91×). Metal achieved 98.00% accuracy and 0.06466 log loss; CPU achieved 97.84% and 0.06845. Their predictions agreed on 98.96% of test images. The fit times include the classifier's internal matrix construction but exclude CSV loading.

Median warmed predict time on the full MNIST test set was 3.22 ms on Metal and 5.73 ms on CPU, across 30 calls per backend. For float32 input, median fit times were 3.88 s and 15.21 s, respectively, with the same accuracy and prediction agreement. Separately, the GPU streaming-copy benchmark measured 535 GB/s median read-plus-write bandwidth for 256 MiB; this is a workload measurement, not a peak-bandwidth claim.

MNIST across Apple silicon machines

The table compares the same stated XGBClassifier settings (float64 pixels divided by 255, 100 rounds, depth 6, learning rate 0.3, tree_method="hist", and seed 42). CPU measurements use stock OpenMP-enabled XGBoost 3.4.1. Fit times exclude CSV loading.

Machine Metal GPU fit Stock CPU fit CPU / GPU time GPU accuracy CPU accuracy
M5 Ultra, 36 CPU threads 3.88 s 15.15 s 3.91× 98.00% 97.84%
M4 Max, 16 CPU threads 9.47 s 37.75 s 3.99× 98.00% 97.84%
M1 Ultra, 20 CPU threads 9.38 s 24.03 s 2.56× 97.95% 97.84%

These measurements are indicative rather than a controlled hardware-only comparison. Metal builds, operating systems, dates, and machine activity differ. The M1 used the xgboost-metal 0.1.0 wheel; the M5 used the newer source build. The M5 data was converted from standard MNIST IDX files; hashes of the older MNIST CSV files have not been verified against it. Other processes were active during the M1 measurements. Each M5 backend used three separate, alternating process trials. The MNIST benchmark script records timings, quality, package versions, and input hashes.

M4 Max benchmark details

The M4 results below were measured on an Apple M4 Max (16 CPU cores, 128 GB unified memory, Release build without Metal validation layers), comparing xgboost-metal on the Apple GPU against regular OpenMP-enabled xgboost 3.4.1 using all 16 CPU cores. Separate M1 Ultra MNIST measurements follow the M4 MNIST table.

MNIST 10-Class Classification (60,000 × 784 Train → 10,000 × 784 Test)

Configuration Metric xgboost-metal (GPU) xgboost 3.4.1 (16-Core CPU) Speedup / Delta
Default XGBClassifier (float64 X/255, 100 rounds = 1,000 trees, max_depth=6) Train (fit) 9.47 s 37.75 s 3.98× faster
Inference (predict) 7.29 ms 18.18 ms 2.50× faster
Inference (predict_proba) 7.16 ms 18.72 ms 2.61× faster
Test Accuracy / Log-Loss 98.00% / 0.0647 97.84% / 0.0685 +0.16% (98.96% agreement)
Native DMatrix + xgb.train (float32, 100 rounds = 1,000 trees, max_depth=6) DMatrix Train Ingest (188 MB) 12.40 ms 49.91 ms 4.03× faster
Pure xgb.train 9.41 s 31.71 s 3.37× faster
Pure Booster.predict(dtest) 2.16 ms 14.18 ms 6.56× faster
Test Accuracy / Log-Loss 98.00% / 0.0647 97.84% / 0.0685 +0.16%
Native Sparse CSR (19.1% nonzero pixels, 100 rounds = 1,000 trees, max_depth=6) Pure xgb.train (CSR) 6.13 s 20.45 s 3.33× faster
Pure Booster.predict(dtest_csr) 6.02 ms 40.22 ms 6.68× faster
Test Accuracy / Log-Loss 97.71% / 0.0735 97.60% / 0.0752 +0.11%
Tuned XGBClassifier (300 rounds = 3,000 trees, max_depth=5, subsample=0.66, colsample_bytree=0.53) Train (fit) 26.97 s 76.04 s 2.82× faster
Inference (predict_proba) 7.50 ms 34.21 ms 4.56× faster
Test Accuracy / Log-Loss 97.87% / 0.0654 97.75% / 0.0705 +0.12% (99.44% agreement)

MNIST on Mac Studio M1 Ultra

Measured on an Apple M1 Ultra Mac Studio (20 CPU cores, 128 GB unified memory, macOS 26.5.1) using the published xgboost-metal 0.1.0 wheel and the OpenMP-enabled xgboost 3.4.1 wheel with 20 CPU threads. Both use the same XGBClassifier settings: 100 rounds, max_depth=6, learning_rate=0.3, tree_method="hist", and random_state=42. The float64 input matches the type in the M4 default-classifier result; the float32 row repeats the earlier M1 comparison.

Input Metric xgboost-metal (GPU) xgboost 3.4.1 (20-thread CPU) Speedup / Delta
float64 X/255 Train (fit) 9.38 s 24.03 s 2.56× faster
Inference (predict) 6.70 ms 12.33 ms 1.84× faster
Inference (predict_proba) 6.33 ms 12.31 ms 1.94× faster
Test accuracy / log-loss 97.95% / 0.0642 97.84% / 0.0685 +0.11 percentage points
float32 X/255 Train (fit) 9.33 s 24.26 s 2.60× faster
Inference (predict) 5.14 ms 12.18 ms 2.37× faster
Inference (predict_proba) 4.91 ms 11.93 ms 2.43× faster
Test accuracy / log-loss 97.95% / 0.0642 97.84% / 0.0685 +0.11 percentage points

The M1 runs used the MNIST train.csv.gz and test.csv.gz files (60,000 training and 10,000 test images). Each backend was run in a separate process, alternating CPU and GPU; training times are medians of three fits and inference times are medians of 30 warmed calls per backend over the full test set. CSV loading is excluded from timings. Predictions agreed on 98.78% of test images for both input types. Other processes were active on the machine, so timings may vary with system load. The MNIST benchmark script records individual timings, predictions, package versions, and input hashes.

Core Training, Inference, Evaluation & Ingestion (xgboost-metal vs 16-Core CPU)

Workload xgboost-metal (GPU) xgboost 3.4.1 (16-Core CPU) Speedup vs CPU
Dense hist train (262,144 × 64, 100 rounds, max_depth=8) 264.1 ms 1,055.6 ms 4.00×
Dense hist train / predict (100,000 × 32, 100 rounds, max_depth=6) 164.5 ms / 1.72 ms 340.9 ms / 7.37 ms 2.07× / 4.28×
multi:softprob 5-class train (100,000 × 32, 50 rounds, max_depth=6) 226.7 ms 726.7 ms 3.21×
monotone_constraints hist train (100,000 × 32, 100 rounds, max_depth=6) 132.0 ms 256.4 ms 1.94×
colsample_bylevel/bynode=0.5 hist train (100,000 × 32, 100 rounds) 163.7 ms 291.6 ms 1.78×
subsample=0.7 hist train (100,000 × 32, 100 rounds, max_depth=6) 235.7 ms 354.4 ms 1.50×
Sparse CSR hist train (200,000 × 512, 2% nnz, 50 rounds, max_depth=6) 192.9 ms 752.1 ms 3.90×
Sparse CSR predict (200,000 × 512, 50 rounds) 2.78 ms 20.58 ms 7.41×
Dense TreeSHAP pred_contribs=True (65,536 × 32, 100 trees) 74.1 ms 1,153.4 ms 15.56×
Sparse CSR TreeSHAP pred_contribs=True (16,384 × 512, 50 trees) 20.1 ms 120.2 ms 5.99×
Weighted auc + aucpr evaluation (1,000,000 rows, GPU radix sort) 3.92 ms 81.74 ms 20.86×
5-Fold xgb.cv (100,000 × 32, 40 rounds, binary:logistic, logloss + auc) 1.27 s 1.95 s 1.53×
gblinear coord_descent (100,000 × 32, 100 rounds, cyclic / thrifty) 303.4 ms / 162.4 ms 928.9 ms / 361.7 ms 3.06× / 2.23×
DMatrix ingestion (100,000 × 32: dense f32 / Fortran / f64 / pyarrow.Table) 1.07 / 0.92 / 1.06 / 2.19 ms 3.35 / 3.40 / 3.51 / 4.70 ms 3.13× / 3.72× / 3.31× / 2.15×
Page-aligned zero-copy DMatrix ingestion (1,000,000 × 32, 128 MB) 7.66 ms 24.94 ms 3.25×

Compared with the previous xgboost-metal baseline (6cdb29d), GPU radix-sort auc+aucpr is 34×–158× faster, sparse CSR DMatrix ingestion is 30.7× faster with 1.84× faster training and 2.83× faster prediction, 5-fold xgb.cv is 5.34× faster, and constrained/sampled/multiclass GPU tree training is 2.05×–2.94× faster. See benchmarking for measurement methodology and reproduction commands.

Documentation

Guide Contents
Installation Environments, source builds, wheels, and troubleshooting
Usage Training, categorical data, ranking, survival, and model persistence
Compatibility API baseline, supported features, and current limits
Benchmarking Training and prediction measurements
Contributing Development builds, tests, and package verification

Support

Report reproducible issues through GitHub Issues. Include the macOS version, Apple chip, Python version, xgboost-metal version (python -m pip show xgboost-metal), and output of xgboost.build_info().

License

Licensed under the Apache License 2.0. The Python adapter and public C API include code from XGBoost. Additional dependencies and attributions are listed in third-party notices.

About

GPU-accelerated gradient boosting for Apple silicon with the XGBoost Python API

Resources

Contributing

Stars

16 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages