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.1.tar.gz (23.0 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.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (288.1 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

radix_mlp-0.0.1-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.1-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.1-cp313-cp313t-musllinux_1_2_i686.whl (513.9 kB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ i686

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

Uploaded CPython 3.13tmusllinux: musl 1.2+ ARMv7l

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

Uploaded CPython 3.13tmusllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

radix_mlp-0.0.1-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.1-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.whl (294.1 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.5+ i686

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

Uploaded CPython 3.13tmacOS 11.0+ ARM64

radix_mlp-0.0.1-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.1-cp310-abi3-win_amd64.whl (135.8 kB view details)

Uploaded CPython 3.10+Windows x86-64

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

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

radix_mlp-0.0.1-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.1-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.1-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.1-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.1-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.1-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.1-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (410.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ppc64le

radix_mlp-0.0.1-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.1-cp310-abi3-macosx_11_0_arm64.whl (247.8 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

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

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for radix_mlp-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6393051edefabd7d9054d4a0aa15d6bca5d3df0f09a0f798a90919ccb20173ed
MD5 3bb03a977e3878228bab984afaa1e315
BLAKE2b-256 93276d1ed41af2fa0c626f44005801f92da6a906c4f2e87c8b509f3a21caa277

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b494b12f3963df8296e206d4abbddbf0d55778c4033e23663f39b1916797c03b
MD5 fce65df1c15e110879fa4c72feae0b61
BLAKE2b-256 026779091e8aa107f0c32cad884ec50c518d9b34a84d15035b028566c501204f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 1effb3f09eccfb7daea5c0772f7f0c4d58b6e2fc8842cbe23202229150b7e825
MD5 7cc23afa5cb038d7d853a4c66aef9bd9
BLAKE2b-256 115b6eaa1136745d2bec1a59288fd8ca6672e6f4c004a8f0c06747319b7d20a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp313-cp313t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c12c7a4de4ad030bb1dedfaecf38914959d9e0932b92e7577f71a1e6d8528322
MD5 18726d8689fdb06b4c7f7d6a187b8d3d
BLAKE2b-256 15ab17b1abe15080451fde464cdb8bd85517dd1d824caa8fe41c5a85690c9a77

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp313-cp313t-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 bae26e1557cb461d79c6824ba629779a83387d9680e20bbe45134da95c0eba53
MD5 62f8a73ad8eedfae6403faad92f3fac9
BLAKE2b-256 64e8aa05f0bc62160d0856a013104b5d19d4efe2540b456e5ce54e05da0b9696

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp313-cp313t-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 2e5381ee7a11467d2a50550e404fe560ebad31929db4a7130e41ac467bf5b837
MD5 ca49296467a4b1e47a2a3a77f2d63c07
BLAKE2b-256 1c1d80f691a8d03096ea198552a18c9a3a38ef8d38edef526d4c1d57e56278c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp313-cp313t-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f806c1e1d9e26c936be921abc3df0030192001353121f0bf00be554402b805d9
MD5 5cb9c37d9835d66043cfa6b616c3aa72
BLAKE2b-256 479156f7d51ef173681ffaca837391da79edd488d4fed168404bab2e817ba6e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 79534ad92ef9d70408d6ba42d0a67850a0c3f08200355fccb2eff28b5426d2f4
MD5 2f6edcfb54f4fabf095aecf435d8a37d
BLAKE2b-256 6078e9f7f69de387aa2b2465977b907e767d6fedaa681da8981ee5d864cacbc3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 9ab591482c9aaf178c1b68746fb8d20fd88762810909b2a50a6916e16779a7d1
MD5 285304da3b1c260a20b48501bf343e1e
BLAKE2b-256 9220ba22026f1e98bc9b815a3c21fb0bb2bba495d40bd25b58ee8d6652b4fcf7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 86b9588878602a65ef75c2b58070547ebbac3d7c30a08567dea99ad45402e13c
MD5 a721ef455a3902210b2aa6b922b453d1
BLAKE2b-256 b5e43daf2bf4a8d934ca683b6fa2f79d10d96159ea5f40534ef26cef6dae5c76

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2a7853f7b15ad612948e28f546c4113aa0912eca54b497eae5604e799f397202
MD5 bd2b7fdb84e4296c85609fc7744dc1cc
BLAKE2b-256 bbaf061d3650e54cd242cc288251a48500de6e0de362e2230f8ff96c4ff50c0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp313-cp313t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f22b28b1f8c0d33ca51fb6516181860a7f2d79efedc44ee85c37078b02d0ad5e
MD5 ee8a676422597cb13780ea1f526b9a97
BLAKE2b-256 4cc1787110647d59ceaa7a2e9ddb0326b3b9d871488406c628b99743e6cd9927

See more details on using hashes here.

File details

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

File metadata

  • Download URL: radix_mlp-0.0.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 135.8 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.10.2

File hashes

Hashes for radix_mlp-0.0.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 87a8770407c080aad909e9441e3fbb346bd0da8b8ecfddd17d3fe6a730120f7a
MD5 89abb4eea719cefbc8df3e668cb85651
BLAKE2b-256 0305e30af746d4e60e3da5ddb462f591b464050cb664a4235ebf45303bdc7d7d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1b25db1cef0466d34b084486e42b71bbd9eccaa7d9772cc637f6be2655bf71c9
MD5 31bf4d713ec248d1ad86d5ce21ea3bc6
BLAKE2b-256 4ed241a06c50a4b5fa2fc54d3c68305e57be87b38e7e9fed18535ffa5ce3c047

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 b6588c5b6a5dc06360e54f4748c428aae474c1d4a01d61832f1779930554b6da
MD5 35e255fd18fd7a2d0aacab6882e3895b
BLAKE2b-256 6294eadad63924e24208ac4fbbb0db05e34d0fa18fcf79740bab7d7de81d948f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp310-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 7aaaa1339c1b297b8793656e5619a273d082af0626ab1e87e6f04cf6f8d2a927
MD5 7967bd542f1f2d238be59a2fe8f93c06
BLAKE2b-256 90020de0e34b9c317731221715fc9fcf61d47163ac3aa95dc469b649491f41c9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 3533b65446e40364cf185dbc84df40f972462693aa982f3c8c2f2f4797229429
MD5 5ef9e0ed52f02d93d0ad7da9b1935d2a
BLAKE2b-256 51371a46d550eb8f3fc56758ff78b51edc1bea9028cd8bda4097fd9f731595b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp310-abi3-manylinux_2_28_armv7l.whl
Algorithm Hash digest
SHA256 0eb00da67531705e68b51e1f10d3ca201beb1f946fb67bd39df52afd8be3697d
MD5 6bb42971f71024a98fa9b17e1b0204f7
BLAKE2b-256 cffe4d0bd2321fc3f914afdd6ee7ff2c02132d0ff6b1e0d20eea39a1b2fce7b0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d6d0c30eddcaf5237c039c52eeff347e4444242fe5a82543b4b469dbfc816f05
MD5 4c1f9dd6d98cf93038ff94790bdf7ea6
BLAKE2b-256 662c59a638b3e17e48b4a01fb9aecdb0b75e86250bb20d900047ba0e767c468c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 36cffa2e38160395d8a50d5f6cd992539b401ccb51ab801e4985c9fa776ee40c
MD5 f10b2d492a8244b231480c92df4eeca1
BLAKE2b-256 bf2a05fb39f00edd887c02149ef9ab6fcf2e7e8640648747b69db19b224bc48f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 ba8b0e476db332842f42ad7fb6b394ebe2826c14fc3613809bc5a982e9f13db2
MD5 86867d32aa9c250000291cb8e799c686
BLAKE2b-256 7e0c3bdc32223ba9c384ae93ec2dcfb6f9185d60a13896ff257b8d5dbc7abdfa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 3f8ed62f52750bc0c816afd75d22d26a70b6ee62ca343713ff81c12d77a67be2
MD5 eca415769e05eafad52ca12a24e8c38c
BLAKE2b-256 35f84065bdb42be1e491c6d0eae453132abac0a40eff0f41797558d9d6b95d52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f635bfc0c78f27d4357824d89de6bc957fe7a4140e6f564824e22e8d3c088673
MD5 b6ccdf0171186dde0a24f28df1fbc0c0
BLAKE2b-256 7624e656544c1a868e57eb8676c637a03a16bc42ef3b9f48ee144955049b93bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 5eb2ce89c0650a7b7cd05d3744bbef356a7cd8d4ea06b994d16acd1e6a54e097
MD5 ce54c7a212331488805c211f1165d0d4
BLAKE2b-256 17a9026c6c5a7d5750e0adc26838356b11883de8c1c6956490faf09cbcc118b1

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