Devices and methods for providing transformer neural network model

By selecting a representative subset of query, key, and value vectors, the attention layer optimizes transformer models to operate efficiently in resource-constrained environments, addressing memory challenges and maintaining performance.

WO2025213310A1PCT designated stage Publication Date: 2025-10-16HUAWEI TECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/086479
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Filing Date
2024-04-07
Publication Date
2025-10-16

AI Technical Summary

Technical Problem

Transformer neural network models face significant memory challenges due to the linear growth of key-value cache requirements, particularly in resource-constrained environments, limiting their practical deployment on devices like smartphones and IoT devices.

Method used

Implementing an attention layer that selects a representative subset of query, key, and value vectors to reduce computational complexity and memory usage, using techniques such as kernel regression to prune unnecessary key-value pairs.

Benefits of technology

This approach reduces memory and computational costs without degrading performance, enabling efficient operation of transformer models on resource-constrained devices.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024086479_16102025_PF_FP_ABST
    Figure CN2024086479_16102025_PF_FP_ABST
Patent Text Reader

Abstract

A data processing apparatus (100) is disclosed, comprising a processing circuitry (110) configured to operate a transformer neural network, wherein the transformer neural network comprises a plurality of processing layers, including an attention layer, for processing an input sequence comprising a plurality of tokens. One or more of the plurality of processing layers upstream of the attention layer are configured to determine for each of the plurality of tokens of the input sequence a query vector qi, a key vector ki, and a value vector vi. The attention layer is configured to select a subset of the plurality of pairs of key vectors ki and value vectors vi and to determine an output of the attention layer based on the selected subset. Thus, a data processing apparatus is disclosed allowing to reduce the computational complexity of an attention layer of a transformer neural network model without significantly reducing its performance.
Need to check novelty before this filing date? Find Prior Art

Description

DEVICES AND METHODS FOR PROVIDING TRANSFORMER NEURAL NETWORK MODELTECHNICAL FIELD

[0001] The present invention relates to data processing. More specifically, the present invention relates to devices and methods for providing and operating a transformer neural network model with a key-value, KV, cache.BACKGROUND

[0002] Neural networks, which are being implemented in more and more electronic devices for a variety of different purposes, are usually demanding with respect to computational resources. Therefore, it is a challenge to implement large neural networks on electronic devices with limited hardware capabilities in terms of processing power, memory and energy resources, such as smartphones, intelligent cameras or other types of IoT devices. Even for cloud computing, where the processing capabilities, the memory and the power resources of cloud servers are usually not an issue, reducing the computational complexity of neural networks may provide advantages. For Large Language Models (LLMs) resources becomes an issue when considering serving users at large scale. Moreover, typically, LLMs cannot run on, for instance, IoT devices and smartphones.

[0003] Recently, transformer neural network models have emerged as a very popular type of neural networks for analysing data that is in or can be processed into sequential form. It has been applied in various fields, such as natural language processing, computer vision, neural machine translation, document summarization, protein structure prediction and the like.

[0004] LLMs, for instance, which have revolutionized natural language processing tasks, showcasing remarkable capabilities across a wide spectrum of applications, owe their success to the transformer model architecture. The transformer model architecture is particularly adept at capturing intricate relationships between words (or tokens) in a given input sequence through the use of attention mechanisms, e.g. one or more attention layers. This allows the model to focus on different parts of the input sequence while processing each token, enabling the extraction of complex patterns and dependencies. Despite their impressive performance, the deployment of LLMs on resource-constrained computing environments poses a significant challenge. One of the major bottlenecks is the growth of memory requirements concerning the length of both the input sequence and the generated output. This limitation is particularly pronounced for generative inference implementations, where tokens are generated one at a time and previous key-value pairs are kept in the cache (i.e., KV-cache) , leading to a potential explosion in memory usage.

[0005] The key-value (KV) cache problem is a crucial aspect contributing to this memory challenge in LLMs. In the context of the transformer model architecture, the attention mechanism relies on key-value pairs to assign weights to different parts of the input sequence. As the length of the input sequence and the generated output, i.e. text increases, the key-value cache associated with each token grows. To break it down, for each token generated, the model needs to store key-value pairs for all the tokens in the input sequence, resulting in a memory requirement that scales linearly with the length of the text. This linear growth in memory can quickly become prohibitive in resource-constrained environments, limiting the practical deployment of LLMs.SUMMARY

[0006] It is an object of the invention to provide improved devices and methods for operating transformer neural network models with a key-value cache requiring less computational resources without a significant performance degradation.

[0007] The foregoing and other objects are achieved by the subject matter of the independent claims. Further implementation forms are apparent from the dependent claims, the description and the figures.

[0008] According to a first aspect a data processing apparatus is provided, comprising a processing circuitry configured to operate a transformer neural network, wherein the transformer neural network comprises a plurality of processing layers, including an attention layer, for processing an input sequence comprising a plurality of tokens. One or more of the plurality of processing layers upstream of the attention layer are configured to determine for each of the plurality of tokens of the input sequence a query vector qi, a key vector ki, and a value vector vi, wherein the plurality of query vectors qi define a query matrix Q, the plurality of key vectors ki define a key matrix K, and the plurality of value vectors vi define a value matrix V. The attention layer is configured to select a subset of the plurality of pairs of key vectors ki and value vectors vi (each pair assigning different weights to the tokens of the input sequence) and to determine an output of the attention layer based on the selected subset. Thus, a data processing apparatus is provided allowing to reduce the computational complexity of an attention layer of a transformer neural network without significantly reducing its performance. In an implementation form the attention layer is configured to select a respective subset of the plurality of pairs of key vectors ki and value vectors vi for each attention head of a plurality of attention heads of the attention layer.

[0009] In a further possible implementation form, for selecting the subset of the plurality of pairs of key vectors ki and value vectors vi the attention layer is configured to select a representative subset of the plurality of query vectors qi. In an implementation form the attention layer is configured to select a respective representative subset of the plurality of query vectors qi for each attention head of a plurality of attention heads of the attention layer.

[0010] In a further possible implementation form, the representative subset of the plurality of query vectors qi comprises a number of query vectors of the plurality of query vectors qi having the largest norms and being most orthogonal with respect to each other.

[0011] In a further possible implementation form, the attention layer is configured to select the representative subset of the plurality of query vectors qi by:

[0012] (a) choosing the query vector of the plurality of query vectors qi with the largest norm as the first representative query vector;

[0013] (b) subtracting the projection of the first representative query vector from the remaining query vectors of the of the plurality of query vectors qi for obtaining a reduced set of query vectors qi (which is equivalent to projecting the remaining query vectors on the nullspace of the first representative query vector with the largest norm) ;

[0014] (c) repeating steps (a) and (b) with the reduced set of query vectors qi until a desired number of representative query vectors have been obtained that form the representative subset of the plurality of query vectors qi.

[0015] In a further possible implementation form, for selecting the subset of the plurality of pairs of key vectors ki and value vectors vi the attention layer is configured to select a subset of the plurality of the plurality of key vector ki by selecting a subset of the plurality of key vectors ki resulting in the largest functional values of the function wherein denotes a matrix defined by the representative subset of the plurality of query vectors qi.

[0016] In a further possible implementation form, the function f comprises a sum, a norm, a maximum function, and / or a dot product with another vector.

[0017] In a further possible implementation form, the attention layer is configured to determine the output of the attention layer based on the selected subset using the following equation:

[0018] wherein Softmax () denotes the Softmax function,  denotes a matrix defined by the selected subset of the plurality of key vectors ki, V′t denotes a matrix defined by the selected subset of the plurality of value vectors vi, and n denotes a normalization factor.

[0019] In a further possible implementation form, the attention layer is configured to determine the normalization factor n as:

[0020] wherein d denotes an embedding dimension per attention head of the query matrix Q and the key matrix K.

[0021] In a further possible implementation form, the processing circuitry is configured to operate a large language model comprising the transformer neural network.

[0022] In a further possible implementation form, the attention layer is configured to determine the output of the attention layer based on the selected subset using generative inference.

[0023] According to a second aspect a data processing method is provided, wherein the data processing method comprises:

[0024] operating a transformer neural network, wherein the transformer neural network comprises a plurality of processing layers, including an attention layer, for processing an input sequence comprising a plurality of tokens;

[0025] determining, by one or more of the plurality of processing layers upstream of the attention layer, for each of the plurality of tokens of the input sequence a query vector qi, a key vector ki, and a value vector vi, wherein the plurality of query vectors qi define a query matrix Q, the plurality of key vectors ki define a key matrix K, and the plurality of value vectors vi define a value matrix V;

[0026] selecting a subset of the plurality of pairs of key vectors ki and value vectors vi, each pair assigning different weights to the tokens of the input sequence by the attention layer; and

[0027] determining an output of the attention layer based on the selected subset.

[0028] The data processing method according to the second aspect can be performed by the data processing apparatus according to the first aspect. Thus, further features of the data processing method according to the second aspect result directly from the functionality of the data processing apparatus according to the first aspect and its different implementation forms described above and below.

[0029] According to a third aspect a computer program or a computer program product is provided, comprising a computer-readable storage medium carrying program code which causes a computer or a processor to perform the data processing method according to the second aspect when the program code is executed by the computer or the processor.

[0030] The different aspects of the invention can be implemented in software and / or hardware.

[0031] Details of one or more embodiments are set forth in the accompanying drawings and the description below. Other features, objects, and advantages will be apparent from the description, drawings, and claims.BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In the following embodiments of the invention are described in more detail with reference to the attached figures and drawings, in which:

[0033] Fig. 1 is a schematic diagram illustrating a data processing apparatus according to an embodiment for operating a transformer neural network model with an improved attention layer;

[0034] Fig. 2 is a schematic diagram illustrating an exemplary transformer neural network model implemented by a data processing apparatus according to an embodiment including an improved attention layer;

[0035] Fig. 3 is a schematic diagram illustrating an exemplary attention layer implemented by a data processing apparatus according to an embodiment;

[0036] Fig. 4 is a schematic diagram illustrating several processing stages implemented by an application layer of a data processing apparatus according to an embodiment for selecting a representative query vector subset;

[0037] Fig. 5 is a schematic diagram illustrating several processing stages implemented by an application layer of a data processing apparatus according to an embodiment for selecting a representative subset of key and value vector pairs based on the representative query vector subset;

[0038] Fig. 6 is a flow diagram illustrating several further processing stages implemented by an application layer of a data processing apparatus according to an embodiment for selecting a representative query vector subset and generating an output of the attention layer based on the representative subset;

[0039] Figs. 7a and 7b show graphs illustrating the effect of selecting a representative key and value vector subset as implemented by a data processing apparatus according to an embodiment;

[0040] Fig. 8 is flow diagram illustrating processing steps implemented by a data processing apparatus according to an embodiment;

[0041] Figs. 9a and 9b show graphs illustrating the performance of a data processing apparatus according to an embodiment;

[0042] Figs. 10a-c show tables illustrating the performance of a data processing apparatus according to an embodiment;

[0043] Fig. 11 shows a graph illustrating the performance of a data processing apparatus according to an embodiment; and

[0044] Fig. 12 is a flow diagram illustrating a computer-implemented data processing method according to an embodiment for operating a transformer neural network model with an improved attention layer.

[0045] In the following identical reference signs refer to identical or at least functionally equivalent features.

[0046] DETAILED DESCRIPTION OF THE EMBODIMENTS

[0047] In the following description, reference is made to the accompanying figures, which form part of the disclosure, and which show, by way of illustration, specific aspects of embodiments of the invention or specific aspects in which embodiments of the present invention may be used. It is understood that embodiments of the invention may be used in other aspects and comprise structural or logical changes not depicted in the figures. The following detailed description, therefore, is not to be taken in a limiting sense, and the scope of the present invention is defined by the appended claims.

[0048] For instance, it is to be understood that a disclosure in connection with a described method may also hold true for a corresponding device or system configured to perform the method and vice versa. For example, if one or a plurality of specific method steps are described, a corresponding device may include one or a plurality of units, e.g. functional units, to perform the described one or plurality of method steps (e.g. one unit performing the one or plurality of steps, or a plurality of units each  performing one or more of the plurality of steps) , even if such one or more units are not explicitly described or illustrated in the figures. On the other hand, for example, if a specific apparatus is described based on one or a plurality of units, e.g. functional units, a corresponding method may include one step to perform the functionality of the one or plurality of units (e.g. one step performing the functionality of the one or plurality of units, or a plurality of steps each performing the functionality of one or more of the plurality of units) , even if such one or plurality of steps are not explicitly described or illustrated in the figures. Further, it is understood that the features of the various exemplary embodiments and / or aspects described herein may be combined with each other, unless specifically noted otherwise.

[0049] Fig. 1 is schematic diagram illustrating a data processing apparatus 100 according to an embodiment. In the embodiment shown in figure 1 the data processing apparatus 100 may be, by way of example, a server 100, for instance, a cloud server 100. As will be appreciated, however, in other embodiments the data processing apparatus 100 may be implemented, for instance, as a server farm, a desktop computer, a laptop computer, a tablet computer, a smartphone, an IoT device or another device having the computational resources for implementing a neural network.

[0050] As illustrated in figure 1, the server 100 may comprise a processing circuitry 110, such as one or more processors or cores 110 for processing data and a memory 130 for storing and retrieving data. Furthermore, the server 100 may comprise a communication interface 150, for instance, for exchanging data with other devices, such as a smartphone 160, via a wired and / or wireless communication channel 170 provided, for instance, by the Internet.

[0051] The processing circuitry 110 of the server 100 may be implemented in hardware and / or software. The hardware may comprise digital circuitry, or both analog and digital circuitry. Digital circuitry may comprise components such as application-specific integrated circuits (ASICs) , field-programmable gate arrays (FPGAs) , digital signal processors (DSPs) , or general-purpose processors. The memory 130 may store executable program code which, when executed by the processing circuitry 110, causes the server 100 to perform the functions and methods described herein.

[0052] As will be described in more detail in the following under further reference to figure 2, the processing circuitry 110 of the data processing apparatus 100, e.g. server 100 is configured to implement, i.e. operate a transformer neural network model 111, wherein the transformer neural network model 111 comprises a plurality of processing layers 113 for processing a plurality, i.e. a sequence of input elements 201. By way of example, the plurality of input elements 201 (also referred to as tokens) may comprise a plurality of words 201 making up a sentence or a query.

[0053] One or more of the plurality of processing layers 113 of the transformer neural network model 111 may comprise a plurality of neural network weights, which are usually determined or adapted during a training phase of the transformer neural network model 111. The plurality of neural network weights of a respective processing layer 113 may be stored in the memory 130 of the data processing apparatus 100. The plurality of processing layers 113 may comprise different types of neural network layers, such as fully connected, convolution, deconvolution, recurrent layers and the like. As will be appreciated, the transformer neural network model 111 may be a part or component of a larger neural network implemented by the data processing apparatus 100.

[0054] As illustrated in figure 2 and as will be described in the following in more detail under further reference to figure 3, one of the plurality of processing layers 113 of the transformer neural network model 111 is implemented as an attention layer 113a for identifying short and long-term correlations between the plurality of input elements 201. One or more of the plurality of processing layers 113 upstream of the attention layer 113a are configured to determine for each of the plurality of input elements, i.e. tokens 201 a query vector qi, a key vector ki, and a value vector vi, wherein the plurality of query vectors qi define a query matrix Q, the plurality of key vectors ki define a key matrix K, and the plurality of value vectors vi define a value matrix V. For instance, the plurality of query vectors qi may define the rows or columns of the query matrix Q, the plurality of key vectors ki may define the rows or columns of the key matrix K, and the plurality of value vectors vi may define the rows of the value matrix V. As further illustrated in figure 3, the attention layer is configured to determine an output 203 based on these vectors and / or matrices (which in an embodiment may also be higher-dimensional tensors) .

[0055] As will be described in the following in more detail under further reference to figures 4 and 5, which illustrate a two-stage process, embodiments disclosed herein provide an attention layer 113a, which is improved with respect to a conventional attention layer, because instead of using the full set of query vectors qi provided by the one or more upstream processing layers the attention layer 113a is configured to filter or prune these vectors by selecting a representative subset thereof. Based on this representative subset of the set of query vectors qi the attention layer 113a is further configured to determine a subset of the pairs of key and value vectors and, thus, to essentially prune the full set of input tokens 201 for the most important tokens for providing its output 203 based on this representative subset. In other words, the attention layer 113a is configured to select a subset of the plurality of pairs of key vectors ki and value vectors vi and to determine an output 203 of the attention layer 113a based on the selected subset. In an embodiment, the attention layer 113a comprises a plurality of attention heads and is configured to perform the operations described above and below in parallel for each attention head of the attention layer 113a. For instance, in an embodiment, the multi-head attention layer 113a is configured to select a respective subset of the plurality of pairs of key vectors ki and value vectors vi for each attention head of a plurality of attention heads of the attention layer 113a.

[0056] As will be appreciated, the attention layer 113a illustrated in figure 3 and its formulation may be interpreted within the context of kernel regression. Based on this interpretation the attention layer 113a can be regarded to learn to estimate an unknown function for input q using a set of N pairs of parameter vectors resulting in the equation:

[0057] Embodiments disclosed herein are based on the idea that not all key-value pairs may carry unique or critical information, rather some pairs might encode redundant or similar information. The kernel regression interpretation suggests that by carefully selecting a subset of key vectors ki and their corresponding value vectors vi it's possible to achieve a similar output estimation. In other words, the output estimation implemented by the attention layer 113a according to embodiments disclosed herein is done using less key-value vectors pairs (ki, vi) than a conventional attention layer. Thus, by selecting a proper representative set of the pairs (ki, vi) , a significant portion of the key-value, KV, tokens can be discarded without degrading the estimation, which is illustrated in figures 7a and 7b. By eliminating unnecessary key-value pairs, not only the memory 130 of the data processing apparatus 100 that is needed to store the KV data is reduced but also the computational cost of attention computation is reduced. This is particularly beneficial in scenarios where computational resources are constrained. As will be described in more detail below, in an embodiment, the attention layer 113a is configured to select the proper representative set of the pairs (ki, vi) by selecting a representative subset of the set of query vectors qi.

[0058] In summary, the kernel regression interpretation shows that not all key-value pairs are equally important for the estimation performed by the attention layer 113a. Selecting a subset of these pairs, guided by the learned weights, allows for a more efficient and streamlined attention mechanism implemented by the attention layer 113a according to embodiments disclosed herein. This insight is leveraged by embodiments disclosed herein for optimization in terms of both computational efficiency and memory consumption.

[0059] Fig. 4 is a schematic diagram illustrating several processing stages implemented by the application layer 113a implemented by the data processing apparatus 100 according to an embodiment for selecting a representative query vector subset, while figure 5 illustrates several processing stages implemented by the application layer 113a for using this subset for token pruning, i.e. selecting the most important tokens. As already mentioned above, according to an embodiment for selecting the subset of the plurality of pairs of key vectors ki and value vectors vi the attention layer 113a is configured to select a representative subset of the plurality of query vectors qi, which is illustrated in figure 4.

[0060] As illustrated in figure 4, out of the full set of N query vectors qi the attention layer 113a is configured to select a group of n query vectors [q (1) , q (2) , q (n) ] out of N>>n, that are the largest, yet, as orthogonal as possible to each other. These vectors create  the largest volume parallelepiped that can be constructed using n vectors from the set of Q of N vectors. More specifically, the attention layer 113a is configured to select the representative subset of the plurality of query vectors qi by:

[0061] (a) choosing the query vector of the plurality of query vectors qi with the largest norm as the first representative query vector (see (1) in figure 4) ;

[0062] (b) subtracting the projection of the first representative query vector from the remaining query vectors of the of the plurality of query vectors qi for obtaining a reduced set of query vectors qi (see (2) in figure 4) ; and

[0063] (c) repeating steps (a) and (b) with the reduced set of query vectors qi until a desired number of representative query vectors have been obtained that form the representative subset of the plurality of query vectors qi (see (3) of figure 4) .

[0064] For selecting the subset of the plurality of pairs of key vectors ki and value vectors vi, as illustrated in figure 5, the attention layer 113a is configured to select a subset of the plurality of the plurality of key vector ki by selecting a subset of the plurality of key vectors ki resulting in the largest functional values of a function wherein denotes a matrix [q (1) , q (2) , q (n) ] defined by the representative subset of the plurality of query vectors qi determined by the process illustrated in figure 4. In an embodiment, the function f may comprise a sum, a norm, a maximum function, and / or a dot product with another vector.

[0065] According to an embodiment, in inference, once the KV-cache size is above a pre-defined budget, the key-value pairs may be ranked using the above, and only the most relevant ones are kept.

[0066] Fig. 6 is a flow diagram providing further detail about the two-stage process described in the context of figures 4 and 5 above and implemented by the application layer 113a according to an embodiment. Based on the input parameter #qreps the attention layer 113a in steps 601, 603 and 605 of figure 6 constructs a subset of the full set of query vectors that contains the largest vectors that are as orthogonal as possible with respect to each other until a subset of the desired size #qreps has been obtained. Based on the further input parameter #kreps the attention layer 113a in steps 607 and 609 of figure 6 evaluates and filter the most relevant keys based on the query vector subset, such as the top-k indices of or In step 611 of figure 6 the attention layer 113a uses only the selected keys / values pairs for the attention computation. In an embodiment, the attention layer 113a is configured to determine the output of the attention layer 113a based on the selected subset using the following equation:

[0067] wherein Softmax () denotes the Softmax function,  denotes a matrix defined by the selected subset of the plurality of key vectors ki, V′t denotes a matrix defined by the selected subset of the plurality of value vectors vi, and n denotes a normalization factor. In an embodiment, the normalization factor n may be chosen as wherein d denotes an embedding dimension per attention head of the query matrix Q and / or the key matrix K.

[0068] Fig. 8 is flow diagram illustrating processing steps implemented by the data processing apparatus 100 according to an embodiment for a chat bot application, where a user sends prompt by prompt 201 and the prompts 201 are typically related. In this case, a KV-cache 130a may contain all the history of generated tokens and prompts, which grows linearly fast with the number of prompt / generated tokens. Nevertheless, only a small fraction of the KV-cache 130a is relevant for the last prompt from the user. Thus, it is vital to maintain only relevant data in cache, to reduce memory consumption and accelerate the attention (by utilizing smaller matrix multiplications) , as achieved by embodiments disclosed herein. For instance, as illustrated in figure 8, a compression 801 may be implemented under certain circumstances. More specifically, once the user prompts the model, and the KV-cache is larger than a pre-defined value, the data processing apparatus 100 according to an embodiment obtains a signature of the query (i.e., the representatives) and keeps only the most relevant keys to these representatives.

[0069] Figs. 9a and 9b show a time graph and a memory graph illustrating the performance of the data processing apparatus 100 according to an embodiment. The results illustrated in figures 9a and 9b are based on the performance of a single attention layer of Llama 7B with (illustrated by the curve (s) A) and without the selection and pruning (i.e. sensing. Illustrated by the curve (s) B) approach disclosed herein. The maximum KV-cache size for the graph with sensing is 1024 and once the KV-cache reaches this value, tokens from the cache are discarded to reduce its size to 512 (i.e., discard 512 tokens) . Fig. 9a depicts the latency of the attention. Interestingly, when the sensing compression is done, small peaks appear in the graph that occur due to the sensing overhead. Nevertheless, this overhead is worthy since it reduces the overall time when comparing to the other graph (without sensing) which grows linearly with the sequence length (and hence, with the KV-cache size) . Fig. 9b illustrates the memory allocations for this attention layer. Interestingly, the memory allocation with sensing is smaller and after reaching the max KV-cache, the framework releases a lot of memory every 512 tokens (long dips in the graph with sensing) .

[0070] Figs. 10a-c show tables illustrating the performance of the data processing apparatus 100 according to an embodiment. Fig. 10a summarizes the results of the graphs on figures 9a and 9b, showing the mean time and memory that is required for the attention with and without sensing. Remarkably, even when considering the mean time (and not the time in the longest sequence) , sensing attains significant results. Fig. 10b depicts the generation time and prompt time when the model is asked to generate 32k tokens (this is why it is stated that the compression is × 32) . The Llama model, however, does not support this length, and this measurement is for potential illustration only. In this experiments, it can be observed that the overhead of the sensing is about 3ms as appears in the prompt row (21ms vs 18ms) . Yet, in generation, this overhead becomes negligible, as the time per token reduces from about 21ms to 7ms. Fig. 10c shows the edit distance between the model’s output (i.e., the number of single character edits between the outputs) . Note that when sensing does not discard too many tokens, then, the outputs of the conventional model without sensing and the model with sensing are aligned. This means that sensing does not distort the model outputs.

[0071] Fig. 11 shows a graph illustrating the performance of a data processing apparatus 100 according to an embodiment. Fig. 11 illustrates the perplexity (ppl) of the model when generating a text that is longer than the length upon which model is trained on. As can be taken from curve A of figure 11, the baseline breaks after generating a 2k sequence, and (as can be taken from curve B of figure 11) with sensing the ppl remains low (which is better) . As will be appreciated, however, the ppl only measures the ability of the model to predict the next token of a given text. It does not measure the quality of text generation in general.

[0072] Fig. 12 is a flow diagram illustrating a computer-implemented data processing method 1200 according to an embodiment. The data processing method 1200 comprises a step 1201 of operating the transformer neural network 111, wherein, as already described above, the transformer neural network 111 comprises a plurality of processing layers 113, including an attention layer 113a, for processing an input sequence 201 comprising a plurality of tokens. Moreover, the method 1200 comprises a step 1203 of determining, by one or more of the plurality of processing layers 113 upstream of the attention layer 113a, for each of the plurality of tokens of the input sequence 201 a query vector qi, a key vector ki, and a value vector vi. The method 1200 further comprises a step 1205 of selecting a respective subset of the plurality of pairs of key vectors ki and value vectors vi by the attention layer 113a, for instance, in the way described above. Moreover, the method 1200 comprises a step 1207 of determining an output of the attention layer 113a based on the selected representative subset.

[0073] The person skilled in the art will understand that the "blocks" ( "units" ) of the various figures (method and apparatus) represent or describe functionalities of embodiments of the invention (rather than necessarily individual "units" in hardware or software) and thus describe equally functions or features of apparatus embodiments as well as method embodiments (unit = step) .

[0074] In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus, and method may be implemented in other manners. For example, the described apparatus embodiment is merely exemplary. For example, the unit division is merely logical function division and may be other division in actual implementation. For example, a plurality of units or components may be combined or integrated into another system, or some features may be ignored or not performed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections may be  implemented by using some interfaces. The indirect couplings or communication connections between the apparatuses or units may be implemented in electronic, mechanical, or other forms.

[0075] The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one position, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the objectives of the solutions of the embodiments.

[0076] In addition, functional units in the embodiments of the invention may be integrated into one processing unit, or each of the units may exist alone physically, or two or more units are integrated into one unit.

Claims

1.A data processing apparatus (100) , comprising a processing circuitry (110) configured to operate a transformer neural network (111) , wherein the transformer neural network (111) comprises a plurality of processing layers (113) , including an attention layer (113a) , for processing an input sequence (201) comprising a plurality of tokens;wherein one or more of the plurality of processing layers (113) upstream of the attention layer (113a) are configured to determine for each of the plurality of tokens of the input sequence (201) a query vector qi, a key vector ki, and a value vector vi; andwherein the attention layer (113a) is configured to select a subset of the plurality of pairs of key vectors ki and value vectors vi and to determine an output of the attention layer (113a) based on the selected subset.2.The data processing apparatus (100) of claim 1, wherein for selecting the subset of the plurality of pairs of key vectors ki and value vectors vi the attention layer (113a) is configured to select a representative subset of the plurality of query vectors qi.3.The data processing apparatus (100) of claim 2, wherein the representative subset of the plurality of query vectors qi comprises a number of query vectors of the plurality of query vectors qi having the largest norms and being most orthogonal with respect to each other.4.The data processing apparatus (100) of claim 2 or 3, wherein the attention layer (113a) is configured to select the representative subset of the plurality of query vectors qi by:(a) choosing the query vector of the plurality of query vectors qi with the largest norm as the first representative query vector;(b) subtracting the projection of the first representative query vector from the remaining query vectors of the of the plurality of query vectors qi for obtaining a reduced set of query vectors qi;(c) repeating steps (a) and (b) with the reduced set of query vectors qi until a desired number of representative query vectors have been obtained that form the representative subset of the plurality of query vectors qi.5.The data processing apparatus (100) of any one of the preceding claims, wherein for selecting the subset of the plurality of pairs of key vectors ki and value vectors vi the attention layer (113a) is configured to select a subset of the plurality of the plurality of key vector ki by selecting a subset of the plurality of key vectors ki resulting in the largest functional values of the function wherein denotes a matrix defined by the representative subset of the plurality of query vectors qi.6.The data processing apparatus (100) of claim 5, wherein the function f comprises a sum, a norm, a maximum function, and / or a dot product with another vector.7.The data processing apparatus (100) of any one of the preceding claims, wherein the attention layer (113a) is configured to determine the output of the attention layer (113a) based on the selected subset using the following equation: wherein Softmax ( ) denotes the Softmax function, denotes a matrix defined by the selected subset of the plurality of key vectors ki, V′t denotes a matrix defined by the selected subset of the plurality of value vectors vi, and n denotes a normalization factor.8.The data processing apparatus (100) of claim 7, wherein the attention layer (113a) is configured to determine the normalization factor n as: wherein d denotes an embedding dimension of the query matrix Q and the key matrix K.9.The data processing apparatus (100) of any one of the preceding claims, wherein the processing circuitry (110) is configured to operate a large language model comprising the transformer neural network (111) .10.The data processing apparatus (100) of any one of the preceding claims, wherein the attention layer (113a) is configured to determine the output of the attention layer (113a) based on the selected subset using generative inference.11.A data processing method (1200) , wherein the method (1200) comprises:operating (1201) a transformer neural network (111) , wherein the transformer neural network (111) comprises a plurality of processing layers (113) , including an attention layer (113a) , for processing an input sequence (201) comprising a plurality of tokens;determining (1203) , by one or more of the plurality of processing layers (113) upstream of the attention layer (113a) , for each of the plurality of tokens of the input sequence (201) a query vector qi, a key vector ki, and a value vector vi;selecting (1205) a subset of the plurality of pairs of key vectors ki and value vectors vi by the attention layer; anddetermining (1207) an output of the attention layer (113a) based on the selected subset.12.A computer program product comprising a computer-readable storage medium for storing program code which causes a computer or a processor to perform the method (1200) of claim 11 when the program code is executed by the computer or the processor.

Citation Information

Patent Citations

  • Granular neural network architecture search over low level primitives

    CN117121016A

  • Attention neural networks with sparse attention mechanisms

    US20210383191A1

  • Attention neural networks with parallel attention and feed-forward layers

    US20230316055A1

  • Attention neural networks with tree attention mechanisms

    US20240005131A1

  • Neural networks implementing attention over object embeddings for object-centric visual reasoning

    US20240020972A1