Mixture of Block Attention (MoBA) (Lu et al., 2025) is a promising building block for efficiently processing long contexts in LLMs by enabling queries to sparsely attend to a small subset of key-value blocks, drastically reducing computational cost. However, the design principles governing MoBA's performance are poorly understood, and it lacks an efficient GPU implementation, hindering its practical adoption. In this paper, we first develop a statistical model to analyze MoBA's underlying mechanics. Our model reveals that performance critically depends on the router's ability to accurately distinguish relevant from irrelevant blocks based on query-key affinities. We derive a signal-to-noise ratio that formally connects architectural parameters to this retrieval accuracy. Guided by our analysis, we identify two key pathways for improvement: using smaller block sizes and applying a short convolution on keys to cluster relevant signals, which enhances routing accuracy. While theoretically better, small block sizes are inefficient on GPUs. To bridge this gap, we introduce FlashMoBA, a hardware-aware CUDA kernel that enables efficient MoBA execution even with the small block sizes our theory recommends. We validate our insights by training LLMs from scratch, showing that our improved MoBA models match the performance of dense attention baselines. FlashMoBA achieves up to 14.7x speedup over FlashAttention-2 for small blocks, making our theoretically-grounded improvements practical. Code is available at: https://github.com/mit-han-lab/flash-moba.
본 논문은 블록 어텐션 혼합(MoBA, Mixture of Block Attention) 메커니즘에 대한 체계적 최적화를 다룬다. MoBA는 쿼리가 소수의 키-값 블록에만 희소하게 주목하도록 함으로써 긴 컨텍스트를 효율적으로 처리한다. 그러나 설계 원칙이 명확하지 않고 효율적인 GPU 구현이 부족하다. 저자들은 MoBA 메커니즘을 분석하는 통계 모델을 수립하고, 신호대잡음비(SNR) 공식 SNR ∝ √(d/B)를 도출하여 아키텍처 파라미터와 검색 정확도의 관계를 규명했다. 이론적 분석을 바탕으로 두 가지 개선 경로를 제시한다: 더 작은 블록 크기 사용과 키에 단기 합성곱 적용을 통한 신호 클러스터링. 작은 블록의 GPU 효율성 문제를 해결하기 위해 하드웨어 인식 CUDA 커널인 FlashMoBA를 개발했으며, FlashAttention-2 대비 최대 14.7배 가속을 달성하여 이론상 최적 구성을 실제로 가능하게 했다.
대규모 언어 모델(LLM)이 비디오 이해 및 생성 등 멀티모달 분야로 확장되면서 초장 컨텍스트 처리가 필요해졌다. 그러나 자기 어텐션 메커니즘의 이차 계산 복잡도가 병목이 된다. 희소 어텐션 방법은 중요한 영역에만 주목하여 이 문제를 해결하려 하며, MoBA는 각 쿼리를 소수의 키-값 블록으로 라우팅하는 학습된 라우터를 통해 복잡도를 거의 선형으로 감소시키는 유망한 방법이다.
단계 2: FlashAttention-2에서 영감을 받은 타일 커널로 Q와 K̃ 간 점수 계산, 각 쿼리의 상위-k 키 블록 찾기, 전체 점수 행렬 물리화 없음 (알고리즘 3)
단계 3: 효율적인 에필로그가 쿼리 중심 인덱스를 키 블록 중심의 varlen 레이아웃으로 재포맷
2. 전진 패스: 수집-및-밀집화(알고리즘 1)
각 논리 쿼리 블록 Q_i에 대해:
각 논리 키 블록 K_j에 대해:
varlen 인덱스를 사용하여 관련 쿼리 찾기
쿼리 부분집합을 밀집 물리 블록으로 배치:
- HBM에서 물리 쿼리 블록을 SRAM으로 수집
- SRAM에 캐시, 논리 키 블록 K_j의 모든 물리 타일 간 재사용
- 효율적인 밀집 GEMM 실행
- 결과를 HBM으로 산포
핵심 최적화: SRAM에 수집된 쿼리 블록을 캐시하여 여러 밀집 GEMM 간 재사용함으로써 불규칙한 수집 작업의 비용을 효과적으로 분산
고정 패턴 방법: Sparse Transformer (Child et al., 2019), Longformer (Beltagy et al., 2020), BigBird (Zaheer et al., 2021)
학습 방법: Reformer (LSH, Kitaev et al., 2020), Linformer (투영, Wang et al., 2020), Routing Transformer (Roy et al., 2021), Performer (Choromanski et al., 2021)
FlashAttention 시리즈: Dao et al. (2022), Dao (2023) - IO 효율적 어텐션 구현 기초
키 합성곱: Yang et al. (2025) - 선형 변환의 델타 규칙 병렬화
평가 기준:
RULER: Hsieh et al. (2024) - 장 컨텍스트 검색 평가
LongBench: Bai et al. (2024) - 다중 작업 장 컨텍스트 이해
관련 희소 방법:
Block Sparse Attention: Guo et al. (2024)
XAttention: Xu et al. (2025)
BigBird: Zaheer et al. (2021)
종합 평가: 이것은 이론과 실제가 긴밀하게 결합된 우수한 논문이다. 이론상 SNR 모델이 희소 어텐션 설계에 명확한 지침을 제공하고, 실제로 FlashMoBA가 이론적 통찰을 실제 성능 향상으로 변환한다. 모델 규모와 실험 범위에서 한계가 있지만, 핵심 기여 - 형식화된 설계 원칙과 효율적 구현 - 은 장 컨텍스트 LLM 발전에 중요한 의미를 갖는다. 특히 저자들이 제어 변수 실험을 통해 이론을 검증하는 엄밀한 태도와 오픈소스 코드로 커뮤니티 채택을 촉진하는 노력이 높이 평가된다.