Efficient Methods for Natural Language Processing: A Survey

Abstract Recent work in natural language processing (NLP) has yielded appealing results from scaling model parameters and training data; however, using only scale to improve performance means that resource consumption also grows. Such resources include data, time, storage, or energy, all of which are naturally limited and unevenly distributed. This motivates research into efficient methods that require fewer resources to achieve similar results. This survey synthesizes and relates current methods and findings in efficient NLP. We aim to provide both guidance for conducting NLP under limited resources, and point towards promising research directions for developing more efficient methods.


Introduction
Scaling has become a key ingredient in achieving state-of-the-art performance in NLP (Fig. 1), as recent research suggests that some capabilities only emerge once models grow beyond a certain size (Wei et al., 2022b).However, despite the merits of scaling, it poses key challenges to making these breakthroughs accessible in resource constrained environments (Ahmed and Wahed, 2020); in having a non-negligible environmental impact (Strubell et al., 2019;Schwartz et al., 2020a;Derczynski, 2020;Patterson et al., 2021;Wu et al., 2022a); and in complying with hardware constraints (Thompson et al., 2020).To tackle these limitations, there has been renewed focus around research that seeks to improve model efficiency.
Definition Efficiency is characterized by the relationship between resources going into a sys-tem and its output, with a more efficient system producing the same output with fewer resources.Schwartz et al. (2020a) formalize efficiency as the cost of a model in relation to the results it produces: Cost(R) ∝ E • D • H, i.e., the Cost(•) of producing a certain NLP (R)esult as proportional to three (non-exhaustive) factors: (1) The cost of model execution on a single (E)xample, (2) the size of the (D)ataset and (3) the number of training runs required for (H)yperparameter tuning.Here we take a different approach, and consider the role efficiency plays across the different steps in the NLP pipeline, by providing a detailed overview of efficiency methods specific to NLP (Fig. 2).

Scope of this survey
We address this work to two groups of readers: (1) Researchers from all fields of NLP working with limited resources; and (2) Researchers interested in improving the state of the art of efficient methods in NLP.Each section concludes with a discussion of limitations, open challenges, and possible future directions of the presented methods.We start by discussing methods to increase data efficiency (Sec.2), and continue with methods related to model design (Sec.3).We then consider efficient methods for the two typical training setups in modern NLP: pre-training (Sec.4) and fine-tuning (Sec.5).We then discuss methods for making inference more efficient (Sec.6).While we mainly focus on algorithmic approaches, we provide appropriate pointers regarding hardware that are connected to the scale at which we expect to deploy a model (Sec.7).We then discuss how to quantify efficiency and what factors to consider during evaluation (Sec.8), and finally-how to efficiently decide upon the best suited model (Sec.9).
To guide the reader, Fig. 3 presents a typology of efficient NLP methods considered in this survey.Figure 1: Exponential growth in the number of parameters in pretrained language models.Adapted from Lakim et al. (2022).

Data
Data efficiency is improved by using fewer training instances, or by making better use of available instances.Fixed compute budgets motivate balancing model size and training data size, especially during pre-training (Hoffmann et al., 2022).

Filtering
Improving data quality can boost performance while reducing training costs during pre-training and fine-tuning.For instance, Lee et al. (2022b) showed that removing duplicates in pre-training increases training efficiency, giving equal or even better model performance compared to using all data.Zhang et al. (2022) used MinhashLSH (Leskovec et al., 2020) to remove duplicates while developing OPT.De-duplication can lead to substantially reduced computation cost, especially in cases with abundant pre-training data but limited compute budget (Hoffmann et al., 2022).
Similar observations have been made for finetuning.For instance, Mishra and Sachdeva (2020) found-via adversarial filtering (Zellers et al., 2018)-a subset of only ∼2% of the SNLI data (Bowman et al., 2015) that leads to performance comparable to using the full corpus.While such filtering approaches are useful for mitigating biases (Le Bras et al., 2020), they may not always serve as tools to filter existing datasets, as these often suffer from insufficient training data.

Active Learning
Active learning aims to reduce the number of training instances.In contrast to filtering, it is applied during data collection (instead of after) to only annotate the most helpful or useful instances for training (Settles, 2012;Ren et al., 2021b).To assess usefulness of an instance without knowing its actual label, one can use the model uncertaintyassuming that labeling instances with the highest uncertainty is most helpful (Lewis and Gale, 1994;Tang et al., 2002;Gal et al., 2017;Yuan et al., 2020); instance representativeness-to maximize diversity of sampled instances while avoiding outliers (Bodó et al., 2011;Sener and Savarese, 2018;Gissin and Shalev-Shwartz, 2019); or a combination of both criteria (Kirsch et al., 2019;Ash et al., 2020;Margatina et al., 2021;Siddiqui et al., 2021;Agarwal et al., 2022).Active learning has been successfully applied in machine translation (MT, Liu et al. 2018), language learning (Lee et al., 2020), entity linking (Klie et al., 2020), and coreference resolution (Li et al., 2020a;Yuan et al., 2022).Despite its advantages, some open questions make active learning difficult to apply in practice.It remains unclear how model-based sampling impacts the performance of models using architectures different from that in sampling (Lowell et al., 2019;Ein-Dor et al., 2020).Also, selecting "difficult" instances may increase annotation cost and difficulty (Settles et al., 2008;Lee et al., 2022a).Finally, it is prone to selection biases and can favor outliers (Cortes et al., 2008;Karamcheti et al., 2021).

Curriculum Learning
Curriculum learning aims to find a data ordering that reduces the number of training steps required to achieve a target performance (Elman, 1993;Bengio et al., 2009).This method does not reduce dataset size, but does improve its utilization.Hence, it is a common approach for improving training efficiency in both pre-training and fine-tuning.Many curriculum learning methods order instances by difficulty, using heuristics such as sentence length.This has yielded improvements for transformer pretraining (Press et al., 2021;Agrawal et al., 2021) as well as fine-tuning on tasks such as question answering (Tay et al., 2019), MT (Zhang et al., 2019), and others (Xu et al., 2020).
A major challenge in curriculum learning is determining pace, i.e., when to progress to more difficult instances.If not chosen carefully, curriculum learning can waste compute on "easy" instances.To tackle this, work has investigated adaptive ordering strategies based on current model state, called self-paced learning (Kumar et al., 2010).This has been successfully applied to improve performance Notably, the training stage is divided into two parts: pre-training, which aims to learn generalizable parameters, and fine-tuning, which optimizes these parameters for specific downstream tasks.
Figure 3: Typology of efficient NLP methods.
in MT using model and data uncertainty (Wan et al., 2020;Zhou et al., 2020;Zhao et al., 2020), and in dialog generation with knowledge distillation (Zhu et al., 2021).However, self-paced learning involves large training costs, and disentangling instance ordering from factors such as optimizer choice and batch size is non-trivial (Dodge et al., 2020).

Estimating Data Quality
In an era of ever larger datasets, auditing and estimating the quality of data is increasingly challenging.Datasets frequently present high levels of noise and misaligned instances (Kreutzer et al., 2022).Estimating data quality encompasses research efforts which propose better uncertainty estimates (Baldock et al., 2021;D'souza et al., 2021;Ethayarajh et al., 2022) as well as analytical tools such as dataset cartography (Swayamdipta et al., 2020).Qualitative tools include documentation for datasets and model attributes (Gebru et al., 2021).

Model Design
Efficient model design covers architectural changes and adding new modules to accelerate training.

Improving Attention in Transformers
The transformer's self-attention mechanism has a quadratic dependency on sequence length which is not fully utilized by existing models (Hassid et al., 2022).To reduce computational costs, efficient attention mechanisms for long sequences have been proposed (Tay et al., 2022).Existing strategies include better using already processed segments via recurrence to connect multiple segments (Dai et al., 2019), learning a network to compress a longer-term memory (Rae et al., 2020), separately modeling global and local attention (Ainslie et al., 2020), and modeling long inputs as a continuoustime signal (Martins et al., 2022b).Another line of research uses fixed attention patterns, where tokens attend to their immediate context (local attention) and possibly to a few global positions (global attention; Beltagy et al., 2020;Zaheer et al., 2020;Child et al., 2019).Compared to using the full selfattention matrix, such approaches can scale linearly with the input length.Some methods learn attention sparsity patterns directly from data, e.g. by grouping tokens into buckets, leading to a more accurate yet more expensive approximation of the full attention matrix (Kitaev et al., 2020;Daras et al., 2020;Roy et al., 2021).Instead of seeking better attention patterns, some strategies modify the attention mechanism and derive low-rank approximations to the querykey matrices via reverse application of the kernel trick, resulting in linear time attention (Katharopoulos et al., 2020;Choromanski et al., 2021;Peng et al., 2020;Zhai et al., 2021).Recently, IO-aware attention mechanisms have been proposed, decreasing reads and writes to the attention matrix to GPU high-bandwidth memory (Dao et al., 2022b).
Despite various improvements in attention mechanisms, most of them struggle with very long sequences (Tay et al., 2021).S4 (Gu et al., 2022b), and its successors (Gupta et al., 2022;Mehta et al., 2023;Gu et al., 2022a), suggest an alternative to transformers that alleviates the short memory problem and the quadratic bottleneck cost of self-attention by discretizing state space representations through parameterization of the state matrix.More recently, Mega (Ma et al., 2023) replaced the multi-headed transformer attention mechanism with a single-headed mechanism that receives contextualized vectors from a multidimensional exponential moving average module, and then splits the input into multiple fixed-length chunks to reduce the computation cost.Both S4 and Mega strongly outperform attention-based methods on all tasks of the Long Range Arena benchmark (Tay et al., 2021), while increasing training speed by approximately 5x and reducing memory cost by about 15% when compared to a standard transformer.This success is attributed to their convolutional structure, which emphasizes nearby tokens and has a parameter count that grows sub-linearly with sequence length (Li et al., 2022b).

Sparse Modeling
To leverage sparsity for efficiency, many models follow the mixture-of-experts (MoE) concept (Jacobs et al., 1991;Shazeer et al., 2017;Fedus et al., 2022a), which routes computation through small subnetworks instead of passing the input through the entire model.Relevant works on this line include GShard (Lepikhin et al., 2021), Switch Transformer (Fedus et al., 2022b), and ST-MoE (Zoph et al., 2022), which replace the feed forward layers in transformers with MoE layers.More recently, Rajbhandari et al. (2022) scaled transformers up by compressing and optimizing the usage of MoE.Overall, MoE models have been shown to achieve strong performance across several NLP tasks while reducing the overall resource consumption (Sec.8).For instance, GLaM (Du et al., 2022) used only ∼ 1 3 of GPT-3's energy consumption (with additional hardware-based optimization), while Rajbhandari et al. (2022) reached a 5x reduction in terms of training cost.However, MoE models have also exhibited training instabilities in practice, and may require architecture-specific implementation (Zoph et al., 2022;Mustafa et al., 2022).
Another promising direction for exploiting sparse modeling is Sparsefinder (Treviso et al., 2022), which extends the Adaptively Sparse Transformer (Correia et al., 2019) to allow a more efficient attention mechanism by identifying beforehand the sparsity pattern returned by entmax attention-a sparse alternative to (dense) softmax attention (Peters et al., 2019).Finally, sparsity can also be induced via modularity, e.g., by encapsulating task-specific parameters (Ponti et al., 2022).

Parameter Efficiency
Methods that reduce parameter count can reduce computational costs and memory usage.One such approach is to share weights across layers of a model while maintaining the downstream task performance (Dehghani et al., 2019;Lan et al., 2019).Besides sharing weights, Perceiver (Jaegle et al., 2021) also minimizes the computational cost of self-attention on long sequences by mapping the input to a small latent vector.ALBERT (Lan et al., 2019) further uses matrix decomposition to reduce the size of the embedding layer, which is one of the largest consumers of model parameters.Finally, Reid et al. (2021) studied ways to share weights in transformers, showing that sharing only the middle layers of the model outperforms the alternatives.

Retrieval-Augmented Models
Parametric models can be combined with retrieval mechanisms for text generation, leading to semiparametric models (Gu et al., 2018;Lewis et al., 2020b;Li et al., 2022a).This typically amounts to trading model size with the number of database entries.For instance, RETRO (Borgeaud et al., 2022) matched the performance of models 25 times larger, by retrieving chunks of tokens from a 2 trillion token database.At inference time, the model retrieves tokens / phrases / sentences from a database, which are used by the model through a combination of probability distributions (Khandelwal et al., 2020), gating mechanisms (Yogatama et al., 2021), or attention (Borgeaud et al., 2022).
These models also have good generalization properties: by retrieving from domain-specific databases, they can be applied to new domains, reducing the need for domain-specific fine-tuning (Khandelwal et al., 2020(Khandelwal et al., , 2021)).That is, having an explicit "memory" also allows retrieval-augmented models to be adapted post-training.Although they may yield slow running speeds as the retrieval time grows as the datastore scales, recent works proposed strategies to alleviate this, such as pruning the database (He et al., 2021), having smaller input-dependent databases (Meng et al., 2022), reducing the representation dimension (Martins et al., 2022a), and clustering data points (Wang et al., 2021b;Alon et al., 2022).In particular, Martins et al. (2022c) have shown that carefully constructing a database not only leads to better translations than fine-tuning, but can also reduce the total translation time (inference + online adaptation).

Model Design Considerations
Despite considerable advances, one major challenge is modeling long sequences in many realworld documents.For instance, sustainability reports have on average 243.5 pages (Manes-Rossi et al., 2018) which substantially exceeds the maximum length (16k tokens) found in Path-X from Long Range Arena (Tay et al., 2021).In fact, the ability of a model to handle longer sequences than those seen during training may depend on design choices, such as the attention mechanism (Dubois et al., 2020) and the positional encoding (Shaw et al., 2018;Press et al., 2022).The effect of this behavior when using transformers with sub-quadratic attention, sparse modeling approaches, or parameter efficient models is not yet well-understood.
While sparse modeling approaches like MoE can substantially reduce inference and training costs, they require additional model parameters for retraining specialized modules and have instability issues during training (Zoph et al., 2022).Models that rely on built-in sparse transformations, such as entmax (Peters et al., 2019), have achieved strong results without stability issues, but have not yet fully realized competitive efficiency gains.Combining MoE with built-in sparse functions may be a promising research direction, e.g., by using entmax in the routing layer.
In retrieval-augmented models, the quality of the retrieval component is critical to performance, and the tradeoff between storing information in model parameters vs. external resources needs to be better understood, especially when deploying models in low-resource settings like edge devices.Finally, while new model designs improve efficiency through different means, further improvements can emerge from combining approaches, such as making MoE more efficient using quantization (Sec.6.3) and using parameter-efficient models for distillation (Sec.6.2).

Pre-training
Modern transfer learning approaches in NLP typically involve pre-training a model in a selfsupervised fashion on large amounts of text before fine-tuning it on specific tasks (Sec.5).Improving the pre-training procedure of a model can significantly reduce the cost of hyperparameter tuning and increase data efficiency for fine-tuning (Peters et al., 2018;He et al., 2019;Neyshabur et al., 2020).

Optimization Objective
The choice of the task can determine the success of the pre-trained model on downstream tasks.Leftto-right language models, such as GPT (Radford et al., 2019;Brown et al., 2020) and PaLM (Chowdhery et al., 2022), are trained with the causal language modeling (CLM) objective, which involves predicting the next token given a context.BERT (Devlin et al., 2019) uses a masked language model (MLM) task, which involves filling randomly masked tokens.
To make better use of available data, various masking strategies have been investigated.Masking objects and content words only rather than random tokens (Bitton et al., 2021) or masking more tokens (Wettig et al., 2022) has led to higher task performance and more efficient use of the available data.ELECTRA (Clark et al., 2020) and DeBERTa (He et al., 2023) tried replaced token detection (RTD), an objective that uses a small generator model to replace input tokens, and converges more quickly to better performance.A limitation of the MLM and RTD objectives is that they work with single token replacements.T5 (Raffel et al., 2020) and BART (Lewis et al., 2020a) overcome this by adopting a denoising sequence-to-sequence objective to pretrain an encoder-decoder model, allowing the decoder to predict a span of tokens for masked positions.In practice, this allows training on shorter sequences without losing task performance, which helps to reduce training costs.

Pre-training Considerations
Despite increases in the size of pre-trained models (cf.Fig. 1), many pre-training efficiency gains come from improving model design (Sec.3) and selection (Sec.9) as well as making more efficient use of the available data (Sec.2).These factors have had a greater impact on model performance than the pre-training objective itself (Alajrami and Aletras, 2022).However, pre-training is usually computationally expensive, requiring significant amounts of GPU memory and computational power (Rae et al., 2021), and may require large amounts of quality data which can be difficult to acquire and curate (Kaplan et al., 2020).Surprisingly, as demonstrated by Chinchilla (Hoffmann et al., 2022), decreasing model size to account for the amount of available data not only leads to better performance, but also reduces computational cost and improves model applicability to downstream tasks.Continued focus on the role of data in efficient pre-training is a promising direction, such as recent work studying the role of (de-)duplication of examples in large scale pretraining corpora (Lee et al., 2022b).While transformers have been the dominant architecture in pre-trained models, more efficient modeling methods such as state space representations and MoEs (Sec.3.1) have the potential to overcome some challenges of pre-training transformers.

Fine-tuning
Fine-tuning refers to adapting a pre-trained model to a new downstream task.While some approaches explicitly aim to make the fine-tuning process more efficient, in this survey, we use a broader definition of fine-tuning that includes any method used to apply a pre-trained model to a downstream task.

Parameter-Efficient Fine-Tuning
Gradient-based fine-tuning typically involves training all model parameters on a downstream task.Hence, fine-tuning a pre-trained model on a new task creates an entirely new set of model parameters.If a model is fine-tuned on many tasks, the storage requirements can become onerous.Adapting a pre-trained model to downstream tasks by training a new classification layer and leaving the rest of the parameters fixed (aka feature extraction, Peters et al., 2018) updates dramatically fewer parameters than training the full model but has been shown to produce worse performance and has become less common (Devlin et al., 2019).
Several approaches have been proposed to adapt a model to a new task while only updating or adding a relatively small number of parametersup to four orders of magnitude fewer parameters than full-model fine-tuning-without sacrificing (and in some cases improving) performance.Adapters (Houlsby et al., 2019;Bapna and Firat, 2019;Rebuffi et al., 2017;Pfeiffer et al., 2020) inject new trainable dense layers into a pre-trained model, while leaving the original model parameters fixed.They have recently been improved by the Compacter method (Karimi Mahabadi et al., 2021), which constructs the adapter parameter matrices through Kronecker products of low-rank matrices.While adapters can reduce training time due to a reduced number of trained parameters, and mitigate some deployment costs due to reduced storage requirements, one shortcoming is increased inference time due to more parameters (Rücklé et al., 2021).To mitigate this, Moosavi et al. (2022) proposed training an additional layer selector, to only use adapter layers necessary for a given task.
As an alternative to adding new layers, parameter-efficiency can be achieved by directly modifying activations with learned vectors, either by concatenation (Liu et al., 2021a;Li and Liang, 2021;Lester et al., 2021), multiplication (Liu et al., 2022a), or addition (Ben Zaken et al., 2022).Two notable approaches are prefix-tuning (Li and Liang, 2021) and prompt-tuning (Lester et al., 2021) which fine-tune continuous prompts as an alternative to engineering discrete prompts (cf.Sec.5.3).Although they are conceptually similar to adapters, He et al. (2022b) show that they are equivalent to a parallel insertion whereas adapters are inserted sequentially.Alternatively, rather than adding new parameters or changing the computational graph, it is possible to make sparse (Sung et al., 2021;Guo et al., 2021) or low-rank (LoRA, Hu et al. 2022) updates.Finally, optimization can be performed in a low-dimensional subspace (Li et al., 2018), which leads to parameter-efficient updates (Aghajanyan et al., 2021b).Although low-rank approaches mitigate the issue of increased inference time, they require an additional optimization step to identify the best rank.To mitigate this, Valipour et al. (2022) proposed a dynamic solution that substantially reduces training time compared to LoRA.Lastly, Wang et al. (2022b) devised AdaMix to combine different parameter efficient fine-tuning techniques together via routing and showed that their approach can even outperform full fine-tuning.

Multi-Task and Zero-Shot Learning
While traditional transfer learning includes finetuning, there are other paradigms that allow for immediate application of a pre-trained model to a downstream task of interest.Multi-task learning (Caruana, 1997;Ruder, 2017) aims to train a single model that can perform a wide variety of tasks out of the box.Typically, this is done by fine-tuning on data from all downstream tasks of interest.Multi-task models can improve fine-tuning performance (Raffel et al., 2020;Aghajanyan et al., 2021a;Aribandi et al., 2022;Liu et al., 2022a).In certain cases, a multi-task model works on new tasks without any fine-tuning, also referred to as zero-shot generalization (Sanh et al., 2022;Wei et al., 2022a).Radford et al. (2017Radford et al. ( , 2019) ) and Brown et al. (2020) demonstrated that language models trained with an unsupervised objective can perform a variety of tasks out-of-the-box.While it can circumvent the need for fine-tuning, zero-shot ability depends on model size and only becomes competitive at a certain scale (Wei et al., 2022b).

Prompting
Inspired by models like GPT-3 (Brown et al., 2020), prompting refers to casting a task as a textual instruction to a language model (Liu et al., 2023).In general, prompts can be either crafted manually or automatically using fill-in templates for token, span, and sentence-level completion (Petroni et al., 2019;Brown et al., 2020;Shin et al., 2020).This makes prompting applicable to more challenging NLP tasks, such as QA, MT, and summarization (Schick and Schütze, 2021).Although prompting eliminates the need for any fine-tuning, identifying good prompts can be difficult (Liu et al., 2021a).Hence, recent works investigate the automated creation of suitable prompts, albeit with additional training cost (Bach et al., 2022).

Fine-Tuning Considerations
An emerging problem with large language models is the universally high cost of fully fine-tuning them (Chen et al., 2021).Although prompting (without fine-tuning) can alleviate this issue, designing prompts can be tedious-even with automated help.One promising direction for efficiently introducing new knowledge into models is to combine existing methods for efficient fine-tuning.This could involve methods such as Karimi Mahabadi et al. ( 2022), who proposed task-specific adapters to avoid generating prompts, and achieved considerable speed ups while tuning under 1% of parameters.Another challenge in adopting large pretrained models for fine-tuning is the complexity in interpreting the final model, due in part to the use transformers.To gain a better understanding of these models while still leveraging efficiency, a premising direction is to combine techniques such as sparse modeling and parameter-efficient methods (Correia et al., 2019;Treviso et al., 2022).

Inference and Compression
Inference involves computing a trained model's prediction for a given input.Inference can be made more efficient by accelerating the process for time efficiency (latency), or by compressing the model to reduce memory requirements.

Pruning
Proposed by LeCun et al. (1989), pruning removes irrelevant weights from a neural network to reduce computation, and furthermore, decreases memory capacity and bandwidth requirements.Pruning can be applied at different stages of the NLP pipeline (Fig. 2).For instance, Gordon et al. (2020) found that up to ∼40% of BERT can be pruned at pretraining without affecting its performance.Others proposed pruning methods that work as regularizers and can be applied to pre-training and finetuning (Louizos et al., 2018;Wang et al., 2020b).Finally, works investigated pruning during finetuning (Han et al., 2015;Sanh et al., 2020) or dynamically during inference (Fan et al., 2020).
Pruning was initially introduced at the individual weight level (unstructured pruning), but more recent approaches prune larger components of the network (structured pruning).Examples of the latter include removing attention heads (Voita et al., 2019;Michel et al., 2019), weak attention values (Ji et al., 2021;Qu et al., 2022), and even entire hidden layers (Dong et al., 2017;Sajjad et al., 2023).In particular, Xia et al. (2022) found that pruning all these components yields more accurate and efficient models.When comparing the two pruning approaches, unstructured pruning is often found to better preserve a model's performance (Gale et al., 2019;Ahia et al., 2021), but existing hardware often cannot exploit the resulting sparsity.In contrast, structured pruning methods often lead to a higher improvement in terms of inference speed (Hoefler et al., 2021).The increasing popularity of pruning methods has further raised the question of how to quantify and compare them (Gale et al., 2019;Blalock et al., 2020;Tessera et al., 2021;Hoefler et al., 2021) and motivated works that combine pruning with other efficiency methods such as adapters (Rücklé et al., 2021) and distillation (Zafrir et al., 2021).
While early pruning (e.g., during pre-training) can further reduce training costs, it increases the risk of over-pruning: removing nodes essential for downstream task performance (Gordon et al., 2020).Although this can be mitigated by "regrowing" pruned weights (Mostafa and Wang, 2019), this increases training costs.Other pruning downsides include additional costs for hyperparameter tuning such as the number of preserved weights.

Knowledge Distillation
The process of knowledge distillation uses supervision signals from a large (teacher) model to train a smaller (student) model (Hinton et al., 2015), and often leads to the student outperforming a similarlysized model trained without this supervision.While early works focused on distilling task-specific models (Kim and Rush, 2016), recent works focus on distilling pre-trained models that can then be finetuned on specific downstream tasks (Sanh et al., 2019;Liu et al., 2020;Jiao et al., 2020;Sun et al., 2020;Gou et al., 2021).The downsides of distillation include the added cost of tuning student hyperparameters and the potential for reduced performance and generalization capability (Stanton et al., 2021).Recently, Zhu et al. (2022) discovered that some performance loss is due to undistillable classes and suggested ways to address this.

Quantization
Mapping high-precision data types to low-precision ones is referred to as quantization.Quantization can be applied at different stages in the NLP model-building pipeline to reduce training and inference costs.Various research has shown that low-precision data format can reduce memory consumption by 4x-24x and improve the throughput by 4.5x compared to 32-bit floating point format.Various works targeted specific precision-levels such as integers (Kim et al., 2021), 8-bit (Quinn and Ballesteros, 2018;Zafrir et al., 2019;Bhandare et al., 2019;Prato et al., 2020;Dettmers et al., 2022a), ternary (Zhang et al., 2020;Ji et al., 2021;Zadeh et al., 2022), and even binary representations (Bai et al., 2021).
Different components may have a different sensitivities regarding their underlying precision, so there is a body of work on mixed-precision quantization.Shen et al. (2020) showed that embedding layers require more precise parameter representations than the attention layer, while Kim et al. (2021) showed that nonlinear functions require more bits than the general matrix multiplication.Others defined quantization as a constrained optimization problem to automatically identify layers where lower precision is sufficient (Hubara et al., 2021).Finally, several works proposed quantization during training to make them robust against performance loss after quantization (Zafrir et al., 2019;Kim et al., 2021;Stock et al., 2021).For instance, Bai et al. ( 2021) and Zhang et al. (2020) proposed using knowledge distillation to maintain the accuracy of binarized and ternarized models.These show that component-customized quantization can preserve accuracy while improving efficiency.To maximize the benefit from quantization, one should also consider the available underlying hardware and associated specialized kernels compatible with different bit representations (Noune et al., 2022;Kuzmin et al., 2022).

Inference Considerations
While efficiency during pre-training and finetuning focuses on the computational resources and time required to train and optimize a model, inference efficiency is focused on how well a learned model can perform on new input data in real-world scenarios.Moreover, inference optimization is ultimately context-specific and the requirements vary according to the use-case.Therefore, there is no one-size-fits-all solution to optimizing inference, but instead a plethora of techniques.For instance, while Wu et al. (2022b) combine several methods to achieve utmost model compression, other works improve task-specific mechanisms such as beam-search in MT (Peters and Martins, 2021).Parallelism can also be leveraged to increase inference efficiency, but its effectiveness may depend on the hardware available (Rajbhandari et al., 2022).Dynamic computation techniques, such as early-exit (Schwartz et al., 2020b;Xin et al., 2020) and mixture-of-experts (Sec.3.1), can improve inference efficiency by selectively performing computation only on the parts of the model that are needed for a given input.However, current dynamic computation methods often use eager execution mode, which can prevent them from low-level optimization, as noted by Xu and McAuley (2023).Work focusing on inference efficiency should carefully report the exact target setting (hardware, eager vs. static execution framework).Accordingly, promising directions for optimizing inference efficiency might consider tighter integration across or more general purpose approaches with respect to algorithm, software and hardware.One recent such example is neural architecture search for hardwarespecific efficient transformers (Wang et al., 2020a).

Hardware Utilization
Many hardware-specific methods focus on reducing GPU memory consumption, a major bottleneck in transformer models.Others leverage specialized hardware, co-design of hardware, and adaptations targeted to edge devices.Many techniques can be combined and applied across different stages of training and inference (Fig. 2) for further efficiency.

Reducing Optimizer Memory
Optimizers that track gradient history incur a memory cost.Libraries like DeepSpeed (Ren et al., 2021a) allow gradient history to be offloaded from GPU to CPU RAM where computation is performed via efficient AVX instructions.bitsandbytes (Dettmers et al., 2022b) uses dynamic block-wise quantization to reduce memory pressure.It splits tensors into blocks and quantizes each block individually.This reduces memory consumption by 75% and improves training times due to reduced inter-GPU communication.

Specialized Hardware
Specialized NLP hardware has been built using Application Specific Integrated Circuits or Field Programmable Gate Arrays, though it is not yet broadly available.These designs use dedicated units for efficient operations like quantization and pruning (Sec.6).For example, Zadeh et al. (2020Zadeh et al. ( , 2022)), Li et al. (2021), andQu et al. (2022) support ultra-low-bit and mixed precision computation that cannot be done on CPUs/GPUs; Ham et al. (2020Ham et al. ( , 2021) ) and Wang et al. (2021a) design hardware that predicts and prunes redundant heads/tokens and weak attention values in transformers.Qu et al. (2022) presents a design that balances the workload to alleviate the irregularity in the pruned attention.Others develop new types of processors and memories optimized for transformer components: Lu et al. (2020) and Liu et al. (2021b) implemented dedicated hardware for softmax and layer normalization respectively, and Tambe et al. ( 2021) used embedded Resistive RAM-a nonvolatile memory with low latency and energy consumption-to store word embeddings.

Co-design
Some works optimize hardware, software, and algorithms jointly, which historically has been a common way to realize efficiency gains (Hooker, 2021).For instance, Lepikhin et al. (2021) demonstrated that improving the underlying compiler can substantially improve parallelization and enable scaling.Other examples for co-design focus on hardware-aware mixture of experts models and attention mechanisms to produce substantial speedups (He et al., 2022a;Rajbhandari et al., 2022;Dao et al., 2022b).Barham et al. (2022) proposed a gang-scheduling approach with parallel asynchronous dispatch, that leads to substantial efficiency gains.Finally, Hinton (2022) suggested "mortal computation", an extreme form of co-design, where by training a model that is tailored to a specific hardware, the need to guarantee consistent software behavior across different hardware is reduced, potentially saving computation.

Edge Devices
Tight compute and memory constraints on edge devices motivate a separate set of efficiency solutions.SqueezeBERT (Iandola et al., 2020) incorporates group convolutions into self-attention to improve efficiency on mobile devices.EdgeFormer (Ge et al., 2022) interleaves self-attention layers with lightweight feed-forward layers and an encoder heavy parameterization to meet edge memory budgets.GhostBERT (Huang et al., 2021) uses ghost modules built on depth-wise separable convolutions used in MobileNets (Howard et al., 2017).LiteTransformer (Wu et al., 2020) uses long-short range attention to encode local context by convolutions for MT in resource-constrained settings.Through quantization llama.cpp1runs a 7B-parameter LLM on recent mobile phone hardware.Finally, ProFormer (Sankar et al., 2021) reduces runtime and memory via locality sensitive hashing and local projection attention layers.

Hardware Considerations
To deliver more computational power, vendors pack denser computational units into domain-specific hardware, such as tensor cores in Intel FPGAs, Xilinx AI Engines, and matrix processors in the Google TPU.However, irregularities in the transformer, like sparsity and mixed data types, restrict the use of these resources.We suggest focusing on adapting efficient transformers to existing specialized hardware platforms, including using hardwareoptimized data formats like block floating point, and exploring sparsity on dense tensor units.

Evaluating Efficiency
Evaluating efficiency requires establishing which computational aspect one aims to minimize.We discuss the two most prominent aspects (FLOP/s and power consumption), and list open challenges.

Evaluation Measures
Pareto optimality When improving efficiency, multiple factors often need to be traded-off.For instance, longer training time can increase task performance, but simultaneously increase resource consumption.A principled way to characterize trade-offs is to identify Pareto-optimal solutions (Pareto, 1896), those for which no other system reaches a better or equal task performance with lower resource consumption.As there may be several Pareto-optimal solutions, final choice depends on the application context; a small, average-quality model and a large, higher-quality model can both be optimal.Thus, as long as a model contributes to or extends the Pareto-optimal curve for a given problem and measurement space, it it worthwhileeven if other solutions may use less resources or produce higher quality scores.
Advancing NLP by pushing Pareto barriers is an established practice (Kim et al., 2019;Bogoychev et al., 2020;Behnke and Heafield, 2021).For instance, the WNGT 2020 MT shared task (Birch et al., 2020)  FLOP/s A frequently reported efficiency measure is the number of floating point operations (FLOPs) and floating points per second (FLOP/s).While these discrete metrics seem well-defined in terms of what the hardware does, there is some variation at multiple stages of the stack, adding uncertainty.For example, different operations may count as a FLOP on different hardware; non-floatingpoint operations are not considered; and hardware is rarely 100% utilised and achieving this productively is a challenge, so theoretical FLOP/s performance cannot be multiplied with time elapsed to yield the amount of computing performed.Still, FLOP/s per unit power can indicate which hardware choices have the potential to offer Paretoefficient trade-offs (Hsu et al., 2005).
Power consumption There exist various ways to measure power consumption, for instance, by using specific hardware such as an electricity meter.While this can provide precise figures with a high temporal accuracy, it cannot provide a fine-grained estimate for individual computers in a network.Moreover, it does not cover external energy costs such as cooling or networking.Another way is to use software tools such as MLCO2 (Luccioni et al., 2019).Some tools even provide a real-time breakdown of the power consumption of different components within a machine (Henderson et al., 2020) or local machine API-reported figures to stop training early if prudent (Anthony et al., 2020).Finally, Hershcovich et al. (2022) introduced a model card for NLP systems that encourages researchers to document efficiency in a consistent manner.
Measuring power consumption programmati-cally comes with a number of caveats.First, sampling frequency is often restricted at various levels of the stack and may result in a lag in measurement start.Consequently, shorter experiments may log an energy use of zero, and there will almost always be energy demand that is missed.Second, inefficiencies such as heat loss are not reported by current APIs and hence, do not cover cooling and other system management activities.Third, not all architectures and operating systems are supported.
For instance, power consumption under macOS is difficult to manage, and direct figures for TPU power consumption are not available.
Carbon emissions Carbon emissions are usually computed using the power consumption and the carbon intensity of the marginal energy generation used to run the program.Thus, low-energy does not mean low-carbon, and high-energy models can-in the right region and with some care-be zero-carbon in terms of point energy consumption impact, if executed at the right time (i.e., when the energy mix is low-carbon intensity, Dodge et al., 2022).For estimating the CO 2 emissions from a specific program execution, APIs such as Electric-ityMap 2 provide real-time access to carbon intensity for many regions.However, as carbon intensity varies and is affected by other factors like the power usage efficiency in a data center, it is often a poor basis for comparison; in fact, Henderson et al.
(2020) recommended using multiple runs for a stable estimate.Furthermore, one needs to consider that zero-carbon program executions still consume energy, and that efficiency does not intrinsically guarantee a reduction in overall resource consumption, as the resulting cost reduction may lead to an increase in demand counteracting any gains, an effect known as Jevons' paradox (Jevons, 1866).

Open Challenges in Measuring Efficiency
Hardware choice can lead to pronounced differences in certain efficiency measurements such as latency and thoroughput (Lee-Thorp et al., 2022).
Properly measuring efficiency remains a major challenge (Cao et al., 2020).
Separating different stages It is important to characterize efficiency of pre-training and finetuning stages separately (Secs.4 and 5).Models may present different memory requirements during training yet result in trained models with compa-2 https://electricitymap.org rable inference memory consumption.This is because training often involves design choices that increase the memory overhead of backward propagation.Further, some optimizers may require substantially more memory than others.Similarly, parameter sharing techniques may show little benefits during training but show memory improvements at inference (Dehghani et al., 2022).Finally, while larger models run slower than smaller ones, they converge faster and better compress using methods like pruning and quantization (Li et al., 2020c).Hessenthaler et al. (2022) established that many approaches for increasing fairness in NLP models also increase computation, and jointly with work like Wang et al. (2022a) showed that distillation can decrease model fairness.Xu and Hu (2022) studied these effects more systematically, with mixed conclusions.While more positive insights have been found with respect to other desiderata such as out-of-distribution (OOD) generalization (Ahia et al., 2021;Iofinova et al., 2022;Ogueji et al., 2022) and model transfer (Gordon et al., 2020), more work is needed to better understand and benchmark the impact of efficiency beyond accuracy.

Model Selection
Finally, we discuss lines of research that opt to efficiently select a well-performing model variant.

Hyperparameter Search
The performance of machine learning methods can be improved by choosing hyperparameters carefully.Model-based techniques such as Bayesian optimization (BO; Snoek et al., 2012;Feurer et al., 2015) and graph-based semi-supervised learning (Zhang and Duh, 2020) use surrogate models to search efficiently for optimal hyperparameters, avoiding inefficient grid search or manual tuning.A complementary approach is successive halving (SHA; Jamieson and Talwalkar, 2016) and its massively parallel variant, asynchronous SHA (ASHA; Li et al., 2020b), which test multiple hyperparameter settings in parallel for a fixed number of training iterations, then discard the half of the settings with the worst validation set performance.The SMAC3 library (Lindauer et al., 2022) implements several BO strategies, including a budgetlimited variant for expensive deep learning tasks, and is integrated into auto-sklearn (Feurer et al., 2022) and auto-pytorch (Zimmer et al., 2021).However, with limited computational budgets, both BO and ASHA may fail to identify good settings (Liu and Wang, 2021).It is unclear whether these methods can be used to choose random initial weights or to order training samples, which also affect model performance (Dodge et al., 2020).

Hyperparameter Transfer
To minimize the number of trials needed to find optimal hyperparameter settings, one can transfer knowledge from other datasets or tasks-similar to how an ML engineer might select reasonable settings by hand.Transferring hyperparameters can be especially beneficial during expensive stages in the NLP pipeline, such as pre-training.Transfer neural processes (Wei et al., 2021) provide a way to transfer observations, parameters and configurations from previous tasks using Bayesian optimization with a neural process as the surrogate model.This can lead to more accurate models with fewer trials than conventional BO approaches, but has yet to be tested for large NLP models.Finally, the cost of training can be reduced using µTransfer (Yang et al., 2021), which tunes a small model, then transfers the hyperparameters to a larger model.

Model Selection Considerations
While identifying an optimal model is crucial in deployment, it raises several challenges around reporting practices (Reimers and Gurevych, 2017;Agarwal et al., 2021) and hyperparameter tuning (Bouthillier and Varoquaux, 2020;Gundersen et al., 2022).3A first step towards improved comparability could be to fix hyperparameter tuning budget (Dodge et al., 2019;Hoffmann et al., 2022), or consider the full search space (Bell et al., 2022).

Conclusion
This survey provides a broad overview of considerations for increasing efficiency in modern NLP models, identifying both immediate successes and remaining challenges.Most progress so far has been in model design, typically targeted at a specific computational budget and hardware paradigm.Key challenges include better understanding and modelling trade-offs between end-task performance and resource consumption, and the dependency between hardware choices and software implementations.Furthermore, we note that efficiency in NLP has many definitions and can be achieved in many different ways, but is also subject to various open challenges, and cannot be measured by a single metric.We outline several promising research directions aligned with overcoming these challenges, ranging from approaches that make better use of available data, strategies for reducing the cost of pre-training and fine-tuning large models, to prioritizing the importance of interactions between algorithms, software, and hardware.
Impressive advances in NLP enabled primarily by scaling computation have produced remarkable progress in a short span of time.However, in order to realize the full potential of this technology for a broader swath of society, we must reduce the amount of computation that is required to achieve these remarkable results.We hope that this survey can serve to accelerate advances in this important area of research with great potential for impact both within our field and for society as a whole.
considers the Pareto frontier between real time taken, system or GPU memory usage, and model size, as well as BLEU score.Puvis de Chavannes et al. (2021) included power consumption as a trade-off against perplexity to explore Pareto-efficient hyperparameter combinations for transformer models.Finally, Liu et al. (2022b) examined Pareto efficiency for a number of tasks in an attempt to narrow model selection search space.
Schematic overview of the efficient NLP stages covered in this paper, starting with data collection and model design, followed by training and inference, and ending with evaluation and model selection.