AB
AiBoss
project

MoBA - A novel attention mechanism proposed by Moonshot AI

MoBA (Mixture of Block Attention) is a novel attention mechanism proposed by Moonshot AI to improve the efficiency of large language models (LLMs) in handling long-context tasks. It works by dividing the context into multiple blocks (bl...

What is MoBA?

MoBA (Mixture of Block Attention) is a novel attention mechanism proposed by Moonshot AI to improve the efficiency of large language models (LLMs) in handling long-context tasks. By dividing the context into multiple blocks and introducing a parameterless top-k gating mechanism, it allows each query token to dynamically select the most relevant key-value (KV) block for attention computation. This significantly reduces computational complexity while maintaining performance comparable to full attention mechanisms. MoBA's core advantage lies in its ability to seamlessly switch between full attention and sparse attention modes, while adhering to the "less structured" principle to avoid introducing predefined biases and allowing the model to autonomously determine its focus. Experiments show that MoBA is 6.5 times faster than traditional full attention mechanisms when processing long texts with 1 million tokens. MoBA has been validated on the Kimi platform, and its code has been open-sourced.

Main functions of MoBA

  • Block sparse attentionMoBA divides the context into multiple blocks, and for each query token, it dynamically selects the most relevant key-value (KV) block for attention calculation, thus achieving efficient processing of long sequences.
  • Parameterless gating mechanismThrough a novel top-k gating mechanism, MoBA dynamically selects the most relevant block for each query token, ensuring that the model only focuses on the most informative parts.
  • Seamless switching between full attention and sparse attentionMoBA is designed as a flexible alternative to full attention, seamlessly switching between full attention and sparse attention modes to improve efficiency without compromising performance.
  • High performance implementationMoBA combines the optimization techniques of FlashAttention and MoE (Hybrid Expert Model) to significantly reduce computational complexity. When processing long texts with 1M tokens, MoBA is 6.5 times faster than traditional full attention mechanisms, and when processing 10M tokens, the speedup is up to 16 times.
  • Compatibility with existing modelsMoBA can be easily integrated into existing Transformer models without requiring extensive training and tuning.

MoBA's technical principles

  • Causal designTo maintain the causal relationships in the autoregressive language model, MoBA ensures that the query token does not focus on future blocks, applying a causal mask within the current block. This avoids information leakage while preserving local contextual information.
  • Fine-grained block partitioning and scalabilityMoBA supports fine-grained block partitioning, similar to the expert partitioning strategy in MoE (Hybrid Expert Model). This design improves performance, enabling MoBA to scale to extremely long contexts (such as 10M tokens) and perform exceptionally well in long-context tasks.

MoBA's project address

MoBA application scenarios

  • Long text processingMoBA reduces computational complexity by dividing the context into blocks and dynamically selecting relevant blocks for attention computation, enabling it to efficiently handle long texts, such as historical data analysis, complex reasoning, and decision-making tasks.
  • Long context language modelMoBA has deployed support for Kimi's long context request processing, significantly improving processing efficiency. When processing ultra-long texts with 1M or even 10M tokens, the speed is improved by 6.5 times and 16 times respectively.
  • Multimodal tasksMoBA's architecture can be extended to multimodal tasks, processing and understanding various types of data (such as text and images), and combined with long context processing capabilities, it supports complex tasks.
  • Personal Assistants and Smart HomesIn personal assistants and smart home control, MoBA can efficiently process long user commands and respond quickly through dynamic attention mechanisms, thus improving the user experience.
  • Education and LearningIn the field of education, MoBA can help students process long learning materials, assist in completing assignments, or provide intelligent tutoring based on long contexts.
  • Complex Reasoning and Decision MakingMoBA's dynamic attention mechanism can efficiently handle complex reasoning tasks, such as long chain reasoning (CoT) and multi-step decision-making, while maintaining performance comparable to full attention mechanisms.