원시데이터 수집 시스템
선정목록으로

Efficiently Distilling LLMs for Edge Applications

관련 패션 · (24) 패션(코오롱FnC)

기본 정보

저자
  1. Achintya Kundu — IBM Research , Singapore
  2. Yu Chin Fabian Lim
  3. Aaron Chew — IBM Research , Singapore
  4. Laura Wynter — IBM Research , Singapore
  5. Penny Chong — IBM Research , Singapore
  6. Rhui Dih Lee — IBM Research , Singapore
DOI
10.18653/v1/2024.naacl-industry.5
저널
–
발행년도
2024
발행기관
–
피인용수
11
라이선스
cc-by
논문 유형
–
언어
–
원문 페이지
https://doi.org/10.18653/v1/2024.naacl-industry.5
토픽
Advancements in Photolithography Techniques
OpenAlex ID
W4401043244

평가 내용

관련도
관련
사업분야
패션 · (24) 패션(코오롱FnC)
부 분야
–
R&D 측면
–
확신도
–
근거 용어
–
판단 근거
임베딩 유사도 기반 평가로 '패션 > 패션(코오롱FnC)' 분야에 선정된 논문입니다.
R&D 활용 포인트
–
평가 입력
–

초록

Achintya Kundu, Yu Chin Fabian Lim, Aaron Chew, Laura Wynter, Penny Chong, Rhui Lee. Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 6: Industry Track). 2024.

본문 50,861자

본문 펼치기
# Efficiently Distilling LLMs for Edge Applications Achintya Kundu, Fabian Lim, Aaron Chew, Laura Wynter, Penny Chong, Rhui Dih Lee IBM Research, Singapore Abstract Supernet training of LLMs is of great interest in industrial applications as it confers the ability to produce a palette of smaller models at constant cost, regardless of the number of models (of different size / latency) produced. We propose a new method called Multistage Low-rank Fine-tuning of Super-transformers (MLFS) for parameter-efficient supernet training. We show that it is possible to obtain high-quality encoder models that are suitable for commercial edge applications, and that while decoder-only models are resistant to a comparable degree of compression, decoders can be effectively sliced for a significant reduction in training time. 1 Introduction Given their sizes up to billions of parameters, (Raffel et al., 2020; Brown et al., 2020), it is challenging for enterprises to fine-tune Large Language Models (LLMs), and furthermore they are not suitable for deployment on edge devices with limited memory and computational power. We wish to enable LLMs on edge environments for enterprise use cases. This requires the following two capabilities. (1) Accommodating a variety of edge device hardware: A single fine-tuned model is not optimal across the spectrum of devices. For industrial applications, a palette of fine-tuned LLMs is required for different hardware. (2) Dynamically changing resource levels: At run-time, the available resources on edge devices evolve over time, and appropriate model should be dynamically selected based on the available resources of each device. A considerable amount of research has focused on compressing LLMs (Zhu et al., 2023; Sanh et al., 2019; Mukherjee and Awadallah, 2020; Mukherjee et al., 2021; Jiao et al., 2020; Hsieh et al., 2023). Methods that train a single small model guided by a large teacher model such as DistilBERT (Sanh et al., 2019) and BERT-PKD (Sun et al., 2019), either achieve limited compression or do not scale to a large number of deployment devices. Supernet training methods (Hou et al., 2020; Xu et al., 2021; Cai et al., 2019; Kundu et al., 2023; Lou et al., 2021; Jawahar et al., 2023) were introduced to address these limitations: multiple smaller subnets within the supernet are trained simultaneously with weight-sharing. This one-time training approach produces a palette of smaller models, helping mitigate the computational cost of fine-tuning a model for each deployment scenario. However, the fullparameter supernet training approach is impractical when fine-tuning of an LLM is required for multiple deployment scenarios, limiting its utility for enterprises. Parameter-efficient fine-tuning (PEFT) methods such as Low-Rank Adaptation (LoRA) reduces the number of trainable parameters by allowing only rank-decomposition matrices to be trained while freezing the pre-trained weights of the model. PEFT methods, however, are not applicable to supernet training due to the implications on the weight-shared sub-networks. Our work bridges this gap to enable efficient fine-tuning of LLMs for edge devices. Our contributions are: 1. We propose a parameter-efficient, distillationbased approach for supernet training of LLMs. 2. We devise a gradient scaling scheme to improve convergence speed of any form of supernet training. 3. We demonstrate significant compression of encoder models for edge. We highlight the limits of comparable compression for decoder models, while demonstrating a huge reduction in the steps needed for convergence. 2 Related Work Classical compression methods have been used for LLMs including pruning (McCarley et al., 2019; Voita et al., 2019), low rank approximation (Ma 52 _Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics:_ _Human Language Technologies (Volume 6:_ et al., 2019; Lan et al., 2019), and quantization (Shen et al., 2020; Zafrir et al., 2019; Bhandare et al., 2019). Knowledge distillation (KD) is adopted in BERT-PKD (Sun et al., 2019), tinyBERT (Jiao et al., 2020), and distilBERT (Sanh et al., 2019) and (Gu et al., 2023) in MiniLLM to distill knowledge from the layers of a large transformer model to a smaller one. See also the survey (Zhu et al., 2023). All these existing methods produce a single compressed model, unsuitable for edge scenarios with multiple deployment devices having varying computational capability. Neural architecture search (NAS) based on reinforcement learning (Zoph and Le, 2016) and evolutionary algorithms (Real et al., 2019; Zhu et al., 2019) trains every possible architecture and is very slow. Weight-sharing NAS was thus developed: in Guo et al. (2020); Cai et al. (2018), the building blocks in the same layer are isolated as all architectures are single paths. Weight-sharing NAS does not scale well to large architecture search spaces, hence, weight-entangled NAS, where subnets with common parts share weights, was introduced. For resource-constrained edge deployment, supernet training (Cai et al., 2019; Kundu et al., 2023; Chen et al., 2021b; Xu et al., 2021; Gao et al., 2022; Dong et al., 2022) was developed as a mode of jointly training multiple sub-networks (subnets) with entangled weights: one trains the supernet only once for all deployment scenarios. Cai et al. (2019) introduced an elastic convolutional neural network with "progressive shrinkage", where larger subnets are trained first. Recent works have improved sampling strategies, e.g. the sandwich rule with in-place distillation (Yu et al., 2020), attentive sampling (Wang et al., 2021), stochastic nature gradient (Zhang et al., 2021), or post-training sampling (Lou et al., 2021). Our work is related to supernet training for transformer models (Hou et al., 2020; Zhang et al., 2021; Wang et al., 2022, 2020; Chen et al., 2021b). This gradient scaling technique can be used with any of the above supernet methods. Parameter-efficient fine-tuning (PEFT) has been of great benefit in fine tuning LLMs. BitFit (Ben Zaken et al., 2022) updates the bias terms in pre-trained models while freezing the remaining parameters. LoRA (Hu et al., 2022) decomposes attention weight gradients into low-rank matrices to reduce the number of trainable parameters. AdaLoRA (Zhang et al., 2023) and QLoRA (Dettmers et al., 2023) further improve LoRA (Hu et al., 2022). Note that PEFT allows fine-tuning a base model on a single GPU but does not produce smaller models. None of the PEFT methods can be used for weight-sharing supernet training. 3 Solution Design For use in enterprise settings, the solution must allow fine-tuning of models on a small GPU footprint. In addition, inference cost in terms of storage must be minimised. We therefore design a solution which does not store the full size model checkpoint for every downstream task but only the frozen weights of the pre-trained base model and the low rank matrices. For inference in commercial edge use cases, we wish to enable storing the desired models locally for a wide variety of edge device resource requirements. We thus develop an approach where storage is minimised, storing only one base model and as many low rank adapter matrices as there are target model size variations, where lowrank adapters are very small. If the model is stored locally on an edge device, our proposed slicing operation takes place where the supernet fine-tuning is performed and the desired model is downloaded for inference. The slicing operation takes place for each model size-task combination and each resulting subnet can be cached for inference. 4 Problem Formulation First, we provide notation. Given a transformer model with architectural configuration Φ and weights W, we denote its forward-pass mapping by fΦ( _·_ ; W) : _X_ _→Y_ . We consider the output space _Y_ to be the set of all non-negative vectors in R <sup>_ν_</sup> with elements summing to 1, where _ν_ denotes the number of classes / vocabulary size). With slight abuse of notation, we write the forward-pass mapping of an input _x ∈X_ through a transformer model Φ as _y, z,_ ˆ h = fΦ( _x_ ; W) _,_ where _y_ ˆ _∈Y_ denotes the predicted probability distribution over the (class labels) vocabulary, _z_ denotes the vector of logits, and h represents a tuple of features such as hidden state vectors and attention values from different transformer layers. Note that _y_ ˆ = _σ_ ( _z_ ), where _σ_ is the standard soft-max function that maps a vector of logits into a probability vector. Given a training data set _Dtrain_ _⊂X_ _× Y_, model weights W are learnt by minimizing training loss: _,_ (1) - <sup>�</sup> argmin W _L_ Φ(W) := E _ℓ_ [ fΦ( _x_ ; W) _, y_ ] 53 where E denotes expectation over training example ( _x, y_ ) drawn uniformly at random from _Dtrain_ and _ℓ_ denotes a loss function. Most commonly, _ℓ_ is chosen to be a task specific loss function, _ℓ_ task, such as cross-entropy (i.e., CE[ _·, ·_ ]) for classification or causal language modeling loss for generative models. Next, we introduce the super-transformer and related terminologies. We define three types of networks - _Teacher network_, _Super-transformer_ (supernet) and _Sub-transformer_ (subnet). The teacher is a fixed network with the same configuration as the pre-trained transformer. A super-transformer is a dynamic model whose architectural dimensions (embedding dimension, number of heads, number of layers, etc.) are configurable at run time. The _maxnet_ (resp. _minnet_ ) is the largest (resp. smallest) network in the super-transformer’s architecture space. Weight entanglement (weight-sharing) allows super-transformer weights to be used across sub-transformers, which are subsets of the supertransformer. Pre-trained transformer weights initialise the super-transformer. The dynamic nature of a super-transformer is explicitly specified via a set _A_, called _configuration_ _space_, consisting of architectural configurations of all sub-transformer models under consideration. The definition of a super-transformer also includes how the configuration Φ _∈A_ is to be mapped to a unique transformer model fΦ. A weight-sharing super-transformer uses a set of shared weights WSup to define all sub-transformer models’ weights. This is done through a weight projection operator Π that slices (selects an appropriate subset of) the super-transformer’s weights WSup into weights of a sub-transformer model: WΦ := Π Φ(WSup) _,_ _∀_ Φ _∈A._ (2) The aim of a weight-sharing super-transformer is to simultaneously train all the transformer models _{_ fΦ( _·_ ; Π Φ(W)) : _X_ _→Y |_ Φ _∈A}_ through the shared weights WSup. A typical training objective for super-transformers is the training loss averaged over all model configurations in _A_ : the super-transformer’s loss _L_ Sup estimated as fΦ _∇_ ˆ W _L_ Sup(WSup)= _K_ <sup><u>1</u></sup> _K_ _j_ =1 _j_ =1 _∇_ ˆ W _L_ Φ _j_ - _, y_ <sup>_i_</sup> <sup>�</sup> _,_ (4) _x_ <sup>_i_</sup> ; WΦ _j_ Π Φ _j_ (WSup) _∇_ ˆ W _L_ Φ(WΦ)= <sup><u>1</u></sup> _|B|_ _∇_ ˆ W _L_ Φ(WΦ)= <sup><u>1</u></sup> - _i∈B_ _i∈B_ _,_ (5) _∇_ W _ℓ_ where _{_ Φ1 _, · · ·_ _,_ Φ _K}_ are _K_ sub-transformer configurations sampled from _A_ to approximate the expectation in (3) and _B_ is a mini-batch of training examples sampled from _Dtrain_ to approximate the expectation in (1). Fine-tuning LLM supertransformers is computationally challenging in enterprise use cases as it involves computing gradients of sub-transformers’ loss functions with respect to a huge number of parameters. 5 MLFS We therefore developed Multistage Low-rank Fine tuning of Super-transformers (MLFS). Given a teacher model with configuration ΦTch and pretrained weights WTch <sup>pretrain</sup>, we assume that its trained weights WTch <sup>pretrain</sup>, we assume that its weights (denoted WTch) can be fine-tuned on the given task by learning low-rank matrices _A_ 0 _, B_ 0 on top of pre-trained weights WTch <sup>pretrain</sup> : Tch <sup>pretrain</sup> : WTch := WTch <sup>pretrain</sup> Tch <sup>pretrain</sup> (7) + _A_ 0 _∗_ _B_ 0 _,_ where _A_ 0 _, B_ 0 are of (low) rank _r_ . Note that pre-trained weights WTch <sup>pretrain</sup> remain unchanged Π Φ(WSup) pre-trained weights WTch <sup>pretrain</sup> remain unchanged during super-transformer fine-tuning. The lowrank matrices, _A_ 0 and _B_ 0, are learnt by minimizing the cross-entropy loss of the teacher model fΦTch( _·_ ; WTch) : _X_ _→Y_ over the training data set _Dtrain_ . Specifically, we perform _E_ 0 epochs of fine-tuning on the teacher to learn _A_ 0 _, B_ 0. This is stage-0 of the multistage fine-tuning algorithm. We denote the teacher weights obtained at the end of stage-0 by WTch. We now define a supertransformer with maxnet configuration the same as the teacher’s. Thus the super-transformer’s weights WSup are of the same size as the teacher weights WTch). To fine-tune the super-transformer weights WSup, in each of the subsequent stages, we freeze WTch and propose learning two stage-specific low rank matrices _As, Bs_, of the same rank, _r_, as _A_ 0 _, B_ 0, that are shared across all sub-transformer models in that stage. To be precise, we impose the following structure on the weights of the subtransformers at stage- _s_ : end of stage-0 by WTch. We now define a supertransformer with maxnet configuration the same as the teacher’s. Thus the super-transformer’s weights WSup are of the same size as the teacher weights WTch). To fine-tune the super-transformer weights WSup, in each of the subsequent stages, we freeze WTch and propose learning two stage-specific low _,_ (3) �� <sup>�</sup> argmin _L_ Φ WSup _L_ Sup(WSup) := E where E denotes expectation over model configuration Φ drawn uniformly at random from _A_ and _L_ Φ, as defined in (1), is averaged training loss for configuration Φ. Super-transformer weights, WSup, are learnt with stochastic gradient (denoted _∇_ <sup>ˆ</sup> ) of 54 _s_ =1 <sup>_As ∗_</sup> <sup>_Bs,_</sup> (8) WΦ = Π Φ(WSup) _,_ _∀_ Φ _∈A._ WSup := WTch + <sup>�2</sup> <u>Algorithm 1</u> <u>Multistage Low-rank Fine-tuning of Super-transformers (MLFS)</u> Input: Transformer model (teacher) with configuration ΦTch & off-the-shelf pre-trained weights WTch <sup>pretrain</sup>, model configuration space _A_ consisting of smaller (than ΦTch) transformer architectures of interest, _Dtrain_ : fine-tuning data set for the target task, _r_ : rank of the low-rank matrices and distillation factor _α ∈_ [0 _,_ 1]. Loss functions: Target task loss _ℓ_ task, knowledge distillation loss _ℓ_ KD, feature distillation loss _ℓ_ FD. Multistage Training: 1: for stage _s_ = 0 _,_ 1 _,_ 2 do 2: Initialize the low-rank matrices _{As, Bs}_ to be learned at stage _s_ . for iteration = 1 _, ..._ do 3: for iteration = 1 _, ..._ do 4: Get a mini-batch _B_ of training examples from data set _Dtrain_ : _{_ ( _x_ <sup>_i_</sup> _, y_ <sup>_i_</sup> ) _∈Dtrain | i ∈B}_ . 5: 5: Tch Load the super-transformer model with weights WSup _←_ W <sup>pretrain</sup> 6: _l_ =0 <sup>_Al ∗_</sup> <sup>_Bl_</sup> <sup>.</sup> 6: _As_ := _{_ Φ1 _,_ Φ2 _, · · · } ←_ sample_sub-transformers ( _A,_ stage = _s_ ). [Φ1 is the maxnet]. 7: for each Φ _j_ _∈As_ do 8: : _{_ ( _x_ <sup>_i_</sup> _, y_ <sup>_i_</sup> ) Tch <sup>pretrain</sup> _l_ = _s_ ). [Φ1 + <sup>�</sup> <sup>_s_</sup> 8: Load the sub-transformer model Φ _j_ with weights WΦ _j_ := Π Φ _j_ (WSup). 9: _nj_ := # of fine-tuning weights in model configuration Φ _j_ . <sup>_i_</sup> Φ _j_ <sup>_←_</sup> <sup>fΦ</sup> _j_ <sup>(</sup> <sup>_xi_</sup> <sup>; WΦ</sup> _j_ <sup>)</sup> <sup>_,_</sup> <sup>_∀i ∈B_</sup> <sup>.</sup> 10: Compute forward-pass on the sub-transformer Φ _j_ : _y_ ˆ _j_ <sup>_i_</sup> _j_ <sup>_i,_</sup> <sup>h</sup> <sup>_i_</sup> _j_ <sup>_i_</sup> <sup>_, z_</sup> _j_ <sup>_i_</sup> 11: For the case of maxnet (Φ1) set the distillation factor _α_ to 0. 12: Find the loss: loss <sup>_i_</sup> _j_ <sup>_i_</sup> <sup>_, yi_</sup> <sup>] +</sup> <sup>_α_</sup> <sup>_i_</sup> _j_ <sup>_←_</sup> <sup>(1</sup> <sup>_−_</sup> <sup>_α_</sup> <sup>)</sup> <sup>_ℓ_</sup> <sup>task[ˆ</sup> <sup>_y_</sup> _j_ <sup>_i_</sup> _j_ <sup>_i_</sup> <sup>) using backward-pass on sub-transformer Φ</sup> <sup>_j_</sup> <sup>.</sup> _α_ _ℓ_ KD[ _zj_ <sup>_i_</sup> _j_ <sup>_i, z_</sup> 1 <sup>_i_</sup> 1 <sup>_i_</sup> <sup>]</sup> <sup>+</sup> <sup>_ℓ_</sup> <sup>FD[</sup> <sup>h</sup> <sup>_i_</sup> Φ _j_ <sup>_,_</sup> <sup>h</sup> <sup>_i_</sup> Φ <sup>_i_</sup> 1 <sup>]</sup> _,_ _∀i ∈B_ . - <sup>Φ</sup> <sup>_j_</sup> <sup>.</sup> 13: Compute gradients ( _∇As_ loss <sup>_i_</sup> _j_ end for 14: end for <sup>_i_</sup> _j_ <sup>_, ∇B_</sup> _s_ <sup>loss</sup> _j_ <sup>_i_</sup> 15: Update _As, Bs_ using the gradients ( _∇_ <sup>ˆ</sup> _AsL_ Sup _,_ _∇_ <sup>ˆ</sup> _BsL_ Sup) of the super-transformer’s loss: _∇_ ˆW _L_ Φ _j_ _,_ _∇_ ˆW _L_ Φ _j_ = <sup><u>1</u></sup> - _γ_ _|B|_ _|B|_ <u>1</u> _∇_ ˆW _L_ Sup = _|As|_ Φ _j_ _∈As_ - _j_ _∈A_ _nj_ - _<u>n</u>_ <u>1</u> _s_ - _i∈B_ _∇_ Wloss <sup>_i_</sup> _j_ <sup>_,_</sup> <sup>_∀_</sup> <sup>W</sup> <sup>_∈{As, Bs}._</sup> <sup>(6)</sup> _∇_ Wloss <sup>_i_</sup> _j_ 16: end for 17: end for <u>Output:</u> _<u>{As</u>_ <u>,</u> _Bs}s_ <sup>2</sup> <sup>i</sup> _<u>s</u>_ <sup>2</sup> <u>=0</u> <sup><u>and fne-tuned super-transformer weights:i</u></sup> <sup>WSup</sup> <sup>= W</sup> <u>Tch</u> <sup>pretrain</sup> _<u>s</u>_ <u>=0</u> <sup>_As ∗_</sup> <sup>_Bs_</sup> <sup><u>.</u></sup> Stage- _s_ of the fine-tuning process involves learning only the low-rank matrices, _As_, _Bs_, by minimizing the super-transform loss as in (3). In stage-1, we sample sub-transformer models by sampling different widths from the super-transformer keeping the depth (number of layers) same as the maxnet. In stage-2, we sample sub-transformer models by sampling different widths as well as depths. We always sample the maxnet model from the supertransformer as the 1 <sup>_st_</sup> sub-transformer model, Φ1, at every iteration. We call this M ultistage L owrank F ine-tuning of S uper-transformers (MLFS) and present it in Algorithm 1. Proposition 1 _Let_ _the_ _individually_ _fine-tuned_ _weights_ _of_ _a_ _subnet,_ Φ _,_ _be_ _expressed_ _as_ WΦ = Π Φ(WTch <sup>pretrain</sup> ) + ∆WΦ _._ _Then, MLFS has the fol-_ _lowing structure on_ ∆WΦ _:_ _where_ _{As, Bs}s_ =0 _,_ 1 _,_ 2 _are_ _low-rank_ _matrices_ _shared across all sub-transformers_ Φ _∈A._ To illustrate the computational savings, recall WTch <sup>pretrain</sup> _∈_ R <sup>_d×d_</sup>, where _d_ is typically of the order 10 <sup>4</sup> _−_ 10 <sup>6</sup> . For rank _r_ (typically _<_ 10) for the low-rank matrices: _As_ _∈_ R <sup>_d×r_</sup>, _Bs_ _∈_ R <sup>_r×d_</sup> _,_ _s_ = 0 _,_ 1 _,_ 2, where _r_ _≪_ _d_ . Then, the number of parameters to be learnt in the MLFS approach is 6 _rd_ . In contrast, full fine-tuning requires updating _d_ <sup>2</sup> <sup>i</sup> <u>Tch</u> <sup>pretrain</sup> _<u>s</u>_ + <sup><u>�2</u></sup> To illustrate the computational savings, recall WTch <sup>pretrain</sup> _∈_ R <sup>_d×d_</sup>, where _d_ is typically of the or _,_ _∀_ Φ _∈A,_ (9) 55 parameters at every iteration. Gradient Scaling For faster convergence of the smaller sub-transformers within a super- transformer, we propose a novel weighted-combination of the gradients of the sampled sub-transformers. Proposition 2 _Let_ 1 <sup>_st_</sup> _sampled_ _sub-transformer,_ Φ1 _, be the maxnet be in every iteration._ _Then the_ _scaled gradient of the super-transformer training_ ∆WΦ = Π Φ _s_ =0 <sup>_As ∗_</sup> <sup>_Bs_</sup> ��2 _loss, L_ Sup _, in Algorithm 1 is given by_ _j_ =1 <sup>(</sup> <sup>_n_</sup> <sup>1</sup> <sup>_/nj_</sup> <sup>)</sup> <sup>_γ ∇_</sup> <sup>W</sup> <sup>_L_</sup> <sup>Φ</sup> _j_ <sup>_,_</sup> (10) - _K_ _only_ _those_ vector from _l_ -th layer of sub-transformer Φ _j_ . In super-transformers, the model (maxnet) having the largest configuration, Φ1, acts as the teacher and knowledge distillation loss for all other subtransformers w.r.t the teacher is defined as _where_ _∇_ W _denotes_ _gradient_ _w.r.t._ _only_ _those_ _weights that are being fine-tuned (in this case only_ _the LoRA matrices), nj_ _denotes the actual number_ _of trainable weights in model configuration_ Φ _j_ _and_ _γ_ _≥_ 1 _is a hyper-parameter._ Proof: Each sub-transformer gradient in (10), grad <sup>_j_</sup>, is scaled by ( _n_ 1 _/nj_ ), which is obtained from the relative weighting of the loss functions. Let _Lj_ (W) denote the _j_ -th sub-transformer’s loss. Using first-order Taylor expansion, we get: to a low-dimensional space R <sup>_d_</sup> <sup>low</sup> : _ℓ_ KD[ _z_ Φ <sup>_i_</sup> Φ <sup>_i_</sup> 1 <sup>] = KL[</sup> <sup>_σ_</sup> <sup>(</sup> <sup>_z_</sup> Φ <sup>_i_</sup> Φ <sup>_i_</sup> _j_ <sup>_, z_</sup> Φ <sup>_i_</sup> Φ <sup>_i_</sup> _j_ <sup>_/t_</sup> <sup>)</sup> <sup>_,_</sup> <sup>_σ_</sup> <sup>(</sup> <sup>_zi_</sup> Φ <sup>_i_</sup> 1 <sup>_/t_</sup> <sup>) ]</sup> <sup>_,_</sup> <sup>_∀j_</sup> <sup>_>_</sup> <sup>1</sup> <sup>_,_</sup> where KL[ _·, ·_ ] denotes the standard KL divergence between two probability vectors, and _t_ _≥_ 1 is a hyper-parameter called the temperature. Let _dj_ denote the embedding dimension (hidden size) in sub-transformer Φ _j_ . We compute feature based distillation loss by projecting features h <sup>_i,l_</sup> Φ _j_ <sup>_∈_</sup> <sup>R</sup> <sup>_dj_</sup> <sup>_i,l_</sup> Φ _j_ <sup>_∈_</sup> <sup>R</sup> <sup>_dj_</sup> _L_ Φ _j_ (W + _δ_ ) _≈L_ Φ _j_ (W) + _⟨∇_ W _L_ Φ _j_ (W) _,_ _δ_ _⟩,_ where _⟨·, ·⟩_ denotes inner (dot) product operation. Therefore, the steepest possible decrease in the loss function _L_ Φ _j_ can be approximated as: ∆ _L_ Φ _j_ _≈∥∇_ W _L_ Φ _j_ (W) _∥_ 1 _|_ _δ_ _|max_ _≈_ _O_ ( _nj_ ) _|_ _δ_ _|max,_ where we approximate the _∥· ∥_ 1 norm using the zero-th norm, i.e., number of non-zero elements and _nj_ stands for the actual number of trainable parameters in sub-transformer configuration Φ _j_ . Since the decrease in the loss of a sub-transformer model Φ _j_ is approximately proportional to the number of trainable model parameters ( _nj_ ), we scale the losses using ( _n_ 1 _/nj_ ) <sup>_γ_</sup> _, γ_ _≥_ 1 so that training losses of smaller sub-transformer models converge at a rate similar to that of larger sub-transformer configurations. Recall that _n_ 1 is the maximum number of trainable parameters as 1 <sup>_st_</sup> sampled subtransformer Φ1 is always the maxnet. Distillation Loss for Super-transformers: Knowledge distillation is straightforward in a fixed-network fine-tuning setting. However, it is less so when fine-tuning a supernet, and in particular, fine-tuning a supernet using the proposed multistage LoRA based approach. Specifically, the subnets receive two types of knowledge distillation (KD) from the teacher: (a) the usual KD loss that utilizes the output logits of the teacher and (b) distillation of features from transformer layers (Jiao et al., 2020) of the teacher. tion matrices _{_ U <sup>_l_</sup> 1 <sup>:</sup> <sup>_l_</sup> <sup>= 1</sup> <sup>_,_</sup> <sup>2</sup> <sup>_, . . .}_</sup> <sup>, making feature</sup> distillation in a super-transformer setting computationally efficient. Additionally, we save computation through use of features only from a fixed subset of maxnet layers for distillation across all sub-transformers: i.e., we use the following subset of maxnet layers: _{ g_ min( _l_ ) : _l_ = 1 _, . . .,_ _L_ min _}_, where _L_ min denotes the number of transformer layers in the smallest sub-transformer Φmin and _g_ min maps layer indices of Φmin to that of maxnet Φ1. 6 Results on Encoder and Decoder LLMs We report performance on encoder tasks using GLUE (Wang et al., 2018) with BERT _base_ as the teacher model ΦTch. For decoder LLMs, we use Santacoder (Allal et al., 2023) and Codellama7B (Rozière et al., 2023) on a python coding task using _bigcode/the-stack_ data (Kocetkov et al., 2022). We 1 <sup>h</sup> <sup>_i,g_</sup> Φ1 <sup>_j_</sup> <sup>(</sup> <sup>_l_</sup> <sup>)</sup> 2 <sup>_,_</sup> <sup>_l_</sup> _∥_ <sup>2</sup> 2 <sup>2</sup> <sup>_,_</sup> _ℓ_ FD[ h <sup>_i_</sup> Φ <sup>_i_</sup> 1 <sup>] =</sup> _j_ <sup>_l_</sup> <sup>h</sup> <sup>_i,l_</sup> Φ <sup>_i,l_</sup> Φ _j_ <sup>_−_</sup> <sup>U</sup> 1 <sup>_l_</sup> <sup>_i_</sup> Φ _j_ <sup>_,_</sup> <sup>h</sup> <sup>_i_</sup> _l_ _β_ <sup>_l_</sup> _j_ <sup>_l_</sup> <sup>_∥_</sup> <sup>U</sup> _j_ <sup>_l_</sup> where _gj_ maps each layer index of the subtransformer configuration Φ _j_ to that of the supertransformer ( / maxnet Φ1). In this paper, we propose to share the maxnet’s feature projection matrices _{_ U <sup>_l_</sup> 1 <sup>_∈_</sup> <sup>R</sup> <sup>_d_</sup> <sup>low</sup> <sup>_×d_</sup> <sup>1</sup> <sup>_}_</sup> <sup>across all sub-transformer</sup> trices _{_ U <sup>_l_</sup> 1 <sup>_∈_</sup> <sup>R</sup> <sup>_d_</sup> <sup>low</sup> <sup>_×d_</sup> <sup>1</sup> <sup>_}_</sup> <sup>across all sub-transformer</sup> models. We do so by slicing the matrices _{_ U <sup>_l_</sup> 1 <sup>_}_</sup> <sup>:</sup> <sup>_l_</sup> 1 <sup>_}_</sup> <sup>:</sup> <sup>_l_</sup> _j_ <sup>:=</sup> <sup>[</sup> <sup>U</sup> <sup>_g_</sup> 1 <sup>_j_</sup> <sup>(</sup> <sup>_l_</sup> <sup>)</sup> U <sup>_l_</sup> _j_ <sup>_g_</sup> 1 <sup>_j_</sup> <sup>(</sup> <sup>_l_</sup> <sup>)</sup> ]Φ _j_ _∈_ R <sup>_d_</sup> <sup>low</sup> <sup>_×dj_</sup> _,_ (11) where the operation [ ]Φ _j_ selects appropriate subset of columns depending on the configuration Φ _j_ . To reduce the number of user-chosen hyper-parameters, we propose the following hyperparameter sharing: _βj_ <sup>_l_</sup> <sup>:=</sup> <sup>_βg_</sup> _j_ <sup>(</sup> <sup>_l_</sup> <sup>)</sup> <sup>_,_</sup> <sup>_∀j,_</sup> <sup>_l_</sup> <sup>=</sup> <sup>1</sup> <sup>_,_</sup> <sup>2</sup> <sup>_, . . ._</sup> <sup>.</sup> parameter sharing: _βj_ <sup>_l_</sup> <sup>:=</sup> <sup>_βg_</sup> _j_ <sup>(</sup> <sup>_l_</sup> <sup>)</sup> <sup>_,_</sup> <sup>_∀j,_</sup> <sup>_l_</sup> <sup>=</sup> <sup>1</sup> <sup>_,_</sup> <sup>2</sup> <sup>_, . . ._</sup> <sup>.</sup> Thus, apart from setting fewer hyper-parameters, one needs to learn only maxnet’s feature projection matrices _{_ U <sup>_l_</sup> 1 <sup>:</sup> <sup>_l_</sup> <sup>= 1</sup> <sup>_,_</sup> <sup>2</sup> <sup>_, . . .}_</sup> <sup>, making feature</sup> distillation in a super-transformer setting compu To define the distillation based losses precisely, let the forward-pass mapping of an input training sample _x_ <sup>_i_</sup> through sub-transformer Φ _j_ be _y_ ˆ _j_ <sup>_i_</sup> <sup>_, z_</sup> _j_ <sup>_i,_</sup> <sup>h</sup> <sup>_i_</sup> Φ _j_ <sup>_←_</sup> <sup>fΦ</sup> _j_ <sup>(</sup> <sup>_xi_</sup> <sup>; WΦ</sup> _j_ <sup>),</sup> <sup>where</sup> <sup>h</sup> _j_ <sup>_i_</sup> <sup>:=</sup> _j_ <sup>_i_</sup> <sup>_, z_</sup> _j_ <sup>_i_</sup> _j_ <sup>_i,_</sup> <sup>h</sup> <sup>_i_</sup> _j_ <sup>_i_</sup> <sup>:=</sup> ( h <sup>_i,_</sup> _j_ <sup>1</sup> <sup>_i,_</sup> _j_ <sup>1</sup> <sup>_,_</sup> <sup>_. . .,_</sup> <sup>h</sup> <sup>_i,l_</sup> _j_ <sup>_i,l_</sup> _j_ <sup>_,_</sup> <sup>_. . ._</sup> <sup>) with</sup> <sup>h</sup> <sup>_i,l_</sup> _j_ <sup>_i_</sup> Φ _j_ <sup>_←_</sup> <sup>fΦ</sup> _j_ <sup>(</sup> <sup>_xi_</sup> <sup>; WΦ</sup> _j_ <sup>),</sup> <sup>where</sup> <sup>h</sup> _j_ <sup>_i_</sup> <sup>_i,l_</sup> _j_ <sup>denoting the feature</sup> 56 90 80 70 60 90 80 70 60 <u>Data set: SST2</u> TinyBERT DistilBERT PD-BERT BERT-PKD DynaBERT MLFS <u>40</u> <u>50</u> <u>60</u> <u>70</u> <u>80</u> <u>90</u> # Parameters (M) <u>Data set: SST2</u> TinyBERT DistilBERT DynaBERT MLFS <u>75</u> <u>100</u> <u>125</u> <u>150</u> <u>175</u> <u>200</u> Latency (ms) 90 80 70 60 90 80 70 60 <u>Data set: RTE</u> <u>40</u> <u>50</u> <u>60</u> <u>70</u> <u>80</u> <u>90</u> # Parameters (M) <u>Data set: RTE</u> <u>75</u> <u>100</u> <u>125</u> <u>150</u> <u>175</u> <u>200</u> Latency (ms) 90 80 70 60 90 80 70 60 <u>Data set: MRPC</u> <u>40</u> <u>50</u> <u>60</u> <u>70</u> <u>80</u> <u>90</u> # Parameters (M) <u>Data set: MRPC</u> <u>75</u> <u>100</u> <u>125</u> <u>150</u> <u>175</u> <u>200</u> Latency (ms) Figure 1: Performance of task-specific BERT models produced by MLFS vs. other methods on 3 GLUE data sets. report performance of the sub-transformer models at the end of stage _s_ = 2. On GLUE, we use the train set for fine-tuning and the dev set for accuracy evaluation. For santacoder, we evaluate performance using HumanEval (Chen et al., 2021a) and report pass@1 scores. All experiments were conducted using PyTorch on a single Nvidia A100 (40GB) GPU. Additional details on the experiment settings are provided in the Appendix. 6.1 Performance of Encoder Models We compare performance of encoder models ob tained with the MLFS approach against a static, fixed model (BERT base) from (Zhang et al., 2021; Hou et al., 2020), two popular distilled variants of the fixed model: TinyBERT (Jiao et al., 2020) and DistilBERT (Sanh et al., 2019), and models trained using existing super-transformer methods (DynaBERT (Hou et al., 2020). Figure 1 shows the performance of the palette of models, from a 45M param. minnet to full-size 110M maxnet. Encoder models produced by MLFS are at par or better than much costlier methods. Results of PDBERT, BERT-PKD are from (Zhang et al., 2021), static BERT from (Zhang et al., 2021) for all except MRPC for which we use (Hou et al., 2020). Note that TinyBERT performs data augmentation leading to higher accuracy but much longer computation time. We do not perform data augmentation for fairness of the comparison to the other methods. The main observation is that MLFS provides accurate, smaller encoder models at 1/4 the size of the teacher and 1/3 its runtime latency on a single GPU. Figure 2: Ablation study on gradient scaling: MLFS minnet convergence is improved using gradient scaling. Ablation Study on Gradient Scaling In supernet training, the weights of maxnet and subnets are shared and trained simultaneously. The maxnet tends to converge and overfit earlier than smaller subnets. The different convergence rates renders selecting a single supernet checkpoint for all networks difficult. Gradient scaling solves this by speeding up convergence of the smaller subnets to match that of the larger subnets or the maxnet. Fig. 2 shows that gradient scaling improves minnet convergence, indicated by lower minnet loss. Figure 3: Ablation study on MLFS rank of _A, B_ . Maxnet (top: blue), minnet (bottom: green), and average of two medium-sized subnets (middle: orange). Rank _r_ = 8 is optimal for small and medium subnets. Ablation Study on Rank in MLFS Finally, in Fig. 3, we examines the impact of rank _r_ of the 57 matrices _A, B_ on performance. Note that the actual number of parameters fine-tuned vary as we vary the rank _r_ . The aim is to provide good results for the smaller networks. Here, rank _r_ = 8 works well across the GLUE data sets. Therefore, we use rank _r_ = 8 for _A, B_ for all other MLFS experiments. From the scale of the y-axis in 3, observe that MLFS is not overly sensitive to the chosen rank. 6.2 Performance of Decoder Models 4 3 2 1 Full FT + random init. MLFS ( =0, r=8) MLFS ( =0.9, r=8) 0 10000 20000 30000 40000 50000 Iteration 20 15 10 5 0 Full FT + random init. MLFS ( =0, r=8) MLFS ( =0.9, r=8) Teacher (Santacoder 1.1B) 10K 400K 1.2M 24.2M Data set size (# of examples) Figure 4: Performance of MLFS on a custom Santacoder 0.7B model using 10K/400K/1.2M training examples. <u>Model size</u> Data set size <u>0.5B</u> <u>0.7B</u> <u>0.9B</u> <u>10K</u> <u>4.5</u> <u>8.6</u> <u>13.4</u> <u>400K</u> <u>4.7</u> <u>9.5</u> <u>13.5</u> Table 1: HumanEval pass@1 (%) performance of 3 small models produced by MLFS from Santacoder 1.1B. <u>Model size</u> Data set size <u>4.5B</u> <u>5.3B</u> <u>6B</u> <u>200K</u> <u>11.0</u> <u>19.5</u> <u>23.2</u> <u>400K</u> <u>14.0</u> <u>28.1</u> <u>30.5</u> Table 2: HumanEval pass@1 (%) performance of 3 small models produced by MLFS from CodeLlama7B-Python Turning now to decoder models, we consider two code-pre-trained LLMs, Santacoder (Allal et al., 2023) and Codellama7B (Rozière et al., 2023). We evaluate a custom 0.7B parameter Santacoder model obtained from the 1.1B teacher. Due to an inability to fine-tune on the full 24M coding examples, we use up to 1.2M. Fig. 4 shows that MLFS pass@1 improves rapidly as number of tokens increases from a low 10k to 400k to 1.2M examples, only 5% of the 24M examples. Table 1 shows analogous results with 3 small MLFS models. The Figure 5: Convergence comparison of validation loss while fine-tuning a custom model from random vs using MLFS. MLFS achieves low validation loss much faster. improvement in pass@1 indicates that the smaller models retain the ability to learn from the larger teacher. Again, from Table 2, we see that smaller models produced by MLFS from _CodeLlama-7B-_ _Python_ retain their ability to learn and improve quickly as the number of examples increases. Note that the full data set includes 24M examples; MLFS achieves nearly 75% of the performance of fullsize CodeLlama after less than 2% of the examples. Contrary to encoder models, the compression levels that retain sufficient performance of the teacher with decoders is less. While MLFS retains accuracy performance of encoder models at 1/4 the size of the teacher, the decoder models are reduced to at most 2/3 the teacher’s size. MLFS slicing of the teacher model can, however, benefit decoder models by reducing substantially the training/fine-tuning time needed compared to a randomly-initialised model, as shown in Fig. 5 on Santacoder sliced from 1.1B to 0.7B. In other words, when a smaller model is required for edge inference, one can train it from a random initialisation, or slice from a teacher as does MLFS, and train starting from the sliced weights. The latter significantly reduces training time as seen in the validation loss curves. See (Samragh et al., 2023) for a similar observation. 7 Perspectives Enterprise users require an efficient way to finetune LLMs for inference on edge devices of many sizes. We developed MLFS for such edge deployment scenarios. We demonstrate its benefits on encoder LLMs. We show the limitation of compressing decoder LLMs to a comparable degree; however, MLFS offers significant gains for smaller decoder training/fine-tuning by slicing from a larger pre-trained teacher. 58 References Loubna Ben Allal, Raymond Li, Denis Kocetkov, Chenghao Mou, Christopher Akiki, Carlos Munoz Ferrandis, Niklas Muennighoff, Mayank Mishra, Alex Gu, Manan Dey, et al. 2023. Santacoder: don’t reach for the stars! _arXiv preprint arXiv:2301.03988_ . Elad Ben Zaken, Yoav Goldberg, and Shauli Ravfogel. 2022. BitFit: [Simple parameter-efficient fine-tuning](https://doi.org/10.18653/v1/2022.acl-short.1) [for transformer-based masked language-models.](https://doi.org/10.18653/v1/2022.acl-short.1) In _Proceedings of the 60th Annual Meeting of the As-_ _sociation for Computational Linguistics (Volume 2:_ _Short Papers)_, pages 1–9, Dublin, Ireland. Association for Computational Linguistics. Aishwarya Bhandare, Vamsi Sripathi, Deepthi Karkada, Vivek Menon, Sun Choi, Kushal Datta, and Vikram Saletore. 2019. Efficient 8-bit quantization of transformer neural machine language translation model. _arXiv preprint arXiv:1906.00532_ . Tom Brown, Benjamin Mann, Nick Ryder, Melanie Subbiah, Jared D Kaplan, Prafulla Dhariwal, Arvind Neelakantan, Pranav Shyam, Girish Sastry, Amanda Askell, et al. 2020. Language models are few-shot learners. _Advances in neural information processing_ _systems_, 33:1877–1901. Han Cai, Chuang Gan, Tianzhe Wang, Zhekai Zhang, and Song Han. 2019. Once-for-all: Train one network and specialize it for efficient deployment. _arXiv_ _preprint arXiv:1908.09791_ . Han Cai, Ligeng Zhu, and Song Han. 2018. Proxyless nas: Direct neural architecture search on target task and hardware. _arXiv preprint arXiv:1812.00332_ . Mark Chen, Jerry Tworek, Heewoo Jun, Qiming Yuan, Henrique Ponde de Oliveira Pinto, Jared Ka plan, Harri Edwards, Yuri Burda, Nicholas Joseph, Greg Brockman, Alex Ray, Raul Puri, Gretchen Krueger, Michael Petrov, Heidy Khlaaf, Girish Sastry, Pamela Mishkin, Brooke Chan, Scott Gray, Nick Ryder, Mikhail Pavlov, Alethea Power, Lukasz Kaiser, Mohammad Bavarian, Clemens Winter, Philippe Tillet, Felipe Petroski Such, Dave Cummings, Matthias Plappert, Fotios Chantzis, Elizabeth Barnes, Ariel Herbert-Voss, William Hebgen Guss, Alex Nichol, Alex Paino, Nikolas Tezak, Jie Tang, Igor Babuschkin, Suchir Balaji, Shantanu Jain, William Saunders, Christopher Hesse, Andrew N. Carr, Jan Leike, Josh Achiam, Vedant Misra, Evan Morikawa, Alec Radford, Matthew Knight, Miles Brundage, Mira Murati, Katie Mayer, Peter Welinder, Bob McGrew, Dario Amodei, Sam McCandlish, Ilya Sutskever, and Wojciech Zaremba. 2021a. Evaluating large language models trained on code. _arXiv_ _preprint arXiv:2107.03374_ . Tim Dettmers, Artidoro Pagnoni, Ari Holtzman, and Luke Zettlemoyer. 2023. Qlora: Efficient finetuning of quantized llms. _arXiv preprint arXiv:2305.14314_ . Peijie Dong, Xin Niu, Lujun Li, Linzhen Xie, Wen bin Zou, Tian Ye, Zimian Wei, and Hengyue Pan. 2022. Prior-guided one-shot neural architecture search. _arXiv preprint arXiv:2206.13329_ . Jiahui Gao, Hang Xu, Han Shi, Xiaozhe Ren, LH Philip, Xiaodan Liang, Xin Jiang, and Zhenguo Li. 2022. Autobert-zero: Evolving bert backbone from scratch. In _Proceedings of the AAAI Conference on Artificial_ _Intelligence_, volume 36-10, pages 10663–10671. Yuxian Gu, Li Dong, Furu Wei, and Minlie Huang. 2023. Knowledge distillation of large language models. _arXiv preprint arXiv:2306.08543_ . Zichao Guo, Xiangyu Zhang, Haoyuan Mu, Wen Heng, Zechun Liu, Yichen Wei, and Jian Sun. 2020. Single path one-shot neural architecture search with uniform sampling. In _Computer_ _Vision–ECCV_ _2020:_ _16th European Conference, Glasgow, UK, August 23–_ _28, 2020, Proceedings, Part XVI 16_, pages 544–560. Springer. Lu Hou, Zhiqi Huang, Lifeng Shang, Xin Jiang, Xiao Chen, and Qun Liu. 2020. Dynabert: Dynamic bert with adaptive width and depth. _Advances in Neural_ _Information Processing Systems_, 33:9782–9793. Cheng-Yu Hsieh, Chun-Liang Li, Chih-Kuan Yeh, Hootan Nakhost, Yasuhisa Fujii, Alexander Ratner, Ranjay Krishna, Chen-Yu Lee, and Tomas Pfister. 2023. Distilling step-by-step! outperforming larger language models with less training data and smaller model sizes. _arXiv preprint arXiv:2305.02301_ . Edward J Hu, Yelong Shen, Phillip Wallis, Zeyuan Allen-Zhu, Yuanzhi Li, Shean Wang, Lu Wang, and Weizhu Chen. 2022. [LoRA: Low-rank adaptation of](https://openreview.net/forum?id=nZeVKeeFYf9) [large language models.](https://openreview.net/forum?id=nZeVKeeFYf9) In _International Conference_ _on Learning Representations_ . Ganesh Jawahar, Haichuan Yang, Yunyang Xiong, Zechun Liu, Dilin Wang, Fei Sun, Meng Li, Aasish Pappu, Barlas Oguz, Muhammad AbdulMageed, Laks V. S. Lakshmanan, Raghuraman Krishnamoorthi, and Vikas Chandra. 2023. Mixtureof-supernets: Improving weight-sharing supernet training with architecture-routed mixture-of-experts. _arXiv preprint arXiv:2306.04845_ . Minghao Chen, Houwen Peng, Jianlong Fu, and Haibin Ling. 2021b. Autoformer: Searching transformers for visual recognition. In _Proceedings_ _of_ _the_ _IEEE/CVF international conference on computer vi-_ _sion_, pages 12270–12280. Xiaoqi Jiao, Yichun Yin, Lifeng Shang, Xin Jiang, Xiao Chen, Linlin Li, Fang Wang, and Qun Liu. 2020. [TinyBERT: Distilling BERT for natural language un-](https://doi.org/10.18653/v1/2020.findings-emnlp.372) [derstanding.](https://doi.org/10.18653/v1/2020.findings-emnlp.372) In _Findings of the Association for Com-_ _putational Linguistics:_ _EMNLP 2020_, pages 4163– 4174, Online. Association for Computational Linguistics. Denis Kocetkov, Raymond Li, Loubna Ben Allal, Jia Li, Chenghao Mou, Carlos Muñoz Ferrandis, Yacine Jernite, Margaret Mitchell, Sean Hughes, Thomas Wolf, Dzmitry Bahdanau, Leandro von Werra, and 59 Harm de Vries. 2022. The stack: 3 tb of permissively licensed source code. _arXiv_ _preprint_ _arXiv:2211.15533_ . Achintya Kundu, Laura Wynter, Rhui Dih Lee, and Luis Angel D. Bathen. 2023. [Transfer-once-for-all:](https://doi.org/10.1109/EDGE60047.2023.00017) AI [model optimization for edge.](https://doi.org/10.1109/EDGE60047.2023.00017) In _IEEE International_ _Conference_ _on_ _Edge_ _Computing_ _and_ _Communica-_ _tions, EDGE 2023, Chicago, IL, USA, July 2-8, 2023_, pages 26–35. IEEE. Zhenzhong Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, and Radu Soricut. 2019. Albert: A lite bert for self-supervised learning of language representations. _arXiv_ _preprint_ _arXiv:1909.11942_ . Wei Lou, Lei Xun, Amin Sabet, Jia Bi, Jonathon Hare, and Geoff V Merrett. 2021. Dynamic-ofa: Runtime dnn architecture switching for performance scaling on heterogeneous embedded platforms. In _Proceed-_ _ings of the IEEE/CVF Conference on Computer Vi-_ _sion and Pattern Recognition_, pages 3110–3118. Xindian Ma, Peng Zhang, Shuai Zhang, Nan Duan, Yuexian Hou, Ming Zhou, and Dawei Song. 2019. A tensorized transformer for language modeling. _Ad-_ _vances in neural information processing systems_, 32. Mohammad Samragh, Mehrdad Farajtabar, Sachin Mehta, Raviteja Vemulapalli, Fartash Faghri, Devang Naik, Oncel Tuzel, and Mohammad Rastegari. 2023. Weight subcloning: [direct initialization of transform-](http://arxiv.org/abs/2312.09299) [ers using larger pretrained ones.](http://arxiv.org/abs/2312.09299) Victor Sanh, Lysandre Debut, Julien Chaumond, and Thomas Wolf. 2019. Distilbert, a distilled version of bert: smaller, faster, cheaper and lighter. _arXiv_ _preprint arXiv:1910.01108_ . Sheng Shen, Zhen Dong, Jiayu Ye, Linjian Ma, Zhewei Yao, Amir Gholami, Michael W Mahoney, and Kurt Keutzer. 2020. Q-bert: Hessian based ultra low precision quantization of bert. In _Proceedings of the AAAI_ _Conference on Artificial Intelligence_, volume 34-05, pages 8815–8821. Siqi Sun, Yu Cheng, Zhe Gan, and Jingjing Liu. 2019. Patient knowledge distillation for bert model compression. _arXiv preprint arXiv:1908.09355_ . Elena Voita, David Talbot, Fedor Moiseev, Rico Sen nrich, and Ivan Titov. 2019. Analyzing multihead self-attention: Specialized heads do the heavy lifting, the rest can be pruned. _arXiv_ _preprint_ _arXiv:1905.09418_ . JS McCarley, Rishav Chakravarti, and Avirup Sil. 2019. Structured pruning of a bert-based question answering model. _arXiv preprint arXiv:1910.06360_ . Subhabrata Mukherjee and Ahmed Awadallah. 2020. Xtremedistil: Multi-stage distillation for massive multilingual models. _arXiv_ _preprint_ _arXiv:2004.05686_ . Subhabrata Mukherjee, Ahmed Hassan Awadallah, and Jianfeng Gao. 2021. Xtremedistiltransformers: Task transfer for task-agnostic distillation. _arXiv preprint_ _arXiv:2106.04563_ . Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J Liu. 2020. Exploring the limits of transfer learning with a unified text-to-text transformer. _The Journal of Machine Learning Research_, 21(1):5485–5551. Esteban Real, Alok Aggarwal, Yanping Huang, and Quoc V Le. 2019. Regularized evolution for image classifier architecture search. In _Proceedings of the_ _aaai conference on artificial intelligence_, volume 3301, pages 4780–4789. Baptiste Rozière, Jonas Gehring, Fabian Gloeckle, Sten Sootla, Itai Gat, Xiaoqing Ellen Tan, Yossi Adi, Jingyu Liu, Tal Remez, Jérémy Rapin, Artyom Kozhevnikov, Ivan Evtimov, Joanna Bitton, Manish Bhatt, Cristian Canton Ferrer, Aaron Grattafiori, Wenhan Xiong, Alexandre Défossez, Jade Copet, Faisal Azhar, Hugo Touvron, Louis Martin, Nicolas Usunier, Thomas Scialom, and Gabriel Synnaeve. 2023. [Code](http://arxiv.org/abs/2308.12950) llama: [Open foundation models for code.](http://arxiv.org/abs/2308.12950) Alex Wang, Amanpreet Singh, Julian Michael, Felix Hill, Omer Levy, and Samuel Bowman. 2018. [GLUE:](https://doi.org/10.18653/v1/W18-5446) [A multi-task benchmark and analysis platform for nat-](https://doi.org/10.18653/v1/W18-5446) [ural language understanding.](https://doi.org/10.18653/v1/W18-5446) In _Proceedings of the_ _2018_ _EMNLP_ _Workshop_ _BlackboxNLP:_ _Analyzing_ _and_ _Interpreting_ _Neural_ _Networks_ _for_ _NLP_, pages 353–355, Brussels, Belgium. Association for Computational Linguistics. Jiahui Yu, Pengchong Jin, Hanxiao Liu, Gabriel Ben der, Pieter-Jan Kindermans, Mingxing Tan, Thomas Huang, Xiaodan Song, Ruoming Pang, and Quoc Le. 2020. Bignas: Scaling up neural architecture search Dilin Wang, Meng Li, Chengyue Gong, and Vikas Chan dra. 2021. Attentivenas: Improving neural architecture search via attentive sampling. In _Proceedings_ _of the IEEE/CVF conference on computer vision and_ _pattern recognition_, pages 6418–6427. Hanrui Wang, Zhanghao Wu, Zhijian Liu, Han Cai, Ligeng Zhu, Chuang Gan, and Song Han. 2020. Hat: Hardware-aware transformers for efficient natural language processing. _arXiv preprint arXiv:2005.14187_ . Rui Wang, Qibing Bai, Junyi Ao, Long Zhou, Zhixiang Xiong, Zhihua Wei, Yu Zhang, Tom Ko, and Haizhou Li. 2022. Lighthubert: Lightweight and configurable speech representation learning with once-for-all hidden-unit bert. _arXiv preprint arXiv:2203.15610_ . Jin Xu, Xu Tan, Renqian Luo, Kaitao Song, Jian Li, Tao Qin, and Tie-Yan Liu. 2021. Nas-bert: task-agnostic and adaptive-size bert compression with neural architecture search. In _Proceedings of the 27th ACM_ _SIGKDD_ _Conference_ _on_ _Knowledge_ _Discovery_ _&_ _Data Mining_, pages 1933–1943. 60 with big single-stage models. In _Computer Vision–_ _ECCV 2020:_ _16th European Conference, Glasgow,_ _UK, August 23–28, 2020, Proceedings, Part VII 16_, pages 702–717. Springer. Ofir Zafrir, Guy Boudoukh, Peter Izsak, and Moshe Wasserblat. 2019. Q8bert: Quantized 8bit bert. In _2019_ _Fifth_ _Workshop_ _on_ _Energy_ _Efficient_ _Machine_ _Learning and Cognitive Computing-NeurIPS Edition_ _(EMC2-NIPS)_, pages 36–39. IEEE. Qingru Zhang, Minshuo Chen, Alexander Bukharin, Pengcheng He, Yu Cheng, Weizhu Chen, and Tuo Zhao. 2023. Adaptive budget allocation for parameter-efficient fine-tuning. _arXiv_ _preprint_ _arXiv:2303.10512_ . Shaokun Zhang, Xiawu Zheng, Chenyi Yang, Yuchao Li, Yan Wang, Fei Chao, Mengdi Wang, Shen Li, Jun Yang, and Rongrong Ji. 2021. You only compress once: Towards effective and elastic bert compression via exploit-explore stochastic nature gradient. _arXiv_ _preprint arXiv:2106.02435_ . B Additional Experimental Results First, we present additional results on distilling Santacoder-1.1B model. In Fig. 6, we compare HumanEval performance of a 0.7B Santacoder model fine-tuned through full fine-tuning (FT) from random initialisation vs. full-rank (non-LoRA) MLFS with ( _α_ = 0 _._ 9) and without ( _α_ = 0) distillation. The improvement in the evaluation numbers is remarkable even after fine-tuning on up to only 5% of the examples. In Fig. 7, we also show better convergence of validation loss on the Santacoder 0.7B for MLFS with distillation loss ( _α >_ 0). This demonstrates the benefit of MLFS distillation as compared to full MLFS fine tuning of the sliced model. Full FT + random init. MLFS ( =0, r: full-rank) MLFS ( =0.9, r: full-rank) Teacher (Santacoder 1.1B) 10K 400K 1.2M 24.2M Data set size (# of examples) Hui Zhu, Zhulin An, Chuanguang Yang, Kaiqiang Xu, Erhu Zhao, and Yongjun Xu. 2019. Eena: efficient evolution of neural architecture. In _Proceedings of_ _the_ _IEEE/CVF_ _International_ _Conference_ _on_ _Com-_ _puter Vision Workshops_, pages 0–0. Xunyu Zhu, Jian Li, Yong Liu, Can Ma, and Weip ing Wang. 2023. A survey on model compression for large language models. _arXiv_ _preprint_ _arXiv:2308.07633_ . 15 10 5 0 Barret Zoph and Quoc V Le. 2016. Neural architecture search with reinforcement learning. _arXiv preprint_ _arXiv:1611.01578_ . Appendix A Details of Experimental Set-up Following (Hu et al., 2022), we use the fine-tuned MNLI checkpoint to initialize the model weights for experiments on small data sets such as RTE and MRPC. In MLFS, the Low rank matrices are added on the QKV vectors and the intermediate size of feed-forward network (FFN) layers. We set _βl_ = 0 _._ 1 _∀l_ in feature distillation loss and choose distillation factor _α_ = 0 _._ 9. For training, we use a maximum sequence length of 128; effective batch size of 128 for QQP, MNLI, QNLI, and 64 for the other data sets. Training is done for a maximum of 8 epochs for all GLUE data sets except SST-2 for which we allocate maximum 3 epochs. We set an initial learning rate of 5 _e_ <sup>_−_</sup> <sup>4</sup> for QNLI & MNLI, and 1 _e_ <sup>_−_</sup> <sup>3</sup> for other GLUE data sets. We use rank _r_ = 8 for the low rank matrices _A, B_ unless mentioned otherwise. We choose gradient scaling hyper-parameter _γ_ = 1 for SST-2 and _γ_ = 2 for all other data sets. Figure 6: Superior performance of supernet training compared to other full fine-tuning based approaches on three data sets with 10K/400K/1.2M examples. 1.5 1.4 1.3 1.2 MLFS ( =0, r=8) MLFS ( =0.9, r=8) 0 10000 20000 30000 40000 50000 Iteration Figure 7: Convergence comparison of validation loss while fine-tuning a custom model using MLFS with/without distillation. Finally, in Fig. 8, we show performance of a spectrum of models distilled from BERT _base_ using MLFS on 3 more GLUE data sets: QNLI, QQP, and MNLI. 61 90 80 70 60 90 80 70 60 <u>Data set: QNLI</u> TinyBERT DistilBERT PD-BERT BERT-PKD MLFS <u>40</u> <u>50</u> <u>60</u> <u>70</u> <u>80</u> <u>90</u> # Parameters (M) <u>Data set: QNLI</u> TinyBERT DistilBERT MLFS <u>75</u> <u>100</u> <u>125</u> <u>150</u> <u>175</u> <u>200</u> Latency (ms) 90 80 70 60 90 80 70 60 <u>Data set: QQP</u> <u>40</u> <u>50</u> <u>60</u> <u>70</u> <u>80</u> <u>90</u> # Parameters (M) <u>Data set: QQP</u> <u>75</u> <u>100</u> <u>125</u> <u>150</u> <u>175</u> <u>200</u> Latency (ms) 90 80 70 60 90 80 70 60 <u>Data set: MNLI</u> <u>40</u> <u>50</u> <u>60</u> <u>70</u> <u>80</u> <u>90</u> # Parameters (M) <u>Data set: MNLI</u> <u>75</u> <u>100</u> <u>125</u> <u>150</u> <u>175</u> <u>200</u> Latency (ms) Figure 8: Performance of task-specific BERT models produced by MLFS vs. other methods on 3 GLUE data sets. 62

섹션 본문 87문단 · 29,303자

(제목 없음)

1Supernet training of LLMs is of great interest in industrial applications as it confers the ability to produce a palette of smaller models at constant cost, regardless of the number of models (of different size / latency) produced.We propose a new method called Multistage Low-rank Fine-tuning of Super-transformers (MLFS) for parameter-efficient supernet training.We show that it is possible to obtain highquality encoder models that are suitable for commercial edge applications, and that while decoder-only models are resistant to a comparable degree of compression, decoders can be effectively sliced for a significant reduction in training time.A considerable amount of research has focused on compressing LLMs [45,31,25,26,18,15].Methods that train a single small model guided by a large teacher model such as DistilBERT [31] and BERT-PKD[33], either achieve limited compression or do not scale to a large number of deployment devices.Supernet training methods[14,39,6,20,22,17]were introduced to address these limitations: multiple smaller subnets within the supernet are trained simultaneously with weight-sharing.This one-time training approach produces a palette of smaller models, helping mitigate the computational cost of fine-tuning a model for each deployment scenario.However, the full-parameter supernet training approach is impractical when fine-tuning of an LLM is required for multiple deployment scenarios, limiting its utility for enterprises.Parameter-efficient fine-tuning (PEFT) methods such as Low-Rank Adaptation (LoRA) reduces the number of trainable parameters by allowing only rank-decomposition matrices to be trained while freezing the pre-trained weights of the model.PEFT methods, however, are not applicable to supernet training due to the implications on the weight-shared subnetworks.Our work bridges this gap to enable efficient fine-tuning of LLMs for edge devices.Our contributions are:1. We propose a parameter-efficient, distillation-based approach for supernet training of LLMs.

Introduction

2Given their sizes up to billions of parameters, [27,4], it is challenging for enterprises to fine-tune Large Language Models (LLMs), and furthermore they are not suitable for deployment on edge devices with limited memory and computational power.We wish to enable LLMs on edge environments for enterprise use cases.This requires the following two capabilities.(1) Accommodating a variety of edge device hardware: A single fine-tuned model is not optimal across the spectrum of devices.For industrial applications, a palette of fine-tuned LLMs is required for different hardware.(2) Dynamically changing resource levels: At run-time, the available resources on edge devices evolve over time, and appropriate model should be dynamically selected based on the available resources of each device.

32. We devise a gradient scaling scheme to improve convergence speed of any form of supernet training.

43. We demonstrate significant compression of encoder models for edge.We highlight the limits of comparable compression for decoder models, while demonstrating a huge reduction in the steps needed for convergence.

Related Work

5Classical compression methods have been used for LLMs including pruning [24,34], low rank approximation [23,21], and quantization [32,41,3].Knowledge distillation (KD) is adopted in BERT-PKD [33], tinyBERT [18], and distilBERT [31] and [12] in MiniLLM to distill knowledge from the layers of a large transformer model to a smaller one.See also the survey [45].All these existing methods produce a single compressed model, unsuitable for edge scenarios with multiple deployment devices having varying computational capability.

6Neural architecture search (NAS) based on reinforcement learning [46] and evolutionary algorithms [28,44] trains every possible architecture and is very slow.Weight-sharing NAS was thus developed: in Guo et al. [13], Cai et al. [5], the building blocks in the same layer are isolated as all architectures are single paths.Weight-sharing NAS does not scale well to large architecture search spaces, hence, weight-entangled NAS, where subnets with common parts share weights, was introduced.

7For resource-constrained edge deployment, supernet training [6,20,8,39,11,10] was developed as a mode of jointly training multiple subnetworks (subnets) with entangled weights: one trains the supernet only once for all deployment scenarios.Cai et al. [6] introduced an elastic convolutional neural network with "progressive shrinkage", where larger subnets are trained first.Recent works have improved sampling strategies, e.g. the sandwich rule with in-place distillation [40], attentive sampling [36], stochastic nature gradient [43], or post-training sampling [22].Our work is related to supernet training for transformer models [14,43,38,37,8].This gradient scaling technique can be used with any of the above supernet methods.

8Parameter-efficient fine-tuning (PEFT) has been of great benefit in fine tuning LLMs.BitFit [2] updates the bias terms in pre-trained models while freezing the remaining parameters.LoRA [16] decomposes attention weight gradients into low-rank matrices to reduce the number of trainable parameters.AdaLoRA [42] and QLoRA [9] further improve LoRA [16].Note that PEFT allows fine-tuning a base model on a single GPU but does not produce smaller models.None of the PEFT methods can be used for weight-entangled supernet training.

Solution Design

9For use in enterprise settings, the solution must allow fine-tuning of models on a small GPU footprint.

10In addition, inference cost in terms of storage must be minimised.We therefore design a solution which does not store the full size model checkpoint for every downstream task but only the frozen weights of the pre-trained base model and the low rank matrices.For inference in commercial edge use cases, we wish to enable storing the desired models locally for a wide variety of edge device resource requirements.We thus develop an approach where storage is minimised, storing only one base model and as many low rank adapter matrices as there are target model size variations, where low-rank adapters are very small.If the model is stored locally on an edge device, our proposed slicing operation takes place where the supernet fine-tuning is performed and the desired model is downloaded for inference.The slicing operation takes place for each model size-task combination and each resulting subnet can be cached for inference.

Problem Formulation

11First, we provide notation.Given a transformer model with architectural configuration Φ and weights W, we denote its forward-pass mapping by f Φ (•; W) : X → Y.We consider the output space Y to be the set of all non-negative vectors in R ν with elements summing to 1, where ν denotes the number of classes / vocabulary size).With slight abuse of notation, we write the forward-pass mapping of an input x ∈ X through a transformer model Φ as ŷ, z, h = f Φ (x; W), where ŷ ∈ Y denotes the predicted probability distribution over the (class labels) vocabulary, z denotes the vector of logits, and h represents a tuple of features such as hidden state vectors and attention values from different transformer layers.Note that ŷ = σ(z), where σ is the standard soft-max function that maps a vector of logits into a probability vector.Given a training data set D train ⊂ X × Y, model weights W are learnt by minimizing training loss:

12where E denotes expectation over training example (x, y) drawn uniformly at random from D train and ℓ denotes a loss function.Most commonly, ℓ is chosen to be a task specific loss function, ℓ task , such as cross-entropy (i.e., CE[•, •]) for classification or causal language modeling loss for generative models.

13Next, we introduce the super-transformer and related terminologies.We define three types of networks -Teacher network, Super-transformer (supernet) and Sub-transformer (subnet).The teacher is a fixed network with the same configuration as the pre-trained transformer.A super-transformer is a dynamic model whose architectural dimensions (embedding dimension, number of heads, number of layers, etc.) are configurable at run time.The maxnet (resp.minnet) is the largest (resp.smallest) network in the super-transformer's architecture space.Weight entanglement (weight-sharing) allows supertransformer weights to be used across sub-transformers, which are subsets of the super-transformer.Pre-trained transformer weights initialise the super-transformer.

14The dynamic nature of a super-transformer is explicitly specified via a set A, called configuration space, consisting of architectural configurations of all sub-transformer models under consideration.

15The definition of a super-transformer also includes how the configuration Φ ∈ A is to be mapped to a unique transformer model f Φ .A weight-sharing super-transformer uses a set of shared weights W Sup to define all sub-transformer models' weights.This is done through a weight projection operator Π that slices (selects an appropriate subset of) the super-transformer's weights W Sup into weights of a sub-transformer model:

16The aim of a weight-sharing super-transformer is to simultaneously train all the transformer models {f Φ (•; Π Φ (W)) : X → Y | Φ ∈ A} through the shared weights W Sup .A typical training objective for super-transformers is the training loss averaged over all model configurations in A:

17where E denotes expectation over model configuration Φ drawn uniformly at random from A and L Φ , as defined in (1), is averaged training loss for configuration Φ. Super-transformer weights, W Sup , are learnt with stochastic gradient (denoted ∇) of the super-transformer's loss L Sup estimated as

18where {Φ 1 , • • • , Φ K } are K sub-transformer configurations sampled from A to approximate the expectation in (3) and B is a mini-batch of training examples sampled from D train to approximate the expectation in (1).Fine-tuning LLM super-transformers is computationally challenging in enterprise use cases as it involves computing gradients of sub-transformers' loss functions with respect to a huge number of parameters.

Multistage Low-rank Fine-tuning of Super-transformers

19We therefore developed Multistage Low-rank Fine-tuning of Super-transformers (MLFS).Given a teacher model with configuration Φ Tch and pre-trained weights W pretrain

Tch

20, we assume that its weights (denoted W Tch ) can be fine-tuned on the given task by learning low-rank matrices A 0 , B 0 on top of pre-trained weights W pretrain Tch :

21where A 0 , B 0 are of (low) rank r.Note that pre-trained weights W pretrain Tch remain unchanged during super-transformer fine-tuning.The low-rank matrices, A 0 and B 0 , are learnt by minimizing the cross-entropy loss of the teacher model f ΦTch (•; W Tch ) : X → Y over the training data set D train .Specifically, we perform E 0 epochs of fine-tuning on the teacher to learn A 0 , B 0 .This is stage-0 of the multistage fine-tuning algorithm.We denote the teacher weights obtained at the end of stage-0 by W Tch .We now define a super-transformer with maxnet configuration the same as the teacher's.Thus the super-transformer's weights W Sup are of the same size as the teacher weights W Tch ).To fine-tune the super-transformer weights W Sup , in each of the subsequent stages, we freeze W Tch and propose learning two stage-specific low-rank matrices A s , B s , of the same rank, r, as A 0 , B 0 , that are shared across all sub-transformer models in that stage.To be precise, we impose the following structure on the weights of the sub-transformers at stage-s:

22Stage-s of the fine-tuning process involves learning only the low-rank matrices, A s , B s , by minimizing the super-transform loss as in (3).In stage-1, we sample sub-transformer models by sampling different widths from the super-transformer keeping the depth (number of layers) same as the maxnet.

23In stage-2, we sample sub-transformer models by sampling different widths as well as depths.We always sample the maxnet model from the super-transformer as the 1 st sub-transformer model, Φ 1 , at every iteration.We call this Multistage Low-rank Fine-tuning of Super-transformers (MLFS) and present it in the Appendix in Algorithm 1.

24Proposition 1 Let the individually fine-tuned weights of a subnet, Φ, be expressed as

25Then, MLFS has the following structure on ∆W Φ :

26where {A s , B s } s=0,1,2 are low-rank matrices shared across all sub-transformers Φ ∈ A.

27To illustrate the computational savings, recall W pretrain Tch ∈ R d×d , where d is typically of the order 10 4 −10 6 .For rank r (typically < 10) for the low-rank matrices:

28where r ≪ d.Then, the number of parameters to be learnt in the MLFS approach is 6rd.In contrast, full fine-tuning requires updating d 2 parameters at every iteration.

29Gradient Scaling For faster convergence of the smaller sub-transformers within a super-transformer, we propose a novel weighted-combination of the gradients of the sampled sub-transformers.

30Proposition 2 Let 1 st sampled sub-transformer, Φ 1 , be the maxnet be in every iteration.Then the scaled gradient of the super-transformer training loss, L Sup , in Algorithm 1 is given by

31where ∇ W denotes gradient w.r.t.only those weights that are being fine-tuned (in this case only the LoRA matrices), n j denotes the actual number of trainable weights in model configuration Φ j and γ ≥ 1 is a hyper-parameter.

32Proof: Each sub-transformer gradient in (10), grad j , is scaled by (n 1 /n j ), which is obtained from the relative weighting of the loss functions.Let L j (W) denote the j-th sub-transformer's loss.Using first-order Taylor expansion, we get:

33where ⟨•, •⟩ denotes inner (dot) product operation.Therefore, the steepest possible decrease in the loss function L Φj can be approximated as:

34where we approximate the ∥ • ∥ 1 norm using the zero-th norm, i.e., number of non-zero elements and n j stands for the actual number of trainable parameters in sub-transformer configuration Φ j .Since the decrease in the loss of a sub-transformer model Φ j is approximately proportional to the number of trainable model parameters (n j ), we scale the losses using (n 1 /n j ) γ , γ ≥ 1 so that training losses of smaller sub-transformer models converge at a rate similar to that of larger sub-transformer configurations.Recall that n 1 is the maximum number of trainable parameters as 1 st sampled sub-transformer Φ 1 is always the maxnet.□ Initialize the low-rank matrices {A s , B s } to be learned at stage s.

35for each Φ j ∈ A s do 8:

36Load the sub-transformer model Φ j with weights W Φj := Π Φj (W Sup ).

9:

37n j := # of fine-tuning weights in model configuration Φ j .

3810:

39Compute forward-pass on sub-transformer

4011:

41In the case of Φ 1 (maxnet), set the distillation factor α to 0.

4212:

43Find the loss:

4413:

45Compute backward-pass on sub-transformer Φ j to find (∇ As loss i j , ∇ Bs loss i j ).

14:

46end for 15:

47Update A s , B s using the gradients ( ∇As L Sup , ∇Bs L Sup ) of the super-transformer's loss:

48end for 17: end for Output: {A s , B s } 2 s=0 and fine-tuned super-transformer weights:

49Distillation Loss for Super-transformers: Knowledge distillation is straightforward in a fixednetwork fine-tuning setting.However, it is less so when fine-tuning a supernet, and in particular, fine-tuning a supernet using the proposed multistage LoRA based approach.Specifically, the subnets receive two types of knowledge distillation (KD) from the teacher: (a) the usual KD loss that utilizes the output logits of the teacher and (b) distillation of features from transformer layers [18] of the teacher.

50To define the distillation based losses precisely, let the forward-pass mapping of an input training sample x i through sub-transformer Φ j be ŷi j , z i j , h i Φj ← f Φj (x i ; W Φj ), where h i j := (h i,1 j , . . ., h i,l j , . ..) with h i,l j denoting the feature vector from l-th layer of sub-transformer Φ j .In super-transformers, the model (maxnet) having the largest configuration, Φ 1 , acts as the teacher and knowledge distillation loss for all other sub-transformers w.r.t the teacher is defined as

51where KL[•, •] denotes the standard KL divergence between two probability vectors, and t ≥ 1 is a hyper-parameter called the temperature.Let d j denote the embedding dimension (hidden size) in sub-transformer Φ j .We compute feature based distillation loss by projecting features h i,l Φj ∈ R dj to a low-dimensional space R d low :

52where g j maps each layer index of the sub-transformer configuration Φ j to that of the supertransformer ( / maxnet Φ 1 ).In this paper, we propose to share the maxnet's feature projection matrices {U l 1 ∈ R d low ×d1 } across all sub-transformer models.We do so by slicing the matrices {U l 1 }:

53where the operation [ ] Φj selects appropriate subset of columns depending on the configuration Φ j .

54To reduce the number of user-chosen hyper-parameters, we propose the following hyper-parameter sharing: β l j := β gj (l) , ∀j, l = 1, 2, . ... Thus, apart from setting fewer hyper-parameters, one needs to learn only maxnet's feature projection matrices {U l 1 : l = 1, 2, . ..}, making feature distillation in a super-transformer setting computationally efficient.Additionally, we save computation through use of features only from a fixed subset of maxnet layers for distillation across all sub-transformers: i.e., we use the following subset of maxnet layers: { g min (l) : l = 1, . . ., L min }, where L min denotes the number of transformer layers in the smallest sub-transformer Φ min and g min maps layer indices of Φ min to that of maxnet Φ 1 .

556 Low-rank approach for Distilling an LLM onto a Pre-trained student

56In this section, we considerthe standard single-stage distillation approach for training a smaller (student) model on a target task with help from a larger fine-tuned (teacher) model.Here, we assume availability of the following: (i) target data set D train for fine-tuning, (ii) a task specific loss function ℓ task , (iii) a teacher model with configuration Φ Tch and weights W Tch are already fine-tuned for the task, (iv) a smaller model than the teacher, called the student model, with configuration Φ Std & pre-trained weights W pretrain

Std

57. The goal is to efficiently fine-tune the student model on the target data with knowledge distillation from the larger teacher model.For computational efficiency, we make the following low-rank assumption (as in LoRA approach) on the fine-tuned weights of student model:

Compute forward-pass on the teacher model: ŷi

58Tch , z i Tch , h i Tch ← f ΦTch x i ; W Tch , ∀i ∈ B.

5:

59Compute forward-pass on the student model: ŷi

60Find the loss:

61Compute gradients (∇ A1 loss i , ∇ B1 loss i ) using backward-pass on the student model.

8:

62Update A 1 , B 1 using the gradients

639: end for Output: {A 1 , B 1 } and fine-tuned weights of the student model:

64Given an input sample x i , the knowledge distillation (KD) loss of the student model f ΦStd with respect to the teacher model f ΦStd is given by

65where σ(•) denotes the soft-max operation, KL[•, •] denotes the standard KL divergence between two probability vectors, and t ≥ 1 is called the KD temperature.

Given input x i , let h i

66Std := (h i,1 Std , . . ., h i,l Std , . ..) denote the feature vectors from all transformer layers of the student model with h i,l Std being the feature vector from l-th layer.Now, we define the feature based distillation loss as

67where the summation l is over (a subset of) the layers of the student model, {β l ≥ 0} are user chosen constants, ∥ • ∥ 2 denotes the Euclidean norm, and the function g maps each layer index l of the student model to a layer index g(l) of the teacher model for comparing corresponding features.The projection matrices {U l Std , U l Tch } are simultaneously learned along with the LoRA weights and are needed to compare the feature vectors from the student with those from the teacher by projecting them to a common low-dimensional space.To be precise,

68where d Tch & d Std denote the embedding (hidden) dimension of the teacher and the student model respectively.Usually, the dimension d low of the projected space is chosen to be small, 128 in our experiments.

Results on Encoder and Decoder LLMs

69We report performance on encoder tasks using GLUE [35] with BERT base as the teacher model Φ Tch .For decoder LLMs, we use Santacoder [1] and Codellama7B [29] on a python coding task using bigcode/the-stack data [19].We report performance of the sub-transformer models at the end of stage s = 2. On GLUE, we use the train set for fine-tuning and the dev set for accuracy evaluation.For santacoder, we evaluate performance using HumanEval [7] and report pass@1 scores.All experiments were conducted using PyTorch on a single Nvidia A100 (40GB) GPU.

70In MLFS, the Low rank matrices are added on the QKV vectors and the intermediate size of feedforward network (FFN) layers.We set β l = 0.1 ∀l in feature distillation loss and choose distillation factor α = 0.9.For training, we use a maximum sequence length of 128; effective batch size of 128 for QQP, MNLI, QNLI, and 64 for the other data sets.Training is done for a maximum of 8 epochs for all GLUE data sets except SST-2 for which we allocate maximum 3 epochs.We set an initial learning rate of 5e −4 for QNLI & MNLI, and 1e −3 for other GLUE data sets.We use rank r = 8 for the low rank matrices A, B unless mentioned otherwise.We choose gradient scaling hyper-parameter γ = 1 for SST-2 and γ = 2 for all other data sets.Following [16], we use the fine-tuned MNLI checkpoint to initialize the model weights for experiments on small data sets such as RTE and MRPC.

Performance of Encoder Models

71We compare performance of encoder models obtained with the MLFS approach against a static, fixed model (BERT base) from [43,14], two popular distilled variants of the fixed model: TinyBERT [18] and DistilBERT [31], and models trained using existing super-transformer methods (DynaBERT [14].Figure 1 shows the performance of the palette of models, from a 45M param.minnet to full-size 110M maxnet.Model performance against forward-pass latency is plotted in Figure 2. Encoder models produced by MLFS are at par or better than much costlier methods.Results of PD-BERT, BERT-PKD are from [43], static BERT from [43] for all except MRPC for which we use [14].Note that TinyBERT performs data augmentation leading to higher accuracy but much longer computation time.We do not perform data augmentation for fairness of the comparison to the other methods.The main observation is that MLFS provides accurate, smaller encoder models at 1/4 the size of the teacher and 1/3 its runtime latency on a single GPU.

72Ablation Study on Gradient Scaling In supernet training, the weights of maxnet and subnets are shared and trained simultaneously.The maxnet tends to converge and overfit earlier than smaller subnets.The different convergence rates renders selecting a single supernet checkpoint for all networks difficult.Gradient scaling solves this by speeding up convergence of the smaller subnets to match that of the larger subnets or the maxnet.Fig. 3 shows that gradient scaling improves minnet convergence, indicated by lower minnet loss.

73Ablation Study on Rank of A, B In Fig. 4, we examines the impact of rank r of the matrices A, B on performance.Note that the actual number of parameters fine-tuned vary as we vary the rank r.The aim is to provide good results for the smaller networks.Here, rank r = 8 works well across the GLUE data sets.Therefore, we use rank r = 8 for A, B for all other MLFS experiments.From the scale of the y-axis in 4, observe that MLFS is not overly sensitive to the chosen rank.Figure 4: Ablation study on MLFS rank of A, B. Maxnet (top: blue), minnet (bottom: green), and average of two medium-sized subnets (middle: orange).Rank r = 8 is optimal for small and medium subnets.

Performance of Decoder Models

74Turning now to decoder models, we consider two code-pre-trained LLMs, Santacoder [1] and Codellama7B [29].We evaluate a custom 0.7B parameter Santacoder model obtained from the 1.1B teacher.Due to an inability to fine-tune on the full 24M coding examples, we use up to 1.2M.Fig. 5 shows that MLFS pass@1 improves rapidly as number of tokens increases from a low 10k to 400k to 1.2M examples, only 5% of the 24M examples.Table 1 shows analogous results with 3 small MLFS models.The improvement in pass@1 indicates that the smaller models retain the ability to learn from the larger teacher.Full FT + random init.MLFS ( =0, r=8) MLFS ( =0.9, r=8) Teacher (Santacoder 1.1B) 1: HumanEval pass@1 (%) performance of 3 small models produced by MLFS from Santacoder 1.1B.Contrary to encoder models, the compression levels that retain sufficient performance of the teacher with decoders is less.While MLFS retains accuracy performance of encoder models at 1/4 the size of the teacher, the decoder models are reduced to at most 2/3 the teacher's size.

75MLFS slicing of the teacher model can, however, benefit decoder models by reducing substantially the training/fine-tuning time needed compared to a randomly-initialised model, as shown in Fig. 6 on Santacoder sliced from 1.1B to 0.7B.In other words, when a smaller model is required for edge inference, one can train it from a random initialisation, or slice from a teacher as does MLFS, and train starting from the sliced weights.The latter significantly reduces training time as seen in the validation loss curves.We see the same benefit on Codellama, as shown below.See [30] for a similar observation.

Validation loss

76Full FT + random init.MLFS ( =0, r=8) MLFS ( =0.9, r=8) 14.0 28.1 30.5 Table 2: HumanEval pass@1 (%) performance of 3 small models produced by MLFS from CodeLlama-7B-Python Ablation Study on Santacoder In Fig. 7, we compare HumanEval performance of a 0.7B Santacoder model fine-tuned through full fine-tuning (FT) from random initialisation vs. fullrank (non-LoRA) MLFS with (α = 0.9) and without (α = 0) distillation.The improvement in the evaluation numbers is remarkable even after fine-tuning on up to only 5% of the examples.HumanEval pass@1 (%) Full FT + random init.MLFS ( =0, r: full-rank) MLFS ( =0.9, r: full-rank) Teacher (Santacoder 1.1B)In Fig. 8, we see better convergence of validation loss on the Santacoder 0.7B for MLFS with distillation loss (α > 0).This demonstrates the benefit of MLFS distillation as compared to full MLFS fine tuning of the sliced model.

Perspectives

77Enterprise users require an efficient way to fine-tune LLMs for inference on edge devices of many sizes.We developed MLFS for such edge deployment scenarios.We demonstrate its benefits on encoder LLMs.We show the limitation of compressing decoder LLMs to a comparable degree; however, MLFS offers significant gains for smaller decoder training/fine-tuning by slicing from a larger pre-trained teacher.

Algorithm 1

78Multistage Low-rank Fine-tuning of Super-transformers (MLFS) Input: Transformer model (teacher) with configuration Φ Tch & off-the-shelf pre-trained weights W pretrain Tch , model configuration space A consisting of smaller (than Φ Tch ) transformer architectures of interest, D train : fine-tuning data set for the target task, r: rank of the low-rank matrices to be learned and distillation factor α ∈ [0, 1].Loss functions: Target task loss ℓ task , knowledge distillation loss ℓ KD , feature distillation loss ℓ FD .Multistage Training:1: for stage s = 0, 1, 2 do 2:

3 : 4 : 5 :

79for iteration = 1, ... do Get a mini-batch B of training examples: {(x i , y i ) ∈ D train | i ∈ B}.Load the super-transformer model with weights W Sup ← W pretrain Tch + s l=0 A l * B l .6:

1 :

80where A 1 , B 1 are LoRA matrices of low rank (typically rank r is chosen between 4 and 16).Algorithm 2 Low-rank approach for Distilling an LLM onto a Pre-trained Student Input: Larger transformer model (teacher) with configuration Φ Tch & weights W Tch already finetuned for the given target task, student model with configuration Φ Std & pre-trained weights W pretrain Std , D train : fine-tuning data set for the target task, r: rank of the low-rank matrices to be learned and distillation factor α ∈ [0, 1].Loss functions: Target task loss ℓ task , knowledge distillation loss ℓ KD , feature distillation loss ℓ FD .Initialize the low-rank matrices {A 1 , B 1 } for fine-tuning the student model f ΦStd weights: W Std := W pretrain Std + A 1 * B 1 , where W pretrain Std is kept frozen and only {A 1 , B 1 } are learned.2: for iteration = 1, 2, . . .do 3: Get a mini-batch B of training examples: {(x i , y i ) ∈ D train | i ∈ B}.

Figure 1 :

81Figure 1: Model size vs performance trade-off for task-specific BERT models produced by MLFS against other methods on 6 GLUE data sets.

Figure 2 :

82Figure 2: Latency vs performance trade-off for task-specific BERT models produced by MLFS against other methods on 6 GLUE data sets.

Figure 3 :

83Figure 3: Ablation study on gradient scaling: MLFS minnet convergence is improved using gradient scaling.

Figure 6 :

84Figure 6: Convergence comparison of validation loss while fine-tuning a custom model from random vs using MLFS.MLFS achieves low validation loss much faster.

Figure 7 :

85Figure 7: Superior performance of supernet training compared to other full fine-tuning based approaches on three data sets with 10K/400K/1.2Mexamples.

Figure 8 :

86Figure 8: Convergence comparison of validation loss while fine-tuning a custom model using MLFS with/without distillation.

Table 2 shows

87HumanEval performance of these models as the number of examples is increased from 200K to 400K.Again, we see that the sliced CodeLlama retain their ability to learn and improve quickly as the number of examples increases.Note that the full data set includes 24M examples; MLFS achieves nearly 75% of the performance of fullsize CodeLlama after less than 2% of the examples.

참고문헌

참고문헌 정보가 없습니다.