Few-shot Task-agnostic Neural Architecture Search for Distilling Large Language Models
Anonymous Author(s)
AffiliationAddress
Abstract
Traditional knowledge distillation (KD) methods manually design student architectures to compress large models given pre-specified computational cost.
Thisrequires several trials to find viable students, and repeating the process with changein computational budget.
We use Neural Architecture Search (NAS) to automatically distill several compressed students with variable cost from a large model.
Existing NAS methods train a single SuperLM consisting of millions of subnetworks with weight-sharing, resulting in interference between subnetworks ofdifferent sizes.
Additionally, many of these works are task-specific requiring tasklabels for SuperLM training.
Our framework AutoDistil addresses above challenges with the following steps: (a) Incorporates inductive bias and heuristics topartition Transformer search space into K compact sub-spaces (e.g., K = 3 cangenerate typical student sizes of base, small and tiny); (b) Trains one SuperLM foreach sub-space using task-agnostic objective (e.g., self-attention distillation) withweight-sharing of students; (c) Lightweight search for the optimal student withoutre-training.
Task-agnostic training and search allow students to be reused for finetuning on any downstream task.
Experiments on GLUE benchmark demonstrate
AutoDistil to outperform state-of-the-art KD and NAS methods with upto 3 xadditional reduction in computational cost and negligible loss in task performance.
Introduction
While large pre-trained language models (e.g., BERT [1], GPT-3 [2]) are effective, their huge sizeposes significant challenges for downstream applications in terms of energy consumption and costof inference [3] limiting their usage in on the edge scenarios and under constrained computationalinference budgets.
Knowledge distillation [4, 5, 6, 7] has shown strong results in compressing pretrained language models into small student models.
However, these works require pre-specification ofthe student architecture and computational cost (e.g., number of parameters, FLOPs) for distillation.
This poses two significant challenges: (i) it requires several trials to come up with viable architecturesas they are hand-engineered and to define several hyper-parameters (e.g., number of layers andattention heads, hidden dimension, etc.)
; (ii) one has to re-run distillation with any change inspecification for the student architecture or computational cost for using it in a target environment.
Neural Architecture Search (NAS) [8, 9, 10, 11] provides a natural solution to automatically searchthrough a large space of candidate models.
The dominant NAS paradigm consists of two main steps:(a) Training a Super model combining all possible architectures into a single graph and jointly trainingthem via weight-sharing; (b) Searching for optimal architecture from Super model with best accuracyon a downstream task, satisfying user-specified latency constraint for target device.
Parallel to abovecomputer vision (CV) works, NAS has shown strong results in recent works like DynaBERT [12],
AutoTinyBERT [13] and NAS-BERT [14] for natural language understanding (NLU).
Drawbacks of existing NAS methods.[D1: Co-adaptation in weight-sharing] Aboveworks train one single large Super Language Model (SuperLM) consisting of millions of diverse student architectures.
This results in someundesirable effects of co-adaptation [15] likeconflicts in weight-sharing where bigger studentmodels converge faster in contrast to smallerones converging slower [16, 11].[D2: Multi-stage training]
A single SuperLMmay not have sufficient capacity to encode alarge search space.
As a result, these worksuse multi-stage training process, where theyfirst conduct NAS to identify candidate studentsand then perform further pre-training [13] andknowledge distillation [14] of the candidates.[D3: Task-specific training]
NAS works inthe CV domain (e.g., AutoFormer [17], Oncefor-all [10], One-Shot NAS [11, 18]) leveragehard class labels from a given task (e.g., image classification) or soft labels from ImageNetpre-trained models (e.g., MobileNet [7], RegNet [19]) for task-specific optimization with accuracy as an evaluation metric.
Different from CV domain, NLU tasks have different objectives and evaluation metrics for classification (e.g., MNLI), regression (e.g., STS-B) and correlation(e.g., CoLA).
Correspondingly, pre-trained language models like BERT [1] are also trained in selfsupervised fashion without using task labels.
This makes it challenging to adapt existing NAS worksto the NLU domain in a task-agnostic setting.
Recent NAS works in the NLU domain are not fullytask-agnostic.
For instance, DynaBERT [12] accesses both task labels for knowledge distillationand task development set for network rewiring.
NAS-BERT [14] performs two-stage knowledgedistillation with pre-training and fine-tuning of the candidates for best performance.
While AutoTinyBERT [13] also explores task-agnostic training, we demonstrate better performance from few-shot NAS and much cheaper cost from single stage training without additional pre-training and distillation.
Contributions.
We address above challenges with fully task-agnostic few-shot NAS consisting ofthree steps.
(S1) Search space design.
We partition the Transformer search space into K sub-spacesconsidering important architectural hyper-parameters like the network depth, width and attentionheads.
We further leverage inductive bias and heuristics to limit the number of student architecturesin each sub-space.
(S2) Fully task-agnostic SuperLM training.
We train K
SuperLM overall, onefor every sub-space.
This allows each SuperLM more capacity to encode a sub-space as opposed to asingle large one.
We train each SuperLM with a fully task-agnostic objective (without accessing anytask labels) like deep self-attention distillation, where we transfer knowledge from the self-attentionmodule (including keys, queries and values) of a pre-trained teacher (e.g., BERT) to the student anduse weight-sharing to train the SuperLM.
(S3)
Lightweight optimal student search.
We obtainoptimal student(s) directly from well-trained SuperLM(s) without any re-training that can be simplyfine-tuned on downstream tasks.
Our contributions over existing NAS works can be summarized as:
• In contrast to prior works (e.g., DynaBERT, AutoTinyBERT, NAS-BERT), we do a single-stagetraining combining NAS and distillation with no further pre-training or augmentation and demonstratesuperior performance of the NAS process itself with significantly reduced training cost.
Obtainedsubnetworks are simply fine-tuned on downstream tasks. [Table] • Fully task-agnostic training with subnetwork attention state alignment for self-attention relationdistillation and search in contrast to prior works in NLU (e.g., DynaBERT, NAS-BERT) and CV (e.g.,AutoFormer, BigNAS, Once-For-All).• Few-shot NAS to mitigate gradient conflicts in SuperNet training compared to prior One-shot NASworks in NLU (e.g., DynaBERT, AutoTinyBERT, NAS-BERT).
AutoFormer in the CV domain is anexception to this point which also uses few-shot NAS but accesses task labels during training.• Strong results over all the above NAS and distillation works in NLU with 3 x additional compressionover best performing distillation technique with negligible drop in task performance. [Table]
Search Engine
TaskAgnostic TaskProxy 𝛼 𝒜∗
Performance Cost 𝓐𝓐𝓐
K -shot Learning for SuperLM
SubnetworkSearch
K Search Partitions …
Transformer
Transformer Transformer
Transformer Transformer
Transformer T x 1 x 2 x…
Transformer
Transformer
Transformerx 1 x 2 x
Transformer S
Q
K
V
Distill Q
K
V
Attention
W Q
W K
W V
W o
W W
Sampled Subnetworks
Pre-trained Teacher
Adaptive Transformer Block ofSampled Subnetworks
Multi-head Self-attention Relation Distillation
Background
We present an overview of Transformers [20], especially its two main sub-layers, multi-head selfattention (MHA) and feed-forward network (FFN).
Transformer layers are stacked to encode contextual information for input tokens as: X l = Transformer l ( X l − 1 ) , l ∈ [1 , L ] where L is the numberof Transformer layers, X l ∈ R s ∗ d hid , s is the sentence length, and d hid is the hidden dimension.
Inthe following, we omit the layer indices for simplicity.
Multi-Head Self-Attention (MHA).
Given previous Transformer layer’s output X , MHA computes:
[Equation]
where W Qh , W Kh , W Vh ∈ R d hid ∗ d head , W O ∈ R d hid ∗ d hid are linear transformations.
Q h , K h , V h∈ R s ∗ d head are called queries, keys, and values, respectively.
H is the number of heads.
head h =
Attention( Q h , K h , V h ) denotes the h -th attention head.
Concat is the concatenating operation.d head =
d hid /H is the dimension of each head.
Feed-Forward Network (FFN).
Each Transformer layer contains an FNN sub-layer, which is stackedon the MHA.
FFN consists of two linear transformations with a ReLU activation as:
[Equation]
where W 1 ∈ R d hid ∗ d f , W 2 ∈ R d f ∗ d hid , b 1 ∈ R d f , and b 2 ∈ R d hid .
In addition, there are residualconnection and layer normalization on top of MHA and FFN (denoted by ⊕ in Figure 2), which areformulated as LayerNorm(x + MHA(x)) and LayerNorm(x + FFN(x)), respectively.
Few-shot Task-agnostic NAS
Given a large pre-trained language model (e.g., BERT) as teacher, AutoDistil distills severalcompressed models with variable computational cost with the following major components.
3.1 Search Space Design
Searchable transformer components.
From Transformers overview (Section 2) and our framework(Figure 2), we observe four important hyper-parameters for the Transformer blocks to include:(1)
Feed-forward network (FFN) dimension - we encode this by the MLP (multi-layer perceptron)ratio defined as r =
d f d hid , with d f and d hid representing the intermediate dimension of the FFN andhidden dimension respectively; (2) Number of layers ( L ) to capture the network depth; (3) Hiddendimension ( d hid ) to encode input; (4) Attention heads ( H ) for multi-head self-attention.
All of the above factors are important for model capacity and have a significant impact on the modelsize and computational cost.
For instance, different layers have different feature representationcapabilities.
Recent works show that Transformer models are overparameterized [21, 22], such asthe feed-forward layer (FFN), which is one of the most computation intensive components [23].
Therefore, we search for optimal MLP ratio and hidden dimension that reduce computational costresulting from FFN layers.
Furthermore, studies [24, 25] show that attention heads can be redundantwhen they learn to encode similar relationships for each word.
Thus, we make the number of attentionheads searchable as well.
Inductive bias.
Prior work [26] demonstrate that thinner and deeper neural networks with improvedrepresentation capacity perform better than wider and shallower ones.
We incorporate this as aninductive bias to decide the number of layers to consider for the students in each of our K sub-spaces(base, small, tiny), where we prefer deeper students in terms of the number of layers.
Furthermore,we constrain all the Transformer layers in a given student model to share identical and homogeneousstructures, i.e., the same number of attention heads, hidden dimension, etc.
This not only reduces thesize of the search space, it is also more friendly to hardware and software frameworks [13].
Search space partition.
Existing works [13, 14] train a single large SuperLM containing millions ofstudent architectures by weight-sharing.
This leads to performance degradation due to optimizationinterference and convergence of subnetworks with very different sizes [11].
To mitigate suchinterference, we employ a few-shot learning strategy [17, 16] as follows.
We partition the whole
Transformer search space into K sub-spaces such that each sub-space covers different sizes of studentmodels given by the number of parameters.
For instance, K = 3 can cover typical student sizes,namely base, small and tiny versions.
Table 1 shows the parameter ranges for the K sub-spaces,along with the student configurations contained in each.
[Table]
BERT #Subnets
[Table]
N/A #Layers (
[Table]
We now encode each subspace into a SuperLM,where each student modelin the space is a subnetworkof the SuperLM.
Furthermore, all the student subnetworks share the weights oftheir common dimensions,with the SuperLM being thelargest one in the searchspace.
Considering K independent SuperLMs, eachone now has more capacityto encode a sub-space, incontrast to a limited capacity single SuperLM as in prior works.
Furthermore, our choices for the heuristic partition andinductive bias result in less number of student models of comparable size in each sub-space whichalleviates conflicts in weight-sharing.
We extract student subnetworks from the SuperLM by a simple truncation strategy like bottom-leftextraction.
We defer more sophisticated extraction strategies to future work.
In the above strategy,given a specific architecture α
= { l, d hid , r, h } , (i) we first extract alternate l Transformer layers fromthe SuperLM; (ii) then extract bottom-left sub-matrices in terms of d hid and r from the originalmatrices that represent the hidden dimension and the MLP ratio respectively; (iii) finally, for theattention heads, we extract the leftmost h heads and retain the dimension of each head as the SuperLM.
3.2 Task-agnostic SuperLM Training
We illustrate SuperLM training process in Algorithm 1.
Given a large pre-trained language model (e.g.,
BERT) as teacher, we initialize the SuperLM with the weights of teacher.
In each step of SuperLMtraining, we randomly sample several student subnetworks from the search space; apply knowledgedistillation between sampled subnetworks and the teacher to accumulate gradients; and then updatethe SuperLM.
During sampling, we employ Sandwich rule [27], also used in BigNAS [11], thatsamples the smallest subnetwork, the largest subnetwork and M random ones for updating SuperLM.
The motivation is to improve the performance of all subnetworks by increasing the performancelower bound (smallest subnetwork) and upper bound (largest one) across all subnetworks.
We leverage deep self-attention distillation [4] for task-agnostic training.
To this end, we employmulti-head self-attention relation distillation to align the attention distributions as well as scaleddot-product of keys, queries and values of the teacher and sampled student subnetworks.
Consider
A 1 , A 2 , A 3 to denote the queries, keys and values of multiple relation heads of teacher model,and B 1 , B 2 , B 3 respectively for a sampled subnetwork.
Mean squared error ( MSE( · ) ) betweenmulti-head self-attention relation of teacher and sampled subnetwork is used as distillation objective:
[Equation]
where R Ti = softmax( A i
A ⊤ i / √ d k ) , R Si = softmax( B i B ⊤ i / √ d k ) , H is the number of attentionheads; R Ti represents the teacher’s Q − Q , K − K , or V − V relation; R Si represents the same forstudent.
R Tik is the relation information based on one attention head, and d k is the attention head size.
Relation knowledge distillation avoids the introduction of additional parameters to transform thestudent’s representations with different dimensions to align to that of the teacher.
For the teachermodel and subnetworks with different number of attention heads, we first concatenate the selfattention vectors of different attention heads of the subnetwork and then split them according to thenumber of relation heads of the teacher model.
Then, we align their queries with the same number ofrelation heads for distillation.
In addition, we only transfer the self-attention knowledge from thelast layer of the teacher model to the last layer of the student model.
Automatically selecting whichlayers to align is an interesting research direction that we defer to future work.
[Table] A k ; pre-trained teacher T ; unlabeled data D ; training epochs E ; sampling steps M
Output: Trained SuperLMs { S k } for k = 1 to K do for i = 1 to E do
Get a batch of data from D for batch in D do
Clear gradients in SuperLM S k for m = 1 to M do
Randomly sample a subnetwork s from S k Calculate self-attention distil.
loss between subnetwork s and teacher T with Eqn.
(4) Accumulate gradients end for
Update S k with the accumulated gradients end for end for end for
The SuperLM for sub-space
A k is trained as:
[Equation]
where, K is the number of sub-space partitions; W are the weights of the SuperLM;
W α are the weights in W specified by the architecture α ; U are the weights of the teachermodel including the self-attention moduleused for distillation; D train is the training dataset, and L ( · ) is the self-attention loss functionfrom Eqn.
3.3 Lightweight Optimal Student Search
We outline two search strategies for selectingthe optimal student subnetwork.
Task-agnostic search.
We adopt this to be ourprimary strategy to compare against all baselines since it does not access any task labelinformation.
We compute the task-agnosticself-attention distillation loss for all student subnetworks using Eqn.
(4) on a heldout validation setfrom the unlabeled training corpus.
The student subnetworks are directly obtained by bottom-leftextraction from the well-trained SuperLM (outlined in Section 3.1).
This process is lightweight sinceit does not require any training or adaptation of the student and number of subnetworks is limited.
Theoptimal student is given by the subnetwork with least validation loss subject to following constraint.
[Equation]
[Equation] where W ∗ α is the weights of architecture α obtained from W ∗A k , D val is the validation data set, Lis the self-attention distillation loss, and g ( · ) is a function to calculate the computational cost (e.g.,#FLOPs, #parameters) of the subnetwork subject to a given user-specified resource constraint c .
Task-proxy search.
We compare our task-agnostic search against another strategy that considers aproxy task (e.g., MNLI [28]) with label information to fine-tune the 256 candidate subnetworks ineach sub-space.
The optimal student in each sub-space is given by the one with the best downstreamtask performance (e.g., accuracy).
Note that, for this strategy, the proxy task is used only duringsearch while the NAS training is still fully task-agnostic.
Experiments
Datasets.
We conduct experiments on the General Language Understanding Evaluation (GLUE)benchmark [29].
We compare our method with the baseline methods on two single-sentence classification tasks (CoLA [30], SST-2 [31]), two similarity and paraphrase tasks (MRPC [32], QQP [33]),and three inference tasks (MNLI [28], QNLI [34], RTE [35, 36, 37, 38]) 1 .
We report accuracy for
MNLI, QNLI, QQP, SST-2, RTE, report f1 for MRPC, and report Matthew’s correlation for CoLA.
Baselines.
We compare against several task-agnostic methods 2 generating compressed models from
BERT base teacher, using (i) knowledge distillation like BERT SMALL [39], Truncated BERT [28],
DistilBERT [5], TinyBERT [6], MINILM [4]; as well as those based on Neural Architecture Search,like AutoTinyBERT [13], DynaBERT [12], and NAS-BERT [14].
AutoDistil
configuration.
We use uncased BERT BASE as the teacher consisting of 12 Transformer layers, 12 attention heads; with the hidden dimension and MLP ratio being 768 and 4,respectively.
It consists of 109 M parameters with 11 .
2 G FLOPs.
We use English Wikipedia and
BookCorpus data for SuperLM training with WordPiece tokenization.
We use a batch size of 128and 4 e - 5 as the peak learning rate for 10 epochs.
The maximum sequence length is set to 128 .
The coefficients in distillation objective (Eqn.
(4)), β 1 , β 2 , and β 3 , are all set to 1 .
We distill theself-attention knowledge of the last layer to train the SuperLM.
Both the teacher and SuperLM areinitialized with pre-trained BERT BASE .
Other hyper-parameter settings are shown in Appendix.
Weuse 16 V 100 GPUs to train the SuperLM with 336 GPU-hours as the training cost.
4.1 Finding the Optimal Compressed Models
AutoDistil Agnostic is obtained by fully task-agnostic training and task-agnostic search withoutusing any task label information.
We set a constraint in Eqn.
(6) such that the #FLOPs of the optimalcompressed model is atleast 50% less than the teacher model.
We rank all the subnetworks containedin all the partitions of the trained SuperLM by their self-attention distillation loss on the heldoutvalidation set, and select the one that meets the constraint with the minimum loss.
AutoDistil Proxy uses MNLI [28] as a proxy to estimate downstream task performance of differentsubnetworks.
Prior work [40] has demonstrated performance improvements in MNLI to be correlatedto other GLUE tasks.
To this end, we fine-tune all the 256 subnetworks in each partition of the trainedsuperLMs, and select corresponding subnetworks with the best trade-off between task performance(accuracy) and computational cost (#FLOPs).
This results in K = 3 optimal students, corresponding to
AutoDistil Proxy B , AutoDistil Proxy S and AutoDistil Proxy T obtained from the corresponding 253 sub-spaces of SuperLM Base , SuperLM Small and SuperLM Tiny , respectively.
Notably all students areobtained from the AutoDistil SuperLM still trained in a fully task-agnostic fashion.
4.1.1 Comparison with Traditional Knowledge Distillation Baselines
We compare AutoDistil against state-of-the-art KD models distilled from the same teacher
BERT BASE in Table 2 with respect to the following measures: computational cost in the form of (i)
FLOPs and (ii) parameters, along with (iii) improvement in the average task performance aggregatedover all the GLUE tasks.
We observe that the compressed model AutoDistil Agnostic generatedvia our task-agnostic SuperLM training leads to upto 3 x reduction in FLOPs over state-of-the-artdistilled models (e.g., MINILM [4], TinyBERT [6], DistilBERT [5]) that are hand-engineered whilematching the overall task performance.
The most aggressive compressed version corresponding to
AutoDistil Proxy T obtains a massive 41 x reduction in FLOPs over BERT BASE while incurring5 point accuracy drop in GLUE (excluding CoLA) and 10 point drop (including CoLA).
Notably
CoLA is a syntactic task in contrast to other semantic tasks in the benchmark like natural languageinference, paraphrase detection and sentiment classification.
This depicts an interesting impact ofmassive model compression on varying task types.
4.1.2 Comparison with Neural Architecture Search Baselines
We report the performance of several NAS-generated student models of comparable FLOPs andparameters from corresponding papers in Table 2.
[Table] [Table]
[Table] [Table]
[Table]
AutoDistil outperforms all competing methods on aggregate for all sizes; except for small-sizedmodel; where it has marginally lower performance (0.1 points on avg) compared to AutoTinyBERT.
[Table]
comparison for generating students of similar FLOPs.
NR AutoTinyBERT does not report the cost of SuperNet training - typically the most expensive step.
Further Training refers to additional pre-training applied to NAS-generated candidates
It is worthwhile to note that computational cost of training process is another important dimension for comparing methods.
This is especially important when comparing to NAS methodsthat use multi-stage training; where additional pre-training anddistillation is applied to NAS-generated candidates.
To better understand the impact of single-stage vs. multi-stagemethods on the training cost, we compare the overall cost of
NAS for AutoDistil and that reported in AutoTinyBERT 3for the small model segment in Table 3.
AutoDistil is muchcheaper due to its single-stage training protocol; where no additional pre-training or distillation is needed.
It is worth notingthat the overall SuperNet training cost of AutoDistil (themost expensive component of NAS) is less or comparable tothe additional training cost of re-training candidate modelsfor AutoTinyBERT.
Note that AutoTinyBERT does not reporttheir SuperNet training cost.
Additionally, AutoDistil hasa much faster search mechanism due to (1) inductive biasesbuilt into the search space definition to limit the number of student architectures and (2) task-agnosticsearch that only requires computing self-attention validation loss without the need for any training.
Finally, we show the pareto frontier of student subnetworks generated by several KD and NASmethods in Figure 3 for the MNLI task.
The blue points represent all the subnetworks extracted from
AutoDistil and red points denote the optimal ones, all fine-tuned on the MNLI task.
We observethe optimal AutoDistil models to outperform several competing methods.
4.1.3 Task-agnostic Training Strategies
[Table]
We study different task-agnostic strategies for SuperLM training in AutoDistil .
Specifically, we compare three strategies in Table 4.
(i)
We replacing the KD loss in Eqn.
(4) withmasked language modeling (MLM) loss [1] to calculate gradients which is the most widely used task-agnostic pre-trainingand distillation strategy.
(ii) KD att
+Cont further continuestraining the searched compressed models on the large languagecorpus (iii) KD att is the strategy adopted in AutoDistil for self-attention distillation.
We evaluatesubnetworks with the same architecture ( 6 layers, 768 hidden, 12 heads, MLP ratio 4 ) from the
[Figure] trained SuperLM.
We fine-tune the subnetworks on RTE and MRPC tasks, and report accuracy and f1 respectively.
First, we observe self-attention distillation to perform better than MLM, for SuperLM training. Second, we observe limited performance gains with continued training of theoptimal subnetworks from NAS as done in existing works demonstrating the effectiveness of oursingle-stage training protocol .
4.1.4 One-shot vs. Few-shot NAS with Varying K
[Table]
For few-shot NAS, we choose K = 3 (i.e. 3 subspaces) for following reasons: (1) the 3 sub-spacescorrespond to base, small and tiny model sizes; asused in prior work in CV; e.g. AutoFormer [17],(2) searching over different values of K is a veryresource-extensive process since it requires training
K SuperLMs for each choice of K , (3) As K increases, the search process becomes similar to theundesirable brute-force discrete search that trains all models in search space individually.
To understand the effect of few-shot NAS vs. one-shot NAS, we compare the performance of asingle space ( K = 1 ) to multiple sub-spaces ( K = 3 ).
We extract subnetworks with the samearchitecture ( 6 layers, 768 hidden, 12 heads, MLP ratio 4 ) from trained SuperLMs for each strategyfor evaluation with results presented in Table 5.
For one-shot NAS, we consider a single search spacecontaining different numbers of subnetworks (e.g., 27 , 864 , 11232 ).
The few-shot NAS contains 256subnetworks in each partition.
We fine-tune the subnetworks on RTE and MRPC tasks, and reportaccuracy and f1 respectively.
We observe fewer subnetworks contained in a single search space forone-shot NAS result in a better performance.
This results from optimization interference and gradientconflicts as the number and size of subnetworks increase in the space.
Finally, we observe our designstrategy performs the best while containing lesser number of subnetworks demonstrating the benefitof few-shot NAS for language model distillation .
4.1.5 Comparing Search Strategies and Optimal Architectures
From Table 2, we observe that the student models AutoDistil Agnostic and AutoDistil Proxy Sobtained from SuperLM small by task-agnostic and task-proxy search strategies respectively obtain asimilar trade-off between performance and cost.
The task-proxy search results in a minor performancegain 0 .
3 over the fully task-agnostic search mechanism.
Table 6 shows the configuration of searchedoptimal architectures from AutoDistil with corresponding computational cost.
For reference, wealso show the architecture of the teacher BERT BASE and a state-of-the-art distilled model MINILM [4]that are hand-engineered.
We observe that the obtained architectural hyper-parameters are quite
[Table]
non-standard and difficult
to obtain bytrial and error considering the largespace of Transformer architectures.
We also observe that optimal compressed models have thin-and-deepstructure consistent with findings thatthinner and deeper models performbetter [26] than wider and shallowerones.
While we use this as an inductive bias for sub-space partitioning,our search space (Table 1) also contains diverse subnetworks with different depth and width.
Non-maximal MLP ratio and attention heads for optimal compression indicatethat self-attention and feed-forward layers of Transformers are overparameterized [21, 22].
Related Work
Task-specific knowledge distillation.
Knowledge distillation (KD)
[41] is a widely used techniquefor model compression, which transfers knowledge from a large teacher to a smaller student.
Taskspecific KD aims to generate smaller students by using downstream task label information.
Typicaltask-specific KD works include BERT-PKD [42], BERT SMALL [39], TinyBERT [6], DynaBERT [12],and SparseBERT [43].
While task-specific KD often achieves good task performance, a typicaldrawback is that it is resource-consuming to run KD for each and every task, and also not scalable.
Task-agnostic knowledge distillation.
In contrast to task-specific KD, we explore task-agnostic
KDthat does not use any task label information.
The distilled task-agnostic models can be re-used bysimply fine-tuning on downstream tasks.
Task-agnostic KD leverages knowledge from soft targetprobabilities, hidden states, layer mappings and self-attention distributions of teacher to train studentmodels.
Typical task-agnostic KD works include DistilBERT [5] MobileBERT [7], and MiniLM [4].
MobileBERT assumes that students have the same number of layers as the teacher for layer-by-layerdistillation.
MiniLM transfers self-attention knowledge from the last layer of the teacher to that of thestudent.
These works rely on hand-designed architecture for the student models for KD that requiresseveral trials, and needs to be repeated for a new student with a different cost.
In contrast, we developtechniques to automatically design and distill several student models with variable cost using NAS.
Neural Architecture Search.
While NAS has been extensively studied in computer vision [8,9, 10, 11], there has been relatively less exploration in natural language processing.
Evolved
Transformer [44] and HAT [45] search for efficient sub-networks from the Transformer architecturefor machine translation tasks.
Some recent approaches closest to our method include, DynaBERT [12],
AutoTinyBERT [13] and NAS-BERT [14].
DynaBERT performs task-specific distillation.
NASBERT performs two-stage knowledge distillation with pre-training and fine-tuning of candidates.
Similar to above approaches, AutoTinyBERT also employs one-shot NAS with a single large searchspace containing millions of subnetworks that result in co-adaption and weight-sharing challengesfor SuperLM training.
Further it also uses a multi-stage training protocol for further pre-trainingand distillation of the NAS-generated candidates.
In contrast, AutoDistil employs few-shot NASwith a compact search space design with a single-stage task-agnostic training protocol.
This furtherallows us to do a lightweight search for the optimal student without re-training.
Conclusion
We develop a few-shot task-agnostic NAS framework, namely AutoDistil for distilling largelanguage models into compressed students with variable computational cost.
To address the coadaption and weight-sharing challenges for SuperLM training, we partition the Transformer searchspace into K compact sub-spaces covering important architectural components like the networkdepth, width, and number of attention heads.
We leverage deep self-attention distillation for fullytask-agnostic SuperLM training and lightweight optimal student search without any re-training.
This allows our students to be re-used by simply fine-tuning on downstream tasks.
AutoDistilgenerates students with 3 x less computational cost (FLOPs) than state-of-the-art task-agnosticdistillation methods while obtaining a similar downstream task performance in the GLUE benchmark.
Checklist
For all authors...
(a) Do the main claims made in the abstract and introduction accurately reflect the paper’s
contributions and scope?
[Yes]
(b) Did you describe the limitations of your work?
[Yes] Appendix
(c) Did you discuss any potential negative societal impacts of your work?
[N/A]
(d) Have you read the ethics review guidelines and ensured that your paper conforms to them?
[Yes]
If you are including theoretical results...
(a) Did you state the full set of assumptions of all theoretical results?
[Yes]
(b) Did you include complete proofs of all theoretical results?
[Yes]
If you ran experiments...
(a) Did you include the code, data, and instructions needed to reproduce the main experi-
mental results (either in the supplemental material or as a URL)?
[Yes]
(b) Did you specify all the training details (e.g., data splits, hyperparameters,
how they
were chosen)?
[Yes]
(c) Did you report error bars (e.g., with respect to the random seed after running experi-
ments multiple times)?
[No]
(d) Did you include the total amount of compute and the type of resources used (e.g., type of GPUs, internal cluster, or cloud provider)?
[Yes]
If you are using existing assets (e.g., code, data, models) or curating/releasing new assets...
(a) If your work uses existing assets, did you cite the creators?
[Yes]
(b) Did you mention the license of the assets?
[N/A]
(c) Did you include any new assets either in the supplemental material or as a URL?
[N/A]
(d) Did you discuss whether and how consent was obtained from people whose data you’re
using/curating?
[N/A]
(e) Did you discuss whether the data you are using/curating contains personally identifiable
information or offensive content?
[N/A]
If you used crowdsourcing or conducted research with human subjects...
(a) Did you include the full text of instructions given to participants and screenshots, if
applicable?
[N/A]
(b) Did you describe any potential participant risks, with links to Institutional Review
Board (IRB) approvals, if applicable?
[N/A]
(c) Did you include the estimated hourly wage paid to participants and the total amount
spent on participant compensation?
[N/A]