RadixMLP Python Bindings
Python bindings for the RadixMLP algorithm, enabling prefix-based computation sharing for transformer models.
Installation
Development Installation
# Using uv (recommended)
uv pip install -e .
# Using pip
pip install -e .
Release Installation
pip install radix-mlp
Usage
import numpy as np
from radix_mlp import compute_fold_and_scatter
# Example: Two sequences with shared prefix
input_ids = np.array([1, 2, 3, 1, 2, 4], dtype=np.uint32)
position_ids = np.array([0, 1, 2, 0, 1, 2], dtype=np.uint32)
cu_seq_lengths = np.array([0, 3, 6], dtype=np.uint32)
compact_ids, compact_pos, scatter, fold = compute_fold_and_scatter(
input_ids, position_ids, cu_seq_lengths
)
print(f"Original tokens: {len(input_ids)}")
print(f"Compact tokens: {len(compact_ids)}")
print(f"Compression ratio: {len(compact_ids) / len(input_ids):.2%}")
PyTorch Interface
For PyTorch users, a convenient interface is available:
import torch
from radix_mlp import compute_fold_and_scatter_torch # only available if you installed torch in your environment
# Example: Two sequences with shared prefix
input_ids = torch.tensor([1, 2, 3, 1, 2, 4], dtype=torch.int32)
position_ids = torch.tensor([0, 1, 2, 0, 1, 2], dtype=torch.int32)
cu_seq_lengths = torch.tensor([0, 3, 6], dtype=torch.int32)
compact_ids, compact_pos, scatter, fold = compute_fold_and_scatter_torch(
input_ids, position_ids, cu_seq_lengths
)
print(f"Original tokens: {len(input_ids)}")
print(f"Compact tokens: {len(compact_ids)}")
print(f"Compression ratio: {len(compact_ids) / len(input_ids):.2%}")
# Works with GPU tensors too (via CPU)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
input_ids = input_ids.to(device)
API Reference
compute_fold_and_scatter
Computes indices for RadixMLP-style folding and scattering.
Parameters:
input_ids(np.ndarray[np.uint32]): Flattened token IDsposition_ids(np.ndarray[np.uint32]): Flattened position IDscu_seq_lengths(np.ndarray[np.uint32]): Cumulative sequence lengthspad_multiple_of(Optional[int]): IfSome(n), pad output to multiple ofnfor performance. IfNone, no padding (default: None)
Returns:
compact_input_ids: Unique token IDscompact_position_ids: Corresponding position IDsscatter_indices: Unfold indices (compact -> original)fold_gather: Gather indices (original -> compact)
Development
Building
# Development build
maturin develop
# Release build
maturin build --release
License
MIT License - Copyright (c) 2025 michaelfeil
Metadata
Release files for radix-mlp 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| radix_mlp-0.0.2.tar.gz | 23.3 kB | Details |
Built distributions (wheels)
Total release size: 8.3 MB
Release files / radix_mlp-0.0.2.tar.gz
| Download URL | radix_mlp-0.0.2.tar.gz |
|---|---|
| Size | 23.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fba2944eb1e25a2b223807a7e0e7c032ec1bd72d22aa02676be2fe98d52457ed
|
|
BLAKE2b-256 checksum How to use checksums |
c7710466411c5b884df82d6b211f48512d3af5e03352fbccbea6de61f714fd8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | radix_mlp-0.0.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 286.4 kB |
| Tags | Linux glibc 2.17+ x86-64 PyPy 3.11 PyPy 3.11 7.3 |
|
SHA-256 checksum How to use checksums |
5c71801bfca8f2227149fcabb8831587479600d601147f01d189c9450c166955
|
|
BLAKE2b-256 checksum How to use checksums |
62af12aa19ef2e5c64f3c7d4d1e07b8452aed02e827b780cff0797a5fc98e80f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl
| Download URL | radix_mlp-0.0.2-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl |
|---|---|
| Size | 297.4 kB |
| Tags | Linux glibc 2.5+ x86-32 PyPy 3.11 PyPy 3.11 7.3 |
|
SHA-256 checksum How to use checksums |
1add3c704f8f1ed27e24a3a7c4cb0435b0611c4531432b415c81fc2e824ecc18
|
|
BLAKE2b-256 checksum How to use checksums |
0c88ed1b3fd6f43a57ff1f584af39c428a103c92cb30972229da30ef6b6d9e6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_x86_64.whl
| Download URL | radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 482.5 kB |
| Tags | CPython 3.13 CPython 3.13 free-threading Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
fad1b2886c6bbc4bf7246023b0494cda647dcf601ac67fffc1a727ba5acb2916
|
|
BLAKE2b-256 checksum How to use checksums |
a478fd30ee55863afbc1af74e63c52e756cc1519c0c20f3b1321624be267cee4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_i686.whl
| Download URL | radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_i686.whl |
|---|---|
| Size | 513.6 kB |
| Tags | CPython 3.13 CPython 3.13 free-threading Linux musl 1.2+ x86-32 |
|
SHA-256 checksum How to use checksums |
a96c51905a73392911ba96180ccd41312d4a34747dc03771a52f8b6460d5db32
|
|
BLAKE2b-256 checksum How to use checksums |
47b1aa2a78c66db1ef4f0af2d07079a179253d0d15bcd6406652c83998b8eb5e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_armv7l.whl
| Download URL | radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 551.1 kB |
| Tags | CPython 3.13 CPython 3.13 free-threading Linux musl 1.2+ ARMv7l |
|
SHA-256 checksum How to use checksums |
af36cb19710e085966d024f862c5e9420007377fc180650285893dffd8f4330c
|
|
BLAKE2b-256 checksum How to use checksums |
504daaca1960eb21b44bfbcdc3c09bf9d16544f46c3ef3fcfb66d903ac437a85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_aarch64.whl
| Download URL | radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 453.6 kB |
| Tags | CPython 3.13 CPython 3.13 free-threading Linux musl 1.2+ ARM64 |
|
SHA-256 checksum How to use checksums |
4a0765d33b8e9b8b5a6b1f69ecdc4b5f5a0d6b91c3eb2068fbc5c8014dadbd3e
|
|
BLAKE2b-256 checksum How to use checksums |
707de983a5f720b617e73a36470350992d10f0a76badbadfc82c5d501895e86a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | radix_mlp-0.0.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 282.8 kB |
| Tags | CPython 3.13 CPython 3.13 free-threading Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
65c808fb3e65c60d50a83f88ffe995f6280fc1e83862aa95cadaec15ea8cf050
|
|
BLAKE2b-256 checksum How to use checksums |
61dfb59dbc4c198820a5dd102e67f9c3ffaea5aa3d24cc78298fb90ca21b7148
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | radix_mlp-0.0.2-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 406.1 kB |
| Tags | CPython 3.13 CPython 3.13 free-threading Linux glibc 2.17+ PowerPC 64-le |
|
SHA-256 checksum How to use checksums |
e45345ffac177356cb75b5c931e344f6ab5d8f123f39a71275640ec1efe89c48
|
|
BLAKE2b-256 checksum How to use checksums |
0517b8d272107d85cccd86d250bf99cdebb59d23501e058221cec3844c91c960
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.whl
| Download URL | radix_mlp-0.0.2-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.whl |
|---|---|
| Size | 293.8 kB |
| Tags | CPython 3.13 CPython 3.13 free-threading Linux glibc 2.5+ x86-32 |
|
SHA-256 checksum How to use checksums |
a0143b983ea7188e974a83321fd48acd159e27b01fff5e2b6f1016890ee88f9b
|
|
BLAKE2b-256 checksum How to use checksums |
7b8abfaa00686d0f30025767ab89a49667280acfdfa3f24e2ebd7e1c36a2719c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp313-cp313t-macosx_11_0_arm64.whl
| Download URL | radix_mlp-0.0.2-cp313-cp313t-macosx_11_0_arm64.whl |
|---|---|
| Size | 241.5 kB |
| Tags | CPython 3.13 CPython 3.13 free-threading macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ccf8ff94f7b8c43bb4a4dbf66457a4714b9af32c652c0722362e0a5936d665fc
|
|
BLAKE2b-256 checksum How to use checksums |
f887fa23c28ddca6e811534f4f28c9e12a68ff54ccccf7236f796f19135572f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp313-cp313t-macosx_10_12_x86_64.whl
| Download URL | radix_mlp-0.0.2-cp313-cp313t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 245.7 kB |
| Tags | CPython 3.13 CPython 3.13 free-threading macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
491f9da91e68245729935b51c0d1fbddb6fee6dcac6db054ec7f32d8ed283dc5
|
|
BLAKE2b-256 checksum How to use checksums |
e085ec34a707a72a58d3326114252ac221b68b8ad2d63a82fd5dd5ac25cdb8fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp310-abi3-win_amd64.whl
| Download URL | radix_mlp-0.0.2-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 134.7 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
5d977d64bb91580cec769b7b2379e90cb292454cf6de5ae0b1289aced7a5c48b
|
|
BLAKE2b-256 checksum How to use checksums |
cc44240d9b731907f46c9b408fe859d1f61dcf6e8a22e2bf4020911074653513
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 487.8 kB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f2df36c173b382cace8afd0abbd17bc97ac43da933c850891fc851366b97d763
|
|
BLAKE2b-256 checksum How to use checksums |
d31c6f20704d8f69d11bd93b04555e7332aa9729f05a72327bbf9be830e8be24
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_i686.whl
| Download URL | radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_i686.whl |
|---|---|
| Size | 520.6 kB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
e15ca41836c098dea60dda02a338b747b166326b9f4cc0b4c81e9ac0f731a1be
|
|
BLAKE2b-256 checksum How to use checksums |
12e3554ad6c0eb594da53071e7c1624d0e1a62523c48bdab8d01362fe7611b65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_armv7l.whl
| Download URL | radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 556.3 kB |
| Tags | CPython 3.10 Linux musl 1.2+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
58600243c176fab9ce2adddfbe4735ed5add8defb46cbffcc04c3e563d04090d
|
|
BLAKE2b-256 checksum How to use checksums |
133d7b6457f6abff0edaa5e689afb76d8f0dbba7e8ca5f28191f6b408f3d8204
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 460.0 kB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
f73f753369f024effa18f3cacccbfd09ea1bfeb6fdc9bcd671283d9e43b922a7
|
|
BLAKE2b-256 checksum How to use checksums |
8bcf1f22246a5993fc2a740a2b740ecc7c13f72ac4ea8211f7c291c602bf22e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp310-abi3-manylinux_2_28_armv7l.whl
| Download URL | radix_mlp-0.0.2-cp310-abi3-manylinux_2_28_armv7l.whl |
|---|---|
| Size | 286.7 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
e961c56508b200571a1ae21eca2ca7cea8173ddd458721c172d17cd83609e523
|
|
BLAKE2b-256 checksum How to use checksums |
9056a6688c7fb241e8a1ed97108c137e8d8a69709bfb92d385fa52142266fbf2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | radix_mlp-0.0.2-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 277.3 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
8305348d297c431fc6a99b78e112bc6319e81951506346fd4fdd51270d377c1b
|
|
BLAKE2b-256 checksum How to use checksums |
da73fa6fc552261ec47931cec2e468888f1fceee5878547c82785a05efb1a2a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | radix_mlp-0.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 289.6 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
0418b5adc84ed4875e1265b2a7452e54d64a201904589159e6ff0a470982363e
|
|
BLAKE2b-256 checksum How to use checksums |
5a1bd49fa4846769ae6ea2accea93f1af04f138af56aea9a0c18ea17f5a20d87
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | radix_mlp-0.0.2-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 408.6 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
bd79d7e5bef3e14616750573b0c518322e4e3100e45124ce020fcc8d2d4aff9b
|
|
BLAKE2b-256 checksum How to use checksums |
08f18cfad6311c962a3346c94530346b7110c80a708224669c4b9ae2ca056af2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl
| Download URL | radix_mlp-0.0.2-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl |
|---|---|
| Size | 301.9 kB |
| Tags | CPython 3.10 Linux glibc 2.5+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
3c6b1095f4a449a1b21a30074a3705ebf4c973a2a28052fc928d6c60d7e675ee
|
|
BLAKE2b-256 checksum How to use checksums |
55c2e850295ffd9c68bfe62067149bb4849233efcf76fd47a1c9a6b507695ce7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | radix_mlp-0.0.2-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 246.5 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e26855cdfd7193646a19fd5854368a0876cf32d74f76bb3d92c59e3a6e667bea
|
|
BLAKE2b-256 checksum How to use checksums |
cb954ae6afffbbdb8348bb46c93b2dbadcbe18d9d02b6563bba4f11bbe954103
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|
Release files / radix_mlp-0.0.2-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | radix_mlp-0.0.2-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 250.8 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
ec94349e1a1eec2ed334fce523b41e1bb0d98f9a7613e8f4a58cf8e721980daa
|
|
BLAKE2b-256 checksum How to use checksums |
e2674936fc4dd1687c594a12fd1010d76c384208945504f4217c6efbf111b060
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.10.2
|