Elastic adapter for fine-tuning neural network

Elastic adapters with paired linear layers address the inefficiencies of fine-tuning LLMs by reducing model size and computational cost, enhancing efficiency and adaptability for specific tasks.

WO2026152640A1PCT designated stage Publication Date: 2026-07-23INTEL CORP +5
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
INTEL CORP
Filing Date
2025-06-26
Publication Date
2026-07-23

AI Technical Summary

Technical Problem

Fine-tuning large language models (LLMs) is time-consuming and cost-expensive due to their large model size and dense weight updates, and existing parameter-efficient fine-tuning methods result in models with similar or larger sizes, maintaining high computational costs during inference.

Method used

Implementing elastic adapters with paired linear layers after each DNN layer, allowing the pretrained weights to remain fixed during fine-tuning, and merging trained adapters into the DNN layers for inference, reducing model size and computational cost.

Benefits of technology

Significantly improves fine-tuning and inference efficiency by reducing model size and computational cost, while maintaining performance, through the use of elastic adapters that adaptively adjust to specific tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2025103772_23072026_PF_FP_ABST
    Figure CN2025103772_23072026_PF_FP_ABST
Patent Text Reader

Abstract

A pretrained neural network may be fine-tuned using one or more elastic adapters, each of which may be inserted into the pretrained neural network at a position that is immediately after a corresponding layer of the pretrained neural network. An elastic adapter may include a first linear layer and a second linear layer. During the fine-tuning, one or more internal parameters (e.g., weights) of the elastic adapter may be updated based on a loss function, while internal parameters of the corresponding layer (e.g., pretrained weights) may be fixed. After the fine-tuning, the first linear layer may be merged with the corresponding layer to form a new layer. The new layer may replace the corresponding layer in the neural network. The updated neural network, which has the new layer and the second linear layer, may be a fine-tuned neural network and may be used to perform one or more AI tasks.
Need to check novelty before this filing date? Find Prior Art

Description

ELASTIC ADAPTER FOR FINE-TUNING NEURAL NETWORKCross-Reference to Related Application

[0001] This application claims the benefit of International Application No. PCT / CN2025 / 073224, filed January 20, 2025, and titled “ELASTIC ADAPTER FOR INFERENCE-EFFICIENT AND PARAMETER-EFFICIENT FINE-TUNING OF LARGE LANGUAGE MODELS, ” which is incorporated by reference in its entirety.Technical Field

[0002] This disclosure relates generally to neural network (also referred to as “deep neural network” or “DNN” ) , and more specifically, elastic adapters for fine-tuning DNNs, including transformer-based models, such as large language models (LLM) .Background

[0003] DNNs are used extensively for a variety of artificial intelligence applications ranging from computer vision to speech recognition and natural language processing due to their ability to achieve high accuracy. However, the high accuracy comes at the expense of significant computation cost. DNNs have extremely high computing demands as there can be a large number of operations as well as a large amount of data to read and write. Therefore, techniques to improve efficiency of DNNs are needed.Brief Description of the Drawings

[0004] Embodiments can be readily understood by the following detailed description in conjunction with the accompanying drawings. To facilitate this description, like reference numerals designate like structural elements. Embodiments are illustrated by way of example, and not by way of limitation, in the figures of the accompanying drawings.

[0005] FIG. 1 is a block diagram of an artificial intelligence (AI) system, in accordance with various embodiments.

[0006] FIG. 2 illustrates an elastic adapter for fine-tuning a DNN layer, in accordance with various embodiments.

[0007] FIG. 3 illustrates a modified DNN layer, in accordance with various embodiments.

[0008] FIG. 4 illustrates modifying a DNN with elastic adapters, in accordance with various embodiments.

[0009] FIG. 5 illustrates an example transformer model, in accordance with various embodiments.

[0010] FIGS. 6A and 6B illustrate an example multi-head attention (MHA) layer, in accordance with various embodiments.

[0011] FIG. 7 illustrates an example linear classifier, in accordance with various embodiments.

[0012] FIG. 8 illustrates a first inference stage of a transformer model, in accordance with various embodiments.

[0013] FIG. 9 illustrates subsequent inference stages of the transformer model, in accordance with various embodiments.

[0014] FIG. 10 is a flowchart of a method of fine-tuning a DNN, in accordance with various embodiments.

[0015] FIG. 11 is a block diagram of an example computing device, in accordance with various embodiments.Detailed Description

[0016] The last decade has witnessed a rapid rise in AI based data processing, particularly based on DNNs. DNNs are widely used in the domains of computer vision, speech recognition, image, and video processing mainly due to their ability to achieve beyond human-level accuracy. A DNN typically includes a sequence of layers. A DNN layer may include one or more deep learning operations (also referred to as “neural network operations” ) , such as convolution, matrix multiplication, layer normalization, batch normalization, SoftMax operation, pooling, elementwise operation, linear operation, nonlinear operation, and so on.

[0017] Input or output data of deep learning operations may be arranged in data structures called tensors. A tensor is a data structure having multiple elements across one or more dimensions. Examples of tensors include vector (which is one-dimensional (1D) tensor) , matrix (which is two-dimensional (2D) tensor) , three-dimensional (3D) tensors, four-dimensional (4D) tensors, and even higher dimensional tensors. A dimension of a tensor may correspond to an axis, e.g., an axis in a coordinate system. A dimension may be measured by the number of data points along the axis. The dimensions of a tensor may define the shape of the tensor. A DNN layer may receive one or more input tensors and compute an output tensor from the one or more input tensors. Taking a convolutional layer for example, the input tensors include an activation tensor (also referred to as “input feature map” or “input activation tensor” ) including one or more activations (also referred to as “input elements” ) and a weight tensor. The weight tensor may be a kernel (a 2D weight tensor) , a filter (a 3D weight tensor) , or a group of filters (a 4D weight tensor) . A convolution may be performed on the input activation tensor and weight tensor to compute an output activation tensor in the convolutional layer.

[0018] An exemplary transformer model includes an encoder, a decoder, and a head. An inference request may be made to request the transformer model to make a prediction. During inference, the encoder may receive input tokens and generate an encoder output from the input tokens. A token may be a representation (e.g., numerical representation) of a signal (e.g., a word, image, audio, video, etc. ) provided to the transformer model. The decoder may receive inputs and generate decoder outputs from the dynamic inputs and the encoder output during a sequence of inference stages. The decoder inputs may be dynamic across inference stages as the token predicted in an inference stage is added to the decoder input for the next inference stage. Key-value (KV) tensors in the decoder may also be dynamic across inference stages. An inference stage may be a cycle of executing operations in the decoder and head to predict a new token. An inference stage may also be referred to as an inference phase or inference cycle. The first inference stage may populate the KV cache with keys and values corresponding to the input tokens received by the encoder. The decoder may use the KV tensors to generate an output, which is then used by the head to generate the first predicted token. In each subsequent inference stage, the KV cache may be further populated with new keys and values corresponding to the toke predicted in the previous inference stage. All the inference stages may constitute a whole inference process. A sequence of tokens may be obtained after all the inference stages are complete. The sequence of tokens ( “output sequence” ) may be the prediction of the transformer model.

[0019] DNNs (such as LLMs) with transformer architectures have become the dominant learning models for various AI tasks. LLMs typically have billions to trillions of parameters, which are pretrained on tens of trillions of tokens. Pretrained LLMs typically need to be fine-tuned on each task-specific dataset to handle different application usages. However, fine-tuning a pretrained LLM for an application usage can be very time-consuming and cost-expensive, due to its huge model size and dense update of model weights. Furthermore, the fine-tuned model usually has the same / slightly larger model size compared to its corresponding pretrained LLM and each application usage typically has a unique fine-tuned model, retaining the heavy computational cost at inference.

[0020] Parameter-efficient fine-tuning (PEFT) are de facto solutions for fine-tuning many LLMs. In design, PEFT methods introduce adapters with a small set of extra learnable parameters (in total, about 1~5%ratio to the model size of a pretrained LLM) inserted into a given pretrained LLM. In the fine-tuning process, the original weights of the pretrained LLM are fixed, and the pre-defined adapters are trained for each application usage. However, in inference, almost all existing adapters are permanently inserted into the pretrained LLM as extra layers, except LORA based adapters in which the trained weights of its adapters are directly added into the pretrained weights through elementwise sum operation. Therefore, for currently available PEFT methods, the fine-tuned model has the same (for low-rank adaptation (LoRA) based adapters) or slightly larger (for most existing adapters) model size compared to the pretrained LLM, retaining the heavy computational cost at inference.

[0021] Embodiments of the present disclosure may improve on at least some of the challenges and issues described above by providing DNN fine-tuning using elastic adapters. In an example, an elastic adapter, which includes paired linear layers, may be inserted after every DNN layer for which fine-tuning is needed. The fine-tuning process may be a process of training the elastic adapter, while the pretrained weights of the DNN may remain the same. For inference, a part of the trained elastic adapter may be merged into the corresponding DNN layer. The elastic adapter approach in this disclosure provides a novel and powerful fine-tuning technique that can significantly improve the fine-tuning efficiency and inference efficiency of DNNs, including LLMs.

[0022] In various embodiments of the present disclosure, a pretrained DNN may be fine-tuned using one or more elastic adapters. An elastic adapter may be inserted into the pretrained DNN at a position that is immediately after a layer of the pretrained DNN. The layer is a pretrained layer with a pretrained weight tensor. An elastic adapter may include a first linear layer and a second linear layer. The first linear layer of the elastic adapter may be placed between the pretrained layer of the pretrained DNN and the second linear layer of the elastic adapter. A fine-tuning dataset including samples and reference values of the samples may be used for the fine-tuning process. The fine-tuning dataset may be specific to one or more AI tasks (e.g., language modeling, reasoning, translation, etc. ) to be performed by the DNN after fine-tuning. During the fine-tuning, internal parameters of the elastic adapter may be updated based on a loss function, while internal parameters of the pretrained layer may be fixed. The fine-tuning process may be a process of training the elastic adapter. After the fine-tuning, the first linear layer of the elastic adapter may be merged with the pretrained layer to form a new layer. For instance, the trained weight tensor of the first linear layer may be merged with the pretrained weight tensor of the pretrained layer to form a new weight tensor. A new layer having the new weight tensor may replace the pretrained layer in the DNN. The second linear layer of the elastic adapter may be kept in the DNN. The updated DNN, which has the new layer and the second linear layer of the elastic adapter, may be a fine-tuned DNN and may be used to perform the one or more AI tasks.

[0023] For purposes of explanation, specific numbers, materials and configurations are set forth in order to provide a thorough understanding of the illustrative implementations. However, it can be apparent to one skilled in the art that the present disclosure may be practiced without the specific details or / and that the present disclosure may be practiced with only some of the described aspects. In other instances, well known features are omitted or simplified in order not to obscure the illustrative implementations.

[0024] Further, references are made to the accompanying drawings that form a part hereof, and in which is shown, by way of illustration, embodiments that may be practiced. It is to be understood that other embodiments may be utilized, and structural or logical changes may be made without departing from the scope of the present disclosure. Therefore, the following detailed description is not to be taken in a limiting sense.

[0025] Various operations may be described as multiple discrete actions or operations in turn, in a manner that is most helpful in understanding the claimed subject matter. However, the order of description should not be construed as to imply that these operations are necessarily order dependent. In particular, these operations may not be performed in the order of presentation. Operations described may be performed in a different order from the described embodiment. Various additional operations may be performed or described operations may be omitted in additional embodiments.

[0026] For the purposes of the present disclosure, the phrase “A or B” or the phrase "A and / or B" means (A) , (B) , or (A and B) . For the purposes of the present disclosure, the phrase “A, B, or C” or the phrase "A, B, and / or C" means (A) , (B) , (C) , (A and B) , (A and C) , (B and C) , or (A, B, and C) . The term "between, " when used with reference to measurement ranges, is inclusive of the ends of the measurement ranges.

[0027] The description uses the phrases "in an embodiment" or "in embodiments, " which may each refer to one or more of the same or different embodiments. The terms "comprising, " "including, " "having, " and the like, as used with respect to embodiments of the present disclosure, are synonymous. The disclosure may use perspective-based descriptions such as "above, " "below, " "top, " "bottom, " and "side" to explain various features of the drawings, but these terms are simply for ease of discussion, and do not imply a desired or required orientation. The accompanying drawings are not necessarily drawn to scale. Unless otherwise specified, the use of the ordinal adjectives “first, ” “second, ” and “third, ” etc., to describe a common object, merely indicates that different instances of like objects are being referred to and are not intended to imply that the objects so described must be in a given sequence, either temporally, spatially, in ranking or in any other manner.

[0028] In the following detailed description, various aspects of the illustrative implementations may be described using terms commonly employed by those skilled in the art to convey the substance of their work to others skilled in the art.

[0029] The terms “substantially, ” “close, ” “approximately, ” “near, ” and “about, ” generally refer to being within + / -20%of a target value as described herein or as known in the art. Similarly, terms indicating orientation of various elements, e.g., “coplanar, ” “perpendicular, ” “orthogonal, ” “parallel, ” or any other angle between the elements, generally refer to being within + / -5-20%of a target value as described herein or as known in the art.

[0030] In addition, the terms “comprise, ” “comprising, ” “include, ” “including, ” “have, ” “having” or any other variation thereof, are intended to cover a non-exclusive inclusion. For example, a method, process, device, or DNN accelerator that comprises a list of elements is not necessarily limited to only those elements but may include other elements not expressly listed or inherent to such method, process, device, or DNN accelerators. Also, the term “or” refers to an inclusive “or” and not to an exclusive “or. ”

[0031] The systems, methods and devices of this disclosure each have several innovative aspects, no single one of which is solely responsible for all desirable attributes disclosed herein. Details of one or more implementations of the subject matter described in this specification are set forth in the description below and the accompanying drawings.

[0032] FIG. 1 is a block diagram of an AI system 100, in accordance with various embodiments. The AI system 100 may produce DNNs, including transformer-based models, that can perform AI tasks, such as language processing, computer vision, speech recognition, and so on. For instance, the AI system 100 may train a DNN. The AI system 100 may also compress a DNN, e.g., through quantization, before compiling or deploying the DNN. The quantization may be quantization of internal parameters of the DNN (e.g., weights) and can accelerate the execution of the DNN. As shown in FIG. 1, the AI system 100 includes an interface module 110, a training module 120, a fine-tuning module 130, a compiler 140, a transformer execution module 150, and a datastore 160. In other embodiments, alternative configurations, different or additional components may be included in the AI system 100. Further, functionality attributed to a component of the AI system 100 may be accomplished by a different component included in the AI system 100 or a different module or system.

[0033] The interface module 110 facilitates communications of the AI system 100 with other modules or systems. For example, the interface module 110 establishes communications between the AI system 100 with an external database to receive data that can be used to train DNNs or input into DNNs to perform tasks. As another example, the interface module 110 supports the AI system 100 to distribute DNNs to other systems, e.g., computing devices configured to apply DNNs to perform tasks. The interface module 110 may receive inference requests from users of transformer models.

[0034] The training module 120 trains DNNs by using a training dataset. The training module 120 may form the training dataset. The training dataset may include training samples and reference values. The reference values may represent correct predictions made by the DNN from the training samples. In an example where the training module 120 trains an DNN to process language, training samples may be training prompts, and reference values may be correct tokens generated from the training prompts. In some embodiments, a part of the training dataset may be used to initially train the DNN, and the rest of the training dataset may be held back as a fine-tuning subset used by the fine-tuning module 130 to fine-tune a trained DNN or as a validation subset used by the training module 120 to validate performance of a trained or fine-tuned DNN. The portion of the training dataset not including the fine-tuning subset and the validation subset may be used to train the DNN.

[0035] The training module 120 may also determine hyperparameters for training the DNN. Hyperparameters are variables specifying the DNN training process. Hyperparameters are different from parameters inside the DNN (e.g., weights of filters) . In some embodiments, hyperparameters include variables determining the architecture of the DNN, such as number of hidden layers, etc. Hyperparameters also include variables which determine how the DNN is trained, such as batch size, number of epochs, etc. A batch size defines the number of training samples to work through before updating the parameters of the DNN. The batch size is the same as or smaller than the number of samples in the training dataset. The training dataset can be divided into one or more batches. The number of epochs defines how many times the entire training dataset is passed forward and backwards through the entire network. The number of epochs defines the number of times that the deep learning algorithm works through the entire training dataset. One epoch means that each training sample in the training dataset has had an opportunity to update the parameters inside the DNN. An epoch may include one or more batches. The number of epochs may be 1, 5, 10, 50, 100, 500, 1000, or even larger.

[0036] To train a DNN, the training module 120 inputs the training samples into the DNN. The training module 120 modifies the parameters inside the DNN ( “internal parameters of the DNN” ) to minimize the error between the DNN’s prediction and target values. The target values may be used as reference values to measure the loss during training. The target values may be actual values (e.g., values indicating ground truth) or values verified to be accurate or true. The internal parameters may be learnable parameters whose values can be optimized by training the DNN. The internal parameters include weights, such as weights in weights in linear layers, weights in attention layers, and so on.

[0037] In some embodiments, the training module 120 may define stages in the training process. For example, for each training sample or each epoch, the training module 120 defines a forward pass, a backward pass, and an optimization process. During the forward pass, data propagates forward through the DNN layers. For instance, data (e.g., activations) pass from the input layer to hidden layers, then to the output layer. An output of the DNN, which indicates a prediction of the DNN, may be generated at the last layer, which may be the output layer of the DNN. This part of the forward pass may be an inference process in which the DNN is executed to process the training sample and make a prediction. The inference process may be denoted as outnn=fw (x) =f (x, w) , where outnn is the DNN output, f is the network architecture, and w are the internal parameters (e.g., weights) .

[0038] The training module 120 may apply gradient descent to train DNNs. After the DNN output is generated, a loss may be computed. The training module 120 may define a loss function that can measure a loss during forward pass. The loss may measure the difference between the DNN output and the actual values. It may provide a measure of error that an optimization algorithm can use to update the internal parameters during the optimization process. In some embodiments, the loss function may be selected, e.g., by the training module 120, from various types of loss functions, such as mean square error (MSE) , cross-entropy loss, mean absolute error (MAE) , Huber loss, Hinger loss, cosine similarity, Poisson loss, and so on. The computation of the loss function may be denoted as where is the loss, yref is the reference value (s) , and N is the number of training samples in a batch.

[0039] During the backward pass, data propagates backwards and the DNN is run backwards. The data may be gradients computed using the loss. A gradient may be a partial derivative of a function (e.g., a loss function) with respect to its inputs, which may be the slope of the function. Gradients computed during the backward pass may measure the changes in weights with respect to the change in error or loss. Gradients computed during the backward pass may include output gradients, input gradients, and weight gradients. An output gradient of a layer may be a gradient with respect to the layer output and may be denoted as An input gradient of a layer may be the gradient with respect to the layer input and may be denoted as Aweight gradient may be a gradient of each parameter with respect to the layer output and may be denoted as where i is the index of the layer. The training module 120 may define a MatMul operation to compute the weight gradient and another MatMul operation to compute the input gradient. The input gradient may be defined as where x is the layer input, Wi is the layer parameters, as y is the layer output. The weight gradient may be defined as In some embodiments, the layer being executed in the forward pass may be denoted as y=x*Wi. Therefore, the function for the input gradient may become where and The function for the weight gradient may become where and may be an input tensor (e.g., the activation tensor) of the layer. WT may be a weight tensor of the lawyer. In some embodiments,  may be a tensor having the same spatial shape as WT . The input gradient may be propagated to the previous layer. The weight gradient may be used to update the parameters through an optimization process.

[0040] During the optimization process, the internal parameters may be updated using an optimization function. The training module 120 may define the optimization function. An example optimization function may be:  where γ is the learning rate,  N is the index of the current batch, and N+1 is the index of the next batch.

[0041] In some embodiments, the training module 120 may also verify accuracy of DNNs after training or fine-tuning. In some embodiments, the training module 120 inputs samples in a validation dataset into a trained DNN and uses the outputs of the DNN to determine the model accuracy. In some embodiments, a validation dataset may be formed of some or all the samples in the training dataset. Additionally or alternatively, the validation dataset includes additional samples, other than those in the training sets. In some embodiments, the training module 120 may determine an accuracy score measuring the precision, recall, or a combination of precision and recall of the DNN. The training module 120 may use the following metrics to determine the accuracy score: Precision = TP  /  (TP + FP) and Recall = TP  /  (TP + FN) , where precision may be how many the DNN correctly predicted (TP or true positives) out of the total it predicted (TP + FP or false positives) , and recall may be how many the DNN correctly predicted (TP) out of the total number of objects that did have the property in question (TP + FN or false negatives) . The F-score (F-score = 2 *PR  /  (P + R) ) unifies precision and recall into a single measure.

[0042] The training module 120 may compare the accuracy score with a threshold score. In an example where the training module 120 determines that the accuracy score of the DNN is less than the threshold score, the training module 120 instructs the training module 120 to retrain the DNN. In one embodiment, the training module 120 may iteratively retrain the DNN until the occurrence of a stopping condition, such as the accuracy measurement indication that the DNN may be sufficiently accurate, or a number of training rounds having taken place.

[0043] The fine-tuning module 130 fine-tunes DNNs, such as DNNs that have been trained by the training module 120. In some embodiments, the fine-tuning module 130 may fine-tune a pretrained DNN using one or more elastic adapters. An elastic adapter may include one or more dimension-reduction-up linear operations. In an example, an elastic adapter may have paired dimension-reduction-up linear operations. The elastic adapter may include two linear layers. The fine-tuning module 130 may insert an elastic adapter immediately after a layer of the pretrained DNN. In some embodiments, the fine-tuning module 130 may insert an elastic adapter after every layer of the pretrained DNN.

[0044] The first linear layer of the elastic adapter may have a weight matrix A∈Rk×r , r<< (d, k) that can transform the feature output (e.g., an output tensor) of the layer. The feature output may be generated at the layer from the pretrained weight matrix W∈Rd×k of the layer. The first linear layer of the elastic adapter may transfer the feature output into a space with k / r times dimension reduction (e.g., r=64, k=2048, d=2048) . The second linear layer of the elastic adapter may have a weight matrix B∈Rr×k that may transform the dimension-reduced feature output back to the original space. That way, the feature output can still be processed in the next layer of the pretrained DNN.

[0045] During the fine-tuning phase, the elastic adapter (s) inserted into the pretrained DNN may be trained, while the weights of the layers of the pretrained DNN may be fixed. The fine-tuning module 130 may use a fine-tuning dataset (such as the fine-tuning dataset described above) to fine-tune the pretrained DNN. In some embodiments, the fine-tuning dataset may include fine-tuning samples and reference values. The fine-tuning samples may be input into the DNN 400 with the elastic adapters, and internal parameters of the elastic adapters may be adjusted to minimize a loss. The loss may measure a difference between the reference values and the predictions made by the DNN 400 using the fine-tuning samples. The fine-tuning dataset may be specific to the task to be performed by the DNN. In some embodiments, the fine-tuning module 130 may update the internal parameters of the elastic adapter (s) using a loss function, such as the loss functions described above in conjunction with the training module 120. In some embodiments, the fine-tuning module 130 may also determine hyperparameters for fine-tuning, such as batch size, number of epochs, and so on. In some embodiments, the batch size or number of epochs for fine-tuning a DNN may be smaller than the batch size or number of epochs for training a DNN.

[0046] After the fine-tuning, the fine-tuning module 130 may modify the DNN layer (s) using the trained elastic adapter (s) . in some embodiments, for each DNN layer with an elastic adapter, the fine-tuning module 130 may merge a DNN layer with the first linear layer of the elastic adapter for the DNN layer to form a new DNN layer. For instance, the fine-tuning module 130 may merge the pretrained weight matrix W of a layer and the newly trained weight matrix A (for the first linear layer of the elastic adapter) into a single weight matrix Wr. In some embodiments, the fine-tuning module 130 may merge the two weight matrices by performing a matrix multiplication operation on the two weight matrices. In some embodiments, W∈Rd×k, A∈Rk×r, and the result of the matrix multiplication operation is Wr=WA∈Rd×r. A dot product is performed between each row of the weight matrix W and each column of weight matrix A to generate a single point in the weight matrix Wr. The number of columns in the weight matrix W (i.e., the width of the weight matrix W, which is k) equals the number of rows in the weight matrix A (i.e., the height of the weight matrix A, which is also k) . The resulting weight matrix Wr has the same number of rows or height as the weight matrix W (i.e., d) and the same number of columns or width as the weight matrix A (i.e., r) .

[0047] The fine-tuning module 130 may replace the pretrained DNN layer having the weight matrix W with the new DNN layer having the weight matrix Wr. The fine-tuning module 130 may keep the second linear layer of the elastic adapter in the DNN. The second linear layer has the newly trained weight matrix B. The fine-tuning module 130 may save the merged weight matrix Wr and the newly trained weight matrix B for inference. During the inference phase, the task-specific fine-tuned model may have times reduction both in layer size and computational cost compared to the pretrained model. Certain aspects regarding fine-tuning with elastic adapters are described below in conjunction with FIGS. 2-4.

[0048] The compiler 140 compiles DNNs to generate instructions that can be executed by a hardware device (e.g., one or more processing units) to carry out neural network operations in DNNs, either for training purposes or deployment purposes. In some embodiments, the compiler 140 may generate a graph representing a DNN. The graph may include nodes and edges. A node may represent a specific neural network operation in the DNN. An edge may connect two nodes and represent a connection between the two corresponding neural network operations. In an example, an edge may encode a tensor that flows from one of the neural network operations to the other neural network operation. The tensor may be an output tensor of the first neural network operation and an input tensor of the second neural network operation. The edge may encode one or more attributes of the tensor, such as size, shape, storage format, and so on. The compiler 140 may use the graph to generate executable DNNs. For instance, the compiler may generate computer program instructions for executing DNNs.

[0049] In some embodiments, the compiler 140 may generate configuration parameters that may be used to configure components of the hardware device for DNN executions. The configuration parameters may be stored in one or more configuration registers associated with the components of the hardware device. In some embodiments, the compiler 140 may compile a DNN before the DNN is trained or fine-tuned. Additionally or alternatively, the compiler 140 may compile a DNN after the DNN is fine-tuned. The compiler 140 may perform different complications before and after training or fine-tuning. For instance, the compiler 140 may compile the DNN before training or fine-tuning based on the condition that internal parameters of the DNN are to be changed during the training or fine-tuning process. The compiler 140 may compile the DNN after training or fine-tuning based on the condition that internal parameters of the DNN would remain the same. The compiler 140 may provide the executable DNN to the hardware device, and the hardware device may execute the layers of the DNN.

[0050] The transformer execution module 150 facilitates execution of transformer models, including transformer models with compressed KV cache. The transformer execution module 150 may map operations in transformer models to the hardware device. The transformer execution module 150 may modify transformer models based on attributes of hardware resources (e.g., memories, compute elements, etc. ) of the hardware device. The transformer execution module 150 may also determine parameters that may be used in inference of transformer models. In some embodiments, the transformer execution module 150 may determine optimal data layouts in KV caches in transformer models. Memory footprint can be a challenge to both inference latency and energy consumption of transformer model inference on DNN accelerators. During cached inference, self-attention KV cache and cross-attention KV cache may undergo transpose operations before getting fed to MatMul operations inside MHA layers. For instance, the transformer execution module 150 may transpose a key tensor before the key tensor is multiplied with a query tensor.

[0051] The datastore 160 stores data received, generated, used, or otherwise associated with the AI system 100. For example, the datastore 160 stores the datasets used by the training module 120 and fine-tuning module 130. The datastore 160 may also store data generated by the training module 120 and fine-tuning module 130, such as the hyperparameters for training or fine-tuning DNNs, internal parameters of trained or fine-tuned DNNs (e.g., weights, etc. ) , and so on. The datastore 160 may store graphs, configuration parameters, compilation descriptors, or other data generated by the compiler 140 or the transformer execution module 150. The datastore 160 may include one or more memories. In the embodiment of FIG. 1, the datastore 160 is a component of the AI system 100. In other embodiments, the datastore 160 may be external to the AI system 100 and communicate with the AI system 100 through a network.

[0052] FIG. 2 illustrates an elastic adapter 200 for fine-tuning a DNN layer 205, in accordance with various embodiments. The elastic adapter 200 includes a linear layer 210 and linear layer 220. In other embodiments, the elastic adapter 200 may include fewer, more, or different components. For instance, the elastic adapter 200 may include more than one linear layer 210 or more than one linear layer 220.

[0053] The DNN layer 205 may be a layer in a DNN, such as a transformer-based DNN. In an example, the DNN is an LLM. The DNN may have been trained, and the internal parameters of the DNN layer 205 may have been determined from the training. The DNN layer 205 may be an attention layer (e.g., MHA layer) , feed forward layer, add and norm layer, linear layer, other types of layers, or some combination thereof. The DNN layer 205 has an input tensor 201 and output tensor 202. In some embodiments, one or more neural network operations in the DNN layer 205 may be performed on the input tensor 201 and internal parameters of the DNN layer 205 (e.g., a weight tensor of the DNN layer 205) to produce the output tensor 202.

[0054] As shown in FIG. 2, the elastic adapter 200 is placed after the DNN layer 205. During the fine-tuning process, the input tensor 201 is first processed at the DNN layer 205 and then processed at the elastic adapter 200. For instance, the output of the DNN layer 205, which is generated from the input tensor 201, is input into the linear layer 210. And the output of the linear layer 210, which is generated from the output of the DNN layer 205, is input into the linear layer 220. The linear layer 220 generates and outputs the output tensor 202. The linear layer 210 or linear layer 220 may perform a linear transformation on its input data. This transformation may involve a weighted sum of the inputs, which may be followed by the addition of a bias. The weights or bias may be learnable parameters that are adjusted during the fine-tuning process to optimize the performance of the DNN. The linear transformation may be denoted as y=wx+b, where x is an input, w is weight, b is bias, and y is output.

[0055] In some embodiments, the weight tensor of the DNN layer 205 is denoted as W∈Rd×k, where W is the weight tensor, d is a dimension (e.g., height) of the weight tensor, and k is another dimension (e.g., width) of the weight tensor. The input tensor 201 is denoted as X∈Rn×d, where n is a dimension (e.g., height) of the input tensor 201, and d is another dimension (e.g., width) of the input tensor 201. The output tensor 202 is denoted as Y∈Rn×k, where n is a dimension (e.g., height) of the output tensor 202, andk is another dimension (e.g., width) of the output tensor 202. The weight tensor of the linear layer 210 is denoted as A∈Rk×r, where k is a dimension (e.g., height) of the weight tensor, and r is another dimension (e.g., width) of the weight tensor. The weight tensor of the linear layer 220 is denoted as B∈Rr×k, where r is a dimension (e.g., height) of the weight tensor, and k is another dimension (e.g., width) of the weight tensor. The linear layer 210 with weight tensor A∈Rk×rmay transform the feature output from the pretrained weight matrix W∈Rd×k of the DNN layer 205 into a space with k / r times dimension reduction, and the linear layer 220 with the weight matrix B∈Rr×k may transform the dimension-reduced feature output back to the original space.

[0056] In some embodiments, the fine-tuning may be done with task-specific dataset. In some embodiments, the internal parameters of the DNN layer 205 are fixed during the fine-tuning process, while the linear layer 210 or linear layer 220 is trained to improve or optimize the accuracy of the DNN layer 205 for the specific task. For instance, the internal parameters of the linear layer 210 or linear layer 220 can be updated during the fine-tuning process. The ratio of the tunable weights to the pretrained weights may be I n some embodiments, r<< (d, k) . In an example, r=64, k=2048, d=2048. Therefore, the ratio of the tunable weights to the pretrained weights can be significantly small. The elastic adapter 200 can smartly leverages the paired dimension-down-up linear operations to formulate its structure. The elastic adapter 200 can endow the fine-tuning of the DNN layer 205 with the capability to significantly improve the inference efficiency besides the fine-tuning efficiency. In some embodiments, the elastic adapter 200 may be inserted after multiple layers in the DNN. For instance, the elastic adapter 200 may be inserted after every layer that needs to be fine-tuned.

[0057] FIG. 3 illustrates a modified DNN layer 300, in accordance with various embodiments. The modified DNN layer 300 may be generated by modifying the DNN layer 205 with the linear layer 210. After the fine-tuning, the pretrained weight matrix W of the DNN layer 205 and the newly trained weight matrix A of the linear layer 210 may be merged into Wr= WA∈Rd×r, where d is a dimension (e.g., height) of the weight matrix Wr, and r is another dimension (e.g., width) of the weight matrix Wr. The pretrained weight matrix W of the DNN layer 205 and the newly trained weight matrix A of the linear layer 210 may be mergeable due to the linear property. The merged weight matrix Wr may be the weight tensor of the modified DNN layer 300.

[0058] In some embodiments, the modified DNN layer 300 and linear layer 220 may replace the DNN layer 205 to form a modified DNN. The modified DNN may be executed to perform the task. The merged weight matrix Wr and the newly trained weight matrix B may be saved in the fine-tuned model. The re-trained weight matrix W of the DNN layer 205 and the trained weight matrix A may not be saved for inference purpose. In some embodiments, the fine-tuned model may have times reduction both in layer size and computational cost (e.g., MAC operations) compared to the pretrained model.

[0059] For an arbitrary layer of the fine-tuned model, there may be r (d+k) parameters and ndr+nrk MAC operations in total, while there are dk parameters and ndk MAC operations in total for the corresponding layer of the pretrained model. In an example where all layers of the DNN have the same-dimension weight matrix, the fine-tuned model can have times reduction both in layer size and computational cost against the pretrained model.

[0060] FIG. 4 illustrates modifying a DNN 400 with elastic adapters, in accordance with various embodiments. The DNN 400 may be a transformer-based model. For the purpose of illustration, FIG. 4 shows three layers of the DNN 400: DNN layer 410, DNN layer 420, and DNN layer 430. The DNN 400 may include one or more other layers. The DNN layer 410, DNN layer 420, and DNN layer 430 are arranged in a sequence.

[0061] The DNN 400 may be fine-tuned using one or more elastic adapters, an example of which may be the elastic adapter 200 in FIG. 2. For instance, an elastic adapter may be placed after each of the DNN layer 410, DNN layer 420, and DNN layer 430. In some embodiments, one or more layers in the DNN 400 may have no elastic adapter for fine-tuning. The fine-tuning may be done after a training process, through which internal parameters of the DNN layer 410, DNN layer 420, and DNN layer 430 may have been determined. During the fine-tuning process, the internal parameters of the DNN layer 410, DNN layer 420, and DNN layer 430 may remain the same. The internal parameters of the elastic adapters (e.g., weights of linear transformations) may be trained to improve the performance of the DNN 400. In some embodiments, the fine-tuning may be done using a fine-tuning dataset, which may include fine-tuning samples and reference values. The fine-tuning samples may be input into the DNN 400 with the elastic adapters, and internal parameters of the elastic adapters may be adjusted to minimize a loss. The loss may measure a difference between the reference values and the predictions made by the DNN 400 using the fine-tuning samples. The fine-tuning dataset may be formed based on the AI task to be performed using the DNN 400. The AI task may be a task for language processing, computer vision, speech recognition, and so on.

[0062] After the update of the internal parameters of the elastic adapters is complete, the DNN layer 410, DNN layer 420, and DNN layer 430 are modified to generate modified DNN layer 415, modified DNN layer 425, and modified DNN layer 435, respectively. The modified DNN layer 415 may be generated by merging the DNN layer 410 with a linear layer in the elastic adapter for the DNN layer 410. The modified DNN layer 425 may be generated by merging the DNN layer 420 with a linear layer in the elastic adapter for the DNN layer 420. The modified DNN layer 435 may be generated by merging the DNN layer 430 with a linear layer in the elastic adapter for the DNN layer 430. The modified DNN layer 415 is followed by another linear layer 417 in the elastic adapter for the DNN layer 410. The modified DNN layer 425 is followed by another linear layer 427 in the elastic adapter for the DNN layer 420. The modified DNN layer 435 is followed by another linear layer 437 in the elastic adapter for the DNN layer 430. A modified DNN 405 is formed and includes the modified DNN layer 415, linear layer 417, modified DNN layer 425, linear layer 427, modified DNN layer 435, and linear layer 437. The modified DNN 405 is a fine-tuned DNN and may be used to perform the AI task.

[0063] FIG. 5 illustrates an example transformer model 500, in accordance with various embodiments. The transformer model 500 may transform input sequences into output sequences. In some embodiments, the transformer model 500 is a DNN that can learn context and meaning by tracking relationships in sequential data, such as sequential words in a sentence, sequential audio signals, sequential images, and so on. In an example, the transformer model 500 may be an example of the DNNs described above. The transformer model 500 includes an encoder block 510, a decoder block 520, and a head block 530. In other embodiment, different or additional components may be included in the transformer model 500. Further, functionality attributed to a component of the transformer model 500 may be accomplished by a different component included in the transformer model 500 or a different model or module.

[0064] The encoder block 510 receives input sequences and generates matrix representations of the input sequences. In the embodiments of FIG. 5, the encoder block 510 receives an input 501 and generates an encoder output 502. The input 501 may be an input prompt. In some embodiments, the input 501 may include one or more input tokens, such as words, phrases, sentences, images, audio signals, other types of input tokens, or some combination thereof. In an example, the input 501 may include a prompt received from a user of the transformer model 500. The prompt may include a question or request made by the user. A word in the prompt may be an input token. The encoder output 502 may include one or more vectors that are contextualized representations of the input 501. Each vector in the encoder output 502 may represent a token in the input 501 with contextual understanding.

[0065] The encoder block 510 includes an embedding layer 513, a positional encoding layer 515, and a plurality of layers 540 (individually referred to as “layer 540” ) . In other embodiments, the encoder block 510 may have different, fewer, or more components. Also, the arrangement of the components in the encoder block 510 may be different from the arrangement shown in FIG. 5. For the purpose of illustration, the encoder block 510 has N layers in FIG. 5, where N is an integer. Each layer 540 may include one or more neural network operations. The layers 540 may transform a sequence of embeddings into a representation that encapsulates the learned information from the input 501. Different layers 540 may have different internal parameters, e.g., different weights, bias, or other types of internal parameters. In some embodiments, the layers 540 have identical components. The components in a layer 540 may be layers and may also be referred to as sub-layers of the layer 540. As shown in FIG. 5, a layer 540 includes four sub-layers: an MHA layer 541, an add & norm layer 542, a feed forward layer 543, and another add & norm layer 544.

[0066] The decoder block 520 iteratively generates outputs 503 using encoded representations generated by the encoder block 510. The decoder block 520 includes an embedding layer 523, a positional encoding layer 525, and a plurality of layers 550 (individually referred to as “layer 550” ) . For the purpose of illustration, the decoder block 520 has N layers in FIG. 5, where N is an integer. In the embodiments of FIG. 2, the number of layers 550 in the decoder block 520 is the same as the number of layers 540 in the encoder block 510. In other embodiments, the number of layers 550 in the decoder block 520 may be different from the number of layers 540 in the encoder block 510. Each layer 550 may include one or more neural network operations. Different layers 550 may have different internal parameters. In some embodiments, the layers 550 may have identical components. The components in a layer 550 may be layers and may also be referred to as sub-layers of the layer 550. As shown in FIG. 5, a layer 550 includes six sub-layers: an MHA layer 551, an add & norm layer 552, an MHA 553, another add & norm layer 554, a feed forward layer 555, and another add & norm layer 556.

[0067] In some embodiments, a sequence of inference stages is performed in the decoder block 520 using encoder outputs, e.g., the encoder output 502. A matrix may be predicted through each inference stage. The outputs 503 may include a plurality of matrices. Each matrix may be further processed in the head block 530 to predict a token. The plurality of matrices may be used to predict a sequence of tokens. For the first inference stage, the decoder block 520 may receive one or more start tokens as input tokens and compute a first matrix from the input tokens and the output of the encoder block 510. The first matrix may be used by the head block 530 to predict a first token. The predicted token may be used as a new input token, in addition to the start token (s) , in the second inference stage. Similarly, a second token may be predicted through the second inference stage and may be used in the third inference stage. This iteration may continue till all the inference stages are complete.

[0068] The head block 530 receives the output of the decoder block 520 and processes it in a linear layer 533 and a SoftMax layer 535. A linear operation may be performed on the output of the decoder block 520 in the linear layer 533. The linear operation may include a multiplication of the output of the decoder block 520 with a weight matrix. The output of the linear layer 533 may be a vector. In some embodiments, the head block 530 may function as a classifier. The number of data elements in the vector computed in the linear layer 533 may depend on the number of classes involved. In an example where there are M classes, where M is an integer, the vector computed in the linear layer 533 may have M data elements representing the prediction for the M classes, respectively.

[0069] The output of the linear layer 533 may be input into the SoftMax layer 535. A SoftMax function may be applied on the output of the linear layer 533 to compute probability scores. A probability score may have a value in the range from 0 to 5. In some embodiments, a probability value is computed for each data element in the vector computed in the linear layer 533. The highest one of the probability scores may be the key. The corresponding index of the key may point to the token that the transformer model 500 predicts as the next in the sequence. The final output of the transformer model 500 may be the sequence of predicted tokens. In some embodiments, the head block 530 may be a language modeling head.

[0070] An embedding layer (e.g., the embedding layer 513 or the embedding layer 523) converts an input of the embedding layer (e.g., the input 501 or the outputs 503) into one or more embeddings. An embedding may be a vector, which is also referred to as an embedding vector or a vector embedding. The vector embedding may include a sequence of data elements. In some embodiments, the embedding layer 513 may generate a plurality of embeddings, each of which may be converted from a different input token in the input 501. The embeddings may capture the semantic meaning of the tokens in the input 501. The embeddings may be numerical representations that capture the relationships or meanings of words, phrases, or other data types. In an example where the input 501 is a prompt including a sequence of words, the embedding layer 513 may generate an embedding from each word in the input 501. The embedding layer 523 in the decoder block 520 may generate a plurality of embeddings from tokens received by the decoder block 520 in a similar manner as the embedding layer 513.

[0071] A positional encoding layer (e.g., the positional encoding layer 515 or the positional encoding layer 525) performs positional encoding on embeddings generated in the corresponding embedding layer. In some embodiments, the positional encoding layer may apply one or more positional encoding vectors (e.g., a positional encoding vector 504 or positional encoding vector 505) on vector embeddings from the corresponding embedding layer to generate new vector embeddings that represents the embeddings with positional context. The positional encoding vector may encode information about the position of the embedding in a sequence of embeddings. In some embodiments, the positional encoding layer performs an addition operation on a positional encoding vector and a vector embedding. The addition operation may be elementwise addition. The positional encoding layer may output an embedding matrix that includes the vector embeddings computed in the positional encoding layer.

[0072] An MHA layer (e.g., the MHA layer 541, the MHA layer 551, or the MHA layer 553) may implement a multi-head attention mechanism, which may be a multi-head self-attention mechanism or a multi-head cross-attention mechanism. In some embodiments, the MHA layer 541 or the MHA layer 551 may implement a self-attention mechanism. For self-attention, the queries, keys, and values may come from the same place. For instance, for the MHA layer 541, the queries, keys, and values may all come from the positional encoding layer 515. For the MHA layer 551, the queries, keys, and values may all come from the positional encoding layer 525. The self-attention mechanism may enable the transformer model 500 to relate each token with other tokens. The MHA layer may compute attention scores from embeddings generated in the corresponding positional encoding layer. In some embodiments, the MHA layer may receive one or more queries, one or more keys, and one or more values. In some embodiments, the MHA layer has a number of heads that receive different linearly projected versions of the queries, keys, and values and produce outputs in parallel that are then used to generate the final result.

[0073] In some embodiments, the queries, keys, and values input into the MHA layer 541 may be computed from vector embeddings generated by the positional encoding layer 515. The queries, keys, and values input into the MHA layer 551 may be computed from vector embeddings generated by the positional encoding layer 525. A query, key, or value may be a vector the represents a token in a sequence. In some embodiments, a query matrix may be computed by multiply an embedding matrix  (e.g., an embedding matrix computed in a positional encoding layer) with a weight matrix where d is the dimension of a vector embedding, N is the number of vector embeddings in the embedding matrix, and h is the number of attention heads. Each row in the query matrix may be a query. A key matrix may be computed by multiple an embedding matrix  (e.g., an embedding matrix computed in a positional encoding layer) with a weight matrix Each row in the key matrix may be a key. A value matrix may be computed by multiple an embedding matrix  (e.g., an embedding matrix computed in a positional encoding layer) with a weight matrix Each row in the value matrix may be a value.

[0074] In some embodiments, the MHA layer 551 may implement masked multi-head self-attention. The MHA layer 551 may prevent positions from attending to subsequent positions. For instance, each token in the sequence may not be influenced by future tokens. This masking can ensure that the predictions of a particular position can depend on known outputs at positions before it and not depend on unknown outputs at positions after it.

[0075] In some embodiments, the MHA layer 553 may implement a cross-attention mechanism, such as encoder-decoder cross-attention. The MHA layer 553 may use outputs from the previous layer (i.e., the add & norm layer 552) as queries and use outputs from the encoder block 510 as keys and values. The cross-attention can align the encoder’s input with the decoder’s , empowering the decoder block 520 to identify and emphasize the most relevant parts of the encoder’s input. Certain aspects of MHA layers are described below in conjunction with FIGS. 6A and 6B.

[0076] An add & norm layer in the transformer model 500, such as the add & norm layer 542, 544, 552, 554, and 556, has an addition operation followed by a layer normalization operation. The addition operation may be an addition of the output of the preceding layer and the input of the preceding layer. The preceding layer is a layer that is arranged right before the add & norm layer. For example, the preceding layer of the add & norm layer 542 is the MHA layer 541. As another example, the preceding layer of the add & norm layer 554 is the encoder-decoder attention layer 553.

[0077] Then the layer normalization operation is applied on the result of the addition operation, which may be denoted as LayerNorm (x+sublayer (x) ) , where LayerNorm denotes layer normalization, x is the input of the preceding layer, and sublayer (x) denotes the output of the preceding layer. In some embodiments, the layer normalization operation may include a sequence of computations. In an example, the layer normalization operation may include a mean computation, which may be denoted as where Axyz denotes a data element in the input tensor, x may be the positional index of the data element in one of the spatial dimensions, y may be the positional index of the data element in the other one of the spatial dimensions, z may be the positional index of the data element in the channel dimension, and μxy denotes the output of the mean computation, which may be a 2D matrix. The mean computation may be channel-wise reduction operation. The layer normalization operation may convert μxy to a 3D tensor μxyz, e.g., by replicating every data element over z output points.

[0078] The layer normalization operation may also include an elementwise subtraction, which may be denoted as Dxyz=Axyz-μxyz. The layer normalization operation may further include a variance computation denoted as and a division computation denoted as may be a 2D tensor. The layer normalization operation may also convert Mxy to a 3D tensor Mxyz, e.g., by replicating every data element over z output points. Further, the layer normalization operation may have an element multiplication denoted as Dxyz×Mxyz. The layer normalization operation may further compute and LNxyz=A″xyz×γz. LNxyz may be the output of the layer normalization operation.

[0079] A feed forward layer (e.g., the feed forward layer 543 and the feed forward layer 555) may be a position-wise fully-connected feed forward network. In an example, the feed forward layer may include two linear layers with an activation function in between. An example of the activation function is Rectified Linear Unit (ReLU) .

[0080] FIGS. 6A and 6B illustrate an example MHA layer 600, in accordance with various embodiments. The MHA layer 600 may be an example of the MHA layer 541 or the MHA layer 551 in FIG. 5. As shown in FIG. 6A, the MHA layer 600 includes linear layers 610, 620, and 630, a MatMul layer 640, a scale layer 650, a SoftMax layer 660, another MatMul layer 670, a concatenation layer 680, and another linear layer 690. In other embodiments, the MHA layer 600 may include fewer, more, or different layers.

[0081] The MHA layer 600 receive three input matrices: a query matrix 601, a key matrix 602, and a value matrix 603, which are inputs of the linear layers 610, 620, and 630, respectively. The linear layers 610, 620, and 630 are in a linear block 615 of the MHA layer 600. In some embodiments, the MHA layer 600 includes a plurality of linear blocks that includes the linear block 615. For the purpose of illustration, the MHA layer 600 includes hlinear blocks in FIG. 6A, where h is an integer. Each of the linear blocks may have the same layers as the linear block 615. Each linear block may compute three parameter matrices from the query matrix 601, key matrix 602, and value matrix 603, respectively. For instance, the linear layer 610 may perform a multiplication of the query matrix 601 with a weight matrix to compute a parameter matrix 604 shown in FIG. 6B. The linear layer 620 may perform a multiplication of the key matrix 602 with a weight matrix to compute a parameter matrix 605 shown in FIG. 6B. The linear layer 630 may perform a multiplication of the value matrix 603 with a weight matrix to compute a parameter matrix 607 shown in FIG. 6B.

[0082] The parameter matrix 604 may be denoted as   where Q is the query matrix 601 and is the weight matrix. The parameter matrix 605 may be denoted as  where K is the key matrix 602 and is the weight matrix. The parameter matrix 607 may be denoted as where V is the value matrix 603 and is the weight matrix. i may indicate the index of the head. dq is the dimension of a query vector. dk is the dimension of a key vector. dv is the dimension of a value vector. In some embodiments, dq=dk=dv=dmodel / h.

[0083] The MatMul layer 640, scale layer 650, mask layer 655, SoftMax layer 660, and MatMul layer 670 are in an attention block 625 of the MHA layer. The attention block 625 may implement a scaled dot-product attention mechanism. In some embodiments, the MHA layer 600 includes a plurality of attention blocks that includes the attention block 625. For the purpose of illustration, the MHA layer 600 includes h attention blocks in FIG. 6A. Each of the attention blocks may have the same layers as the attention block 625. The linear block 615 and attention block 625 may constitute a head of the MHA layer 600. As the MHA layer 600 has h linear blocks and h attention blocks, the MHA layer 600 has h heads. A head may be denoted as

[0084] A matrix multiplication operation may be performed on the parameter matrices 604 and 605 in the MatMul layer 640, which computes a score matrix 606. In some embodiments, the score matrix 606 may establish the degree of emphasis each token should place on other tokens. The 606 may include a plurality of scores. Each token may be assigned a score in relation to other tokens within the same time step. A higher score may indicate a higher focus or emphasis. The score matrix 606 may be scaled in the scale layer 650. In some embodiments, the score matrix 606 is scaled down in the scale layer 650 by dividing the scores in the score matrix by the square root of the dimension of the query vector and the key vector, which may be denoted as The output of the scale layer 650 may be a scaled matrix 608, which includes adjusted scores. The mask layer 655 may be optional in some embodiments. The mask layer 655 may add an attention mask (which may be an input to the attention block 625) to the output of the scale layer 650 to mask out some elements in the output of the scale layer 650. The positions of the masked out elements may be defined by the attention mask. A SoftMax function may be applied on the scaled matrix 608 in the SoftMax layer 660 to compute an attention weight matrix 609. The attention weight matrix 609 includes attention weights. The attention weights may be probability values ranging from 0 to 1. The SoftMax function may emphasize high scores while diminishing low scores, which can enhance the model’s ability to determine which tokens should get more attention.

[0085] In the MatMul layer 670, a matrix multiplication operation is performed on the attention weight matrix 609 computed in the SoftMax layer 660 and the parameter matrix 607 computed from value matrix 603 in the linear layer 630. The result of the matrix multiplication operation is a single-head output matrix 611, which is an output of the attention block 625.

[0086] As the MHA layer 600 has h attention blocks, there may be h single-head output matrices. The single-head output matrices are concatenated in the concatenation layer 680 to form a concatenated matrix. A linear operation (also referred to as “linear transformation” ) is performed on the concatenated matrix using a weight matrix in the linear layer 690. In some embodiments, the MHA may be denoted as MultiHead (Q, K, V) =Concat (head1, head2, …, headh) WO, where Concat denotes concatenation, and is the weight matrix in the linear layer 690.

[0087] FIG. 7 illustrates an example linear classifier 700, in accordance with various embodiments. The linear classifier 700 may be used in transformer models. In some embodiments, the linear classifier 700 may generate tokens based on outputs of decoders. The linear classifier 700 may be an example of the head block 530 in FIG. 5. As shown in FIG. 7, the linear classifier 700 includes a linear layer 710 and a SoftMax layer 720. In other embodiments, the linear classifier 700 may include fewer, more, or different components.

[0088] The linear layer 710 is provided with a matrix 701. The matrix 701 may be an output of a decoder, e.g., the decoder block 520. A linear transformation may be performed on the matrix 701 and a weight matrix in the linear layer 710. The weight matrix may include weights, which are internal parameters of the linear layer 710. The linear layer outputs a vector 702. In some embodiments, the dimension of the vector 702 (e.g., the total number of elements in the vector 702) may be equal to the total number of classes associated with the AI task being performed by the transformer model. The vector 702 is provided to the SoftMax layer 720. The SoftMax layer 720 generates a vector 703 from the vector 702. In some embodiments, the dimension of the vector 703 may equal the dimension of the vector 702. Each element in the vector 703 may correspond to a predicted token and may indicate a probability score of the predicted token. The probability score may indicate the probability that the prediction is correct. A predicted token 704 having the highest probability score may be selected and output from the linear classifier 700.

[0089] The output of the linear classifier 700 may be the output of the transformer model. The execution of the linear classifier 700 may be performed multiple times during inference of the transformer model. For instance, the transformer model may have multiple inference stages, and the linear classifier 700 may be executed at least once in each inference stage. The dimensions of the vectors and matrices shown in FIGS. 2-5 are example dimensions used for purpose of illustration and simplicity. Any of the vectors and matrices used or computed by operations illustrated in FIGS. 2-5 may have different dimensions.

[0090] FIG. 8 illustrates a first inference stage of a transformer model 800, in accordance with various embodiments. The transformer model 800 includes an encoder 810, a decoder 820, and a head 830. An example of the transformer model 800 may be the transformer model 500 in FIG. 5. In the embodiments of FIG. 8, the encoder 810 receives an input tensor 801. The input tensor 801 may be a feature map extracted from one or more images, text documents, audio files, videos, other types of data, or some combination thereof. In some embodiments, the input tensor 801 may be generated by another neural network, e.g., a CNN. The encoder 810 generates an output tensor 802 from the input tensor 801. The shape of the output tensor 802 may be denoted as [batch size, SLencoder, dmodel] , where SLencoder may be the dimension along the X axis (i.e., the width of the output tensor 802) , and dmodel may be the dimension along the Y axis (i.e., the height of the output tensor 802) . The encoder 810 may include a plurality of layers arranged in a sequence, such as the layers inside the encoder block 510 in FIG. 5. The output tensor 802 is provided to the decoder 820.

[0091] The decoder 820 receives the output tensor 802 and an input sequence 803. The input sequence 803 may be a sequence of tokens. A token may be a numerical representation of an input signal, such as word, image, audio signal, video signal, etc. The dimension of the input sequence 803, which may be denoted as SLinput, may be the total number of tokens in the input sequence 803. For the purpose of illustration and simplicity, SLinput is 4. In other embodiments, the input sequence 803 may have a different shape. For instance, the input sequence 803 may be a 2D tensor. The dimension of the 2D tensor along the X axis may be SLinput, while the dimension of the 2D tensor along the Y axis may be a batch size indicating the number of batches in the input sequence 803.

[0092] The decoder 820 computes an output tensor 804, a self-attention key tensor 805, a self-attention value tensor 806, a cross-attention key tensor 807, and a cross-attention value tensor 808. In some embodiments, the shape of the output tensor 804 may be denoted as [batch size, SLinput, dmodel] . The shape of the self-attention key tensor 805 or the shape of the self-attention value tensor 806 may be denoted as N× [batch size, h, SLinput, dhead] , where N is the number of identical layers in the decoder (e.g., the number of layers 550 in the decoder block 520) , h is the total number of heads in a MHA layer, and dhead is the dimension of a query vector, key vector, or value vector. In some embodiments, dmodel=h×dhead. The shape of the cross-attention key tensor 807 or the shape of the cross-attention value tensor 808 may be denoted as N× [batch size, h, SLencoder, dhead] .

[0093] The output tensor 804 may be provided to the head 830 and the head 830 outputs a predicted token 809. The shape of the token 809 may be denoted as [batch size, 1] . For the purpose of illustration and simplicity, batch size is 1 in FIG. 8. In other embodiments, batch size may be a larger number. The predicted token 809 may be stored in a buffer. In some embodiments, the predicted token 809 may be used to update the input sequence 803. For instance, the predicted token 809 may be added to the right of the input sequence 803. The updated input sequence may be used as the input sequence in the second inference stage. In the second inference stage, the decoder 820 may receive the updated input sequence and the output tensor 802 for predicting another token. The output tensor 802 may remain the same during inference of the decoder 820. Certain aspects of subsequent inference stages are described below in conjunction with FIG. 9.

[0094] In some embodiments, the self-attention key tensor 805 and the self-attention value tensor 806 may be provided to a self-attention layer in the decoder 820, an example of such a self-attention layer is the MHA layer 551. The self-attention key tensor 805 may be stored in a self-attention key cache. The self-attention key cache may have the same shape as the self-attention key tensor 805. The self-attention value tensor 806 may be stored in a self-attention value cache. The self-attention value cache may have the same shape as the self-attention value tensor 806.

[0095] In some embodiments, the decoder 820 computes the self-attention key tensor 805 and the self-attention value tensor 806 from the input sequence 803. The input sequence 803 may be dynamic during inference of the decoder 820. For instance, a new token may be added to the input sequence 803 after each inference stage, as described above. As the input sequence 803 changes, the self-attention key tensor 805 and the self-attention value tensor 806 would also change. For instance, the dimension of the self-attention key tensor 805 or the self-attention value tensor 806 along the X axis may increase as SLinput increases. The self-attention key cache and the self-attention value cache may change during all the inference stages of the decoder 820 to accommodate the changes in the self-attention key tensor 805 and the self-attention value tensor 806.

[0096] In some embodiments, the self-attention value tensor 806 and the cross-attention value tensor 807 may be provided to a cross-attention layer in the decoder 820, an example of such a cross-attention layer is the MHA layer 553. The cross-attention key tensor 807 may be stored in a cross-attention key cache. The cross-attention key cache may have the same shape as the cross-attention key tensor 807. The cross-attention value tensor 808 may be stored in a cross-attention value cache. The cross-attention value cache may have the same shape as the cross-attention value tensor 808. In some embodiments, the decoder 820 computes the self-attention value tensor 806 and the cross-attention value tensor 807 from the output tensor 802 generated in the encoder 810. As the output tensor 802 does not change during inference of the decoder 820, the self-attention value tensor 806 and the cross-attention value tensor 807 may remain the same during all the inference stages of the decoder 820. The cross-attention key cache and the cross-attention value cache may remain the same during all the inference stages of the decoder 820.

[0097] FIG. 9 illustrates subsequent inference stages of the transformer model, in accordance with various embodiments. In the second inference stage, the decoder 820 may reuse the self-attention key tensor 805, self-attention value tensor 806, cross-attention key tensor 807, and cross-attention value tensor 808. The decoder 820 also receives the predicted token 809. The decoder 820 may compute self-attention key vectors from the predicted token 809 and concatenate the self-attention key vectors with the self-attention key tensor 805 to generate a new self-attention key tensor 815. For instance, a self-attention key vector for each head may be added to the right of a self-attention key matrix in the self-attention key tensor 805, and the self-attention key vector and the self-attention key matrix may correspond to the same head. The elements highlighted with a dot pattern in the self-attention key tensor 815 are the self-attention key vectors generated from the predicted token 809.

[0098] Similarly, the decoder 820 may compute self-attention value vectors from the predicted token 809 and concatenate the self-attention value vectors with the self-attention value tensor 806 to generate a new self-attention value tensor 816. For instance, a self-attention value vector for each head may be added to the right of a self-attention value matrix in the self-attention value tensor 806, and the self-attention value vector and the self-attention value matrix may correspond to the same head. The elements highlighted with a dot pattern in the self-attention value tensor 816 are the self-attention value vectors generated from the predicted token 809.

[0099] The decoder 820 also generates an output tensor 814. The decoder 820 may generate the output tensor 814 using the new self-attention key tensor 815 and new self-attention value tensor 816. The output tensor 814 is used by the head 830 to generate another predicted token 819. The predicted token 819 is the output of the transformer model 800 in the second inference stage.

[0100] One or more other subsequent inference stages may be conducted. In each subsequent inference stage, the decoder 820 receives a token predicted in the previous inference stage, a self-attention key tensor generated in the previous inference stage, a self-attention value tensor generated in the previous inference stage, the cross-attention key tensor 807, and the cross-attention value tensor 808. The decoder 820 may, in the subsequent inference stage, generate a larger self-attention key tensor and a larger self-attention value tensor, in addition to an output tensor which can be used by the head 830 to predict a new token.

[0101] In embodiments where the total number of inference stages is N, the input sequence 803 is updated to an input sequence 813 after N-1 inference stages. In the last inference stage (i.e., the Nth inference stage) , the decoder 820 may receive the predicted token generated in the (N-1) th inference stage, the self-attention key tensor generated in the (N-1) th inference stage, the self-attention value tensor generated in the (N-1) thinference stage, the cross-attention key tensor 807, and the cross-attention value tensor 808. The decoder 820 may generate a self-attention key tensor 825 and a self-attention value tensor 826 using the predicted token generated in the (N-1) th inference stage, the self-attention key tensor generated in the (N-1) th inference stage, and the self-attention value tensor generated in the (N-1) th inference stage. The dimensions of the self-attention key tensor 825 or self-attention value tensor 826 along the X axis is SLinput+N. The decoder 820 also generates an output tensor 824, which is used by the head 830 to generate the last predicted token 829. The N tokens predicted by the transformer model in the N inference stages may constitute an output tensor 839, which may be the final output of the transformer model.

[0102] FIG. 10 is a flowchart of a method 1000 of fine-tuning a DNN, in accordance with various embodiments. The method 1000 may be performed by the fine-tuning module 130 in FIG. 1. Although the method 1000 is described with reference to the flowchart illustrated in FIG. 10, many other methods for fine-tuning DNNs may alternatively be used. For example, the order of execution of the steps in FIG. 10 may be changed. As another example, some of the steps may be changed, eliminated, or combined.

[0103] The fine-tuning module 130 inserts 1010 a first linear layer and a second linear layer into the DNN. The layer of the DNN has a pretrained weight tensor. The layer of the DNN has a pretrained weight tensor. In some embodiments, the first linear layer and the second linear layer are inserted after the layer of the DNN. In some embodiments, the first linear layer is arranged between the layer of the DNN and the second linear layer. In some embodiments, the DNN is a transformer-based model. An example of the DNN is an LLM. In some embodiments, the first linear layer or second linear includes a linear transformation. In some embodiments, the linear transformation is based on the weight tensor of the linear layer. In some embodiments, the weight tensor is a 2D matrix.

[0104] The fine-tuning module 130 trains 1020 a weight tensor of the first linear layer and a weight tensor of the second linear layer based on a difference between a reference value of a fine-tuning sample and a prediction made by the DNN with the first linear layer and the second linear layer using the fine-tuning sample. In some embodiments, the fine-tuning sample is in a fine-tuning dataset. In some embodiments, the fine-tuning module 130 forms or obtains the fine-tuning sample or fine-tuning dataset. In some embodiments, the fine-tuning sample or fine-tuning dataset is specific to one or more AI tasks to be performed by the DNN after the fine-tuning.

[0105] In some embodiments, a dimension of the weight tensor of the first linear layer equals a dimension of a weight tensor of the second linear layer. In some embodiments, the dimension of the weight tensor of the second linear layer is smaller than another dimension of the weight tensor of the second linear layer. In some embodiments, a dimension of the weight tensor of the first linear layer is smaller than a dimension of the pretrained weight tensor of the layer of the DNN. In some embodiments, another dimension of the weight tensor of the first linear layer equals another dimension of the pretrained weight tensor of the layer of the DNN.

[0106] The fine-tuning module 130 forms 1030 a new layer by merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the DNN after training the weight tensor of the first linear layer and the weight tensor of the second linear layer. In some embodiments, the fine-tuning module 130 merges the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the DNN by performing a multiplication operation on the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the DNN to produce a new weight tensor.

[0107] The fine-tuning module 130 generates 1040 a new DNN with the new layer and the second linear layer. In some embodiments, the fine-tuning module 130 inserts an additional linear layer into the DNN by placing the additional linear layer after an additional layer of the DNN. The fine-tuning module 130 modifies one or more values of a weight tensor of the additional linear layer while maintaining values of a pretrained weight tensor of the additional layer. The fine-tuning module 130 generates the new DNN is by merging the additional linear layer and the additional layer.

[0108] FIG. 11 is a block diagram of an example computing device 1100, in accordance with various embodiments. In some embodiments, the computing device 1100 can be used as at least part of the AI system 100 in FIG. 1. A number of components are illustrated in FIG. 11 as included in the computing device 1100, but any one or more of these components may be omitted or duplicated, as suitable for the application. In some embodiments, some or all of the components included in the computing device 1100 may be attached to one or more motherboards. In some embodiments, some or all of these components are fabricated onto a single system on a chip (SoC) die. Additionally, in various embodiments, the computing device 1100 may not include one or more of the components illustrated in FIG. 11, but the computing device 1100 may include interface circuitry for coupling to the one or more components. For example, the computing device 1100 may not include a display device 1106, but may include display device interface circuitry (e.g., a connector and driver circuitry) to which a display device 1106 may be coupled. In another set of examples, the computing device 1100 may not include an audio input device 1118 or an audio output device 1108 but may include audio input or output device interface circuitry (e.g., connectors and supporting circuitry) to which an audio input device 1118 or audio output device 1108 may be coupled.

[0109] The computing device 1100 may include a processing device 1102 (e.g., one or more processing devices) . The processing device 1102 processes electronic data from registers and / or memory to transform that electronic data into other electronic data that may be stored in registers and / or memory. The computing device 1100 may include a memory 1104, which may itself include one or more memory devices such as volatile memory (e.g., DRAM) , nonvolatile memory (e.g., read-only memory (ROM) ) , high bandwidth memory (HBM) , flash memory, solid state memory, and / or a hard drive. In some embodiments, the memory 1104 may include memory that shares a die with the processing device 1102. In some embodiments, the memory 1104 includes one or more non-transitory computer-readable media storing instructions executable to perform operations for executing transformer models (e.g., the method 1000 described in conjunction with FIG. 10) or some operations performed by one or more components of the AI system 100 (e.g., operations performed by the fine-tuning module 130) . The instructions stored in the one or more non-transitory computer-readable media may be executed by the processing device 1102.

[0110] In some embodiments, the computing device 1100 may include a communication chip 1112 (e.g., one or more communication chips) . For example, the communication chip 1112 may be configured for managing wireless communications for the transfer of data to and from the computing device 1100. The term "wireless" and its derivatives may be used to describe circuits, devices, systems, methods, techniques, communications channels, etc., that may communicate data through the use of modulated electromagnetic radiation through a nonsolid medium. The term does not imply that the associated devices do not contain any wires, although in some embodiments they might not.

[0111] The communication chip 1112 may implement any of a number of wireless standards or protocols, including but not limited to Institute for Electrical and Electronic Engineers (IEEE) standards including Wi-Fi (IEEE 802.10 family) , IEEE 802.16 standards (e.g., IEEE 802.16-2005 Amendment) , Long-Term Evolution (LTE) project along with any amendments, updates, and / or revisions (e.g., advanced LTE project, ultramobile broadband (UMB) project (also referred to as "3GPP2" ) , etc. ) . IEEE 802.16 compatible Broadband Wireless Access (BWA) networks are generally referred to as WiMAX networks, an acronym that stands for worldwide interoperability for microwave access, which is a certification mark for products that pass conformity and interoperability tests for the IEEE 802.16 standards. The communication chip 1112 may operate in accordance with a Global System for Mobile Communication (GSM) , General Packet Radio Service (GPRS) , Universal Mobile Telecommunications System (UMTS) , High Speed Packet Access (HSPA) , Evolved HSPA (E-HSPA) , or LTE network. The communication chip 1112 may operate in accordance with Enhanced Data for GSM Evolution (EDGE) , GSM EDGE Radio Access Network (GERAN) , Universal Terrestrial Radio Access Network (UTRAN) , or Evolved UTRAN (E-UTRAN) . The communication chip 1112 may operate in accordance with Code-division Multiple Access (CDMA) , Time Division Multiple Access (TDMA) , Digital Enhanced Cordless Telecommunications (DECT) , Evolution-Data Optimized (EV-DO) , and derivatives thereof, as well as any other wireless protocols that are designated as 3G, 4G, 5G, and beyond. The communication chip 1112 may operate in accordance with other wireless protocols in other embodiments. The computing device 1100 may include an antenna 1122 to facilitate wireless communications and / or to receive other wireless communications (such as AM or FM radio transmissions) .

[0112] In some embodiments, the communication chip 1112 may manage wired communications, such as electrical, optical, or any other suitable communication protocols (e.g., the Ethernet) . As noted above, the communication chip 1112 may include multiple communication chips. For instance, a first communication chip 1112 may be dedicated to shorter-range wireless communications such as Wi-Fi or Bluetooth, and a second communication chip 1112 may be dedicated to longer-range wireless communications such as global positioning system (GPS) , EDGE, GPRS, CDMA, WiMAX, LTE, EV-DO, or others. In some embodiments, a first communication chip 1112 may be dedicated to wireless communications, and a second communication chip 1112 may be dedicated to wired communications.

[0113] The computing device 1100 may include battery / power circuitry 1114. The battery / power circuitry 1114 may include one or more energy storage devices (e.g., batteries or capacitors) and / or circuitry for coupling components of the computing device 1100 to an energy source separate from the computing device 1100 (e.g., AC line power) .

[0114] The computing device 1100 may include a display device 1106 (or corresponding interface circuitry, as discussed above) . The display device 1106 may include any visual indicators, such as a heads-up display, a computer monitor, a projector, a touchscreen display, a liquid crystal display (LCD) , a light-emitting diode display, or a flat panel display, for example.

[0115] The computing device 1100 may include an audio output device 1108 (or corresponding interface circuitry, as discussed above) . The audio output device 1108 may include any device that generates an audible indicator, such as speakers, headsets, or earbuds, for example.

[0116] The computing device 1100 may include an audio input device 1118 (or corresponding interface circuitry, as discussed above) . The audio input device 1118 may include any device that generates a signal representative of a sound, such as microphones, microphone arrays, or digital instruments (e.g., instruments having a musical instrument digital interface (MIDI) output) .

[0117] The computing device 1100 may include a GPS device 1116 (or corresponding interface circuitry, as discussed above) . The GPS device 1116 may be in communication with a satellite-based system and may receive a location of the computing device 1100, as known in the art.

[0118] The computing device 1100 may include another output device 1110 (or corresponding interface circuitry, as discussed above) . Examples of the other output device 1110 may include an audio codec, a video codec, a printer, a wired or wireless transmitter for providing information to other devices, or an additional storage device.

[0119] The computing device 1100 may include another input device 1120 (or corresponding interface circuitry, as discussed above) . Examples of the other input device 1120 may include an accelerometer, a gyroscope, a compass, an image capture device, a keyboard, a cursor control device such as a mouse, a stylus, a touchpad, a bar code reader, a Quick Response (QR) code reader, any sensor, or a radio frequency identification (RFID) reader.

[0120] The computing device 1100 may have any desired form factor, such as a handheld or mobile computer system (e.g., a cell phone, a smart phone, a mobile internet device, a music player, a tablet computer, a laptop computer, a netbook computer, an ultrabook computer, a personal digital assistant (PDA) , an ultramobile personal computer, etc. ) , a desktop computer system, a server or other networked computing component, a printer, a scanner, a monitor, a set-top box, an entertainment control unit, a vehicle control unit, a digital camera, a digital video recorder, or a wearable computer system. In some embodiments, the computing device 1100 may be any other electronic device that processes data.

[0121] The following paragraphs provide various examples of the embodiments disclosed herein.

[0122] Example 1 provides a method of fine-tuning a neural network, including inserting a first linear layer and a second linear layer into the neural network for a layer of the neural network, the layer of the neural network having a pretrained weight tensor; training a weight tensor of the first linear layer and a weight tensor of the second linear layer based on a difference between a reference value of a fine-tuning sample and a prediction made by the neural network with the first linear layer and the second linear layer using the fine-tuning sample; and after training the weight tensor of the first linear layer and the weight tensor of the second linear layer, forming a new layer by merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network; and generating a new neural network with the new layer and the second linear layer.

[0123] Example 2 provides the method of example 1, in which the first linear layer and the second linear layer are inserted after the layer of the neural network.

[0124] Example 3 provides the method of example 2, in which the first linear layer is arranged between the layer of the neural network and the second linear layer.

[0125] Example 4 provides the method of any one of examples 1-3, in which a dimension of the weight tensor of the first linear layer equals a dimension of a weight tensor of the second linear layer.

[0126] Example 5 provides the method of example 4, in which the dimension of the weight tensor of the second linear layer is smaller than another dimension of the weight tensor of the second linear layer.

[0127] Example 6 provides the method of any one of examples 1-5, in which merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network includes performing a multiplication operation on the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network to produce a new weight tensor.

[0128] Example 7 provides the method of any one of examples 1-6, in which a dimension of the weight tensor of the first linear layer is smaller than a dimension of the pretrained weight tensor of the layer of the neural network.

[0129] Example 8 provides the method of example 7, in which another dimension of the weight tensor of the first linear layer equals another dimension of the pretrained weight tensor of the layer of the neural network.

[0130] Example 9 provides the method of any one of examples 1-8, further including inserting an additional linear layer into the neural network by placing the additional linear layer after an additional layer of the neural network; and modifying one or more values of a weight tensor of the additional linear layer while maintaining values of a pretrained weight tensor of the additional layer, in which generating the new neural network is by merging the additional linear layer and the additional layer.

[0131] Example 10 provides one or more non-transitory computer-readable media storing instructions executable to perform operations for fine-tuning a neural network, the operations including inserting a first linear layer and a second linear layer into the neural network for a layer of the neural network, the layer of the neural network having a pretrained weight tensor; training a weight tensor of the first linear layer and a weight tensor of the second linear layer based on a difference between a reference value of a fine-tuning sample and a prediction made by the neural network with the first linear layer and the second linear layer using the fine-tuning sample; after training the weight tensor of the first linear layer and the weight tensor of the second linear layer, forming a new layer by merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network; and generating a new neural network with the new layer and the second linear layer.

[0132] Example 11 provides the one or more non-transitory computer-readable media of example 10, in which the first linear layer and the second linear layer are inserted after the layer of the neural network.

[0133] Example 12 provides the one or more non-transitory computer-readable media of example 11, in which the first linear layer is arranged between the layer of the neural network and the second linear layer.

[0134] Example 13 provides the one or more non-transitory computer-readable media of any one of examples 10-12, in which a dimension of the weight tensor of the first linear layer equals a dimension of a weight tensor of the second linear layer.

[0135] Example 14 provides the one or more non-transitory computer-readable media of example 13, in which the dimension of the weight tensor of the second linear layer is smaller than another dimension of the weight tensor of the second linear layer.

[0136] Example 15 provides the one or more non-transitory computer-readable media of any one of examples 10-14, in which merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network includes performing a multiplication operation on the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network to produce a new weight tensor.

[0137] Example 16 provides the one or more non-transitory computer-readable media of any one of examples 10-15, in which a dimension of the weight tensor of the first linear layer is smaller than a dimension of the pretrained weight tensor of the layer of the neural network.

[0138] Example 17 provides the one or more non-transitory computer-readable media of example 16, in which another dimension of the weight tensor of the first linear layer equals another dimension of the pretrained weight tensor of the layer of the neural network.

[0139] Example 18 provides the one or more non-transitory computer-readable media of any one of examples 10-17, further including inserting an additional linear layer into the neural network by placing the additional linear layer after an additional layer of the neural network; and modifying one or more values of a weight tensor of the additional linear layer while maintaining values of a pretrained weight tensor of the additional layer, in which generating the new neural network is by merging the additional linear layer and the additional layer.

[0140] Example 19 provides an apparatus, including a computer processor for executing computer program instructions; and a non-transitory computer-readable memory storing computer program instructions executable by the computer processor to perform operations for fine-tuning a neural network, the operations including inserting a first linear layer and a second linear layer into the neural network for a layer of the neural network, the layer of the neural network having a pretrained weight tensor, training a weight tensor of the first linear layer and a weight tensor of the second linear layer based on a difference between a reference value of a fine-tuning sample and a prediction made by the neural network with the first linear layer and the second linear layer using the fine-tuning sample, after training the weight tensor of the first linear layer and the weight tensor of the second linear layer, forming a new layer by merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network, and generating a new neural network with the new layer and the second linear layer.

[0141] Example 20 provides the apparatus of example 19, in which the first linear layer and the second linear layer are inserted after the layer of the neural network, in which the first linear layer is arranged between the layer of the neural network and the second linear layer.

[0142] Example 21 provides the apparatus of example 19 or 20, in which a dimension of the weight tensor of the first linear layer equals a dimension of a weight tensor of the second linear layer.

[0143] Example 22 provides the apparatus of example 21, in which the dimension of the weight tensor of the second linear layer is smaller than another dimension of the weight tensor of the second linear layer.

[0144] Example 23 provides the apparatus of any one of examples 19-22, in which merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network includes performing a multiplication operation on the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network to produce a new weight tensor.

[0145] Example 24 provides the apparatus of any one of examples 19-23, in which a dimension of the weight tensor of the first linear layer is smaller than a dimension of the pretrained weight tensor of the layer of the neural network, in which another dimension of the weight tensor of the first linear layer equals another dimension of the pretrained weight tensor of the layer of the neural network.

[0146] Example 25 provides the apparatus of any one of examples 19-24, in which the operations further includes inserting an additional linear layer into the neural network by placing the additional linear layer after an additional layer of the neural network; and modifying one or more values of a weight tensor of the additional linear layer while maintaining values of a pretrained weight tensor of the additional layer, in which generating the new neural network is by merging the additional linear layer and the additional layer.

[0147] The above description of illustrated implementations of the disclosure, including what is described in the Abstract, is not intended to be exhaustive or to limit the disclosure to the precise forms disclosed. While specific implementations of, and examples for, the disclosure are described herein for illustrative purposes, various equivalent modifications are possible within the scope of the disclosure, as those skilled in the relevant art can recognize. These modifications may be made to the disclosure in light of the above detailed description.

Claims

1.A method of fine-tuning a neural network, comprising:inserting a first linear layer and a second linear layer into the neural network for a layer of the neural network, the layer of the neural network having a pretrained weight tensor;training a weight tensor of the first linear layer and a weight tensor of the second linear layer based on a difference between a reference value of a fine-tuning sample and a prediction made by the neural network with the first linear layer and the second linear layer using the fine-tuning sample;after training the weight tensor of the first linear layer and the weight tensor of the second linear layer, forming a new layer by merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network; andgenerating a new neural network with the new layer and the second linear layer.2.The method of claim 1, wherein the first linear layer and the second linear layer are inserted after the layer of the neural network.3.The method of claim 2, wherein the first linear layer is arranged between the layer of the neural network and the second linear layer.4.The method of any one of claims 1-3, wherein a dimension of the weight tensor of the first linear layer equals a dimension of a weight tensor of the second linear layer.5.The method of claim 4, wherein the dimension of the weight tensor of the second linear layer is smaller than another dimension of the weight tensor of the second linear layer.6.The method of any one of claims 1-5, wherein merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network comprises:performing a multiplication operation on the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network to produce a new weight tensor.7.The method of any one of claims 1-6, wherein a dimension of the weight tensor of the first linear layer is smaller than a dimension of the pretrained weight tensor of the layer of the neural network.8.The method of claim 7, wherein another dimension of the weight tensor of the first linear layer equals another dimension of the pretrained weight tensor of the layer of the neural network.9.The method of any one of claims 1-8, further comprising:inserting an additional linear layer into the neural network by placing the additional linear layer after an additional layer of the neural network; andmodifying one or more values of a weight tensor of the additional linear layer while maintaining values of a pretrained weight tensor of the additional layer,wherein generating the new neural network is by merging the additional linear layer and the additional layer.10.One or more non-transitory computer-readable media storing instructions executable to perform operations for fine-tuning a neural network, the operations comprising:inserting a first linear layer and a second linear layer into the neural network for a layer of the neural network, the layer of the neural network having a pretrained weight tensor;training a weight tensor of the first linear layer and a weight tensor of the second linear layer based on a difference between a reference value of a fine-tuning sample and a prediction made by the neural network with the first linear layer and the second linear layer using the fine-tuning sample;after training the weight tensor of the first linear layer and the weight tensor of the second linear layer, forming a new layer by merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network; andgenerating a new neural network with the new layer and the second linear layer.11.The one or more non-transitory computer-readable media of claim 10, wherein the first linear layer and the second linear layer are inserted after the layer of the neural network.12.The one or more non-transitory computer-readable media of claim 11, wherein the first linear layer is arranged between the layer of the neural network and the second linear layer.13.The one or more non-transitory computer-readable media of any one of claims 10-12, wherein a dimension of the weight tensor of the first linear layer equals a dimension of a weight tensor of the second linear layer.14.The one or more non-transitory computer-readable media of claim 13, wherein the dimension of the weight tensor of the second linear layer is smaller than another dimension of the weight tensor of the second linear layer.15.The one or more non-transitory computer-readable media of any one of claims 10-14, wherein merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network comprises:performing a multiplication operation on the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network to produce a new weight tensor.16.The one or more non-transitory computer-readable media of any one of claims 10-15, wherein a dimension of the weight tensor of the first linear layer is smaller than a dimension of the pretrained weight tensor of the layer of the neural network.17.The one or more non-transitory computer-readable media of claim 16, wherein another dimension of the weight tensor of the first linear layer equals another dimension of the pretrained weight tensor of the layer of the neural network.18.The one or more non-transitory computer-readable media of any one of claims 10-17, further comprising:inserting an additional linear layer into the neural network by placing the additional linear layer after an additional layer of the neural network; andmodifying one or more values of a weight tensor of the additional linear layer while maintaining values of a pretrained weight tensor of the additional layer,wherein generating the new neural network is by merging the additional linear layer and the additional layer.19.An apparatus, comprising:a computer processor for executing computer program instructions; anda non-transitory computer-readable memory storing computer program instructions executable by the computer processor to perform operations for fine-tuning a neural network, the operations comprising:inserting a first linear layer and a second linear layer into the neural network for a layer of the neural network, the layer of the neural network having a pretrained weight tensor,training a weight tensor of the first linear layer and a weight tensor of the second linear layer based on a difference between a reference value of a fine-tuning sample and a prediction made by the neural network with the first linear layer and the second linear layer using the fine-tuning sample,after training the weight tensor of the first linear layer and the weight tensor of the second linear layer, forming a new layer by merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network, andgenerating a new neural network with the new layer and the second linear layer.20.The apparatus of claim 19, wherein the first linear layer and the second linear layer are inserted after the layer of the neural network, wherein the first linear layer is arranged between the layer of the neural network and the second linear layer.21.The apparatus of claim 19 or 20, wherein a dimension of the weight tensor of the first linear layer equals a dimension of a weight tensor of the second linear layer.22.The apparatus of claim 21, wherein the dimension of the weight tensor of the second linear layer is smaller than another dimension of the weight tensor of the second linear layer.23.The apparatus of any one of claims 19-22, wherein merging the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network comprises:performing a multiplication operation on the trained weight tensor of the first linear layer and the pretrained weight tensor of the layer of the neural network to produce a new weight tensor.24.The apparatus of any one of claims 19-23, wherein a dimension of the weight tensor of the first linear layer is smaller than a dimension of the pretrained weight tensor of the layer of the neural network, wherein another dimension of the weight tensor of the first linear layer equals another dimension of the pretrained weight tensor of the layer of the neural network.25.The apparatus of any one of claims 19-24, wherein the operations further comprises:inserting an additional linear layer into the neural network by placing the additional linear layer after an additional layer of the neural network; andmodifying one or more values of a weight tensor of the additional linear layer while maintaining values of a pretrained weight tensor of the additional layer,wherein generating the new neural network is by merging the additional linear layer and the additional layer.