{"id":21094408,"url":"https://github.com/branebb/mamba","last_synced_at":"2026-04-23T12:33:13.391Z","repository":{"id":257299880,"uuid":"857858218","full_name":"branebb/mamba","owner":"branebb","description":"Interactive demo of the Mamba state-space language model with pretrained weights and a Streamlit interface.","archived":false,"fork":false,"pushed_at":"2026-01-18T16:35:40.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-19T00:46:12.695Z","etag":null,"topics":["mamba-state-space-models","python","pytorch","streamlit"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/branebb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-09-15T19:34:15.000Z","updated_at":"2026-01-18T16:37:03.000Z","dependencies_parsed_at":"2024-09-15T20:47:55.195Z","dependency_job_id":null,"html_url":"https://github.com/branebb/mamba","commit_stats":null,"previous_names":["branebb/mamba"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/branebb/mamba","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/branebb%2Fmamba","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/branebb%2Fmamba/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/branebb%2Fmamba/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/branebb%2Fmamba/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/branebb","download_url":"https://codeload.github.com/branebb/mamba/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/branebb%2Fmamba/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32181371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-23T11:42:27.955Z","status":"ssl_error","status_checked_at":"2026-04-23T11:42:18.877Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mamba-state-space-models","python","pytorch","streamlit"],"created_at":"2024-11-19T22:17:26.225Z","updated_at":"2026-04-23T12:33:13.385Z","avatar_url":"https://github.com/branebb.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Mamba Architecture\n\n\u003cdiv align=\"justify\"\u003e\n\nThis project implements a **Mamba-inspired language model** using **PyTorch**, along with an interactive **Streamlit-based web application** for real-time text generation. The model architecture is based on the key ideas introduced in the *Mamba* paper, focusing on **linear-time sequence modeling with selective state space models (SSMs)** instead of attention mechanisms.\n\nThe application allows users to select pretrained Mamba models and generate text completions from custom prompts through a simple web interface.\n\n---\n\n## Project Overview\n\nRecent advances in sequence modeling have shown that attention mechanisms are not the only viable approach for modeling long-range dependencies. The **Mamba architecture** introduces a novel alternative based on **selective state space models**, enabling **linear-time** and **memory-efficient** sequence processing.\n\nThis project provides:\n- A **custom PyTorch implementation** of a simplified Mamba-style language model\n- Support for loading **official pretrained Mamba weights**\n- An **interactive Streamlit demo** for autoregressive text generation\n\n---\n\n## Architecture Overview\n\nThe model follows a stacked residual architecture composed of multiple **Mamba blocks**, each including:\n\n- Token embeddings with tied output projection\n- Pre-normalization using **RMSNorm**\n- Input projection with gating\n- Depthwise 1D convolution for local mixing\n- **Selective State Space Model (SSM)** with learnable parameters\n- Linear-time **selective scan** over the sequence\n- Residual connections\n\nThis design enables efficient autoregressive generation while avoiding quadratic attention costs.\n\n---\n\n## Reference Paper\n\nThe implementation is **inspired by** the following paper:\n\n\u003e **Mamba: Linear-Time Sequence Modeling with Selective State Spaces**  \n\u003e Albert Gu, Tri Dao  \n\u003e arXiv:2312.00752 (2023)  \n\u003e https://arxiv.org/abs/2312.00752\n\nThis project does **not** aim to be a full or optimized reproduction of the original implementation, but rather a **simplified and educational adaptation** of its core ideas.\n\n---\n\n## Features\n\n- **Mamba-inspired architecture** with selective state space models\n- **Linear-time sequence processing**\n- Autoregressive text generation\n- Support for pretrained Mamba models (`130M`, `370M`)\n- Interactive **Streamlit web interface**\n- GPU acceleration via CUDA (if available)\n\n---\n\n## Tech Stack\n\n- **Python 3.8+**\n- **PyTorch** – model implementation and inference\n- **Hugging Face Transformers** – pretrained weights and tokenizer\n- **Einops** – tensor manipulation\n- **Streamlit** – web-based user interface\n\n---\n\n## Requirements\n\n- Python 3.8 or higher\n- PyTorch (CPU or CUDA version)\n- CUDA-compatible GPU (optional, recommended for larger models)\n\n---\n\n## Installation \n\n1. **Clone the repository**\n```bash\ngit clone https://github.com/your-username/your-repo-name.git\ncd your-repo-name\n```\n\n2. **Create and activate a virtual environment**\n```bash\npython -m venv venv\n# Windows\nvenv\\Scripts\\activate\n# Linux / macOS\nsource venv/bin/activate\n```\n\n3. **Upgrade pip**\n```bash\npython -m pip install --upgrade pip\n```\n\n4. **Install dependencies**\n```bash\npip install -r requirements.txt\n```\n\n## Usage\n\nThis project provides an interactive web-based interface for text generation using pretrained Mamba language models.\n\n### Running the Application\n\nTo start the application, run the Streamlit app from the project root:\n\n```bash\nstreamlit run app.py\n```\n\n## Pretrained Models\n\nThis project supports loading **official pretrained Mamba language models** released by the authors of the Mamba architecture. The models are automatically downloaded from the Hugging Face Hub at runtime.\n\n### Available Models\n\n- `state-spaces/mamba-130m`  \n  A lightweight Mamba model suitable for fast experimentation and limited hardware.\n\n- `state-spaces/mamba-370m`  \n  A larger model with improved generation quality and stronger language modeling capabilities.\n\n### Tokenizer\n\nAll models use the tokenizer from:\n\n- `EleutherAI/gpt-neox-20b`\n\nThis tokenizer is compatible with the pretrained Mamba checkpoints and is required for correct text encoding and decoding.\n\n### Loading Mechanism\n\nPretrained weights and configuration files are fetched automatically using the Hugging Face `transformers` library. No manual download is required.\n\nThe models are loaded once at application startup and cached to avoid repeated initialization.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbranebb%2Fmamba","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbranebb%2Fmamba","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbranebb%2Fmamba/lists"}