All models

fla_layer_multiscaleretention

RetNet replaces attention with retention, which trains in parallel and runs inference recurrently.

Language · 322 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (26 KB)

Open in a new tab

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.

At a glance

Family
RetNet
Parameters
97.2K
Operations
322
Framework
PyTorch
Recurrent
No
Published
2023, arXiv preprint
Cited by
142 (as of 29 October 2026)
Authors
Yutao Sun, Li Dong, Shaohan Huang and others
License
MIT
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m4954
Graph hash
156b4e860bf2f23c85a8f41f66a34e78adbf0579149d84695e477a6d0fcec6eb
Skeleton hash
13506d9d7c0a2ab76a04ebda2a3303dce4721e3a0ce747140b44d17cc4e51dd6
Architecture hash
8bb4163b2b66a3396db47d9fed222b6f7f554d55e47e054c0240cae9936a5a88
Diagram SHA-256
51cdd312a61073660096e5f62b48dac1358ef2c2b6f062ce05330fef131a2206
TorchLens version
2.35.3
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

How this diagram was made

menagerie.classics.fla_reimpl:build_fla: build({})

What it is

This model is a single multi-scale retention layer, the module RetNet uses in place of multi-head attention, without the surrounding blocks.

About this model's family

RetNet (Retentive Network) is a sequence model proposed as a foundation architecture for large language models. It replaces multi-head attention with a multi-scale retention mechanism that can be computed in three ways: parallel, recurrent and chunkwise recurrent. The paper's aim is to keep the parallel training of a Transformer while making inference cheap, since a Transformer's per-step cost grows with sequence length.

The parallel form is used for training. The recurrent form gives O(1) inference in memory and computation, and the paper notes it needs no key-value cache. The chunkwise form handles long sequences by encoding each chunk in parallel while summarizing the chunks recurrently. Each block pairs a multi-scale retention module with a feed-forward network, in a layout similar to the Transformer's. Each retention head gets its own decay rate γ, and a swish gate is added to increase the non-linearity of the retention layers.

For a 7B model at 8k sequence length, the paper reports that RetNet decodes 8.4× faster and saves 70% of memory compared with Transformers using key-value caches.

Key idea. The paper derives a retention mechanism with equivalent parallel and recurrent forms, so a language model can train in parallel and run inference at O(1) cost per step.

  • RetNet
  • Retentive Network
  • retention
  • multi-scale retention
  • language model
  • O(1) inference
  • linear complexity
  • chunkwise recurrent
  • torchscale

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.

Cite the paper

@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}, 
}