Skip to main content

Optimized Mamba implementation with chunk processing and ONNX export

Project description

MambaX

PyTorch implementation of the Mamba architecture with enhanced production-ready features:

  1. ONNX Export - Full model export support for deployment
  2. Chunk Processing - Single-forwardpass chunk handling (no token loops)
  3. CPU-First - Optimized execution without CUDA dependencies

Installation

Install the package directly from PyPI:

pip install mambax

Key Advantages

  • Production Ready: ONNX-compatible for serving
  • No Token Loops: Processes entire chunks in single forward pass
  • Hardware Agnostic: Runs equally well on CPU/GPU

Acknowledgements

Builds upon reference work from alxndrTL/mamba.py

Usage

1. Standard Forward Pass

import torch
import torch.nn as nn
from mambax import Mamba

# Initialize model
model = Mamba(
    d_model=512,
    d_inner=1024,
    d_conv=4,
    d_state=16,
    dt_rank=64,
    use_cuda=False
)

# Process full sequence
x = torch.rand(1, 128, 512)  # (batch, seq_len, dim)
output = model(x)  # single forward pass

2. Single Token Processing

x_token = torch.rand(1, 1, 512)  # (batch, 1, dim)
output, new_state, new_conv = model(x_token, state_cache, conv_cache)

3. Chunk-Based Processing

# Initialize with empty caches
state_cache = torch.zeros(1, 1024, 16)  # (batch, d_inner, d_state)
conv_cache = torch.zeros(1, 1024, 3)     # (batch, d_inner, d_conv-1)

# Process chunks (e.g. 8 tokens at once)
x_chunk = torch.rand(1, 8, 512)
output, new_state, new_conv = model(x_chunk, state_cache, conv_cache)

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

mambax-0.4.1.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

mambax-0.4.1-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file mambax-0.4.1.tar.gz.

File metadata

  • Download URL: mambax-0.4.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for mambax-0.4.1.tar.gz
Algorithm Hash digest
SHA256 181adc050dbdd8d7dc5457f1997590e909d0bd64a802c2c230633ea6b87c404a
MD5 7e12cda39dffcb74ea866618af68a887
BLAKE2b-256 35881da3f1a1db2919b16ee8580a012d5ae6c47b938c9eb57b315a658dfb59fa

See more details on using hashes here.

File details

Details for the file mambax-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: mambax-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for mambax-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b22873d63afde085e71acd62793b1f0540a70912c242e7ac47d14d08c22cf8e5
MD5 27b7f588e6481f0e6be7383e58140be2
BLAKE2b-256 24d878ba6da2aee2f9af4916bdb689595bd1285aadb1ca1f5b74b7ad547bbf09

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