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 (Optional[int]): If Some(n), pad output to multiple of n for performance. If None, no padding (default: None)

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.2.tar.gz (23.3 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.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (286.4 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

radix_mlp-0.0.2-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl (297.4 kB view details)

Uploaded PyPymanylinux: glibc 2.5+ i686

radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_x86_64.whl (482.5 kB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ x86-64

radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_i686.whl (513.6 kB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ i686

radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_armv7l.whl (551.1 kB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ ARMv7l

radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_aarch64.whl (453.6 kB view details)

Uploaded CPython 3.13tmusllinux: musl 1.2+ ARM64

radix_mlp-0.0.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (282.8 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ x86-64

radix_mlp-0.0.2-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (406.1 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.17+ ppc64le

radix_mlp-0.0.2-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.whl (293.8 kB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.5+ i686

radix_mlp-0.0.2-cp313-cp313t-macosx_11_0_arm64.whl (241.5 kB view details)

Uploaded CPython 3.13tmacOS 11.0+ ARM64

radix_mlp-0.0.2-cp313-cp313t-macosx_10_12_x86_64.whl (245.7 kB view details)

Uploaded CPython 3.13tmacOS 10.12+ x86-64

radix_mlp-0.0.2-cp310-abi3-win_amd64.whl (134.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_x86_64.whl (487.8 kB view details)

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

radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_i686.whl (520.6 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ i686

radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_armv7l.whl (556.3 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARMv7l

radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_aarch64.whl (460.0 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

radix_mlp-0.0.2-cp310-abi3-manylinux_2_28_armv7l.whl (286.7 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARMv7l

radix_mlp-0.0.2-cp310-abi3-manylinux_2_28_aarch64.whl (277.3 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ ARM64

radix_mlp-0.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (289.6 kB view details)

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

radix_mlp-0.0.2-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (408.6 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ppc64le

radix_mlp-0.0.2-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl (301.9 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.5+ i686

radix_mlp-0.0.2-cp310-abi3-macosx_11_0_arm64.whl (246.5 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

radix_mlp-0.0.2-cp310-abi3-macosx_10_12_x86_64.whl (250.8 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for radix_mlp-0.0.2.tar.gz
Algorithm Hash digest
SHA256 fba2944eb1e25a2b223807a7e0e7c032ec1bd72d22aa02676be2fe98d52457ed
MD5 b15fd38c8e642c77a4d46d6c2be1855c
BLAKE2b-256 c7710466411c5b884df82d6b211f48512d3af5e03352fbccbea6de61f714fd8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-pp311-pypy311_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5c71801bfca8f2227149fcabb8831587479600d601147f01d189c9450c166955
MD5 7368193ea1ffd7d20f000d9e6c599ce1
BLAKE2b-256 62af12aa19ef2e5c64f3c7d4d1e07b8452aed02e827b780cff0797a5fc98e80f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-pp311-pypy311_pp73-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 1add3c704f8f1ed27e24a3a7c4cb0435b0611c4531432b415c81fc2e824ecc18
MD5 efdc00078f618321dd1799f7c5c3c487
BLAKE2b-256 0c88ed1b3fd6f43a57ff1f584af39c428a103c92cb30972229da30ef6b6d9e6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fad1b2886c6bbc4bf7246023b0494cda647dcf601ac67fffc1a727ba5acb2916
MD5 6211808527d2fee4dfbce40bd6bf00a3
BLAKE2b-256 a478fd30ee55863afbc1af74e63c52e756cc1519c0c20f3b1321624be267cee4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 a96c51905a73392911ba96180ccd41312d4a34747dc03771a52f8b6460d5db32
MD5 3889bf6610a2d2ee8a95d55bc16ef62d
BLAKE2b-256 47b1aa2a78c66db1ef4f0af2d07079a179253d0d15bcd6406652c83998b8eb5e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 af36cb19710e085966d024f862c5e9420007377fc180650285893dffd8f4330c
MD5 02d3f50894803743c3815d39705b96f7
BLAKE2b-256 504daaca1960eb21b44bfbcdc3c09bf9d16544f46c3ef3fcfb66d903ac437a85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp313-cp313t-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 4a0765d33b8e9b8b5a6b1f69ecdc4b5f5a0d6b91c3eb2068fbc5c8014dadbd3e
MD5 c38d518fbe41846ef0de3b94645f8155
BLAKE2b-256 707de983a5f720b617e73a36470350992d10f0a76badbadfc82c5d501895e86a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp313-cp313t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 65c808fb3e65c60d50a83f88ffe995f6280fc1e83862aa95cadaec15ea8cf050
MD5 73aa46b9eb7b9504486784fa31238c3c
BLAKE2b-256 61dfb59dbc4c198820a5dd102e67f9c3ffaea5aa3d24cc78298fb90ca21b7148

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp313-cp313t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 e45345ffac177356cb75b5c931e344f6ab5d8f123f39a71275640ec1efe89c48
MD5 71b2970ef868e4fa08bf41647a22b558
BLAKE2b-256 0517b8d272107d85cccd86d250bf99cdebb59d23501e058221cec3844c91c960

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp313-cp313t-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 a0143b983ea7188e974a83321fd48acd159e27b01fff5e2b6f1016890ee88f9b
MD5 1d5391fc6b298053ea3a315e1e428a6e
BLAKE2b-256 7b8abfaa00686d0f30025767ab89a49667280acfdfa3f24e2ebd7e1c36a2719c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp313-cp313t-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 ccf8ff94f7b8c43bb4a4dbf66457a4714b9af32c652c0722362e0a5936d665fc
MD5 3c8028b6c57b00b44b94279470cda1cd
BLAKE2b-256 f887fa23c28ddca6e811534f4f28c9e12a68ff54ccccf7236f796f19135572f9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp313-cp313t-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 491f9da91e68245729935b51c0d1fbddb6fee6dcac6db054ec7f32d8ed283dc5
MD5 eb7ef72d5fa08a3a6bd76b1c002ad593
BLAKE2b-256 e085ec34a707a72a58d3326114252ac221b68b8ad2d63a82fd5dd5ac25cdb8fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5d977d64bb91580cec769b7b2379e90cb292454cf6de5ae0b1289aced7a5c48b
MD5 9aae7db9b20e729cf867725f4bc139e1
BLAKE2b-256 cc44240d9b731907f46c9b408fe859d1f61dcf6e8a22e2bf4020911074653513

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 f2df36c173b382cace8afd0abbd17bc97ac43da933c850891fc851366b97d763
MD5 f5bcb9ea46d08d7bed07f87c4171041f
BLAKE2b-256 d31c6f20704d8f69d11bd93b04555e7332aa9729f05a72327bbf9be830e8be24

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 e15ca41836c098dea60dda02a338b747b166326b9f4cc0b4c81e9ac0f731a1be
MD5 267ee307ec89f99af4875889a2992ada
BLAKE2b-256 12e3554ad6c0eb594da53071e7c1624d0e1a62523c48bdab8d01362fe7611b65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 58600243c176fab9ce2adddfbe4735ed5add8defb46cbffcc04c3e563d04090d
MD5 e03de1844e230fd5cc6e16be1df6b6ae
BLAKE2b-256 133d7b6457f6abff0edaa5e689afb76d8f0dbba7e8ca5f28191f6b408f3d8204

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 f73f753369f024effa18f3cacccbfd09ea1bfeb6fdc9bcd671283d9e43b922a7
MD5 840fb1da49b61622d368cf050ecf4a6b
BLAKE2b-256 8bcf1f22246a5993fc2a740a2b740ecc7c13f72ac4ea8211f7c291c602bf22e8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp310-abi3-manylinux_2_28_armv7l.whl
Algorithm Hash digest
SHA256 e961c56508b200571a1ae21eca2ca7cea8173ddd458721c172d17cd83609e523
MD5 154bc18dfbf7a6a8143876f7ce0e8149
BLAKE2b-256 9056a6688c7fb241e8a1ed97108c137e8d8a69709bfb92d385fa52142266fbf2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp310-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8305348d297c431fc6a99b78e112bc6319e81951506346fd4fdd51270d377c1b
MD5 e0d6bf3eced2398bd4b2c390e7dea791
BLAKE2b-256 da73fa6fc552261ec47931cec2e468888f1fceee5878547c82785a05efb1a2a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0418b5adc84ed4875e1265b2a7452e54d64a201904589159e6ff0a470982363e
MD5 227b1ec46e3447fb9b06d92359a947df
BLAKE2b-256 5a1bd49fa4846769ae6ea2accea93f1af04f138af56aea9a0c18ea17f5a20d87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp310-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 bd79d7e5bef3e14616750573b0c518322e4e3100e45124ce020fcc8d2d4aff9b
MD5 ec66660c79c0f5fba2fed68c11e8e3a4
BLAKE2b-256 08f18cfad6311c962a3346c94530346b7110c80a708224669c4b9ae2ca056af2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp310-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 3c6b1095f4a449a1b21a30074a3705ebf4c973a2a28052fc928d6c60d7e675ee
MD5 8424fe32a3dc3d370267632416ae8da6
BLAKE2b-256 55c2e850295ffd9c68bfe62067149bb4849233efcf76fd47a1c9a6b507695ce7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e26855cdfd7193646a19fd5854368a0876cf32d74f76bb3d92c59e3a6e667bea
MD5 9653b47f2bd72f256a180efc022926e2
BLAKE2b-256 cb954ae6afffbbdb8348bb46c93b2dbadcbe18d9d02b6563bba4f11bbe954103

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for radix_mlp-0.0.2-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ec94349e1a1eec2ed334fce523b41e1bb0d98f9a7613e8f4a58cf8e721980daa
MD5 462d25364a5ed69f270f402cbc11639a
BLAKE2b-256 e2674936fc4dd1687c594a12fd1010d76c384208945504f4217c6efbf111b060

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