↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Layer 1 of 12 Re(FT X FD) = CT X CD − ST X SD · no parameters · 0 tokens × 768 hidden dims
Loading recorded Fourier mixing…

What FNet is

FNet (Lee-Thorp et al., 2021) asks how much of a Transformer encoder's quality needs attention at all. It replaces each self-attention sublayer with a two-dimensional discrete Fourier transform, over the tokens and over the hidden dimensions, and keeps the real part. The transform has no parameters and does not look at the input to choose its weights. The paper reports 92–97 % of BERT's accuracy on the GLUE benchmark while training 80 % faster on GPUs and 70 % faster on TPUs at 512 input tokens.

The page records FNet-base, all 12 layers, on three short prompts. In each layer the Fourier sublayer's output is added to its input and normalised, then passed to an ordinary feed-forward layer, which is where all the learned computation happens.

The discrete Fourier transform as a matrix

The DFT of a sequence is

so it is a fixed matrix , with and . Row measures how much the sequence varies at frequency , that is cycles across the positions; row 0, labelled DC, simply adds everything up. The head card draws or for the prompt's tokens (its pager switches between the cos and sin parts), one row per frequency, and the plot beside it overlays the selected row on its continuous wave.

Two transforms, one real part

FNet applies the DFT along both axes of the layer input , a table: over tokens with and over hidden dimensions with . Multiplying out and keeping the real terms gives

That is the page read from left to right: Token mixing applies (or ) over tokens, Hidden mixing applies the matching 768-point (or ), and Real part shows the recorded output, the cos product minus the sin product. The recorded output matches the recomputed products to a relative error of about . Because the DFT sums rather than averages, the values grow large, up to 2,571 in this recording; the LayerNorm after the residual brings them back to scale.

Mixing without attention

Every output token is a weighted sum of every input token, as in attention, but the weights are the same for every input: no queries, no keys, no softmax, and no mask, since FNet is an encoder that reads the whole text at once. What makes the model work is the alternation. The Fourier sublayer spreads information across all positions and dimensions, and the learned feed-forward layers decide what to do with it. Position is built in, because shifting the input changes the phase of every frequency; FNet-base also adds learned position embeddings before layer 1, as BERT does.

The fast Fourier transform (Cooley and Tukey, 1965) computes each transform in steps, against the scores of attention. On the long inputs of the Long Range Arena benchmark the paper found FNet as accurate as the most accurate efficient Transformers and, on GPUs, faster than the fastest at every sequence length.

Where it came from

Synthesizer (Tay et al., 2020) had already found that attention weights learned without any token-to-token comparison, even random fixed ones, do surprisingly well; FNet went further, with no learned mixing weights at all. MLP-Mixer (the Mixer tab) learns its token-mixing matrix for images instead; Global Filter Networks (Rao et al., 2021) multiply in the Fourier domain by learned filters; and Hyena (the Hyena tab) uses the FFT to apply long learned convolutions. PoolFormer (the PoolFormer tab) takes the question to its limit for images with plain average pooling.

Papers

  1. FNet: Mixing Tokens with Fourier Transforms James Lee-Thorp, Joshua Ainslie, Ilya Eckstein, Santiago Ontanon · NAACL 2022 Self-attention replaced by the real part of a 2-D Fourier transform, the model recorded here.
  2. BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding Jacob Devlin, Ming-Wei Chang, Kenton Lee, Kristina Toutanova · NAACL 2019 The Transformer encoder FNet keeps apart from attention, and the baseline it is compared with.
  3. An algorithm for the machine calculation of complex Fourier series James W. Cooley, John W. Tukey · Mathematics of Computation 1965 The fast Fourier transform, which computes FNet's mixing in N log N steps.
  4. Synthesizer: Rethinking Self-Attention in Transformer Models Yi Tay et al. · ICML 2021 Attention weights synthesised without token-to-token comparison, including fixed random ones.
  5. Global Filter Networks for Image Classification Yongming Rao, Wenliang Zhao, Zheng Zhu, Jiwen Lu, Jie Zhou · NeurIPS 2021 Learned filters applied in the Fourier domain: FNet's transform with trainable weights, for images.
  6. Attention Is All You Need Ashish Vaswani et al. · NeurIPS 2017 The Transformer whose self-attention sublayer FNet replaces.

See also