Attention score based value cache optimization in generative artificial intelligence workloads
By selectively reading cache memory blocks based on attention scores, the method addresses inefficiencies in self-attention operations, reducing memory traffic and improving output quality in generative AI models.
Patent Information
- Application Number
- US19/217113
- Authority / Receiving Office
- US · United States
- Patent Type
- Applications(United States)
- Current Assignee / Owner
- Filing Date
- 2025-05-23
- Publication Date
- 2026-11-26
AI Technical Summary
Conventional self-attention operations in generative AI models are memory-bound and noisy, with significant runtime spent on reading irrelevant cache data, leading to inefficient processing and degraded output quality.
Implement a method to selectively read cache memory blocks based on attention scores, ignoring tokens with low scores to reduce memory traffic and noise, using threshold-based or data-driven criteria to determine relevant cache reads.
Reduces memory traffic by up to 50% and improves output quality by focusing on relevant tokens, without requiring retraining or additional tuning, enhancing the efficiency and effectiveness of generative AI models.
Smart Images

Figure US20260377324A1-D00000_ABST
Abstract
Description
BACKGROUND
[0001] The present application relates generally to computers and computer applications, and more particularly to machine learning and optimizing a self-attention mechanism in generative artificial intelligence workloads.BRIEF SUMMARY
[0002] The summary of the disclosure is given to aid understanding of a computer system and method of optimizing attention score based value cache in generative artificial intelligence workloads, and not with an intent to limit the disclosure or the invention. It should be understood that various aspects and features of the disclosure may advantageously be used separately in some instances, or in combination with other aspects and features of the disclosure in other instances. Accordingly, variations and modifications may be made to the computer system and / or their method of operation to achieve different effects.
[0003] In some embodiments, a computer-implemented method includes, during performing a self-attention computation by a generative artificial intelligence (AI) model implemented based on transformer architecture and running on at least one processor, selectively reading page blocks of cache memory that store value vectors (e.g., V-cache) representing information associated with tokens of an input sequence, by reading the page blocks corresponding to the tokens that have attention scores meeting a criterion and omitting to read the page blocks corresponding to the tokens that have attention scores not meeting the criterion. The method also includes performing an attention scores-value matrix multiplication of the self-attention computation, using the value vectors stored in the page blocks of the cache memory that are read, where the tokens that have attention scores not meeting the criterion are ignored from the self-attention computation.
[0004] In some embodiments, a computer system includes a processor set. The computer system also include a set of one or more computer-readable storage media. The computer system also include program instructions, collectively stored in the set of one or more computer-readable storage media, for causing the processor set to perform the following computer operations. The computer operations include, during performing a self-attention computation by a generative artificial intelligence (AI) model implemented based on transformer architecture and running on the processor set, selectively reading page blocks of cache memory that store value vectors representing information associated with tokens of an input sequence, by reading the page blocks corresponding to the tokens that have attention scores meeting a criterion and omitting to read the page blocks corresponding to the tokens that have attention scores not meeting the criterion. The computer operations also include performing an attention scores-value matrix multiplication of the self-attention computation, using the value vectors stored in the page blocks of the cache memory that are read, where the tokens that have attention scores not meeting the criterion are ignored from the self-attention computation.
[0005] In some embodiments, a computer program product comprising a set of one or more computer-readable storage media, and program instructions, collectively stored in the set of one or more storage media, for causing a processor set to perform computer operations that perform one or more methods described herein also may be provided.
[0006] Further features as well as the structure and operation of various embodiments are described in detail below with reference to the accompanying drawings. In the drawings, like reference numbers indicate identical or functionally similar elements.BRIEF DESCRIPTION OF THE DRAWINGS
[0007] FIG. 1 shows an example of a computing environment, which can implement an attention score based value cache optimization in some embodiments.
[0008] FIG. 2 is a diagram illustrating a self-attention operation in an attention score based value cache optimization in some embodiments.
[0009] FIG. 3 is a diagram that shows an example plot of normalized attention scores after a softmax operation.
[0010] FIG. 4 shows self-attention with value cache (V-cache) optimization in some embodiments.
[0011] FIG. 5 shows an attention score based value cache optimization efficiency improvement in some embodiments.
[0012] FIG. 6 is a diagram illustrating a value cache logical and physical layout in some embodiments.
[0013] FIG. 7 is a flow diagram illustrating a method for an attention score based value cache optimization in some embodiments.DETAILED DESCRIPTION
[0014] In some embodiments, a computer-implemented method includes, during performing a self-attention computation by a generative artificial intelligence (AI) model implemented based on transformer architecture and running on at least one processor, selectively reading page blocks of cache memory that store value vectors (e.g., V-cache) representing information associated with tokens of an input sequence, by reading the page blocks corresponding to the tokens that have attention scores meeting a criterion and omitting to read the page blocks corresponding to the tokens that have attention scores not meeting the criterion. The method also includes performing an attention scores-value matrix multiplication of the self-attention computation, using the value vectors stored in the page blocks of the cache memory that are read, where the tokens that have attention scores not meeting the criterion are ignored from the self-attention computation.
[0015] In this way, actual attention scores are used to identify which vectors do not need to be read from the V-cache, for instance, to sub-select V-vectors. Omitting to read some page blocks of memory reduces memory traffic.
[0016] One or more of the following features can be separable or optional from each other.
[0017] In some embodiments, the criterion includes meeting a threshold (e.g., an attention score threshold), the threshold being determined based on running the generative AI model using a plurality of candidate thresholds on a validation dataset, where the threshold is selected from the plurality of candidate thresholds based on the threshold having been used in a run of the generative AI model having a minimum loss. In this way, for example, based on trying or exploring different threshold values, an optimum threshold value can be chosen.
[0018] In some embodiments, the criterion includes meeting a threshold, the threshold being determined based on determining a maximum attention score among a set of attention scores corresponding to the input sequence, determining a standard deviation of the set of attention scores, where the threshold is determined as a difference between the maximum attention score and a predetermined multiple of the standard deviation. In this way, for example, an optimal threshold value can be determined automatically based on actual attention scores.
[0019] In some embodiments, the predetermined multiple is predetermined based on running the generative AI model using a plurality of candidate values on a validation dataset, and a candidate value to use as the predetermined multiple is selected from the plurality of candidate values based on a run of the generative AI model having a minimum loss. In this way, for example, an optimal amount of deviation from the maximum attention score can be determined based on trying or exploring different distances from the maximum attention score.
[0020] In some embodiments, different tokens are selected in each head of the generative AI model in performing the attention scores-value matrix multiplication. For instance, different tokens are selected in different heads, where different sets of tokens may be read from the V-cache in processing different heads, allowing for maximal memory traffic reduction.
[0021] In some embodiments, different tokens are selected in each layer of the generative AI model in performing the attention scores-value matrix multiplication. For instance, different tokens are selected in different layers, where different sets of tokens may be read from the V-cache in processing different layers, allowing for maximal memory traffic reduction.
[0022] In some embodiments, different tokens are selected in each decoding iteration of the generative AI model in performing the attention scores-value matrix multiplication. For instance, different tokens are selected in different decoding iterations, where different sets of tokens may be read from the V-cache in processing different decoding iterations, allowing for maximal memory traffic reduction.
[0023] In some embodiments, a computer system comprising a processor set. a set of one or more computer-readable storage media; and program instructions, collectively stored in the set of one or more computer-readable storage media, for causing the processor set to perform computer operations that perform one or more methods described herein also may be provided.
[0024] In some embodiments, a computer system includes a processor set. The computer system also include a set of one or more computer-readable storage media. The computer system also include program instructions, collectively stored in the set of one or more computer-readable storage media, for causing the processor set to perform the following computer operations. The computer operations include, during performing a self-attention computation by a generative artificial intelligence (AI) model implemented based on transformer architecture and running on the processor set, selectively reading page blocks of cache memory that store value vectors representing information associated with tokens of an input sequence, by reading the page blocks corresponding to the tokens that have attention scores meeting a criterion and omitting to read the page blocks corresponding to the tokens that have attention scores not meeting the criterion. The computer operations also include performing an attention scores-value matrix multiplication of the self-attention computation, using the value vectors stored in the page blocks of the cache memory that are read, where the tokens that have attention scores not meeting the criterion are ignored from the self-attention computation. In this way, actual attention scores are used to identify which vectors do not need to be read from the V-cache, for instance, to sub-select V-vectors. Omitting to read some page blocks of memory reduces memory traffic.
[0025] In some embodiments, a computer program product comprising a set of one or more computer-readable storage media, and program instructions, collectively stored in the set of one or more storage media, for causing a processor set to perform computer operations that perform one or more methods described herein also may be provided.
[0026] In some embodiments, a computer program product includes one or more computer-readable storage media. The computer program product also include program instructions stored on the one or more storage media to perform following operations. The operations includes, during performing a self-attention computation by a generative artificial intelligence (AI) model implemented based on transformer architecture and running on at least one processor, selectively reading page blocks of cache memory that store value vectors representing information associated with tokens of an input sequence, by reading the page blocks corresponding to the tokens that have attention scores meeting a criterion and omitting to read the page blocks corresponding to the tokens that have attention scores not meeting the criterion. The operations also include performing an attention scores-value matrix multiplication of the self-attention computation, using the value vectors stored in the page blocks of the cache memory that are read, where the tokens that have attention scores not meeting the criterion are ignored from the self-attention computation. In this way, actual attention scores are used to identify which vectors do not need to be read from the V-cache, for instance, to sub-select V-vectors. Omitting to read some page blocks of memory reduces memory traffic.
[0027] Various aspects of the present disclosure are described by narrative text, flowcharts, block diagrams of computer systems and / or block diagrams of the machine logic included in computer program product (CPP) embodiments. With respect to any flowcharts, depending upon the technology involved, the operations can be performed in a different order than what is shown in a given flowchart. For example, again depending upon the technology involved, two operations shown in successive flowchart blocks may be performed in reverse order, as a single integrated step, concurrently, or in a manner at least partially overlapping in time.
[0028] A computer program product embodiment ("CPP embodiment" or “CPP”) is a term used in the present disclosure to describe any set of one, or more, storage media (also called "mediums") collectively included in a set of one, or more, storage devices that collectively include machine readable code corresponding to instructions and / or data for performing computer operations specified in a given CPP claim. A "storage device" is any tangible device that can retain and store instructions for use by a computer processor. Without limitation, the computer readable storage medium may be an electronic storage medium, a magnetic storage medium, an optical storage medium, an electromagnetic storage medium, a semiconductor storage medium, a mechanical storage medium, or any suitable combination of the foregoing. Some known types of storage devices that include these mediums include: diskette, hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or Flash memory), static random access memory (SRAM), compact disc read-only memory (CD-ROM), digital versatile disk (DVD), memory stick, floppy disk, mechanically encoded device (such as punch cards or pits / lands formed in a major surface of a disc) or any suitable combination of the foregoing. A computer readable storage medium, as that term is used in the present disclosure, is not to be construed as storage in the form of transitory signals per se, such as radio waves or other freely propagating electromagnetic waves, electromagnetic waves propagating through a waveguide, light pulses passing through a fiber optic cable, electrical signals communicated through a wire, and / or other transmission media. As will be understood by those of skill in the art, data is typically moved at some occasional points in time during normal operations of a storage device, such as during access, de-fragmentation or garbage collection, but this does not render the storage device as transitory because the data is not transitory while it is stored.
[0029] Computing environment 100 contains an example of an environment for the execution of at least some of the computer code involved in performing the inventive methods, such as an attention score based value cache optimization code. In addition to block 200, computing environment 100 includes, for example, computer 101, wide area network (WAN) 102, end user device (EUD) 103, remote server 104, public cloud 105, and private cloud 106. In this embodiment, computer 101 includes processor set 110 (including processing circuitry 120 and cache 121), communication fabric 111, volatile memory 112, persistent storage 113 (including operating system 122 and block 200, as identified above), peripheral device set 114 (including user interface (UI) device set 123, storage 124, and Internet of Things (IoT) sensor set 125), and network module 115. Remote server 104 includes remote database 130. Public cloud 105 includes gateway 140, cloud orchestration module 141, host physical machine set 142, virtual machine set 143, and container set 144.
[0030] COMPUTER 101 may take the form of a desktop computer, laptop computer, tablet computer, smart phone, smart watch or other wearable computer, mainframe computer, quantum computer or any other form of computer or mobile device now known or to be developed in the future that is capable of running a program, accessing a network or querying a database, such as remote database 130. As is well understood in the art of computer technology, and depending upon the technology, performance of a computer-implemented method may be distributed among multiple computers and / or between multiple locations. On the other hand, in this presentation of computing environment 100, detailed discussion is focused on a single computer, specifically computer 101, to keep the presentation as simple as possible. Computer 101 may be located in a cloud, even though it is not shown in a cloud in FIG. 1. On the other hand, computer 101 is not required to be in a cloud except to any extent as may be affirmatively indicated.
[0031] PROCESSOR SET 110 includes one, or more, computer processors of any type now known or to be developed in the future. Processing circuitry 120 may be distributed over multiple packages, for example, multiple, coordinated integrated circuit chips. Processing circuitry 120 may implement multiple processor threads and / or multiple processor cores. Cache 121 is memory that is located in the processor chip package(s) and is typically used for data or code that should be available for rapid access by the threads or cores running on processor set 110. Cache memories are typically organized into multiple levels depending upon relative proximity to the processing circuitry. Alternatively, some, or all, of the cache for the processor set may be located “off chip.” In some computing environments, processor set 110 may be designed for working with qubits and performing quantum computing.
[0032] Computer readable program instructions are typically loaded onto computer 101 to cause a series of operational steps to be performed by processor set 110 of computer 101 and thereby effect a computer-implemented method, such that the instructions thus executed will instantiate the methods specified in flowcharts and / or narrative descriptions of computer-implemented methods included in this document (collectively referred to as “the inventive methods”). These computer readable program instructions are stored in various types of computer readable storage media, such as cache 121 and the other storage media discussed below. The program instructions, and associated data, are accessed by processor set 110 to control and direct performance of the inventive methods. In computing environment 100, at least some of the instructions for performing the inventive methods may be stored in block 200 in persistent storage 113.
[0033] COMMUNICATION FABRIC 111 is the signal conduction path that allows the various components of computer 101 to communicate with each other. Typically, this fabric is made of switches and electrically conductive paths, such as the switches and electrically conductive paths that make up buses, bridges, physical input / output ports and the like. Other types of signal communication paths may be used, such as fiber optic communication paths and / or wireless communication paths.
[0034] VOLATILE MEMORY 112 is any type of volatile memory now known or to be developed in the future. Examples include dynamic type random access memory (RAM) or static type RAM. Typically, volatile memory 112 is characterized by random access, but this is not required unless affirmatively indicated. In computer 101, the volatile memory 112 is located in a single package and is internal to computer 101, but, alternatively or additionally, the volatile memory may be distributed over multiple packages and / or located externally with respect to computer 101.
[0035] PERSISTENT STORAGE 113 is any form of non-volatile storage for computers that is now known or to be developed in the future. The non-volatility of this storage means that the stored data is maintained regardless of whether power is being supplied to computer 101 and / or directly to persistent storage 113. Persistent storage 113 may be a read only memory (ROM), but typically at least a portion of the persistent storage allows writing of data, deletion of data and re-writing of data. Some familiar forms of persistent storage include magnetic disks and solid state storage devices. Operating system 122 may take several forms, such as various known proprietary operating systems or open source Portable Operating System Interface type operating systems that employ a kernel. The code included in block 200 typically includes at least some of the computer code involved in performing the inventive methods.
[0036] PERIPHERAL DEVICE SET 114 includes the set of peripheral devices of computer 101. Data communication connections between the peripheral devices and the other components of computer 101 may be implemented in various ways, such as Bluetooth connections, Near-Field Communication (NFC) connections, connections made by cables (such as universal serial bus (USB) type cables), insertion type connections (for example, secure digital (SD) card), connections made through local area communication networks and even connections made through wide area networks such as the internet. In various embodiments, UI device set 123 may include components such as a display screen, speaker, microphone, wearable devices (such as goggles and smart watches), keyboard, mouse, printer, touchpad, game controllers, and haptic devices. Storage 124 is external storage, such as an external hard drive, or insertable storage, such as an SD card. Storage 124 may be persistent and / or volatile. In some embodiments, storage 124 may take the form of a quantum computing storage device for storing data in the form of qubits. In embodiments where computer 101 is required to have a large amount of storage (for example, where computer 101 locally stores and manages a large database) then this storage may be provided by peripheral storage devices designed for storing very large amounts of data, such as a storage area network (SAN) that is shared by multiple, geographically distributed computers. IoT sensor set 125 is made up of sensors that can be used in Internet of Things applications. For example, one sensor may be a thermometer and another sensor may be a motion detector.
[0037] NETWORK MODULE 115 is the collection of computer software, hardware, and firmware that allows computer 101 to communicate with other computers through WAN 102. Network module 115 may include hardware, such as modems or Wi-Fi signal transceivers, software for packetizing and / or de-packetizing data for communication network transmission, and / or web browser software for communicating data over the internet. In some embodiments, network control functions and network forwarding functions of network module 115 are performed on the same physical hardware device. In other embodiments (for example, embodiments that utilize software-defined networking (SDN)), the control functions and the forwarding functions of network module 115 are performed on physically separate devices, such that the control functions manage several different network hardware devices. Computer readable program instructions for performing the inventive methods can typically be downloaded to computer 101 from an external computer or external storage device through a network adapter card or network interface included in network module 115.
[0038] WAN 102 is any wide area network (for example, the internet) capable of communicating computer data over non-local distances by any technology for communicating computer data, now known or to be developed in the future. In some embodiments, the WAN 102 may be replaced and / or supplemented by local area networks (LANs) designed to communicate data between devices located in a local area, such as a Wi-Fi network. The WAN and / or LANs typically include computer hardware such as copper transmission cables, optical transmission fibers, wireless transmission, routers, firewalls, switches, gateway computers and edge servers.
[0039] END USER DEVICE (EUD) 103 is any computer system that is used and controlled by an end user (for example, a customer of an enterprise that operates computer 101), and may take any of the forms discussed above in connection with computer 101. EUD 103 typically receives helpful and useful data from the operations of computer 101. For example, in a hypothetical case where computer 101 is designed to provide a recommendation to an end user, this recommendation would typically be communicated from network module 115 of computer 101 through WAN 102 to EUD 103. In this way, EUD 103 can display, or otherwise present, the recommendation to an end user. In some embodiments, EUD 103 may be a client device, such as thin client, heavy client, mainframe computer, desktop computer and so on.
[0040] REMOTE SERVER 104 is any computer system that serves at least some data and / or functionality to computer 101. Remote server 104 may be controlled and used by the same entity that operates computer 101. Remote server 104 represents the machine(s) that collect and store helpful and useful data for use by other computers, such as computer 101. For example, in a hypothetical case where computer 101 is designed and programmed to provide a recommendation based on historical data, then this historical data may be provided to computer 101 from remote database 130 of remote server 104.
[0041] PUBLIC CLOUD 105 is any computer system available for use by multiple entities that provides on-demand availability of computer system resources and / or other computer capabilities, especially data storage (cloud storage) and computing power, without direct active management by the user. Cloud computing typically leverages sharing of resources to achieve coherence and economies of scale. The direct and active management of the computing resources of public cloud 105 is performed by the computer hardware and / or software of cloud orchestration module 141. The computing resources provided by public cloud 105 are typically implemented by virtual computing environments that run on various computers making up the computers of host physical machine set 142, which is the universe of physical computers in and / or available to public cloud 105. The virtual computing environments (VCEs) typically take the form of virtual machines from virtual machine set 143 and / or containers from container set 144. It is understood that these VCEs may be stored as images and may be transferred among and between the various physical machine hosts, either as images or after instantiation of the VCE. Cloud orchestration module 141 manages the transfer and storage of images, deploys new instantiations of VCEs and manages active instantiations of VCE deployments. Gateway 140 is the collection of computer software, hardware, and firmware that allows public cloud 105 to communicate through WAN 102.
[0042] Some further explanation of virtualized computing environments (VCEs) will now be provided. VCEs can be stored as “images.” A new active instance of the VCE can be instantiated from the image. Two familiar types of VCEs are virtual machines and containers. A container is a VCE that uses operating-system-level virtualization. This refers to an operating system feature in which the kernel allows the existence of multiple isolated user-space instances, called containers. These isolated user-space instances typically behave as real computers from the point of view of programs running in them. A computer program running on an ordinary operating system can utilize all resources of that computer, such as connected devices, files and folders, network shares, CPU power, and quantifiable hardware capabilities. However, programs running inside a container can only use the contents of the container and devices assigned to the container, a feature which is known as containerization.
[0043] PRIVATE CLOUD 106 is similar to public cloud 105, except that the computing resources are only available for use by a single enterprise. While private cloud 106 is depicted as being in communication with WAN 102, in other embodiments a private cloud may be disconnected from the internet entirely and only accessible through a local / private network. A hybrid cloud is a composition of multiple clouds of different types (for example, private, community or public cloud types), often respectively implemented by different vendors. Each of the multiple clouds remains a separate and discrete entity, but the larger hybrid cloud architecture is bound together by standardized or proprietary technology that enables orchestration, management, and / or data / application portability between the multiple constituent clouds. In this embodiment, public cloud 105 and private cloud 106 are both part of a larger hybrid cloud.
[0044] Generative artificial intelligence (GenAI) workloads refer to work involved in the process of performing inference using a GenAI model. A GenAI model can be built based on a large language model (LLM) or a foundation model, which can be built using transformer architecture. The transformer architecture uses the concept of self-attention. Self-attention is a mechanism that helps a model understand the relationships between different parts of an input sequence, like words in a sentence. For instance, self-attention captures the importance of each word to another word (relationship between each word) in an input sequence of words. This importance is computed as a self-attention score, and helps a transformer model focus on or ignore specific words at a specific moment. Generally, a transformer model works by generating query (Q), key (K) and value (V) vectors to each word in a sequence of words, and use the generated Q, K and V vectors to compute self-attention scores through a series of matrix multiplication. Briefly, query or Q represents the word currently being focused on and asks the rest of the words in the sentence, how relevant they are to the current word; key or K represents the characteristics of each word; value or V represents the actual information of each word. A system and / or method in some embodiments applies optimization to attention layers (e.g., in V-cache reads) in the GenAI model, which in turn reduces the load on the memory units of the hardware running the model.
[0045] The transformer architecture tokenizes words in input sequence into tokens, where the transformer model generates Q, K and V vectors to each token. A word can map to a token or multiple tokens. The description herein, for simplicity of explanation, refers to the term “word”, which at times can mean “token” in relation to the workings of a general transformer model. Further, while the description refers to words and a sequence of words or text, the techniques disclosed herein can apply to any other data sequence such as data that represent image data, acoustic data, and / or others.
[0046] FIG. 2 illustrates a self-attention computation in an attention score based value cache optimization in some embodiments. Self-attention is a building block of generative artificial intelligence (AI) (GenAI) workloads or models. Self-attention helps a GenAI model understand the input tokens or input sequence, based on the amount of attention that the GenAI model places on all the tokens (e.g., words) that came before a current token. Input 202 to this self-attention operation is an embedding vector for a current token that is being processed. GenAI models use self-attention to understand relationships between input tokens. Each token places an amount of “attention” on every other token based on their relative importance to each other. For input x, Q = MatMul (x, WQ); K = Concat (Prev-K, MatMul (x, WK)); V = Concat (Prev-V, MatMul (x, WV)); Attn-scores = MatMul(Q, KT); Self-attn(X) = MatMul (softmax (Attn-scores), V). Here “MatMul” refers to a matrix multiplication operation; “Concat” refers to a concatenation operation. Softmax is a function that takes raw output, e.g., a vector of numbers, and convert that raw output into a probability distribution; Softmax normalizes the raw output such that the sum of all the probabilities is 1.
[0047] For example, in a current decoding iteration, the input 202 is multiplied by three weight matrices, WQ at 204, WK at 206, and WV at 208 to obtain Q, K and V. Q refers to Query vector, K refers to Key vector and V refers to Value vector. Briefly, in each decoding iteration, a single token is produced. For instance, a decode iteration takes the previously produced token as input, and produces the next token. In order for a Gen AI model to produce the full output text sequence, the system and / or method runs multiple decoding iterations. For example, if the total output sequence has N words, the system and / or method runs one prefill iteration to produce the first output token and fills the KV-cache with the prompt vectors, and then runs N-1 decoding iterations. This process is referred to as the “decoding” or “generation” phase of model execution (vs. the “prefill” phase).
[0048] At 210, prior key vectors are read or retrieved. That is, for all the tokens that came before the current token, both in the prompt encoding phase and the previous decoding iterations, K vectors for all these prior tokens are retrieved from memory that stores K vectors. The K vectors are referred to as “K cache”. At 212, the result of the multiplication of the input 202 (input vector) with the weight matrix WK at 206 is concatenated with all previous values K cache at 210. The Concatenation at 212 produces K.
[0049] Similarly, at 214, prior value vectors are read or retrieved. In some embodiments, as will be described in more detail below, for all the tokens that came before the current token, both in the prompt encoding phase and the previous decoding iterations, V vectors of these prior tokens, whose attention scores meet a criterion with respect to the current token being processed, are read or retrieved from memory that stores V vectors. The V vectors are referred to as “V cache”. As will be described further in detail below, the criterion can be whether the attention scores are above a threshold value. Such threshold value can be configured and / or determined as will be described in further detail below. In some embodiments, the criterion can be determined based on the normalized attention scores computed at 220, which are input to 214. In some embodiments, self-attention mechanism is optimized, where rather than reading all previous V from V cache, only those that meet the criterion are read. Hence, the time to read the V vectors is reduced.
[0050] At 216, the result of the multiplication of the input 202 (input vector) with the weight matrix WV at 208 is concatenated with all previous values of V cache at 214. The concatenation at 216 produces V.
[0051] At 218, attention scores are computed by multiplying the result of the multiplication of the input 202 (input vector) with the weight matrix WQ at 204, which is a Q vector, with a transpose of the K matrix produced at 212.
[0052] At 220, the attention scores are normalized and bound between zero and one by passing the attention scores through a softmax operation. In some embodiments, the output of the softmax operation, i.e., normalized attention scores can be input to the processing at 214 for determining which previous V vectors are read from the V cache.
[0053] At 222, each of the vector read from the V cache is multiplied with their corresponding attention scores, and at 224 aggregated, producing an output 226, which is a new embedding representation for the current input 202. This new embedding is a context aware representation of the current input determined based on the current input’s relationship with all previous tokens in an input sequence in which the current input appears.
[0054] The self-attention operation is memory-bound because of the sizes of the K and V caches and the number of or the amount of data that needs to be read from the K and V caches often exceeds the size of the model itself. As a result, in many practical applications, reading those K and V caches accounts for the vast majority of the runtime. For instance, the K and V cache read times alone may accounting for 70 percent to 80 percent of the total execution time. As the prompt sizes increases for the generative AI models, this percentage may increase further. For instance, the actual computations may account for a small proportion of the total runtime, while the memory operations which includes reading from the K and V caches account for the most of the runtime for these generative AI models.
[0055] In addition, a conventional self-attention operation is inherently noisy because every token places an amount of attention on all the tokens that occurred before the current token, even if these tokens are completely unrelated to each other. FIG. 3 is a diagram that shows an example plot of normalized attention scores after a softmax operation. The X-axis shows the normalized attention scores and the Y-axis shows the number of entries that have a particular score. The plot shows that there are very few entries with large attention scores, but there are many entries that have very small non-zero attention scores. Aggregating these entries to produce the final representation for the token adds noise during this process, which degrades the quality of the output that is produced.
[0056] In some embodiments, a system, method and / or technique are provided that perform attention score based value cache optimization to optimize or minimize the cache read times and reduce the noise introduced in the self-attention operations, e.g., as shown in FIG. 2. In the conventional self-attention operation, every token that is processed places at least a small amount of attention on every other token that came before it. Small but non-zero attention scores can lead to noise during the self-attention operation process. The system, method and / or technique in some embodiments omit processing of, or ignore, those vectors that have very low attention with respect to the current token being processed. This helps the current token to only focus on those other tokens that are most relevant to understand its context. For instance, as shown at 214, only those tokens meeting a criterion or threshold are read from V cache. Also as shown at 220 and 214, the criterion or threshold may be determined dynamically based on normalized attention scores computed for a particular input.
[0057] FIG. 4 shows self-attention with V cache optimization in some embodiments. Consider a sentence or text sequence “The dog is running on the street” being processed under the self-attention operation as shown at 402, and consider that the self-attention scores with the current token, dog, is high for the tokens “running” and “street” as shown with solid lines, but low with respect to other tokens (e.g., normalized attention scores of less than 0.001, but non-zero still), for example, shown as dotted lines. The system, method and / or technique in some embodiments process only the vectors representing those tokens with high attention scores, for example, shown at 404 with solid lines. Attention noise elimination removes irrelevant token aggregations, where tokens with low attention scores are ignored, thereby reducing noise, and each token focuses only on those tokens that are most relevant to it. In the example shown, when the self-attention operation processes the word “dog”, all of the attention is focused on the two words, “running” and “street”, which are most relevant and provide the context needed to identify what “dog” is doing in this sentence. Aggregating other words in the sentence adds to the noise because they do not provide much meaning about the context of the word “dog”. By ignoring the attention scores with low values, the self-attention operation disclosed herein in some embodiments can reduce noise during the self-attention operation process and improve the quality of the output produced by the generative AI model by helping each token focus only on the other entries that are most relevant to that token.
[0058] In addition, this optimization helps improve efficiency because the entries from the V cache corresponding to the vectors with very low attention scores no longer need to be read and aggregated. FIG. 5 shows an attention score based value cache optimization efficiency improvement in some embodiments. In the example, if the current query 502 is the word (or token) “street” (e.g., shown as represented by a vector embedding 508), the self-attention operation looks at the normalized attention scores 504 that are produced after the softmax operation (e.g., performed at 220 in FIG. 2), and determines other words with which this particular query has high attention. According to the normalized attention scores 504, this query has high attention with the words “dog” and “running”, but has very low attention scores with all the other words that are stored in the value cache 506. Hence, in this example, the self-attention operation only needs to retrieve or read entries from the value cache 506 corresponding to those high attention score words, i.e., “dog” and “running”, and aggregate those two words to get a new representation for the word “street”. As a result, by ignoring the aggregations of tokens with low attention scores, the self-attention operation does not need to read those tokens from the value cache (V-cache) 506. The self-attention operation evaluates the normalized attention scores 504, for example, which can be in a vector form, selects those entries that have high scores, and reads those entries from the value cache 506, and aggregates those entries. By omitting those entries with low attention scores, the self-attention operation only reads a small subset of the entries in the value cache 506. For instance, value (V) vectors corresponding to low attention scores no longer need to be fetched. In cases where high attention scores are sparse, e.g., as shown by the plot in FIG. 3, significant reduction in memory traffic can be achieved. Also, the number of computations in the attention score and V matrix multiplication (e.g., shown at 222 in FIG. 2) to get the new representation for the input token is also reduced, because the irrelevant entries are no longer processed and aggregated.
[0059] In some embodiments, whether an attention score is high or low to use them or omit them in the self-attention processing can be determined based on a threshold or a criterion. Various automated methods can be used to determine this optimal threshold. For instance, attention scores that are smaller than this threshold can be safely ignored or omitted in self-attention processing. In one embodiment, finding this threshold includes an automated search with a validation set. This method automates a search for an optimal threshold by trying different threshold values as candidate threshold values on a validation set that is independent from both the training and the testing data set. A validation set is a small representative subset of the inputs that a generative AI model is likely to see. The method may extract a validation set from a larger training set. For instance, the method may create a validation set by taking a training set and randomly select a percentage (e.g., 5%) of all samples in the training set. Using the samples in the validation set, the method runs a generative AI model using the self-attention operation disclosed herein with various candidate threshold values. By way of example only, a candidate threshold value of 0.5 can be used, then a candidate threshold value of 0.4 can be used in a next set of runs, then a candidate threshold value of 0.3 can be used in a subsequent set of runs, and so on. Hence, different threshold values can be used in running a generative AI model with the validation set as input. The candidate threshold values can be ranked in the order of loss. A loss function is a mathematical function that measures the distance between the predictions of a neural network and the actual target values (labels), and is typically used to determine how good a neural network is in performing a given task. The method chooses a threshold value that gives the minimum value of the loss (indicating best output quality) in the generative AI model’s output, and the method uses this threshold value as the optimal threshold value, for pruning the value cache reads or retrieval. This method can be a fully automated procedure with no hand-crafted hyperparameters that need to be pre-configured.
[0060] Another method for determining the threshold value for attention scores is a data-driven thresholding based on score histograms. This method provides even greater flexibility. For each input in each layer and for each attention head, after computing the normalized attention scores (e.g., shown at 220 in FIG. 2), the method plots a histogram of those attention scores. The method determines an optimal threshold value based on the maximum attention score in the histogram and an overall distribution, e.g., measured by standard deviation. For instance, by comparing the maximum attention score in the histogram with the overall distribution, which is measured by the standard deviation, the method determines which scores are likely to be irrelevant. The method computes the standard deviation. The entries that have attention scores less than the difference between the maximum attention score and a predefined multiple of the standard deviation are considered to have low attention score and can be ignored in the computation. In some embodiments, the predefined multiple can be determined by evaluating different values (e.g., 1 x standard deviation, 2 x standard deviation) on running a generative AI model using a validation set. Different layers, or even different heads (e.g., multi-head attention) in the same layer can have different types of distributions. This method provides different threshold values for specific layers, heads, and inputs, e.g., rather than having a global threshold value. This method allows flexibility in that the method can select a different absolute threshold value for ignoring attention scores for each head layer, decoding iteration, and for each input, allowing for maximum flexibility in pruning and keeping only the relevant entries that help the context. For example, different layers, or even different heads in the same layer can have different types of distributions.
[0061] In some embodiments, the threshold value can be a user-defined parameter, where the attention score values less than this parameter are ignored. In some embodiments, this threshold can be set to a very small number (e.g., 0.0001) to denote that attention scores less than this value are truly “noise”.
[0062] In some embodiments, the self-attention operation with V-cache optimization as described herein is applied on each input for each decoding iteration, for each transformer layer, and for each head inside the transformer layer. This self-attention operation can occur in parallel, e.g., attention heads operating in parallel. In each occurrence, a different set of words (tokens) can be selected based on a threshold value, e.g., an optimal set from a V cache independently from the set of tokens chosen in all other occurrences.
[0063] Various test results show that self-attention operation in some embodiments can reduce the amount of time spent in reading from the value cache by about 50%, which can further increase the speed of overall processing of a generative AI model, while also simultaneously improving the quality of outputs produced by the model. The system, method and / or technique disclosed herein also requires no retraining or additional fine tuning, since such operations can become costly in terms of time and computing resources. Larger efficiency gains can be expected for larger context lengths, since the number of high attention scores typically remains constant irrespective of context length. For example, as context lengths get larger, the self-attention operation can ignore, disregard or omit a greater proportion of entries from the value cache.
[0064] FIG. 6 is a diagram illustrating a value cache logical and physical layout in some embodiments. In some embodiments, key (K) and value (V) cache entries are stored as “paged” tensors. Such paged storage maximizes memory utilization by allowing contiguous key and value vectors to be stored in non-contiguous memory locations. Contiguous logical blocks of a tensor (“pages”) are mapped to non-contiguous physical blocks in memory using block tables. For example, contiguous logical V cache blocks 602 are stored in non-contiguous physical V cache blocks 604 in memory. A V cache can be divided into pages (blocks) where a page contains a subset of entries. These pages can be stored in discontinuous locations in memory. The system, method and / or technique in some embodiments utilize paging to fetch a different set of entries from the cache for each head and for each input in a batch. Indirect memory access is used to fetch disjointed parts of the V cache tensor. For example, different parts of the tensor can be accessed through indirect memory access. Using such techniques, disjointed locations in memory can be accessed to read or retrieve only those words that are considered to have high attention score (e.g., attention score above a threshold). Such page layout can maximize the utilization of available space in a given memory, and also can be useful in reading from discontiguous locations in memory without losing performance, compared to contiguous reads.
[0065] In some embodiments, to avoid performance losses, the system, method and / or technique selects a page size such that fetching one page fully utilizes the available memory bandwidth, so that the reading from discontiguous locations does not slow the performance as compared to reading from contiguous memory locations. For example, depending on a particular computing environment and / or processor configuration, certain amount of data should be fetched for full memory bandwidth utilization. Consider by way of example, that for a chosen computing environment, a processor should fetch one kilobyte (KB) of data at any given time for full memory bandwidth utilization to avoid loss in performance. Consider also that the hidden size of each V cache vector is typically 128. Consider also by way of example that, in a multi-head attention LLM model, page size = 1KB / (128 * 2B) = 4 in floating point 16, implying that 4 entries from the V cache are placed in one page and should be fetched together. In another example, with grouped query attention LLM model where 4 KV-heads share a single Q-head, page size = 1KB / (128 * 4 * 2B) = 1, which implies that one entry in V-cache is placed in each page. In this example, all entries can be fetched independently one-by-one without performance loss.
[0066] Following with the above example, an implementation may place every four entries in the V-cache as one page. In some embodiments, a cache read occurs at the page granularity rather than at the individual vector granularity. For example, if one entry in a page needs to be read, all entries in the page are read. Hence, the full page is read with all four entries in the page. Irrelevant entries are masked before a computation is performed. For example, prior to performing the attention score and V matrix multiplication (e.g., shown at 222 in FIG. 2), if the page read contains one or more entries that have attention scores smaller than the threshold value, the self-attention operation masks those entries. Masking can include substituting the values of those entries with zeroes, so that after the computation, these entries have no bearing on the result of the attention score and V matrix multiplication. Masking does not change or overwrite entries in the V-cache.
[0067] Using the physical V-cache blocks 604 as an example, the self-attention operation reads block 3 that is mapped to the logical V-cache block for “running”, to retrieve the word “running”. Block 3, however, also contains an entry corresponding to the word “is”. Since the word “is” considered to have a low attention score, that entry is masked before performing an attention score and V matrix multiplication.
[0068] Test results illustrate that the self-attention mechanism with V cache optimization disclosed herein can speed up cache reads and an end-to-end generative AI model performance. High attention scores often occur in clusters rather than being randomly distributed. If one entry in the page has a high attention score, it is likely that other entries in the same page have high attention scores, because these high attention score value words occur in clusters. In some embodiments, each page includes V vectors of consecutive tokens. Reading multiple entries simultaneously when reading a page does not adversely affect the sparsity of the self-attention operation disclosed herein. In some cases, an overall unstructured vector sparsity translates almost directly to the page read sparsity. For instance, with page size = 4, the page read sparsity with V-cache may be 54%, compared to 59% overall read sparsity.
[0069] In some embodiments, the self-attention operation based on V-cache optimization uses actual attention scores to reduce memory traffic, and hence, is reactive and need not be predictive. The self-attention operation based on V-cache optimization does not actually evict entries from the V-cache. The self-attention operation based on V-cache optimization allows a different set of tokens to be selected in each head, layer and decoding iteration, allowing for maximum memory traffic reduction. In some embodiments, since the system and / or method uses actual attention scores to sub-select V-vectors (e.g., the system and / or method only eliminates aggregations of tokens with attention scores lower than a threshold), the system and / or method does not accidentally remove important tokens and only reduces noise in attention, leading to simultaneous output quality and efficiency improvements. The self-attention operation based on V-cache optimization does not require any additional training or fine-tuning, and consequently can provide a plug-and-play applicability to off-the-shelf foundation models or large language models.
[0070] In some embodiments, the self-attention operation based on V-cache optimization leads to accuracy gains by eliminating noisy aggregations in each head and decoding iteration independently. For example, with the self-attention operation based on V-cache optimization, different number of tokens can be selected in each head, layer and decoding step. The self-attention operation based on V-cache optimization provides enhanced sparsity in V-reads. For example, an optimal number of attention scores are retained in each head, layer and decoding iteration independent of others. The self-attention operation based on V-cache optimization exploits unique computational characteristics of inference during generation phase (latency is determined by traffic from K-cache and V-cache) to also improve latency.
[0071] As described above a computer-implemented method in some embodiments, during a generative AI model run, ignore tokens with low attention scores (as determined using a threshold or criterion) in performing attention score – V matrix multiplication, where the method automatically determines the threshold (e.g., without additional re-training or fine-tuning), allowing the generative AI model to focus on relevant tokens, and hence improve output quality.
[0072] The computer-implemented method also exploits increased sparsity in attention scores to reduce the amount of data read from the V-cache, reducing memory traffic and easing the memory bottleneck during decoding, leading to efficiency gains.
[0073] The computer-implemented method further enables and exploits three simultaneous axes of freedom in V-cache sub-selection, where different tokens can be selected in each head, layer and decoding iteration, where there is a complete independence across layers, heads and queries in tokens selected, leading to maximum reduction in memory reads during decoding. For instance, the system and / or method allows a different set of V-vectors or V-cache to be selected (i.e., different set of tokens to be considered) in each layer, head and decoding iteration. By way of example, the system and / or method can consider token A in layer i+1 even when token A was not used in layer i. Similarly, if token A is useful only in layers 2 and 4 but not in layers 1 and 3, the system and / or method uses these tokens only in layers 2 and 4. Consequently, the three axes of freedom in the system and / or method in some embodiments allows for maximal memory traffic reduction, ensuring that only the necessary tokens are read from the V-cache in each head, layer and decoding iteration. The system and / or method can be complementary to, and can be combined with existing predictive token pruning techniques, since further efficiency gains can be achieved by ignoring tokens with low attention scores (based on a threshold determination) from among the retained tokens retained by such existing predictive token pruning techniques.
[0074] In some embodiments, the system and / or method does not actually evict any entries from the V-cache. As a result, even if a token in the cache is not used in the current decoding iteration, it can be used in future iterations (i.e., each query selects only its most relevant tokens, independent of prior and future queries). For instance, the system and / or method may maximally reduce the amount of data read from the V-cache, thereby eliminating a cause of the bottleneck during decoding. In some embodiments, during execution, the amount of data read from V-cache can be much fewer compared to the amount of data read from K-cache.
[0075] FIG. 7 is a flow diagram illustrating a method for an attention score based value cache optimization in some embodiments. The method can be performed on or by one or more computer or hardware processors, e.g., but not limited to, running on a computing environment shown in FIG. 1.
[0076] At 702, during performing a self-attention computation by a generative artificial intelligence (AI) model implemented based on transformer architecture and running on at least one processor, the method includes selectively reading page blocks of cache memory that store value vectors representing information associated with tokens of an input sequence, by reading the page blocks corresponding to the tokens that have attention scores meeting a criterion and omitting to read the page blocks corresponding to the tokens that have attention scores not meeting the criterion. For instance, as discussed above, selectively reading includes reading only the page blocks corresponding to the tokens that have attention scores meeting a criterion, where the page blocks corresponding to the tokens that have attention scores not meeting the criterion are omitted from reading.
[0077] At 704, the method also include performing an attention scores-value matrix multiplication of the self-attention computation, using the value vectors stored in the page blocks of the cache memory that are read. For instance, only the value vectors in the page blocks of the cache memory that are read participate in the self-attention computation. Consequently, the tokens that have attention scores not meeting the criterion are ignored from the self-attention computation.
[0078] In some embodiments, the criterion includes meeting a threshold (e.g., an attention score threshold). In some embodiments, as discussed above, the threshold is determined based on running the generative AI model using a plurality of candidate thresholds on a validation dataset, where the threshold is selected from the plurality of candidate thresholds based on the threshold having been used in a run of the generative AI model having a minimum loss.
[0079] In some embodiments, as also discussed above, the threshold is determined based on determining a maximum attention score among a set of attention scores corresponding to the input sequence, determining a standard deviation of the set of attention scores, where the threshold is determined as a difference between the maximum attention score and a predetermined multiple of the standard deviation.
[0080] In some embodiments, as discussed above, the predetermined multiple is predetermined based on running the generative AI model using a plurality of candidate values on a validation dataset, and a candidate value to use as the predetermined multiple is selected from the plurality of candidate values based on a run of the generative AI model having a minimum loss.
[0081] In some embodiments, as discussed above, different tokens are selected in each head of the generative AI model in performing the attention scores-value matrix multiplication. In some embodiments, different tokens are selected in each layer of the generative AI model in performing the attention scores-value matrix multiplication. In some embodiments, different tokens are selected in each decoding iteration of the generative AI model in performing the attention scores-value matrix multiplication.
[0082] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention. As used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. As used herein, the term “or” is an inclusive operator and can mean “and / or”, unless the context explicitly or clearly indicates otherwise. It will be further understood that the terms "comprise", "comprises", "comprising", "include", "includes", "including", and / or "having," when used herein, can specify the presence of stated features, integers, steps, operations, elements, and / or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or groups thereof. As used herein, the phrase “in some embodiments” does not necessarily refer to the same embodiment, although it may. As used herein, the phrase “in one embodiment” does not necessarily refer to the same embodiment, although it may. As used herein, the phrase “in another embodiment” does not necessarily refer to a different embodiment, although it may. Further, embodiments and / or components of embodiments can be freely combined with each other unless they are mutually exclusive.
[0083] The corresponding structures, materials, acts, and equivalents of all means or step plus function elements, if any, in the claims below are intended to include any structure, material, or act for performing the function in combination with other claimed elements as specifically claimed. The description of the present invention has been presented for purposes of illustration and description, but is not intended to be exhaustive or limited to the invention in the form disclosed. Many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the invention. The embodiment was chosen and described in order to best explain the principles of the invention and the practical application, and to enable others of ordinary skill in the art to understand the invention for various embodiments with various modifications as are suited to the particular use contemplated.
Claims
1. A computer-implemented method comprising:during performing a self-attention computation by a generative artificial intelligence (AI) model implemented based on transformer architecture and running on at least one processor, selectively reading page blocks of cache memory that store value vectors representing information associated with tokens of an input sequence, by reading the page blocks corresponding to the tokens that have attention scores meeting a criterion and omitting to read the page blocks corresponding to the tokens that have attention scores not meeting the criterion; andperforming an attention scores-value matrix multiplication of the self-attention computation, using the value vectors stored in the page blocks of the cache memory that are read,wherein the tokens that have attention scores not meeting the criterion are ignored from the self-attention computation.
2. The computer-implemented method of claim 1, wherein the criterion includes meeting a threshold, the threshold being determined based on running the generative AI model using a plurality of candidate thresholds on a validation dataset, wherein the threshold is selected from the plurality of candidate thresholds based on the threshold having been used in a run of the generative AI model having a minimum loss.
3. The computer-implemented method of claim 1, wherein the criterion includes meeting a threshold, the threshold being determined based on determining a maximum attention score among a set of attention scores corresponding to the input sequence, determining a standard deviation of the set of attention scores, wherein the threshold is determined as a difference between the maximum attention score and a predetermined multiple of the standard deviation.
4. The computer-implemented method of claim 3, wherein the predetermined multiple is predetermined based on running the generative AI model using a plurality of candidate values on a validation dataset, and a candidate value to use as the predetermined multiple is selected from the plurality of candidate values based on a run of the generative AI model having a minimum loss.
5. The computer-implemented method of claim 1, wherein different tokens are selected in each head of the generative AI model in performing the attention scores-value matrix multiplication.
6. The computer-implemented method of claim 1, wherein different tokens are selected in each layer of the generative AI model in performing the attention scores-value matrix multiplication.
7. The computer-implemented method of claim 1, wherein different tokens are selected in each decoding iteration of the generative AI model in performing the attention scores-value matrix multiplication.
8. A computer program product comprising:one or more computer-readable storage media; andprogram instructions stored on the one or more storage media to perform operations comprising:during performing a self-attention computation by a generative artificial intelligence (AI) model implemented based on transformer architecture and running on at least one processor, selectively reading page blocks of cache memory that store value vectors representing information associated with tokens of an input sequence, by reading the page blocks corresponding to the tokens that have attention scores meeting a criterion and omitting to read the page blocks corresponding to the tokens that have attention scores not meeting the criterion; andperforming an attention scores-value matrix multiplication of the self-attention computation, using the value vectors stored in the page blocks of the cache memory that are read, wherein the tokens that have attention scores not meeting the criterion are ignored from the self-attention computation.
9. The computer program product of claim 8, wherein the criterion includes meeting a threshold, the threshold being determined based on running the generative AI model using a plurality of candidate thresholds on a validation dataset, wherein the threshold is selected from the plurality of candidate thresholds based on the threshold having been used in a run of the generative AI model having a minimum loss.
10. The computer program product of claim 8, wherein the criterion includes meeting a threshold, the threshold being determined based on determining a maximum attention score among a set of attention scores corresponding to the input sequence, determining a standard deviation of the set of attention scores, wherein the threshold is determined as a difference between the maximum attention score and a predetermined multiple of the standard deviation.
11. The computer program product of claim 10, wherein the predetermined multiple is predetermined based on running the generative AI model using a plurality of candidate values on a validation dataset, and a candidate value to use as the predetermined multiple is selected from the plurality of candidate values based on a run of the generative AI model having a minimum loss.
12. The computer program product of claim 8, wherein different tokens are selected in each head of the generative AI model in performing the attention scores-value matrix multiplication.
13. The computer program product of claim 8, wherein different tokens are selected in each layer of the generative AI model in performing the attention scores-value matrix multiplication.
14. The computer program product of claim 8, wherein different tokens are selected in each decoding iteration of the generative AI model in performing the attention scores-value matrix multiplication.
15. A computer system comprising:a processor set;a set of one or more computer-readable storage media;program instructions, collectively stored in the set of one or more computer-readable storage media, for causing the processor set to perform the following computer operations:during performing a self-attention computation by a generative artificial intelligence (AI) model implemented based on transformer architecture and running on the processor set, selectively reading page blocks of cache memory that store value vectors representing information associated with tokens of an input sequence, by reading the page blocks corresponding to the tokens that have attention scores meeting a criterion and omitting to read the page blocks corresponding to the tokens that have attention scores not meeting the criterion; andperforming an attention scores-value matrix multiplication of the self-attention computation, using the value vectors stored in the page blocks of the cache memory that are read, wherein the tokens that have attention scores not meeting the criterion are ignored from the self-attention computation.
16. The computer system of claim 15, wherein the criterion includes meeting a threshold, the threshold being determined based on running the generative AI model using a plurality of candidate thresholds on a validation dataset, wherein the threshold is selected from the plurality of candidate thresholds based on the threshold having been used in a run of the generative AI model having a minimum loss.
17. The computer system of claim 15, wherein the criterion includes meeting a threshold, the threshold being determined based on determining a maximum attention score among a set of attention scores corresponding to the input sequence, determining a standard deviation of the set of attention scores, wherein the threshold is determined as a difference between the maximum attention score and a predetermined multiple of the standard deviation.
18. The computer system of claim 17, wherein the predetermined multiple is predetermined based on running the generative AI model using a plurality of candidate values on a validation dataset, and a candidate value to use as the predetermined multiple is selected from the plurality of candidate values based on a run of the generative AI model having a minimum loss.
19. The computer system of claim 15, wherein different tokens are selected in each head of the generative AI model in performing the attention scores-value matrix multiplication.
20. The computer system of claim 15, wherein different tokens are selected in each layer of the generative AI model in performing the attention scores-value matrix multiplication.
