← 开源
MoonshotAI

MoBA

MoBA: Mixture of Block Attention for Long-Context LLMs

Model DevelopmentArchitecturePython
在 GitHub 打开
增长势头
+124 小时新增 Star+0.0%
2.19k
Star
161
Fork
+2
本周
2
贡献者
创建于 2025-02-17 · 更新于 2026-10-15 · 今日第 5148 名
主要开发者
eltociearhewr2010

MoonshotAI/MoBA 排名第 5,148,有 2,194 个星标。

同类别比较

MoonshotAI/MoBA 排名第 5,148,此处有 8 个同类条目;RubixML/ML 排名第 5,139。

同类别比较
名称排名指标
NVlabs/MambaVision5,124
语言:
Python
星标数:
2,242
分叉数:
149
简介:
[CVPR 2025] Official PyTorch Implementation of MambaVision: A Hybrid Mamba-Transformer Vision Backbone
Jongchan/attention-module5,127
语言:
Python
星标数:
2,237
分叉数:
406
简介:
Official PyTorch code for "BAM: Bottleneck Attention Module (BMVC2018)" and "CBAM: Convolutional Block Attention Module (ECCV2018)"
oxwhirl/pymarl5,129
语言:
Python
星标数:
2,223
分叉数:
414
简介:
Python Multi-Agent Reinforcement Learning framework
RubixML/ML5,139
语言:
PHP
星标数:
2,211
分叉数:
192
简介:
A high-level machine learning and deep learning library for the PHP language.
open-mmlab/mmrotate5,158
语言:
Python
星标数:
2,176
分叉数:
644
简介:
OpenMMLab Rotated Object Detection Toolbox and Benchmark
glouw/tinn5,167
语言:
C
星标数:
2,139
分叉数:
188
简介:
A tiny neural network library
marlbenchmark/on-policy5,170
语言:
Python
星标数:
2,121
分叉数:
387
简介:
This is the official implementation of Multi-Agent PPO (MAPPO).
eloialonso/diamond5,172
语言:
Python
星标数:
2,120
分叉数:
168
简介:
DIAMOND (DIffusion As a Model Of eNvironment Dreams) is a reinforcement learning agent trained in a diffusion world model. NeurIPS 2024 Spotlight.
关键参数与规格
关键参数与规格
参数值
语言Python
类别Model Development
子类别Architecture
星标数2,194
分叉数161
贡献者2
创建日期2025-02-17
更新日期2026-10-15
1 天星标数1
7 天星标数2
排名5,148
上次排名8,941
排名变化3,793
7 天星标排名7,838
上次 7 天星标排名9,505
7 天星标排名变化1,667
总星标排名5,896
上次总星标排名5,894
总星标排名变化-2
国家China
README 摘录

**Parameter-less Gating Mechanism**: A novel Parameter-less top-k gating mechanism is introduced to selects the most relevant blocks for each query token, ensuring that the model focuses only on the most informative blocks. **Seamlessly Transition between Full and Sparse Attention**: MoBA is designed to be a flexible substitute for full attention, allowing seamless transitions between full and sparse attention modes. **Note**: MoBA requires continue training of existing models to achieve its acceleration benefits. It is not a drop

-in sparse attention solution that can be directly applied to pretrained models without additional training. Abstract Scaling the effective context length is essential for advancing large language models (LLMs) toward artificial general intelligence (AGI). However, the quadratic increase in computational complexity inherent in traditional attention mechanisms presents a prohibitive overhead. Existing approaches either impose strongly biased structures, such as sink or window attention which are task-specific, or radically modify the attention mechanism into linear approximations, whose performance in complex

reasoning tasks remains inadequately explored. In this work, we propose a solution that adheres to the **“less structure”** principle, allowing the model to autonomously determine where to attend, rather than introducing predefined biases. We introduce Mixture of Block Attention (MoBA), an innovative approach that applies the principles of Mixture of Experts (MoE) to the attention mechanism. This novel architecture demonstrates superior performance on long-context tasks while offering a key advantage: the ability to seamlessly transition between full and sparse

attention, enhancing efficiency without the risk of compromising performance. MoBA has already been deployed to support Kimi’s long-context requests and demonstrates significant advancements in efficient attention computation for LLMs. Our code is available at MoonshotAI/MoBA. Evaluation with 1M context length Environment Setup **Note that current kernel implementations rely on and ** Quick Start We provide a transformers-friendly implementation for MoBA. Feel free to choose attention backends by between and . Implementation Details **moba_naive**: A naive implementation based

on attention masks. It's designed to help understand how MoBA selects corresponding chunks. You may save and visualize the attention masks to see the block selection process. **moba_efficient**: Our production-ready implementation optimized for performance. It achieves up to 40x speedup compared to moba_naive (tested with 32K sequence length, 1 attention head, MoBA Block 2048 and MoBA Topk 3). We recommend using this version for practical applications. Unit Tests References Llama Implementation: huggingface/transformers Flash Attention: Dao-AILab

/flash-attention Citation If you find MoBA is useful or want to use in your projects, please kindly cite our paper:

常见问题

记录了多少星标和分叉?

MoonshotAI/MoBA 有 2,194 个星标和 161 个分叉。

仓库排名是多少?

MoonshotAI/MoBA 排名第 5,148。

记录的语言和类别是什么?

MoonshotAI/MoBA 有 2,194 个星标,语言为 Python,类别为 Model Development。

哪个仓库排名最接近?

MoonshotAI/MoBA 与 RubixML/ML 比较,后者排名第 5,139,有 2,211 个星标。

README

MoBA: Mixture of Block Attention for Long-Context LLMs

Full Report

🚀 Introducing MoBA --- Mixture of Block Attention

  • Trainable Block Sparse Attention: The full context is divided into blocks, where each query token learns to attend to the most relevant KV blocks, enabling efficient processing of long sequences.

  • Parameter-less Gating Mechanism: A novel Parameter-less top-k gating mechanism is introduced to selects the most relevant blocks for each query token, ensuring that the model focuses only on the most informative blocks.

  • Seamlessly Transition between Full and Sparse Attention: MoBA is designed to be a flexible substitute for full attention, allowing seamless transitions between full and sparse attention modes.

Note: MoBA requires continue training of existing models to achieve its acceleration benefits. It is not a drop-in sparse attention solution that can be directly applied to pretrained models without additional training.

Abstract

Scaling the effective context length is essential for advancing large language models (LLMs) toward artificial general intelligence (AGI). However, the quadratic increase in computational complexity inherent in traditional attention mechanisms presents a prohibitive overhead. Existing approaches either impose strongly biased structures, such as sink or window attention which are task-specific, or radically modify the attention mechanism into linear approximations, whose performance in complex reasoning tasks remains inadequately explored.

In this work, we propose a solution that adheres to the “less structure” principle, allowing the model to autonomously determine where to attend, rather than introducing predefined biases. We introduce Mixture of Block Attention (MoBA), an innovative approach that applies the principles of Mixture of Experts (MoE) to the attention mechanism. This novel architecture demonstrates superior performance on long-context tasks while offering a key advantage: the ability to seamlessly transition between full and sparse attention, enhancing efficiency without the risk of compromising performance. MoBA has already been deployed to support Kimi’s long-context requests and demonstrates significant advancements in efficient attention computation for LLMs.

Our code is available at MoonshotAI/MoBA.

Evaluation with 1M context length

Environment Setup

Note that current kernel implementations rely on flash-attn==2.6.3 and torch >= 2.1.0

conda create -n moba python=3.10
conda activate moba
pip install .

Quick Start

We provide a transformers-friendly implementation for MoBA.

Feel free to choose attention backends by --attn between moba and moba_naive.

python3 examples/llama.py --model meta-llama/Llama-3.1-8B --attn moba

Implementation Details

  • moba_naive: A naive implementation based on attention masks. It's designed to help understand how MoBA selects corresponding chunks. You may save and visualize the attention masks to see the block selection process.
  • moba_efficient: Our production-ready implementation optimized for performance. It achieves up to 40x speedup compared to moba_naive (tested with 32K sequence length, 1 attention head, MoBA Block 2048 and MoBA Topk 3). We recommend using this version for practical applications.

Unit Tests

pytest tests/test_moba_attn.py

References

Citation

If you find MoBA is useful or want to use in your projects, please kindly cite our paper:

@article{lu2025mobamixtureblockattention,
  author = {Enzhe Lu and Zhejun Jiang and Jingyuan Liu and Yulun Du and Tao Jiang and Chao Hong and Shaowei Liu and Weiran He and Enming Yuan and Yuzhi Wang and Zhiqi Huang and Huan Yuan and Suting Xu and Xinran Xu and Guokun Lai and Yanru Chen and Huabin Zheng and Junjie Yan and Jianlin Su and Yuxin Wu and Yutao Zhang and Zhilin Yang and Xinyu Zhou and Mingxing Zhang and Jiezhong Qiu},
  title = {MoBA: Mixture of Block Attention for Long-Context LLMs},
  journal={arXiv preprint arXiv:2502.13189},
  year={2025}
}
排名相邻
同类项目