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

TL;DR
Megalodon is a novel neural architecture designed for efficient long-sequence modeling, outperforming traditional Transformers in pretraining efficiency and accuracy, especially at large scales with unlimited context length.
Contribution
It introduces multiple technical innovations to enhance the Mega architecture, enabling scalable, stable, and efficient sequence modeling with unlimited context length.
Findings
Megalodon outperforms Llama2 in efficiency at 7 billion parameters.
Achieves a training loss of 1.70, competitive with larger models.
Demonstrates effective long-sequence modeling with unlimited context.
Abstract
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. We introduce Megalodon, 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…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
Videos
Taxonomy
TopicsNatural Language Processing Techniques · Handwritten Text Recognition Techniques
MethodsAttention Is All You Need · Dropout · Adam · Position-Wise Feed-Forward Layer · Linear Layer · Layer Normalization · Byte Pair Encoding · Absolute Position Encodings · Dense Connections · Label Smoothing
