# rishikksh20/mamba3-pytorch architecture

> Architecture diagram of the GitHub repository rishikksh20/mamba3-pytorch, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rishikksh20/mamba3-pytorch
- Repository: https://github.com/rishikksh20/mamba3-pytorch

## Overview

This repository is a readable PyTorch reference implementation of Mamba-3, supporting both sequence processing and autoregressive decoding, plus a stacked language model. The main workflow sends input through Mamba3 projections and an SSM scan to produce output; the scan implements either SISO or MIMO state updates, with rotary and trapezoidal features documented in the README. Decoding uses a separate single-token step and persistent inference state. The graph also preserves the documented residual-block and language-model layers. Internal links are limited to relationships stated in the README or visible in the excerpt; unsampled implementation details are not inferred.

Main entry points: [`mamba3.py`](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py) (Language model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ssm["SSM Core"]
  node_mamba["Mamba3 mixer<br/>[mamba3.py]"]
  node_inproj["Input projection<br/>[mamba3.py]"]
  node_norm["B/C RMSNorm<br/>[mamba3.py]"]
  node_rope["Rotary embedding<br/>[mamba3.py]"]
  node_scan["SSM scan<br/>[mamba3.py]"]
  node_siso["SISO scan<br/>[mamba3.py]"]
  node_mimo["MIMO scan<br/>[mamba3.py]"]
  node_output["Mixer output<br/>[mamba3.py]"]
end

subgraph group_decode["Decode State"]
  node_cache["Inference cache<br/>[mamba3.py]"]
  node_state["Decode state<br/>[mamba3.py]"]
  node_step["Single-token step<br/>[mamba3.py]"]
end

subgraph group_language["Language Model"]
  node_block["Residual block<br/>[mamba3.py]"]
  node_mlp["Feed-forward layer<br/>[mamba3.py]"]
  node_lm["Language model<br/>[mamba3.py]"]
  node_config["Model config<br/>[mamba3.py]"]
  node_embedding["Token embedding<br/>[mamba3.py]"]
  node_head["LM head<br/>[mamba3.py]"]
  node_count["Parameter counter<br/>[mamba3.py]"]
end

node_user(("Model caller"))
node_input["Sequence input"]
node_decode_user(("Decode caller"))
node_logits["Token logits"]

node_user -->|"supplies"| node_input
node_input -->|"passes to"| node_mamba
node_mamba -->|"projects"| node_inproj
node_inproj -->|"normalizes B/C"| node_norm
node_inproj -->|"rotates B/C"| node_rope
node_inproj -->|"provides projections"| node_scan
node_scan -->|"dispatches SISO"| node_siso
node_scan -->|"dispatches MIMO"| node_mimo
node_scan -->|"produces"| node_output
node_mamba -->|"projects output"| node_output
node_decode_user -->|"provides token"| node_step
node_decode_user -->|"allocates"| node_cache
node_cache -->|"returns states"| node_state
node_state -->|"updates across steps"| node_step
node_step -->|"returns output"| node_decode_user
node_config -->|"configures"| node_lm
node_lm -->|"embeds tokens"| node_embedding
node_lm -->|"stacks blocks"| node_block
node_lm -->|"may include"| node_mlp
node_lm -->|"projects logits"| node_head
node_head -->|"produces"| node_logits
node_user -->|"counts parameters"| node_count

click node_mamba "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_inproj "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_norm "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_rope "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_scan "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_siso "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_mimo "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_output "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_cache "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_state "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_step "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_block "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_mlp "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_lm "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_config "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_embedding "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_head "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"
click node_count "https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mamba,node_inproj,node_norm,node_rope,node_scan,node_siso,node_mimo,node_output toneBlue
class node_cache,node_state,node_step toneAmber
class node_block,node_mlp,node_lm,node_config,node_embedding,node_head,node_count toneMint
class node_user,node_input,node_decode_user,node_logits toneIndigo
```

## Components

### SSM Core

- [Mamba3 mixer](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [Input projection](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [B/C RMSNorm](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [Rotary embedding](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [SSM scan](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [SISO scan](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [MIMO scan](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [Mixer output](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`

### Decode State

- [Inference cache](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [Decode state](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [Single-token step](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`

### Language Model

- [Residual block](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [Feed-forward layer](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [Language model](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [Model config](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [Token embedding](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [LM head](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`
- [Parameter counter](https://github.com/rishikksh20/mamba3-pytorch/blob/master/mamba3.py): `mamba3.py`

### Other components

- **Model caller**
- **Sequence input**
- **Decode caller**
- **Token logits**

## Connections

- Model caller → Sequence input: supplies (evidence: `README.md`)
- Sequence input → Mamba3 mixer: passes to (evidence: `README.md`)
- Mamba3 mixer → Input projection: projects (evidence: `README.md`)
- Input projection → B/C RMSNorm: normalizes B/C (evidence: `README.md`)
- Input projection → Rotary embedding: rotates B/C (evidence: `README.md`)
- Input projection → SSM scan: provides projections (evidence: `README.md`)
- SSM scan → SISO scan: dispatches SISO (evidence: `README.md`)
- SSM scan → MIMO scan: dispatches MIMO (evidence: `README.md`)
- SSM scan → Mixer output: produces (evidence: `README.md`)
- Mamba3 mixer → Mixer output: projects output (evidence: `README.md`)
- Decode caller → Single-token step: provides token (evidence: `README.md`)
- Decode caller → Inference cache: allocates (evidence: `README.md`)
- Inference cache → Decode state: returns states (evidence: `README.md`)
- Decode state → Single-token step: updates across steps (evidence: `README.md`)
- Single-token step → Decode caller: returns output (evidence: `README.md`)
- Model config → Language model: configures (evidence: `README.md`)
- Language model → Token embedding: embeds tokens (evidence: `README.md`)
- Language model → Residual block: stacks blocks (evidence: `README.md`)
- Language model → Feed-forward layer: may include (evidence: `README.md`)
- Language model → LM head: projects logits (evidence: `README.md`)
- LM head → Token logits: produces (evidence: `README.md`)
- Model caller → Parameter counter: counts parameters (evidence: `README.md`)
