Instructions to use AndrewThompson1233/maba-v2-architecture with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AndrewThompson1233/maba-v2-architecture with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AndrewThompson1233/maba-v2-architecture")# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("AndrewThompson1233/maba-v2-architecture", device_map="auto") - RWKV
How to use AndrewThompson1233/maba-v2-architecture with RWKV:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use AndrewThompson1233/maba-v2-architecture with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AndrewThompson1233/maba-v2-architecture" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AndrewThompson1233/maba-v2-architecture", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/AndrewThompson1233/maba-v2-architecture
- SGLang
How to use AndrewThompson1233/maba-v2-architecture with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "AndrewThompson1233/maba-v2-architecture" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AndrewThompson1233/maba-v2-architecture", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "AndrewThompson1233/maba-v2-architecture" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AndrewThompson1233/maba-v2-architecture", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use AndrewThompson1233/maba-v2-architecture with Docker Model Runner:
docker model run hf.co/AndrewThompson1233/maba-v2-architecture
Overview
Reference PyTorch implementation of the 3:1 hybrid architecture uniting linear recurrence (DGDA) and sparse global attention (MABA-SA).
The model routes 75% of compute through constant-state recurrence and 25% through latent-compressed sparse attention with centroid routing.
- Decode latency: 35-37 ms/token flat up to 1,000,000 tokens on consumer GPUs.
- KV-cache footprint: 1.20 GB for 1M tokens in FP16 (compared to 48.8 GB for standard dense attention).
- Retrieval: Single-needle retrieval at token #742,189 with Rank #1 out of 15,625 blocks.
- Positional stability: Uses recurrent exponential decay (α_t) instead of RoPE to prevent phase distortion over long contexts.
Architectural Comparison
| Architecture | Macro-Topology | Attention Paradigm | Decode Complexity | KV Cache @ 131k | KV Cache @ 1M | Max Context |
|---|---|---|---|---|---|---|
| Maba (Canonical) | 3:1 Hybrid (15 DGDA : 5 MABA-SA) | Latent MLA (d_c=128) + 64:1 Centroids | O(1) Flat (35 ms) | 163.6 MB | 1.20 GB | 1,000,000+ (NoPE) |
| Qwen3.8-Flash-Next | Hybrid GDN + QSA MoE (6B active) | Micro-Block Sparse Attention | Sublinear O(log L) | 640.0 MB | 4.80 GB | 262k / 1M (YaRN) |
| MiniCPM-5 | Dense CausalLM (1B / 2B) | 100% Dense GQA | Linear O(L) | 3.20 GB | 24.50 GB | 131,072 (RoPE) |
| Dense Transformer | Standard Transformer | 100% Dense Softmax MHA | Linear O(L) | 6.40 GB | 48.82 GB | 64,000 max (OOM) |
Scaling & Benchmarks
All parameter scaling laws, model tiers (100M to 30B), analytical KV-cache memory formulations, and empirical context scaling comparisons are documented in SCALING.md.
Full hardware benchmark results - including decode dynamics, multi-architecture NIAH comparison, and Triton kernel ablation - are in BENCHMARK_REPORT.md.
Architectural Specifications
- Reference Config: config.json (101,282,319 parameters).
- Macro-Stack (20 layers, 3:1 ratio):
- 15 layers: DGDA (Decoupled Gated Delta Attention) linear recurrence.
- 5 layers: MABA-SA (Sparse Attention) with MLA latent compression (d_c = 128).
- Factorized Embeddings: Vocab 32,768 -> 128 -> 640 in maba_sparse/model.py.
- Anti-Dilution Routing: DG-Indexer uses hybrid pooling 0.5 × (mean + max) with distance decay penalty λ · log(1 + Δ) to protect salient single-token facts against background noise.
- Superposition Attention: 3 streams dynamically superposed via data-dependent gate logits:
- Local Sliding Window (128 tokens + 4 sinks).
- Sparse Top-32 Blocks (2,048 gathered tokens).
- Hierarchical Context Attention (HCA 64:1 compressed prefix).
- Multi-Backend Kernels: maba_sparse/kernels/ provides fused Triton GPU kernels (264k-375k tok/s on GPU), CPU OpenMP parallel kernels, and PyTorch autograd fallbacks.
Quick Start
Installation
git clone https://github.com/AndrewThompson1233/maba-v2-architecture.git
cd maba-v2-architecture
pip install -e .
Autoregressive Generation
import torch
from maba_sparse.model import MabaSparseForCausalLM, get_101m_config
config = get_101m_config()
model = MabaSparseForCausalLM(config).cuda().eval()
input_ids = torch.tensor([[101, 2045, 312]], device="cuda")
with torch.no_grad():
output = model.generate(input_ids, max_new_tokens=32, temperature=0.7)
print(output)
Training
# Distributed Data Parallel training on multi-GPU
torchrun --nproc_per_node=2 train.py \
--model maba_sparse \
--dataset synthetic \
--steps 100 \
--batch_size 4 \
--fp16
Benchmark Suite
All benchmark suites are consolidated in benchmark.py. Hardware benchmark metrics are in BENCHMARK_REPORT.md and benchmark_results.json.
# Frontier architectural comparison vs Qwen3.8-Flash-Next & MiniCPM-5
python benchmark.py --mode arch
# End-to-end model & attention scaling (Maba vs Dense Transformer)
python benchmark.py --mode model --contexts 128,256,512,1024,2048,4096
# Constant O(1) decode latency scaling
python benchmark.py --mode decode
# KV-cache footprint comparison (40x reduction)
python benchmark.py --mode memory
# 1,000,000 token single-needle fact extraction
python benchmark.py --mode needle
# 50 Hard Negatives ('semantic mines') & Multi-Hop reasoning across 640k tokens
python benchmark.py --mode multihop
# Triton hardware kernel throughput
python benchmark.py --mode triton
# Run all suites sequentially
python benchmark.py --mode all
Tests
Run tests:
pytest -q
Unit tests are in tests/.
License & Attribution
Maba v2 Architecture is released under the MABA Open Architecture License (MOAL-1.0).
- Author: Andrew Thompson (
AndrewThompson1233) - Commercial & Research Use: Permitted without royalty fees.
- Attribution: Any derivative architecture, implementation, checkpoint, or paper must state:
Created based on Maba v2 Architecture by Andrew Thompson - Anti-Plagiarism Protection: The name Maba / Maba v2 and its foundational mechanisms (DGDA, MABA-SA, DG-Indexer, HCA) may not be renamed, rebranded, or claimed under different names when adapting or copying this architecture.
See LICENSE for the full license text.
- Downloads last month
- 703