Token processing with continuous prefilling and caching
The transformer server application with continuous prefilling and caching techniques addresses latency issues in transformer-based systems by processing input chunks ahead of time, reducing post-completion prefilling work and enhancing responsiveness in applications like voice assistants and chat systems.
Patent Information
- Application Number
- US19/739863
- Authority / Receiving Office
- US · United States
- Patent Type
- Applications(United States)
- Current Assignee / Owner
- Priority Date
- 2022-10-31
- Filing Date
- 2026-07-13
- Publication Date
- 2026-11-26
AI Technical Summary
Conventional transformer-based token processing systems experience delays in generating responses due to prefilling operations being performed only after the input stream is complete, particularly for lengthy inputs, leading to increased latency and reduced responsiveness in applications like voice assistants and chat systems.
Implement a transformer server application with a scheduler that performs continuous prefilling and caching by generating cache entries for chunks of input tokens before the input stream is complete, using a trained machine learning model to process and store key-value data in a KV cache, and updating it based on edits, allowing for immediate decoding upon input completion.
Reduces latency and improves responsiveness by minimizing post-completion prefilling work, enabling faster generation of output tokens and reducing redundant computations through reuse of cached information.
Smart Images

Figure US20260377318A1-D00000_ABST
Abstract
Description
BACKGROUNDTechnical Field
[0001] Embodiments of the present disclosure relate generally to computer science, artificial intelligence (AI), and machine learning, and, more specifically, to techniques for token processing with continuous prefilling and caching.Description of the Related Art
[0002] Transformer-based token processing systems are machine learning systems that process inputs to generate responses. A transformer model is a type of machine learning model that processes a sequence of input items, referred to as “tokens,” such as words or portions of words, and uses attention operations to determine relationships among the input items. For example, when a user speaks a question into a voice assistant or types a question into a user interface, the user input can be converted into tokens, which are smaller units of text that a transformer model is able to process, and the transformer model can process the tokens to generate output tokens that form a response to the user.
[0003] In conventional transformer-based token processing systems, a user input is typically processed after the user has finished providing the input. For example, after a user finishes speaking, typing, or otherwise submitting an input stream, the token processing system can convert the completed input stream into tokens and perform a prefilling operation on the tokens. During the prefilling operation, the transformer model processes the tokens and generates key-value data for use during output token generation. After the prefilling operation is complete, the transformer model uses the key-value data to generate output tokens that form a response to the user.
[0004] One drawback of the above approach is that, because the prefilling operation is performed only after the input stream is complete, a delay exists between when a user provides an input to the system and when a response is generated by the system. Further, the delay can increase when the input stream includes many tokens, causing the system to wait for all of those tokens before performing the prefilling operation and then generating output tokens. As a result, voice assistants, chat systems, coding assistants, and other interactive transformer-based token processing systems can be slow or unresponsive, particularly when generating responses to lengthy spoken, typed, or other inputs that are received over time.
[0005] As the foregoing illustrates, what is needed in the art are more effective techniques for token processing.SUMMARY
[0006] One embodiment of the present disclosure includes a computer-implemented method for responding to inputs using a trained machine learning model. The method includes generating, based at least on a first portion of an input stream, one or more first tokens. The method also includes accumulating the one or more first tokens into a first chunk. The method further includes performing, using the trained machine learning model and prior to completion of the input stream, a first prefilling operation to generate one or more first cache entries based at least on the first chunk. In addition, the method includes, in response to determining that the input stream is complete, generating, using the trained machine learning model, one or more output tokens based at least on cached information that includes the one or more first cache entries.
[0007] Other embodiments of the present disclosure include, without limitation, one or more computer-readable media including instructions for performing one or more aspects of the disclosed techniques as well as a computing device for performing one or more aspects of the disclosed techniques.
[0008] At least one technical advantage of the disclosed techniques relative to the prior art is that the disclosed techniques reduce latency in machine learning systems, such as transformer-based systems, that process real-time input streams. The disclosed techniques reduce an amount of prefilling work that remains after an input stream is complete and can reduce a time between completion of the input stream and generation of a first output token. The disclosed techniques can also reduce redundant computations by reusing cache entries generated for previously processed tokens, while maintaining consistency of cached information (e.g., a key-value cache) when input data is edited or deleted. Accordingly, the disclosed techniques can improve responsiveness of voice assistants, chat interfaces, coding assistants, and other machine learning-based applications while reducing compute delays associated with processing long input sequences.
[0009] These technical advantages provide one or more technological improvements over prior art approaches.BRIEF DESCRIPTION OF THE DRAWINGS
[0010] So that the manner in which the above recited features of the various embodiments can be understood in detail, a more particular description of the inventive concepts, briefly summarized above, can be had by reference to various embodiments, some of which are illustrated in the appended drawings. It is to be noted, however, that the appended drawings illustrate only typical embodiments of the inventive concepts and are therefore not to be considered limiting of scope in any way, and that there are other equally effective embodiments.
[0011] FIG. 1 is a block diagram of a computer system configured to implement one or more aspects of various embodiments;
[0012] FIG. 2 is a more detailed illustration of the computing device of FIG. 1, according to various embodiments;
[0013] FIG. 3 is a more detailed illustration of the transformer server application of FIG. 1, according to various embodiments;
[0014] FIG. 4 illustrates an example of continuous prefilling and caching, according to various embodiments; and
[0015] FIG. 5 is a flow diagram of method steps for generating one or more output tokens, according to various embodiments.DETAILED DESCRIPTION
[0016] In the following description, numerous specific details are set forth to provide a more thorough understanding of the various embodiments. However, it will be apparent to one skilled in the art that the concepts can be practiced without one or more of these specific details.General Overview
[0017] As described, transformer-based token processing systems can generate responses to inputs, such as audio data, text data, speech data, transcript data, or other input-stream data, that is converted into tokens for processing by a transformer model. The transformer model processes the tokens using attention operations that generate key data and value data. The key data and value data can be stored in a key-value cache for reuse during generation of output tokens. However, in conventional systems, a prefilling operation for generating the key data and the value data typically does not begin until after a user has finished providing an input stream. As a result, when the input stream includes many tokens or is received over an extended period of time, the system can wait until the input stream is complete before processing the tokens to populate the key-value cache, causing a delay between completion of the input stream and generation of a first output token. Such operations can waste processing cycles, graphics-processing resources, memory bandwidth, and cache resources while increasing the time to generate the first token of a response, reducing responsiveness of voice assistants, user interfaces, coding assistants, and other interactive transformer-based token processing systems, as well as limiting the ability of such systems to reuse key-value data generated for earlier portions of an input stream before later portions of the input stream are received.
[0018] Embodiments of the present disclosure provide techniques for token processing with continuous prefilling and caching. The disclosed techniques include a transformer server application that uses a transformer model to process an input stream and generate one or more output tokens. The transformer model is a trained machine learning model, such as a neural network. In some embodiments, the transformer server application includes a scheduler that schedules operations performed by, among other things, a chunk generator, a tokenizer, a prefilling module, a decoding module, and a key-value (KV) cache editing module. Although described herein primarily with respect to transformer models and KV caches as a reference example, techniques disclosed herein can be applied to any technically feasible machine learning models, such as other generative models, that use cached information. The tokenizer processes the input stream and generates one or more tokens. The chunk generator accumulates the tokens into a chunk. Once the chunk is generated, the scheduler schedules prefilling based on the chunk. During prefilling, the prefilling module uses the transformer model to perform a prefilling operation to generate KV entries based on the chunk. The prefilling module stores the KV entries in a KV cache. In some embodiments, the scheduler determines whether there is an edit in the input stream. When the scheduler determines an edit in the input stream, the scheduler schedules an update to the KV cache based on the edit. The KV cache editing module updates the KV cache based on the edit. In some embodiments, the scheduler determines whether the input stream is complete. When the scheduler determines that the input stream is complete, the scheduler schedules decoding. During decoding, the decoding module uses the transformer model to process the KV cache and one or more most recently generated tokens in an autoregressive manner to generate the output tokens.System Overview
[0019] FIG. 1 illustrates a block diagram of a computer-based system 100 configured to implement one or more aspects of at least one embodiment. As shown, system 100 includes a data store 121 and a computing device 140 in communication over a network 130. Network 130 can be a wide area network (WAN), such as the Internet; a local area network (LAN); a cellular network; and / or any other suitable network. Data store 121 includes, without limitation, a transformer model 124. Computing device 140 includes, without limitation, one or more processors 142 and a memory 144. Memory 144 includes, without limitation, a transformer server application 146 and a key-value (KV) cache 125. Transformer server application 146 includes, without limitation, a scheduler 147, a chunk generator 148, a tokenizer 149, a prefilling module 150, a decoding module 151, and a KV cache editing module 152.
[0020] Processor(s) 142 receive user input from input devices, such as a keyboard or a mouse. Processor(s) 142 may include one or more primary processors of computing device 140, and processor(s) 142 control and coordinate operations of other system components. In particular, processor(s) 142 can issue commands that control the operation of one or more graphics processing units (GPUs) (not shown) and / or other parallel processing circuitry (e.g., parallel processing units, deep learning accelerators, etc.) that incorporates circuitry optimized for graphics and video processing and includes, for example, video output circuitry. The GPU(s) can deliver pixels to a display device, and the display device can be any conventional cathode ray tube, liquid crystal display, light-emitting diode display, and / or similar technologies.
[0021] Memory 144 of computing device 140 stores content, such as software applications and data, for use by processor(s) 142 and the GPU(s) and / or other processing units. Memory 144 can be any type of memory capable of storing data and software applications, such as a random-access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash ROM), a high-bandwidth memory (HBM), GPU memory, or any suitable combination of the foregoing. In some embodiments, a storage (not shown) can supplement or replace memory 144. The storage can include any number and type of external memories that are accessible to processor(s) 142 and / or the GPU(s). For example, and without limitation, the storage can include an external Flash memory, an optical storage device, a magnetic storage device, a network-accessible storage device, and / or any suitable combination of the foregoing.
[0022] Computing device 140 shown herein is for illustrative purposes only, and variations and modifications are possible without departing from the scope of the present disclosure. For example, the number of processors 142, the number of GPUs and / or other processing unit types, and the number of memories 144 can be modified as desired. Further, the connection topology between the various units in FIG. 1 can be modified as desired. In some embodiments, any combination of processor(s) 142, memory 144, and GPUs can be included in and / or replaced with any type of virtual computing system, distributed computing system, and / or cloud computing environment, such as a public, private, or hybrid cloud system.
[0023] As shown, transformer server application 146 executes on processor(s) 142 of computing device 140. In some embodiments, transformer server application 146 transformer model 124, which is stored in data store 121 and accessed via network 130, as well as KV cache 125 to process an input stream and generate one or more output tokens. Transformer model 124 is a trained machine learning model, such as a neural network, that processes input data and generates output data based on relationships among the input data. In some embodiments, transformer server application 146 receives input stream 301 via a network message, an application programming interface (API) call, a streaming communication session, a web-based interface, a voice-assistant interface, a user interface, a file upload, another software application, or the like. In some embodiments, input stream 301 includes text data, audio data, speech data, and / or any other input data associated with a user input. In some embodiments, the input stream includes one or more edits, such as deletions, insertions, replacements, cursor-positions, and / or other modification events associated with text data, audio data, and / or speech data. In some embodiments, transformer server application 146 can output responses generated using transformer model 124 in any suitable manner, such as by converting output tokens into audio using a text-to-speech model / process and causing the audio to be output to a user via a speaker device, by displaying output responses via a user interface, and / or the like. In some embodiments, transformer server application 146 implements, extends, interfaces with, or includes one or more transformer-serving systems, such as an inference-serving framework configured to execute transformer model 124. Transformer server application 146 is described in greater detail herein at least in conjunction with FIGS. 3-5.
[0024] FIG. 2 is a more detailed illustration of computing device 140, according to various embodiments. Computing device 140 may include any type of computing system, including, without limitation, a server machine, a server platform, a desktop machine, a laptop machine, a handheld / mobile device, a digital kiosk, an in-vehicle infotainment system, and / or a wearable device. In some embodiments, computing device 140 is a server machine operating in a data center or a cloud computing environment that provides scalable computing resources as a service over a network.
[0025] As shown, computing device 140 includes, without limitation, processor(s) 142 and memory 144 coupled to a parallel processing subsystem 262 via a memory bridge 255 and a communication path 263. Memory bridge 255 is further coupled to an I / O (input / output) bridge 257 via a communication path 256, and I / O bridge 257 is, in turn, coupled to a switch 266.
[0026] In some embodiments, I / O bridge 257 is configured to receive user input information from optional input devices 258, such as a keyboard, mouse, touch screen, or sensor data analysis device, and / or forward the input information to processor(s) 142 for processing. In some embodiments, computing device 140 may be a server machine in a cloud computing environment. In some embodiments, computing device 140 may not include input devices 258 but may receive equivalent input information by receiving commands in the form of messages transmitted over a network and received via network adapter 268. In some embodiments, switch 266 is configured to provide connections between I / O bridge 257 and other components of computing device 140, such as network adapter 268 and various add-in cards 270 and 271.
[0027] In some embodiments, I / O bridge 257 is coupled to a system disk 264 that may be configured to store content, applications, and data for use by processor(s) 142 and parallel processing subsystem 262. In some embodiments, system disk 264 provides non-volatile storage for applications and data and may include fixed or removable hard disk drives, flash memory devices, and CD-ROM, DVD-ROM, Blu-ray, HD DVD, or other magnetic, optical, or solid-state storage devices. In various embodiments, other components, such as universal serial bus or other port connections, compact disc drives, digital versatile disc drives, film recording devices, and the like, may be connected to I / O bridge 257 as well.
[0028] In various embodiments, memory bridge 255 may be a Northbridge chip, and I / O bridge 257 may be a Southbridge chip. In addition, communication paths 256 and 263, as well as other communication paths within computing device 140, may be implemented using any technically suitable protocols, including, without limitation, AGP, HyperTransport, PCI Express, or any other bus or point-to-point communication protocol known in the art.
[0029] In some embodiments, parallel processing subsystem 262 comprises a graphics subsystem that delivers pixels to display device 272, which may be any conventional cathode ray tube display, liquid crystal display, light-emitting diode display, organic light-emitting diode display, head-mounted display, projection display, and / or the like. In some embodiments, parallel processing subsystem 262 may incorporate circuitry that is optimized for graphics and video processing, including, for example, video output circuitry. Such circuitry may be incorporated across one or more parallel processing units (PPUs), also referred to herein as parallel processors, included within parallel processing subsystem 262.
[0030] In some embodiments, parallel processing subsystem 262 incorporates circuitry that is optimized for general-purpose and / or compute processing. Again, such circuitry may be incorporated across one or more PPUs included within parallel processing subsystem 262 that are configured to perform such general-purpose and / or compute operations. In yet other embodiments, the one or more PPUs included within parallel processing subsystem 262 may be configured to perform graphics processing, general-purpose processing, and / or compute processing operations. Memory 144 includes at least one device driver configured to manage the processing operations of the one or more PPUs within parallel processing subsystem 262. In addition, memory 144 includes, without limitation, transformer server application 146. Although described herein primarily with respect to transformer server application 146, techniques disclosed herein can also be implemented, either entirely or in part, in other software and / or hardware, such as in parallel processing subsystem 262.
[0031] In various embodiments, parallel processing subsystem 262 may be integrated with one or more of the other elements of FIG. 2 to form a single system. For example, parallel processing subsystem 262 may be integrated with processor(s) 142 and other connection circuitry on a single chip to form a system on a chip (SoC).
[0032] In some embodiments, processor(s) 142 includes the primary processor of computing device 140, controlling and coordinating operations of other system components. In some embodiments, processor(s) 142 issues commands that control the operation of the one or more PPUs. In some embodiments, communication path 263 is a PCI Express link, in which dedicated lanes are allocated to each PPU. Other communication paths may also be used. The PPU advantageously implements a highly parallel processing architecture, and the PPU may be provided with any amount of local parallel processing memory.
[0033] It will be appreciated that the system shown herein is illustrative and that variations and modifications are possible. The connection topology, including the number and arrangement of bridges, the number of processor(s) 142, and the number of parallel processing subsystems 262, may be modified as desired. For example, in some embodiments, memory 144 could be connected to processor(s) 142 directly rather than through memory bridge 255, and other devices may communicate with memory 144 via memory bridge 255 and processor(s) 142. In other embodiments, parallel processing subsystem 262 may be connected to I / O bridge 257 or directly to processor(s) 142, rather than to memory bridge 255. In still other embodiments, I / O bridge 257 and memory bridge 255 may be integrated into a single chip instead of existing as one or more discrete devices. In some embodiments, one or more components shown in FIG. 2 may not be present. For example, switch 266 could be eliminated, and network adapter 268 and add-in cards 270 and 271 would connect directly to I / O bridge 257. Lastly, in some embodiments, one or more components shown in FIG. 2 may be implemented as virtualized resources in a virtual computing environment, such as a cloud computing environment. In particular, parallel processing subsystem 262 may be implemented as a virtualized parallel processing subsystem in at least one embodiment. For example, parallel processing subsystem 262 may be implemented as virtual graphics processing unit(s) (vGPU(s)) that render graphics on virtual machine(s) executing on server machine(s) whose GPU(s) and other physical resources are shared across one or more virtual machine(s).Continuous Prefilling and Caching
[0034] FIG. 3 is a more detailed illustration of transformer server application 146, according to various embodiments. As shown, transformer server application 146 includes, without limitation, scheduler 147, chunk generator 148, tokenizer 149, prefilling module 150, decoding module 151, and KV cache editing module 152. In operation, scheduler 147 schedules operations performed by, among other things, tokenizer 149, chunk generator 148, prefilling module 150, decoding module 151, and KV cache editing module 152. In some embodiments, scheduler 147 can be aware of the underlying hardware resources (e.g., GPUs) and perform any technically feasible scheduling. Tokenizer 149 processes input stream 301 and generates one or more tokens 302. Chunk generator 148 accumulates tokens 302 into a chunk 304. Once chunk 304 is generated, prefilling module 150 uses transformer model 124 to perform a prefilling operation to generate one or more KV entries 306 based on chunk 304 and a prefilling task 305 that is dispatched by scheduler 147. Prefilling module 150 stores KV entries 306 in KV cache 125. Although described herein primarily with respect to transformer models and KV caches as a reference example, techniques disclosed herein can be applied to any technically feasible machine learning models, such as other generative models, that use cached information. In some embodiments, scheduler 147 determines whether there is an edit in input stream 301. When scheduler 147 determines an edit in input stream 301, scheduler 147 dispatches an editing task 303 based on the edit. KV cache editing module 152 edits KV cache 125 based on editing task 303. In some embodiments, scheduler 147 determines whether input stream 301 is complete. When scheduler 147 determines that input stream 301 is complete, scheduler 147 dispatches a decoding task 307. Upon receiving decoding task 307, decoding module 151 uses transformer model 124 to process KV cache 125 and one or more most recently generated tokens in an autoregressive manner to generate one or more output tokens 308.
[0035] Tokenizer 149 is a module of transformer server application 146 that processes input stream 301 and generates tokens 302. In some embodiments, input stream 301 includes text data that tokenizer 149 converts into tokens 302. In some embodiments, tokenizer 149 converts the text data into tokens 302 according to a tokenization scheme associated with transformer model 124. In some embodiments, tokens 302 include token identifiers, subword tokens, wordpiece tokens, byte-pair encoding tokens, sentencepiece tokens, byte-level tokens, and / or any other units that can be processed by transformer model 124. In some embodiments, input stream 301 includes audio data. In such cases, tokenizer 149 uses a speech-to-text model, which is a trained machine learning model such as a neural network, to process audio data included in input stream 301 and generate text data corresponding to the audio data. In addition, tokenizer 149 converts the text data into tokens 302. For example, in some embodiments, the speech-to-text model can include a connectionist temporal classification (CTC) model, a transducer model, an attention-based encoder-decoder model, an automatic speech recognition model, a transformer-based model, a Conformer-based model, or any other model configured to map an acoustic signal to text data. In some embodiments, the speech-to-text model includes an encoder implemented using a transformer architecture, a Conformer architecture that combines transformer operations and convolution operations, or another neural network architecture configured to process the audio data. In some embodiments, the text data generated by the speech-to-text model is aligned with diarization output, event-detection output, or other timing information, such that the text data indicates one or more of spoken content, a speaker associated with the spoken content, a time associated with the spoken content, and / or background-event information associated with the spoken content. In some embodiments, tokenizer 149 generates tokens 302 while input stream 301 is being received, such that tokens 302 are available before input stream 301 is complete.
[0036] Chunk generator 148 is a module of transformer server application 146 that accumulates a number of tokens 302 into chunk 304. In some embodiments, chunk 304 corresponds to a unit of prefilling work that is processed by transformer model 124 to populate KV cache 125. In some embodiments, chunk 304 corresponds to a block or page of cached tokens in KV cache 125. In some embodiments, chunk 304 corresponds to a chunked-prefill unit and / or corresponds to a block or page of cached tokens, such as a block used in a PagedAttention memory-management technique. In some embodiments, chunk generator 148 generates multiple chunks from input stream 301 while input stream 301 is being received. In some embodiments, when input stream 301 is complete, chunk generator 148 generates a final chunk that includes fewer tokens than a previously completed chunk. In some embodiments, chunk generator 148 can determine that chunk 304 is complete when chunk 304 satisfies a chunk-completion condition, such as including a threshold number of tokens 302, including a predetermined number of tokens 302, corresponding to a threshold amount of text data, corresponding to a linguistic boundary, corresponding to a time interval of input stream 301, and / or the like. In some embodiments, each chunk 304, except a last chunk generated from input stream 301, can have a chunk size of four or more tokens. It should be noted that smaller chunk sizes can reduce a time-to-first-token (TTFT) between the end of an input stream and the first token of a generated response when techniques disclosed herein are used to prefill a KV cache, but smaller chunk sizes introduce processing overhead.
[0037] In some embodiments, scheduler 147 dispatches prefilling task 305 for prefilling module 150 to perform prefilling based on chunk 304. In some embodiments, prefilling task 305 identifies chunk 304, a position of chunk 304 within input stream 301, one or more cache locations associated with chunk 304, and / or one or more parameters for processing chunk 304 using transformer model 124.
[0038] Prefilling module 150 uses transformer model 124 to perform a prefilling operation to generate KV entries 306 based on chunk 304 and prefilling task 305. In some embodiments, transformer model 124 includes a neural network model based on a transformer architecture. A transformer architecture uses attention operations to process relationships among tokens in a sequence. In some embodiments, transformer model 124 includes one or more attention layers, feed-forward layers, residual connections, normalization layers, positional encodings, learned positional embeddings, relative positional encodings, rotary positional embeddings, and / or any other components associated with transformer-based sequence processing. In some embodiments, transformer model 124 can be an encoder-only model, a decoder-only model, or an encoder-decoder model. In some embodiments, prefilling module 150 uses transformer model 124 to perform a prefilling operation on chunk 304 before input stream 301 is complete. During the prefilling operation, transformer model 124 ingests input tokens from chunk 304 and populates KV cache 125 with KV entries 306 corresponding to the input tokens. Multiple token positions can be processed in parallel during the prefilling operation. As described, in conventional transformer-based token processing systems, a latency associated with a prefilling operation after an input stream is complete can contribute to a TTFT, and the TTFT can increase as a length of the input stream increases.
[0039] In some embodiments, during a prefilling operation, transformer model 124 processes the tokens included in chunk 304 and generates key data and value data associated with the tokens. For example, for input activations X corresponding to the tokens included in chunk 304, the attention layers of transformer model 124 can generate query data Q, key data K, and value data V according to:Q=XWQ K=XWK V=XWV, (Equation 1)where WQ, WK, and WV are model parameters of transformer model 124. In some embodiments, transformer model 124 performs an attention operation based on Q, K, and V according to:Attention (Q,K,V)=softmax (QKTdk)V,(Equation 2)where KT denotes a transpose of K, and dk corresponds to a dimension of the key data K. KV entries 306 include the key data K and the value data V generated by one or more attention layers of transformer model 124. In some embodiments, KV entries 306 are associated with one or more token positions, one or more layer identifiers, one or more attention-head identifiers, one or more cache locations, and / or one or more sequence identifiers corresponding to chunk 304. Prefilling module 150 stores KV entries 306 in KV cache 125 so that KV entries 306 can be used during a subsequent decoding operation.KV cache 125 is a memory structure that stores KV entries 306 generated by transformer model 124 during one or more prefilling operations. KV cache 125 stores key data and value data for tokens 302 that have already been processed by transformer model 124. In some embodiments, KV cache 125 stores KV entries 306 on a per-layer basis, a per-attention-head basis, a per-token-position basis, a per-sequence-position basis, a per-chunk basis, a per-request basis, or any combination thereof. For example, in some embodiments, KV cache 125 can store key data and value data having a shape based on a batch size, a number of attention heads, a sequence length, and a head dimension. In some embodiments, the memory size of KV cache 125 is based on 2×a number of layers×a number of attention heads×a head dimension×a sequence length×a batch size×a number of bytes per stored element. KV cache 125 can be implemented in any technically feasible manner in some embodiments, including using system memory, GPU memory, high-bandwidth memory, a paged memory structure, a block-based memory structure, a distributed memory structure, a quantized memory structure, or any other memory structure suitable for storing key data and value data generated by transformer model 124. In some embodiments, KV cache 125 is implemented using a multi-query attention (MQA) configuration, a grouped-query attention (GQA) configuration, or another configuration that reduces a number of key-value heads stored in KV cache 125. In some embodiments, KV cache 125 stores KV entries 306 using a quantized format, such as an int8 format, an fp8 format, or another reduced-precision format.In some embodiments, scheduler 147 determines whether there is an edit in input stream 301. In such cases, the edit can include, without limitation, an insertion, deletion, replacement, correction, cursor movement, truncation, or other modification in the input stream 301, such as an edit to text data that was previously entered via a user interface, an edit in audio-derived text data, an edit referenced in audio data, or the like. In some embodiments, the edit can be determined from text that is included in or derived from input stream 301. In some embodiments, when scheduler 147 determines that the edit affects one or more tokens 302 for which KV entries 306 have been stored in KV cache 125, scheduler 147 generates editing task 303. In some embodiments, editing task 303 can identify one or more affected tokens 302, one or more affected chunks 304, one or more token positions, one or more sequence positions, one or more cache locations, and / or one or more KV entries 306 to be modified, removed, or invalidated. In such cases, scheduler 147 can track the positions within KV cache 125 at which KV entries corresponding to different tokens from chunks 304 are stored, as well as associated temporal information. In some embodiments, KV cache editing module 152 edits KV cache 125 based on editing task 303. KV cache editing module 152 edits KV cache 125 based on editing task 303 so that KV cache 125 corresponds to a current version of input stream 301. In some embodiments, when the edit includes a deletion of text data in input stream 301 or tokens 302, KV cache editing module 152 removes or invalidates one or more KV entries 306 corresponding to the deleted text data or tokens 302, and chunk generator 148 resumes accumulation of tokens 302 from a position in input stream 301 associated with the deletion.In some embodiments, scheduler 147 determines whether input stream 301 is complete. In such cases, scheduler 147 can determine that input stream 301 is complete based on an end-of-input indication (e.g., another machine learning model outputting a lack of activity signal indicating completion of input stream 301), a user-submitted input, a send command, a pause in received audio data, an end-of-speech indication, an end-of-stream message, or another indication that no additional input data is expected. When scheduler 147 determines that input stream 301 is complete, scheduler 147 generates decoding task 307. In some embodiments, decoding task 307 can identify KV cache 125, one or more KV entries 306 stored in KV cache 125, one or more sequence positions associated with input stream 301, and / or one or more decoding parameters. Decoding module 151 uses transformer model 124 to process KV cache 125 and decoding task 307 to generate output tokens 308, without recomputing key data and value data for tokens 302 previously processed during prefilling. The decoding operation is an autoregressive inference operation in which transformer model 124 generates output tokens 308 one token at a time. During each decoding step, transformer model 124 can process a single most recent token or a small number of recent tokens, compute query data, key data, and value data for a current output token 308, retrieve previously stored key data and value data from KV cache 125, and perform an attention operation using the retrieved key data and value data. In some embodiments, decoding module 151 appends key data and value data generated for one or more output tokens 308 to KV cache 125. In some embodiments, decoding module 151 generates output tokens 308 autoregressively by generating a next output token based at least on KV entries 306 and one or more previously generated output tokens 308. In an autoregressive decoding operation, when transformer model 124 generates a token at position t, a causal self-attention operation can use key data and value data associated with prior positions 1, . . . , t−1. Because the key data and value data for the prior positions do not change when a new output token 308 is generated, KV cache 125 allows transformer model 124 to reuse the previously generated key data and value data instead of recomputing that data at each decoding step.In some embodiments, prefilling and decoding have different computational characteristics. For example, a prefilling operation can process multiple tokens 302 in parallel using dense matrix operations and can be compute-bound, while a decoding operation can process one or a small number of output tokens 308 at a time, repeatedly accessing KV cache 125, and can be memory-bandwidth-bound. In some embodiments, per-token latency during decoding corresponds to time per output token (TPOT) or inter-token latency. The asymmetry between compute-bound prefilling and memory-bandwidth-bound decoding can affect operation of transformer server application 146. For example, transformer-serving techniques can use continuous batching to pack decoding steps from multiple requests together, chunked prefilling to interleave prefilling operations and decoding operations, and / or disaggregated serving to execute prefilling operations and decoding operations using different hardware resources. By scheduling prefilling operations for chunks 304 before input stream 301 is complete, transformer server application 146 can reduce an amount of compute-bound prefilling work that remains after input stream 301 is complete and can allow decoding module 151 to begin memory-bandwidth-bound decoding operations sooner.
[0045] Because prefilling module 150 can generate KV entries 306 for completed chunks 304 while input stream 301 is still being received, transformer server application 146 can reduce the delay between completion of input stream 301 and generation of a first output token 308. In a conventional transformer-serving system, a prefilling operation is typically performed for an entire input sequence after the input sequence is complete. Thus, if input stream 301 includes N tokens 302, the conventional transformer-serving system would perform post-completion prefilling for N tokens before decoding begins. By contrast, transformer server application 146 performs prefilling operations for one or more completed chunks 304 before input stream 301 is complete, such that KV cache 125 already stores KV entries 306 for those completed chunks 304 when input stream 301 is complete. If chunk 304 has a chunk size C, and a final chunk 304 includes R tokens 302, where R≤C, then transformer server application 146 can perform post-completion prefilling for only the R tokens 302 included in the final chunk 304 before decoding begins. Accordingly, a post-completion prefilling workload can be reduced from N tokens 302 to R tokens 302. In some embodiments, the reduction in post-completion prefilling workload can be represented asN-RN.Because R≤C, the reduction can be at leastN-CN.In some embodiments, a prefill contribution to time to first token can be reduced from approximately Tprefill(N) to approximately Tprefill(R), where Tprefill(N) represents a time to perform prefilling for N tokens and Tprefill(R) represents a time to perform prefilling for R tokens. For example, when N=4096 tokens and C=256 tokens, no more than 256 tokens remain to be prefilled after input stream 301 is complete, and the post-completion prefilling workload can be reduced by at least4096-2564096=0.9375,or 93.75 percent relative to prefilling all 4096 tokens after input stream 301 is complete. Such a reduction allows decoding module 151 to begin generating output tokens 308 after prefilling the final chunk 304 instead of after prefilling all tokens 302 included in input stream 301.FIG. 4 illustrates an example of continuous prefilling and caching, according to various embodiments. As shown, an input stream 401 includes audio data corresponding to the spoken input “Can you help me find my nearest grocery store?” Tokenizer 149 processes input stream 401 and generates tokens 402 corresponding to the spoken input in input stream 401. In some embodiments, tokenizer 149 includes and / or uses a speech-to-text model that processes the audio data in input stream 401 and generates text data, and tokenizer 149 further converts the text data into tokens 402. In some embodiments, when an input stream includes text rather than audio data, tokenizer 149 can convert the text into tokens.Chunk generator 148 accumulates tokens 402 into multiple chunks, including a first chunk 411a, a second chunk 411b, and a third chunk 411c. As shown, first chunk 411a includes tokens corresponding to “Can you help me,” second chunk 411b includes tokens corresponding to “find my nearest grocery,” and third chunk 411c includes tokens corresponding to “store?” In some embodiments, third chunk 411c is a final chunk that includes fewer tokens than one or more previously completed chunks 411a and 411b. As first chunk 411a and second chunk 411b are generated while input stream 401 is being received, scheduler 147 can generate a prefilling task 305 for the corresponding chunk before all of input stream 401 has been processed. After third chunk 411c is generated, scheduler 147 can generate prefilling task 305 for third chunk 411c. Prefilling module 150 uses transformer model 124 to process first chunk 411a to generate KV entries 410a, process second chunk 411b to generate KV entries 410b, and process third chunk 411c to generate KV entries 410c. KV entries 410a-410c are stored in KV cache 403, which can correspond to KV cache 125 of FIG. 3. In this manner, KV cache 403 is populated incrementally while input stream 401 is being received, rather than waiting until input stream 401 is complete before generating KV entries 410a-410c for all tokens 402.After KV cache 403 stores KV entries 410c corresponding to final chunk 411c, scheduler 147 dispatches decoding task 307 to decoding module 151. Decoding module 151 uses transformer model 124 to process KV cache 403 and decoding task 307 to generate output tokens 404. As shown, output tokens 404 can include tokens corresponding to a response, such as “Sure,”“let,”“me,”“look,”“into,”“that,”“for,” and “you.” Because KV entries 410a and 410b were generated before input stream 401 was complete, transformer server application 146 can begin generating output tokens 404 after prefilling final chunk 411c, thereby reducing a delay between completion of input stream 401 and generation of a first output token in output tokens 404.FIG. 5 is a flow diagram of method steps for generating output tokens 308, according to various embodiments. Although the method steps are described in conjunction with the systems of FIGS. 1-4, persons skilled in the art will understand that any system configured to perform the method steps in any order falls within the scope of the present embodiments.
[0051] As shown, a method 500 begins with step 501, where transformer server application 146 receives input stream 301. In some embodiments, transformer server application 146 receives input stream 301 via a network message, an API call, a streaming communication session, a web-based interface, a voice-assistant interface, a user interface, a file upload, or another software application. In some embodiments, input stream 301 includes text data, audio data, speech data, and / or any other input data associated with a user input. In some embodiments, input stream 301 includes one or more edits, such as deletions, insertions, replacements, cursor-positions, and / or other modification events associated with text data, audio data, or speech data.
[0052] At step 502, tokenizer 149 generates tokens 302 based on input stream 301. In some embodiments, tokenizer 149 includes a speech-to-text model, which is a trained machine learning model, that processes audio data included in input stream 301 and generates text data corresponding to the audio data, and tokenizer 149 converts the text data into tokens 302. In such cases, tokenizer 149 can convert the text data into tokens 302 according to a tokenization scheme associated with transformer model 124. In some embodiments, tokens 302 include token identifiers, subword tokens, wordpiece tokens, byte-pair encoding tokens, sentencepiece tokens, byte-level tokens, or any other units that can be processed by transformer model 124. In some embodiments, the text data generated by the speech-to-text model is aligned with diarization output, event-detection output, or other timing information, such that the text data indicates one or more of spoken content, a speaker associated with the spoken content, a time associated with the spoken content, and / or background-event information associated with the spoken content. In some embodiments, tokenizer 149 generates tokens 302 while input stream 301 is being received, such that tokens 302 are available before input stream 301 is complete.
[0053] At step 503, chunk generator 148 accumulates tokens 302 into a chunk 304. In some embodiments, chunk 304 corresponds to a unit of prefilling work that is processed by transformer model 124 to populate KV cache 125. In some embodiments, chunk 304 corresponds to a block or page of cached tokens in KV cache 125. In some embodiments, chunk 304 corresponds to a chunked-prefill unit and / or corresponds to a block or page of cached tokens. In some embodiments, chunk generator 148 generates multiple chunks from input stream 301 while input stream 301 is being received. In some embodiments, when input stream 301 is complete, chunk generator 148 generates a final chunk that includes fewer tokens than a previously generated chunk. In some embodiments, chunk generator 148 can determine that chunk 304 is complete when chunk 304 satisfies a chunk-completion condition, such as including a threshold number of tokens 302, including a predetermined number of tokens 302, corresponding to a threshold amount of text data, corresponding to a linguistic boundary, corresponding to a time interval of input stream 301, and / or the like. It should be noted that smaller chunk sizes can reduce a TTFT between the end of an input stream and the first token of a generated response when techniques disclosed herein are used to prefill a KV cache, but smaller chunk sizes introduce processing overhead.
[0054] At step 504, scheduler 147 dispatches prefilling task 305. In some embodiments, scheduler 147 generates prefilling task 305 for chunk 304. In some embodiments, prefilling task 305 identifies chunk 304, a position of chunk 304 within input stream 301, one or more cache locations associated with chunk 304, and / or one or more parameters for processing chunk 304 using transformer model 124.
[0055] At step 505, prefilling module 150 performs, using transformer model 124, a prefilling operation to generate KV entries 306 based on prefilling task 305 and chunk 304. In some embodiments, transformer model 124 includes a neural network model based on a transformer architecture. In some embodiments, prefilling module 150 causes transformer model 124 to perform a prefilling operation on chunk 304 before input stream 301 is complete. During the prefilling operation, transformer model 124 ingests input tokens from chunk 304 and populates KV cache 125 with KV entries 306 corresponding to the input tokens. Multiple token positions can be processed in parallel during the prefilling operation.
[0056] More specifically, during the prefilling operation, transformer model 124 processes the tokens included in chunk 304 and generates key data and value data associated with the tokens. For example, for input activations X corresponding to the tokens included in chunk 304, the attention layers of transformer model 124 can generate query data Q, key data K, and value data V according to Equation 1. In some embodiments, transformer model 124 performs an attention operation based on Q, K, and V according to Equation 2. In some embodiments, KV entries 306 are associated with one or more token positions, one or more layer identifiers, one or more attention-head identifiers, one or more cache locations, and / or one or more sequence identifiers corresponding to chunk 304. Prefilling module 150 stores KV entries 306 in KV cache 125 so that KV entries 306 can be used during a subsequent decoding operation.
[0057] At step 506, scheduler 147 determines whether input stream 301 is complete. In some embodiments, scheduler 147 can determine that input stream 301 is complete based on an end-of-input indication from a trained machine learning model or elsewhere, a user-submitted input, a send command, a pause in received audio data, an end-of-speech indication, an end-of-stream message, or another indication that no additional input data is expected. When scheduler 147 determines input stream 301 is not complete, the method 500 returns to step 501, where transformer server application 146 receives an additional portion of input stream 301. When scheduler 147 determines that input stream 301 is complete, the method 500 proceeds to step 507.
[0058] At step 507, scheduler 147 dispatches a decoding task 307. In some embodiments, decoding task 307 can identify KV cache 125, one or more KV entries 306 stored in KV cache 125, one or more sequence positions associated with input stream 301, and / or one or more decoding parameters.
[0059] At step 508, decoding module 151 generates, using transformer model 124, output tokens 308 based on decoding task 307 and KV cache 125. In some embodiments, decoding module 151 uses transformer model 124 to process KV cache 125 and decoding task 307 to generate output tokens 308 without recomputing key data and value data for tokens 302 previously processed during prefilling. The decoding operation is an autoregressive inference operation in which transformer model 124 generates output tokens 308 one token at a time. During each decoding step, transformer model 124 can process a single most recent token or a small number of recent tokens, compute query data, key data, and value data for a current output token 308, retrieve previously stored key data and value data from KV cache 125, and perform an attention operation using the retrieved key data and value data. In some embodiments, decoding module 151 appends key data and value data generated for one or more output tokens 308 to KV cache 125. In some embodiments, decoding module 151 generates output tokens 308 autoregressively by generating a next output token based at least on KV entries 306 and one or more previously generated output tokens 308. In an autoregressive decoding operation, when transformer model 124 generates a token at position t, a causal self-attention operation can use key data and value data associated with prior positions 1, . . . , t−1. Because the key data and value data for the prior positions do not change when a new output token 308 is generated, KV cache 125 allows transformer model 124 to reuse the previously generated key data and value data instead of recomputing that data at each decoding step. In some embodiments, transformer server application 146 can output responses generated using transformer model 124 in any suitable manner, such as by converting output tokens generated by transformer model 124 into audio using a text-to-speech model / process and causing the audio to be output to a user via a speaker device, by displaying output responses that include the output tokens via a user interface, and / or the like.
[0060] At step 509, scheduler 147 determines whether there is an edit in input stream 301. In some embodiments, the edit can include an insertion, deletion, replacement, correction, cursor movement, truncation, or other modification included in the input stream 301, such as an edit to text data that was previously entered via a user interface, audio-derived text data, audio data, or the like. In some embodiments, the edit can be determined from text that is included in or derived from input stream 301. When scheduler 147 determines there is an edit in input stream 301, the method 500 continues to step 510. When scheduler 147 determines there is no edit in input stream 301, the method 500 proceeds to step 502.
[0061] At step 510, scheduler 147 dispatches editing task 303. In some embodiments, when scheduler 147 determines that the edit affects one or more tokens 302 for which KV entries 306 have been stored in KV cache 125, scheduler 147 generates editing task 303. In some embodiments, editing task 303 can identify one or more affected tokens 302, one or more affected chunks 304, one or more token positions, one or more sequence positions, one or more cache locations, or one or more KV entries 306 to be modified, removed, or invalidated.
[0062] At step 511, KV cache editing module 152 edits KV cache 125 based on editing task 303. In some embodiments, KV cache editing module 152 edits KV cache 125 based on editing task 303 so that KV cache 125 corresponds to a current version of input stream 301. In some embodiments, when the edit includes a deletion of text data in input stream 301 or tokens 302, KV cache editing module 152 removes or invalidates one or more KV entries in KV cache 125 that correspond to the deleted text data or tokens 302, and chunk generator 148 resumes accumulation of tokens 302 from a position in input stream 301 associated with the deletion. In some embodiments, scheduler 147 can track the positions within KV cache 125 at which KV entries corresponding to different tokens from chunks 304 are stored, as well as associated temporal information, allowing scheduler 147 to later remove or invalidate entries in KV cache 125 corresponding to deleted tokens. The method 500 then returns to step 501, where transformer server application 146 receives the rest of input stream 301.
[0063] In sum, techniques are disclosed for token processing with continuous prefilling and caching. The disclosed techniques include a transformer server application that uses a transformer model to process an input stream and generate one or more output tokens. The transformer model is a trained machine learning model, such as a neural network. In some embodiments, the transformer server application includes a scheduler that schedules operations performed by, among other things, a chunk generator, a tokenizer, a prefilling module, a decoding module, and a KV cache editing module. Although described herein primarily with respect to transformer models and KV caches as a reference example, techniques disclosed herein can be applied to any technically feasible machine learning models, such as other generative models, that use cached information. The tokenizer processes the input stream and generates one or more tokens. The chunk generator accumulates the tokens into a chunk. Once the chunk is generated, the scheduler schedules prefilling based on the chunk. During prefilling, the prefilling module uses the transformer model to perform a prefilling operation to generate KV entries based on the chunk. The prefilling module stores the KV entries in a KV cache. In some embodiments, the scheduler determines whether there is an edit in the input stream. When the scheduler determines an edit in the input stream, the scheduler schedules an update to the KV cache based on the edit. The KV cache editing module updates the KV cache based on the edit. In some embodiments, the scheduler determines whether the input stream is complete. When the scheduler determines that the input stream is complete, the scheduler schedules decoding. During decoding, the decoding module uses the transformer model to process the KV cache and one or more most recently generated tokens in an autoregressive manner to generate the output tokens.
[0064] At least one technical advantage of the disclosed techniques relative to the prior art is that the disclosed techniques reduce latency in machine learning systems, such as transformer-based systems, that process real-time input streams. The disclosed techniques reduce an amount of prefilling work that remains after an input stream is complete and can reduce a time between completion of the input stream and generation of a first output token. The disclosed techniques can also reduce redundant computations by reusing cache entries generated for previously processed tokens, while maintaining consistency of cached information (e.g., a key-value cache) when input data is edited or deleted. Accordingly, the disclosed techniques can improve responsiveness of voice assistants, chat interfaces, coding assistants, and other machine learning-based applications while reducing compute delays associated with processing long input sequences.
[0065] These technical advantages provide one or more technological improvements over prior art approaches.
[0066] 1. In some embodiments, a computer-implemented method for responding to inputs using a trained machine learning model includes generating, based at least on a first portion of an input stream, one or more first tokens, accumulating the one or more first tokens into a first chunk, performing, using the trained machine learning model and prior to completion of the input stream, a first prefilling operation to generate one or more first cache entries based at least on the first chunk, and in response to determining that the input stream is complete, generating, using the trained machine learning model, one or more output tokens based at least on cached information that includes the one or more first cache entries.
[0067] 2. The computer-implemented method of clause 1, further including generating, based at least on a second portion of the input stream, one or more second tokens, accumulating the one or more second tokens into a second chunk, and performing, using the trained machine learning model, a second prefilling operation to generate one or more second cache entries included in the cached information based at least on the second chunk.
[0068] 3. The computer-implemented method of clauses 1 or 2, where the first chunk includes a first number of tokens, and the second chunk includes a second number of tokens.
[0069] 4. The computer-implemented method of any of clauses 1-3, where accumulating the one or more first tokens into the first chunk includes determining that the first chunk satisfies a chunk-completion condition.
[0070] 5. The computer-implemented method of any of clauses 1-4, where the chunk-completion condition includes the input stream satisfying at least one of a threshold number of tokens, a predefined number of tokens, a threshold amount of text data, a linguistic boundary, or a predefined time interval.
[0071] 6. The computer-implemented method of any of clauses 1-5, where the first chunk includes at least one of a block or a page of tokens.
[0072] 7. The computer-implemented method of any of clauses 1-6, where the trained machine learning model includes a transformer model, where the one or more first cache entries include key data and value data generated by one or more attention layers included in the transformer model, and where the cached information includes a key-value cache.
[0073] 8. The computer-implemented method of any of clauses 1-7, where generating the one or more output tokens includes autoregressively generating, based at least on the one or more first cache entries, a next output token included in the one or more output tokens.
[0074] 9. The computer-implemented method of any of clauses 1-8, further including in response to determining that the input stream includes an edit, performing at least one of modifying, removing, or invalidating one or more second cache entries included in the cached information.
[0075] 10. The computer-implemented method of any of clauses 1-9, where generating the one or more first tokens includes generating, using a trained speech-to-text model, text data based at least on audio data included in the first portion of the input stream.
[0076] 11. In some embodiments, one or more non-transitory computer-readable media store instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of generating, based at least on a first portion of an input stream, one or more first tokens, accumulating the one or more first tokens into a first chunk, performing, using a trained machine learning model and prior to completion of the input stream, a first prefilling operation to generate one or more first cache entries based at least on the first chunk, and in response to determining that the input stream is complete, generating, using the trained machine learning model, one or more output tokens based at least on cached information that includes the one or more first cache entries.
[0077] 12. The one or more non-transitory computer-readable media of clause 11, where accumulating the one or more first tokens into the first chunk includes determining that the first chunk satisfies a chunk-completion condition.
[0078] 13. The one or more non-transitory computer-readable media of clauses 11 or 12, where the chunk-completion condition includes the input stream satisfying at least one of a threshold number of tokens, a predefined number of tokens, a threshold amount of text data, a linguistic boundary, or a predefined time interval.
[0079] 14. The one or more non-transitory computer-readable media of any of clauses 11-13, where the trained machine learning model includes a transformer model, where the one or more first cache entries include key data and value data generated by one or more attention layers included in the transformer model, and where the cached information includes a key-value cache.
[0080] 15. The one or more non-transitory computer-readable media of any of clauses 11-14, where generating the one or more first tokens includes generating, using a trained speech-to-text model, text data based at least on audio data included in the first portion of the input stream, and converting the text data into the one or more first tokens.
[0081] 16. The one or more non-transitory computer-readable media of any of clauses 11-15, where the instructions, when executed by the one or more processors, further cause the one or more processors to perform the step of, in response to determining that the input stream includes an edit, performing at least one of modifying, removing, or invalidating one or more second cache entries included in the cached information.
[0082] 17. The one or more non-transitory computer-readable media of any of clauses 11-16, where determining that the input stream is complete includes determining that the input stream satisfies an input-completion condition.
[0083] 18. The one or more non-transitory computer-readable media of any of clauses 11-17, where the input-completion condition includes at least one of an end-of-input indication, a user-submitted input, a send command, a pause in audio data, an end-of-speech indication, an end-of-stream message, or an indication that no additional input data is expected.
[0084] 19. The one or more non-transitory computer-readable media of any of clauses 11-18, where the instructions, when executed by the one or more processors, further cause the one or more processors to perform the step of storing the one or more first cache entries in the cached information using at least one of a per-layer basis, a per-attention-head basis, a per-token-position basis, a per-sequence-position basis, a per-chunk basis, a per-request basis, or a quantized format.
[0085] 20. In some embodiments, a system includes one or more memories storing instructions, and one or more processors that are coupled to the one or more memories and, when executing the instructions generate, based at least on a first portion of an input stream, one or more first tokens, accumulate the one or more first tokens into a first chunk, perform, using a trained machine learning model and prior to completion of the input stream, a first prefilling operation to generate one or more first cache entries based at least on the first chunk, and in response to determining that the input stream is complete, generate, using the trained machine learning model, one or more output tokens based at least on cached information that includes the one or more first cache entries.
[0086] Any and all combinations of any of the claim elements recited in any of the claims and / or any elements described in this application, in any fashion, fall within the contemplated scope of the present disclosure and protection.
[0087] The descriptions of the various embodiments have been presented for purposes of illustration, but are not intended to be exhaustive or limited to the embodiments 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 described embodiments.
[0088] Aspects of the present embodiments may be embodied as a system, method or computer program product. Accordingly, aspects of the present disclosure may take the form of an entirely hardware embodiment, an entirely software embodiment (including firmware, resident software, micro-code, etc.) or an embodiment combining software and hardware aspects that may all generally be referred to herein as a “module” or “system.” Furthermore, aspects of the present disclosure may take the form of a computer program product embodied in one or more computer readable medium(s) having computer readable program code embodied thereon.
[0089] Any combination of one or more computer readable medium(s) may be utilized. The computer readable medium may be a computer readable signal medium or a computer readable storage medium. A computer readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. More specific examples (a non-exhaustive list) of the computer readable storage medium would include the following: an electrical connection having one or more wires, a portable computer diskette, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this document, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
[0090] Aspects of the present disclosure are described above with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the disclosure. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus to produce a machine. The instructions, when executed via the processor of the computer or other programmable data processing apparatus, enable the implementation of the functions / acts specified in the flowchart and / or block diagram block or blocks. Such processors may be, without limitation, general purpose processors, special-purpose processors, application-specific processors, or field-programmable gate arrays.
[0091] The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and / or flowchart illustration, and combinations of blocks in the block diagrams and / or flowchart illustration, can be implemented by special purpose hardware-based systems that perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
[0092] While the preceding is directed to embodiments of the present disclosure, other and further embodiments of the disclosure may be devised without departing from the basic scope thereof, and the scope thereof is determined by the claims that follow.
Claims
1. A computer-implemented method for responding to inputs using a trained machine learning model, the method comprising:generating, based at least on a first portion of an input stream, one or more first tokens;accumulating the one or more first tokens into a first chunk;performing, using the trained machine learning model and prior to completion of the input stream, a first prefilling operation to generate one or more first cache entries based at least on the first chunk; andin response to determining that the input stream is complete, generating, using the trained machine learning model, one or more output tokens based at least on cached information that includes the one or more first cache entries.
2. The computer-implemented method of claim 1, further comprising:generating, based at least on a second portion of the input stream, one or more second tokens;accumulating the one or more second tokens into a second chunk; andperforming, using the trained machine learning model, a second prefilling operation to generate one or more second cache entries included in the cached information based at least on the second chunk.
3. The computer-implemented method of claim 2, wherein:the first chunk includes a first number of tokens; andthe second chunk includes a second number of tokens.
4. The computer-implemented method of claim 1, wherein accumulating the one or more first tokens into the first chunk includes determining that the first chunk satisfies a chunk-completion condition.
5. The computer-implemented method of claim 4, wherein the chunk-completion condition includes the input stream satisfying at least one of a threshold number of tokens, a predefined number of tokens, a threshold amount of text data, a linguistic boundary, or a predefined time interval.
6. The computer-implemented method of claim 1, wherein the first chunk includes at least one of a block or a page of tokens.
7. The computer-implemented method of claim 1, wherein the trained machine learning model includes a transformer model, wherein the one or more first cache entries include key data and value data generated by one or more attention layers included in the transformer model, and wherein the cached information includes a key-value cache.
8. The computer-implemented method of claim 1, wherein generating the one or more output tokens includes autoregressively generating, based at least on the one or more first cache entries, a next output token included in the one or more output tokens.
9. The computer-implemented method of claim 1, further comprising in response to determining that the input stream includes an edit, performing at least one of modifying, removing, or invalidating one or more second cache entries included in the cached information.
10. The computer-implemented method of claim 1, wherein generating the one or more first tokens includes generating, using a trained speech-to-text model, text data based at least on audio data included in the first portion of the input stream.
11. One or more non-transitory computer-readable media storing instructions that, when executed by one or more processors, cause the one or more processors to perform the steps of:generating, based at least on a first portion of an input stream, one or more first tokens;accumulating the one or more first tokens into a first chunk;performing, using a trained machine learning model and prior to completion of the input stream, a first prefilling operation to generate one or more first cache entries based at least on the first chunk; andin response to determining that the input stream is complete, generating, using the trained machine learning model, one or more output tokens based at least on cached information that includes the one or more first cache entries.
12. The one or more non-transitory computer-readable media of claim 11, wherein accumulating the one or more first tokens into the first chunk includes determining that the first chunk satisfies a chunk-completion condition.
13. The one or more non-transitory computer-readable media of claim 12, wherein the chunk-completion condition includes the input stream satisfying at least one of a threshold number of tokens, a predefined number of tokens, a threshold amount of text data, a linguistic boundary, or a predefined time interval.
14. The one or more non-transitory computer-readable media of claim 11, wherein the trained machine learning model includes a transformer model, wherein the one or more first cache entries include key data and value data generated by one or more attention layers included in the transformer model, and wherein the cached information includes a key-value cache.
15. The one or more non-transitory computer-readable media of claim 11, wherein generating the one or more first tokens includes:generating, using a trained speech-to-text model, text data based at least on audio data included in the first portion of the input stream; andconverting the text data into the one or more first tokens.
16. The one or more non-transitory computer-readable media of claim 11, wherein the instructions, when executed by the one or more processors, further cause the one or more processors to perform the step of, in response to determining that the input stream includes an edit, performing at least one of modifying, removing, or invalidating one or more second cache entries included in the cached information.
17. The one or more non-transitory computer-readable media of claim 11, wherein determining that the input stream is complete includes determining that the input stream satisfies an input-completion condition.
18. The one or more non-transitory computer-readable media of claim 17, wherein the input-completion condition includes at least one of an end-of-input indication, a user-submitted input, a send command, a pause in audio data, an end-of-speech indication, an end-of-stream message, or an indication that no additional input data is expected.
19. The one or more non-transitory computer-readable media of claim 11, wherein the instructions, when executed by the one or more processors, further cause the one or more processors to perform the step of storing the one or more first cache entries in the cached information using at least one of a per-layer basis, a per-attention-head basis, a per-token-position basis, a per-sequence-position basis, a per-chunk basis, a per-request basis, or a quantized format.
20. A system, comprising:one or more memories storing instructions; andone or more processors that are coupled to the one or more memories and, when executing the instructions:generate, based at least on a first portion of an input stream, one or more first tokens,accumulate the one or more first tokens into a first chunk,perform, using a trained machine learning model and prior to completion of the input stream, a first prefilling operation to generate one or more first cache entries based at least on the first chunk, andin response to determining that the input stream is complete, generate, using the trained machine learning model, one or more output tokens based at least on cached information that includes the one or more first cache entries.
