RiptideRiptide
Download Riptide SDKInstall Riptorch
Menu
Riptorch 0.4.0

Your PyTorch code, unchanged.

Riptorch is a PyTorch-compatible library, written from scratch in Raya. Change one import and your program runs on it: the same API, with correct results by default.

# before import torch # after: nothing else changes import riptorch as torch

pip install riptorch installs Riptorch 0.4.0 from PyPI on macOS, Linux and Windows, for Python 3.10 to 3.14. Every install method.

Andromeda notebooks

Run Riptorch right here.

Notebooks on the page, on live Riptorch kernels. Edit any cell, press Shift+Enter, or Run all.

Andromedariptorch-first-steps
Live kernel

Headline results · Apple M5 Pro CPU

Where PyTorch's CPU is slow, Riptorch isn't.

Three results from the M5 Pro's CPU, each with the conditions it was measured under. They hold for that chip; other Macs give different numbers.

3,840×
float16 matrix multiply, 4096³
52 ms vs 201 s · Riptorch best of 5 (median 66.5 ms); PyTorch 2.15 at the faster of 6 and 18 threads. PyTorch's own float32 path takes 88.7 ms here, so code that already converts to float32 gains 1.7×.
844×
exact int8 → int32 matrix multiply, 4096³
29.9 ms vs 25,228 ms (torch._int_mm, 18 threads) · best of 2 · 0 wrong entries on both sides.
6.1×
exact vector search, 1 million documents, 16 questions
4.14 ms vs 25.33 ms · 256 numbers per document · Riptorch's exact int8 index (built once in 6 ms) vs PyTorch's normalize, multiply and top-k · median of 7.

Apple M5 Pro CPU, PyTorch 2.15.0, November 23, 2026. Every Apple M5 result, with its conditions.

Swap it in and check

Same answers as PyTorch, or better ones.

Three short scripts to paste and run. Each one runs the same work on stock PyTorch and on Riptorch in one process and prints both, so you can see the difference for yourself. Below each is exactly what it printed on two machines.

Install both first: pip install riptorch torch numpy. Import torch before riptorch to keep both loaded in one program. Times are the best of 7 runs, include reading the result back, and vary from run to run. Measured November 29, 2026.

Cosine similarity: one query against 100,000 vectors

What this shows: the same scores as stock PyTorch, to within 2×10−7 (float32 rounding), from the same line of code, in less time.

PyTorch
import torch
scores = torch.nn.functional.cosine_similarity( q, docs, dim=1)
Riptorch
import riptorch as torch scores = torch.nn.functional.cosine_similarity( q, docs, dim=1)
The script, both libraries in one run · swap_cosine.py
# Cosine similarity of one query against 100,000 vectors, on stock PyTorch and on Riptorch. # The function body is the same for both: only the module passed in as `torch` differs. # Needs: pip install torch numpy riptorch import time import numpy as np import torch # stock PyTorch import riptorch # import it after torch, so both stay loaded side by side def cosine(torch, q, docs): return torch.nn.functional.cosine_similarity(q, docs, dim=1).numpy() def best_of_7(lib, q, docs): q, docs = lib.from_numpy(q), lib.from_numpy(docs) times = [] for _ in range(7): t = time.perf_counter(); out = cosine(lib, q, docs); times.append(time.perf_counter() - t) return out, min(times) * 1e3 rng = np.random.default_rng(0) q = rng.standard_normal((1, 256), dtype=np.float32) docs = rng.standard_normal((100_000, 256), dtype=np.float32) a, ta = best_of_7(torch, q, docs) b, tb = best_of_7(riptorch, q, docs) np.set_printoptions(precision=6) print(f"PyTorch {a[:4]} {ta:6.2f} ms") print(f"Riptorch {b[:4]} {tb:6.2f} ms") print(f"max abs difference {np.abs(a - b).max():.1e}, Riptorch {ta / tb:.1f}x faster")
What it printed
MacBook Pro, Apple M1 Pro · PyTorch 2.15.0 on the CPU · Riptorch on its default device, the GPU
$ python swap_cosine.py
PyTorch  [-0.013118  0.098844  0.033685 -0.111846]    8.36 ms
Riptorch [-0.013118  0.098844  0.033685 -0.111846]    2.49 ms
max abs difference 1.9e-07, Riptorch 3.4x faster
Linux x86-64, AWS c7i.xlarge (4 vCPUs, Intel Xeon Platinum 8488C), Ubuntu 24.04 · PyTorch 2.15.0+cpu · Riptorch on the CPU
$ python swap_cosine.py
PyTorch  [-0.013118  0.098844  0.033685 -0.111846]   86.12 ms
Riptorch [-0.013118  0.098844  0.033685 -0.111846]   44.62 ms
max abs difference 1.9e-07, Riptorch 1.9x faster

Top 10 nearest neighbours: topk → similarity_topk

What this shows: the same ten rows in the same order, with the same scores, in one call instead of two. When rows tie, Riptorch returns them in index order every time; stock PyTorch doesn't promise an order for ties, and here it returns them shuffled.

PyTorch
import torch scores = torch.nn.functional.cosine_similarity( q.float(), docs.float(), dim=1) top = torch.topk(scores, 10)
Riptorch
import riptorch as torch # int8 rows scored exactly, ranked in one pass top = torch.similarity_topk( q, docs, 10, exact=True)
The script, both libraries in one run · swap_topk.py
# Top-10 nearest neighbours by cosine over 100,000 int8 embeddings. # Stock PyTorch: cosine_similarity, then topk. Riptorch: similarity_topk(..., exact=True), one call. # Needs: pip install torch numpy riptorch import time import numpy as np import torch # stock PyTorch import riptorch # import it after torch, so both stay loaded side by side def stock(q, docs): # docs: float32 copy of the int8 rows r = torch.topk(torch.nn.functional.cosine_similarity(q, docs, dim=1), 10) return r.indices.tolist(), r.values.numpy() def rip(q, docs): # docs: the int8 rows themselves r = riptorch.similarity_topk(q, docs, 10, exact=True) return r.indices.tolist()[0], r.values.numpy()[0] def best_of_7(f, q, docs): times = [] for _ in range(7): t = time.perf_counter(); out = f(q, docs); times.append(time.perf_counter() - t) return out, min(times) * 1e3 def compare(q, docs): (si, sv), ts = best_of_7(stock, torch.from_numpy(q).float(), torch.from_numpy(docs).float()) (ri, rv), tr = best_of_7(rip, riptorch.from_numpy(q), riptorch.from_numpy(docs)) print(f"PyTorch {si} {ts:5.2f} ms") print(f"Riptorch {ri} {tr:5.2f} ms") print(f"same rows: {sorted(si) == sorted(ri)}, same order: {si == ri}, " f"max abs difference in scores {np.abs(sv - rv).max():.1e}, Riptorch {ts / tr:.1f}x faster") rng = np.random.default_rng(0) docs = rng.integers(-127, 128, (100_000, 256), dtype=np.int8) q = rng.integers(-127, 128, (1, 256), dtype=np.int8) compare(q, docs) print("\nFour identical rows near the query: a four-way tie for first place.") print("Riptorch puts tied rows in index order; PyTorch's order for ties isn't specified.") near = np.clip(q[0].astype(np.int16) + rng.integers(-20, 21, 256), -127, 127).astype(np.int8) docs[[90_001, 512, 77_777, 3]] = near compare(q, docs)
What it printed
MacBook Pro, Apple M1 Pro · PyTorch 2.15.0 on the CPU · Riptorch on its default device, the GPU
$ python swap_topk.py
PyTorch  [75729, 77699, 49417, 10219, 19686, 58055, 23726, 36589, 84640, 75094]   8.08 ms
Riptorch [75729, 77699, 49417, 10219, 19686, 58055, 23726, 36589, 84640, 75094]   1.35 ms
same rows: True, same order: True, max abs difference in scores 3.0e-08, Riptorch 6.0x faster

Four identical rows near the query: a four-way tie for first place.
Riptorch puts tied rows in index order; PyTorch's order for ties isn't specified.
PyTorch  [512, 77777, 90001, 3, 75729, 77699, 49417, 10219, 19686, 58055]   7.62 ms
Riptorch [3, 512, 77777, 90001, 75729, 77699, 49417, 10219, 19686, 58055]   1.35 ms
same rows: True, same order: False, max abs difference in scores 1.2e-07, Riptorch 5.6x faster
Linux x86-64, AWS c7i.xlarge (4 vCPUs, Intel Xeon Platinum 8488C), Ubuntu 24.04 · PyTorch 2.15.0+cpu · Riptorch on the CPU
$ python swap_topk.py
PyTorch  [75729, 77699, 49417, 10219, 19686, 58055, 23726, 36589, 84640, 75094]  86.69 ms
Riptorch [75729, 77699, 49417, 10219, 19686, 58055, 23726, 36589, 84640, 75094]   3.25 ms
same rows: True, same order: True, max abs difference in scores 3.0e-08, Riptorch 26.7x faster

Four identical rows near the query: a four-way tie for first place.
Riptorch puts tied rows in index order; PyTorch's order for ties isn't specified.
PyTorch  [3, 77777, 90001, 512, 75729, 77699, 49417, 10219, 19686, 58055]  85.63 ms
Riptorch [3, 512, 77777, 90001, 75729, 77699, 49417, 10219, 19686, 58055]   3.11 ms
same rows: True, same order: False, max abs difference in scores 1.2e-07, Riptorch 27.5x faster

An int8 matrix multiply: where stock PyTorch is wrong

What this shows: the same line, a @ b, on int8 matrices. Stock PyTorch keeps the int8 type, so almost every sum wraps around with no error or warning. Riptorch returns int32 and every entry is exact. torch.set_compat("pytorch") switches back to stock behaviour.

PyTorch
import torch c = a @ b # int8, wraps around
Riptorch
import riptorch as torch c = a @ b # int32, exact
The script, both libraries in one run · swap_int8_matmul.py
# An int8 matrix multiply on stock PyTorch and on Riptorch, checked against the exact answer. # Needs: pip install torch numpy riptorch import numpy as np import torch # stock PyTorch import riptorch # import it after torch, so both stay loaded side by side rng = np.random.default_rng(0) a = rng.integers(-128, 128, (64, 256), dtype=np.int8) b = rng.integers(-128, 128, (256, 64), dtype=np.int8) exact = a.astype(np.int64) @ b.astype(np.int64) for name, lib in (("PyTorch ", torch), ("Riptorch", riptorch)): c = (lib.from_numpy(a) @ lib.from_numpy(b)).numpy() # the same line for both print(f"{name} {str(c.dtype):5} first row {c[0, :4]} wrong entries {(c != exact).sum()} of {c.size}") print(f"exact first row {exact[0, :4]}")
What it printed
MacBook Pro, Apple M1 Pro · PyTorch 2.15.0 on the CPU · Riptorch on its default device, the GPU
$ python swap_int8_matmul.py
PyTorch  int8   first row [ 43 101 -57 -38]  wrong entries 4095 of 4096
Riptorch int32  first row [ 53803  88933 -62521  57818]  wrong entries 0 of 4096
exact          first row [ 53803  88933 -62521  57818]
Linux x86-64, AWS c7i.xlarge (4 vCPUs, Intel Xeon Platinum 8488C), Ubuntu 24.04 · PyTorch 2.15.0+cpu · Riptorch on the CPU
$ python swap_int8_matmul.py
PyTorch  int8   first row [ 43 101 -57 -38]  wrong entries 4095 of 4096
Riptorch int32  first row [ 53803  88933 -62521  57818]  wrong entries 0 of 4096
exact          first row [ 53803  88933 -62521  57818]
Install and requirements

One install, no compiler. 0.4.0

Riptorch 0.4.0 is on PyPI. One command installs it, with nothing to compile.

  • Python 3.10 to 3.14. Works with Python from python.org, Homebrew, uv and venv. One wheel per platform covers every supported Python, so there's nothing to match.
  • No compiler needed. Nothing is compiled on your machine, so you don't need the Xcode command-line tools, Visual Studio or gcc.
  • Stock PyTorch is optional. Riptorch doesn't need it. Install PyTorch alongside only if you want to compare the two side by side.
# Riptorch 0.4.0, from PyPI python3 -m venv .venv source .venv/bin/activate pip install riptorch # or with uv uv pip install riptorch # optional, for comparisons pip install torch
Platform support

Where Riptorch runs.

Riptorch 0.4.0 has a wheel for each of these platforms. Each one was installed clean and checked on every Python from 3.10 to 3.14 before it was published.

PlatformStatusNotes
macOS on Apple silicon
M1 to M5
0.4.0macOS 14 or later. The Metal 4 matrix kernels are used where macOS has them.
macOS on Intel0.4.0macOS 11 or later. CPU kernels for your processor (AVX2 or AVX-512).
Linux x86-640.4.0A manylinux_2_28 wheel (glibc 2.28 or later): Ubuntu 20.04 and later, including 24.04, 26.04 LTS and 26.10; Debian 10 and later; Fedora; RHEL, Rocky and Alma 8 and later; Amazon Linux 2023. No extra libraries needed.
Linux ARM640.4.0The same distributions on ARM64: AWS Graviton, Ampere and other ARMv8 servers.
Windows x640.4.0Windows 10 and 11, and Windows Server 2025. The Microsoft runtime is built in, so there's nothing else to install. On Windows on ARM, use an x64 Python: it runs the x64 wheel through emulation.

There are no wheels for musl-based Linux (Alpine), glibc older than 2.28, 32-bit Python or an ARM64 Python on Windows.

Where it's fastest

Fastest on Apple silicon, today.

Riptorch is fastest, and exact, on Apple chips. On Linux and Windows it gives the same results, and uses PyTorch's own kernels where they're faster when stock torch is imported first.

Apple silicon

Our fastest kernels. The CPU's matrix unit (SME on M4 and M5, AMX on M1 to M3) and the GPU through Metal. torch.matrix_unit() tells you which matrix unit your Mac has.

Linux, Windows and Intel Macs

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. Its lead there is in exact integer matrix multiplies and similarity search; for the rest, import stock PyTorch first and the faster kernel is used.

GPUs

Apple GPUs through Metal. NVIDIA GPUs on Linux with pip install "riptorch[cuda]" (NVIDIA's own runtime wheels, as stock PyTorch uses), and AMD Instinct on Linux with riptorch[rocm]. Without a usable GPU, Riptorch runs on the CPU.

Virtual machines

A virtual machine without access to a GPU falls back to the CPU automatically. Nothing to configure.

PyTorch's own kernel where it's 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 matrix multiplies, the correct-by-default rows) and calls that record gradients stay on Riptorch. Without PyTorch, nothing changes; RIPTORCH_STOCK_PATH=0 turns it off.

Correct by default

Correct results first, and how to switch.

Where stock PyTorch gives a wrong answer (an int8 matrix multiply that silently wraps, for example), Riptorch gives the exact one. Every default that differs from stock is listed, with the measurement behind it, and you can switch back.

import riptorch as torch # defaults better than stock, measured torch.improvements() torch.improvements("index_add") # stock behaviour everywhere, and back torch.set_compat("pytorch") torch.set_compat("riptorch") # exact rational maths torch.set_maths("rational")

Environment variables

Set these before import riptorch. You don't need any of them for normal use.

VariableWhat it does
RIPTORCH_COMPAT=pytorchStock PyTorch's behaviour everywhere, the same as torch.set_compat("pytorch").
RIPTORCH_MATHS=rationalExact rational maths for supported operations, the same as torch.set_maths("rational").
RIPTORCH_MATMUL=fp16 or bf16Mixed-precision matrix multiplies: each multiply rounds its inputs to 16 bits and adds up in float32; weights, gradients and optimizer state stay float32. The default is fp32; exact uses the unfused reference paths. On the Apple GPU, fast and high are also available. Same as torch.set_matmul(...).
RIPTORCH_STOCK_PATH=0Never hands an op to stock PyTorch's kernel, even when it's faster and stock PyTorch is loaded.
RIPTORCH_HYBRID=1Apple silicon: splits a large float32, bfloat16 or float16 matrix multiply between the GPU and the CPU's matrix unit at the same time (the CPU takes the last 22% of rows by default). Not used for exact results, batches or a transposed first operand.
RIPTORCH_DEVICE=cpuRuns everything on the CPU, even when a GPU is available.
RIPTORCH_LA_METHODFor testing: how float32 linear algebra is computed. auto (default, a measured table), f64 (in float64, rounded once), mixed (float32 LU refined in float64) or f32 (stock-style float32). Float64 inputs always use float64.
RIPTORCH_CPU_OFFFor testing: CPU features to treat as absent, a comma-separated list such as sme,i8mm,bf16 or amx. Lets an M4 or M5 run the way an M1 would.
RIPTORCH_LOOPS_STRICT=1Raises an error, instead of one warning and a slower Python fallback, if Riptorch's compiled kernels for special functions (lgamma, the Bessel functions, cummax and others) can't load.
Checking your install

Four lines tell you what you've got.

import riptorch as torch print(torch.backend()) print(torch.matrix_unit()) print(len(torch.improvements())) print(torch.get_compat())
  • torch.backend() names the engine that runs large operations: the Metal GPU on a Mac with one, otherwise the CPU.
  • torch.matrix_unit() is "SME" on M4 and M5, "AMX" on M1 to M3, and "none" on other processors, which use the portable kernels.
  • torch.improvements() lists every default that differs from stock PyTorch, each with its measurement.
  • torch.get_compat() is "riptorch" unless you've switched to stock behaviour.
Known limitations in 0.4.0

What isn't there yet.

  • NVIDIA GPUs are supported on Linux only. On Windows, Riptorch runs on the CPU.
  • Outside integer matrix multiplies and search, the 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 to 25 microseconds in Python, more than stock's whole call on a tiny tensor.
  • Free-threaded Python builds (such as 3.14t) are untested. Use the standard build of Python.
  • A few rarely used corners aren't finished. Almost every public PyTorch name exists (1,977 of them behave exactly as in PyTorch; a few rare dtypes such as int1…int7 and complex32 are not there yet); a part that isn't implemented yet raises a clear NotImplementedError saying what's missing.
Riptorch 0.4.0

Install Riptorch.

Riptorch 0.4.0 is on PyPI for macOS (Apple silicon and Intel), Linux (x86-64 and ARM64) and Windows x64, for Python 3.10 to 3.14.

pip install riptorch, then import riptorch as torch.