long-context memory-optimization memory-efficiency sequence-modeling flashattention transformer-architectures transformer-optimization audio-processing
Abstract
Relative-position attention mechanisms offer compelling alternatives to RoPE across various transformer architectures, delivering superior performance in domains such as audio. These mechanisms typically modify attention scores by adding content-position or bias-position terms. Unlike RoPE, which encodes position via per-token rotations directly on the queries and keys, relative-position terms generally require pairwise offset-dependent computation or lookups, complicating their integration into fused attention kernels and introducing severe memory, bandwidth, and compute overheads as sequences scale. To address this bottleneck, we propose an exact attention algorithm that incorporates additive relative-position terms into FlashAttention-style tiled computation. Our method (1) uses offset-aware tiling to avoid redundant indexing and memory accesses, (2) computes only the necessary key/query-relation products and reuses them across token pairs in both forward and backward passes, and (3) uses offset-based gradient sharding and aggregation, eliminating atomic contention. We provide a unified, efficient Triton implementation across diverse relative-position attention mechanisms and evaluate it against naive and specialized implementations. For 8K-token sequences, our method speeds up the forward (backward) pass by 1.8-6.4times (2.0-21times) and reduces peak memory up to 2.9-128times (1.4-54times) over the strongest baseline for each mechanism, enabling long-context end-to-end transcription that is 1.8times faster and uses 2.4times less memory. Our method thus provides a drop-in, hardware-efficient solution for scaling relative-position attention transformers.
한국어 요약
한 줄 요약
Fast and Exact Relative-Position Attention를 구현한 새로운 알고리즘으로, FlashAttention 기반 구조에서 메모리와 연산 효율성을 크게 향상시킨다.
핵심 기여도
- Offset-aware tiling을 통해 불필요한 인덱싱과 메모리 접근을 제거.
- Key/query-relation product 재사용으로 forward/backward 연산 최적화.
- Offset-based gradient sharding과 aggregation으로 atomic contention 제거.
- 8K 토큰 시퀀스에서 forward/backward 속도가 1.8–6.4×, 2.0–21× 향상되고, 메모리 사용량은 2.9–128×, 1.4–54× 감소.
핵심 아이디어
기존의 Relative-Position Attention는 토큰 간 오프셋에 따라 계산이 이루어지며, 이는 FlashAttention과 같은 퓨즈드 연산에 통합하기 어려운 메모리 및 연산 오버헤드를 유발한다. 본 연구는 FlashAttention의 타일 기반 연산에 Relative-Position Attention을 정확히 통합하는 알고리즘을 제안한다. 핵심 아이디어는 오프셋에 따라 타일을 구성하고, 필요한 키/쿼리 관계만 계산하여 반복 사용함으로써 메모리와 연산 효율성을 동시에 달성하는 것이다. 이는 기존의 RoPE와 달리, 토큰 간 상대 위치 정보를 유지하면서도 하드웨어 효율성을 확보한다.
기술적 접근법
- **Offset-aware tiling**: 불필요한 인덱싱을 제거.
- **Key/query-relation product 재사용**: Forward와 Backward 연산에서 동일한 키/쿼리 관계 재사용.
- **Offset-based gradient sharding**: 각 오프셋에 따라 그래디언트를 분할하고 집계하여 atomic contention 제거.
- **Triton 기반 구현**: 다양한 Relative-Position Attention 메커니즘에 대한 통합된 효율적인 구현 제공.
- **하드웨어 최적화**: FlashAttention-2와 유사한 타일 기반 연산 구조 활용.
주요 결과
- **8K 토큰 시퀀스에서**: Forward 속도 1.8–6.4×, Backward 속도 2.0–21× 향상.
- **메모리 사용량**: Forward에서 2.9–128×, Backward에서 1.4–54× 감소.
- **실제 작업 성능**: Long-context end-to-end transcription에서 1.8× 빠르고 2.4× 적은 메모리 사용.
의의 및 한계
본 연구는 Relative-Position Attention의 확장성을 제한하던 메모리 및 연산 병목 현상을 해결하여, 실제 산업 모델에서의 대규모 훈련 및 추론에 적용 가능하게 만든다. 특히, FlashAttention-2와 유사한 구조를 유지하면서도 Relative-Position Attention을 정확히 처리할 수 있어, 기존 RoPE 대체 기술의 실용성을 높인다. 그러나, 특정 메커니즘(예: identity, clipped, bucketed map)에만 최적화되었으며, 다른 유형의 Relative-Position Attention에 대한 일반화 가능성은 추가 연구가 필요하다.
실용적 활용
음성 처리, 대형 언어 모델, 장문 텍스트 분석 등에서 상대 위치 정보가 중요한 트랜스포머 모델에 적용 가능하다. 특히, 메모리 효율성이 요구되는 실시간 추론 및 대규모 훈련 환경에서 유용하다.