Sliding-window quantization of pretrained large language model
Sliding-window quantization techniques for LLMs address the challenges of storage and compute costs by minimizing accuracy loss, enabling efficient deployment in resource-constrained environments.
Patent Information
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- INTEL CORP
- Filing Date
- 2025-06-24
- Publication Date
- 2026-07-23
AI Technical Summary
Large language models (LLMs) suffer from significant storage and compute costs due to their gigantic parameter sizes, and existing post-training quantization techniques result in noticeable model accuracy loss, especially at low bit-widths, limiting their deployment in resource-constrained scenarios.
Implement sliding-window quantization techniques that partition DNN layers into overlapping windows and progressively quantize them, leveraging inter-layer and intra-layer parameter dependencies to minimize accuracy loss.
The proposed method significantly reduces accuracy loss and enhances efficiency, enabling the deployment of LLMs in resource-constrained scenarios by effectively compressing and accelerating them.
Smart Images

Figure CN2025102900_23072026_PF_FP_ABST
Abstract
Description
SLIDING-WINDOW QUANTIZATION OF PRETRAINED LARGE LANGUAGE MODELCross-Reference to Related Application
[0001] This application claims the benefit of International Application No. PCT / CN2025 / 073235, filed January 20, 2025, and titled “POST-TRAINING QUANTIZATION FOR COMPRESSING AND ACCELERATING 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, sliding-window quantization of pretrained DNNs, such as pretrained large language models (LLMs) .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 layer-wise quantization, in accordance with various embodiments.
[0007] FIG. 3 illustrates sliding-window quantization, in accordance with various embodiments.
[0008] FIG. 4 illustrates dual sliding-window quantization, 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 compressing 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 (IFM) ” 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 (a2D weight tensor) , a filter (a3D weight tensor) , or a group of filters (a4D 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. 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] Large Language Models (LLMs) , including transformer-based neural networks like GPT (Generative Pretrained Transformer) and BERT (Bidirectional Encoder Representations from Transformers) , are used for language processing in various applications, from virtual assistants, document summarization, to coding assistants, language translation and speech recognition apps. Despite the remarkable capabilities of LLMs, their gigantic parameter sizes lead to significant storage and compute costs. Consequently, how to efficiently deploy modern LLMs in real-world scenarios, especially resource-constrained scenarios, becomes a great challenge. Recently, post-training quantization has emerged as an efficient and promising way to reduce the heavy storage and compute costs for pretrained LLMs. However, they still suffer from noticeable model accuracy loss, especially when the bit-with goes down, e.g., 4 / 3 / 2-bit weight quantization, limiting their adoptions in real usages.
[0020] Embodiments of the present disclosure may improve on at least some of the challenges and issues described above by providing sliding-window quantization techniques for compressing and accelerating DNNs, such as LLMs. In an example, a sliding window is introduced to sequentially partition layers of a pretrained DNN into overlapping windows, then progressively perform quantization window-by-window instead of layer-by-layer, exploiting inter-layer parameter dependency in a neat and efficient way. This mechanism is referred to as inter-layer sliding-window quantization. Additionally or alternatively, an inflated sliding quantization may be applied at each layer in an incremental way to further exploit the intra-layer parameter dependency for enhancing the quantization process. This mechanism is referred to as intra-layer sliding-window quantization. Coupling these two mechanisms together can form an efficient dual implementation of sliding-window quantization, which can achieve significantly superior performance to currently available techniques for DNN quantization.
[0021] In various embodiments of the present disclosure, a pretrained DNN may be quantized using a sliding-window quantization mechanism. The sliding-window quantization mechanism may include an inter-layer sliding-window quantization mechanism or inter-layer sliding-window quantization mechanism. A combination of both mechanisms may be referred to as dual sliding-window quantization. A quantization window (also referred to as “window” or “inter-layer window” ) , which can slide through the DNN, may be used for inter-layer sliding-window quantization. The window may enclose up to l layers at a time, where l is an integer greater than 1. l may be referred to as the window size. Sliding the window through the DNN may initiate a plurality of quantization iterations. At each position of the window, weight tensors of the l layers over the window are quantized. The quantized weights of the l layers may be optimized based on a loss. The loss may indicate an error in the output of the l layers due to the quantization. The output of the l layers may be the output of the last layer of the l layers. The loss may be measured based on an input to the first layer, the weight tensors before quantization, and the weight tensors after quantization. The window may have a step size, which indicates the number of layers that the window moves down from one position to the next position.
[0022] In embodiments where intra-layer sliding-window quantization is applied, another quantization window (also referred to as “window” or “intra-layer window” ) may be used to slide over a weight tensor of each layer within the l layers over the window. The part of the weight tensor enclosed in the intra-layer window may be quantized, while the rest of the weight tensor may remain the same and be preserved in the higher-precision format. Then the l layers may be optimized together. After that, another part of the weight tensor of each layer may be quantized as the intra-layer window slides to the other part of the weight tensor. The window used for inter-layer sliding-window quantization or intra-layer sliding-window quantization may also be referred to as a quantization window. After all the quantization and optimization are done, a compressed DNN is generated. The compressed DNN may be executed to perform AI tasks, such as language processing, speech recognition, computer vision, and so on.
[0023] The approach in this disclosure uses sliding-window mechanisms to compensate for accuracy loss from the quantization process. These mechanisms are completely new and different from the currently available techniques for DNN quantitation. With these novel and compelling techniques, the accuracy loss of compressing and accelerating pretrained LLMs under extremely low bit-width settings can be significantly reduced, paving the way for a broad range of usages. Compared to currently mainstream post-training quantization solutions, the approach in this disclosure can achieve significantly superior performance.
[0024] 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.
[0025] 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.
[0026] 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.
[0027] For the purposes of the present disclosure, the phrase “A or B” or the phrase "Aand / 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.
[0028] 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.
[0029] 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.
[0030] 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.
[0031] 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. ”
[0032] 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.
[0033] 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 compressing 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.
[0034] 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.
[0035] 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 validation subset used by the training module 120 to validate performance of a trained DNN or as a fine-tuning subset used by the training module 120 to fine-tune a trained DNN. The portion of the training dataset not including the validation subset and the fine-tuning subset may be used to train the DNN.
[0036] 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.
[0037] 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.
[0038] 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) .
[0039] 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.
[0040] 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 xT 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.
[0041] 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.
[0042] 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.
[0043] 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.
[0044] The compressing module 130 compresses DNNs. For instance, the compressing module 130 may modify internal parameters of DNN layers (e.g., weights) to reduce computational complexity or memory usage. The modification may be done before, during, or after training. In some embodiments, the compressing module 130 may modify weight by quantizing weights. For example, the compressing module 130 may convert weights of a floating-point format to values of a fixed-point format (e.g., an integer format) . Quantized weights may have a lower precision than the original weights. Quantization can reduce computation resources required to execute the DNN layer, such as memory usage, memory bandwidth, number of compute units, and so on. In an example, the compressing module 130 may use a quantization function to quantize DNN layer. The quantization function may be denoted as y= (x-Z) ×S, where x denotes the original data element, y denotes the quantized data element, Z denotes a zero point, and S denotes a scale (also referred to as “scale factor” ) . In some embodiments, the compressing module 130 may use the same quantization parameters (e.g., scale or zero point) for multiple layers. In other embodiments, the compressing module 130 may use different quantization parameters for different layers. In yet other embodiments, the compressing module 130 may use different quantization parameters for different portions of the weight tensor of a layer. For instance, the compressing module 130 may partition the weight tensor into subtensor or blocks and may quantize the subtensors or blocks with different quantization parameters. The compressing module 130 may quantize the weight tensor into blocks with different data formats.
[0045] In some embodiments, the compressing module 130 performs sliding-window quantization of DNN layers. The compressing module 130 may define a window for a DNN and use the window to perform inter-layer sliding-window quantization. In some embodiments, the compressing module 130 may determine a window size l, which indicates the total number of layers falling into the window. The window may slide over the DNN to facilitate a plurality of quantization iterations. The position of the window over the DNN changes for each quantization iteration. The compressing module 130 may also determine a step size that indicates the number of layers the window moves down (or moves to the right) for every new quantization iteration. In an example, the step size is 1, meaning the window moves down by one layer. In another example, the step size is 2, meaning the window moves down by two layers. The window size l may be a multiple of the step size.
[0046] The compressing module 130 may determine the window size or step size based on one or more specifications of the DNN, one or more specifications of the hardware device executing the DNN, one or more requirements of the AI task on the DNN, other factors, or some combination thereof. Specifications of the DNN may include the total number of layers in the DNN, the number of computation-heavy layers in the DNN, the size of the DNN (e.g., the number or amount of internal parameters) , the size of a DNN layer, and so on. Specifications of the hardware device may include data format (s) supported by the hardware device (e.g., data formats supported by memories, multipliers, adders, or other types of components of the hardware device) , the number of available compute units in the hardware device, the amount of available data storage space in the hardware device, and so on.The hardware device may be a component of the AI system 100. Requirements of the AI task on the DNN may include requirements on the DNN accuracy, requirements on the execution efficiency, requirements on power consumption, requirements on time consumption, and so on. In some embodiments, the compressing module 130 may confine the window size l to a predetermined range. An exemplary predetermined range is a range from 2 to 8.
[0047] In each quantization iteration, the compressing module 130 may quantize the layers within the window as a group. For instance, the compressing module 130 may apply the same or different quantization functions on the layers in the same group. After the quantization, the compressing module 130 may optimize the quantized weights of the layers using a single optimization process, in which the compressing module 130 may provide an input to the first layer in the group and obtain the output of the last layer in the group. The compressing module 130 may use an optimization function to measure a loss of the output of the last layer in the group due to the quantization and update the quantized weights in the group to minimize the loss. That way, the optimization can leverage the dependency among the layers within the group and can suppress the accumulation of quantization errors over layers.
[0048] The compressing module 130 may also perform intra-layer sliding-window quantization in addition or alternative to the inter-layer sliding-window quantization. The compressing module 130 may define a window that slides over a weight tensor of a layer to facilitate a plurality of iterations. For each iteration, the weights within the window are quantized, while the other weights of the layer may remain the same. The compressing module 130 may perform sliding-window quantization that incorporate both intra-layer sliding-window quantization and inter-layer sliding-window quantization. Certain aspects regarding sliding-window quantization are described below in conjunction with FIG. 3 and FIG. 4.
[0049] 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.
[0050] 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 compressed. Additionally or alternatively, the compiler 140 may compile a DNN after the CNN is compressed. The compiler 140 may perform different complications before and after training or compression. For instance, the compiler 140 may compile the DNN before training or compression based on the condition that internal parameters of the DNN are to be changed during the training or compression process. The compiler 140 may compile the DNN after training or compression 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.
[0051] 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.
[0052] 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, compressing module 130, and compiler 140. The datastore 160 may also store data generated by the training module 120, such as the hyperparameters for training DNNs, internal parameters of trained DNNs (e.g., weights, etc. ) , and so on. The datastore 160 may also store compressed data (e.g., quantized data) generated by the compressing module 130. 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.
[0053] FIG. 2 illustrates layer-wise quantization, in accordance with various embodiments. For the purpose of illustration, FIG. 2 shows six layers 210, 220, 230, 240, 250, and 260 of a DNN. The DNN may be a transformer-based model, such as an LLM. The DNN may include additional layers that are not shown in FIG. 2. The DNN may have been trained before the quantization.
[0054] In the embodiments of FIG. 2, the quantization is performed layer-by-layer separately. This assumes that layers of the pretrained DNN have no dependency to each other. In some embodiments, the layers 210, 220, 230, 240, 250, and 260 are quantized separately. For instance, a layer-particular quantization function may be applied on each layer to reduce data precisions of the weights of the layer. After the layer is quantized, the weights may be optimized using an optimization function. In some embodiments, the optimization function is denoted as where X is the input to the layer, W is the weight tensor before quantization, and is the weight tensor after quantization (e.g., the quantized weight tensor) . The optimization function may be used to update values of the quantized weights to minimize the loss caused by the quantization. The loss may be measured by a difference between the output of the layer itself before quantization (e.g., WX) and the output of the layer itself after quantization (e.g., ) . The optimization may also be performed layer-by-layer separately.
[0055] The layer-wise quantization framework fails to consider dependency between layers. It assumes that the layers have no dependency to each other. As this framework ignores parameter dependencies, it lacks the ability to suppress the accumulation of quantization errors over layers. Errors caused by the layer-wise quantization can be unrecoverable. Also, errors can be accumulated from shallow layers to deep layers. Errors can be significantly magnified when the bit width goes down. These drawbacks make layer-wise quantization methods suffer from noticeable model accuracy loss, especially when the bit-with goes down, such as 4 / 3 / 2-bit weight quantization, limiting their adoptions in real usages.
[0056] FIG. 3 illustrates sliding-window quantization, in accordance with various embodiments. A window 300 is used to quantize the DNN. For the purpose of illustration, FIG. 3 shows six layers 310, 320, 330, 340, 350, and 360 of a DNN. Each of these layers is represented by a 8×8 weight tensor, i.e., a tensor having 64 weights arranged in 8 columns and 8 rows. In other embodiments, a layer may have a weight tensor with a different spatial shape or size. The DNN may be a transformer-based model, such as an LLM. The DNN may include additional layers that are not shown in FIG. 2. The DNN may have been trained before the quantization.
[0057] The window 300 may be defined by the compressing module 130 in FIG. 1. The window 300 has a size l=4. The window 300 slides over the DNN, triggering a sequence of quantization iterations. For the purpose of illustration, FIG. 3 shows a position 301 and a position 302 of the window 300. At the position 301, the window 300 encloses the layer 310, layer 320, layer 330, and layer 340. An iteration of quantization may be performed on these four layers. For instance, the compressing module 130 may quantize the weights of the four layers. In some embodiments, the compressing module 130 may use the same quantization parameters (e.g., scale, zero points, etc. ) to quantize all the four layers. In other embodiments, the compressing module 130 may use different quantization parameters for different layers. At the position 302, the window 300 encloses the layer 330, layer 340, layer 350, and layer 360. In this example, the step size of the window 300 is 2, and the window 300 slides two layers down from the position 301 to the position 302. Another iteration of quantization may be performed on the layer 330, layer 340, layer 350, and layer 360.
[0058] For each iteration, the weight tensors of the l layers before quantization may be denoted as {W1…Wl} . The weight tensors of the l layers after quantization ( “quantized weight tensors” ) may be denoted as In an example, the weights before quantization may have a floating-point format, such as FP16, BF16, FP32, and so on. The quantized weights may have an integer format, such as INT4, INT8, and so on. After the quantization, the compressing module 130 may optimize the quantized weights of the layer 310, layer 320, layer 330, and layer 340 together. For instance, the compressing module 130 may apply an optimization function on the layer 310, layer 320, layer 330, and layer 340. The optimization function may be where X is the input to the layer 310. The optimization function may also include one or more functional operations, such as layer normalization, addition, or other types of functional operations included in or associated with layer 310, layer 320, layer 330, and layer 340. The optimization function may be used to minimize the difference between an output of the layer 340 before quantization and an output of the layer 340 after quantization by modifying values of one or more quantized weights. The optimized weights may have the same data format as the quantized weights.
[0059] The window 300 can sequentially partitions all layers of the DNN into overlapping windows, then progressively performs quantization window-by-window instead of layer-by-layer, exploiting inter-layer parameter dependency in a neat and efficient way. The sliding-window quantization shown in FIG. 3 is inter-layer sliding-window quantization, which can leverage parameter dependencies across successive layers. The inter-layer sliding-window quantization framework is flexible can adopt various quantization techniques for quantizing DNN layers within the inter-layer sliding-window quantization framework.
[0060] FIG. 4 illustrates dual sliding-window quantization, in accordance with various embodiments. The dual sliding-window quantization in FIG. 4 includes both inter-layer sliding-window quantization and intra-layer sliding-window quantization.
[0061] The inter-layer sliding-window quantization in FIG. 4 may be the same as or similar to the sliding-window quantization shown in FIG. 3. For the purpose of illustration, a window 400 is used. The window 400 has a size l=4. The window 400 slides over the DNN, triggering a sequence of quantization iterations. For the purpose of illustration, FIG. 4 shows a position 401 and a position 402 of the window 400. At the position 401, the window 400 encloses the layer 410, layer 420, layer 430, and layer 440. At the position 402, the window 400 encloses the layer 430, layer 440, layer 450, and layer 460. In this example, the step size of the window 400 is 2, and the window 400 slides two layers down from the position 401 to the position 402.
[0062] For the intra-layer sliding-window quantization, an inter-layer window is applied on the weight tensor of each layer in the window 400. The inter-layer window may slide over the weight tensor. For each iteration in the intra-layer sliding-window quantization, a part of the weight tensor that overlaps with the inter-layer window is quantized and the rest of the weight tensor may remain the same and be preserved in the higher-precision format. This way, quantization can be performed in an incremental way for each layer in the window 400. For the purpose of illustration, FIG. 4 shows an example in which the size of the inter-layer window shown in FIG. 4 is 8×4, which is half of the size of the weight tensor. In this example, the intra-layer sliding-window quantization includes two stages for each iteration within the inter-layer sliding-window quantization. In the first stage, half of the weight tensor (represented by boxes with a dotted pattern in FIG. 4) is quantized. This can leave sufficient room to the remaining full-precision parameters in the current sliding window to adapt to the quantization process, suppressing quantization error. In the second stage, the entire weight tensor of each layer in the window 400 are quantized.
[0063] In some embodiments, the intra-layer sliding-window quantization is performed on each layer for each position of the window 400. For instance, at the position 401, half of the weight tensor of each of the layer 410, layer 420, layer 430, and layer 440 is quantized. Then an optimization function (e.g., the optimization function described above in conjunction with FIG. 3) is applied on the layer 410, layer 420, layer 430, and layer 440. Next, the entire weight tensor of each of the layer 410, layer 420, layer 430, and layer 440 is quantized. And the optimization function is applied on the layer 410, layer 420, layer 430, and layer 440 again, which may conclude the first iteration of the inter-layer sliding-window quantization. At the position 402, half of the weight tensor of each of the layer 430, layer 440, layer 450, and layer 460 is quantized. Then an optimization function (e.g., the optimization function described above in conjunction with FIG. 3) is applied on the layer 430, layer 440, layer 450, and layer 460. Next, the entire weight tensor of each of the layer 430, layer 440, layer 450, and layer 460 is quantized. And the optimization function is applied on the layer 430, layer 440, layer 450, and layer 460 again, which may conclude the second iteration of the inter-layer sliding-window quantization
[0064] The dual sliding-window quantization framework is flexible and can adopt various quantization techniques for quantizing DNN layers within the dual sliding-window quantization framework. The dual quantization mechanism shown can leverage parameter dependencies both across successive layers and within a single layer to compensate for accuracy loss from the quantization process. The accumulation of quantization errors over the layers can be suppressed. Compared with layer-wise quantization, sliding-window quantization can significantly reduce accuracy loss of compressing and accelerating pretrained DNNs, even under extremely low bit-width settings, paving the way for a broad range of usages.
[0065] Even though weight quantization is described above in conjunction with FIG. 3 and FIG. 4, the sliding-window quantization mechanism (s) may also be used for activation quantization. In some embodiments, activations may be quantified first separately using the sliding-window quantization mechanism (s) . Then the weights may be quantized based on the quantized activations.
[0066] 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.
[0067] 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.
[0068] 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.
[0069] 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 encoder-decoder attention layer 553, another add &norm layer 554, a feed forward layer 555, and another add &norm layer 556.
[0070] 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.
[0071] 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.
[0072] 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.
[0073] 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.
[0074] 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.
[0075] 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.
[0076] 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.
[0077] 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.
[0078] 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.
[0079] 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.
[0080] 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.
[0081] 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 Mxy 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 The layer normalization operation may further compute and LNxyz=A″xyz×γz. LNxyz may be the output of the layer normalization operation.
[0082] 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) .
[0083] 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.
[0084] 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.
[0085] The parameter matrix 604 may be denoted as QWiQ, where Q is the query matrix 601 and is the weight matrix. The parameter matrix 605 may be denoted as KWiK, where K is the key matrix 601 and is the weight matrix. The parameter matrix 607 may be denoted as VWiV, where V is the value matrix 601 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.
[0086] 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 headi=Attention (QWiQ, KWiK, VWiV) .
[0087] 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 score matrix 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.
[0088] 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.
[0089] 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.
[0090] 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 linear 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.
[0091] 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.
[0092] 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.
[0093] 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.
[0094] 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, SLinpit 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.
[0095] 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 dhea 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] .
[0096] 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.
[0097] 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.
[0098] 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.
[0099] 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 807may 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.
[0100] 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.
[0101] 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.
[0102] 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.
[0103] 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.
[0104] 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) th inference 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.
[0105] FIG. 10 is a flowchart of a method 1000 of compressing a DNN, in accordance with various embodiments. The method 1000 may be performed by the compressing module 130 in FIG. 1. Although the method 1000 is described with reference to the flowchart illustrated in FIG. 10, many other methods for compressing 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.
[0106] The compressing module 130 generates 1010 an inter-layer window. The inter-layer window has a size indicating a predetermined number of neural network layers to be included in the inter-layer window. In some embodiments, the predetermined number is in a range from two to eight. In some embodiments, the compressing module 130 also determines a step size of the inter-layer window. The step size indicates a number of layers the window moves from a position to a next position.
[0107] The compressing module 130 initiates 1020 a plurality of quantization iterations by sliding the inter-layer window over the neural network. The inter-layer window encloses the predetermined number of neural network layers for each of the plurality of quantization iterations. In some embodiments, a layer of the neural network is enclosed in the window for two iterations of the plurality of quantization iterations.
[0108] The compressing module 130 performs 1030 the plurality of quantization iterations. The compressing module 130 performs a quantization iteration by quantizing weight tensors of the predetermined number of neural network layers and modifying one or more values of the quantized weight tensors based on a loss in an output of a last layer of the predetermined number of neural network layers. In some embodiments, the compressing module 130 quantizes a first part of each of the weight tensors. The compressing module 130 maintains a second part of each of the weight tensors. The one or more values are in the first part.
[0109] In some embodiments, the compressing module 130 quantizes the second part of each of the weight tensors after modifying the one or more values. The compressing module 130 modifies one or more values in the second part based on another loss in another output of the last layer. In some embodiments, the compressing module 130 generates an intra-layer window, the intra-layer window sliding over each of the weight tensors. The intra-layer window is over the first part before the intra-layer window is over the second part.
[0110] In some embodiments, the compressing module 130 determines a first output of the last layer based on the weight tensors and an input to a first layer of the predetermined number of layers of the neural network. The compressing module 130 also determines a second output of the last layer based on the quantized weight tensors and the input to the first layer. The compressing module 130 determines a loss based on the first output and the second output. The one or more values are modified to minimize the loss.
[0111] The compressing module 130 generates 1040 a compressed neural network with the quantized weight tensors having the one or more modified values. In some embodiments, the neural network comprises a transformer model.
[0112] 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.
[0113] 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 compressing module 130) . The instructions stored in the one or more non-transitory computer-readable media may be executed by the processing device 1102.
[0114] 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.
[0115] 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) .
[0116] 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.
[0117] 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) .
[0118] 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.
[0119] 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.
[0120] 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) .
[0121] 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.
[0122] 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.
[0123] 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.
[0124] 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.
[0125] The following paragraphs provide various examples of the embodiments disclosed herein.
[0126] Example 1 provides a method of compressing a neural network, including generating an inter-layer window, the inter-layer window having a size indicating a predetermined number of neural network layers to be included in the inter-layer window; initiating a plurality of quantization iterations by sliding the inter-layer window over the neural network, the inter-layer window enclosing the predetermined number of neural network layers for each of the plurality of quantization iterations; performing the plurality of quantization iterations, in which performing a quantization iteration includes quantizing weight tensors of the predetermined number of neural network layers, and modifying one or more values of the quantized weight tensors based on a loss in an output of a last layer of the predetermined number of neural network layers; and generating a compressed neural network with the quantized weight tensors having the one or more modified values.
[0127] Example 2 provides the method of example 1, in which the predetermined number is in a range from two to eight.
[0128] Example 3 provides the method of example 1 or 2, further including determining a step size of the inter-layer window, the step size indicating a number of layers the window moves from a position to a next position.
[0129] Example 4 provides the method of any one of examples 1-3, in which a layer of the neural network is enclosed in the window for two iterations of the plurality of quantization iterations.
[0130] Example 5 provides the method of any one of examples 1-4, in which quantizing the weight tensors of the predetermined number of neural network layers includes quantizing a first part of each of the weight tensors; and maintaining a second part of each of the weight tensors, in which the one or more values are in the first part.
[0131] Example 6 provides the method of example 5, in which performing the quantization iteration further includes after modifying the one or more values, quantizing the second part of each of the weight tensors; and modifying one or more values in the second part based on another loss in another output of the last layer.
[0132] Example 7 provides the method of example 5 or 6, in which performing the quantization iteration further includes generating an intra-layer window, the intra-layer window sliding over each of the weight tensors, in which the intra-layer window is over the first part before the intra-layer window is over the second part.
[0133] Example 8 provides the method of any one of examples 1-7, in which performing the quantization iteration further includes determining a first output of the last layer based on the weight tensors and an input to a first layer of the predetermined number of neural network layers; determining a second output of the last layer based on the quantized weight tensors and the input to the first layer; and determining a loss based on the first output and the second output, in which the one or more values are modified to minimize the loss.
[0134] Example 9 provides the method of any one of examples 1-8, in which the neural network includes a transformer model.
[0135] Example 10 provides one or more non-transitory computer-readable media storing instructions executable to perform operations for compressing a neural network, the operations including generating an inter-layer window, the inter-layer window having a size indicating a predetermined number of neural network layers to be included in the inter-layer window; initiating a plurality of quantization iterations by sliding the inter-layer window over the neural network, the inter-layer window enclosing the predetermined number of neural network layers for each of the plurality of quantization iterations; performing the plurality of quantization iterations, in which performing a quantization iteration includes quantizing weight tensors of the predetermined number of neural network layers, and modifying one or more values of the quantized weight tensors based on a loss in an output of a last layer of the predetermined number of neural network layers; and generating a compressed neural network with the quantized weight tensors having the one or more modified values.
[0136] Example 11 provides the one or more non-transitory computer-readable media of example 10, in which the predetermined number is in a range from two to eight.
[0137] Example 12 provides the one or more non-transitory computer-readable media of example 10 or 11, further including determining a step size of the inter-layer window, the step size indicating a number of layers the window moves from a position to a next position.
[0138] Example 13 provides the one or more non-transitory computer-readable media of any one of examples 10-12, in which a layer of the neural network is enclosed in the window for two iterations of the plurality of quantization iterations.
[0139] Example 14 provides the one or more non-transitory computer-readable media of any one of examples 10-13, in which quantizing the weight tensors of the predetermined number of neural network layers includes quantizing a first part of each of the weight tensors; and maintaining a second part of each of the weight tensors, in which the one or more values are in the first part.
[0140] Example 15 provides the one or more non-transitory computer-readable media of example 14, in which performing the quantization iteration further includes after modifying the one or more values, quantizing the second part of each of the weight tensors; and modifying one or more values in the second part based on another loss in another output of the last layer.
[0141] Example 16 provides the one or more non-transitory computer-readable media of example 14 or 15, in which performing the quantization iteration further includes generating an intra-layer window, the intra-layer window sliding over each of the weight tensors, in which the intra-layer window is over the first part before the intra-layer window is over the second part.
[0142] Example 17 provides the one or more non-transitory computer-readable media of any one of examples 10-16, in which performing the quantization iteration further includes determining a first output of the last layer based on the weight tensors and an input to a first layer of the predetermined number of neural network layers; determining a second output of the last layer based on the quantized weight tensors and the input to the first layer; and determining a loss based on the first output and the second output, in which the one or more values are modified to minimize the loss.
[0143] Example 18 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 compressing a neural network, the operations including generating an inter-layer window, the inter-layer window having a size indicating a predetermined number of neural network layers to be included in the inter-layer window, initiating a plurality of quantization iterations by sliding the inter-layer window over the neural network, the inter-layer window enclosing the predetermined number of neural network layers for each of the plurality of quantization iterations, performing the plurality of quantization iterations, in which performing a quantization iteration includes quantizing weight tensors of the predetermined number of neural network layers, and modifying one or more values of the quantized weight tensors based on a loss in an output of a last layer of the predetermined number of neural network layers, and generating a compressed neural network with the quantized weight tensors having the one or more modified values.
[0144] Example 19 provides the apparatus of example 18, in which the predetermined number is in a range from two to eight.
[0145] Example 20 provides the apparatus of example 18 or 19, further including determining a step size of the inter-layer window, the step size indicating a number of layers the window moves from a position to a next position.
[0146] Example 21 provides the apparatus of any one of examples 18-20, in which a layer of the neural network is enclosed in the window for two iterations of the plurality of quantization iterations.
[0147] Example 22 provides the apparatus of any one of examples 18-21, in which quantizing the weight tensors of the predetermined number of neural network layers includes quantizing a first part of each of the weight tensors; and maintaining a second part of each of the weight tensors, in which the one or more values are in the first part.
[0148] Example 23 provides the apparatus of example 22, in which performing the quantization iteration further includes after modifying the one or more values, quantizing the second part of each of the weight tensors; and modifying one or more values in the second part based on another loss in another output of the last layer.
[0149] Example 24 provides the apparatus of example 22 or 23, in which performing the quantization iteration further includes generating an intra-layer window, the intra-layer window sliding over each of the weight tensors, in which the intra-layer window is over the first part before the intra-layer window is over the second part.
[0150] Example 25 provides the apparatus of any one of examples 18-24, in which performing the quantization iteration further includes determining a first output of the last layer based on the weight tensors and an input to a first layer of the predetermined number of neural network layers; determining a second output of the last layer based on the quantized weight tensors and the input to the first layer; and determining a loss based on the first output and the second output, in which the one or more values are modified to minimize the loss.
[0151] 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 compressing a neural network, comprising:generating an inter-layer window, the inter-layer window having a size indicating a predetermined number of neural network layers to be included in the inter-layer window;initiating a plurality of quantization iterations by sliding the inter-layer window over the neural network, the inter-layer window enclosing the predetermined number of neural network layers for each of the plurality of quantization iterations;performing the plurality of quantization iterations, wherein performing a quantization iteration comprises:quantizing weight tensors of the predetermined number of neural network layers, andmodifying one or more values of the quantized weight tensors based on a loss in an output of a last layer of the predetermined number of neural network layers; andgenerating a compressed neural network with the quantized weight tensors having the one or more modified values.2.The method of claim 1, wherein the predetermined number is in a range from two to eight.3.The method of claim 1 or 2, further comprising:determining a step size of the inter-layer window, the step size indicating a number of layers the inter-layer window moves from a position to a next position.4.The method of any one of claims 1-3, wherein a layer of the neural network is enclosed in the inter-layer window for two iterations of the plurality of quantization iterations.5.The method of any one of claims 1-4, wherein quantizing the weight tensors of the predetermined number of neural network layers comprises:quantizing a first part of each of the weight tensors; andmaintaining a second part of each of the weight tensors,wherein the one or more values are in the first part.6.The method of claim 5, wherein performing the quantization iteration further comprises:after modifying the one or more values, quantizing the second part of each of the weight tensors; andmodifying one or more values in the second part based on another loss in another output of the last layer.7.The method of claim 5 or 6, wherein performing the quantization iteration further comprises:generating an intra-layer window, the intra-layer window sliding over each of the weight tensors,wherein the intra-layer window is over the first part before the intra-layer window is over the second part.8.The method of any one of claims 1-7, wherein performing the quantization iteration further comprises:determining a first output of the last layer based on the weight tensors and an input to a first layer of the predetermined number of neural network layers;determining a second output of the last layer based on the quantized weight tensors and the input to the first layer; anddetermining a loss based on the first output and the second output,wherein the one or more values are modified to minimize the loss.9.The method of any one of claims 1-8, wherein the neural network comprises a transformer model.10.One or more non-transitory computer-readable media storing instructions executable to perform operations for compressing a neural network, the operations comprising:generating an inter-layer window, the inter-layer window having a size indicating a predetermined number of neural network layers to be included in the inter-layer window;initiating a plurality of quantization iterations by sliding the inter-layer window over the neural network, the inter-layer window enclosing the predetermined number of neural network layers for each of the plurality of quantization iterations;performing the plurality of quantization iterations, wherein performing a quantization iteration comprises:quantizing weight tensors of the predetermined number of neural network layers, andmodifying one or more values of the quantized weight tensors based on a loss in an output of a last layer of the predetermined number of neural network layers; andgenerating a compressed neural network with the quantized weight tensors having the one or more modified values.11.The one or more non-transitory computer-readable media of claim 10, wherein the predetermined number is in a range from two to eight.12.The one or more non-transitory computer-readable media of claim 10 or 11, further comprising:determining a step size of the inter-layer window, the step size indicating a number of layers the inter-layer window moves from a position to a next position.13.The one or more non-transitory computer-readable media of any one of claims 10-12, wherein a layer of the neural network is enclosed in the inter-layer window for two iterations of the plurality of quantization iterations.14.The one or more non-transitory computer-readable media of any one of claims 10-13, wherein quantizing the weight tensors of the predetermined number of neural network layers comprises:quantizing a first part of each of the weight tensors; andmaintaining a second part of each of the weight tensors,wherein the one or more values are in the first part.15.The one or more non-transitory computer-readable media of claim 14, wherein performing the quantization iteration further comprises:after modifying the one or more values, quantizing the second part of each of the weight tensors; andmodifying one or more values in the second part based on another loss in another output of the last layer.16.The one or more non-transitory computer-readable media of claim 14 or 15, wherein performing the quantization iteration further comprises:generating an intra-layer window, the intra-layer window sliding over each of the weight tensors,wherein the intra-layer window is over the first part before the intra-layer window is over the second part.17.The one or more non-transitory computer-readable media of any one of claims 10-16, wherein performing the quantization iteration further comprises:determining a first output of the last layer based on the weight tensors and an input to a first layer of the predetermined number of neural network layers;determining a second output of the last layer based on the quantized weight tensors and the input to the first layer; anddetermining a loss based on the first output and the second output,wherein the one or more values are modified to minimize the loss.18.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 compressing a neural network, the operations comprising:generating an inter-layer window, the inter-layer window having a size indicating a predetermined number of neural network layers to be included in the inter-layer window,initiating a plurality of quantization iterations by sliding the inter-layer window over the neural network, the inter-layer window enclosing the predetermined number of neural network layers for each of the plurality of quantization iterations,performing the plurality of quantization iterations, wherein performing a quantization iteration comprises:quantizing weight tensors of the predetermined number of neural network layers, andmodifying one or more values of the quantized weight tensors based on a loss in an output of a last layer of the predetermined number of neural network layers, andgenerating a compressed neural network with the quantized weight tensors having the one or more modified values.19.The apparatus of claim 18, wherein the predetermined number is in a range from two to eight.20.The apparatus of claim 18 or 19, further comprising:determining a step size of the inter-layer window, the step size indicating a number of layers the inter-layer window moves from a position to a next position.21.The apparatus of any one of claims 18-20, wherein a layer of the neural network is enclosed in the inter-layer window for two iterations of the plurality of quantization iterations.22.The apparatus of any one of claims 18-21, wherein quantizing the weight tensors of the predetermined number of neural network layers comprises:quantizing a first part of each of the weight tensors; andmaintaining a second part of each of the weight tensors,wherein the one or more values are in the first part.23.The apparatus of claim 22, wherein performing the quantization iteration further comprises:after modifying the one or more values, quantizing the second part of each of the weight tensors; andmodifying one or more values in the second part based on another loss in another output of the last layer.24.The apparatus of claim 22 or 23, wherein performing the quantization iteration further comprises:generating an intra-layer window, the intra-layer window sliding over each of the weight tensors,wherein the intra-layer window is over the first part before the intra-layer window is over the second part.25.The apparatus of any one of claims 18-24, wherein performing the quantization iteration further comprises:determining a first output of the last layer based on the weight tensors and an input to a first layer of the predetermined number of neural network layers;determining a second output of the last layer based on the quantized weight tensors and the input to the first layer; anddetermining a loss based on the first output and the second output,wherein the one or more values are modified to minimize the loss.