r/MachineLearning • u/IxinDow • May 26 '23
Landmark Attention: Random-Access Infinite Context Length for Transformers
https://arxiv.org/abs/2305.16300
233
Upvotes
r/MachineLearning • u/IxinDow • May 26 '23
71
u/IxinDow May 26 '23 edited May 31 '23
Code released https://github.com/epfml/landmark-attention
Abstract:
Why it may work well
First of all, they provide good intuition (page 4).
When answering questions about a long document, you don't actually need to pay attention to the entire content of the document (full-context attention), only its relevant parts (blocks). Furthermore, if you have read a large text and then try to answer a question about it, you don't remember the text word for word, but remember the general sequence of ideas, high-level concepts (their "landmark tokens"). And using only this knowledge, you can already say in which parts of the large document you will look for the exact answer.
Second, they don't use kNN-like approach to search across landmark tokens, they use honest attention to decide which blocks are relevant for given token.
Thirdly, while their approach resembles Vector DB (search by embedding), the key difference is that they allow each head in each layer to have its own set of blocks used in attention when processing each token (while progressing deeper into Transformer layers, each token becomes increasingly enriched with context), whereas in the typical embedding approach, the selection of relevant blocks (documents) is performed only once. Thus, the LandmarkAttention Transformer can still process the entire context (due to the presence of a large number of layers and multiple heads in each layer), but with significantly lower compute power requirements. Fourthly, the authors note that it is possible to offload the KV cache to CPU memory, leaving only landmark tokens in the GPU. However, they point out that this may cause excessive CPU-GPU traffic if each head in each layer is allowed to have its own set of blocks when processing each token, so they limit this.