Mixture-of-Depths: Dynamically allocating compute in transformer-based language models

David Raposo, Sam Ritter, Blake Richards, Timothy Lillicrap, Peter Conway Humphreys +1 more
4/2/2024
cs.LGcs.CL

No official code found. Best implementation: astramind-ai/Mixture-of-depths (177 stars, last commit 2024-06-20). 3 more below.

Abstract

Transformer-based language models spread FLOPs uniformly across input sequences. In this work we demonstrate that transformers can instead learn to dynamically allocate FLOPs (or compute) to specific positions in a sequence, optimising the allocation along the sequence for different layers across the model depth. Our method enforces a total compute budget by capping the number of tokens ($k$) that can participate in the self-attention and MLP computations at a given layer. The tokens to be processed are determined by the network using a top-$k$ routing mechanism. Since $k$ is defined a priori, this simple procedure uses a static computation graph with known tensor sizes, unlike other conditional computation techniques. Nevertheless, since the identities of the $k$ tokens are fluid, this method can expend FLOPs non-uniformly across the time and model depth dimensions. Thus, compute expenditure is entirely predictable in sum total, but dynamic and context-sensitive at the token-level. Not only do models trained in this way learn to dynamically allocate compute, they do so efficiently. These models match baseline performance for equivalent FLOPS and wall-clock times to train, but require a fraction of the FLOPs per forward pass, and can be upwards of 50\% faster to step during post-training sampling.

View on arXivView PDF

Code Implementations(4)

MIT

Implementation of the paper: "Mixture-of-Depths: Dynamically allocating compute in transformer-based language models"

1227Shell, PythonApr 5, 20246 months agoMIT
Apache-2.0

Jax module for the paper: "Mixture-of-Depths: Dynamically allocating compute in transformer-based language models"

30Shell, PythonApr 10, 20242 years agoApache-2.0

Unofficial implementation for the paper "Mixture-of-Depths: Dynamically allocating compute in transformer-based language models"

17715PythonApr 12, 20242 years ago

An unofficial implementation of "Mixture-of-Depths: Dynamically allocating compute in transformer-based language models"

354Python, Jupyter NotebookApr 6, 20242 years agoNOASSERTION

Similar Papers

Cite this paper

@article{raposo2024mixtureofdepths,
  title  = {Mixture-of-Depths: Dynamically allocating compute in transformer-based language models},
  author = {David Raposo and Sam Ritter and Blake Richards and Timothy Lillicrap and Peter Conway Humphreys and Adam Santoro},
  year   = {2024},
  eprint = {2404.02258},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2404.02258v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2404.02258.svg)](https://codeofpaper.com/paper/2404.02258)

Discussion