Data query method, device and equipment

By dividing the data query logic into a double loop of key K and value V during the incremental inference process of the large language model, the data dependency problem in attention calculation is solved, and query efficiency and memory access efficiency are improved.

CN123178392APending Publication Date: 2026-11-27HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510690420.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-26
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

In the incremental inference process of large language models, attention calculation is time-consuming due to strong data dependencies, which affects query efficiency, especially posing a significant adaptation challenge on neural network processors (NPUs).

Method used

By dividing the data query logic into a double loop of key K and value V, matrix operations are first performed on all keys K, and then matrix operations are performed on all values ​​V, reducing data dependencies and improving memory access efficiency.

Benefits of technology

It effectively reduces the number of synchronization waits, reduces delays caused by value misses, and improves query efficiency and the compactness of memory access pipeline.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123178392A_ABST
    Figure CN123178392A_ABST
Patent Text Reader

Abstract

The application discloses a data query method, device and equipment, and belongs to the technical field of computers. The method comprises the following steps: acquiring a query vector corresponding to query data and acquiring all keys K related to the query vector; obtaining a target probability score matrix according to the all keys K and the query vector; acquiring all values V related to the query vector; and obtaining a target query result corresponding to the query data according to the target probability score matrix and the all values V. It can be seen that the data query is divided into two parts: one part is the carrying of all keys K and the matrix operation on all keys K, and the other part is the carrying of all values V and the matrix operation on all values V, so that the KV double cycle is realized, the dependency relationship between the matrix operation result of part of the keys K and part of the values V is not required, the data dependency in the calculation is effectively weakened, the delay and time consumption problems caused by the value miss are reduced, the pipeline related to the KV calculation and the memory access is more compact, and the query efficiency is effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a data query method, apparatus, and device. Background Technology

[0002] In large language model inference systems, incremental inference (decoding) is the core component of text generation, and its performance determines the system's latency and throughput. Under autoregressive encoding mechanisms, attention computation requires repeatedly loading the key-value (KV) vectors of the entire historical token set, resulting in a typical memory-intensive inference load. With the continuous evolution of large model capabilities (such as long context processing and full-thinking), the size of the key-value cache (KV cache) grows linearly with the sequence length, and attention computation gradually becomes the main bottleneck in the incremental inference stage.

[0003] In recent years, optimizing attention query efficiency has become a key research focus in the field of computing architecture. Mainstream solutions are based on deep optimization of the hardware characteristics of graphics processing units (GPUs). However, due to differences in hardware architecture, these optimization solutions face significant adaptation challenges on neural processing units (NPUs).

[0004] Therefore, in related technologies, a data query method implemented through a model typically involves, in a single loop, first transferring a portion of the key K from global memory into the processor used for attention calculation, then converting the format of the key K, and finally using the processor's matrix calculation unit to calculate Q*K using the query Q and the converted key K. T The process involves obtaining the attention score matrix. A portion of the value V is then moved from global memory into the processor, and its format is converted. The vector computation unit then performs vector calculations on the attention score matrix to obtain a vector matrix. The converted value V is then used to perform matrix operations on the vector matrix, and the calculation result is output. This process is repeated for all keys K and values ​​V. It is evident that in a single loop, because the calculation of the next step depends on the result of the previous step, the instruction stream exhibits a strong data dependency. If an instruction is not read, it will continue to be read until it is found, which can easily cause value retrieval delays, resulting in long calculation times and impacting query efficiency. Summary of the Invention

[0005] This application provides a data query method, apparatus, and device that weakens data dependencies in computation, reduces the number of synchronization waits, and makes the pipeline related to KV calculation and memory access more compact, effectively improving query efficiency. The technical solution is as follows.

[0006] Firstly, a data query method is provided, applied to a processor. The method includes: obtaining a query vector corresponding to the query data and obtaining all keys K related to the query vector; obtaining a target probability score matrix based on all keys K and the query vector, the target probability score matrix representing the normalized attention weights of the query data on all keys K; obtaining all values ​​V related to the query vector; and obtaining the target query result corresponding to the query data based on the target probability score matrix and all values ​​V. This is achieved by first performing matrix operations on all keys K to obtain the matrix operation result (i.e., the target probability score matrix). Subsequently, matrix operations are performed on all values ​​V based on the target probability score matrix. This allows the data query logic to be divided into two parts: one part involves transporting all keys K and performing matrix operations on all keys K, and the other part involves transporting all values ​​V and performing matrix operations on all values ​​V. This achieves a KV double loop. Compared to the single loop in related technologies, there is no dependency between the matrix operation results of some keys K and some values ​​V, effectively weakening the data dependency in the calculation, reducing the number of synchronization waits, and reducing delays and time consumption caused by value misses. This makes the pipeline related to KV calculation and memory access more compact, effectively improving query efficiency. In addition, since most of the above execution operations are confined to the K loop and V loop, the instruction locality corresponding to most execution operations is relatively strong.

[0007] In one possible implementation, the target probability score matrix is ​​obtained based on all keys K and the query vector, including: obtaining the target attention score matrix based on all keys K and the query vector; and performing vector operations on the target attention score matrix to obtain the target probability score matrix. During the matrix operations on all keys K, the result (i.e., the target attention score matrix) can be obtained by performing operations on all keys K and the query vector matrix, and then performing vector operations on this result. This allows the data query logic to be divided into three parts: the first part involves transporting all keys K and performing matrix operations on all keys K; the second part involves performing vector operations on the result of the first part; and the third part involves transporting all values ​​V and performing matrix operations on all values ​​V based on the result of the second part. This achieves a KV double loop while treating the vector operation logic as a separate part, ensuring that a vector operation is performed after each key K matrix operation. This avoids performing a vector operation for each key K matrix operation, effectively weakening data dependencies in the computation, reducing the number of synchronization waits, and mitigating delays and time consumption caused by missed values. At the same time, it effectively reduces the instruction flow, making the pipeline related to KV calculation and memory access more compact, thus effectively improving query efficiency.

[0008] In one possible implementation, retrieving all keys K associated with the query vector includes: retrieving all keys K if the sum of the sizes of all keys K is less than or equal to the capacity of the processor's uniform buffer, wherein all keys K are formatted using vector operations. Retrieving all keys K at once allows for a larger data transfer volume per operation, improving memory bandwidth utilization. Furthermore, it eliminates the overhead of additional format conversion required for handling smaller data volumes during matrix operations.

[0009] In one possible implementation, obtaining all keys K associated with the query vector includes: if the sum of the sizes of all keys K is greater than the capacity of the processor's unified buffer, obtaining the i-th part of keys K from all keys K for the i-th time, based on the capacity of the unified buffer, where the sum of the sizes of the i-th part of keys K is less than or equal to the capacity of the unified buffer; i is a positive integer greater than or equal to 1 and less than N, where N is less than or equal to the value of all keys K / the capacity of the unified buffer; obtaining the target attention score matrix based on all keys K and the query vector includes: obtaining the i-th attention score matrix based on the i-th part of keys K and the query vector; and so on, obtaining N attention score matrices after obtaining all keys K, which are used to determine the target attention score matrix. If the capacity of the unified buffer cannot accommodate all keys K, it is necessary to move the keys K in batches. For example, after moving the first part of keys K, while performing matrix operations on the first part of keys K, it is possible to instruct the movement of the second part of keys K. In this way, all keys K can be moved in batches. However, even though the movement is done in batches, it is still based on the capacity of the unified buffer to move as much data as possible at once, so as to maximize the utilization of memory bandwidth.

[0010] In one possible implementation, the ith attention score matrix is ​​obtained based on the ith part of the key K and the query vector. This includes obtaining the ith attention score matrix during the (i+1)th retrieval of the ith part of all keys K. When the capacity of the unified buffer cannot accommodate all keys K, keys K need to be moved in batches. For example, after moving the first part of keys K, while performing matrix operations on the first part, the second part of keys K can be moved simultaneously. This synchronizes the matrix operation time with the second key K movement, improving the data movement pipeline utilization. Furthermore, this implementation synchronizes data movement operations and matrix operations, making efficient use of time and effectively improving query efficiency.

[0011] In one possible implementation, obtaining all keys K related to the query vector includes: if the sum of the sizes of all keys K is greater than the capacity of the processor's unified buffer, obtaining the i-th part of keys K from all keys K for the i-th time, where the sum of the sizes of the i-th part of keys K is less than or equal to the capacity of the unified buffer; i is a positive integer greater than or equal to 1 and less than N, where N is less than or equal to the value of all keys K / the capacity of the unified buffer; obtaining the target attention score matrix based on all keys K and the query vector includes: obtaining the i-th attention score matrix based on the i-th part of keys K and the query vector; performing vector operations on the target attention score matrix to obtain the target probability score matrix includes: performing vector operations on the i-th attention score matrix to obtain the i-th probability score matrix; and so on, obtaining all keys K to obtain N probability score matrices, which are used to determine the target probability score matrix. When the capacity of a unified buffer cannot accommodate all keys K, it is necessary to move the keys K in batches. For example, after moving the first batch of keys K, while performing matrix operations on the first batch, the system can instruct the system to move the second batch of keys K. In this way, the matrix operation time is synchronized with the second batch of keys K, achieving simultaneous execution of data moving and matrix operations, making efficient use of time and effectively improving query efficiency. Alternatively, the probability score matrix can be dimensionally split, that is, the matrix operation results of each batch of keys K can be used to perform vector operations separately. This is suitable for hardware with insufficient vector computing unit processing power, allowing this granular partitioning to better save query time.

[0012] In one possible implementation, retrieving all values ​​V associated with the query vector includes: retrieving all values ​​V, where the sum of the sizes of all values ​​V is less than or equal to the capacity of the processor's uniform buffer, and all values ​​V are formatted using vector operations. Retrieving all values ​​V at once allows for a larger data transfer volume per operation, improving memory bandwidth utilization. Furthermore, it eliminates the overhead of additional format conversions required for handling smaller data volumes during matrix operations.

[0013] In one possible implementation, obtaining all values ​​V related to the query vector includes: if the sum of the sizes of all values ​​V is greater than the capacity of the processor's unified buffer, obtaining the j-th part of all values ​​V for the j-th time, where the sum of the sizes of the j-th part of values ​​V is less than or equal to the capacity of the unified buffer; j is a positive integer greater than or equal to 1 and less than M, where M is less than or equal to the value of all values ​​V / the capacity of the unified buffer; obtaining the target query result corresponding to the query data based on the target probability score matrix and all values ​​V, including: obtaining the j-th query result based on the target probability score matrix and the j-th part of values ​​V; and so on, obtaining M query results after obtaining all values ​​V, which are used to determine the target query result. If the capacity of the unified buffer cannot accommodate all values ​​V, it is necessary to move the values ​​V in batches. For example, after moving the first part of the values ​​V, while performing matrix operations on the first part of the values ​​V, it is possible to instruct the movement of the second part of the values ​​V. In this way, all keys K can be moved in batches. However, even though the data is moved in batches, it is still based on the capacity of the unified buffer to move as much data as possible at once, so as to maximize the utilization of memory bandwidth.

[0014] In one possible implementation, the j-th query result is obtained based on the target probability score matrix and the j-th part value V. This includes obtaining the j-th query result based on the target probability score matrix and the j-th part value V during the (j+1)-th retrieval of all values ​​V. When the capacity of the unified buffer cannot accommodate all values ​​V, values ​​V need to be transported in batches. For example, after transporting the first part of values ​​V, while performing matrix operations on the first part of values ​​V, the transport of the second part of values ​​V can be instructed. This synchronizes the matrix operation time with the second value V transport time, improving the data transport pipeline utilization rate. Furthermore, it achieves synchronous execution of data transport operations and matrix operation operations, making reasonable use of time and effectively improving query efficiency.

[0015] Secondly, a data query device is provided, which is applied to a processor. The device includes: an acquisition module for acquiring a query vector corresponding to query data and acquiring all keys K related to the query vector; a calculation module for obtaining a target probability score matrix based on all keys K and the query vector, wherein the target probability score matrix is ​​used to characterize the normalization of the attention weights of the query data to all keys K; the acquisition module is also used to acquire all values ​​V related to the query vector; and the calculation module is also used to obtain a target query result based on the target probability score matrix and all values ​​V.

[0016] In one possible implementation, a computation module is used to obtain a target attention score matrix based on all keys K and query vectors; and to perform vector operations on the target attention score matrix to obtain a target probability score matrix.

[0017] In one possible implementation, a retrieval module is used to retrieve all keys K, which are formatted keys K using vector operations, provided that the sum of the sizes of all keys K is less than or equal to the capacity of the processor's uniform buffer.

[0018] In one possible implementation, an acquisition module is used to acquire the i-th part of all keys K for the i-th time, based on the capacity of the unified buffer, when the sum of the sizes of all keys K is greater than the capacity of the processor's unified buffer. The sum of the sizes of the i-th part of keys K is less than or equal to the capacity of the unified buffer. i is a positive integer greater than or equal to 1 and less than N, where N is less than or equal to the value of all keys K / the capacity of the unified buffer. A calculation module is used to obtain the i-th attention score matrix based on the i-th part of keys K and the query vector. This process is repeated until all keys K are acquired, resulting in N attention score matrices. These N attention score matrices are used to determine the target attention score matrix.

[0019] In one possible implementation, the computation module is used to obtain the ith attention score matrix based on the ith part of the keys K and the query vector during the (i+1)th time of obtaining all keys K.

[0020] In one possible implementation, an acquisition module is used to acquire the i-th part of all keys K in the i-th iteration, based on the capacity of the unified buffer, when the sum of the sizes of all keys K is greater than the capacity of the processor's unified buffer. The sum of the sizes of the i-th part of keys K is less than or equal to the capacity of the unified buffer. i is a positive integer greater than or equal to 1 and less than N, where N is less than or equal to the value of all keys K / the capacity of the unified buffer. A calculation module is used to obtain the i-th attention score matrix based on the i-th part of keys K and the query vector. Vector operations are performed on the i-th attention score matrix to obtain the i-th probability score matrix. This process is repeated until all keys K are acquired, resulting in N probability score matrices. These N probability score matrices are used to determine the target probability score matrix.

[0021] In one possible implementation, a module is configured to retrieve all values ​​V, which are formatted values ​​V using vector operations, provided that the sum of the sizes of all values ​​V is less than or equal to the capacity of a uniform buffer in the processor.

[0022] In one possible implementation, an acquisition module is used to acquire, for example, the j-th part of all values ​​V when the sum of the sizes of all values ​​V is greater than the capacity of the processor's unified buffer, based on the capacity of the unified buffer, the j-th time acquiring the j-th part of the values ​​V, where the sum of the sizes of the j-th part of the values ​​V is less than or equal to the capacity of the unified buffer; j is a positive integer greater than or equal to 1 and less than M, where M is less than or equal to the value of all values ​​V / the capacity of the unified buffer; a calculation module is used to obtain the j-th query result based on the target probability score matrix and the j-th part of the values ​​V; and so on, until all values ​​V are acquired, resulting in M ​​query results, which are used to determine the target query result.

[0023] In one possible implementation, the calculation module is used to obtain the j-th query result based on the target probability score matrix and the j-th partial value V during the (j+1)-th retrieval of all values ​​V.

[0024] Thirdly, a computing device is provided, the computing device including a processor coupled to a memory; the memory storing at least one instruction, the at least one instruction being loaded and executed by the processor to enable the computing device to implement the method of the first aspect.

[0025] Fourthly, a computer program (product) is provided, comprising: computer program code, which, when executed by a computer, causes the computer to perform the methods described in the above aspects.

[0026] Fifthly, a computer-readable storage medium is provided that stores a program or instructions, wherein when the program or instructions are run on a computer, the methods described in the preceding aspects are executed.

[0027] In a sixth aspect, a chip is provided, including a processor for retrieving and executing instructions stored in memory, causing a computer equipped with the chip to perform the methods described in the foregoing aspects.

[0028] In a seventh aspect, another chip is provided, comprising: an input interface, an output interface, a processor, and a memory, wherein the input interface, the output interface, the processor, and the memory are connected via an internal connection path, the processor is used to execute code in the memory, and when the code is executed, a computer with the chip installed performs the methods in the above aspects.

[0029] It should be understood that the beneficial effects achieved by the technical solutions and corresponding possible implementations of the second to seventh aspects of this application can be found in the technical effects of the first aspect and its corresponding possible implementations described above, and will not be repeated here. Furthermore, the data query device mentioned in the second aspect can be the chip mentioned in the sixth or seventh aspect, or the data query device can also be the computing device mentioned in the third aspect. Attached Figure Description

[0030] Figure 1 This is a flowchart illustrating a data query method provided in related technologies.

[0031] Figure 2 A flowchart illustrating a data query method provided in this application embodiment;

[0032] Figure 3 Another flowchart illustrating a data query method provided in this application embodiment;

[0033] Figure 4 A schematic diagram of a data query device provided in an embodiment of this application;

[0034] Figure 5 This is a schematic diagram of the structure of a computing device provided in an embodiment of this application. Detailed Implementation

[0035] The terminology used in the implementation section of this application is for the purpose of explaining specific embodiments of this application only, and is not intended to limit this application.

[0036] In large language model inference systems, incremental inference (decoding) is the core component of text generation, and its performance determines the system's latency and throughput. Under autoregressive encoding mechanisms, autoregressive generation requires gradually constructing the output sequence. Each step of attention computation requires repeatedly loading the key-value (KV) vectors of all historical tokens, forming a typical memory-intensive inference load. This results in the key-value vector size being proportional to the sequence length L and the model dimension d, potentially reaching gigabyte (GB) levels in long-context scenarios. Furthermore, each time a new token is generated, all historical key-value vectors must be loaded from GPU memory / RAM, while the actual computation only involves the interaction between the query vector (Query) corresponding to the currently generated token and the historical key-value vectors.

[0037] With the continuous evolution of large model capabilities, for example, long context processing (tasks such as document understanding and code generation require handling contexts of thousands or even tens of thousands of tokens), and full-thinking (i.e., the model needs to retain complete historical information to maintain logical coherence, and cannot rely on local attention or sliding window pruning of the cache), the size of the key-value cache (KV cache) grows linearly with the sequence length, making attention computation a major bottleneck in the incremental inference stage. In recent years, optimizing attention computation efficiency has become a research focus in the field of computing architecture. Mainstream technical solutions (such as flash attention (FA) series, FlashInfer, etc.) are all deeply optimized based on the hardware characteristics of graphics processing units (GPUs). However, due to differences in hardware architecture, these optimization solutions face significant adaptation challenges on neural network processors (NPUs). Therefore, attention computation optimization for NPUs needs to reconstruct the algorithm design based on hardware-algorithm collaborative optimization.

[0038] However, in order to optimize attention calculation, Figure 1 This is a flowchart illustrating a data query method provided in related technologies, such as... Figure 1 As shown, this method typically involves the following steps in a single loop: Step ①: A portion of the keys K are loaded from global memory into the processor used for attention calculation, and the key K is simultaneously converted to a new format. Step ②: The processor's matrix calculation unit calculates Q*KT using the query vector Q and the converted key K to obtain the attention score matrix. Simultaneously, a portion of the values ​​V are loaded from global memory into the processor, the values ​​V are converted to a new format, and the vector calculation unit performs vector calculations on the attention score matrix to obtain a vector matrix. Step ③: The converted values ​​V are used to perform matrix operations with the vector matrix to output the query result. This process is repeated for all keys K and values ​​V. It is evident that in a single loop, since the calculation of the next step depends on the result of the previous step, the instruction stream exhibits a strong data dependency. If a certain instruction is not read, it will continue to be read until it is found, which can easily cause value retrieval delays, resulting in long calculation times and impacting query efficiency.

[0039] To address the aforementioned technical problems, embodiments of this application provide a data query method. This method is applied to a processor and may include: obtaining a query vector corresponding to the query data and obtaining all keys K related to the query vector; obtaining a target probability score matrix based on all keys K and the query vector, whereby the target probability score matrix characterizes the normalized attention weights of the query data on all keys K; obtaining all values ​​V related to the query vector; and obtaining the target query result corresponding to the query data based on the target probability score matrix and all values ​​V. The matrix operation result (i.e., the target probability score matrix) is obtained by first performing matrix operations on all keys K. Subsequently, matrix operations are performed on all values ​​V based on the target probability score matrix. This allows the data query logic to be divided into two parts: one part involves transporting all keys K and performing matrix operations on all keys K, and the other part involves transporting all values ​​V and performing matrix operations on all values ​​V. This achieves a KV double loop. Compared to the single loop in related technologies, there is no dependency between the matrix operation results of some keys K and some values ​​V, effectively weakening the data dependency in the calculation, reducing the number of synchronization waits, and reducing delays and time consumption caused by value misses. This makes the pipeline related to KV calculation and memory access more compact, effectively improving query efficiency. In addition, since most of the above execution operations are confined to the K loop and V loop, the instruction locality corresponding to most execution operations is relatively strong.

[0040] For example, Figure 2 This is a flowchart illustrating a data query method provided in an embodiment of this application, such as... Figure 2 As shown, the processor may include a vector computation unit and a cube computation unit. The vector computation unit may include a uniform buffer (UB). The cube computation unit may include a data buffer L1. The processor obtains the query vector Q corresponding to the query data. The length d of the query vector Q can be set according to actual conditions. Step ①: The processor moves all keys K related to the query vector Q from global memory (GM) into the uniform buffer UB of the vector computation unit. Step ②: The vector computation unit obtains all keys K from the uniform buffer UB and performs format conversion on all keys K to obtain keys K that satisfy the matrix operation format (i.e., ...). Figure 2(as shown in transK). Then, all keys K are moved into the data buffer L1 of the matrix computation unit (cube unit). Step ③: The matrix computation unit (cube unit) retrieves all keys K from the data buffer L1 and performs matrix operations on the query vector Q and all keys K to obtain the target attention score matrix. Step ④: The vector computation unit (vector) performs vector operations on the target attention score matrix to obtain the target probability score matrix S. Step ⑤: The processor moves all values ​​V related to the query vector Q from the global memory GM into the unified buffer UB of the vector computation unit (vector). Step ⑥: The vector computation unit (vector) retrieves all values ​​V from the unified buffer UB and performs format conversion on all values ​​V to obtain values ​​V that satisfy the matrix operation format (i.e., ...). Figure 2 (as shown in transV). Then, all values ​​V are moved into the data buffer L1 of the matrix calculation unit (cube unit). Step ⑦: The matrix calculation unit (cube unit) retrieves all values ​​V from the data buffer L1 and performs matrix operations on the target probability score matrix S and all values ​​V to obtain the target query result. Step ⑧: Update the target query result (i.e., Figure 2 The Div shown.

[0041] The data query method provided in this application can be applied to most large language models, such as large language model series, large model family series, and multimodal models, such as large multimodal models, large multimodal models, etc., or general client models, for accelerating attention calculation in the incremental inference stage. The application corresponding to the data query method provided in this application can be encapsulated as an operator application program interface. Of course, the data query method provided in this application can also be applied to graphics processing models, and no specific limitation is made in this application.

[0042] The data query method provided in the embodiments of this application will be described in detail below with reference to examples. Figure 3 This is another flowchart illustrating the data query method provided in an embodiment of this application. For example... Figure 3 As shown, this method is applied to a processor and can be divided into the following stages.

[0043] Phase 1, key K loop.

[0044] S301. Obtain the query vector corresponding to the query data and obtain all keys K related to the query vector.

[0045] The queried data can be multimedia data, such as image data, audio data, video data, and text data. Therefore, the data query method provided in this application can be applied to text query scenarios, image query scenarios, etc. Of course, it can also be applied to other scenarios, such as voice query scenarios. These will not be listed individually in this application.

[0046] Retrieving all keys K can be understood as the processor moving all keys K from global memory GM into the unified buffer UB of the processor's vector computation unit. Since the unified buffer UB has a limited capacity, the keys K need to be moved based on the capacity of the unified buffer UB. Therefore, retrieving all keys K can also be understood as: retrieving all keys K at once, or retrieving all keys K multiple times.

[0047] To retrieve all keys K at once, it can be implemented by retrieving all keys K if the sum of the sizes of all keys K is less than or equal to the capacity of the processor's uniform buffer. For example, as shown... Figure 2 As shown, the processor moves all keys K from the global memory GM into the unified buffer UB at once. This allows for a larger data transfer volume per operation by acquiring all keys K at once, thus improving memory bandwidth utilization. Furthermore, all the transferred keys K are formatted using vector operations; for example, as shown... Figure 2 As shown, the storage addresses of all keys K can be uniformly converted by the vector computation unit to obtain the formatted keys K, so as to meet the format requirements of subsequent matrix operations. This eliminates the need for multiple additional format conversions caused by moving a small amount of data at a time to adapt to matrix operations.

[0048] For retrieving all keys K in multiple steps, the following approach can be used: If the sum of the sizes of all keys K is greater than the capacity of the processor's unified buffer, then, based on the capacity of the unified buffer, the i-th portion of keys K from all keys K is retrieved in the i-th step. The sum of the sizes of the i-th portion of keys K is less than or equal to the capacity of the unified buffer; i is a positive integer greater than or equal to 1 and less than N, where N is less than or equal to the value of all keys K divided by the capacity of the unified buffer. Optionally, the maximum amount of key K data that can be retrieved in a single step is determined based on the capacity of the unified buffer. This process continues until all keys K are retrieved. For example, assuming the total number of keys K is 1000, and N is 10 based on the capacity of the unified buffer, this means that if 1000 initial keys K are moved in 10 steps, then 100 initial keys K are moved in each step. The process begins with moving 100 initial keys K to the vector computing unit. The vector computing unit uses vector operations to format these 100 initial keys K, obtaining the final key K, and then moves these 100 keys K into the data buffer L1 of the processor's cube computing unit, awaiting matrix operations. This process is repeated for the second time, moving another 100 initial keys K to the vector computing unit. The vector computing unit then uses vector operations to format these second set of 100 initial keys K, obtaining the final key K, and moves these 100 keys K into the data buffer L1 of the processor's cube computing unit, awaiting matrix operations. This process continues until all 10 moves are completed. Although related technologies also move keys K in batches, the amount moved each time is fixed and very small, such as 10 keys K. This allows for batch moving of all keys K, but even with batch moving, the goal is to move as much data as possible at once, maximizing memory bandwidth utilization, while maintaining a unified buffer capacity.

[0049] S302. Based on all keys K and the query vector, obtain the target probability score matrix. The target probability score matrix is ​​used to represent that the attention weights of the query data on all keys K are normalized.

[0050] In one possible implementation, S302 can be implemented as: S3021, obtaining the target attention score matrix based on all keys K and the query vector. For example, as... Figure 2 As shown, the matrix operation unit (cube unit) of the processor is used to perform matrix operations on the query vector Q and all keys K to obtain the target attention score matrix P, which can be expressed as P = Q * K. T (T represents the transpose of K). S3022, Perform vector operations on the target attention score matrix to obtain the target probability score matrix. For example, as follows... Figure 2As shown, the processor's vector computation unit (vector) performs vector operations on the target attention score matrix P using the Softmax function to obtain the target probability score matrix S, which can be expressed as: S = Softmax(p).

[0051] As described above, if all keys K are obtained multiple times, S3021 can also be implemented as follows: based on the i-th part of the key K and the query vector, the i-th attention score matrix is ​​obtained. This process continues until all keys K are obtained, resulting in N attention score matrices. These N attention score matrices are used to determine the target attention score matrix. Continuing with the example above, the matrix calculation unit (cube unit) performs matrix operations on the first 100 keys K and the query vector Q to obtain the first attention score matrix P1. This process continues until 10 matrix operations are performed, resulting in 10 attention score matrices. The target attention score matrix can then be determined based on these 10 matrix operations. This allows for dimensional decomposition of the target attention score matrix, i.e., matrix operations are performed on each part of the key K separately. This is suitable for hardware with insufficient computing power in the vector calculation unit, enabling this granular segmentation to better save query time.

[0052] Similarly, if all keys K are obtained multiple times, S3021 can also be implemented as: obtaining the i-th attention score matrix based on the i-th part of the keys K and the query vector. S3022 can also be implemented as: performing vector operations on the i-th attention score matrix to obtain the i-th probability score matrix; and so on, after obtaining all keys K, N probability score matrices are obtained, and the N probability score matrices are used to determine the target probability score matrix. For example, after the matrix calculation unit (cube unit) performs matrix operations on the first 100 keys K and the query vector Q to obtain the first attention score matrix P1, the vector calculation unit (vector) performs vector operations on the attention score matrix P1 to obtain the first probability score matrix S1. And so on, after completing 10 vector operations, 10 probability score matrices can be obtained, and the target probability score matrix can be determined based on the 10 probability score matrices. In this way, the target probability score matrix can be dimensionally split, that is, the matrix operation results of each part key K can be vectorized separately. This is suitable for hardware with insufficient computing power of vector computing units, so that this granular segmentation can better save query time.

[0053] Of course, during the process of obtaining the i-th attention score matrix based on the i-th part of the key K and the query vector, the (i+1)-th part of the keys K can be retrieved from all keys K in the (i+1)-th iteration. Continuing with the example above, during the matrix computation unit (cube unit) performing matrix operations on the first 100 keys K and the query vector Q to obtain the first attention score matrix P1, the processor can initiate the second transfer of the 100 keys K, i.e., transferring the second 100 initial keys K to the vector computation unit (vector). And so on. The matrix operations of the current batch and the transfer of the next batch of keys K are executed synchronously. For example, the (i+1)-th retrieval of the i-th part of the keys K in the above-mentioned (i+1)-th iteration can be achieved by triggering an instruction to transfer the (i+1)-th part of the keys K. In this way, the matrix operation time is synchronized with the second key K transfer time, improving the data transfer pipeline utilization and reducing the bubbling ratio of instructions executing data transfer. Furthermore, the synchronous execution of data transfer operations and matrix operations makes reasonable use of time and effectively improves query efficiency.

[0054] To further simplify the instruction flow, vector operations can be performed to obtain the target probability score matrix after obtaining the target attention score matrix. That is, vector operations can be treated as an independent stage. In other words, during matrix operations on all keys K, all keys K can be operated on with the query vector matrix to obtain the result (i.e., the target attention score matrix), and then vector operations can be performed on this result. This allows the data query logic to be divided into three parts: the first part involves transporting all keys K and performing matrix operations on them; the second part involves performing vector operations on the result of the first part; and the third part involves transporting all values ​​V and performing matrix operations on all values ​​V based on the result of the second part. This achieves a KV double loop while treating the vector operation logic as a separate part, ensuring that a vector operation is performed after each key K matrix operation. This avoids performing a vector operation for each key K matrix operation, effectively weakening data dependencies in the computation, reducing the number of synchronization waits, and mitigating delays and time consumption caused by value misses. This makes the KV computation and memory access pipeline more compact, effectively improving query efficiency.

[0055] The first stage described above involves transferring all keys K and performing matrix operations on all keys K and the query vector Q to obtain the target probability score matrix. After obtaining the target probability score matrix in the first stage, all values ​​V are transferred, and matrix operations are performed on all values ​​V and the target probability score matrix to obtain the target query result, as described in the relevant section of the second stage.

[0056] Phase 2, Value V loop.

[0057] S303. Retrieve all values ​​V related to the query vector.

[0058] Retrieving all values ​​V can be understood as the processor moving all values ​​V from global memory GM into the unified buffer UB of the vector computation unit. Since the unified buffer UB of the processor's vector computation unit has a limited capacity, the values ​​V need to be moved based on the capacity of the unified buffer UB. Therefore, retrieving all values ​​V can also be understood as: retrieving all values ​​V at once, or retrieving all values ​​V multiple times.

[0059] To retrieve all values ​​V at once, it can be implemented by retrieving all values ​​V if the sum of the sizes of all values ​​V is less than or equal to the capacity of the processor's uniform buffer. For example, as shown... Figure 2 As shown, the processor moves all values ​​V from global memory GM into a unified buffer UB in one go. This allows for a larger data transfer volume per operation by acquiring all values ​​V at once, improving memory bandwidth utilization. Furthermore, the transferred values ​​V are formatted using vector operations. For example, the storage addresses of all values ​​V can be uniformly converted using a vector computation unit to obtain the formatted values ​​V, satisfying the format requirements of subsequent matrix operations. This eliminates the overhead of multiple additional format conversions required for adapting to matrix operations with smaller data transfer volumes per operation.

[0060] To retrieve all values ​​V multiple times, the following approach can be used: If the sum of the sizes of all values ​​V exceeds the capacity of the processor's unified buffer, then, based on the capacity of the unified buffer, the j-th portion of values ​​V from all values ​​V is retrieved in the j-th retrieval, where the sum of the sizes of the j-th portion of values ​​V is less than or equal to the capacity of the unified buffer; j is a positive integer greater than or equal to 1 and less than M, where M is less than or equal to the sum of all values ​​V divided by the capacity of the unified buffer. Optionally, the maximum amount of data V that can be retrieved in a single retrieval is determined based on the capacity of the unified buffer. This process continues until all values ​​V are retrieved. For example, assuming the total number of values ​​V is 1000, and M is 10 based on the capacity of the unified buffer, this means that 1000 initial values ​​V are moved in 10 retrievals, with 100 initial values ​​V being moved each time. The process begins with moving 100 initial values ​​V to the vector computing unit. The vector computing unit uses vector operations to format these 100 initial values ​​V, obtaining the final value V. This 100 values ​​V are then loaded into the data buffer L1 of the processor's cube computing unit, awaiting matrix operations. This process is repeated for the next 100 initial values ​​V. Similarly, the vector computing unit uses vector operations to format these 100 initial values ​​V, obtaining the final value V. This 100 values ​​V are then loaded into the data buffer L1 of the processor's cube computing unit, awaiting matrix operations. This process continues until all 10 moves are completed. While related technologies also move values ​​V in batches, the amount moved each time is fixed and very small, such as 10 values ​​V. This allows for batch moving of all values ​​V, but even with batch moving, the goal is to move as much data as possible at once, maximizing memory bandwidth utilization, while maintaining a unified buffer capacity.

[0061] S304. Based on the target probability score matrix and all values ​​V, obtain the target query results corresponding to the query data.

[0062] As described above, if all values ​​V are acquired at once, then S304 can be implemented as follows: Figure 2As shown, the matrix calculation unit (cube unit) of the processor performs matrix operations on the target probability score matrix S and all values ​​V to obtain the target query result D, which can be expressed as D = S * V. If all values ​​V are obtained multiple times, S304 can also be implemented as follows: Continuing with the above example, the matrix calculation unit (cube unit) performs matrix operations on the first 100 values ​​V and the target probability score matrix S to obtain the first query result D1. Furthermore, based on the first query result D1 and a first threshold, the target query result is obtained. The matrix calculation unit (cube unit) performs matrix operations on the second 100 values ​​V and the target probability score matrix S to obtain the second query result D2, and based on the second query result D2 and a second threshold, the updated target query result is obtained. This process continues, completing 10 matrix operations to obtain the latest target query result. In this way, the probability score matrix can be dimensionally split, that is, matrix operations are performed on each part of the values ​​V separately. This is suitable for hardware with insufficient vector calculation unit computing power, allowing this granular segmentation to better save query time.

[0063] The data query method provided by the embodiments of this application has been described above. Corresponding to the above method, the embodiments of this application also provide a data query device. This device is applied to a processor. This device is used to query data via... Figure 4 Each module shown performs the above... Figure 3 The data query method executed by the processor. For example... Figure 4 As shown, the data query device 400 provided in this application embodiment includes the following modules.

[0064] The acquisition module 401 is used to acquire the query vector corresponding to the query data and to acquire all keys K related to the query vector; for example, combined with Figure 2 The acquisition module 401 can be used to execute steps ① and ②, and, in combination with Figure 3 The acquisition module 401 can be used to execute step 301.

[0065] Calculation module 402 is used to obtain a target probability score matrix based on all keys K and the query vector. The target probability score matrix is ​​used to characterize the normalized attention weights of the query data on all keys K. For example, it combines... Figure 2 The calculation module 402 can be used to execute steps ③ and ④, and, in combination with Figure 3 The calculation module 402 can be used to execute step 302.

[0066] The acquisition module 401 is also used to acquire all values ​​V related to the query vector; exemplarily, in combination with Figure 2 The acquisition module 401 can be used to execute steps ⑤ and ⑥, and, in conjunction with Figure 3The acquisition module 401 can be used to execute step 303.

[0067] The calculation module 402 is further configured to obtain the target query result corresponding to the query data based on the target probability score matrix and all values ​​V. For example, in combination with... Figure 2 The calculation module 402 can be used to perform steps ⑦ and ⑧, and, in combination with Figure 3 The calculation module 402 can be used to execute step 304.

[0068] In one possible implementation, the calculation module 402 is used to obtain the target attention score matrix based on all keys K and the query vector; and to perform vector operations on the target attention score matrix to obtain the target probability score matrix.

[0069] In one possible implementation, the acquisition module 401 is used to acquire all keys K, which are formatted keys K using vector operations, provided that the sum of the sizes of all keys K is less than or equal to the capacity of the processor's uniform buffer.

[0070] In one possible implementation, the acquisition module 401 is used to acquire the i-th part of all keys K for the i-th time, based on the capacity of the unified buffer, when the sum of the sizes of all keys K is greater than the capacity of the processor's unified buffer. The sum of the sizes of the i-th part of keys K is less than or equal to the capacity of the unified buffer. i is a positive integer greater than or equal to 1 and less than N, and N is less than or equal to the value of all keys K / the capacity of the unified buffer. The calculation module 402 is used to obtain the i-th attention score matrix based on the i-th part of keys K and the query vector. By analogy, after acquiring all keys K, N attention score matrices are obtained. The N attention score matrices are used to determine the target attention score matrix.

[0071] In one possible implementation, the calculation module 402 is used to obtain the ith attention score matrix based on the ith part of the keys K and the query vector during the (i+1)th time of obtaining all keys K.

[0072] In one possible implementation, the acquisition module 401 is used to acquire the i-th part of all keys K in the i-th iteration, based on the capacity of the unified buffer, when the sum of the sizes of all keys K is greater than the capacity of the processor's unified buffer. The sum of the sizes of the i-th part of keys K is less than or equal to the capacity of the unified buffer. i is a positive integer greater than or equal to 1 and less than N, and N is less than or equal to the value of all keys K / the capacity of the unified buffer. The calculation module 402 is used to obtain the i-th attention score matrix based on the i-th part of keys K and the query vector. The i-th attention score matrix is ​​then subjected to vector operations to obtain the i-th probability score matrix. This process is repeated until all keys K are acquired, resulting in N probability score matrices. These N probability score matrices are used to determine the target probability score matrix.

[0073] In one possible implementation, the acquisition module 401 is used to acquire all values ​​V, which are formatted values ​​V using vector operations, provided that the sum of the sizes of all values ​​V is less than or equal to the capacity of the processor's uniform buffer.

[0074] In one possible implementation, the acquisition module 401 is used to acquire the j-th part of all values ​​V for the j-th time, based on the capacity of the unified buffer, when the sum of the sizes of all values ​​V is greater than the capacity of the processor's unified buffer; the sum of the sizes of the j-th part of values ​​V is less than or equal to the capacity of the unified buffer; j is a positive integer greater than or equal to 1 and less than M, where M is less than or equal to the value of all values ​​V / the capacity of the unified buffer; the calculation module 402 is used to obtain the j-th query result based on the target probability score matrix and the j-th part of values ​​V; and so on, after acquiring all values ​​V, M query results are obtained, and the M query results are used to determine the target query result.

[0075] In one possible implementation, the calculation module 402 is used to obtain the j-th query result based on the target probability score matrix and the j-th partial value V during the (j+1)-th acquisition of all values ​​V.

[0076] It should be understood that the above Figure 4 The beneficial effects that the provided device possesses in performing its function are... Figure 3 The data query methods provided all offer the same beneficial effects, which will not be elaborated upon here. Additionally, Figure 4 The provided device, in implementing its functions, is only illustrated by the division of the above-described functional modules. In practical applications, the functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. Furthermore, the device and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation processes are detailed in the method embodiments, and will not be repeated here.

[0077] See Figure 5 , Figure 5 A schematic diagram of the structure of an exemplary computing device 500 of this application is shown. The computing device 500 includes at least one processor 501, a memory 503, and at least one network interface 504.

[0078] Processor 501 may be, for example, a general-purpose central processing unit (CPU), a digital signal processor (DSP), a network processor (NP), a GPU, a neural-network processing unit (NPU), a data processing unit (DPU), a microprocessor, or one or more integrated circuits or application-specific integrated circuits (ASICs), programmable logic devices (PLDs), other general-purpose processors or other programmable logic devices, discrete gates, transistor logic devices, discrete hardware components, or any combination thereof for implementing the scheme of this application. A PLD may be, for example, a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof. A general-purpose processor may be a microprocessor or any conventional processor. It is worth noting that the processor may be a processor supporting an advanced reduced instruction set machine (RISC) machine (ARM) architecture. It can implement or execute the various logic blocks, modules, and circuits described in conjunction with the disclosure of this application. A processor can also be a combination of components that perform computing functions, such as a combination of one or more microprocessors, a combination of a DSP and a microprocessor, and so on.

[0079] Optionally, the computing device 500 also includes a bus. The bus is used to transfer information between the various components of the computing device 500. The bus can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The symbol is represented by only one line, but this does not mean that there is only one bus or one type of bus.

[0080] Memory 503 may be volatile memory or non-volatile memory, or may include both. The non-volatile memory may be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory may be random access memory (RAM), which is used as an external cache.

[0081] By way of example, but not limitation, many forms of ROM and RAM are available. For example, ROM is a compact disc read-only memory (CD-ROM). RAM includes, but is not limited to, static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DR RAM).

[0082] Memory 503 can also be other types of storage devices capable of storing static information and instructions. Alternatively, it can be other types of dynamic storage devices capable of storing information and instructions. It can also be other optical disc storage, optical disk storage (including compressed optical discs, laser discs, optical discs, digital versatile optical discs, Blu-ray discs, etc.), magnetic disk storage media, or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures that can be accessed by a computer, but is not limited thereto. Memory 503 may exist independently and be connected to processor 501 via a bus. Memory 503 may also be integrated with processor 501.

[0083] Network interface 504 uses any transceiver-like device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), or wireless local area network (WLAN). Network interface 504 can include wired network interfaces and wireless network interfaces. Specifically, network interface 504 can be an Ethernet interface, such as Fast Ethernet (FE), Gigabit Ethernet (GE), Asynchronous Transfer Mode (ATM), WLAN, cellular network, or combinations thereof. The Ethernet interface can be an optical interface, an electrical interface, or a combination thereof. In some embodiments of this application, network interface 504 can be used for computing device 500 to communicate with other devices.

[0084] In specific implementations, as some embodiments, processor 501 may include one or more CPUs, such as Figure 5 The CPU0 and CPU1 shown are examples of processors. Each of these processors can be a single-core processor or a multi-core processor. A processor here can refer to one or more devices, circuits, and / or processing cores used to process data (e.g., computer program instructions).

[0085] In specific implementations, as some embodiments, the computing device 500 may include multiple processors, such as... Figure 5 The processors 501 and 505 are shown in the diagram. Each of these processors may be a single-core processor or a multi-core processor. A processor here may refer to one or more devices, circuits, and / or processing cores used to process data (such as computer program instructions).

[0086] In some embodiments, memory 503 is used to store program instructions 510 for executing the scheme of this application, and processor 501 can execute the program instructions 510 stored in memory 503. That is, computing device 500 can implement the method provided in the method embodiment through processor 501 and program instructions 510 in memory 503. Figure 3 The method executed. Program instructions 510 may include one or more software modules. Optionally, processor 501 itself may also store program instructions for executing the scheme of this application.

[0087] In specific implementation, the computing device 500 of this application may correspond to a processor for executing the above method. The processor 501 in the computing device 500 reads instructions from the memory 503, causing... Figure 5 The computing device 500 shown is capable of performing all or part of the steps in the method embodiments.

[0088] The computing device 500 can also correspond to the above. Figure 4 The device shown, Figure 4 Each functional module in the illustrated device is implemented using software from computing device 500. In other words, Figure 4 The device shown includes functional modules generated by the processor 501 of the computing device 500 reading program instructions 510 stored in the memory 503.

[0089] in, Figure 3 Each step of the method shown is implemented through integrated logic circuits in the hardware of the processor of the computing device 500 or through instructions in the form of software. The steps of the method embodiments disclosed in this application can be directly implemented by the hardware processor, or implemented by a combination of hardware and software modules in the processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other storage media mature in the art. Since this storage medium is located in memory, the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method embodiments; to avoid repetition, they will not be described in detail here.

[0090] In an exemplary embodiment, a computing device is provided, the computing device including a processor coupled to a memory; the memory stores at least one instruction, the at least one instruction being loaded and executed by the processor to enable the computing device to perform... Figure 3 The method in the middle.

[0091] In an exemplary embodiment, a computer program (product) is provided, comprising: computer program code, which, when executed by a computer, causes the computer to perform... Figure 3 The method in the middle.

[0092] In an exemplary embodiment, a computer-readable storage medium is provided that stores a program or instructions, which, when executed on a computer, cause the computer to perform the aforementioned actions. Figure 3 The method in the middle.

[0093] In an exemplary embodiment, a chip is provided, including a processor for recalling and executing instructions stored in memory, causing a computer with the chip installed to perform... Figure 3 The method in the middle.

[0094] In an exemplary embodiment, another chip is provided, including: an input interface, an output interface, a processor, and a memory. The input interface, output interface, processor, and memory are connected via internal interconnection paths. The processor is used to execute code in the memory. When the code is executed, a computer with the chip installed performs... Figure 3 The method in the middle.

[0095] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive).

[0096] In this application, the terms "first," "second," etc., are used to distinguish identical or similar items with substantially the same function. It should be understood that there is no logical or temporal dependency between "first," "second," and "nth," nor does it limit the quantity or order of execution. It should also be understood that although the following description uses the terms "first," "second," etc., to describe various elements, these elements should not be limited by the terms. These terms are merely used to distinguish one element from another.

[0097] It should also be understood that, in the various embodiments of this application, the sequence number of each process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.

[0098] In this application, the term "at least one" means one or more, and the term "multiple" means two or more. For example, multiple second devices means two or more second devices. The terms "system" and "network" are often used interchangeably herein.

[0099] It should be understood that the terminology used in the description of the various examples herein is for the purpose of describing particular examples only and is not intended to be limiting. As used in the description of the various examples and the appended claims, the singular forms “a” and “the” are intended to include the plural forms as well, unless the context clearly indicates otherwise.

[0100] It should also be understood that the term "and / or" as used herein refers to and covers any and all possible combinations of one or more of the associated listed items. The term "and / or" describes an association between related objects, indicating that three relationships can exist; for example, A and / or B can represent: A alone, A and B simultaneously, or B alone. Additionally, the character " / " in this application generally indicates that the preceding and following related objects are in an "or" relationship.

[0101] It should also be understood that the terms “if” and “if” can be interpreted as meaning “when” or “upon”, or “in response to determination” or “in response to detection”. Similarly, depending on the context, the phrases “if determination…” or “if detection [the stated condition or event]” can be interpreted as meaning “when determination…”, or “in response to determination…”, or “when detection [the stated condition or event]” or “in response to detection [the stated condition or event]”.

[0102] The above description is merely an embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the principles of this application should be included within the protection scope of this application.

Claims

1. A data query method, characterized in that, The method is applied to a processor, and the method includes: Obtain the query vector corresponding to the query data and obtain all keys K related to the query vector; Based on all the keys K and the query vector, a target probability score matrix is ​​obtained. The target probability score matrix is ​​used to characterize that the attention weights of the query data on all keys K are normalized. Retrieve all values ​​V associated with the query vector; Based on the target probability score matrix and all values ​​V, the target query result corresponding to the query data is obtained.

2. The method according to claim 1, characterized in that, The step of obtaining the target probability score matrix based on all keys K and the query vector includes: Based on all the keys K and the query vector, the target attention score matrix is ​​obtained; The target attention score matrix is ​​subjected to vector operations to obtain the target probability score matrix.

3. The method according to claim 1 or 2, characterized in that, The step of obtaining all keys K related to the query vector includes: If the sum of the sizes of all keys K is less than or equal to the capacity of the processor's uniform buffer, then obtain all keys K, which are keys K formatted using vector operations.

4. The method according to claim 2, characterized in that, The step of obtaining all keys K related to the query vector includes: If the sum of the sizes of all keys K is greater than the capacity of the processor's unified buffer, the i-th part of keys K from all keys K is obtained for the i-th time according to the capacity of the unified buffer, and the sum of the sizes of the i-th part of keys K is less than or equal to the capacity of the unified buffer; i is a positive integer greater than or equal to 1 and less than N, and N is less than or equal to the value of all keys K / the capacity of the unified buffer; The step of obtaining the target attention score matrix based on all keys K and the query vector includes: Based on the i-th partial key K and the query vector, the i-th attention score matrix is ​​obtained; By analogy, after obtaining all the keys K, the N attention score matrices are obtained, and the N attention score matrices are used to determine the target attention score matrix.

5. The method according to claim 2, characterized in that, The step of obtaining all keys K related to the query vector includes: If the sum of the sizes of all keys K is greater than the capacity of the processor's unified buffer, the i-th part of keys K from all keys K is obtained for the i-th time according to the capacity of the unified buffer, and the sum of the sizes of the i-th part of keys K is less than or equal to the capacity of the unified buffer; i is a positive integer greater than or equal to 1 and less than N, and N is less than or equal to the value of all keys K / the capacity of the unified buffer; The step of obtaining the target attention score matrix based on all keys K and the query vector includes: Based on the i-th partial key K and the query vector, the i-th attention score matrix is ​​obtained; The step of performing vector operations on the target attention score matrix to obtain the target probability score matrix includes: Perform vector operations on the i-th attention score matrix to obtain the i-th probability score matrix; By analogy, after obtaining all the keys K, the N probability score matrices are obtained, and the N probability score matrices are used to determine the target probability score matrix.

6. The method according to claim 4 or 5, characterized in that, The step of obtaining the i-th attention score matrix based on the i-th partial key K and the query vector includes: During the (i+1)th time of obtaining the (i+1)th part of the keys K from all the keys K, the ith attention score matrix is ​​obtained based on the ith part of the keys K and the query vector.

7. The method according to any one of claims 1-6, characterized in that, The step of obtaining all values ​​V related to the query vector includes: If the sum of the sizes of all values ​​V is less than or equal to the capacity of the processor's uniform buffer, then all values ​​V are obtained, wherein all values ​​V are values ​​formatted using vector operations.

8. The method according to any one of claims 1-6, characterized in that, The step of obtaining all values ​​V related to the query vector includes: If the sum of the values ​​V is greater than the capacity of the processor's unified buffer, the j-th part of the values ​​V is obtained for the j-th time according to the capacity of the unified buffer, where the sum of the values ​​V is less than or equal to the capacity of the unified buffer; j is a positive integer greater than or equal to 1 and less than M, where M is less than or equal to the sum of the values ​​V and the capacity of the unified buffer. The step of obtaining the target query result corresponding to the query data based on the target probability score matrix and all values ​​V includes: Based on the target probability score matrix and the j-th part value V, the j-th query result is obtained; By analogy, after obtaining all the values ​​V, the M query results are obtained, and the M query results are used to determine the target query result.

9. The method according to claim 8, characterized in that, The step of obtaining the j-th query result based on the target probability score matrix and the j-th part value V includes: During the (j+1)th time of obtaining the (j+1)th part of the values ​​V from all values ​​V, the j-th query result is obtained based on the target probability score matrix and the j-th part of the values ​​V.

10. A data query device, characterized in that, The device is applied to a processor, and the device includes: The acquisition module is used to acquire the query vector corresponding to the query data and to acquire all keys K related to the query vector; The calculation module is used to obtain a target probability score matrix based on all keys K and the query vector, wherein the target probability score matrix is ​​used to characterize that the attention weights of the query data to all keys K are normalized; The acquisition module is also used to acquire all values ​​V related to the query vector; The calculation module is also used to obtain the target query result corresponding to the query data based on the target probability score matrix and all values ​​V.

11. A computing device, characterized in that, The computing device includes a processor coupled to a memory; the memory stores at least one instruction, which is loaded and executed by the processor to enable the computing device to implement the method of any one of claims 1-9.

12. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one instruction, which is loaded and executed by a processor to implement the method of any one of claims 1-9.

13. A computer program product, characterized in that, The computer program product includes a computer program / instruction that is executed by a processor to enable a computer to perform the method described in any one of claims 1-9.

14. A chip, including a processor, for retrieving and executing instructions stored in a memory, such that a computer having the chip installed performs the method of any one of claims 1-9.