MEGALODON: Efficient LLM Pretraining and Inference with Unlimited Context Length

Опубликовано: 10 Июнь 2026
на канале: Data Science Gems
436
15

The quadratic complexity and weak length extrapolation of Transformers limits their ability to scale to long sequences, and while sub-quadratic solutions like linear attention and state space models exist, they empirically underperform Transformers in pretraining efficiency and downstream task accuracy. MEGALODON is a neural architecture for efficient sequence modeling with unlimited context length. MEGALODON inherits the architecture of MEGA (exponential moving average with gated attention), and further introduces multiple technical components to improve its capability and stability, including complex exponential moving average (CEMA), timestep normalization layer, normalized attention mechanism and pre-norm with two-hop residual configuration. In a controlled head-to-head comparison with LLAMA2, MEGALODON achieves better efficiency than Transformer in the scale of 7 billion parameters and 2 trillion training tokens. MEGALODON reaches a training loss of 1.70, landing mid-way between LLAMA2- 7B (1.75) and 13B (1.67). The improvements of MEGALODON over Transformers are robust throughout a range of benchmarks across different tasks and modalities.

In this video, I talk about the following: How does Moving Average Equipped Gated Attention (MEGA) work? What is Exponential moving average, Multi-dim Damped EMA, Gated attention and chunk-wise attention in EMA? How does Megalodon work? What is Complex exponential moving average (CEMA), Timestep normalization layer, Normalized attention, and Pre-norm with two-hop residual configuration in Megalodon? How does Megalodon perform?

For more details, please look at https://arxiv.org/pdf/2404.08801 and https://github.com/XuezheMax/megalodon and https://arxiv.org/pdf/2209.10655

Ma, Xuezhe, Xiaomeng Yang, Wenhan Xiong, Beidi Chen, Lili Yu, Hao Zhang, Jonathan May, Luke Zettlemoyer, Omer Levy, and Chunting Zhou. "Megalodon: Efficient LLM Pretraining and Inference with Unlimited Context Length." arXiv:2404.08801 (2024).