# Block-Recurrent Transformers

论文地址：

* <https://arxiv.org/abs/2203.07852>

## 整体思路以及计算方式

利用Memory的方式增加Transformer的性能，利用窗口的方式降低计算复杂度，对Memory部分使用递归的方式更新。

计算方式：

* 输入：$$\mathbf X\in \mathbb R^{n\times d}, \mathbf M \in \mathbb R^{m\times d}$$；
  * $$\mathbf M$$表示Memory；
* 输出部分更新方式：
  * $$\mathbf X\_1=\mathrm{MHA}\_{w}(\mathbf X, \mathbf X)\in \mathbb R^{n\times d}$$
  * $$\mathbf Y\_1=\mathrm{MHA}\_{w}(\mathbf X, \mathbf M)\in \mathbb R^{n\times d}$$
  * $$\mathbf O =\[\mathbf X\_1, \mathbf Y\_1] \mathbf W \in \mathbb R^{n\times d}$$
* Memory部分更新方式：
  * $$\mathbf M\_1=\mathrm{MHA}\_{w}(\mathbf M, \mathbf M)\in \mathbb R^{m\times d}$$
  * $$\mathbf Y\_1=\mathrm{MHA}\_{w}(\mathbf M, \mathbf X)\in \mathbb R^{m\times d}$$
  * $$\mathbf O =\[\mathbf M\_1, \mathbf Y\_1] \mathbf W \in \mathbb R^{m\times d}$$

备注，这里省略了ffn部分，其中$$\mathbf M$$的ffn为rnn。

整体结构：

![](https://2520240655-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fb2lKDIgZ0I1cirExLedu%2Fuploads%2Fgit-blob-2d2fdd6915ff703e4f9390da8de7e2d5714a5863%2F1.jpg?alt=media)

## 时间复杂度

$$O((n+m)wd)$$。

## 训练以及loss

不变。

## 代码

* <https://github.com/dashstander/block-recurrent-transformer>

## 实验以及适用场景

论文测试了lm，效果还不错。

## 细节

暂无。

## 简评

依然是一个空间换性能的方法。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://doraemonzzz.gitbook.io/transformer_evolution_paper/memory/007.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
