Skip to main content

Raxis

Raxis is a from-scratch re-implementation of the core of PyTorch, the ATen tensor library and the autograd engine, in C++20 with Python bindings. It is distilled from the PyTorch source: it keeps the techniques that make ATen fast (TensorIterator, vectorized kernels with runtime CPU dispatch, BLAS/MKL) without the breadth and indirection that make the original hard to read.

The goal is a codebase that someone curious about how PyTorch works inside can read end to end, while running at PyTorch speed on CPU.

Status: alpha. CPU only. Tensors with views and broadcasting, type promotion, elementwise ops, reductions, matmul, autograd, and an nn/optim package with enough to train MLPs, CNNs (Conv1d/2d, pooling, BatchNorm) and a small GPT (Embedding, LayerNorm, GELU, scaled dot product attention). CUDA is next.

Install

pip install raxis

Wheels for Windows and Linux (x86-64), Python 3.10 to 3.14. Raxis has no runtime dependencies; numpy is optional (.numpy(), raxis.from_numpy).

import raxis
from raxis import nn, optim

model = nn.Sequential(nn.Linear(784, 128), nn.ReLU(), nn.Linear(128, 10))
optimizer = optim.SGD(model.parameters(), lr=0.01, momentum=0.9)

x, y = raxis.randn((64, 784)), raxis.randint(0, 10, (64,))
loss = nn.functional.cross_entropy(model(x), y)
optimizer.zero_grad()
loss.backward()
optimizer.step()

The API follows PyTorch's, so most code only needs torch replaced by raxis.

raxis.autograd.graph exports the autograd graph of a tensor as Graphviz DOT or Mermaid text, as autograd nodes (view="backward") or as forward ops (view="forward"):

from raxis.autograd import graph

print(graph.to_mermaid(loss, dict(model.named_parameters()), view="forward"))
graph.render(loss, "loss.svg")  # needs pip install 'raxis[viz]' and Graphviz

Performance

Measured on a Ryzen 7 9700X (Zen 5, 8 cores, AVX512) with Windows 11, 8 threads, PyTorch 2.14.1 and Intel MKL in both libraries. The scripts and notebooks to reproduce them are in the repo (see Build from source).

Training the examples. Time of trainer.fit in each notebook (training plus the validation pass of every epoch) with Raxis, PyTorch and the two earlier projects of the same author: synapx (autograd in C++ on top of libtorch) and synapgrad (autograd in pure Python on top of NumPy).

Notebook Raxis PyTorch synapx synapgrad Params Train set Batch Epochs
basic_mlp.ipynb 0.20 s 1.4 s 0.53 s 0.26 s 337 150 4 50
mnist_mlp.ipynb 2.9 s 4.5 s 5.6 s 10.0 s 178,110 48,000 64 10
mnist_cnn.ipynb 10.8 s 37.8 s - 4 min 55 s 20,538 48,000 128 5

The models reach the same accuracy with every library (MNIST: ~97.6% val with the MLP, ~98.6% with the CNN). Most of PyTorch's time in the CNN is Dropout: its CPU random numbers come from a serial mt19937, Raxis draws them from Philox in parallel. synapx has no Conv2d.

nanoGPT. nanoGPT's character-level Shakespeare model, trained with examples/nanogpt/train.py (nanoGPT's model.py with only the imports changed):

Config Raxis step PyTorch step Raxis val loss PyTorch val loss
nanoGPT README's CPU run: 4 layers, n_embd 128, block 64, batch 12, 2000 iters 13.2 ms 14.2 ms 1.9065 1.9121
train_shakespeare_char.py: 6 layers, n_embd 384, block 256, batch 64, dropout 0.2 2.61 s 4.00 s 1.4553 1.4680

Median time of a training step (forward, backward, gradient clipping and AdamW). The full config would take ~5.1 h with Raxis and ~7.2 h with PyTorch on this CPU for its 5000 iterations, but the val loss stops improving around iteration 2000 and the model overfits afterwards, so both were stopped early: the table has the best val loss up to iteration 2000 (1750 for Raxis, 2000 for PyTorch), against 1.4697 in nanoGPT's README. Random numbers differ between the libraries, so the losses do too.

Ops. A selection of scripts/bench_ops.py (float32, forward only unless noted). Over its 388 cases the median ratio Raxis/PyTorch is 0.85x; the only case beyond 2x is the large 3x3 convolution, where PyTorch uses oneDNN's direct convolution and Raxis im2col plus an MKL gemm.

Op Shape Raxis (ms) PyTorch (ms)
add 1000 x 1000 0.017 0.017
exp 1000 x 1000 0.123 0.130
sum(dim=1) 1000 x 1000 0.010 0.018
mm 512 x 512 @ 512 x 512 0.459 0.464
softmax 16384 x 384 0.872 0.885
layer_norm 16384 x 384 0.726 1.182
gelu 16384 x 384 0.814 0.800
sdpa (causal) 64 x 6 x 256 x 64 13.98 15.23
sort 1000 x 1000 5.98 11.03
x[idx] backward 1000 x 1000 0.050 0.317
normal_ 1000 x 1000 0.548 3.111
dropout 1000 x 1000 0.123 6.880
conv2d 3x3, 32 -> 64 ch 64 x 32 x 26 x 26 2.98 1.49
conv2d 3x3, 64 -> 64 ch 64 x 64 x 32 x 32 8.94 4.32

Inside

Path What it holds
libraxis/raxis/tensor TensorImpl and storage, views and strides, type promotion, TensorIterator
libraxis/raxis/ops Operators and their CPU kernels, compiled once per ISA (AVX2, AVX512, NEON) and picked at runtime
libraxis/raxis/autograd Graph, engine and backward functions
libraxis/bindings pybind11 module raxis._C
raxis/ Python package: nn, optim, autograd.graph, tensor printing

Code taken from PyTorch keeps a // From: aten/src/ATen/... comment pointing to the original.

Build from source

Requirements: a C++20 compiler (MSVC 17+, GCC 12+, Clang 14+), CMake 3.22+ and uv.

git clone --recursive https://github.com/pgmesa/raxis.git
cd raxis
uv sync --extra dev --extra cpu        # or --extra cu130 for CUDA PyTorch
uv run python scripts/build_libraxis.py
uv run pytest tests

uv sync installs the pinned build and test dependencies from uv.lock, including Intel MKL from PyPI and PyTorch, the reference the tests compare against. build_libraxis.py builds libraxis with CMake and installs it into the raxis/ package. To work on the C++ side, libraxis/CMakePresets.json has debug and release presets; CMakeLists.txt lists the build options (RAXIS_USE_*).

scripts/bench_ops.py benchmarks each op against PyTorch and NumPy, scripts/bench_training.py times a training step of the example models, and examples/ has notebooks that train MLPs on two moons and MNIST and a CNN on MNIST with either Raxis or PyTorch, and examples/nanogpt trains nanoGPT's character-level Shakespeare model, with its model.py unchanged except for the imports, and samples from it. raxis.save and raxis.load use PyTorch's checkpoint format, so a model trained with one library can be sampled with the other.

License

MIT. Raxis includes code derived from PyTorch (BSD-3-Clause) and links SLEEF, mimalloc and Intel MKL: see THIRD_PARTY_NOTICES.txt.

Metadata

Release files for raxis 0.2.0

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 raxis 0.2.0
File Actions
raxis-0.2.0-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for raxis-0.2.0-cp314-cp314-win_amd64.whl
raxis-0.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details for raxis-0.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
raxis-0.2.0-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for raxis-0.2.0-cp313-cp313-win_amd64.whl
raxis-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for raxis-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
raxis-0.2.0-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for raxis-0.2.0-cp312-cp312-win_amd64.whl
raxis-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for raxis-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
raxis-0.2.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for raxis-0.2.0-cp311-cp311-win_amd64.whl
raxis-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for raxis-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
raxis-0.2.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for raxis-0.2.0-cp310-cp310-win_amd64.whl
raxis-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details for raxis-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Total release size: 89.4 MB

Release files / raxis-0.2.0-cp314-cp314-win_amd64.whl

Download URL raxis-0.2.0-cp314-cp314-win_amd64.whl
Size 7.9 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
a66719a4023fd1aa7fc5fc370cbd5660b2351f76efb6616de28051ab0a2edaef
BLAKE2b-256 checksum
How to use checksums
18677f6e0ce565eaeb12abf30b78982d429affea14cab5cd63471ecd2ed8af5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 26, 2026.

Transparency log

Release files / raxis-0.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL raxis-0.2.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 10.1 MB
Tags CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
1caf3cf769097ac68f87aa87cafb85c67dc9e4d0805dd6be3a4629a083470cf4
BLAKE2b-256 checksum
How to use checksums
1d98e2e42a66916882aebf56e17cd09248323cd4fd03d2ca3f9ddf72d7bf47d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 26, 2026.

Transparency log

Release files / raxis-0.2.0-cp313-cp313-win_amd64.whl

Download URL raxis-0.2.0-cp313-cp313-win_amd64.whl
Size 7.7 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
5cbbdd69b72baf8595b8321490c06dd99e93c02dfac8e7f30282940a0767743a
BLAKE2b-256 checksum
How to use checksums
32b5e539f5ef490fa1d99ece50a40f256e4821e8aa96f4a836da8516199ed86a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 26, 2026.

Transparency log

Release files / raxis-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL raxis-0.2.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 10.1 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
7c17e64f47bac3a790373c687cee8067869c048be4b2fff8678a31ca75fdf78f
BLAKE2b-256 checksum
How to use checksums
40ba3f76dc5dec8237df8d3c2e75b90fdc438c1b88233a75b2746f6df14da4d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 26, 2026.

Transparency log

Release files / raxis-0.2.0-cp312-cp312-win_amd64.whl

Download URL raxis-0.2.0-cp312-cp312-win_amd64.whl
Size 7.7 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
57f35e96215dba690b438d9b235d35603387d9a12c3a4f189be0209ad8bac06e
BLAKE2b-256 checksum
How to use checksums
82950f231a8b9fe83b2fc833e8aba0cbc0679dab996a73b0948f633d97698b38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 26, 2026.

Transparency log

Release files / raxis-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL raxis-0.2.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 10.1 MB
Tags CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
6d70bbd4317f43c97115d78e1e8ea282df91ce160622caf5f507f2dfb45a5c73
BLAKE2b-256 checksum
How to use checksums
05f0c155bd8b59cdfff8332de010486ef66f360138dba027859ab3bab7895e29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 26, 2026.

Transparency log

Release files / raxis-0.2.0-cp311-cp311-win_amd64.whl

Download URL raxis-0.2.0-cp311-cp311-win_amd64.whl
Size 7.7 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
ae4bd9e0c738876f13f26567943a7c2370452c4a5093fdb6755ef98c26c226b5
BLAKE2b-256 checksum
How to use checksums
dd010ab62db7b66137dd8a4839759c73f5ae9dfb6c68f8b4d86fae6ad7c796c8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 26, 2026.

Transparency log

Release files / raxis-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL raxis-0.2.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 10.1 MB
Tags CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
a6e59cdda089a4300fc80219d1d65a1eb4259cfb6c5f53ba85b4edc41be67161
BLAKE2b-256 checksum
How to use checksums
0341c579d88640e0aa4c8ca979662c542c2fb0d5c377e305933f105d9841e4ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 26, 2026.

Transparency log

Release files / raxis-0.2.0-cp310-cp310-win_amd64.whl

Download URL raxis-0.2.0-cp310-cp310-win_amd64.whl
Size 7.7 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
da0ad34a5347f0f840c3beba79f29f8a172dd1045f6ccd2556c7b1e85d93ba62
BLAKE2b-256 checksum
How to use checksums
dbc87d8cb3db870b74521fa74973d837f4a990333ad7fcf16064ce2560584e3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 26, 2026.

Transparency log

Release files / raxis-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL raxis-0.2.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 10.1 MB
Tags CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
79528b39ca3c40208a4855e1f7b2664703a232acb0bb79cd250b1e04b5fa27d9
BLAKE2b-256 checksum
How to use checksums
115743f2e20d380eaaae123867d61557f0f8216f72992cb7668b72b7c433cefb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 26, 2026.

Transparency log

Security for raxis 0.2.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.

Full provenance

All 10 files in this release have been uploaded with provenance metadata.

Select from 10 files

Attestation for raxis-0.2.0-cp314-cp314-win_amd64.whl

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 26, 2026.

Transparency log

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.

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