Skip to main content

Riptorch

A PyTorch-compatible library, compiled from Raya. Your PyTorch code runs unchanged.

import riptorch as torch          # or: from riptorch import torch

import riptorch also answers import torch when stock PyTorch isn't loaded yet, so import torch.nn as nn and libraries that import torch (transformers, diffusers) run on Riptorch without edits. To compare the two in one process, import stock PyTorch first:

import torch      # stock PyTorch
import riptorch   # then Riptorch; `torch` stays stock PyTorch

In the other order, a later import torch gives Riptorch. riptorch.is_torch_alias() says whether torch in this process is Riptorch.

Riptorch runs PyTorch-style code with correct results first. Where stock PyTorch gives wrong answers, Riptorch gives the exact ones by default.

Install

pip install riptorch          # or: uv pip install riptorch
  • Python 3.10 to 3.14. Works with Python from python.org, Homebrew, uv and venv. One wheel per platform covers every supported Python.
  • No compiler needed. Nothing is compiled on your machine: no Xcode command-line tools, Visual Studio or gcc.
  • Stock PyTorch is optional. Riptorch doesn't need it; install torch alongside only if you want side-by-side comparisons.

Platforms

platform wheel notes
macOS on Apple silicon (M1 to M5) macosx_14_0_arm64 macOS 14 or later; the Metal 4 matrix kernels are used where the OS has them
macOS on Intel macosx_11_0_x86_64 macOS 11 or later; CPU kernels for your processor (AVX2 / AVX-512)
Linux x86-64 manylinux_2_28_x86_64 glibc 2.28+: Ubuntu 20.04 and later (including 24.04, 26.04 LTS, 26.10), Debian 10+, Fedora, RHEL / Rocky / Alma 8+, Amazon Linux 2023; no extra libraries needed
Linux ARM64 manylinux_2_28_aarch64 the same distributions on ARM64: AWS Graviton, Ampere, and other ARMv8 servers
Windows x64 win_amd64 Windows 10 and 11, Windows Server 2025; the Microsoft runtime is built in. On Windows on ARM, use an x64 Python (it runs the x64 wheel through emulation)

Each release is installed clean and checked on every one of these platforms, for each Python from 3.10 to 3.14, before it is published. There are no wheels for musl-based Linux (Alpine), glibc older than 2.28, 32-bit Python or an ARM64 Python on Windows.

Where Riptorch is fastest

  • Apple silicon has the fastest kernels: the CPU's matrix unit (SME on M4 and M5, AMX on M1 to M3; torch.matrix_unit() says which) and the GPU through Metal.
  • Linux, Windows and Intel Macs run Riptorch's own native CPU kernels (AVX2 or AVX-512 picked for your processor; NEON on Linux ARM64), with the same results as on Apple silicon. Riptorch's speed lead there is in exact integer matrix multiplies and similarity search; for the rest, install stock PyTorch beside it and the faster kernel is used (below).
  • GPUs: Apple GPUs (Metal); NVIDIA GPUs on Linux with pip install "riptorch[cuda]" (NVIDIA's own runtime wheels, as stock PyTorch uses); AMD Instinct on Linux (riptorch[rocm]). Without a usable GPU, Riptorch runs on the CPU.
  • Virtual machines without GPU access fall back to the CPU automatically.
  • Riptorch uses PyTorch's own kernel where that is faster. With stock PyTorch installed and imported first (import torch, then import riptorch), each op and size where Riptorch measured slower runs on PyTorch's CPU kernel, sharing memory with no copy. Exact results (integer matmul, the correct-by-default rows) and calls that record gradients stay on Riptorch. Without PyTorch, nothing changes.

Check your install

import riptorch as torch

print(torch.backend())            # where big operations run: the Metal GPU, or the CPU
print(torch.matrix_unit())        # "SME" (M4, M5), "AMX" (M1 to M3) or "none"
print(len(torch.improvements()))  # defaults that are better than stock
print(torch.get_compat())         # "riptorch", or "pytorch" after set_compat("pytorch")

The whole public API is there

Every public name of PyTorch 2.15 exists in Riptorch: 1904 of 1904 across torch.* (872), tensor methods (604), torch.nn (169), torch.nn.functional (146), torch.linalg (44), torch.utils.data (29), torch.fft (23) and torch.optim (17), checked name by name against stock 2.15.0. Imports and attribute lookups never fail; the parts that are not implemented yet raise a clear NotImplementedError when you call them (see Status).

52 defaults that are better than stock

torch.improvements()            # every one, with the measurement behind it
torch.improvements("index_add") # one of them
help(torch.index_add)           # the docstring starts with "Better than PyTorch: ..."

52 functions behave better than stock PyTorch by default — exact instead of wrapped, correctly rounded instead of float32-rounded, deterministic instead of random-start, or defined where stock returns nan. Examples, each one measured: index_add sums repeated indices in float64 and rounds once ([1e8, 1, -1e8] at one index gives 1.0, stock gives 0.0); embedding_renorm_ left 21,374 of 160,000 values off in stock's float32 arithmetic; lobpcg returns the same exact eigenpairs on every call; Kumaraswamy.mode returns the mode instead of nan.

torch.set_compat("pytorch") (or RIPTORCH_COMPAT=pytorch before the import) gives stock's behaviour everywhere, exactly.

Exact where PyTorch is wrong

import riptorch as torch
a = torch.randint(-128, 128, (64, 64), dtype=torch.int8)
c = a @ a          # riptorch.int32, exact

Stock PyTorch keeps an integer matmul in the input dtype and wraps modulo 2^bits, with no error: in 200 random int8 @ int8 cases, 200 were wrong, and the same for int16 and int32. Riptorch returns:

  • exact int32 for int8 and uint8, including mixed signs, which stock PyTorch rejects
  • exact int64 for int16 and uint16
  • int64 for int32 and int64, exact whenever the result fits

Integer matrix multiplies, measured

4096 × 4096 × 4096, time for the whole call with the result read back, best of 6, on an Apple M5 Pro at 1-minute load 2.8–3.2 (November 24, 2026). Each library's fastest exact path: stock PyTorch's own integer matmul is wrong at this size, so its column is its fastest path that is not.

case stock PyTorch 2.15 Apple MLX 0.32.4 Riptorch
uint8 @ uint8 136 ms (MPS, int32 cast) 224 ms (CPU, float64) 3.7 ms
int8 @ uint8 136 ms (MPS, int32 cast) 228 ms (CPU, float64) 4.8 ms
int16 @ int16 260 ms (MPS, int64 cast) 219 ms (CPU, float64) 12.6 ms
uint16 @ uint16 260 ms (MPS, int64 cast) 220 ms (CPU, float64) 12.9 ms

int8 @ int8 is the one case stock has a kernel for (torch._int_mm on MPS). Measured alternating call by call in one process, 6 processes, 21 rounds each: Riptorch 2.37–2.42 ms best (median 2.84–3.01) against 3.16–3.35 ms best (median 3.69–3.91). Riptorch was faster in all 6 runs.

16-bit floats go on the same hardware: a 512 × 512 float16 matmul on the CPU measured 0.30 ms against stock's 74.7 ms (stock runs float16 and bfloat16 CPU matmuls 213–836× slower than its own float32).

Riptorch returned the exact integers in every case: 0 wrong entries. MLX has no integer matrix multiply at all; the times above are its float64 CPU fallback. Riptorch multiplies int8, uint8, int16, uint16, int32, int64, float16, bfloat16, float32 and float64 on the GPU's and the CPU's matrix hardware, and picks between them by size (torch.set_int_matmul("auto" | "gpu" | "cpu")).

Similarity search in one pass

riptorch.similarity_topk(queries, keys, k, metric="cosine" | "cross" | "spread" | "dot") (and the ordinary F.cosine_similarity(...).topk(k) composition, which runs the same fused search) scores and selects without ever building the score matrix. Top-10 of 1,000,000 stored 256-dim vectors, median of 7, M5 Pro, load 3.4–4.8 (November 23, 2026), against stock's best (topk(normalize(Q) @ Xn.T) with the keys normalized beforehand):

queries stock PyTorch (best of CPU / MPS) Riptorch Riptorch index
1 4.78 ms 4.33 ms 1.19 ms
16 16.04 ms 6.93 ms 4.00 ms
256 146.37 ms 82.43 ms 53.32 ms

Every row returned the reference top-k (float64 cosine, stably ranked) in the reference order.

Rational trigonometry, built in

Alongside the classic maths, Riptorch can compute geometry exactly, with quadrance and spread instead of transcendental functions, using N. J. Wildberger's rational trigonometry.

  • torch.cross_similarity(u, v) is the rational-trigonometry equivalent of cosine similarity: (u·v)² / (Q(u)·Q(v)), signed. It ranks results the same way as cosine similarity and is exact on integers.
  • torch.spread(u, v) is 1 − cross.
  • torch.set_maths("rational") switches supported operations to their rational forms.

Status

Riptorch 0.4.0. Unchanged PyTorch programs run on Riptorch and match stock PyTorch closely — measured on November 23, 2026 at no worse than 6.5e-6 relative on every step result, model output and parameter:

  • Hugging Face transformers: GPT-2, BERT, Llama (generation) and ViT
  • torchvision ResNet-18 and Faster R-CNN
  • a diffusers UNet
  • a GPT trained with AdamW, under a bfloat16 autocast too
  • MNIST MLP and CNN

That has been tested on small configurations, on the CPU and the Apple GPU.

Not tuned yet: outside matrix multiplication and search, many operations are slower than stock, and some rarely used ones are far slower. Measured step times (November 23, 2026): on Metal, Riptorch is 0.30–0.99× of stock MPS on gpt_min, ResNet-18, GPT-2, BERT, ViT, Llama and the diffusers UNet; on the CPU it is 0.92–2.27× of stock's time, slowest on ResNet-18 (48.3 ms against 22.0 ms).

Corners that are not finished raise a clear NotImplementedError saying what is missing — particular gradients (linalg.eig, householder_product, non-square lu_factor), unpivoted factorisations, the distributed batch-norm helpers, and similar. The normal paths of torch.fft, RNN/LSTM, MultiheadAttention and torch.utils.data.DataLoader all run.

Settings

Riptorch's defaults are correct first. torch.set_compat("pytorch") gives stock behaviour, torch.set_maths("rational") exact rational maths and torch.set_matmul(...) the matmul precision. Environment variables, set before import riptorch (none is needed for normal use):

variable what it does
RIPTORCH_COMPAT=pytorch stock PyTorch's behaviour everywhere (same as set_compat("pytorch"))
RIPTORCH_MATHS=rational exact rational maths for supported operations (same as set_maths("rational"))
RIPTORCH_MATMUL=fp16 / bf16 mixed-precision matmuls: 16-bit multiplies, float32 accumulation, float32 weights and optimizer state. Default fp32; exact for the unfused reference paths; fast and high on the Apple GPU
RIPTORCH_HYBRID=1 Apple silicon: splits a large float32 / bfloat16 / float16 matmul between the GPU and the CPU's matrix unit (not for exact results, batches or a transposed A)
RIPTORCH_DEVICE=cpu runs everything on the CPU
RIPTORCH_STOCK_PATH=0 never hands an op to stock PyTorch's kernel, even when it is faster and stock PyTorch is loaded
RIPTORCH_LA_METHOD testing: float32 linear algebra method, auto (default), f64, mixed or f32
RIPTORCH_CPU_OFF testing: CPU features to treat as absent, a comma list such as sme,i8mm,bf16 or amx
RIPTORCH_LOOPS_STRICT=1 an error, instead of a warning and a Python fallback, when the compiled special-function kernels can't load

Known limitations

  • NVIDIA GPUs are supported on Linux only; on Windows Riptorch runs on the CPU.
  • Outside integer matrix multiplies and search, Riptorch's own Linux, Windows and Intel Mac CPU kernels are often slower than stock; with stock PyTorch loaded, those ops run on its kernels. Apple silicon has the fastest kernels today.
  • Calls on small tensors are still slower than stock on Linux and Windows: each call costs about 15-25 microseconds in Python, more than stock's whole call on tiny tensors. This is being worked on.
  • Free-threaded Python builds (such as 3.14t) are untested.

Installation and platform notes: https://riptidecompute.com/riptorch

Licence: free to use, no redistribution, decompiling or reverse engineering. See LICENSE in the wheel.

Support Riptorch: tip from $3, support monthly, or sponsor as a company at https://riptidecompute.com/support

Contact: sam@s7vc.com

Metadata

Release files for riptorch 0.4.0

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

Source distribution (sdist)

Source distribution for riptorch 0.4.0
File Size Uploaded Provenance Actions
riptorch-0.4.0.tar.gz 7.9 kB Without provenance Details for riptorch-0.4.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for riptorch 0.4.0
File Actions
riptorch-0.4.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for riptorch-0.4.0-py3-none-win_amd64.whl
riptorch-0.4.0-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for riptorch-0.4.0-py3-none-manylinux_2_28_x86_64.whl
riptorch-0.4.0-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details for riptorch-0.4.0-py3-none-manylinux_2_28_aarch64.whl
riptorch-0.4.0-py3-none-macosx_14_0_arm64.whl Python 3 none macOS 14.0+ ARM64 Details for riptorch-0.4.0-py3-none-macosx_14_0_arm64.whl
riptorch-0.4.0-py3-none-macosx_11_0_x86_64.whl Python 3 none macOS 11.0+ x86-64 Details for riptorch-0.4.0-py3-none-macosx_11_0_x86_64.whl

Total release size: 37.1 MB

Release files / riptorch-0.4.0.tar.gz

Download URL riptorch-0.4.0.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ce6bd440c862f2ecbb7c1ca020013eefaee4f2486c4fca4db04ca7b02e5a3fc1
BLAKE2b-256 checksum
How to use checksums
6eed04886ee2db6a8dc4e89edc6861c85ace333d72735ccf76ba0f071dfa4180
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / riptorch-0.4.0-py3-none-win_amd64.whl

Download URL riptorch-0.4.0-py3-none-win_amd64.whl
Size 13.2 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
5c3a7988a79cfbe3af0b422be5ff950204014e6a9c705e6d50eb09b8def15542
BLAKE2b-256 checksum
How to use checksums
8cd2def9985dcf34eb806b563f279a9c1455e028b2f70db40a76d735bf079e8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / riptorch-0.4.0-py3-none-manylinux_2_28_x86_64.whl

Download URL riptorch-0.4.0-py3-none-manylinux_2_28_x86_64.whl
Size 6.7 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
1a50fa3553851520e510fa0353f74ead9a0b0c1561534c1b80498e2283b42f98
BLAKE2b-256 checksum
How to use checksums
f88d508896e33b1fd33b8c6d03f8160dfceef6d901d261fe37a6fd5ed995acfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / riptorch-0.4.0-py3-none-manylinux_2_28_aarch64.whl

Download URL riptorch-0.4.0-py3-none-manylinux_2_28_aarch64.whl
Size 5.4 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
6b66597e67e7212505f0c16e45710a6b94bb019dbc36d330f0e78928af2f35d8
BLAKE2b-256 checksum
How to use checksums
94326cac58c9bade7baedcf2f921b1945397c659d44e9aec41f3df9404216ce1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / riptorch-0.4.0-py3-none-macosx_14_0_arm64.whl

Download URL riptorch-0.4.0-py3-none-macosx_14_0_arm64.whl
Size 5.2 MB
Tags Python 3 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
c4199af736904d0cb32200a409b94873b9b1dab4ee371ae946d0ab75b060c3d2
BLAKE2b-256 checksum
How to use checksums
85f1bdaea2a18ff2cb5971014277058006ae850ff5e6c21eabbcc5a95befd18b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / riptorch-0.4.0-py3-none-macosx_11_0_x86_64.whl

Download URL riptorch-0.4.0-py3-none-macosx_11_0_x86_64.whl
Size 6.6 MB
Tags Python 3 macOS 11.0+ x86-64
SHA-256 checksum
How to use checksums
40c0c59715dceaa375375c0c311972b4c0e6b14c6749c54b19e27dfa0f419daf
BLAKE2b-256 checksum
How to use checksums
17bfae06e54c34a15a5995ab9fd58d91a850a944b2cb39486d822577bda7410d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Security for riptorch 0.4.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.

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.

Release history Release notifications | RSS feed

This release

0.4.0 This release

6 release files No provenance

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