Method, device and related product for determining query results of a query vector
Patent Information
- Application Number
- CN202510414712.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-02
- Publication Date
- 2026-10-16
AI Technical Summary
由于针对查询向量中每个查询对象都需要访问一次内存才能确定该查询对象在查找表中的索引,因此该过程中需要频繁访问内存,而频繁访问内存会导致额外的通信开销,从而降低了查表操作的效率
[0006]This application provides a method for determining the query result of a query vector. In the method provided by this application, a one-hot encoding model is pre-trained using a neural network model. When it is necessary to find the query result of a first query vector from a lookup table, the first query vector can be directly input into the one-hot encoding model, causing the one-hot encoding model to output the one-hot encoding matrix corresponding to the first query vector. Then, based on this one-hot encoding matrix and the lookup table, the query result of the first query vector is determined through matrix multiplication. The fact that the one-hot encoding model directly outputs the one-hot encoding matrix corresponding to the first query vector avoids the need to access memory for each query object in the query vector, thereby avoiding multiple discrete random memory accesses during the query process.
Smart Images

Figure CN122925691A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of big data technology, and in particular to a method, apparatus and related products for determining query results of query vectors. Background Technology
[0002] Many data processing techniques require table lookup operations. A table lookup operation involves retrieving the query result corresponding to each query object in the query vector from a lookup table. A lookup table consists of multiple indexes (keys) for multiple different objects and the query result (value) corresponding to each index. One technique to improve query efficiency is to first determine the one-hot encoding of the index corresponding to each query object in the lookup table. This one-hot encoding can also be called the one-hot encoding result of that query object. Then, based on the one-hot encoding result of each query object in the query vector, the query result corresponding to the query vector can be directly obtained through matrix multiplication.
[0003] In related technologies, descriptions of each index in the lookup table, such as the object corresponding to each index, are pre-stored in memory. Thus, when determining the one-hot encoding of the index corresponding to each query object in the lookup table within the query vector, the index of each query object in the lookup table can be obtained by accessing memory, thereby obtaining the one-hot encoding result of that query object. Since memory access is required once for each query object in the query vector to determine its index in the lookup table, this process involves frequent memory accesses. Frequent memory accesses lead to additional communication overhead, thereby reducing the efficiency of the table lookup operation. Summary of the Invention
[0004] This application provides a method, apparatus, and related products for determining query results of a query vector, which can improve the efficiency of table lookup operations. The technical solution is as follows:
[0005] Firstly, a method for determining the query result of a query vector is provided. In this method, a first query vector is input into a one-hot encoding model, and the one-hot encoding model outputs a one-hot encoding matrix corresponding to the first query vector. The one-hot encoding model is trained by a neural network model. The first query vector includes multiple query objects. Each row element in the one-hot encoding matrix indicates the one-hot encoding result of a query object, and the one-hot encoding result of the query object indicates the index of the query object in a lookup table. The lookup table includes multiple indexes and the query result corresponding to each of the multiple indexes. Based on the one-hot encoding matrix corresponding to the first query vector and the lookup table, the query result of the first query vector is determined by matrix multiplication.
[0006] This application provides a method for determining the query result of a query vector. In the method provided by this application, a one-hot encoding model is pre-trained using a neural network model. When it is necessary to find the query result of a first query vector from a lookup table, the first query vector can be directly input into the one-hot encoding model, causing the one-hot encoding model to output the one-hot encoding matrix corresponding to the first query vector. Then, based on this one-hot encoding matrix and the lookup table, the query result of the first query vector is determined through matrix multiplication. The fact that the one-hot encoding model directly outputs the one-hot encoding matrix corresponding to the first query vector avoids the need to access memory for each query object in the query vector, thereby avoiding multiple discrete random memory accesses during the query process.
[0007] Based on the method provided in the first aspect, in one possible implementation, the method is applied to a neural network processor (NPU) in a computing cluster, wherein the NPU is configured with a one-hot encoding model.
[0008] When this method is implemented on an NPU, since the one-hot encoding model on the NPU can directly output the one-hot encoding matrix corresponding to the first query vector, the entire query process does not require the NPU itself to support instructions or hardware for directly generating one-hot codes. Furthermore, it does not require the CPU to provide the one-hot encoding matrix to the NPU. Therefore, the method provided in this application is adaptable to various types of NPUs and has a wide range of applications.
[0009] Based on the method provided in the first aspect, in one possible implementation, the process of inputting the first query vector into the one-hot encoding model and having the one-hot encoding model output the one-hot encoding matrix corresponding to the first query vector can be as follows: if the length of the first query vector is less than the reference length, padding elements are added to the first query vector to obtain a second query vector with a length equal to the reference length, where the reference length is the length of the input vector required by the one-hot encoding model; the second query vector is input into the one-hot encoding model, and the one-hot encoding model outputs the one-hot encoding matrix corresponding to the second query vector; the one-hot encoding result corresponding to the padding elements is deleted from the one-hot encoding matrix corresponding to the second query vector to obtain the one-hot encoding matrix corresponding to the first query vector.
[0010] If the length of the input vector to the one-hot encoding model is limited to the reference length when training the one-hot encoding model, then the first query vector needs to be preprocessed according to the reference length before inputting it into the one-hot encoding model.
[0011] If the length of the first query vector is less than the reference length, padding elements can be added to the first query vector to obtain the second query vector, so that the length of the preprocessed second query vector meets the reference length required by the one-hot coding model.
[0012] Based on the method provided in the first aspect, in one possible implementation, the process of inputting the first query vector into the one-hot encoding model and having the one-hot encoding model output the one-hot encoding matrix corresponding to the first query vector can be as follows: if the length of the first query vector is greater than the reference length, the first query vector is divided into multiple sub-query vectors according to the reference length, where the reference length is the length of the input vector required by the one-hot encoding model; the multiple sub-query vectors are respectively input into the one-hot encoding model, and the one-hot encoding model outputs the one-hot encoding matrix corresponding to each of the multiple sub-query vectors; the one-hot encoding matrices corresponding to each of the multiple sub-query vectors are concatenated to obtain the one-hot encoding matrix corresponding to the first query vector.
[0013] If the length of the first query vector is greater than the reference length, the first query vector can be split into multiple sub-query vectors so that the length of the preprocessed sub-query vectors meets the reference length required by the one-hot coding model.
[0014] Based on the method provided in the first aspect, in one possible implementation, multiple sample data are acquired, each of which includes a sample query vector and a one-hot encoding matrix corresponding to the sample query vector, and the length of the sample query vector is a reference length; a neural network model is trained based on the multiple sample data to obtain a one-hot encoding model.
[0015] Because the query vectors and corresponding labels (i.e., the one-hot encoding matrices corresponding to the query vectors) in all sample data are deterministic during the training of the one-hot encoding model, and the comprehensiveness of the training dataset is ensured during its construction, the one-hot encoding results for each query object in the input query vector are also deterministic, as the neural network model can ensure a perfect fit to the seen data. This guarantees that no data that has not appeared will be included in the prediction.
[0016] Based on the method provided in the first aspect, in one possible implementation, the size of the neural network model is related to the size of the lookup table, and the size of the neural network model includes the number of parameters of the neural network model.
[0017] In this embodiment, the size of the neural network model can be selected based on the size of the lookup table. The size of the lookup table can be understood as the total number of entries included in the lookup table. The size of the neural network model typically includes the number of parameters of the neural network model. This ensures that the trained one-hot encoding model can fully meet the query requirements, so as to ensure that the complex features and relationships in the data can be captured during the inference stage, and to ensure the accuracy of the inference results.
[0018] Secondly, an apparatus for determining the query result of a query vector is provided. This apparatus has the functionality to implement the method behavior of determining the query result of a query vector described in the first aspect. The apparatus for determining the query result of a query vector includes at least one module, which is used to implement the method for determining the query result of a query vector provided in the first aspect.
[0019] Thirdly, a computing node is provided, the computing node comprising a processor and a memory, the memory storing programs that support the computing node in executing the method for determining query results of a query vector provided in the first aspect, and storing data involved in implementing the method for determining query results of a query vector provided in the first aspect. The processor is configured to execute the programs stored in the memory.
[0020] Fourthly, a computer-readable storage medium is provided, wherein instructions are stored therein, which, when executed on a computing node, cause the computing node to execute the method for determining the query result of the query vector as described in the first aspect.
[0021] Fifthly, a computer program product containing instructions is provided, which, when run on a computing node, causes the computing node to execute the method for determining the query result of the query vector as described in the first aspect.
[0022] The technical effects achieved by the corresponding technical means in the second to fifth aspects mentioned above are similar, and will not be repeated here. Attached Figure Description
[0023] Figure 1 This is a flowchart illustrating a table lookup operation;
[0024] Figure 2 This is a schematic diagram of a system architecture for determining query results using a query vector, provided in an embodiment of this application.
[0025] Figure 3 This is a schematic diagram of another system architecture for determining query results of a query vector, provided in an embodiment of this application.
[0026] Figure 4 This is a schematic diagram of another system architecture for determining query results of a query vector, provided in an embodiment of this application.
[0027] Figure 5 This is a schematic diagram of the structure of a computing node provided in an embodiment of this application;
[0028] Figure 6This is a flowchart of a method for training a one-hot coding model according to an embodiment of this application;
[0029] Figure 7 This is a flowchart illustrating a method for determining query results using a query vector, as provided in an embodiment of this application.
[0030] Figure 8 This is a schematic diagram of the structure of a device for determining the query result of a query vector according to an embodiment of this application. Detailed Implementation
[0031] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.
[0032] Before explaining the embodiments of this application, the technical terms involved in the embodiments of this application will be introduced first.
[0033] One-hot encoding, also known as single-bit encoding, uses an N-bit state register to encode N states. Each state has its own independent register bit, and at any given time, only one bit is active. For example, gender states include "male" and "female." Since there are two states, N=2. Accordingly, the one-hot encoding result for gender state "male" is 10, and the one-hot encoding result for gender state "female" is 01. Another example is sports states including "soccer," "basketball," and "volleyball." Since there are three states, N=3. Accordingly, the one-hot encoding result for sports state "soccer" is 100, the one-hot encoding result for sports state "basketball" is 010, and the one-hot encoding result for sports state "volleyball" is 001. Furthermore, for a lookup table, if the lookup table includes 256 indices, the one-hot encoding result for each index is a bit sequence of 256 bits, in which only one bit has a value of 1.
[0034] Neural network model: In the fields of machine learning and cognitive science, a neural network model is a mathematical or computational model that mimics the structure and function of biological neural networks (the central nervous system of animals, especially the brain) and is used to estimate or approximate functions.
[0035] Neural network processing unit (NPU): A type of microprocessor or computing system specifically designed for hardware acceleration of artificial intelligence (especially artificial neural networks, machine vision, machine learning, etc.).
[0036] The application scenarios involved in the embodiments of this application are described below.
[0037] Table lookup is a widely used technique in cryptography and data compression. It uses a predefined table (hereinafter referred to as a lookup table) to achieve fast non-linear transformations and encoding searches. This operation not only improves the execution efficiency of algorithms but also enhances data security and compression ratio.
[0038] For example, in the field of cryptography, a typical application of table lookup operations is the S-box (substitution box). An S-box is a mechanism used to replace each byte in plaintext, transforming the data into a difficult-to-break form. An S-box typically consists of a 16×16 table, which can be understood as containing 256 indices and 256 corresponding lookup results. Each index and its corresponding lookup result correspond to an input byte and a corresponding output byte, respectively. This substitution operation is non-linear, increasing the complexity of cryptographic algorithms and making them more difficult to crack. In the Advanced Encryption Standard (AES) algorithm, S-boxes are used to perform non-linear substitutions on each byte in a plaintext block, thereby improving encryption security.
[0039] For example, lookup operations also play a crucial role in data compression. Entropy coding is a technique that transforms a sequence of symbols into shorter bit sequences, encoding based on the probability of symbol occurrence. Lookup operations are used here to quickly find the code for each symbol. Huffman coding is a typical example, using a table to store the code for each symbol, thus achieving efficient code lookup. Furthermore, dictionary coding is another important application of lookup operations. Dictionary coding achieves data compression by replacing frequently occurring symbol sequences with shorter codes. In the LZW (Lempel-Ziv-Welch) compression algorithm, a lookup table is used to store frequently occurring symbol sequences and their corresponding replacements. Lookup operations allow the algorithm to quickly find and replace these sequences, thereby achieving data compression.
[0040] The advantage of table lookup operations lies in their ability to significantly improve algorithm execution speed because they avoid repetitive computations. By pre-compiling and storing the results, the algorithm can directly retrieve the required value from the lookup table at runtime, thus saving time. Therefore, table lookup operations remain very popular in scenarios requiring fast execution and high security due to their simplicity and efficiency.
[0041] In summary, table lookup operations play a crucial role in fields such as cryptography and compression / decompression. By rapidly performing non-linear operations and encoding searches, it not only improves algorithm performance but also enhances data security and compression efficiency. With technological advancements, table lookup operations will continue to play a vital role in these areas, providing strong support for data protection and information processing.
[0042] The method for determining the query result of the query vector provided in this application embodiment can be applied to the two table lookup operation scenarios mentioned above. Optionally, the method provided in this application embodiment can also be applied to other types of table lookup operation scenarios, which will not be illustrated here.
[0043] Furthermore, in modern computing architectures, the NPU is a processor specifically designed for tasks such as machine learning and deep learning. The NPU's design focuses on optimizing parallel processing capabilities to accelerate the computation of neural network models. However, the NPU may encounter performance bottlenecks when performing certain types of operations, especially discrete random memory access operations involving table lookups. Therefore, the following considerations exist when performing table lookup operations on the NPU:
[0044] 1. Optimize memory access patterns. NPUs are typically optimized for contiguous memory access to support large-scale matrix operations in neural network models. However, the query objects in a user-initiated query vector are random, so table lookup operations often involve multiple discrete random memory accesses, which contradicts the design intent of NPUs. Therefore, to efficiently perform table lookup operations on an NPU, the algorithm may need to be adjusted to reduce the need for discrete random memory accesses.
[0045] 2. Improve algorithm efficiency. In applications such as cryptography and data compression, table lookup operations are crucial for efficient processing. If the NPU can support efficient table lookup operations, the performance of these algorithms on the NPU will be significantly improved, making the NPU a more general-purpose and powerful computing platform.
[0046] 3. Adapting to diverse computing needs. With the continuous expansion of applications such as artificial intelligence and machine learning, the NPU needs to be able to adapt to various computing modes. By optimizing table lookup operations, the NPU can better serve cryptography, data compression, and other applications that require frequent random access to memory.
[0047] 4. Improve overall system performance. In some application scenarios, table lookup operations can be the bottleneck of the entire system. By optimizing table lookup operations on the NPU, the overall system performance can be significantly improved, making the NPU a more efficient and reliable computing platform.
[0048] Therefore, performing table lookup operations on the NPU is not only necessary but also crucial for improving the NPU's versatility and performance. The method provided in this application, through optimized memory access patterns, algorithmic innovation, and co-design of hardware and software, enables efficient table lookup operations on the NPU, thereby expanding the NPU's application scope and improving its performance in various computing tasks.
[0049] To facilitate subsequent understanding, we will first explain the principle of table lookup operations.
[0050] Figure 1 This is a flowchart illustrating a table lookup operation. For example... Figure 1 As shown, assuming the lookup table is a hash table, the hash table contains multiple key-value pairs. Figure 1 Taking n-1 key-value pairs as an example, the values in these n-1 key-value pairs are labeled V1, V2, ..., Vn-1, respectively. Multiple random queries are performed on this lookup table. Assuming three random queries have been performed so far, the query vectors input to these three random queries are labeled q, respectively. l q m q n Each query vector includes multiple query objects (q). i ). Query vector q l For example, query vector q l Including q l1 q l2 、...q la There are *a* query objects. Each query object has *q* queries. i There is a key-value pair in the lookup table. Therefore, for any query vector, the lookup table stored in the storage system needs to be accessed multiple times before the query result corresponding to the query vector is obtained. Since the key-value pair corresponding to any query object in the lookup table is random, this process can also be called multiple discrete random accesses.
[0051] like Figure 1 As shown, for the query vector q l This requires *a* discrete random memory accesses. For the query vector *q*... m This requires b discrete random memory accesses. For the query vector q... n It requires c discrete random memory accesses.
[0052] Figure 1The lookup operation shown requires accessing the value corresponding to each query object in the lookup table one by one, resulting in low efficiency. To avoid accessing the value corresponding to each query object in the lookup table one by one, a technique using one-hot encoding and matrix multiplication is currently used in table lookup operations. This technique can be implemented by an NPU to fully utilize the parallel processing capabilities of the NPU.
[0053] The process of implementing table lookup operations using one-hot encoding and matrix multiplication is as follows:
[0054] Step 1: Initialize the lookup table (lookup_table).
[0055] The initialized lookup table is an array of length len, i.e., lookup_table = [a0, a1, a2, ..., a...]. (len-1) ], any element in the array is the query result corresponding to a certain query object.
[0056] Step 2: Convert the query vector into a one-hot encoded matrix.
[0057] For ease of explanation, let's denote the query vector as q, and the one-hot encoding matrix resulting from query vector q as Q. Assume the length of query vector q is n, meaning it contains n query objects. Then, the shape of the one-hot encoding matrix Q corresponding to query vector q is (n, len). That is, the one-hot encoding matrix Q contains n rows of elements, each row having a length of len. Each of the n rows corresponds one-to-one with one of the n queries, and each row indicates the index of the corresponding query object in the lookup table. For example, if a row corresponding to a query object is 000100…00 (a total of len bits, with only the fourth bit being 1 and the rest being 0), it indicates that the index of that query object in the lookup table is 4.
[0058] Step 3: Perform matrix multiplication.
[0059] Convert the lookup_table into a column vector as follows: lookup_table T :
[0060]
[0061] Perform the following matrix multiplication:
[0062] R = Q * lookup_table T
[0063] The shape of R is (n,1), meaning that R contains n rows of elements, and each row contains a query result (the query result is an element in the initialized lookup table).
[0064] Step 4: Extract Results:
[0065] The final result R is the query result of the query vector in the lookup table, so R can be output directly.
[0066] The algorithm described above effectively avoids accessing the value corresponding to each query object in the lookup table one by one by using matrix multiplication. Furthermore, the algorithm can be implemented using an NPU, thus fully utilizing the NPU's parallel computing capabilities. However, several key assumptions and potential shortcomings remain in the implementation, which may affect the algorithm's effectiveness on specific hardware architectures.
[0067] 1. Hardware support issues for one-hot encoding matrix generation
[0068] In step 2, the algorithm requires converting the query vector q into a one-hot encoded matrix Q. Specifically, the algorithm converts each query object q[i] in the query vector into a vector of length len, i.e., into a one-hot encoded result. For any query object, in the one-hot encoded result corresponding to that query object, only the bit at the index position of that query object in the lookup table is 1, and the bits at the other positions are 0. For example, if the third entry in the lookup table includes the query object, that is, the index of that query object in the lookup table is 3, then in the one-hot encoded result corresponding to that query object, only the third bit is 1, and the bits at the other positions are all 0.
[0069] The above process can be implemented using software or hardware that directly generates one-hot codes on the NPU. This software or hardware determines the one-hot code result for each query object through multiple discrete random memory accesses. However, this process can present significant challenges in implementation. If the NPU itself does not support the aforementioned software or hardware for directly generating one-hot codes, then it is necessary to set each query object q in the query vector in the NPU one by one through a series of discrete write operations. i The corresponding one-hot encoding result is then used to set the one-hot encoding matrix corresponding to the query vector in the NPU. This item-by-item write operation requires additional computing resources, which may lead to a significant performance bottleneck.
[0070] 2. Discrete memory access and additional communication overhead
[0071] When software or hardware supports direct generation of one-hot codes on the NPU, the NPU uses a lookup table for each query object q in the query vector. iThe process involves finding the corresponding index, generating a one-hot encoding result for each query, and then obtaining the one-hot encoding matrix corresponding to the query vector. The NPU then executes step 3 above. However, this method requires retrieving the index of each query object in the lookup table from memory, which also results in multiple discrete random memory accesses. Especially when the lookup table is large or the query vector contains a large number of query objects, the NPU's weak discrete random memory access performance makes it unable to efficiently handle this intensive discrete random memory access pattern.
[0072] 3. Challenges in heterogeneous systems
[0073] In heterogeneous systems, the one-hot encoding matrix corresponding to the query vector can be quickly generated using the CPU's instruction set. The CPU then transmits this one-hot encoding matrix to the NPU, which executes step 3 above. However, the generation of the one-hot encoding matrix in this approach may consume CPU computing resources, resulting in the overall system's computing power not being optimally utilized. Furthermore, transmitting large amounts of data from the CPU to the NPU can lead to high latency and communication overhead.
[0074] Based on this, embodiments of this application provide a method for determining the query result of a query vector. In the method provided by this application, a one-hot encoding model is pre-trained using a neural network model. Thus, when it is necessary to find the query result of a first query vector from a lookup table, the first query vector can be directly input into the one-hot encoding model, causing the one-hot encoding model to output the one-hot encoding matrix corresponding to the first query vector. Then, based on this one-hot encoding matrix and the lookup table, the query result of the first query vector is determined through matrix multiplication.
[0075] The one-hot encoding model directly outputs the one-hot encoding matrix corresponding to the first query vector, avoiding the need to access memory for each query object in the query vector, thus avoiding multiple discrete random memory accesses during the query process.
[0076] Furthermore, when this method is implemented on an NPU, since the one-hot encoding model on the NPU can directly output the one-hot encoding matrix corresponding to the first query vector, the entire query process does not require the NPU itself to support instructions or hardware for directly generating one-hot codes. It also does not require the CPU to provide the one-hot encoding matrix to the NPU. Therefore, the method provided in this application is adaptable to various types of NPUs and has a wide range of applications.
[0077] The systems, methods, and apparatuses provided in the embodiments of this application will be described in detail below.
[0078] Figure 2 This is a schematic diagram of a system architecture for determining query results using a query vector, provided in an embodiment of this application. For example... Figure 2As shown, the system includes a one-hot encoding model generation module and a query vector reasoning module.
[0079] The one-hot coding model generation module is used to train the neural network model to obtain the one-hot coding model provided in this embodiment. For example, as shown... Figure 2 As shown, the one-hot encoding model generation module includes a model structure selection unit, a training unit, and a model storage unit.
[0080] The model structure selection unit is used to select a suitable neural network model for training. In this embodiment, the size of the neural network model can be selected based on the size of the lookup table. The size of the lookup table can be understood as the total number of entries included in the lookup table. The size of the neural network model typically includes the number of parameters. This ensures that the trained one-hot encoding model can fully meet the query requirements, guaranteeing the capture of complex features and relationships in the data during the inference phase and ensuring the accuracy of the inference results. For example, the larger the size of the lookup table, the larger the size of the neural network model used for training. For instance, considering that the total number of entries in the lookup table is generally in the range of 10 to 1000, a neural network model with 100 parameters is sufficient for training.
[0081] Alternatively, the model structure selection unit may disregard the size of the lookup table and directly select a general-sized neural network model for training.
[0082] Additionally, the model structure selection unit can also be used to select the length of the input vector to the neural network model, i.e., the input vector length. For example, a suitable input vector length can be selected based on the hardware's capabilities. For instance, if the NPU supports a maximum input vector length of n for processing by the neural network model, the input vector length can be less than or equal to n. Optionally, a suitable input vector length can also be selected based on the length of query vectors input by historical users. For example, the average length of query vectors input by historical users can be used as the input vector length.
[0083] The training unit is used to: acquire multiple sample data sets and train a neural network model based on these sample data sets to obtain a one-hot encoding model. Each sample data set includes a sample query vector and a one-hot encoding matrix corresponding to that sample query vector. The length of each sample query vector is a reference length, which is the input vector length determined by the model structure selection unit.
[0084] The multiple sample data can be collectively referred to as the training dataset. In this embodiment, the training dataset is designed to cover all possible query vector scenarios, ensuring comprehensive coverage. This guarantees that the trained one-hot encoding model will not encounter unseen query vectors during the inference phase. In other words, the training dataset is representative.
[0085] Furthermore, the process of training the neural network model to obtain the one-hot encoding model can be completed offline. Offline training ensures sufficient training time and allows for thorough training, thereby avoiding underfitting during training and ensuring the efficiency and accuracy of the trained one-hot encoding model during the inference phase. Optionally, the process of training the neural network model to obtain the one-hot encoding model can also be completed online; this embodiment of the application does not limit this approach.
[0086] The model storage unit is used to store the one-hot encoded model obtained from the training unit. This application embodiment does not limit the storage location of the one-hot encoded model. For example, when the method provided in this application embodiment is applied to an NPU, the trained one-hot encoded model can be loaded into the storage system connected to the NPU.
[0087] Because the query vectors and corresponding labels (i.e., the one-hot encoding matrices corresponding to the query vectors) in all sample data are deterministic during the training of the one-hot encoding model, and the comprehensiveness of the training dataset is guaranteed during its construction, the one-hot encoding result for each query object in the query vector q is also deterministic during inference using the one-hot encoding model. This ensures that no data that has not yet appeared will be included in the prediction.
[0088] Continue to refer to Figure 2 The query vector inference module includes a model loading unit, a query vector preprocessing unit, a model inference unit, and a post-processing unit.
[0089] The model loading unit is used to load the one-hot encoded model obtained from the training process into the relevant memory for performing the table lookup operation. For example, in a scenario where the table lookup operation is implemented by an NPU, the model loading unit can load the one-hot encoded model into the NPU's memory, and optionally, it can also reside permanently in the NPU's memory. As another example, in a scenario where the table lookup operation is implemented by other types of processors, such as a graphics processing unit (GPU) or a central processing unit (CPU), the model loading unit can load the one-hot encoded model into the memory of those other types of processors.
[0090] The query vector preprocessing unit is used to preprocess the query vector to be queried according to the previously determined input vector length, so as to ensure that the length of the input vector input to the one-hot encoding model meets the requirements. The implementation method for preprocessing the query vector can be referred to in subsequent embodiments, and will not be elaborated here.
[0091] The model inference unit is used to infer the preprocessed query vector to obtain the one-hot encoding matrix corresponding to the query vector.
[0092] The post-processing unit is used to perform post-processing on the one-hot encoding matrix corresponding to the query vector, such as determining the query result corresponding to the query vector through matrix multiplication.
[0093] It should be noted that, Figure 2 The system illustrated can be applied to computing systems. This computing system includes multiple computing nodes, each including a CPU and an NPU. The aforementioned modules and units can be integrated on the same NPU or deployed separately on different NPUs. Optionally, they can be partially deployed on the CPU and partially deployed on the NPU. This application does not limit this approach.
[0094] Figure 3 This is a schematic diagram of another system architecture for determining query results using a query vector, provided in an embodiment of this application. For example... Figure 3 As shown, Figure 2 All modules are implemented in the NPU. Specifically, the units in the one-hot encoding model generation module are deployed in the first NPU, and the units in the query vector inference module are deployed in the second NPU. The first NPU and the second NPU can be the same NPU or different NPUs; this embodiment does not limit this.
[0095] Figure 4 This is a schematic diagram of another system architecture for determining query results using a query vector, provided in an embodiment of this application. For example... Figure 4 As shown, Figure 2 The model structure selection unit can be implemented using a CPU. The training unit, model storage unit, model loading unit, query vector preprocessing unit, model inference unit, and post-processing unit can be implemented using an NPU. The NPU deploying the training unit and model storage unit can be the same as or different from the NPU deploying the query vector inference module; this embodiment does not limit this.
[0096] It should be noted that, Figure 3 and Figure 4 For example illustration Figure 2 The hardware implementation of the module is shown. Optionally, in the embodiments of this application, Figure 2The modules shown can also be deployed in other ways, which will not be explained in detail here.
[0097] Figure 5 This is a schematic diagram of the structure of a computing node provided in an embodiment of this application. For example... Figure 5 As shown, the computing node includes at least one central processing unit (CPU) 501, at least one accelerator card 505, a communication bus 502, a memory 503, and at least one communication interface 504. The accelerator card can be, for example, an NPU, a GPU, etc., and runs the one-hot encoding model provided in this embodiment.
[0098] The communication bus 502 may include a path for transmitting information between the aforementioned components.
[0099] Memory 503 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disks 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 and accessible by a computer, but not limited thereto. Memory 503 may exist independently and be connected to processor 501 via communication bus 502. Memory 503 may also be integrated with CPU 501.
[0100] The memory 503 stores program code for executing the scheme of this application, and its execution is controlled by the CPU 501 or the accelerator card 505. The CPU 501 or the accelerator card 505 executes the program code stored in the memory 503. The program code may include one or more software modules. The foregoing embodiments can determine the data used for application development through the processor 501 or the accelerator card 505 and one or more software modules in the program code in the memory 503.
[0101] For example, CPU 501 is used to obtain a first query vector in response to user input and input the first query vector to accelerator card 505 running a one-hot encoding model. Accelerator card 505 outputs the one-hot encoding matrix corresponding to the first query vector through the one-hot encoding model, and determines the query result corresponding to the first query vector through matrix multiplication based on the one-hot encoding matrix and the lookup table.
[0102] Communication interface 504 uses any transceiver-like device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area networks (WLAN), etc.
[0103] In a specific implementation, as one example, the computing node may further include an output device 506 and an input device 507. The output device 506 communicates with the processor 501 and can display information in various ways. For example, the output device 506 may be a liquid crystal display (LCD), a light-emitting diode (LED) display device, a cathode ray tube (CRT) display device, or a projector, etc. The input device 507 communicates with the processor 501 and can receive user input in various ways. For example, the input device 507 may be a mouse, keyboard, touchscreen device, or sensing device, etc.
[0104] The aforementioned computing node can be a general-purpose computing node or a dedicated computing node. In specific implementations, the computing node can be a desktop computer, a laptop computer, a network server, a handheld digital assistant (PDA), a mobile phone, a tablet computer, a wireless terminal device, a communication device, or an embedded device. This application does not limit the type of computing node.
[0105] Figure 6 This is a flowchart illustrating a method for training a one-hot encoding model according to an embodiment of this application. Figure 6 As shown, the method includes the following steps.
[0106] Step 601: Obtain multiple sample data. Each sample data includes a sample query vector and a one-hot encoding matrix corresponding to the sample query vector. The length of the sample query vector is the reference length.
[0107] For any given sample query vector, the sample query vector includes multiple query objects. Each row element in the one-hot encoding matrix is used to indicate the one-hot encoding result of a query object, and the one-hot encoding result of the query object indicates the index of the query object in the lookup table. The lookup table includes multiple indexes and the query result corresponding to each of the multiple indexes.
[0108] based on Figure 2 As can be seen from the relevant content, in some embodiments, the size of the neural network model is related to the size of the lookup table, and the size of the neural network model includes the number of parameters in the neural network model. This will not be elaborated further here.
[0109] Additionally, the explanation of the reference length can also be found here. Figure 2 The relevant content will not be repeated here.
[0110] For example, the neural network model is labeled E(Q), and the sample query vector in the sample data is labeled Q. m The one-hot encoding matrix corresponding to the sample query vector in the sample data is labeled as E. n , where m is the length of the sample query vector, i.e., the reference length, and n is the total number of entries in the lookup table. Therefore, each sample data can be labeled as (Q m E n ).
[0111] Step 602: Train the neural network model based on multiple sample data to obtain a one-hot encoding model.
[0112] The purpose of training the neural network model based on multiple sample data is to enable the neural network model to learn the complex relationship between the sample query vector and the corresponding one-hot encoding matrix in the sample data.
[0113] In some embodiments, the process of training a neural network model based on multiple sample data to obtain a one-hot encoding model can be as follows: Adjust the values of the parameters in the neural network model; then, for any sample data, input the sample query vector from that sample data into the neural network model so that the neural network model outputs the one-hot encoding matrix corresponding to the sample query vector; calculate the deviation between the one-hot encoding matrix output by the neural network model and the one-hot encoding matrix in the sample data, obtaining the deviations corresponding to multiple sample data respectively; and calculate a comprehensive deviation based on the deviations corresponding to the multiple sample data respectively. If the comprehensive deviation is large, readjust the values of the parameters in the neural network model according to the comprehensive deviation, and perform the next round of training. Training is terminated when the comprehensive deviation determined by the neural network model after the most recent parameter adjustment is less than the reference deviation, and the neural network model after the most recent parameter adjustment is taken as the final trained one-hot encoding model.
[0114] One method for calculating a comprehensive deviation based on the deviations corresponding to multiple sample data can be: using the average of the deviations corresponding to the multiple sample data as the comprehensive deviation, or using the maximum deviation among the deviations corresponding to the multiple sample data as the comprehensive deviation. This application does not limit this approach.
[0115] For any sample data, the deviation between the one-hot encoding matrix output by the neural network model and the one-hot encoding matrix in the sample data can be recorded as |E(Q)|. m )-E n The goal of training is to minimize |E(Q)|. m )-E n |, that is, min(|E(Q) m )-E n |).
[0116] It should be noted that the embodiments of this application do not limit the process of training the one-hot encoding model. When applying the embodiments of this application, other methods can also be used to train the model based on the training dataset, which will not be illustrated here.
[0117] Figure 7 This is a flowchart illustrating a method for determining query results using a query vector, as provided in an embodiment of this application. Figure 7 As shown, the method includes the following steps.
[0118] Step 701: Input the first query vector into the one-hot encoding model. The one-hot encoding model outputs the one-hot encoding matrix corresponding to the first query vector. The one-hot encoding model is trained by the neural network model. The first query vector includes multiple query objects. Each row element in the one-hot encoding matrix is used to indicate the one-hot encoding result of a query object. The one-hot encoding result of the query object indicates the index of the query object in the lookup table. The lookup table includes multiple indexes and the query result corresponding to each of the multiple indexes.
[0119] In some embodiments, steps 701 and 702 are applied to an NPU in a computing cluster, the NPU being configured with a one-hot encoding model. Optionally, Figure 7 The method shown can also be implemented by other types of processors, and this application embodiment does not limit this.
[0120] In addition, in some embodiments, if there is no limit to the length of the input vector of the one-hot encoding model when training the one-hot encoding model, the first query vector can be directly input into the one-hot encoding model so that the one-hot encoding model directly outputs the one-hot encoding matrix corresponding to the first query vector.
[0121] Optionally, in other embodiments, if the length of the input vector of the one-hot coding model is limited to a reference length when training the one-hot coding model, then the first query vector needs to be preprocessed according to the reference length before inputting the first query vector into the one-hot coding model, so as to input the preprocessed first query vector into the one-hot coding model.
[0122] Based on this, for example, the implementation of inputting the first query vector into the one-hot encoding model and having the one-hot encoding model output the one-hot encoding matrix corresponding to the first query vector can be as follows: if the length of the first query vector is less than the reference length, add padding elements to the first query vector to obtain a second query vector with a length equal to the reference length, where the reference length is the length of the input vector required by the one-hot encoding model; input the second query vector into the one-hot encoding model, and the one-hot encoding model outputs the one-hot encoding matrix corresponding to the second query vector; delete the one-hot encoding result corresponding to the padding elements from the one-hot encoding matrix corresponding to the second query vector to obtain the one-hot encoding matrix corresponding to the first query vector.
[0123] If the length of the first query vector is less than the reference length, padding elements can be added to the first query vector to obtain the second query vector, so that the length of the preprocessed second query vector meets the reference length required by the one-hot coding model.
[0124] One way to add padding elements to the first query vector is to continue padding with multiple query objects after the last query object in the first query vector, until the length of the padded first query vector reaches the reference length. These multiple padded query objects can be query objects from the first query vector, for example, they can all be the last query object in the first query vector.
[0125] For example, if the first query vector is (apple, banana, pear) with a reference length of 5, then the second query vector after filling can be (apple, banana, pear, pear, pear).
[0126] For example, the implementation of inputting the first query vector into the one-hot encoding model and outputting the one-hot encoding matrix corresponding to the first query vector can be as follows: if the length of the first query vector is greater than the reference length, the first query vector is divided into multiple sub-query vectors according to the reference length, where the reference length is the length of the input vector required by the one-hot encoding model; the multiple sub-query vectors are input into the one-hot encoding model respectively, and the one-hot encoding model outputs the one-hot encoding matrix corresponding to each of the multiple sub-query vectors; the one-hot encoding matrices corresponding to each of the multiple sub-query vectors are concatenated to obtain the one-hot encoding matrix corresponding to the first query vector.
[0127] If the length of the first query vector is greater than the reference length, the first query vector can be split into multiple sub-query vectors so that the length of the preprocessed sub-query vectors meets the reference length required by the one-hot coding model.
[0128] The implementation of dividing the first query vector into multiple sub-query vectors according to a reference length can be as follows: For multiple query objects arranged in sequence in the first query vector, group the sequentially arranged query objects according to the reference length, with the total number of query objects in each group being the reference length. If the length of the first query vector is an integer multiple of the reference length, then the total number of query objects in the last group after division is also the reference length, and each group of query objects is treated as a sub-query vector. If the length of the first query vector is not an integer multiple of the reference length, then the total number of query objects in the last group after division will be less than the reference length. In this case, the last group of query objects is padded to ensure that its length also reaches the reference length, and each group of query objects is treated as a sub-query vector.
[0129] The method for filling the last group of query objects can be referenced from the method for filling the first query vector, and will not be repeated here.
[0130] Optionally, in this embodiment, after receiving the first query vector from the user each time, the first query vector can be cached first, and then the scheme provided in this embodiment can be executed after the cached query vector reaches a certain size. Further details will not be elaborated here.
[0131] Step 702: Based on the one-hot encoding matrix and lookup table corresponding to the first query vector, determine the query result of the first query vector through matrix multiplication.
[0132] The implementation of step 702 can refer to step 3 in the aforementioned process of implementing table lookup operation through one-hot encoding and matrix multiplication, and will not be repeated here.
[0133] To further understand the methods provided in the embodiments of this application, the following example uses a lookup table to illustrate the methods provided in the embodiments of this application.
[0134] Assume the lookup table after array processing is: lookup_table = [2, 5, 128, 6, 251, ..., 100, 97]. The lookup table has a length of 256, meaning the array contains 256 elements, each representing a value corresponding to an index in the lookup table. The first query vector q is: q = [1, 3, 4, 255, 2], where each element represents a query object. We expect the query result to be result = [5, 6, 251, 97, 128], meaning each element of the query vector acts as an index to access the lookup table and return the corresponding query result.
[0135] Based on this, the aforementioned embodiments can be implemented through the following steps:
[0136] Step 1: Initialize the lookup table.
[0137] First, initialize the lookup table `lookup_table` with a length of 256, where each element represents a value in the lookup table. The initialized lookup table is as follows:
[0138] lookup_table=[A[0],A[1],A[2],...,A
[254] ,A
[255] ]
[0139] Where A[0] represents the value corresponding to index 0 in the lookup table, A[1] represents the value corresponding to index 1 in the lookup table, and so on, A
[255] represents the value corresponding to index 255 in the lookup table. Combining the above introduction to the lookup table, we know that A[0] = 2, A[1] = 5, and so on.
[0140] Step 2: Construct a neural network model and train it.
[0141] To perform efficient searching, a deep neural network (DNN) can be designed and trained. Optionally, other types of neural network models can also be selected for training in this embodiment; the following explanation uses DNN as an example. The purpose of training is to map the query object of the query vector q to the one-hot encoding of the index in the lookup table. During the training phase, the input of the DNN is the sample query vector, and the output is the one-hot encoding of the index of each query object in the lookup table, that is, the output is the one-hot encoding matrix of the sample query vector, so that the DNN can learn the mapping relationship between each query object and the one-hot encoding of the index in the lookup table.
[0142] Step 3: Reasoning stage.
[0143] The first query vector q = [1,3,4,255,2] is input into the trained DNN (i.e., the one-hot encoding model). The one-hot encoding model will generate a corresponding one-hot encoding result for each query object, resulting in a one-hot encoding matrix. The output one-hot encoding matrix is represented as follows:
[0144]
[0145] Here, `q_encode` has a shape of (size, 256), where `size` is the size of the first query vector `q`, which is also the total number of query objects in the first query vector `q`. The first row of the one-hot encoding matrix contains the one-hot encoding of the index of the first query object in the first query vector within the lookup table; the second row contains the one-hot encoding of the index of the second query object in the first query vector within the lookup table; and so on. The fifth row of the one-hot encoding matrix contains the one-hot encoding of the index of the fifth query object in the first query vector within the lookup table.
[0146] Step 4: Matrix multiplication:
[0147] R = q_encode * lookup_table T
[0148] Step 5: Extract the results.
[0149] For the result of the matrix multiplication above, the query result corresponding to the first query vector is: result = [5, 6, 251, 97, 128].
[0150] In summary, the solution provided in this application can achieve the following technical effects:
[0151] (1) Construct a neural network model to implement one-hot encoding.
[0152] This application proposes a method to transform the one-hot encoding generation process into neural network inference, avoiding the redundant data movement and computation required for generating one-hot codes separately in traditional techniques. Compared with traditional discrete search methods, by constructing a specialized neural network model, the query vector can be directly mapped to a one-hot encoding matrix, avoiding element-by-element discrete memory access in traditional methods. Therefore, this improvement reduces data transmission overhead. Furthermore, this method fully utilizes the computing power of the NPU, transforming the encoding process into efficient matrix computation, thereby replacing memory access with computation, significantly improving the throughput of search operations and reducing memory access overhead. In addition, directly performing encoding prediction through neural networks can accelerate the query process, especially in parallel computing and large-scale data processing scenarios, significantly improving overall system performance.
[0153] (2) Discrete random search is converted into one inference and one matrix multiplication.
[0154] This application further optimizes the query operation by proposing a parallel query method using a single neural network inference and matrix multiplication. Specifically, the query vector is used as input to the neural network, and a corresponding one-hot encoding matrix is generated through the inference process. The query result is then directly obtained through matrix multiplication. This method can complete the search for multiple elements in a single inference process, equivalent to discrete memory access for each element in traditional methods, while significantly improving computational parallelism and query efficiency.
[0155] (3) Query vector preprocessing.
[0156] This application proposes an optimized preprocessing scheme for query vectors. Query vectors can be processed using caching techniques, padding of short query vectors, or mini-batch processing of long query vectors to conform to the format of the neural network input layer, i.e., the length of the input vector required by the neural network model. This preprocessing method can significantly improve query efficiency and optimize the use of NPU computing resources through parallel processing.
[0157] By caching query vectors, data can be pre-loaded into the NPU, reducing data transmission latency. Short query vector padding ensures that data of different query lengths is compatible with neural network models. Batch processing of long query vectors improves the parallelism of batch computation, significantly increasing computational efficiency. These preprocessing measures not only optimize the NPU's data throughput but also enhance the system's adaptability to different query scenarios, reduce computation latency, and improve overall performance.
[0158] In summary, the embodiments of this application utilize computational memory access and improve throughput through preprocessing. Verification has shown that the theoretical average query latency is 60 times more efficient than that of traditional discrete memory access methods.
[0159] Additionally, it should be noted that the method provided in this application can be applied to various scenarios that require performing lookup table operations. Examples will not be provided here.
[0160] For example, in data compression scenarios, lookup tables are often used to store the mapping between strings and compressed bytes. When compressing large files or message streams, lookup table access often becomes a performance bottleneck. By transforming traditional lookup table operations into neural network inference, parallel processing can be performed during compression, improving the speed of data compression. By using query vector preprocessing techniques, data streams of different sizes and complexities can be effectively handled, optimizing the execution efficiency of data compression algorithms under different input conditions, especially in multi-threaded or distributed systems, thus improving overall compression performance.
[0161] For example, in real-time data stream processing and pattern matching scenarios, such as financial market data analysis and network traffic monitoring, it is often necessary to quickly match and search for features in the data stream. Suppose there is a pattern table that stores the mapping relationship between specific stream features and patterns; each time a data packet arrives, a match needs to be performed in this table. Traditional methods perform a list-by-list search through discrete memory access, which is inefficient. The method described above optimizes the pattern matching search operation through neural network inference, enabling parallel query computation when multiple data streams arrive simultaneously, significantly improving matching efficiency. Furthermore, query vector preprocessing improves the system's adaptability to various data formats, increasing throughput.
[0162] Figure 8 This is a schematic diagram of a device for determining the query result of a query vector according to an embodiment of this application. This device can be deployed, for example, in... Figure 5 The computational nodes shown are used to implement the method for determining the query result of the query vector provided in the embodiments of this application. For example... Figure 8 As shown, the device 800 includes the following modules.
[0163] Input module 801 is used to input the first query vector into the one-hot encoding model. The one-hot encoding model outputs the one-hot encoding matrix corresponding to the first query vector. The one-hot encoding model is trained by a neural network model. The first query vector includes multiple query objects. Each row element in the one-hot encoding matrix indicates the one-hot encoding result of a query object, and the one-hot encoding result of the query object indicates the index of the query object in the lookup table. The lookup table includes multiple indexes and the query result corresponding to each of the multiple indexes. For specific implementation details, please refer to [reference needed]. Figure 7 Step 701 in the embodiment.
[0164] The determination module 802 is used to determine the query result of the first query vector by matrix multiplication based on the one-hot encoding matrix and lookup table corresponding to the first query vector. For specific implementation details, please refer to [reference needed]. Figure 7 Step 702 in the embodiment.
[0165] In some embodiments, the device is applied to a neural network processor (NPU) in a computing cluster, wherein the NPU is configured with a one-hot encoding model.
[0166] In some embodiments, the input module is used for:
[0167] If the length of the first query vector is less than the reference length, padding elements are added to the first query vector to obtain a second query vector with a length equal to the reference length, which is the length of the input vector required by the one-hot encoding model.
[0168] The second query vector is input into the one-hot encoding model, and the one-hot encoding model outputs the one-hot encoding matrix corresponding to the second query vector.
[0169] The one-hot encoding result corresponding to the padding element is deleted from the one-hot encoding matrix corresponding to the second query vector to obtain the one-hot encoding matrix corresponding to the first query vector.
[0170] In some embodiments, the input module is used for:
[0171] If the length of the first query vector is greater than the reference length, the first query vector is divided into multiple sub-query vectors according to the reference length, where the reference length is the length of the input vector required by the one-hot coding model.
[0172] Multiple subquery vectors are input into the one-hot encoding model, and the one-hot encoding model outputs the one-hot encoding matrix corresponding to each of the multiple subquery vectors.
[0173] The one-hot encoding matrices corresponding to each of the multiple subquery vectors are concatenated to obtain the one-hot encoding matrix corresponding to the first query vector.
[0174] In some embodiments, the device further includes:
[0175] The acquisition module is used to acquire multiple sample data. Each sample data includes a sample query vector and a one-hot encoding matrix corresponding to the sample query vector. The length of the sample query vector is a reference length.
[0176] The training module is used to train the neural network model based on multiple sample data to obtain a one-hot encoded model.
[0177] In some embodiments, the size of the neural network model is related to the size of the lookup table, and the size of the neural network model includes the number of parameters in the neural network model.
[0178] In summary, this application provides an apparatus for determining the query result of a query vector. In the apparatus provided in this application, a one-hot encoding model is pre-trained using a neural network model. Thus, when it is necessary to find the query result of a first query vector from a lookup table, the first query vector can be directly input into the one-hot encoding model, causing the one-hot encoding model to output the one-hot encoding matrix corresponding to the first query vector. Then, based on this one-hot encoding matrix and the lookup table, the query result of the first query vector is determined through matrix multiplication. The fact that the one-hot encoding model directly outputs the one-hot encoding matrix corresponding to the first query vector avoids the need to access memory for each query object in the query vector, thereby avoiding multiple discrete random memory accesses during the query process.
[0179] Furthermore, when this method is implemented on an NPU, since the one-hot encoding model on the NPU can directly output the one-hot encoding matrix corresponding to the first query vector, the entire query process does not require the NPU itself to support instructions or hardware for directly generating one-hot codes. It also does not require the CPU to provide the one-hot encoding matrix to the NPU. Therefore, the method provided in this application is adaptable to various types of NPUs and has a wide range of applications.
[0180] It should be noted that the apparatus for determining the query result of a query vector provided in the above embodiments is only illustrated by the division of the above functional modules. In practical applications, the above 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. In addition, the apparatus for determining the query result of a query vector and the method embodiment for determining the query result of a query vector provided in the above embodiments belong to the same concept, and the specific implementation process is detailed in the method embodiment, which will not be repeated here.
[0181] 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 instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of 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 via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) 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 media can be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., digital versatile discs (DVDs)), or semiconductor media (e.g., solid-state disks (SSDs)).
[0182] Those skilled in the art will understand that all or part of the steps of the above embodiments can be implemented by hardware or by a program instructing related hardware. The program can be stored in a computer-readable storage medium, such as a read-only memory, a disk, or an optical disk.
[0183] The above content is not intended to limit the embodiments of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the embodiments of this application should be included within the protection scope of the embodiments of this application.
Claims
1. A method for determining the query result of a query vector, characterized in that, The method includes: The first query vector is input into the one-hot encoding model, which outputs the one-hot encoding matrix corresponding to the first query vector. The one-hot encoding model is trained by a neural network model. The first query vector includes multiple query objects. Each row element in the one-hot encoding matrix is used to indicate the one-hot encoding result of a query object. The one-hot encoding result of the query object indicates the index of the query object in the lookup table. The lookup table includes multiple indexes and query results corresponding to each of the multiple indexes. Based on the one-hot encoding matrix corresponding to the first query vector and the lookup table, the query result of the first query vector is determined by matrix multiplication.
2. The method as described in claim 1, characterized in that, The method is applied to a neural network processor (NPU) in a computing cluster, wherein the NPU is configured with the one-hot encoding model.
3. The method as described in claim 1 or 2, characterized in that, The step of inputting the first query vector into the one-hot encoding model, and the one-hot encoding model outputting the one-hot encoding matrix corresponding to the first query vector, includes: If the length of the first query vector is less than the reference length, padding elements are added to the first query vector to obtain a second query vector with a length of the reference length, where the reference length is the length of the input vector required by the one-hot coding model. The second query vector is input into the one-hot encoding model, and the one-hot encoding model outputs the one-hot encoding matrix corresponding to the second query vector. The one-hot encoding result corresponding to the filling element is deleted from the one-hot encoding matrix corresponding to the second query vector to obtain the one-hot encoding matrix corresponding to the first query vector.
4. The method as described in claim 1 or 2, characterized in that, The step of inputting the first query vector into the one-hot encoding model, and the one-hot encoding model outputting the one-hot encoding matrix corresponding to the first query vector, includes: If the length of the first query vector is greater than the reference length, the first query vector is divided into multiple sub-query vectors according to the reference length, where the reference length is the length of the input vector required by the one-hot coding model. The plurality of subquery vectors are respectively input into the one-hot encoding model, and the one-hot encoding model outputs the one-hot encoding matrix corresponding to each of the plurality of subquery vectors; The one-hot encoding matrices corresponding to each of the multiple subquery vectors are concatenated to obtain the one-hot encoding matrix corresponding to the first query vector.
5. The method according to any one of claims 1-4, characterized in that, The method further includes: Acquire multiple sample data, each of which includes a sample query vector and a one-hot encoding matrix corresponding to the sample query vector, wherein the length of the sample query vector is a reference length; The neural network model is trained based on the multiple sample data to obtain the one-hot encoding model.
6. The method as described in claim 5, characterized in that, The size of the neural network model is related to the size of the lookup table, and the size of the neural network model includes the number of parameters in the neural network model.
7. An apparatus for determining the query result of a query vector, characterized in that, The device includes: An input module is used to input a first query vector into a one-hot encoding model. The one-hot encoding model outputs a one-hot encoding matrix corresponding to the first query vector. The one-hot encoding model is trained by a neural network model. The first query vector includes multiple query objects. Each row element in the one-hot encoding matrix is used to indicate the one-hot encoding result of a query object. The one-hot encoding result of the query object indicates the index of the query object in a lookup table. The lookup table includes multiple indexes and query results corresponding to each of the multiple indexes. The determination module is used to determine the query result of the first query vector by matrix multiplication based on the one-hot encoding matrix corresponding to the first query vector and the lookup table.
8. The apparatus as claimed in claim 7, characterized in that, The device is applied to a neural network processor (NPU) in a computing cluster, and the NPU is configured with the one-hot encoding model.
9. A computing node, characterized in that, The computing node includes a processor and memory; The processor of the computing node is used to execute instructions stored in the memory of the computing node to cause the computing node to perform the method as described in any one of claims 1-6.
10. A computer program product containing instructions, characterized in that, When the instruction is executed by the computing node, the computing node performs the method as described in any one of claims 1-6.