Quantization parameter determination method, vector retrieval method and device for memory computing integrated structure

By performing linear transformations and quantization on vectors within an in-memory computing architecture, and adjusting parameters using optimization methods, the problem of low accuracy in vector retrieval in traditional methods is solved, achieving more efficient and accurate vector retrieval.

CN119046511BActive Publication Date: 2025-12-16BEIJING YIYUAN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411027256.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-30
Publication Date
2025-12-16
Estimated Expiration
2044-07-30

AI Technical Summary

Technical Problem

In existing in-memory computing architectures, traditional quantization methods rely on empirical values, leading to a decrease in the accuracy of vector retrieval.

Method used

The input and output vectors are linearly transformed and quantized by the logic computing unit. The equivalent Euclidean distance is calculated by combining the in-memory computing array. The quantization parameters are adjusted by the optimization method until the quantization loss reaches the threshold, so as to achieve accurate quantization of the vector.

Benefits of technology

The accuracy of vector retrieval was improved, and computational efficiency was increased by allocating computational tasks, ensuring that the quantized Euclidean distance was close to the original distance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119046511B_ABST
    Figure CN119046511B_ABST
Patent Text Reader

Abstract

The application discloses a quantization parameter determination method, a vector retrieval method and a device of a storage-computation integrated structure, comprising: linearly transforming and quantizing an original target vector according to initial input scaling and translation parameters and an input quantization function to obtain a quantized target vector; linearly transforming and quantizing an original base library vector according to initial input translation parameters, initial weight scaling parameters and a weight quantization function to obtain a quantized base library vector; calculating a first equivalent Euclidean distance according to the initial weight scaling parameters, the initial input scaling parameters, the quantized target vector and the base library vector, linearly transforming and quantizing the first equivalent Euclidean distance according to initial output scaling and translation parameters and an output quantization function to obtain a quantized equivalent Euclidean distance, and restoring the quantized equivalent Euclidean distance to obtain a quantized Euclidean distance; and adjusting each parameter by using a current quantization loss calculated according to an original Euclidean distance and the quantized Euclidean distance and an optimization method until convergence to obtain final required parameters.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of vector retrieval, in particular to a quantization parameter determination method of a memory-compute integrated structure, a vector retrieval method and device. BACKGROUND

[0002] With the development of information technology, the scenarios in which vector retrieval can be applied are more and more, for example, cross-modal recognition, face and body recognition, fuzzy text recognition, etc. can all be realized through the method of vector retrieval. However, the amount of data required for retrieval in many scenarios is very large. In order to improve the efficiency of vector retrieval, a memory-compute integrated structure with high density, low power consumption, fast read and write, etc. can be used to realize vector retrieval. The memory-compute integrated structure includes a memory-compute integrated structure of FeRAM (Ferroelectric Random Access Memory), RRAM (Resistive Random Access Memory), FLASH (Flash Memory), etc.

[0003] When vector retrieval is performed based on a memory-compute integrated structure of RRAM structure or a new type of memory, data quantization is often required to adapt to its own precision requirements. However, in the traditional quantization method, not only the input data is quantized, but also the required quantization parameters are determined according to empirical values when the input data is quantized, for example, directly calculating the statistical data, taking the maximum / minimum value, average value, etc. Therefore, using this quantization method will result in a decrease in the accuracy of vector retrieval. SUMMARY

[0004] The present application provides a quantization parameter determination method of a memory-compute integrated structure, a vector retrieval method and device, which can provide a more optimal quantization parameter determination method and improve the accuracy of vector retrieval.

[0005] The specific technical solutions are as follows:

[0006] In a first aspect, the present application provides a quantization parameter determination method of a memory-compute integrated structure, which comprises:

[0007] The logic calculation unit performs linear transformation on the original target vector according to the initial input scaling parameter and the initial input translation parameter to obtain a linearly transformed target vector, and performs linear transformation on the original base library vector according to the initial input translation parameter and the initial weight scaling parameter to obtain a linearly transformed base library vector;

[0008] The digital-analog conversion module quantizes the linearly transformed target vector based on an input quantization function to obtain a quantized target vector, and quantizes the linearly transformed base library vector based on a weight quantization function to obtain a quantized base library vector.

[0009] The logic calculation unit calculates a first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector and the quantized base library vector, wherein the first equivalent Euclidean distance is an adjusted distance of an equivalent Euclidean distance of the quantized target vector and the quantized base library vector according to the initial weight scaling parameter and the initial input scaling parameter, the equivalent Euclidean distance of two vectors is converted from a Euclidean distance formula, and the equivalent Euclidean distance can be used to evaluate the similarity between the two vectors instead of the Euclidean distance;

[0010] The logic calculation unit linearly transforms the first equivalent Euclidean distance according to an initial output scaling parameter and an initial output translation parameter;

[0011] An analog-digital conversion module quantizes the linearly transformed first equivalent Euclidean distance based on an output quantization function to obtain a quantized equivalent Euclidean distance;

[0012] The logic calculation unit restores the quantized equivalent Euclidean distance according to the original target vector, the initial input translation parameter, the initial input scaling parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter to obtain a quantized Euclidean distance between the original target vector and the original base library vector;

[0013] The logic calculation unit calculates a current quantization loss according to an original Euclidean distance and the quantized Euclidean distance, wherein the original Euclidean distance is a Euclidean distance true value before quantization;

[0014] The logic calculation unit adjusts the initial input scaling parameter, the initial input translation parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter by using an optimization method and the current quantization loss until the current quantization loss is less than or equal to a preset loss threshold, and then obtains a target input scaling parameter, a target input translation parameter, a target weight scaling parameter, a target output scaling parameter and a target output translation parameter.

[0015] In a possible implementation, the method for obtaining the original Euclidean distance comprises:

[0016] The logic calculation unit combines the storage-computing integrated array to calculate a second equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the linearly transformed target vector and the linearly transformed base library vector, wherein the second equivalent Euclidean distance is an adjusted distance of the equivalent Euclidean distance of the linearly transformed target vector and the linearly transformed base library vector according to the initial weight scaling parameter and the initial input scaling parameter.

[0017] The logic calculation unit linearly transforms the second equivalent Euclidean distance according to the initial output scaling parameter and the initial output translation parameter to obtain a linearly transformed second equivalent Euclidean distance.

[0018] The logic calculation unit restores the linearly transformed second equivalent Euclidean distance according to the original target vector, the initial input translation parameter, the initial input scaling parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter to obtain the original Euclidean distance.

[0019] In a possible implementation, the logic calculation unit combines the storage-computing integrated array to calculate a first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector and the quantized base library vector, including:

[0020] The logic calculation unit obtains a first equivalent target vector and a first equivalent base library vector required for calculating the first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector and the quantized base library vector, and sends the first equivalent target vector and the first equivalent base library vector to the storage-computing integrated array.

[0021] The storage-computing integrated array performs an inner product operation on the first equivalent target vector and the first equivalent base library vector according to the internal array structure to obtain the first equivalent Euclidean distance.

[0022] In a possible implementation, the logic calculation unit adjusts the initial input scaling parameter, the initial input translation parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter by using an optimization method and the current quantization loss, including:

[0023] The logic calculation unit adjusts the initial input scaling parameter, the initial input translation parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter by using a non-gradient optimization method and the current quantization loss.

[0024] In a second aspect, the embodiments of the present application provide a vector retrieval method, the method comprising:

[0025] The logic calculation unit performs linear transformation on the original target vector according to the target input scaling parameter and the target input translation parameter to obtain a linearly transformed target vector, and performs linear transformation on the original base library vector according to the target input translation parameter and the target weight scaling parameter to obtain a linearly transformed base library vector;

[0026] The digital-to-analog conversion module quantizes the linearly transformed target vector based on an input quantization function to obtain a quantized target vector, and quantizes the linearly transformed base library vector based on a weight quantization function to obtain a quantized base library vector;

[0027] The logic calculation unit calculates a first equivalent Euclidean distance in combination with the memory-compute integrated array according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base library vector;

[0028] The logic calculation unit performs linear transformation on the first equivalent Euclidean distance according to a target output scaling parameter and a target output translation parameter;

[0029] The analog-to-digital conversion module quantizes the linearly transformed first equivalent Euclidean distance based on an output quantization function to obtain a quantized equivalent Euclidean distance;

[0030] The logic calculation unit determines K original base library vectors with the highest similarity to the original target vector by comparing the quantized equivalent Euclidean distances corresponding to different original base library vectors, where K is a positive integer;

[0031] The target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter, and the target output translation parameter are determined according to the quantization parameter determination method of any possible implementation of the first aspect.

[0032] In a possible implementation, the logic calculation unit calculates a first equivalent Euclidean distance in combination with the memory-compute integrated array according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base library vector, which comprises:

[0033] The logic calculation unit obtains a first equivalent target vector and a first equivalent base library vector required for calculating a first equivalent Euclidean distance according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base library vector, and sends the first equivalent target vector and the first equivalent base library vector to the memory-compute integrated array;

[0034] The storage-computation integrated array performs an inner product operation on the first equivalent target vector and the first equivalent library vector according to an internal array structure to obtain a first equivalent Euclidean distance.

[0035] In a third aspect, an embodiment of the present application provides a device for determining a quantization parameter of a storage-computation integrated structure, and the device comprises:

[0036] The logic computation unit is configured to perform linear transformation on an original target vector according to an initial input scaling parameter and an initial input translation parameter to obtain a linearly transformed target vector, and perform linear transformation on an original library vector according to the initial input translation parameter and an initial weight scaling parameter to obtain a linearly transformed library vector.

[0037] The digital-to-analog conversion module is configured to quantize the linearly transformed target vector based on an input quantization function to obtain a quantized target vector, and quantize the linearly transformed library vector based on a weight quantization function to obtain a quantized library vector.

[0038] The logic computation unit, in combination with the storage-computation integrated array, is configured to calculate a first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector, and the quantized library vector, wherein the first equivalent Euclidean distance is an adjusted distance of an equivalent Euclidean distance of the quantized target vector and the quantized library vector according to the initial weight scaling parameter and the initial input scaling parameter, the equivalent Euclidean distance of two vectors is converted from a Euclidean distance formula, and the equivalent Euclidean distance can be used to evaluate the similarity between the two vectors instead of the Euclidean distance.

[0039] The logic computation unit is further configured to perform linear transformation on the first equivalent Euclidean distance according to an initial output scaling parameter and an initial output translation parameter.

[0040] The analog-to-digital conversion module is configured to quantize the linearly transformed first equivalent Euclidean distance based on an output quantization function to obtain a quantized equivalent Euclidean distance.

[0041] The logic calculation unit is further configured to: perform restoration processing on the quantized equivalent Euclidean distance according to the original target vector, the initial input translation parameter, the initial input scaling parameter, the initial weight scaling parameter, the initial output scaling parameter, and the initial output translation parameter, to obtain a quantized Euclidean distance between the original target vector and the original base library vector; calculate a current quantization loss according to an original Euclidean distance and the quantized Euclidean distance, wherein the original Euclidean distance is a Euclidean distance true value before quantization; and adjust the initial input translation parameter, the initial input scaling parameter, the initial weight scaling parameter, the initial output scaling parameter, and the initial output translation parameter by using an optimization method and the current quantization loss, until the current quantization loss is less than or equal to a preset loss threshold, to obtain a target input scaling parameter, a target input translation parameter, a target weight scaling parameter, a target output scaling parameter, and a target output translation parameter.

[0042] In a possible implementation, the logic calculation unit, in combination with the storage-computation integrated array, is configured to: calculate a second equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the linearly transformed target vector, and the linearly transformed base library vector, wherein the second equivalent Euclidean distance is an adjusted distance of an equivalent Euclidean distance of the linearly transformed target vector and the linearly transformed base library vector according to the initial weight scaling parameter and the initial input scaling parameter.

[0043] The logic calculation unit is further configured to: perform linear transformation on the second equivalent Euclidean distance according to the initial output scaling parameter and the initial output translation parameter, to obtain a linearly transformed second equivalent Euclidean distance; and perform restoration processing on the linearly transformed second equivalent Euclidean distance according to the original target vector, the initial input translation parameter, the initial input scaling parameter, the initial weight scaling parameter, the initial output scaling parameter, and the initial output translation parameter, to obtain the original Euclidean distance.

[0044] In a possible implementation, the logic calculation unit is configured to: obtain a first equivalent target vector and a first equivalent base library vector required for calculating a first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector, and the quantized base library vector, and send the first equivalent target vector and the first equivalent base library vector to the storage-computation integrated array.

[0045] The storage-computation integrated array is configured to: perform inner product operation on the first equivalent target vector and the first equivalent base library vector according to an internal array structure, to obtain the first equivalent Euclidean distance.

[0046] In a possible implementation, the logic calculation unit is configured to adjust the initial input scaling parameter, the initial input translation parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter by using a non-gradient optimization method and the current quantization loss.

[0047] In a fourth aspect, an embodiment of the present application provides a vector retrieval device, which comprises:

[0048] The logic calculation unit is configured to perform linear transformation on the original target vector according to a target input scaling parameter and a target input translation parameter to obtain a linearly transformed target vector, and perform linear transformation on an original base library vector according to the target input translation parameter and a target weight scaling parameter to obtain a linearly transformed base library vector.

[0049] The digital-to-analog conversion module is configured to quantize the linearly transformed target vector based on an input quantization function to obtain a quantized target vector, and quantize the linearly transformed base library vector based on a weight quantization function to obtain a quantized base library vector.

[0050] The logic calculation unit in combination with a memory-compute integrated array is configured to calculate a first equivalent Euclidean distance according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector and the quantized base library vector.

[0051] The logic calculation unit is further configured to perform linear transformation on the first equivalent Euclidean distance according to a target output scaling parameter and a target output translation parameter.

[0052] The analog-to-digital conversion module is configured to quantize the linearly transformed first equivalent Euclidean distance based on an output quantization function to obtain a quantized equivalent Euclidean distance.

[0053] The logic calculation unit is further configured to determine K original base library vectors with the highest similarity to the original target vector by comparing quantized equivalent Euclidean distances corresponding to different original base library vectors, where K is a positive integer.

[0054] The target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter and the target output translation parameter are determined according to the quantization parameter determination method of any possible implementation of the first aspect.

[0055] In a possible implementation, the logic calculation unit is configured to obtain, according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base library vector, a first equivalent target vector and a first equivalent base library vector required for calculating a first equivalent Euclidean distance, and send the first equivalent target vector and the first equivalent base library vector to the compute-in-memory array.

[0056] The compute-in-memory array is configured to perform an inner product operation on the first equivalent target vector and the first equivalent base library vector according to an internal array structure, to obtain the first equivalent Euclidean distance.

[0057] In a fifth aspect, an embodiment of the present application provides a compute-in-memory chip, which is used to implement the inner product operation on vectors in the method according to any possible implementation of the first aspect, and is used to store base library vectors.

[0058] In a sixth aspect, an embodiment of the present application provides an electronic device including at least one compute-in-memory chip.

[0059] Compared with related technologies that quantize input vectors only based on experience values, the method for determining a quantization parameter of a compute-in-memory structure, the vector retrieval method, and the device provided in the embodiments of the present application can not only quantize and adjust input vectors, but also quantize and adjust output vectors. When adjusting the quantization parameter, the optimization method is used for automatic adjustment until the current quantization loss is less than or equal to a preset loss threshold, and the target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter, and the target output translation parameter required finally can be obtained. Therefore, when input and output vectors in the vector retrieval process are quantized according to the target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter, and the target output translation parameter, the quantized equivalent Euclidean distance output finally can be closer to the equivalent Euclidean distance before quantization, or the quantized Euclidean distance output finally can be closer to the Euclidean distance before quantization, and thus the accuracy of vector retrieval can be improved whether the similarity is compared using the equivalent formula of the original Euclidean distance formula or the similarity is compared directly using the original Euclidean distance formula.

[0060] In addition, the technical effects that can be achieved by the embodiments of the present application include:

[0061] Whether it's the calculation process of the first equivalent Euclidean distance in the quantization parameter determination method of the in-memory computing structure or the calculation process of the first equivalent Euclidean distance in the vector retrieval method, the embodiments of this application can first have the logic computing unit obtain the first equivalent target vector and the first equivalent base vector required for calculating the first equivalent Euclidean distance based on the weight scaling parameters, input scaling parameters, quantized target vector, and quantized base vector. Then, the in-memory computing array performs an inner product operation on the first equivalent target vector and the first equivalent base vector according to its internal array structure to obtain the first equivalent Euclidean distance. Compared with directly using the logic computing unit to calculate according to the first equivalent Euclidean distance formula, the embodiments of this application only require the logic computing unit to perform a simple conversion to obtain the first equivalent target vector and the first equivalent base vector, while the complex vector inner product operation is handled by the more computationally efficient in-memory computing array, realizing the function of vector retrieval based on the in-memory computing array, thereby improving the computational efficiency of vector retrieval. Similarly, when calculating the second equivalent Euclidean distance, the computational efficiency of the second equivalent Euclidean distance can be improved by combining logic computing units with in-memory computing arrays. Attached Figure Description

[0062] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are merely some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without any creative effort.

[0063] Figure 1 A flowchart illustrating a method for determining quantization parameters in an in-memory computing architecture, provided as an embodiment of this application;

[0064] Figure 2 This is a comparison example of the quantization error calculated based on the quantization parameters determined in the embodiments of this application and the quantization error calculated by related technologies;

[0065] Figure 3 A flowchart illustrating a vector retrieval method provided in an embodiment of this application;

[0066] Figure 4 A block diagram of a quantization parameter determination device with an in-memory computing structure provided in an embodiment of this application;

[0067] Figure 5 This is a block diagram of a vector retrieval device provided in an embodiment of this application. Detailed Implementation

[0068] With reference to the drawings and the embodiments of the present application, the technical solutions in the embodiments of the present application will be described clearly and completely. Obviously, the described embodiments are only a part of the embodiments of the present application, but not all the embodiments of the present application. Based on the embodiments in the present application, all the other embodiments obtained by a person of ordinary skill in the art without creative effort are within the protection scope of the present application.

[0069] It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict. The terms "comprise" and "have" and any variations thereof in the embodiments of the present application are intended to cover the inclusions without exclusivity. For example, the processes, methods, systems, products or devices comprising a series of steps or units are not limited to the listed steps or units, but optionally further comprise the steps or units not listed or optionally further comprise other steps or units inherent to these processes, methods, products or devices.

[0070] The embodiments of the present application can be applied to various vector retrieval scenarios, such as cross-modal identification, face and body recognition, fuzzy text recognition, and various scenarios of target retrieval through vectors. For example, when the embodiments of the present application are applied to the face and body recognition scenario, the original target vector can be a feature vector extracted from a target face (or body) image, and the original base library vector can be a feature vector extracted from a face (or body) image stored in the base library; when the embodiments of the present application are applied to the fuzzy text recognition scenario, the original target vector can be a feature vector extracted from a target text, and the base library vector can be a feature vector extracted from a text stored in the base library.

[0071] In order to improve the accuracy of vector retrieval, the embodiments of the present application provide a quantization parameter determination method of a memory-compute integrated structure, which can be applied to a system including a memory-compute integrated chip, the system including a logic computing unit, a digital-to-analog conversion module, an analog-to-digital conversion module, and a memory-compute integrated array, as shown in Figure 1 The method includes:

[0072] S110: The logic computing unit performs linear transformation on the original target vector according to the initial input scaling parameter and the initial input translation parameter to obtain a linearly transformed target vector, and performs linear transformation on the original base library vector according to the initial input translation parameter and the initial weight scaling parameter to obtain a linearly transformed base library vector.

[0073] The step can specifically include: performing linear transformation on the original target vector according to the initial input scaling parameter and the initial input translation parameter to obtain a linearly transformed target vector, performing linear transformation on the original base library vector according to the initial input translation parameter and the initial weight scaling parameter to obtain a linearly transformed base library vector, and sending the linearly transformed target vector and the linearly transformed base library vector to the digital-to-analog conversion module.

[0074] The initial input scaling parameter is used for scaling operation on the input target vector, the initial input translation parameter is used for translation operation on the input vector, and the initial weight scaling parameter is used for scaling operation on the input base library vector.

[0075] The logic calculation unit includes but is not limited to: a logic circuit in a memory-compute integrated chip, a CPU (Central Processing Unit), an ASIC (Application Specific Integrated Circuit) chip, etc.

[0076] The logic calculation unit can perform translation on the original target vector and the original base library vector in any direction and with any size, as long as the translation direction and the translation amount of the original target image and the original base library vector are consistent. The logic calculation unit can perform scaling operation on the original target vector and the original base library vector, or can perform amplification operation on the original target vector and the original base library vector, but generally the input scaling parameter and the weight scaling parameter are positive numbers.

[0077] The following is an example of linear transformation operation on the original target vector and the original base library vector:

[0078] The specific formula of the linear transformation of the original target vector by the logic calculation unit can include:

[0079]

[0080] wherein, represents the original target vector, λ i represents the initial input translation parameter, k i represents the initial input scaling parameter, represents the linearly transformed target vector.

[0081] The specific formula of the linear transformation of the original base library vector by the logic calculation unit can include:

[0082]

[0083] wherein, represents the original base library vector, λ idenotes an initial input translation parameter, k w denotes an initial weight scaling parameter, denotes a linearly transformed base library vector.

[0084] S120: The digital-to-analog conversion module quantizes the linearly transformed target vector based on the input quantization function to obtain a quantized target vector, and quantizes the linearly transformed base library vector based on the weight quantization function to obtain a quantized base library vector.

[0085] This step can be specifically that the digital-to-analog conversion module receives the linearly transformed target vector and the linearly transformed base library vector sent by the logic calculation unit, and quantizes the linearly transformed target vector based on the input quantization function to obtain a quantized target vector, and quantizes the linearly transformed base library vector based on the weight quantization function to obtain a quantized base library vector.

[0086] Wherein, the digital-to-analog conversion module, also known as D / A converter, is a device, electronic component or functional module for converting digital quantity into analog. The input quantization function is used for quantizing the input target vector. The weight quantization function is used for quantizing the input base library vector.

[0087] The following is an example of quantizing the linearly transformed target vector and the linearly transformed base library vector:

[0088] The specific formula of the digital-to-analog conversion module for quantizing the linearly transformed target vector can include:

[0089]

[0090] Wherein, Q i denotes an input quantization function, denotes a quantized target vector.

[0091] The specific formula of the digital-to-analog conversion module for quantizing the linearly transformed base library vector can include:

[0092]

[0093] Wherein, Q w denotes a weight quantization function, denotes a quantized base library vector.

[0094] S130: The logic calculation unit calculates a first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector and the quantized base library vector in combination with the memory-computing integrated array.

[0095] The first equivalent Euclidean distance is an adjusted distance of an equivalent Euclidean distance of the quantized target vector and the quantized base library vector according to the initial weight scaling parameter and the initial input scaling parameter, the equivalent Euclidean distance of the two vectors is converted from a Euclidean distance formula, and the equivalent Euclidean distance can be used to evaluate the similarity between the two vectors.

[0096] The logic computing unit obtains the first equivalent target vector and the first equivalent base library vector required for calculating the first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector and the quantized base library vector, and sends the first equivalent target vector and the first equivalent base library vector to the memory-compute integrated array; the memory-compute integrated array performs an inner product operation on the first equivalent target vector and the first equivalent base library vector according to the internal array structure to obtain the first equivalent Euclidean distance, and sends the first equivalent Euclidean distance to the logic computing unit.

[0097] The analog-digital conversion module, also known as an A / D converter, is usually referred to as an ADC, which refers to a device, an electronic element or a functional module that converts an analog signal into a digital signal.

[0098] The implementation of the logic computing unit obtaining the first equivalent target vector and the first equivalent base library vector required for calculating the first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector and the quantized base library vector includes steps A1-A3:

[0099] (A1) The logic computing unit determines the first target value according to the square value of the quantized base library vector, the initial weight scaling parameter and the initial input scaling parameter.

[0100] The first target value is the operation value of the second operation item in the first equivalent Euclidean distance formula, the first equivalent Euclidean distance formula includes the first operation item and the second operation item, and the first operation item is the inner product of the quantized target vector and the quantized base library vector.

[0101] The first equivalent Euclidean distance formula includes:

[0102]

[0103] d1 represents the first equivalent Euclidean distance, represents the first operation item, represents the second operation item, and the value of the second operation item is the target value.

[0104] The source of the first equivalent Euclidean distance formula is described as follows:

[0105] The known Euclidean distance formula includes wherein d represents a vector and a vector Euclidean distance between two vectors, n represents the dimension of two vectors, i represents the i-th dimension, a i represents the vector in the i-th dimension, b i represents the vector in the i-th dimension;

[0106] The process of simplifying and converting the above Euclidean distance formula includes:

[0107]

[0108]

[0109] Therefore, since the vector can be regarded as a quantity, the smaller d is, the larger it is, so that the larger it is. Therefore, the smaller d is, the higher the vector similarity is, so the larger it is, indicating that the vector similarity is higher. Therefore, the can be used as an equivalent formula to compare the similarity.

[0110] The above is the equivalent distance corresponding to the original Euclidean distance without linear transformation and quantization. In the case of linear transformation and quantization of the original target vector and the original base library vector, the equivalent distance becomes the first equivalent Euclidean distance, that is

[0111] (A2) The logic calculation unit constructs the first vector and the second vector with the same dimension, so that the inner product result of the first vector and the second vector is the first target value.

[0112] The specific method of constructing the first vector and the second vector with the same dimension is not limited in the embodiments of the present application, as long as the inner product of the two vectors is the first target value. For example, the first vector and the second vector can be constructed by pseudo code, or they can be multiplied by a fixed vector coefficient, set to a periodic function, generate random numbers, etc.

[0113] (A3) The logic calculation unit adds the elements in the first vector to the quantized target vector to obtain the first equivalent target vector, and adds the elements in the second vector to the quantized base library vector to obtain the first equivalent base library vector.

[0114] After obtaining the first vector and the second vector, the elements in the first vector can be added to the tail of the quantized target vector respectively, and the elements in the second vector can be added to the tail of the quantized base vector respectively, so as to realize dimension increasing of the quantized target vector and the quantized base vector. For example, when the quantized target vector is [2, 2], the quantized base vector is [3, 3], the first vector is [1, 1], and the second vector is [-4.5, -4.5], the first equivalent target vector is [2, 2, 1, 1], and the first equivalent base vector is [3, 3, -4.5, -4.5].

[0115] If the first equivalent target vector is represented by d1, and the first equivalent base vector is represented by b1, then Therefore, the inner product operation is performed on the first equivalent target vector and the first equivalent base vector, and the first equivalent Euclidean distance can be obtained.

[0116] S140: The logic calculation unit performs linear transformation on the first equivalent Euclidean distance according to the initial output scaling parameter and the initial output translation parameter.

[0117] The initial output scaling parameter is used for scaling operation on the output vector, and the initial output translation parameter is used for translation operation on the output vector. The logic calculation unit can perform scaling operation on the output vector, or can perform amplification operation on the output vector, but generally the value of the output scaling parameter is a positive number. The logic calculation unit can perform translation on the output vector in any direction and any number, and the application embodiment does not limit the value of the output translation parameter.

[0118] The specific formula of the linear transformation performed by the logic calculation unit on the first equivalent Euclidean distance can include:

[0119] d'1=k o ·(d1)+λ o

[0120] Wherein, d'1 represents the first equivalent Euclidean distance after linear transformation, d1 represents the first equivalent Euclidean distance, k o represents the initial output scaling parameter, and λ o represents the initial output translation parameter.

[0121] S150: The analog-digital conversion module quantizes the first equivalent Euclidean distance after linear transformation based on the output quantization function, and obtains the quantized equivalent Euclidean distance.

[0122] The output quantization function is used for quantization processing on the output vector.

[0123] ​​The specific formula of the analog-digital conversion module for quantizing the linearly transformed first equivalent Euclidean distance can include:

[0124] y3=Q o (d'1)

[0125] wherein y3 represents the quantized equivalent Euclidean distance, Q o represents an output quantization function.

[0126] S160: The logic calculation unit restores the quantized equivalent Euclidean distance according to the original target vector, the initial input translation parameter, the initial input scaling parameter, the initial weight scaling parameter, the initial output scaling parameter, and the initial output translation parameter, to obtain a quantized Euclidean distance between the original target vector and the original base library vector.

[0127] The formula for restoring the quantized equivalent Euclidean distance can include:

[0128]

[0129] wherein y q represents the quantized Euclidean distance, represents the original target vector, λ i represents the initial input translation parameter, k i represents the initial input scaling parameter, k w represents the initial weight scaling parameter, k o represents the initial output scaling parameter, y3 represents the quantized equivalent Euclidean distance, λ o represents the initial output translation parameter.

[0130] S170: The logic calculation unit calculates the current quantization loss according to the original Euclidean distance and the quantized Euclidean distance.

[0131] wherein the original Euclidean distance is the Euclidean distance true value before quantization.

[0132] The method for obtaining the original Euclidean distance comprises: the logic calculation unit combines the storage-computing integrated array to calculate a second equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the linearly transformed target vector and the linearly transformed base library vector, wherein the second equivalent Euclidean distance is an adjusted distance of the equivalent Euclidean distance of the linearly transformed target vector and the linearly transformed base library vector according to the initial weight scaling parameter and the initial input scaling parameter; the logic calculation unit linearly transforms the second equivalent Euclidean distance according to the initial output scaling parameter and the initial output translation parameter to obtain a linearly transformed second equivalent Euclidean distance; and the logic calculation unit restores the linearly transformed second equivalent Euclidean distance according to the original target vector, the initial input translation parameter, the initial input scaling parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter to obtain the original Euclidean distance.

[0133] Specifically, the logic calculation unit obtains a second equivalent target vector and a second equivalent base library vector required for calculating the second equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the linearly transformed target vector and the linearly transformed base library vector, and sends the second equivalent target vector and the second equivalent base library vector to the storage-computing integrated array; the storage-computing integrated array performs inner product operation on the second equivalent target vector and the second equivalent base library vector according to the internal array structure to obtain the second equivalent Euclidean distance, and sends the second equivalent Euclidean distance to the logic calculation unit; the logic calculation unit linearly transforms the second equivalent Euclidean distance according to the initial output scaling parameter and the initial output translation parameter to obtain a linearly transformed second equivalent Euclidean distance, and restores the linearly transformed second equivalent Euclidean distance according to the original target vector, the initial input translation parameter, the initial input scaling parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter to obtain the original Euclidean distance.

[0134] The second equivalent Euclidean distance and the first equivalent Euclidean distance have the same principle, both of which are adjusted distances. adjusted distances.

[0135] The second equivalent Euclidean distance formula comprises:

[0136]

[0137] wherein d2 represents the second equivalent Euclidean distance, represents the linearly transformed target vector, represents the linearly transformed base library vector, k w represents the initial weight scaling parameter, k i represents the initial input scaling parameter, represents a first operation item of the second equivalent Euclidean distance formula, A second operation term representing a second equivalent Euclidean distance formula.

[0138] The specific process of calculating the second equivalent Euclidean distance by the logic calculation unit according to the initial weight scaling parameter, the initial input scaling parameter, the linearly transformed target vector and the linearly transformed base library vector can include steps B1-B3:

[0139] (B1) The logic calculation unit determines a second target value according to the square value of the linearly transformed base library vector, the initial weight scaling parameter and the initial input scaling parameter.

[0140] The second target value is the calculation result of .

[0141] (B2) The logic calculation unit constructs a third vector and a fourth vector with the same dimension, so that the inner product result of the third vector and the fourth vector is the second target value.

[0142] The specific method of constructing the third vector and the fourth vector with the same dimension is not limited in the embodiments of the present application, as long as the inner product of the two vectors is the second target value. For example, the second vector and the third vector can be constructed by pseudo code, or fixed vector multiplication coefficient, periodic function, random number generation and the like can be used.

[0143] (B3) The logic calculation unit adds the elements in the third vector to the linearly transformed target vector to obtain a second equivalent target vector, and adds the elements in the fourth vector to the linearly transformed base library vector to obtain a second equivalent base library vector.

[0144] After obtaining the third vector and the fourth vector, the elements in the third vector can be added to the tail of the linearly transformed target vector, and the elements in the fourth vector can be added to the tail of the linearly transformed base library vector, so as to realize dimension increasing of the linearly transformed target vector and the linearly transformed base library vector.

[0145] In addition, the specific formula of the linear transformation of the logic calculation unit on the second equivalent Euclidean distance can include:

[0146] y2=k o ·(d2)+λ o

[0147] Wherein, y2 represents the linearly transformed second equivalent Euclidean distance, d2 represents the second equivalent Euclidean distance, k o represents the initial output scaling parameter, and λ o represents the initial output translation parameter.

[0148] The specific formula of the linear transformation of the logic calculation unit on the second equivalent Euclidean distance can include:

[0149]

[0150] wherein y represents the original Euclidean distance, represents the original target vector, λ i represents the initial input scaling parameter, k i represents the initial input scaling parameter, k w represents the initial weight scaling parameter, k o represents the initial output scaling parameter, y2represents the equivalent Euclidean distance after linear transformation, λ o represents the initial output scaling parameter.

[0151] It should be noted that the value of the original Euclidean distance is the same as the value of , and there is no error between the two.

[0152] After obtaining the original Euclidean distance and the quantized Euclidean distance, the logic calculation unit can calculate the current quantization loss according to the original Euclidean distance and the quantized Euclidean distance.

[0153] The calculation formula of the current quantization loss can include:

[0154] l(k i ,λ i ,λ w ,k o ,λ o )=abs(y q -y)

[0155] wherein l(k i ,λ i ,λ w ,k o ,λ o ) represents the quantization loss function, y q represents the quantized Euclidean distance, and y represents the original Euclidean distance.

[0156] S180: The logic calculation unit adjusts the initial input scaling parameter, the initial input translation parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter by using the optimization method and the current quantization loss, until the current quantization loss is less than or equal to the preset loss threshold, to obtain the target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter and the target output translation parameter.

[0157] The optimization method includes a non-gradient optimization method, such as a CMA (Covariance Matrix Adaptation) algorithm, a grid search method, or the like. The CMA can be a CMA-ES (Covariance Matrix Adaptation Evolution strategies) algorithm. The preset loss threshold can be an empirical value.

[0158] As shown in FIG. 6, the quantization error obtained by using the CMA or the grid search method is smaller than the quantization error obtained by using an empirical value (such as a max-min method or a mean-variance method). Figure 2

[0159] It should be noted that, for any translation parameter (including an input translation parameter, an output translation parameter), the value can be 0 in any iteration optimization process. For any scaling parameter (including an input scaling parameter, a weight scaling parameter, and an output scaling parameter), the value can be 1 in any iteration optimization process.

[0160] When a translation parameter is 0 and a scaling parameter corresponding to the translation parameter is not 1, only scaling without translation can be achieved. For example, when an original target vector is linearly transformed, if an initial input translation parameter is 0 and an initial scaling parameter is not 1, only scaling without translation of the original target vector can be achieved.

[0161] When a translation parameter is not 0 and a scaling parameter corresponding to the translation parameter is 1, only translation without scaling can be achieved. For example, when an original target vector is linearly transformed, if an initial input translation parameter is not 0 and an initial weight scaling parameter is 1, only translation without scaling of the original target vector can be achieved.

[0162] When the original target vector needs to be linearly transformed, the translation parameter used is an input translation parameter, and the scaling parameter corresponding to the input translation parameter is an input scaling parameter.

[0163] When the original target vector needs to be linearly transformed, the translation parameter used is an input translation parameter, and the scaling parameter corresponding to the input translation parameter is a weight scaling parameter.

[0164] When the first equivalent Euclidean distance or the second equivalent Euclidean distance needs to be linearly transformed, the translation parameter used is an output translation parameter, and the scaling parameter corresponding to the output translation parameter is an output scaling parameter.

[0165] ​That is to say, although the embodiments of the present application use the translation parameter and the scaling parameter at each time of linear transformation, it does not mean that the present application can only realize the linear transformation effect of the coexistence of "translation" and "scaling", but also can realize the linear transformation effect of the alternative existence of "translation" and "scaling".

[0166] Compared with the related technology of quantizing the input vector based on only the empirical value, the quantization parameter determination method of the storage-computing integrated structure provided by the embodiments of the present application can not only quantize and adjust the input vector, but also quantize and adjust the output vector, and when adjusting the quantization parameter, the optimization method is used for automatic adjustment until the current quantization loss is less than or equal to the preset loss threshold, so that the target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter and the target output translation parameter required finally can be obtained, thereby when the input and output quantization of the vector in the vector retrieval process is performed according to the target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter and the target output translation parameter, the equivalent Euclidean distance after quantization finally output can be closer to the equivalent Euclidean distance before quantization, or the Euclidean distance after quantization finally output can be closer to the Euclidean distance before quantization, and then whether the similarity comparison is performed using the equivalent formula of the original Euclidean distance formula or the similarity comparison is performed directly using the original Euclidean distance formula, the accuracy of the vector retrieval can be improved.

[0167] Based on the above method embodiments, another embodiment of the present application provides a vector retrieval method, which can be applied to a system including a storage-computing integrated chip, the system including: a logic computing unit, a digital-to-analog conversion module, an analog-to-digital conversion module, a storage-computing integrated array, as shown in Figure 3 The method includes:

[0168] S210: The logic computing unit performs linear transformation on the original target vector according to the target input scaling parameter and the target input translation parameter to obtain a linearly transformed target vector, and performs linear transformation on the original base library vector according to the target input translation parameter and the target weight scaling parameter to obtain a linearly transformed base library vector.

[0169] The target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter and the target output translation parameter are determined by the quantization parameter determination method provided in any of the above embodiments.

[0170] The specific calculation formula involved in this step is the same as that in the foregoing step S110, and the only difference is that step S110 uses the initial input scaling parameter, the initial input translation parameter, the initial input translation parameter, and the initial weight scaling parameter, while this step uses the target input scaling parameter, the target input translation parameter, the target input translation parameter, and the target weight scaling parameter.

[0171] S220: The digital-to-analog conversion module quantizes the linearly transformed target vector based on the input quantization function to obtain a quantized target vector, and quantizes the linearly transformed base library vector based on the weight quantization function to obtain a quantized base library vector.

[0172] The specific calculation formula involved in this step is the same as that in the foregoing step S120, and will not be repeated here.

[0173] S230: The logic calculation unit calculates the first equivalent Euclidean distance according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base library vector in combination with the memory-computing integrated array.

[0174] Specifically, the logic calculation unit obtains the first equivalent target vector and the first equivalent base library vector required for calculating the first equivalent Euclidean distance according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base library vector, and sends the first equivalent target vector and the first equivalent base library vector to the memory-computing integrated array; the memory-computing integrated array performs inner product operation on the first equivalent target vector and the first equivalent base library vector according to the internal array structure to obtain the first equivalent Euclidean distance, and sends the first equivalent Euclidean distance to the logic calculation unit.

[0175] The specific calculation formula involved in this step is the same as that in the foregoing step S130, and the only difference is that step S130 uses the initial weight scaling parameter and the initial input scaling parameter, while this step uses the target weight scaling parameter and the target input scaling parameter.

[0176] S240: The logic calculation unit linearly transforms the first equivalent Euclidean distance according to the target output scaling parameter and the target output translation parameter.

[0177] The specific calculation formula involved in this step is the same as that in the foregoing step S140, and the only difference is that step S140 uses the initial output scaling parameter and the initial output translation parameter, while this step uses the target output scaling parameter and the target output translation parameter.

[0178] S250: The analog-to-digital conversion module quantizes the linearly transformed first equivalent Euclidean distance based on the output quantization function to obtain a quantized equivalent Euclidean distance.

[0179] S260: The logic calculation unit determines K original base library vectors with the highest similarity to the original target vector by comparing the quantized equivalent Euclidean distances corresponding to different original base library vectors.

[0180] K is a positive integer, which can be 1 or greater than 1.

[0181] This step can be specifically performed by the logic calculation unit by comparing the quantized equivalent Euclidean distances corresponding to different original base library vectors to determine K original base library vectors with the highest similarity to the original target vector.

[0182] After calculating the quantized equivalent Euclidean distances corresponding to each original base library vector, the quantized equivalent Euclidean distances corresponding to each original base library vector can be sorted to find the K largest quantized equivalent Euclidean distances, and the original base library vectors corresponding to the K quantized equivalent Euclidean distances are determined as the K original base library vectors with the highest similarity to the original target vector.

[0183] The vector retrieval method provided by the embodiment of the application uses not only input-related quantization parameters but also output-related quantization parameters, and these quantization parameters are not empirical values but are obtained by automatic adjustment using an optimization method. Therefore, when inputting and outputting the vectors in the vector retrieval process according to the target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter, and the target output translation parameter, the quantized equivalent Euclidean distance finally output can be closer to the equivalent Euclidean distance before quantization, or the quantized Euclidean distance finally output can be closer to the Euclidean distance before quantization, thereby improving the accuracy of vector retrieval whether the similarity is compared using the equivalent formula of the original Euclidean distance formula or directly using the original Euclidean distance formula.

[0184] Based on the above method embodiment, another embodiment of the application provides a quantization parameter determination device of a computing and storage integrated structure, as shown in Figure 4 The device comprises:

[0185] The logic calculation unit 310 is configured to perform linear transformation on the original target vector according to the initial input scaling parameter and the initial input translation parameter to obtain a linearly transformed target vector, and perform linear transformation on the original base library vector according to the initial input translation parameter and the initial weight scaling parameter to obtain a linearly transformed base library vector.

[0186] The digital-to-analog conversion module 320 is configured to quantize the linearly transformed target vector based on an input quantization function to obtain a quantized target vector, and quantize the linearly transformed base library vector based on a weight quantization function to obtain a quantized base library vector.

[0187] The logic calculation unit 310, in combination with the memory-compute integrated array 330, is configured to calculate a first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector, and the quantized base library vector, wherein the first equivalent Euclidean distance is an adjusted distance of an equivalent Euclidean distance of the quantized target vector and the quantized base library vector according to the initial weight scaling parameter and the initial input scaling parameter, the equivalent Euclidean distance of two vectors is converted from a Euclidean distance formula, and can be used to evaluate the similarity between the two vectors instead of the Euclidean distance;

[0188] The logic calculation unit 310 is further configured to perform linear transformation on the first equivalent Euclidean distance according to an initial output scaling parameter and an initial output translation parameter;

[0189] The analog-digital conversion module 340 is configured to quantize the linearly transformed first equivalent Euclidean distance based on an output quantization function to obtain a quantized equivalent Euclidean distance;

[0190] The logic calculation unit 310 is further configured to perform restoration processing on the quantized equivalent Euclidean distance according to the original target vector, the initial input translation parameter, the initial input scaling parameter, the initial weight scaling parameter, the initial output scaling parameter, and the initial output translation parameter to obtain a quantized Euclidean distance between the original target vector and the original base library vector, calculate a current quantization loss according to an original Euclidean distance and the quantized Euclidean distance, wherein the original Euclidean distance is a Euclidean distance true value before quantization, and adjust the initial input scaling parameter, the initial input translation parameter, the initial weight scaling parameter, the initial output scaling parameter, and the initial output translation parameter by using an optimization method and the current quantization loss until the current quantization loss is less than or equal to a preset loss threshold to obtain a target input scaling parameter, a target input translation parameter, a target weight scaling parameter, a target output scaling parameter, and a target output translation parameter.

[0191] In a possible implementation, the logic calculation unit 310, in combination with the memory-compute integrated array 330, is configured to calculate a second equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the linearly transformed target vector, and the linearly transformed base library vector, wherein the second equivalent Euclidean distance is an adjusted distance of an equivalent Euclidean distance of the linearly transformed target vector and the linearly transformed base library vector according to the initial weight scaling parameter and the initial input scaling parameter;

[0192] The logic calculation unit 310 is further configured to perform linear transformation on the second equivalent Euclidean distance according to the initial output scaling parameter and the initial output translation parameter to obtain a linearly transformed second equivalent Euclidean distance; and perform restoration processing on the linearly transformed second equivalent Euclidean distance according to the original target vector, the initial input translation parameter, the initial input scaling parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter to obtain the original Euclidean distance.

[0193] In a possible implementation, the logic calculation unit 310 is configured to obtain a first equivalent target vector and a first equivalent base library vector required for calculating a first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector and the quantized base library vector, and send the first equivalent target vector and the first equivalent base library vector to the memory-compute integrated array.

[0194] The memory-compute integrated array 330 is configured to perform inner product operation on the first equivalent target vector and the first equivalent base library vector according to an internal array structure to obtain the first equivalent Euclidean distance.

[0195] In a possible implementation, the logic calculation unit 310 is configured to adjust the initial input scaling parameter, the initial input translation parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter by using a non-gradient optimization method and the current quantization loss.

[0196] Compared with related technologies that quantize an input vector only based on experience values, the quantization parameter determination apparatus of the memory-compute integrated structure provided in the embodiments of the present application can not only quantize and adjust the input vector, but also quantize and adjust the output vector, and when adjusting the quantization parameters, the optimization method is used for automatic adjustment until the current quantization loss is less than or equal to the preset loss threshold, so that the target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter and the target output translation parameter required finally can be obtained, thereby when the input and output vectors in the vector retrieval process are quantized according to the target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter and the target output translation parameter, the quantized equivalent Euclidean distance output finally can be closer to the equivalent Euclidean distance before quantization, or the quantized Euclidean distance output finally can be closer to the Euclidean distance before quantization, and thus whether the similarity comparison is performed by using the equivalent formula of the original Euclidean distance formula or the similarity comparison is performed directly by using the original Euclidean distance formula, the accuracy of vector retrieval can be improved.

[0197] Based on the above method embodiments, another embodiment of the present application provides a vector retrieval device, as shown in the figure, the device comprises: Figure 5

[0198] a logic calculation unit 410, configured to perform linear transformation on an original target vector according to a target input scaling parameter and a target input translation parameter to obtain a linearly transformed target vector, and perform linear transformation on an original base library vector according to the target input translation parameter and a target weight scaling parameter to obtain a linearly transformed base library vector;

[0199] a digital-to-analog conversion module 420, configured to quantize the linearly transformed target vector based on an input quantization function to obtain a quantized target vector, and quantize the linearly transformed base library vector based on a weight quantization function to obtain a quantized base library vector;

[0200] The logic calculation unit 410 is combined with a memory-compute integrated array 430, configured to calculate a first equivalent Euclidean distance according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base library vector;

[0201] The logic calculation unit 410 is further configured to perform linear transformation on the first equivalent Euclidean distance according to a target output scaling parameter and a target output translation parameter;

[0202] an analog-to-digital conversion module 440, configured to quantize the linearly transformed first equivalent Euclidean distance based on an output quantization function to obtain a quantized equivalent Euclidean distance;

[0203] The logic calculation unit 410 is further configured to determine K original base library vectors with the highest similarity to the original target vector by comparing quantized equivalent Euclidean distances corresponding to different original base library vectors, wherein K is a positive integer;

[0204] The target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter, and the target output translation parameter are determined according to the quantization parameter determination method provided in any possible implementation manner.

[0205] In a possible implementation manner, the logic calculation unit 410 is configured to obtain a first equivalent target vector and a first equivalent base library vector required for calculating the first equivalent Euclidean distance according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base library vector, and send the first equivalent target vector and the first equivalent base library vector to the memory-compute integrated array;

[0206] ​The storage-computation integrated array 430 is configured to perform an inner product operation on the first equivalent target vector and the first equivalent base library vector according to an internal array structure to obtain a first equivalent Euclidean distance.

[0207] The vector retrieval device provided in the embodiments of the present application uses the quantization parameters, which include not only the input-related quantization parameters but also the output-related quantization parameters, and the quantization parameters are not empirical values but are obtained by automatic adjustment using an optimization method. Therefore, when the input and output of the vector in the vector retrieval process are quantized according to the target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter and the target output translation parameter, the quantized equivalent Euclidean distance in the final output is closer to the equivalent Euclidean distance before quantization, or the quantized Euclidean distance in the final output is closer to the Euclidean distance before quantization, thereby improving the accuracy of vector retrieval whether the similarity is compared using the equivalent formula of the original Euclidean distance formula or directly using the original Euclidean distance formula.

[0208] Based on the above method embodiments, another embodiment of the present application provides a storage-computation integrated chip, which is used at least to implement the inner product operation on the vector in the method according to any of the embodiments and to store the base library vector.

[0209] Based on the above method embodiments, another embodiment of the present application provides an electronic device, which includes at least one storage-computation integrated chip as described above.

[0210] The device embodiments correspond to the method embodiments and have the same technical effects as the method embodiments. For details, refer to the method embodiments. The device embodiments are based on the method embodiments, and for details, refer to the method embodiments, which will not be described herein. Those skilled in the art can understand that the modules or processes in the drawings are not necessarily required to implement the present application.

[0211] Those skilled in the art can understand that the modules in the device in the embodiments can be distributed in the device in the embodiments as described in the embodiments, or can be changed and located in one or more devices different from the embodiments. The modules in the above embodiments can be combined into one module, or can be further split into multiple sub-modules.

[0212] It should be noted that the above examples are only used to illustrate the technical solutions of the present application, and are not intended to limit the same. Although the present application has been described in detail with reference to the foregoing examples, it will be understood by those of ordinary skill in the art that modifications can be made to the technical solutions described in the foregoing examples, or some of the technical features thereof can be replaced by equivalent technical features. Such modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for determining quantization parameters in a memory-computing integrated structure, characterized in that, The method comprises: The logic calculation unit performs linear transformation on the original target vector according to the initial input scaling parameter and the initial input translation parameter, and obtains a linearly transformed target vector; and performs linear transformation on the original base library vector according to the initial input translation parameter and the initial weight scaling parameter, and obtains a linearly transformed base library vector; The digital-to-analog conversion module quantizes the linearly transformed target vector based on an input quantization function, and obtains a quantized target vector; and quantizes the linearly transformed base library vector based on a weight quantization function, and obtains a quantized base library vector; The logic calculation unit calculates a first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector and the quantized base library vector in combination with the memory-compute integrated array, wherein the first equivalent Euclidean distance is a distance obtained by adjusting the equivalent Euclidean distance of the quantized target vector and the quantized base library vector according to the initial weight scaling parameter and the initial input scaling parameter, the equivalent Euclidean distance of two vectors is converted from a Euclidean distance formula, and can replace the Euclidean distance to evaluate the similarity between the two vectors; The logic calculation unit performs linear transformation on the first equivalent Euclidean distance according to an initial output scaling parameter and an initial output translation parameter; The analog-to-digital conversion module quantizes the linearly transformed first equivalent Euclidean distance based on an output quantization function, and obtains a quantized equivalent Euclidean distance; The logic calculation unit performs restoration processing on the quantized equivalent Euclidean distance according to the original target vector, the initial input translation parameter, the initial input scaling parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter, and obtains a quantized Euclidean distance between the original target vector and the original base library vector; The logic calculation unit calculates a current quantization loss according to an original Euclidean distance and the quantized Euclidean distance, wherein the original Euclidean distance is a Euclidean distance true value before quantization; The logic calculation unit adjusts the initial input scaling parameter, the initial input translation parameter, the initial weight scaling parameter, the initial output scaling parameter and the initial output translation parameter by using an optimization method and the current quantization loss, until the current quantization loss is less than or equal to a preset loss threshold, and then obtains a target input scaling parameter, a target input translation parameter, a target weight scaling parameter, a target output scaling parameter and a target output translation parameter; The logic calculation unit calculates a first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector and the quantized base library vector in combination with the memory-compute integrated array, comprising: The logic computing unit obtains first equivalent target vectors and first equivalent base vectors required for calculating a first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector, and the quantized base vector, and sends the first equivalent target vectors and the first equivalent base vectors to the memory-compute integrated array; The memory-compute integrated array performs inner product operation on the first equivalent target vectors and the first equivalent base vectors according to an internal array structure to obtain the first equivalent Euclidean distance.

2. The method of claim 1, wherein, The method for obtaining the original Euclidean distance comprises: The logic computing unit calculates a second equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the linearly transformed target vector, and the linearly transformed base vector in combination with the memory-compute integrated array, wherein the second equivalent Euclidean distance is an adjusted distance of an equivalent Euclidean distance of the linearly transformed target vector and the linearly transformed base vector according to the initial weight scaling parameter and the initial input scaling parameter; The logic computing unit linearly transforms the second equivalent Euclidean distance according to the initial output scaling parameter and the initial output translation parameter to obtain a linearly transformed second equivalent Euclidean distance; The logic computing unit restores the linearly transformed second equivalent Euclidean distance according to the original target vector, the initial input translation parameter, the initial input scaling parameter, the initial weight scaling parameter, the initial output scaling parameter, and the initial output translation parameter to obtain the original Euclidean distance.

3. The method according to any one of claims 1-2, characterized in that, The logic computing unit adjusts the initial input scaling parameter, the initial input translation parameter, the initial weight scaling parameter, the initial output scaling parameter, and the initial output translation parameter by using an optimization method and the current quantization loss, comprising: The logic computing unit adjusts the initial input scaling parameter, the initial input translation parameter, the initial weight scaling parameter, the initial output scaling parameter, and the initial output translation parameter by using a non-gradient optimization method and the current quantization loss.

4. A vector retrieval method characterized by, The method comprises: The logic computing unit linearly transforms an original target vector according to a target input scaling parameter and a target input translation parameter to obtain a linearly transformed target vector, and linearly transforms an original base vector according to the target input translation parameter and a target weight scaling parameter to obtain a linearly transformed base vector; The digital-analog conversion module quantizes the linearly transformed target vector based on an input quantization function to obtain a quantized target vector, and quantizes the linearly transformed base vector based on a weight quantization function to obtain a quantized base vector; The logic computing unit calculates a first equivalent Euclidean distance according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base vector in combination with the memory-compute integrated array; The logic calculation unit linearly transforms the first equivalent Euclidean distance according to a target output scaling parameter and a target output translation parameter; The analog-digital conversion module quantizes the linearly transformed first equivalent Euclidean distance based on an output quantization function to obtain a quantized equivalent Euclidean distance; The logic calculation unit determines K original base library vectors with the highest similarity to the original target vector by comparing the quantized equivalent Euclidean distances corresponding to different original base library vectors, where K is a positive integer; The target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter, and the target output translation parameter are determined according to the quantization parameter determination method in any one of claims 1-3; The logic calculation unit calculates a first equivalent Euclidean distance according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base library vector in combination with a memory-compute integrated array, including: The logic calculation unit obtains a first equivalent target vector and a first equivalent base library vector required for calculating a first equivalent Euclidean distance according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base library vector, and sends the first equivalent target vector and the first equivalent base library vector to the memory-compute integrated array; The memory-compute integrated array performs an inner product operation on the first equivalent target vector and the first equivalent base library vector according to an internal array structure to obtain a first equivalent Euclidean distance. 5.A quantization parameter determination apparatus of a computing-in-memory structure, characterized in that, The device comprises: A logic calculation unit is configured to linearly transform an original target vector according to an initial input scaling parameter and an initial input translation parameter to obtain a linearly transformed target vector, and linearly transform an original base library vector according to an initial input translation parameter and an initial weight scaling parameter to obtain a linearly transformed base library vector; A digital-analog conversion module is configured to quantize the linearly transformed target vector based on an input quantization function to obtain a quantized target vector, and quantize the linearly transformed base library vector based on a weight quantization function to obtain a quantized base library vector; The logic calculation unit, in combination with a memory-compute integrated array, is configured to calculate a first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector, and the quantized base library vector, where the first equivalent Euclidean distance is an adjusted distance of an equivalent Euclidean distance of the quantized target vector and the quantized base library vector according to the initial weight scaling parameter and the initial input scaling parameter, the equivalent Euclidean distance of two vectors is converted from a Euclidean distance formula, and can replace the Euclidean distance to evaluate the similarity between the two vectors; The logic calculation unit is further configured to linearly transform the first equivalent Euclidean distance according to an initial output scaling parameter and an initial output translation parameter. An analog-digital conversion module is configured to quantize the linearly transformed first equivalent Euclidean distance based on an output quantization function to obtain a quantized equivalent Euclidean distance; The logic calculation unit is further configured to perform restoration processing on the quantized equivalent Euclidean distance according to the original target vector, the initial input scaling parameter, the initial input translation parameter, the initial weight scaling parameter, the initial output scaling parameter, and the initial output translation parameter, to obtain a quantized Euclidean distance between the original target vector and the original base library vector; calculate a current quantization loss according to an original Euclidean distance and the quantized Euclidean distance, wherein the original Euclidean distance is a Euclidean distance true value before quantization; adjust the initial input scaling parameter, the initial input translation parameter, the initial weight scaling parameter, the initial output scaling parameter, and the initial output translation parameter by using an optimization method and the current quantization loss, until the current quantization loss is less than or equal to a preset loss threshold, to obtain a target input scaling parameter, a target input translation parameter, a target weight scaling parameter, a target output scaling parameter, and a target output translation parameter; The logic calculation unit is configured to obtain a first equivalent target vector and a first equivalent base library vector required for calculating the first equivalent Euclidean distance according to the initial weight scaling parameter, the initial input scaling parameter, the quantized target vector, and the quantized base library vector, and send the first equivalent target vector and the first equivalent base library vector to the memory-compute integrated array. The memory-compute integrated array is configured to perform inner product operation on the first equivalent target vector and the first equivalent base library vector according to an internal array structure to obtain the first equivalent Euclidean distance.

6. A vector retrieval apparatus characterized by comprising: The device comprises: A logic calculation unit is configured to perform linear transformation on an original target vector according to a target input scaling parameter and a target input translation parameter to obtain a linearly transformed target vector, and perform linear transformation on an original base library vector according to the target input translation parameter and a target weight scaling parameter to obtain a linearly transformed base library vector; An analog-digital conversion module is configured to quantize the linearly transformed target vector based on an input quantization function to obtain a quantized target vector, and quantize the linearly transformed base library vector based on a weight quantization function to obtain a quantized base library vector; The logic calculation unit in combination with the memory-compute integrated array is configured to calculate a first equivalent Euclidean distance according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base library vector; The logic calculation unit is further configured to perform linear transformation on the first equivalent Euclidean distance according to a target output scaling parameter and a target output translation parameter; An analog-digital conversion module is configured to quantize the linearly transformed first equivalent Euclidean distance based on an output quantization function to obtain a quantized equivalent Euclidean distance; The logic calculation unit is further configured to determine K original base library vectors with the highest similarity to the original target vector by comparing the quantized equivalent Euclidean distances corresponding to different original base library vectors, wherein K is a positive integer. The target input scaling parameter, the target input translation parameter, the target weight scaling parameter, the target output scaling parameter, and the target output translation parameter are determined according to the quantization parameter determination method in any one of claims 1-3. The logic calculation unit is configured to obtain a first equivalent target vector and a first equivalent base library vector required for calculating a first equivalent Euclidean distance according to the target weight scaling parameter, the target input scaling parameter, the quantized target vector, and the quantized base library vector, and send the first equivalent target vector and the first equivalent base library vector to the memory-compute integrated array. The memory-compute integrated array is configured to perform an inner product operation on the first equivalent target vector and the first equivalent base library vector according to an internal array structure to obtain the first equivalent Euclidean distance.

7. A memory computing integrated chip, comprising: The memory-compute integrated chip is at least used to implement the inner product operation on vectors in the method in any one of claims 1-4, and is used to store base library vectors.

8. An electronic device, comprising: The electronic device comprises at least one memory-compute integrated chip according to claim 7.

Citation Information

Patent Citations

  • Text retrieval model training method and device, question and answer retrieval method and device, equipment and medium

    CN113934830A

  • Data retrieval method and device, electronic equipment and storage medium

    CN115391404A