Maba v2 Logo

Maba v2 Architecture

Linear Recurrence & Sparse Attention Hybrid Architecture

License Parameters Scaling Context Decode O(1)


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

Architectural Comparison: Maba vs Qwen3.8-Flash-Next vs MiniCPM-5 vs Dense Transformer

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):
  • 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:
    1. Local Sliding Window (128 tokens + 4 sinks).
    2. Sparse Top-32 Blocks (2,048 gathered tokens).
    3. 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
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Collection including AndrewThompson1233/maba-v2-architecture