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.
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
License & Related Projects
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| jax_sklearn-0.1.11.tar.gz | 6.9 MB | Without provenance | Details for jax_sklearn-0.1.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| jax_sklearn-0.1.11-cp313-cp313-macosx_26_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 26.0+ ARM64 | Details for jax_sklearn-0.1.11-cp313-cp313-macosx_26_0_arm64.whl |
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
|
Security for jax-sklearn 0.1.11
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.