Skip to main content

JAX-sklearn: JAX-Accelerated Machine Learning

JAX-sklearn is a drop-in replacement for scikit-learn that provides automatic JAX acceleration for machine learning algorithms while maintaining 100% API compatibility.

Python 3.10+ JAX License Version CI Tests


Key Features

  • Drop-in Replacement: Use import xlearn as sklearn — no code changes needed
  • JAX Acceleration: 4-20x speedup on CPU, 100x+ on GPU/TPU
  • Multi-Hardware: CPU, NVIDIA GPU (CUDA), Apple Silicon (Metal), Google TPU
  • Auto Fallback: Graceful degradation when JAX is unavailable
  • Prerequisite for Secret-Learn: Privacy-preserving federated ML with SecretFlow

Quick Install

# Apple Silicon (recommended)
uv pip install jax-sklearn[jax-metal]
# NVIDIA GPU
uv pip install jax-sklearn[jax-gpu]
# CPU only
uv pip install jax-sklearn[jax-cpu]

Or with pip:

pip install jax-sklearn

Build prerequisites: When installing from source (no wheel for your platform), you need C/C++ tooling and Python headers. See Troubleshooting below.


Quick Start

import xlearn as sklearn
from xlearn.linear_model import LinearRegression

model = LinearRegression()
model.fit(X, y)
predictions = model.predict(X_test)
# JAX acceleration applied automatically when beneficial

JAX acceleration can be configured via xlearn._jax:

import xlearn._jax as jax_config

# Default: always enable JAX (best for GPU/TPU)
jax_config.set_config(enable_jax=True)

# Threshold mode: only use JAX for large datasets (CPU users)
jax_config.set_config(enable_jax=True, jax_auto_threshold=True)

# Disable JAX (pure sklearn)
jax_config.set_config(enable_jax=False)

Performance

LinearRegression on Apple Silicon M2 (CPU)

Data Size XLearn sklearn Speedup
10K × 100 0.0097s 0.0113s 1.16x
10K × 1K 0.0384s 0.1590s 4.14x
10K × 10K 2.82s 55.96s 19.86x
50K × 2K 0.54s 1.96s 3.60x
100K × 1K 0.40s 1.23s 3.04x

JAX has ~0.2s JIT compilation overhead on first run. Crossover point is ~10K × 100 on CPU.

Hardware Scaling

Hardware Small Data Medium Data Large Data
CPU ~1x 0.2-0.5x 4-20x
Metal (M1-M4) ~1x 1.5-2x 2-3x
CUDA GPU 1-2x 5-10x 50-100x
TPU 2-5x 10-20x 100x+

Supported Algorithms

JAX-Accelerated

  • Linear Models: LinearRegression, Ridge, Lasso, ElasticNet
  • Clustering: KMeans
  • Decomposition: PCA, TruncatedSVD
  • Preprocessing: StandardScaler, MinMaxScaler

All other scikit-learn algorithms (RandomForest, SVM, Neural Networks, etc.) are fully available via automatic fallback to the original implementation.


Requirements

  • Python: 3.10+
  • JAX: 0.4.20+
  • NumPy: 1.22.0+, SciPy: 1.8.0+

Hardware-specific: NVIDIA GPU (CUDA 11.1+), Apple Silicon (macOS 12+), or Google TPU.


Troubleshooting

Build Issues

# Install Python headers (Linux)
sudo apt-get install python3-dev   # Debian/Ubuntu
sudo dnf install python3-devel     # RHEL/Fedora

# macOS
xcode-select --install

# Disable build isolation if needed
pip install --no-build-isolation jax-sklearn

JAX Not Found / GPU Not Detected

import jax
print("Devices:", jax.devices())
print("Backend:", jax.default_backend())

Contributing

git clone https://github.com/chenxingqiang/jax-sklearn.git
cd jax-sklearn
pip install -e ".[tests]"
pytest xlearn/tests/ -v

JAX-sklearn is BSD 3-Clause licensed.

  • Secret-Learn: Privacy-preserving federated ML with SecretFlow (348 algorithm implementations)

Metadata

Release files for jax-sklearn 0.1.11

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

Source distribution (sdist)

Source distribution for jax-sklearn 0.1.11
File Size Uploaded
jax_sklearn-0.1.11.tar.gz 6.9 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for jax-sklearn 0.1.11
File Interpreter ABI Platform
jax_sklearn-0.1.11-cp313-cp313-macosx_26_0_arm64.whl CPython 3.13 CPython 3.13 macOS 26.0+ ARM64 Details

Total release size: 15.5 MB

Release files / jax_sklearn-0.1.11.tar.gz

Download URL jax_sklearn-0.1.11.tar.gz
Size 6.9 MB
Tags Source
SHA-256 checksum
How to use checksums
6a04e4ca8643f602b308c35e8dd8c38f454cecea2fe0e2d87807a649c0c52bff
BLAKE2b-256 checksum
How to use checksums
e5e08657e4e5fd3c209b76554c96dcb1bc77af3d43b800d00d0430b5daf489a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release files / jax_sklearn-0.1.11-cp313-cp313-macosx_26_0_arm64.whl

Download URL jax_sklearn-0.1.11-cp313-cp313-macosx_26_0_arm64.whl
Size 8.6 MB
Tags CPython 3.13 macOS 26.0+ ARM64
SHA-256 checksum
How to use checksums
cfdacaf10c6a085730cef0190b5f310df81f4fa29e6a97fd2d200e9bd02df7e5
BLAKE2b-256 checksum
How to use checksums
de1069fe1d51b903beb435f4707d46fcddb3afd18de34aab57aec4f60269e763
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

0.1.11 This release

2 release files

0.1.10

2 release files

0.1.9

2 release files

0.1.8

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

1 release file

0.1.1

1 release file

0.1.0

2 release files

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