
retnet_yet_another
Language86 ops27.5K params
Retention instead of attention: parallel for training, recurrent for cheap inference, chunkwise for long inputs.
Language · 80 operations Checked
Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.
The file opened in a new tab. Use your browser's Save command there to keep it.
The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.
retnet_layer is a single RetNet decoder layer rather than the full decoder, so it returns hidden states instead of token logits.
About this model's family
RetNet, the Retentive Network, is proposed as a foundation architecture for large language models that aims to get training parallelism, low-cost inference and good performance at the same time. Its core is the retention mechanism, which the authors derive from a connection between recurrence and attention and which supports three computation paradigms: parallel, recurrent and chunkwise recurrent. The parallel form gives training parallelism, the recurrent form gives O(1) per-token inference, and the chunkwise form encodes each chunk in parallel while recurrently summarising the chunks for linear-complexity long sequences.
A third-party implementation describes the payoff as the 'impossible triangle' of language-model design: accuracy comparable to Transformers, high training throughput from the parallel form and high inference throughput from the recurrent form. The three forms are numerically equivalent, and that repository's tests check the parallel, recurrent and chunkwise outputs against each other, noting only small floating-point drift in the recurrent path. Since October 2023 the official torchscale implementation uses RMSNorm and SwiGLU as RetNet's default modules.
The official implementation lives in Microsoft's torchscale library, where a RetNet model is created from a RetNetConfig in several lines of code. The yet-another-retnet port also ships preconfigured, untrained 1.3B, 2.7B and 6.7B models matching the paper's configurations.
Key idea. RetNet replaces attention with a retention mechanism whose parallel, recurrent and chunkwise forms are equivalent, giving Transformer-level training parallelism together with O(1)-cost recurrent inference.
AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.
@misc{sun2023retentivenetworksuccessortransformer,
title={Retentive Network: A Successor to Transformer for Large Language Models},
author={Yutao Sun and Li Dong and Shaohan Huang and Shuming Ma and Yuqing Xia and Jilong Xue and Jianyong Wang and Furu Wei},
year={2023},
eprint={2307.08621},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2307.08621},
}