MCPcopy Index your code
hub / github.com/LaurentMazare/mamba.rs

github.com/LaurentMazare/mamba.rs @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
76 symbols 148 edges 10 files 7 documented · 9%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

mamba.rs

Pure Rust implementation of Mamba [1] inference with minimal dependencies. Mamba is an alternative to the transformer architecture. It leverages State Space Models (SSMs) with the goal of being computationally efficient on long sequences.

Most of the inspiration for mamba.rs (and some of the code) come from llama2.rs (by @srush).

# Download the tokenizer configs.
wget https://huggingface.co/EleutherAI/gpt-neox-20b/raw/main/vocab.json
wget https://huggingface.co/EleutherAI/gpt-neox-20b/raw/main/merges.txt

# Download and generate the weight files.
python get_weights.py

# Run with a prompt.
cargo run --release -- "Mamba is"

Mamba Is

By default this uses the 130m model. As it is a really small model, the generated text might not be great.

Alternatively to use the 370m model instead of the 130m one, use the following.

python get_weights.py --which 370m
cargo run --release -- "Mamba is" --which 370m

Other variants are 790m, 1.4b, and 2.4b.

Current features:

  • Model weight loading using mmap.
  • Matrix multiplication using rayon to leverage multiple cores, but not cache friendly.

TODO:

  • Improve the efficiency by using SIMD instructions (or fast-math) and more parallelism.
  • Quantized versions?

Extension points exported contracts — how you extend this code

ModelWeights (Interface)
(no doc) [1 implementers]
src/model.rs

Core symbols most depended-on inside this repo

write_buffer
called by 16
get_weights.py
get_tensor
called by 13
get_weights.py
forward
called by 10
src/model.rs
encode
called by 3
src/tokenizer.rs
weights
called by 2
src/main.rs
sample
called by 2
src/main.rs
update
called by 2
src/model_inc.rs
update_state
called by 2
src/model_inc.rs

Shape

Function 31
Method 29
Class 14
Enum 1
Interface 1

Languages

Rust53%
Python47%

Modules by API surface

jax/model.py22 symbols
src/main.rs12 symbols
src/model_inc.rs10 symbols
src/model.rs10 symbols
src/tokenizer.rs8 symbols
jax/data.py7 symbols
jax/train.py5 symbols
get_weights.py2 symbols

For agents

$ claude mcp add mamba.rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact