Skip to main content

RadixMLP: Prefix-based computation sharing for transformer models

Project description

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 IDs
  • position_ids (np.ndarray[np.uint32]): Flattened position IDs
  • cu_seq_lengths (np.ndarray[np.uint32]): Cumulative sequence lengths
  • pad_multiple_of (bool): Pad output for performance (default: False)

Returns:

  • compact_input_ids: Unique token IDs
  • compact_position_ids: Corresponding position IDs
  • scatter_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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

radix_mlp-0.0.1rc0.tar.gz (22.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

radix_mlp-0.0.1rc0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (288.2 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

radix_mlp-0.0.1rc0-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl (299.0 kB view details)

Uploaded PyPymanylinux: glibc 2.5+ i686

radix_mlp-0.0.1rc0-cp313-cp313t-musllinux_1_2_x86_64.whl (483.1 kB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ x86-64

radix_mlp-0.0.1rc0-cp313-cp313t-musllinux_1_2_i686.whl (513.9 kB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ i686

radix_mlp-0.0.1rc0-cp313-cp313t-musllinux_1_2_armv7l.whl (551.3 kB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ ARMv7l

radix_mlp-0.0.1rc0-cp313-cp313t-musllinux_1_2_aarch64.whl (454.4 kB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ ARM64

radix_mlp-0.0.1rc0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (283.6 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

radix_mlp-0.0.1rc0-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (406.7 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ppc64le

radix_mlp-0.0.1rc0-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.whl (294.0 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.5+ i686

radix_mlp-0.0.1rc0-cp313-cp313t-macosx_11_0_arm64.whl (242.1 kB view details)

Uploaded CPython 3.13tmacOS 11.0+ ARM64

radix_mlp-0.0.1rc0-cp313-cp313t-macosx_10_12_x86_64.whl (246.3 kB view details)

Uploaded CPython 3.13tmacOS 10.12+ x86-64

radix_mlp-0.0.1rc0-cp310-abi3-win_amd64.whl (135.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

radix_mlp-0.0.1rc0-cp310-abi3-musllinux_1_2_x86_64.whl (488.7 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

radix_mlp-0.0.1rc0-cp310-abi3-musllinux_1_2_i686.whl (521.7 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

radix_mlp-0.0.1rc0-cp310-abi3-musllinux_1_2_armv7l.whl (557.5 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARMv7l

radix_mlp-0.0.1rc0-cp310-abi3-musllinux_1_2_aarch64.whl (461.1 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_34_x86_64.whl (249.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.34+ x86-64

radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_28_armv7l.whl (288.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARMv7l

radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_28_aarch64.whl (279.0 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (290.8 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (410.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ppc64le

radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl (302.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.5+ i686

radix_mlp-0.0.1rc0-cp310-abi3-macosx_11_0_arm64.whl (247.9 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

radix_mlp-0.0.1rc0-cp310-abi3-macosx_10_12_x86_64.whl (252.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file radix_mlp-0.0.1rc0.tar.gz.

File metadata

  • Download URL: radix_mlp-0.0.1rc0.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for radix_mlp-0.0.1rc0.tar.gz
Algorithm Hash digest
SHA256 5cf1f6dd264723c603b1d17f5d80ded74c96b0bba994971299f35abf98bd761a
MD5 17104999473a367a8124c53c110fd7b4
BLAKE2b-256 3df37a7a90678adab1e6d06e9ff8554d46cd532e8e617982a042b6120b622d36

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b35564f664182be248fe1a0770857af704b50c667effe8605799ae07d1767a80
MD5 688246ea89be7c94da760d645ab9c9ab
BLAKE2b-256 d6e2d5593a3f239673939dc482d773e30dae9997de5731e382e414f2213fac43

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 7d908f4dafbbd33ce5bd47eadb3b5c77e9d71728a47b29aa14046d0118866a38
MD5 391b7f0a305b9e58c86480a61112a45f
BLAKE2b-256 911800b131de8870e27b8f4e40e89a9e30e64558194933ea8e70f5318b57af74

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp313-cp313t-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp313-cp313t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6ae2b3a36cd16e8913410cfe66f96e25f7e44ac97825bf0beee6e17a2e827fbb
MD5 5bf574630f3fbdf3678d361a201dd572
BLAKE2b-256 d2c5a9f055b823f1518107ca2cd8882391f68e782bc77972f24b1f56ee318d17

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp313-cp313t-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp313-cp313t-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 94657efff556e7d74903e1c7af1e4c5cad7c12dca9df82be18db676780062574
MD5 cdeb692411bcab5932da812dc1ce794b
BLAKE2b-256 2183721351ed266218b711eeb817398ca750356561d55c665b31e500b29d8254

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp313-cp313t-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp313-cp313t-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 f858b844a13b2adb350eee454f7cfd5bf180f2a992996d30b0ba94e2da69b76c
MD5 ddae24b0d745b2a1eadace503ddde374
BLAKE2b-256 e334c87f5147e94b8098fa45c24f81443922bfb096298caee3bee7d1897b6066

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp313-cp313t-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp313-cp313t-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 470701aebd48c5f40cc8c80eb7127051bf5dc732d7c71d0396020a664956ffb6
MD5 981e32bd9cfef3c8993f0dbb8ae2c5a7
BLAKE2b-256 08ef93354737604e6ba78dcc362e4791b920dfe781333add1d63367dd32f6f98

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 54191bf38f72ff0247a5f19db774411d061a97a5ecf6d56084283266df4ad048
MD5 0a61ead90ec5a3ad48d3a63a5627f8c3
BLAKE2b-256 dc05c34ab78d9e48a5e929decd6f30cd782314e55a5badecc3a14180195017b8

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 e465e559a693ed49d0e780523651a86cfefd36c2f13ad255da71ef29ac137547
MD5 aa49ba0493c2f8722a76df9a08d9152c
BLAKE2b-256 4d5b6a268e3c40f66b165c93bb87c1b8dcff6b1cff6725278c82c6bf3841e45c

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 4d4b3eb5dcd2bc7a89dbd363f65e8d2787e86cb3ef98984d2840bf8c555233fd
MD5 7524efe74567632c1fc1621f66a1c216
BLAKE2b-256 3d2920824f8e1fe3d6ecddd367c95f02b506007bcf866c7ef667daddc40248f4

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp313-cp313t-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a1331f8a871ec14411de804a1f7078b822487dd40b0437110949debdb2e72240
MD5 179315916998481b2e392649a8b0c44d
BLAKE2b-256 8a44e02daa280829bd4ca0bce3b91172ad8f8acaf23805351960154248e650ae

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp313-cp313t-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp313-cp313t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a724948eae486ed61cd557bfeab38aa00d981e02b257fcac41282f75d351ea24
MD5 9de9fbb16f6eb49a69e8d551ed0175d7
BLAKE2b-256 ec9d221b56a70c21d1dd68f9f13681944579b6501d84c7206065fa7809331212

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 95e72930de3ec929c0eb5d9aaf1c442c8f959447e70fa74a7bf7fe40e82b2c1e
MD5 4f327cf0609dd68c8872a9fffdadcccb
BLAKE2b-256 af7ac7190643284e4ac8701c6a0df640db53cde867660fe0ffe3c2c5726d7788

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e078fca169423ae8f5135a195604b3ef81ae446c2352ada87438ffb4e31ab531
MD5 374815ff9c72199dfe44d7357dcc3c3d
BLAKE2b-256 c9d69316103ffc76764d4e3e8cc74686e2cdc11f68fc94d392a80477296e2109

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 7b494d70aadcb55b9d3768cd8d4f370167cf21f4250fb739a0e297a2d0f915bc
MD5 233d9e1d46f1ef5e1cb945f7391c6057
BLAKE2b-256 e6cbac93e6079f569a899e9863d0cc57005ffce7c724044e4f7c60ab23918b44

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 9504440f4826d633c623c541db5e06aa4bef57b987feebfdf365d3fa0b18a1c2
MD5 7a9e84a0b766739ef911a188b6d2e5da
BLAKE2b-256 ab2b697cef875b6f891bf15ca5fa19977e7cdc92704a0417e97768ee5a4122ad

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f624346ce6d559fdea4bb41b30c6832ff16d5aab864f2104ec5a84f1173f008b
MD5 4c179800eb8822497e172cd4f4cb0659
BLAKE2b-256 fe559e24da345eb86cd2491479d135002c5c464831147cdc08d0336f19950fd7

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 62e621fac6766a66a8e6470d118dff2684f918126ca7a5936634ef3a94677633
MD5 308216389b04d617f9e13a67c17bc75b
BLAKE2b-256 372fefcd31b53ed3c6703fe31a193ac55a87497015865e65c3240dae92ae5d62

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_28_armv7l.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_28_armv7l.whl
Algorithm Hash digest
SHA256 794495cfb54c4437d0d3bc7f553d033aadcd52d3a45acc7f0d6123458c5f0d46
MD5 bab3dd203d85928caeb77d54c10c0797
BLAKE2b-256 97648bb04fe9df2b3b9a4d45e3184251e907a13c73b5ac6be06cc1c37e7071a0

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cc570a8d1e27948e988a020ccb256be77fd66372773c644af3acf9bab8e4b7a0
MD5 36362968eeeac597812ae1beb03b08e0
BLAKE2b-256 fdf9f93b7e4aaba6964dbffdfdf530d6395bab858ed6a0d6df40d77f417f39a5

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 27ed931165078ca6d309964e41b9fe1253939740f7852db76445236b6a67e097
MD5 a33f03af529b6b1b9e444a5b87b2120f
BLAKE2b-256 100c272cae62bf7a8dc4a9bc84449096d60a88f1513b49cb5335525c9d1258d2

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 d2805b7a024a319612c904e2861a2ff950279ed6158711902f8603ebf3e53deb
MD5 74461e1b0ffe5a75c1e9d9f72b4e9d84
BLAKE2b-256 56ca6f807a25fea40596a418243ad70c7a2dd95b831eda8cc65164d194a2db1b

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 b32b45db6d98b361d1b96279b0f2bb1fe95049b85947546522128a06dfaf6e01
MD5 5977f84b258a893f3f0688adc9389e4a
BLAKE2b-256 48a0e8317a1f33fad2da4dfff0481fab9f415197f88610345943feb5db89d1bb

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 869bb706822c6705f3004cf829a139c9e1cd145ad6d75c1a6c18ec0c14c3cb27
MD5 5e05971f8103d1a0927753a64ca4345c
BLAKE2b-256 eadd5a12dca49712e0f0e082a98a4cafc19c837439e4076343dc9fec7ba9e7ba

See more details on using hashes here.

File details

Details for the file radix_mlp-0.0.1rc0-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for radix_mlp-0.0.1rc0-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 40b2e62c3c95fbec0c1df1ed5566f9d81cd776aad9fc8c6871fd7e72f3f8c9f6
MD5 0f14ee91603a298924d125a538b90c30
BLAKE2b-256 021872c50a4d014b879a4b6565b146812cc43cff40aa36cb19df01048ae3ca3f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page