Scaling MLPs: A Tale of Inductive Bias — part 1/4

Cleaned-text code points [0, 15347). Bibliography omitted here; source.md includes it.

# Scaling MLPs: A Tale of Inductive Bias

###### Abstract

In this work we revisit the most fundamental building block in deep learning, the multi-layer perceptron (MLP), and study the limits of its performance on vision tasks. Empirical insights into MLPs are important for multiple reasons. (1) Given the recent narrative "less inductive bias is better" , popularized due to transformers eclipsing convolutional models, it is natural to explore the limits of this hypothesis. To that end, MLPs offer an ideal test bed, as they lack any vision-specific inductive bias. (2) MLPs have almost exclusively been the main protagonist in the deep learning theory literature due to their mathematical simplicity, serving as a proxy to explain empirical phenomena observed for more complex architectures. Surprisingly, experimental datapoints for MLPs are very difficult to find in the literature, especially when coupled with large pre-training protocols. This discrepancy between practice and theory is worrying: Do MLPs reflect the empirical advances exhibited by practical models? Or do theorists need to rethink the role of MLPs as a proxy? We provide insights into both these aspects. We show that the performance of MLPs drastically improves with scale ( 95 % 95\% on CIFAR10, 82 % 82\% on CIFAR100, 58 % 58\% on ImageNet ReaL), highlighting that lack of inductive bias can indeed be compensated. We observe that MLPs mimic the behaviour of their modern counterparts faithfully, with some components in the learning setting however exhibiting stronger or unexpected behaviours. Due to their inherent computational efficiency, large pre-training experiments become more accessible for academic researchers. All of our experiments were run on a single GPU.

## 1 Introduction

Deep learning has undergone tremendous empirical progress in the last decades. The dominant approaches in practice these days rely on very large, pre-trained models which are then fine-tuned to the specific task at hand. For natural language processing, these models usually are some variant of the Transformer architecture ( Vaswani et al.,, 2017 ) , while in computer vision, both convolutional and transformer-based models are very popular ( He et al.,, 2015 ; Tan and Le,, 2020 ; Dosovitskiy et al.,, 2021 ) . The theoretical understanding of these advances on the other hand remains very poor and the gap between the world of theory and practice is growing at an alarming rate. One aspect of this gap is the family of models investigated; due to their mathematical simplicity, theoretical works largely focus on simple multi-layer perceptrons (MLPs). Consisting of a series of unstructured matrix multiplications, interleaved with element-wise non-linearities, the MLP serves as an ideal test bed to analyze empirical phenomena exhibited by more complicated models employed in practice. Due to their inferior performance, MLPs are rarely used and very little is known regarding their behaviour in more modern settings. For instance, to the best of our knowledge, there is not a single published result showcasing an MLP trained on ImageNet1k, the de-facto standard benchmark in vision, let alone any pre-training/transfer learning studies. This lack of empirical data is concerning as theory aims to understand the characteristics of modern architectures through the lens of MLPs, yet only little assessments are made regarding how well such a proxy works. This raises the question, Do MLPs reflect the empirical advances exhibited by practical models? (1) Investigating MLPs is not only interesting for theory but also for practice. With the Vision Transformer (ViT) outperforming its convolutional competitors in very large-scale settings, the role of inductive bias has recently been brought into question. Since a ViT is equipped with significantly less inductive bias for vision compared to convolutional models (e.g. it lacks translation-equivariance) a novel narrative has recently emerged: At large scales of compute, having less inductive bias is beneficial for performance. (2) More evidence for this hypothesis has been collected in the form of the MLP-Mixer ( Tolstikhin et al.,, 2021 ) , an architecture with arguably even less inductive bias, solely relying on multi-layer perceptrons as patch processors and mixers. The MLP architecture is the ideal candidate to test the limits of such a hypothesis, as it exhibits the least inductive bias for vision due to its invariance to permutations of pixels. Unfortunately, the scale where Transformers and MLP-Mixers start to outperform convolutional models is out of reach for most researchers, requiring billions of annotated images and thousands of TPUs. We thus expect similar required scales for MLPs and hence instead investigate the following, weaker hypothesis: Lack of inductive bias can be compensated by scaling compute. (3) i.e. we aim to measure to what degree a lack of inductive bias hinders performance even if a model is subjected to a large parameter count and trained on datasets with many examples (albeit smaller than what is employed in Dosovitskiy et al., (2021) ).

In this work, we provide answers to question 1 and provide further evidence for hypothesis 2 and 3 by investigating how far we can push the empirical performance of models solely built from composing several MLP blocks. We give largely positive answers to question 1 , observing that MLPs behave very similarly to their modern counterparts when subjected to scale, i.e. their performance increases predictably as a power law in parameter count and sample size, akin to Hestness et al., (2017) ; Hestness et al., (2019) ; Kaplan et al., (2020) ; Zhai et al., (2022) (see e.g. Fig. 1 ). In contrast to previous work however, we find that compute-optimal MLPs allocate their budget more strongly into sample size, highlighting again their small inductive bias. While regularization in the form of data augmentation is also helpful for CNNs, its role is significantly amplified for MLPs even at large sample sizes, leading to fatal degradation if turned off. We further investigate how the implicit bias of SGD affects performance, and we make a very counter-intuitive discovery: contrary to CNNs, we find that larger batch sizes generalize significantly better for MLPs. This result questions the validity of the proxy role that the MLP plays in theoretical works investigating the implicit bias of SGD. While, as expected, the scale employed in this work does not suffice for hypothesis 2 , we provide strong evidence for 3 , which we view as an important first step. We observe that enough scale indeed suffices to overcome the bad inductive bias present in MLPs, leading to surprisingly strong downstream performance, e.g. ≈ 95 % \approx 95\% on CIFAR10, ≈ 82 % \approx 82\% on CIFAR100 and ≈ 58 % \approx 58\% on ImageNet ReaL. In summary, we make the following contributions: • We fill the gap between theory and practice, providing the first results for MLPs trained in modern settings.

• We show that MLPs mostly behave comparably to their modern counterparts, making them a good proxy for theory. We observe however that the roles of regularization and implicit bias of SGD significantly differ and theory hence needs to adapt.

• We provide further evidence that inductive bias is not crucial at large scales, showing that even "bad" architectures like MLPs can achieve strong downstream performance. We however identify a shift in compute-optimality, showing that optimal MLPs invest their compute significantly more into dataset size compared to model size.

## 2 Background

#### Theoretical Works.

The MLP has served as the main object of study for theoretical works in deep learning across different domains. The cornerstone results for areas such as convergence of SGD-trained neural networks ( Mei et al.,, 2018 ; Du et al.,, 2019 ; Zou et al.,, 2020 ; Li and Yuan,, 2017 ; Saxe et al.,, 2014 ) , most generalization bounds ( Arora et al., 2019b, ; Mei and Montanari,, 2021 ; Jacot et al.,, 2018 ; Allen-Zhu et al., 2019a, ) , the benefits of overparametrization ( Neyshabur et al.,, 2019 ; Allen-Zhu et al., 2019b, ; Arora et al.,, 2018 ) , the implicit bias of SGD towards favourable solutions ( Soudry et al.,, 2018 ; Neyshabur et al.,, 2014 ; Chizat and Bach,, 2020 ) , signal propagation properties ( Poole et al.,, 2016 ; Schoenholz et al.,, 2017 ) and scaling laws ( Bahri et al.,, 2021 ; Maloney et al.,, 2022 ) are all largely obtained for MLPs. To quote the very influential Principles of Deep Learning Theory book ( Roberts et al.,, 2022 ) : "MLPs are the simplest of these neural network architectures that hinge on this stacking idea, and thus provide a minimal model for an effective theory of deep learning." There are also several theoretical works studying more modern setups such as convolutional or transformer-based networks including Arora et al., 2019a () ; Gunasekar et al., (2018) ; Brutzkus and Globerson, (2017) ; Hron et al., (2020) to name but a few, but the main theoretical focus to the best of our knowledge still remains on the MLP architecture. We thus believe it is important to explore the limits of such a theoretical proxy in realistic settings.

#### MLPs.

The multi-layer perceptron has its origins in Rosenblatt, (1958) , serving as an extension to the classic Perceptron with its hidden layers however fixed to random initialization. Ivakhnenko et al., (1965) devised the first method to update the hidden layers through self-organization . Amari, (1967) then introduced the idea to train the parameters with stochastic gradient descent. Mathematically, an MLP of depth L ∈ ℕ L\in\mathbb{N} can be described very efficiently; given an input 𝒙 ∈ ℝ d \bm{x}\in\mathbb{R}^{d} , it applies a series of linear transformations, interleaved with an element-wise non-linearity σ : ℝ → ℝ \sigma:\mathbb{R}\xrightarrow{}\mathbb{R} : 𝒛 ( l ) = 𝑾 ( l ) ​ 𝒙 ( l − 1 ) → 𝒙 ( l ) = σ ⁡ ( 𝒛 ( l ) ) \bm{z}^{(l)}=\bm{W}^{(l)}\bm{x}^{(l-1)}\hskip 5.69054pt\xrightarrow{\makebox[14.22636pt]{}}\hskip 5.69054pt\bm{x}^{(l)}=\sigma\left(\bm{z}^{(l)}\right) where we define 𝒙 ( 0 ) := 𝒙 \bm{x}^{(0)}:=\bm{x} and 𝑾 ( l ) ∈ ℝ d l × d l − 1 \bm{W}^{(l)}\in\mathbb{R}^{d_{l}\times d_{l-1}} for l = 1 , … , L l=1,\dots,L are the learnable weight matrices. For the sake of readability, we omit the biases. This mathematical simplicity makes the MLP a very attractive model to study from a theoretical perspective (albeit still very far from trivial) and indeed many works frame their results around this more general model class. When used for vision, the input tensor 𝒙 ∈ ℝ h × w × 3 \bm{x}\in\mathbb{R}^{h\times w\times 3} is flattened into a vector vec ⁡ ( 𝒙 ) ∈ ℝ 3 ​ h ​ w \operatorname{vec}(\bm{x})\in\mathbb{R}^{3hw} and then passed through the MLP. Notice how such an architecture completely lacks locality and weight sharing, every unit simply processes the entire image at once. More worryingly, the vectorization vec \operatorname{vec} could be applied in any way, i.e. any permutation of 𝒙 \bm{x} looks identical to an MLP. We want to highlight that MLPs of course are not completely free of inductive bias, in the sense that they encourage learning a hierarchical feature structure. On the other hand, there is no vision-specific inductive bias present in MLPs, which is the main setting we investigate here. We refer to Battaglia et al., (2018) for a more in-depth treatment of inductive bias.

#### Convolutions.

The MLP is a very general model and has no structure built into it to make it more suitable for vision tasks. A convolution on the other hand was designed specifically for vision with desirable characteristics incorporated into the model. A convolution can be viewed as a special case of an MLP, where the weight matrix 𝑾 \bm{W} is very structured by being sparse and having shared entries, leading to spatially localized learning. This can be most easily illustrated in the case of convolving a 2 × 3 × 1 2\times 3\times 1 image 𝒙 \bm{x} with a 2 × 2 2\times 2 filter 𝒇 \bm{f} as the following matrix multiplication: 𝒇 ∗ 𝒙 = 𝑾 𝒇 ​ vec ⁡ ( 𝒙 ) = ( f 1 f 2 0 f 3 f 4 0 0 f 1 f 2 0 f 3 f 4 ) ​ vec ⁡ ( 𝒙 ) \bm{f}*\bm{x}=\bm{W}_{\bm{f}}\operatorname{vec}(\bm{x})=\begin{pmatrix}f_{1}&f_{2}&0&f_{3}&f_{4}&0\\ 0&f_{1}&f_{2}&0&f_{3}&f_{4}\end{pmatrix}\operatorname{vec}(\bm{x}) Here vec \operatorname{vec} denotes the standard, row-wise vectorization-scheme to flatten the image. Instead of operating with a dense matrix as the MLP, the convolution uses a structured matrix 𝑾 𝒇 \bm{W}_{\bm{f}} tailored to the task of vision, leading to a better inductive bias. Moreover, a convolution exhibits translation-equivariance, i.e. shifts of images are processed equivalently to the original. Crucially, in contrast to the MLP, a convolution severely suffers if a permutation is applied to the image.

#### Vision Transformer.

Inspired by the successes in NLP, recently the Transformer architecture has been adapted to vision ( Dosovitskiy et al.,, 2021 ) . An image 𝒙 ∈ ℝ h × w × 3 \bm{x}\in\mathbb{R}^{h\times w\times 3} is broken up into smaller patches (also called tokens) and each such patch is linearly embedded (see Fig. 2 ) and augmented with a so-called positional embedding, marking its spatial location in the image. The obtained embeddings are then processed by self-attention layers where patches can exchange information, and MLP layers, which are shared among patches and transform them individually. While the inductive bias of a ViT is certainly weaker compared to a CNN (it lacks translation-equivariance), the patching and parameter sharing still make the architecture suitable for vision.

#### MLP-Mixer.

Similar to the ViT, the MLP-Mixer also works with a patchified image ( Tolstikhin et al.,, 2021 ) . Unlike the ViT, token-mixing is not implemented using self-attention but rather another MLP block is used to exchange information between patches. We want to clearly highlight the difference between an MLP-Mixer and an MLP: An MLP-Mixer operates on patches, where in each block it applies a shared MLP to each patch for processing, and another MLP for mixing the patches along the channels. We visualize the differences in Fig. 3 for clarity. We again want to stress that breaking the image into patches and sharing parameters among them significantly enhances the amount of inductive bias, compared to a standard MLP.

#### Patchifiying.

As highlighted above, ViTs and Mixers largely obtain their inductive biases through breaking the images into patches. This choice seems to be beneficial even for architectures that already possess a strong inductive bias, such as the ConvMixer ( Trockman and Kolter,, 2022 ) , where convolutions are performed on individual patches. The very recent Metaformer ( Yu et al.,, 2022 ) further shows that even a simple spatial pooling instead of attention can lead to strong performance if the image is patchified. While the success of this mechanism certainly warrants further investigation, in this work we decided to deliberately focus on MLPs as they specifically lack this type of bias.

## 3 Architecture

We study different variants of the MLP architecture, starting from the standard vanilla setup and then adding more components such as residual connections and bottleneck layers.

#### Standard MLP.