Gecko: An Efficient Neural Architecture Inherently Processing Sequences with Arbitrary Lengths

Xuezhe Ma, S. P. Wen, Linghao Jin, Bilge Acun, Ruihang Lai, Bohan Hou, Will Lin, Hao Zhang, Songlin Yang, Ryan Lee, Mengxi Wu, Jonathan May, Luke Zettlemoyer, Carole-Jean Wu · DOI

Abstract: Designing a unified neural network to efficiently and inherently process sequential data with arbitrary lengths is a central and challenging problem in sequence modeling. The design choices in Transformer, including quadratic complexity and weak length extrapolation, have limited their ability to scale to long sequences. In this work, we propose Gecko, a neural architecture that inherits the design of Mega and Megalodon (exponential moving average with gated attention), and further introduces multiple technical components to improve its capability to capture long range dependencies, including timestep decay normalization, sliding chunk attention mechanism, and adaptive working memory. In a controlled pretraining comparison with Llama2 and Megalodon in the scale of 7 billion parameters and 2 trillion training tokens, Gecko achieves better efficiency and long-context scalability. Gecko reaches a training loss of 1.68, significantly outperforming Llama2-7B (1.75) and Megalodon-7B (1.70), and landing close to Llama2-13B (1.67). Notably, without relying on any context-extension techniques, Gecko exhibits inherent long-context processing and retrieval capabilities, stably handling sequences of up to 4 million tokens and retrieving information from contexts up to $4\times$ longer than its attention window.

The Challenge of Infinite Context

The natural language processing landscape is dominated by the Transformer architecture. However, its core mechanism—full self-attention—scales quadratically with sequence length, making the processing of extremely long contexts like entire books or massive codebases computationally prohibitive.

While alternative architectures like State Space Models (SSMs) and linear Transformers offer linear scaling, they often struggle with high-fidelity in-context retrieval tasks compared to standard Transformers. Previous attempts to bridge this gap, such as Mega and Megalodon, utilized chunk-wise attention and exponential moving averages (EMA). However, these models suffered from information loss at chunk boundaries and numerical instability over very long sequences. Gecko aims to resolve these architectural bottlenecks to create a model that is both hardware-efficient and capable of robust, infinite-length context retrieval.

Architectural Innovations

Gecko builds upon the Megalodon backbone with three major technical innovations designed to enhance stability and context flow:

  1. Timestep Decay Normalization: Previous models saw the influence of current tokens on cumulative statistics diminish as sequences grew. Gecko introduces a decay mechanism (inspired by Adam's momentum) that keeps the ratio of current-to-historical statistics fixed, ensuring numerical stability over infinite lengths.
  2. Sliding Chunk Attention (SCA): Standard chunk-wise attention isolates segments, causing performance drops at boundaries. Conversely, token-by-token sliding window attention is inefficient on GPUs. Gecko utilizes SCA, where attention is computed jointly over the current and previous chunks. This allows local context to flow across boundaries while maintaining the high efficiency of large matrix multiplications.
  3. Adaptive Working Memory (AWM): To capture dependencies beyond the sliding chunks, Gecko uses a linear attention mechanism to compress history into a fixed-size state. It introduces a position-aware online softmax kernel that globally compresses history without the "forget gates" found in other models, preserving long-term retrieval capabilities.
Comparison of attention mechanisms: (a) Chunk-wise, (b) Sliding Window, and (c) Gecko's Sliding Chunk Attention.

Experimental Results

Gecko-7B was pretrained on 2 trillion tokens using the same data mixture as Llama2. The results demonstrate that Gecko is not only more efficient but also more capable at scale.

Pretraining Efficiency

At the 2 trillion token mark, Gecko-7B achieved a training loss of 1.68. This significantly outperforms Llama2-7B (1.75) and Megalodon-7B (1.70), placing Gecko’s performance remarkably close to the much larger Llama2-13B (1.67).

Training loss comparison between Llama2 (7B/13B), Megalodon-7B, and Gecko-7B over 2 trillion tokens.

Long-Context and Retrieval

Gecko demonstrates a unique ability to extrapolate context length without specialized fine-tuning:

  • Extreme Lengths: On a dataset of 1,500 books, Gecko's perplexity consistently decreased as context scaled up to 4 million tokens, whereas Megalodon's performance degraded due to boundary issues.
  • Retrieval Accuracy: Despite a 4K training attention window, Gecko achieved near-perfect retrieval on Passkey tasks up to 16K tokens and 100% accuracy on Needle-in-a-Haystack tasks up to 8K tokens.
  • Downstream Performance: On the Scrolls benchmark for long-form QA, Gecko-7B outperformed Llama2-7B-32K, a model specifically fine-tuned for length extension.

Conclusion

Gecko proves that inherent context extrapolation is possible through thoughtful architectural design rather than post-hoc scaling techniques. By combining hardware-aware attention mechanisms with stable normalization and non-forgetting memory, Gecko establishes a new frontier for efficient, long-context sequence modeling. Future work will look toward scaling the architecture to larger parameter counts and exploring its potential in multimodal applications.

Summary updated

BibTeX
@inproceedings{ma2026gecko,
  author = {Xuezhe Ma and S. P. Wen and Linghao Jin and Bilge Acun and Ruihang Lai and Bohan Hou and Will Lin and Hao Zhang and Songlin Yang and Ryan Lee and Mengxi Wu and Jonathan May and Luke Zettlemoyer and Carole-Jean Wu},
  title = {{Gecko: An Efficient Neural Architecture Inherently Processing Sequences with Arbitrary Lengths}},
  booktitle = {COLM},
  year = {2026},
  url = {https://openreview.net/forum?id=82JaGVBTxV},
}
Figure