Skip to main content

mojolearn

PyPI DOI

Bitwise-identical machine learning across Apple, NVIDIA and AMD GPUs.

The same machine-learning workload can produce different bits on different GPUs, changing predictions, learned models and subsequent training updates. mojolearn is a GPU machine-learning library whose default mode is identical. In identical mode, mojolearn returns the same bits on Apple, NVIDIA and AMD GPUs. Its x86-64 Linux and Apple silicon CPU bindings give the same bits too. Results agree bit for bit, not merely within a numerical tolerance.

  • Training and inference for transformers and hybrids. Decoder language models, Mamba-1/2/3 state-space models and Samba attention/state-space hybrids train and serve under the same contract, alongside recurrent networks.
  • 100+ machine-learning algorithms and model components across 12 families, from neural networks to tree ensembles and classical models.
  • Serve models trained elsewhere. Neural models trained in other frameworks can be served with identical outputs across vendors.
  • Move training between vendors. A training run can be handed off from one GPU vendor to another mid-run, or shared by Apple, NVIDIA and AMD GPUs working on one model at once, and the training state after every step is bitwise identical to a single GPU's.
  • A language model trained twice, the same bits. The training experiment on mojolearn.org.
  • Full FP32. Neural training and inference run in full FP32 floating-point arithmetic, without reducing the computation to integers.
  • Every algorithm runs on the Mac's own GPU, where XGBoost, LightGBM, CatBoost and cuML have no supported GPU path.

To the author's knowledge, mojolearn is the first system to enable these capabilities.

One Mojo codebase implements these algorithms across Metal, CUDA and HIP under a shared numerical contract. Mojo compiles code for different GPUs, but maintaining that contract and implementing the algorithms is original work.

Why it matters

A model may serve predictions on NVIDIA GPUs, run locally on an Apple laptop and later be evaluated on an AMD server. With identical weights and inputs, different GPUs normally return different output bits, so hardware becomes another variable in serving, regression testing and auditing. In a tree learner one rounding difference can change the winning split and every node beneath it. In a training loop it perturbs a gradient, then the optimizer state, then every step after that.

mojolearn removes hardware from that list. A team can test a deployed model on different hardware, replay a recorded decision during an audit, replace serving hardware without numerical change, and resume a checkpoint on another vendor's GPU on the same trajectory as uninterrupted training.

How it works

Floating-point addition is not associative, and GPU vendors differ in reduction order, fused multiply-add contraction, denormal handling, square root, tie-breaking and elementary functions. Recompiling does not fix any of that. mojolearn's numerical contract fixes the operations that determine model bits, including reduction order, rounding and elementary functions, and leaves tiling, thread layout, memory placement and kernel scheduling free, so each backend can be tuned for its own hardware without changing a bit. The kernels are mojolearn's own, written in Mojo, and replace vendor math routines wherever their results would depend on the backend.

Algorithms

The table shows representative methods, with related estimator variants grouped together.

family algorithms and components
neural blocks and optimizers transformers, Mamba-1/2/3, Samba, MLPs, RNNs, LSTMs, GRUs, mixture of experts, Adam, AdamW, SGD, RMSprop, Adagrad, Lion
language models and tokenization decoder language models, byte-level BPE tokenization
boosting symmetric-tree, depth-wise, loss-guided and ordered boosting; AdaBoost, DART
trees and ensembles decision trees, random forests, Extra Trees, isolation forests, bagging, voting, stacking
clustering k-means, mini-batch and bisecting k-means, DBSCAN, HDBSCAN, agglomerative, spectral, mean shift, OPTICS, affinity propagation, Gaussian and Bayesian Gaussian mixtures
neighbors, density and search nearest neighbors, k-NN, radius neighbors, kernel density, local outlier factor, label propagation, IVF-Flat, IVF-PQ, CAGRA
linear models least squares, ridge, lasso, elastic net, logistic regression, SGD, Huber, Poisson, Gamma, Tweedie, Bayesian ridge, ARD, Lars, quantile and isotonic regression
kernel methods and Gaussian processes SVMs, kernel ridge, Gaussian process regression and classification, sparse variational GP, Nystroem, random Fourier and chi-square features
decomposition and manifold PCA, incremental and kernel PCA, truncated SVD, NMF, ICA, factor analysis, PLS, CCA, dictionary learning, sparse PCA, LDA, UMAP, t-SNE, Isomap, MDS, LLE
time series ARIMA, AutoARIMA, Holt-Winters, ETS, STL, VAR, Theta, Croston, GARCH, Prophet-style forecasting, KPSS
preprocessing, probabilistic models and resampling scalers, encoders, imputers, discretization, feature selection, naive Bayes, discriminant analysis, bootstrap, permutation tests, Monte Carlo integration
linear algebra matrix products, Cholesky, QR, LU, eigendecomposition, SVD, least squares

Also provided are evaluation metrics, cross-validation, CPU training and inference, Hugging Face checkpoint loading and decoding, BF16 and INT8 weight storage, tokenized corpora and a built-in verifier.

Numeric modes

identical is the default. fast is available on Apple GPUs only, as an opt-in for most families. SUPPORT_MATRIX.md has the table by family.

mode contract
identical The default. In identical mode, mojolearn returns the same bits on Apple, NVIDIA and AMD GPUs.
fast Apple GPUs only: throughput, with no repeatability promise.

The identical contract is across hardware within one release. mojolearn is alpha: a release may change identical output bits (a faster or more accurate route), provided the new bits agree on every supported vendor and the CPU. Compare runs made with the same release.

Select a mode per estimator with numeric_mode=, per process with mojolearn.set_numeric_mode(...), or before import with MOJOLEARN_NUMERIC_MODE. A configuration that cannot meet its mode's contract raises a named error rather than silently returning something weaker.

Install

pip install mojolearn   # Mac: Apple GPU; Linux: NVIDIA or AMD GPU, or CPU

macOS arm64 wheels include Apple Metal support. On Linux x86-64, pip install mojolearn automatically installs the mojolearn-nvidia and mojolearn-amd GPU packages and selects the backend for the GPU it finds. Both platforms also support CPU training and inference.

This release ships native NVIDIA kernels for the sm_89 architecture (Ada: L40S, L40, L4, RTX 4090) and AMD kernels for gfx942 (MI300X, MI325X). A PTX build for every NVIDIA GPU with compute capability 8.0 or newer (A100, H100/H200, Blackwell, ...) is built and recorded in the reference table, but not shipped while the NVIDIA wheel with it exceeds PyPI's 100 MiB limit; other architectures need a source build. See NVIDIA PTX.

mojolearn never substitutes the CPU for a GPU it cannot serve.

mojolearn doctor

reports what the installed wheel supports on this machine.

Verification combines inference and classical training in one routine scope. Neural training is a separate opt-in:

python -m mojolearn verify                    # every applicable routine lane, base fixture
python -m mojolearn verify --quick            # representative routine checks
python -m mojolearn verify --all              # entire routine scope, all nine fixtures
python -m mojolearn verify --neural-training  # neural training/backward/optimizer checks

Routine checks include bundled reference hashes, saved-model inference, and, on a GPU installation, direct GPU/CPU inference comparisons. Neural training is excluded from default, quick and all; combine --neural-training --all to exercise its complete fixture set. Reports name excluded and missing checks.

The advanced --cross-check quick|default|all option runs only direct GPU/CPU comparisons. Its default scope retains the 24-lane diagnostic sample; all has no lane cap and runs every eligible lane on every fixture using sequential child processes. Bare verify uses all eligible cross-check lanes on the base fixture, without that diagnostic sample cap.

Quick start

import numpy as np
import mojolearn

rng = np.random.default_rng(0)
X = rng.random((100_000, 20), dtype=np.float32)
y = (X[:, 0] + X[:, 1] > 1.0).astype(np.float32)

model = mojolearn.GradientBoosting(loss="Logloss", n_estimators=200, max_depth=6)
model.fit(X, y)
print(model.predict_proba(X[:5]))
print(model.numeric_mode_used(), mojolearn.vendor())

In identical mode, mojolearn returns the same bits on Apple, NVIDIA and AMD GPUs. Run the same script on any of them and the model and its predictions are the same bits.

Verify it yourself

The wheel ships the reference results recorded on Apple, NVIDIA, AMD and CPU, and a verifier that checks your machine against them.

Install verification support with python -m pip install "mojolearn[verify]": the same library plus its optional verification dependency. Optional ANN and sequence APIs that use NumPy are supported by mojolearn[numpy]; the verification extra includes that same dependency. The base install does not require NumPy. See verification support.

python -m mojolearn verify          # inference and classical training, base fixture
python -m mojolearn verify --quick  # representative checks from the same scope
python -m mojolearn verify --all    # the same scope on all nine fixtures

--all also includes applicable gradient, batch-size, ragged-batch and sampler/replay checks. --quick keeps its smaller scope.

Each part reports its comparison with the recorded references; missing references read OWED and inapplicable properties are named explicitly. docs/VERIFY.md describes the verifier and docs/VERIFY_EXTERNALLY.md shows how to check the claims from outside the project.

Scope

The guarantee holds for the same code revision, numerical profile, input bytes, hyperparameters and seed, in identical mode, on configurations the verification record covers. It is an FP32 guarantee. Weights trained in another framework reproduce under mojolearn's arithmetic, not that framework's. SUPPORT_MATRIX.md lists the verified devices and configurations.

Runtime rule

No Python compute in the runtime, ever. The Python package is only the API surface (argument checks, routing, calls into compiled Mojo); every computed value comes from Mojo, on the GPU for GPU paths.

Benchmark boards

These are the canonical pages. Update them in place; don't start new ones.

  • Full-dataset A/B experiment board: NVIDIA/AMD IDENTICAL and Apple FAST attempts, recorded toggles, A/B times, quality metrics and decisions. Failed attempts and unrun experiments remain visible; combined measurements do not qualify individual switches.
  • Apple M3 Ultra board: every lane, with our FAST and IDENTICAL arms next to the opponents. The IDENTICAL cells come from the 2026-10-04 sweep (tools/af_board_ident_update.py); FAST and opponent cells come from the 0.8.34 board.
  • Apple FAST refresh: FAST before and after for each lane against the best opponent (tools/af_board_merge.py).
  • Apple IDENTICAL refresh: the same view for IDENTICAL (tools/af_board_merge.py --mode identical).
  • Board protocol and older boards.

Documentation

Trademarks and affiliation

mojolearn is an independent project by Andrew Hendel, licensed under Apache-2.0. It is not affiliated with, sponsored by, or endorsed by Modular, Inc. MAX® and Mojo® are trademarks of Modular, Inc. Binary wheels include unmodified Modular runtime components redistributed under Modular's own license; see NOTICE.

Citation

To cite mojolearn, use CITATION.cff. The concept DOI is 10.5281/zenodo.22068632.

Metadata

Release files for mojolearn 0.8.51

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

Built distributions (wheels)

Table of built distributions (wheels) for mojolearn 0.8.51
File Interpreter ABI Platform
mojolearn-0.8.51-py3-none-manylinux_2_35_x86_64.whl Python 3 none Linux glibc 2.35+ x86-64 Details
mojolearn-0.8.51-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details

Total release size: 114.9 MB

Release files / mojolearn-0.8.51-py3-none-manylinux_2_35_x86_64.whl

Download URL mojolearn-0.8.51-py3-none-manylinux_2_35_x86_64.whl
Size 14.9 MB
Tags Linux glibc 2.35+ x86-64 Python 3
SHA-256 checksum
How to use checksums
225f6bc294af26f450c2bf517cf32748591f65cb373f2ea89cf207ccfb23ee15
BLAKE2b-256 checksum
How to use checksums
80af2f8790f426df5d1368c583bbab7c747c30ffac8e1596cebc6eec72408a91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release files / mojolearn-0.8.51-py3-none-macosx_11_0_arm64.whl

Download URL mojolearn-0.8.51-py3-none-macosx_11_0_arm64.whl
Size 100.0 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7bc1fe155b64d26dd763b2c85e5fce7e8db2cffd763c44960972540eb5855fb9
BLAKE2b-256 checksum
How to use checksums
1f320fb562d2193b0903eb6452565c12a30ab55a86be5fcbc94bc2261988ff07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.8.51 This release

2 release files

0.8.50

2 release files

0.8.49

2 release files

0.8.48

2 release files

0.8.46

2 release files

0.8.45

2 release files

0.8.44

2 release files

0.8.43

2 release files

0.8.42

2 release files

0.8.41

2 release files

0.8.40

1 release file

0.8.39

1 release file

0.8.38

1 release file

0.8.37

1 release file

0.8.31

2 release files

0.8.30

2 release files

0.8.29

2 release files

0.8.28

2 release files

0.8.27

2 release files

0.8.26

2 release files

0.8.25

2 release files

0.8.24

2 release files

0.8.23

1 release file

0.8.22

2 release files

0.8.21

1 release file

0.8.20

2 release files

0.8.19

2 release files

0.8.18

2 release files

0.8.17

2 release files

0.8.16

2 release files

0.8.15

2 release files

0.8.14

2 release files

0.8.13

2 release files

0.8.12

2 release files

0.8.11

2 release files

0.8.10

2 release files

0.8.9

2 release files

0.8.8

2 release files

0.8.7

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

1 release file

0.3.1

2 release files

0.3.0

2 release files

0.2.0

1 release file

0.1.0

1 release file

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