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.
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.
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.
Notebooks on the page, on live Riptorch kernels. Edit any cell, press Shift+Enter, or Run all.
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.
Apple M5 Pro CPU, PyTorch 2.15.0, November 23, 2026. Every Apple M5 result, with its conditions.
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.
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.
swap_cosine.py$ 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$ 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 fastertopk → similarity_topkWhat 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.
swap_topk.py$ 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$ 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 fasterWhat 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.
swap_int8_matmul.py$ 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]$ 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]Riptorch 0.4.0 is on PyPI. One command installs it, with nothing to compile.
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.
| Platform | Status | Notes |
|---|---|---|
| macOS on Apple silicon M1 to M5 | 0.4.0 | macOS 14 or later. The Metal 4 matrix kernels are used where macOS has them. |
| macOS on Intel | 0.4.0 | macOS 11 or later. CPU kernels for your processor (AVX2 or AVX-512). |
| Linux x86-64 | 0.4.0 | A 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 ARM64 | 0.4.0 | The same distributions on ARM64: AWS Graviton, Ampere and other ARMv8 servers. |
| Windows x64 | 0.4.0 | Windows 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.
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.
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.
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.
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.
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.
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.
Set these before import riptorch. You don't need any of them for normal use.
| Variable | What it does |
|---|---|
RIPTORCH_COMPAT=pytorch | Stock PyTorch's behaviour everywhere, the same as torch.set_compat("pytorch"). |
RIPTORCH_MATHS=rational | Exact rational maths for supported operations, the same as torch.set_maths("rational"). |
RIPTORCH_MATMUL=fp16 or bf16 | Mixed-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=0 | Never hands an op to stock PyTorch's kernel, even when it's faster and stock PyTorch is loaded. |
RIPTORCH_HYBRID=1 | Apple 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=cpu | Runs everything on the CPU, even when a GPU is available. |
RIPTORCH_LA_METHOD | For 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_OFF | For 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=1 | Raises 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. |
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.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 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.