Neural network quantization method and device based on memory-computing integrated chip

CN121145950BActive Publication Date: 2026-08-18BEIJING YIYUAN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511337364.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-09-18
Publication Date
2026-08-18
Estimated Expiration
2045-09-18

AI Technical Summary

Technical Problem

然而,由于存算一体芯片制造工艺的限制,其写入过程中存在一定的误差,如脉冲电压和激励时间的不确定性、电导值的偏移等,这些误差会影响神经网络权重的存储精度,进而影响神经网络的计算精度

Benefits of technology

[0059]The neural network quantization method and apparatus based on in-memory computing chips provided in this application expands the dimensions of the original base data vector and the original target data vector using the equivalent Euclidean distance formula, retaining only the spatial relative position information of the data. This makes the perception of errors more insensitive in high-error systems. Simultaneously, through subsequent normalization processing and core distribution interval mapping, the accessed data possesses fixed information amplification characteristics, resulting in more dispersed demand data. This allows for clearer and faster differentiation between valid and invalid data, reducing data filtering and screening operations and improving the overall system's operating efficiency and accuracy. During the data mapping process, by determining the core distribution intervals of the base data and the target data, data within the core distribution interval is selected as the enhanced representation interval, while values ​​in other intervals can fall within fixed numerical points. This approach enhances the robustness of the data in the face of errors, allowing errors to correct data values ​​to a certain extent and yield values ​​closer to the original, thus improving the accuracy of the quantized data. Furthermore, by processing the normalized base vector and target vector separately, the processing of the target vector and base vector is relatively decoupled. The mapping method for the base vector is more flexible, allowing for adjustments to the corresponding mapping value based on the real-time status of the target vector, reducing the impact of errors on the calculation results. Simultaneously, independently determining the core distribution interval and mapping the normalized target vector to the second hardware-adapted quantization interval can largely avoid the influence of local feature values ​​on the overall data, ensuring the display of global data requirements and preventing issues such as numerical offsets causing changes in the relative positions between numerical points, affecting Euclidean distance calculation results, and reducing data resolution.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121145950B_ABST
    Figure CN121145950B_ABST
Patent Text Reader

Abstract

The application discloses a neural network quantization method and device based on a memory-computing integrated chip, which comprises the following steps: performing dimension expansion processing on an original library vector and an original target vector; performing normalization on the dimension-expanded library vector and the dimension-expanded target vector based on the mean value and the mean square deviation of each dimension of the dimension-expanded library vector; sorting the data of each dimension of the normalized library vector to obtain two marker points in the sorting result of each dimension, determining the library data core distribution interval corresponding to the dimension based on the marker points, and mapping the data of the dimension corresponding to the library data core distribution interval in the normalized library vector to a first hardware adaptive quantization interval based on the library data core distribution interval; and determining the corresponding target data core distribution interval according to a first quantity, a second quantity, a maximum value and a minimum value in the normalized target vector, and mapping the normalized target vector to a second hardware adaptive quantization interval based on the target data core distribution interval.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of in-memory computing chips, and more specifically, to a neural network quantization method and apparatus based on in-memory computing chips. Background Technology

[0002] In recent years, neural network accelerators based on in-memory computing chips have received widespread attention in the field of artificial intelligence. Memristors and other in-memory computing chips, as a new type of non-volatile memory, offer advantages such as low power consumption, simple structure, high operating speed, and controllable and variable resistance. They can realize in-memory computing architectures, reducing data transfer and improving computational parallelism. However, due to limitations in the manufacturing process of in-memory computing chips, certain errors exist during the writing process, such as uncertainties in pulse voltage and excitation time, and deviations in conductance. These errors affect the storage accuracy of neural network weights, and consequently, the computational accuracy of the neural network.

[0003] Furthermore, the conductivity value of in-memory computing chips is essentially an analog quantity, requiring sampling and conversion into a digital value via analog devices. This process introduces sampling offset errors. These errors can alter the relative positions of numerical points, affecting the Euclidean distance calculation results, reducing data resolution, and making it difficult to distinguish adjacent numerical points effectively.

[0004] Therefore, designing an effective neural network quantization method to reduce the impact of in-memory computing chip errors on computation results is an urgent problem to be solved. Summary of the Invention

[0005] This application provides a neural network quantization method and apparatus based on in-memory computing chips, which can reduce the impact of the error characteristics of in-memory computing chips on the calculation results.

[0006] The specific technical solution is as follows:

[0007] In a first aspect, embodiments of this application provide a neural network quantization method based on a memory computing chip, the method comprising:

[0008] Based on the equivalent Euclidean distance formula, the original base vector and the original target vector are expanded in dimension to obtain expanded base vector and expanded target vector. The equivalent Euclidean distance formula is transformed from the Euclidean distance formula and can replace the Euclidean distance formula to evaluate the similarity between two vectors. The original base vector and the original target vector are the weight parameters of the neural network model.

[0009] Based on the mean and standard deviation of each dimension of all expanded-dimensional base library vectors, each expanded-dimensional base library vector is normalized to obtain a normalized base library vector. Based on the mean and standard deviation of each dimension of all expanded-dimensional base library vectors, the expanded-dimensional target vector is normalized to obtain a normalized target vector.

[0010] The data under each dimension of all normalized base library vectors are sorted to obtain the first and second identifier points in the sorting results of each dimension. Based on the first and second identifier points of each dimension, the core distribution interval of the base library data corresponding to that dimension is determined. Using the core distribution interval of the base library data as a benchmark, the data under the corresponding dimension of the core distribution interval of the base library data in the normalized base library vector is mapped to the first hardware adaptation quantization interval. The first and second identifier points are identifier points that can reflect the core distribution characteristics of the data in the corresponding dimension.

[0011] Based on the first quantity, second quantity, maximum value, and minimum value in the normalized target vector, the target data core distribution interval corresponding to the normalized target vector is determined. Then, using the target data core distribution interval as a benchmark, the normalized target vector is mapped to a second hardware adaptation quantization interval. The first quantity is the number of elements in the normalized target vector that are greater than or equal to a preset value, and the second quantity is the number of elements in the normalized target vector that are less than the preset value.

[0012] In one possible implementation, the core distribution interval of the base database data and the core distribution interval of the target data are collectively referred to as the core data distribution interval, the normalized base database vector and the normalized target vector are collectively referred to as the normalized vector, and the first hardware adaptation quantization interval and the second hardware adaptation quantization interval are collectively referred to as the target hardware adaptation quantization interval.

[0013] Based on the core data distribution range, the normalized vector is mapped to the target hardware adaptation quantization range, including:

[0014] A refined mapping method is adopted to map the data in the normalized vector that are located within the core data distribution interval to the target hardware adaptation quantization interval. The refined mapping method is a mapping processing method that calculates based on the ratio between the numerical span of the core data distribution interval and the numerical span of the target hardware adaptation quantization interval, so as to maintain the relative positional relationship of the values ​​within the core data distribution interval.

[0015] A fixed-value mapping method is used to map data in the normalized vector that is outside the core data distribution range to the target hardware adaptation quantization range. The fixed-value mapping method directly maps the data outside the core data distribution range to the target boundary value of the target hardware adaptation quantization range. The target boundary value is the boundary value that is closest to the data to be mapped among the boundary values ​​of the target hardware adaptation quantization range.

[0016] In one possible implementation, the target data core distribution interval corresponding to the normalized target vector is determined based on the first quantity, the second quantity, the maximum value, and the minimum value in the normalized target vector, including:

[0017] When the first quantity is greater than the second quantity, the maximum value in the normalized target vector is taken as the maximum value of the target data core distribution interval, and the minimum value of the target data core distribution interval is determined according to the ratio of the second quantity to the first quantity and the minimum value in the normalized target vector.

[0018] When the first quantity is less than the second quantity, the minimum value in the normalized target vector is taken as the minimum value of the target data core distribution interval, and the maximum value of the target data core distribution interval is determined according to the ratio of the first quantity to the second quantity and the maximum value in the normalized target vector.

[0019] When the first quantity is equal to the second quantity, the minimum and maximum values ​​in the normalized target vector are respectively taken as the minimum and maximum values ​​of the core distribution interval of the target data.

[0020] In one possible implementation, determining the minimum value of the target data core distribution interval based on the ratio of the second quantity to the first quantity and the minimum value in the normalized target vector includes: using the product of the ratio of the second quantity to the first quantity and the minimum value in the normalized target vector as the minimum value of the target data core distribution interval; and / or,

[0021] Determining the maximum value of the core distribution interval of the target data based on the ratio of the first quantity to the second quantity and the maximum value in the normalized target vector includes: taking the product of the ratio of the first quantity to the second quantity and the maximum value in the normalized target vector as the maximum value of the core distribution interval of the target data.

[0022] In one possible implementation, when the expanded dimension base vector to be normalized and the expanded dimension target vector to be normalized are collectively referred to as the vector to be normalized, the vector to be normalized is normalized based on the mean and root mean square error of each dimension of all expanded dimension base vectors to obtain the normalized vector, including:

[0023] According to the normalization formula, the vector to be normalized is normalized to obtain the normalized vector;

[0024] The normalization formula includes:

[0025]

[0026] Wherein, the data' i The data is the i-th data point in the dimension to be normalized within the normalized vector. i For the i-th data in the dimension to be normalized in the vector to be normalized, the data mean The data is the mean of the unnormalized dimension of all expanded-dimensional base vectors. std Let be the mean squared error of the dimension to be normalized for all extended-dimensional base vectors.

[0027] In one possible implementation, the original base vector is denoted by b, the original target vector is denoted by a, the expanded dimension base vector is denoted by b', and the expanded dimension target vector is denoted by a'.

[0028] a' and b' have the same dimension, and a' and b' satisfy the following relationship:

[0029]

[0030] Secondly, embodiments of this application provide a neural network quantization device based on a memory computing chip, the device comprising:

[0031] The dimension expansion processing unit is used to expand the dimensions of the original base vector and the original target vector based on the equivalent Euclidean distance formula to obtain the expanded base vector and the expanded target vector. The equivalent Euclidean distance formula is a formula converted from the Euclidean distance formula and can replace the Euclidean distance to evaluate the similarity between two vectors. The original base vector and the original target vector are the weight parameters of the neural network model.

[0032] The normalization unit is used to normalize each of the expanded-dimensional base library vectors based on the mean and standard deviation of each dimension of all expanded-dimensional base library vectors to obtain a normalized base library vector, and to normalize the expanded-dimensional target vector based on the mean and standard deviation of each dimension of all expanded-dimensional base library vectors to obtain a normalized target vector.

[0033] The sorting unit is used to sort the data under each dimension of all normalized base vectors respectively, and obtain the first and second identifier points in the sorting results of each dimension. The first and second identifier points are identifier points that can reflect the core distribution characteristics of the data in the corresponding dimension.

[0034] The interval determination unit is used to determine the core distribution interval of the base database data corresponding to each dimension based on the first and second identifier points of each dimension.

[0035] The mapping unit is used to map the data in the normalized base database vector under the dimension corresponding to the core distribution interval of the base database data to the first hardware adaptation quantization interval, based on the core distribution interval of the base database data.

[0036] The interval determination unit is further configured to determine the target data core distribution interval corresponding to the normalized target vector based on the first quantity, the second quantity, the maximum value and the minimum value in the normalized target vector, wherein the first quantity is the number of elements in the normalized target vector that are greater than or equal to a preset value, and the second quantity is the number of elements in the normalized target vector that are less than the preset value.

[0037] The mapping unit is further configured to map the normalized target vector to the second hardware adaptation quantization interval, based on the target data core distribution interval.

[0038] In one possible implementation, the core distribution interval of the base database data and the core distribution interval of the target data are collectively referred to as the core data distribution interval, the normalized base database vector and the normalized target vector are collectively referred to as the normalized vector, and the first hardware adaptation quantization interval and the second hardware adaptation quantization interval are collectively referred to as the target hardware adaptation quantization interval.

[0039] The mapping unit includes:

[0040] The first mapping module is used to map the data in the normalized vector that is located in the core data distribution interval to the target hardware adaptation quantization interval using a refined mapping method. The refined mapping method is a mapping processing method that calculates based on the proportional relationship between the numerical span of the core data distribution interval and the numerical span of the target hardware adaptation quantization interval, so as to maintain the relative positional relationship of the values ​​within the core data distribution interval.

[0041] The second mapping module is used to map data outside the core data distribution range in the normalized vector to the target hardware adaptation quantization range using a fixed value mapping method. The fixed value mapping method is to directly map the data outside the core data distribution range to the target boundary value of the target hardware adaptation quantization range. The target boundary value is the boundary value closest to the data to be mapped among the boundary values ​​of the target hardware adaptation quantization range.

[0042] In one possible implementation, the interval determination unit includes:

[0043] The first determining module is used to take the maximum value in the normalized target vector as the maximum value of the target data core distribution interval when the first quantity is greater than the second quantity, and to determine the minimum value of the target data core distribution interval based on the ratio of the second quantity to the first quantity and the minimum value in the normalized target vector.

[0044] The second determining module is used to take the minimum value in the normalized target vector as the minimum value of the target data core distribution interval when the first quantity is less than the second quantity, and to determine the maximum value of the target data core distribution interval based on the ratio of the first quantity to the second quantity and the maximum value in the normalized target vector.

[0045] The third determining module is used to take the minimum and maximum values ​​in the normalized target vector as the minimum and maximum values ​​of the target data core distribution interval, respectively, when the first quantity is equal to the second quantity.

[0046] In one possible implementation, the first determining module is configured to take the product of the ratio of the second quantity to the first quantity and the minimum value in the normalized target vector as the minimum value of the target data core distribution interval; and / or,

[0047] The second determining module is used to take the product of the ratio of the first quantity to the second quantity and the maximum value in the normalized target vector as the maximum value of the core distribution interval of the target data.

[0048] In one possible implementation, the normalization unit is used to normalize the vector to be normalized according to the normalization formula, when the expanded dimension base vector to be normalized and the expanded dimension target vector to be normalized are collectively referred to as the vector to be normalized, to obtain the normalized vector.

[0049] The normalization formula includes:

[0050]

[0051] Wherein, the data' i The data is the i-th data point in the dimension to be normalized within the normalized vector. i For the i-th data in the dimension to be normalized in the vector to be normalized, the data mean The data is the mean of the unnormalized dimension of all expanded-dimensional base vectors. std Let be the mean squared error of the dimension to be normalized for all extended-dimensional base vectors.

[0052] In one possible implementation, the original base vector is denoted by b, the original target vector is denoted by a, the expanded dimension base vector is denoted by b', and the expanded dimension target vector is denoted by a'.

[0053] a' and b' have the same dimension, and a' and b' satisfy the following relationship:

[0054]

[0055] Thirdly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, which, when executed by a processing unit, implements the method as described in any possible implementation of the first aspect.

[0056] Fourthly, embodiments of this application provide an electronic device, which includes: one or more processing units;

[0057] The processing unit is coupled to a storage unit for storing one or more programs; when one or more programs are executed by one or more processing units, the electronic device implements the method as described in any possible implementation of the first aspect.

[0058] Fifthly, embodiments of this application provide a computer program product containing instructions that, when executed on a computer or processing unit, cause the computer or processing unit to perform the method described in any possible implementation of the first aspect.

[0059] The neural network quantization method and apparatus based on in-memory computing chips provided in this application expands the dimensions of the original base data vector and the original target data vector using the equivalent Euclidean distance formula, retaining only the spatial relative position information of the data. This makes the perception of errors more insensitive in high-error systems. Simultaneously, through subsequent normalization processing and core distribution interval mapping, the accessed data possesses fixed information amplification characteristics, resulting in more dispersed demand data. This allows for clearer and faster differentiation between valid and invalid data, reducing data filtering and screening operations and improving the overall system's operating efficiency and accuracy. During the data mapping process, by determining the core distribution intervals of the base data and the target data, data within the core distribution interval is selected as the enhanced representation interval, while values ​​in other intervals can fall within fixed numerical points. This approach enhances the robustness of the data in the face of errors, allowing errors to correct data values ​​to a certain extent and yield values ​​closer to the original, thus improving the accuracy of the quantized data. Furthermore, by processing the normalized base vector and target vector separately, the processing of the target vector and base vector is relatively decoupled. The mapping method for the base vector is more flexible, allowing for adjustments to the corresponding mapping value based on the real-time status of the target vector, reducing the impact of errors on the calculation results. Simultaneously, independently determining the core distribution interval and mapping the normalized target vector to the second hardware-adapted quantization interval can largely avoid the influence of local feature values ​​on the overall data, ensuring the display of global data requirements and preventing issues such as numerical offsets causing changes in the relative positions between numerical points, affecting Euclidean distance calculation results, and reducing data resolution.

[0060] Furthermore, the technical effects that can be achieved by the embodiments of this application include:

[0061] The process of determining the core distribution interval of the target data based on the first quantity, second quantity, maximum value, and minimum value of the normalized target vector further optimizes the precise control of the target data: when the first quantity is greater than the second quantity, the maximum value is taken as the maximum value of the core distribution interval of the target data, and the minimum value of the interval is determined by combining the ratio of the second quantity to the first quantity and the minimum value; when the first quantity is less than the second quantity, the minimum value of the interval is taken as the minimum value of the interval, and the maximum value of the interval is determined by combining the ratio of the first quantity to the second quantity and the maximum value; when the two are equal, the minimum value and the maximum value are directly used as the two ends of the interval. This method of dynamically and accurately dividing the core interval based on the distribution characteristics of the number of data elements can better fit the actual distribution pattern of the target data. This ensures that the core distribution range of the target data accurately covers the key information portion of the data. Based on this, subsequent mapping of the target vector to the second hardware-adaptive quantization range can further enhance the fixed information amplification characteristics of the accessed data, making the dispersion of the required data more reasonable. This allows for more efficient differentiation between valid and invalid data, while also more effectively avoiding the interference of local feature values ​​on the overall data. This further ensures a clear display of global data requirements, reduces quantization errors caused by biases in numerical distribution judgment, and makes the correction of data values ​​by errors more precise. In turn, while improving the accuracy of the quantized data, it further reduces the impact of errors on the calculation results, providing stronger support for improving the overall system's operating efficiency and accuracy.

[0062] By multiplying the ratio of the second quantity to the first quantity and the minimum value of the normalized target vector to determine the minimum value of the core distribution interval of the target data, and by multiplying the ratio of the first quantity to the second quantity and the maximum value of the normalized target vector to determine the maximum value of the interval, a more refined and quantitative division of the core distribution interval of the target data is achieved. This method, based on the direct correlation between the proportion of data elements and extreme values, can more accurately reflect the distribution weight of different numerical ranges in the target data, avoid the subjectivity and ambiguity in determining the interval boundaries, and ensure that the core distribution interval can accurately delineate the key information parts of the data while reasonably adjusting the interval range according to the actual distribution characteristics of the data. On this basis, mapping the target vector to the second hardware-adaptive quantization interval can more accurately enhance the amplification of fixed information in the accessed data. This approach ensures that the dispersion of demand data better meets the actual need to distinguish between valid and invalid data, thereby enabling more efficient data filtering and reducing filtering operations. Simultaneously, this precise interval division further reduces the interference of local feature values ​​on the overall data, more clearly showcasing global data requirements, effectively avoiding numerical offsets caused by interval boundary deviations, reducing the impact on Euclidean distance calculation results, and lowering quantization errors. Furthermore, by calculating the product of ratios and extreme values, the error correction effect on data values ​​becomes more targeted, making the corrected values ​​closer to the original values, further improving the accuracy of quantized data. It also provides a more accurate basis for adjusting the original base vector mapping according to the real-time status of the original target vector, thus more effectively reducing the impact of errors on calculation results and laying a more solid foundation for improving the overall system's operational efficiency and accuracy. Attached Figure Description

[0063] 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.

[0064] Figure 1 A schematic diagram of device write characteristic error provided for related technologies;

[0065] Figure 2 A flowchart illustrating a neural network quantization method based on a memory computing chip, provided for an embodiment of this application;

[0066] Figure 3 This is a block diagram of a neural network quantization device based on a memory computing chip, provided as an embodiment of this application. Detailed Implementation

[0067] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application.

[0068] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. The terms "comprising" and "having," and any variations thereof, in the embodiments and drawings of this application are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, products, or devices.

[0069] Before introducing the neural network quantization method based on in-memory computing chips provided in the embodiments of this application, let's take ReRAM (Resistive Random Access Memory) as an example to first introduce the error characteristics of memristor memory:

[0070] 1. Device write characteristic error

[0071] ReRAM is a memristor device that requires a pulse voltage higher than a certain value as an excitation during conduction. The potential difference of the pulse voltage turns the device on. Since the behavior of ReRAM cannot be accurately predicted, the pulse voltage and excitation time cannot be accurately determined. Therefore, a gradual voltage step size is required for excitation, while the established conductance value is read. Because the voltage step size is fixed, the written conductance value will eventually deviate from the expected value. This deviation has a normal distribution probability. Values ​​within this probability interval are considered the required value. Therefore, the actual value is the written value plus a normal distribution error.

[0072] like Figure 1 As shown, there is an interval between the actual value and the ideal value, which is considered to be the tolerance interval for the error. The values ​​falling within this interval follow a Gaussian probability distribution. This error is the systematic error introduced by the write operation, and its value range is [-8, 8].

[0073] 2. Effects of analog devices and numerical drift

[0074] ReRAM-based numerical values ​​are essentially written to the conductance. The final calculation is the current obtained by multiplying the conductance by the voltage that prevents the device from conducting further. Current itself is an analog quantity, which needs to be converted into a comprehensible numerical value according to certain rules. During this conversion process, the analog device needs to sample and read the actual current, and this process introduces numerical offset errors.

[0075] In the overall write process, after each pulse voltage increase with equal-step excitation, the actual write data needs to be read. This is done using an analog device. While this value has a certain degree of sampling offset, because the offset is in a fixed direction, its effect does not significantly change the relative position of the data; it only severely affects the data within its sampling offset step. Considering the overall sampling, the actual conductance value may be either too high or too low. Therefore, the actual written value can be considered as: Actual value = Expected value ± Write error ± Sampling error.

[0076] 3. Quantitative Analysis

[0077] The quantized value refers to the specific value written into the system. This value is primarily affected by the write error, and the written value will randomly fall within a range of the system step size (e.g., step size 16). Since the chip itself calculates using Euclidean distance, such a value will have the following impact:

[0078] (1) Value offset: The offset between the expected and the actual written value will cause the relative position between the value points to change. It is known that the calculation of Euclidean distance mainly considers the relative position between the value points. The dynamic distribution of this interval will affect the calculation result of Euclidean distance.

[0079] (2) Decreased data resolution: The offset of values ​​causes a change in relative position at a single point, which will be reflected as a decrease in resolution in the Euclidean distance calculation results. That is, many values ​​exist at the same point and cannot be distinguished well.

[0080] When performing vector retrieval based on an in-memory computing architecture, the data itself contains location information after abstraction. By combining all data dimensions pairwise and mapping them in a Cartesian coordinate system, specific location information is obtained. However, considering the final data type, existing technologies suffer from data precision degradation due to errors during the in-memory computing architecture's writing process. This causes location points in the dataset to collapse towards the centroid, making data information indistinguishable. How to avoid this problem in quantization mapping and improve the effective location information of the data is a key feature of this application. Therefore, to solve the above problems, this application provides a neural network quantization method based on an in-memory computing chip. This method can be applied to electronic devices, such as devices including an in-memory computing architecture. Figure 2 As shown, the method includes:

[0081] S110: Based on the equivalent Euclidean distance formula, the original base vector and the original target vector are expanded in dimension to obtain the expanded base vector and the expanded target vector.

[0082] The equivalent Euclidean distance formula is derived from the Euclidean distance formula and can replace the Euclidean distance formula to evaluate the similarity between two vectors. The original base vector and the original target vector are the weight parameters of the neural network model.

[0083] The equivalent Euclidean distance formulas include: Where y represents the equivalent Euclidean distance, a represents the original target vector, and b represents the original base vector.

[0084] The specific process of converting the Euclidean distance formula into an equivalent Euclidean distance formula includes: Knowing the Euclidean distance formula includes... Where d represents the Euclidean distance between vectors a and b, n represents the dimensions of the two vectors, i represents the i-th dimension, and a i Let b represent the element of the i-th dimension in vector a. i This represents the element of the i-th dimension in vector b;

[0085] The process of simplifying and transforming the above Euclidean distance formula includes:

[0086] d 2 =(ab) 2 =a 2 +b 2 -2ab

[0087] d 2 -a 2 =b 2 -2ab

[0088] a 2 -d 2=2ab-b 2

[0089]

[0090] Therefore, since vector a can be considered as a fixed quantity, the smaller d is, The larger, therefore The larger d is, the higher the vector similarity. Therefore, the smaller d is, the higher the vector similarity. The larger the value, the higher the vector similarity. Therefore, the equivalent Euclidean distance formula can be used. To perform a similarity comparison.

[0091] In step S110, the equivalent Euclidean distance formula can be used to expand the dimensions of the original base vector and the original target vector. Let the original base vector be represented by b, the original target vector by a, the expanded base vector by b', and the expanded target vector by a'.

[0092] a' and b' have the same dimension, and a' and b' satisfy the following relationship:

[0093]

[0094] Given that expanding the dimension of a by dimension a” to obtain a', and expanding the dimension of b by dimension b” to obtain b', the above relationship can be expressed as:

[0095]

[0096] Therefore, it can be concluded that as long as the expanded vectors (i.e., the incremental parts) of a and b satisfy the relationship... The goal is to ensure that the dimensions of the final a' and b' are the same.

[0097] For example, if both a and b are extended by one dimension, the resulting a' and b' will have at least the following two possibilities:

[0098] (1) And b' = [b, b 2 ];

[0099] (2)

[0100] S120: Based on the mean and standard deviation of each dimension of all expanded-dimensional base library vectors, normalize each expanded-dimensional base library vector to obtain a normalized base library vector; and based on the mean and standard deviation of each dimension of all expanded-dimensional base library vectors, normalize the expanded-dimensional target vector to obtain a normalized target vector.

[0101] Specifically, when both the expanded dimension base vector and the expanded dimension target vector to be normalized are collectively referred to as the vector to be normalized, the vector to be normalized is normalized based on the mean and standard deviation of each dimension of all expanded dimension base vectors, resulting in the normalized vector, including:

[0102] According to the normalization formula, the vector to be normalized is normalized to obtain the normalized vector;

[0103] The normalization formulas include:

[0104]

[0105] Among them, data' i For the i-th data point in the dimension to be normalized in the normalized vector, data i Let data be the i-th data point in the dimension to be normalized within the vector to be normalized. mean The mean of the unnormalized dimension of all expanded-dimensional base library vectors, data std Let be the mean squared error of the dimension to be normalized for all extended-dimensional base vectors.

[0106] As can be seen from the above normalization method, when normalizing the expanded dimension target vector, the mean and standard deviation of each dimension of all expanded dimension base vectors are also used, so as to ensure that the relative position and distribution of the expanded dimension target vector and the expanded dimension base vector remain consistent.

[0107] Suppose the original data has 128 dimensions, and after expansion it has 129 dimensions. Taking the expanded 129-dimensional data as an example, we perform normalization on the 0th dimension. This involves extracting dimension 0 from all vectors in the base dataset, calculating the mean and standard deviation for that dimension, and then normalizing that dimension again. The same process is applied to the other dimensions.

[0108] The advantages of this normalization process include:

[0109] (1) Retain the relative position information of each dimension. Given the characteristics of in-memory computing chips such as RRAM, retaining their numerical information is not very meaningful. Normalizing them according to each dimension can make the position information and trend more meaningful in subsequent calculations.

[0110] (2) Decrease Or b 2 Impact on the data. Because this value will differ significantly from the others, using the same normalization method or choosing a uniform quantization mapping will have a significant impact on the representation of the data for the entire question.

[0111] (3) Reduce the numerical impact of some special dimensions. Based on the characteristics of the original data, there may be some dimensions with very large values, but the differences between different vectors are small. These dimensions can be considered as unimportant dimensions. However, since large values ​​may have a significant impact during the quantization process, this normalization method can reduce the impact of this type of singular value.

[0112] S130: Sort the data under each dimension of all normalized base library vectors respectively, obtain the first and second identifier points in the sorting results of each dimension, and determine the core distribution interval of the base library data corresponding to the dimension based on the first and second identifier points of each dimension. Using the core distribution interval of the base library data as the benchmark, map the data under the dimension corresponding to the core distribution interval of the base library data in the normalized base library vector to the first hardware adaptation quantization interval.

[0113] Among them, the first and second marker points are marker points that can reflect the core distribution characteristics of the data in the corresponding dimension.

[0114] The methods for determining the first and second marker points include, but are not limited to, the following:

[0115] (1) The first marker is the first quantile, and the second marker is the second quantile. For example, the first quantile is the value at 25%, and the second quantile is the value at 75%.

[0116] (2) The first marker point is the Mth value, the second marker point is the Nth value, and the values ​​of M and N can be determined based on the amount of data in the base vector.

[0117] In this embodiment, determining the core distribution range of the base database data corresponding to each dimension based on the first and second identifier points includes: taking the value at the first identifier point as the minimum value of the core distribution range of the base database data corresponding to the dimension, and taking the value at the second identifier point as the maximum value of the core distribution range of the base database data corresponding to the dimension.

[0118] In this embodiment, based on the core distribution range of the base database data, the data in the normalized base database vector corresponding to the core distribution range of the base database data is mapped to the first hardware adaptation quantization range. This includes: using a refined mapping method to map the data in the normalized base database vector located within the core distribution range of the base database data to the first hardware adaptation quantization range. The refined mapping method is calculated based on the proportional relationship between the numerical span of the core distribution range of the base database data and the numerical span of the first hardware adaptation quantization range to maintain the relative positional relationship of the values ​​within the core distribution range of the base database data; and using a fixed value mapping method to map the data in the normalized base database vector located outside the core distribution range of the base database data to the first hardware adaptation quantization range. The fixed value mapping method is to directly map the data outside the core distribution range of the base database data to the first boundary value of the first hardware adaptation quantization range. The first boundary value is the boundary value closest to the data to be mapped among the boundary values ​​of the first hardware adaptation quantization range.

[0119] Specifically, when using a refined mapping method to map data in the normalized base database vector that falls within the core distribution range of the base database data to the first hardware adaptation quantization range, the data in the normalized base database vector that falls within the core distribution range of the base database data can be directly mapped to the first hardware adaptation quantization range. Alternatively, the data in the normalized base database vector that falls within the core distribution range of the base database data can first be mapped to the intermediate range after appropriately expanding the range of the first hardware adaptation quantization range, and then data truncation processing can be performed before mapping to the first hardware adaptation quantization range.

[0120] Since the hardware adaptation quantization intervals corresponding to the base vector and the target vector may be different—for example, the hardware adaptation quantization interval corresponding to the base vector might be represented by int8, while the hardware adaptation quantization interval corresponding to the target vector might be represented by int4—this application, in order to distinguish between the two, names the hardware adaptation quantization interval corresponding to the base vector as the "first hardware adaptation quantization interval" and the hardware adaptation quantization interval corresponding to the target vector as the "second hardware adaptation quantization interval." Here, "first" and "second" are only used to distinguish the differences and do not indicate any order.

[0121] For example, due to the nature of in-memory computing chips such as RRAM, quantization to int8 is required, but the actual usable range is the data interval [-48, 48]. This range corresponds to approximately 40% of the original [-128, 127]. Considering that writing inherently introduces some error, the data is mapped to the interval [-96, 96] and then truncated, so that the largest values ​​are truncated and mapped to 48 and -48. Furthermore, due to the characteristics of interval adjustment and truncation, refining the mapping representation of the middle 50% of the data allows for better handling of subsequent system errors.

[0122] Due to the inherent physical characteristics of the system, the written data will have an error of approximately ±20. Furthermore, due to ADC sampling issues, the actual written value will be 1-2 times smaller in absolute terms than 8. Choosing a larger range of the original mapping interval can better approximate the original value after incorporating such errors. For example, the original value quantized in the range [-96, 96] is 74, the truncated value is 48, and the written value after sampling might be in the range [40, 48]. Considering the system error distribution, positive errors are more likely to be positively biased, while copying errors are more likely to be negatively biased, resulting in an additional error of [15, 20]. The result after incorporating the error would then be [55, 68], with an error range of [6, 19] relative to the original value, which is smaller and more favorable for preserving positional information.

[0123] S140: Based on the first quantity, second quantity, maximum value and minimum value in the normalized target vector, determine the target data core distribution interval corresponding to the normalized target vector, and map the normalized target vector to the second hardware adaptation quantization interval based on the target data core distribution interval.

[0124] The first quantity is the number of elements in the normalized target vector that are greater than or equal to a preset value, and the second quantity is the number of elements in the normalized target vector that are less than a preset value. The preset value can be determined based on practical experience; for example, it can be 0 or a non-zero value.

[0125] Methods for determining the core distribution interval of the target data corresponding to the normalized target vector include:

[0126] (1) When the first quantity is greater than the second quantity, the maximum value in the normalized target vector is taken as the maximum value of the core distribution interval of the target data, and the minimum value of the core distribution interval of the target data is determined according to the ratio of the second quantity to the first quantity and the minimum value in the normalized target vector.

[0127] Among them, the product of the ratio of the second quantity to the first quantity and the minimum value in the normalized target vector can be used as the minimum value of the core distribution interval of the target data.

[0128] Therefore, when the first quantity is greater than the second quantity, the core distribution interval of the target data can be represented as:

[0129]

[0130] Here, the minimum value of the target vector refers to the minimum value in the normalized target vector, and the maximum value of the target vector refers to the maximum value in the normalized target vector.

[0131] (2) When the first quantity is less than the second quantity, the minimum value in the normalized target vector is taken as the minimum value of the core distribution interval of the target data, and the maximum value of the core distribution interval of the target data is determined according to the ratio of the first quantity to the second quantity and the maximum value in the normalized target vector.

[0132] The product of the ratio of the first quantity to the second quantity and the maximum value in the normalized target vector is taken as the maximum value of the core distribution interval of the target data.

[0133] Therefore, when the first quantity is greater than the second quantity, the core distribution interval of the target data can be represented as:

[0134]

[0135] Here, the minimum value of the target vector refers to the minimum value in the normalized target vector, and the maximum value of the target vector refers to the maximum value in the normalized target vector.

[0136] (3) When the first quantity is equal to the second quantity, the minimum and maximum values ​​in the normalized target vector are respectively taken as the minimum and maximum values ​​of the core distribution interval of the target data.

[0137] When the first quantity equals the second quantity, the core distribution interval of the target data can be represented as:

[0138] Core distribution interval of target data = [Minimum value of target vector, Maximum value of target vector]

[0139] Here, the minimum value of the target vector refers to the minimum value in the normalized target vector, and the maximum value of the target vector refers to the maximum value in the normalized target vector.

[0140] Based on the core distribution range of the target data, the normalized target vector is mapped to the second hardware-adaptive quantization range. This includes: using a refined mapping method to map data within the core distribution range of the target data in the normalized target vector to the second hardware-adaptive quantization range. The refined mapping method is calculated based on the ratio between the numerical span of the core distribution range of the target data and the numerical span of the second hardware-adaptive quantization range to maintain the relative positional relationship of the values ​​within the core distribution range of the target data; and using a fixed-value mapping method to map data outside the core distribution range of the target data in the normalized target vector to the second hardware-adaptive quantization range. The fixed-value mapping method directly maps data outside the core distribution range of the target data to the second boundary value of the second hardware-adaptive quantization range. The second boundary value is the boundary value closest to the data to be mapped among the boundary values ​​of the second hardware-adaptive quantization range.

[0141] Based on the above method for interval mapping between the normalized base data vector and the target vector, it can be seen that, when the core distribution intervals of the base data and the target data are collectively referred to as the core data distribution interval, the normalized base data vector and the normalized target vector are collectively referred to as the normalized vector, and the first hardware adaptation quantization interval and the second hardware adaptation quantization interval are collectively referred to as the target hardware adaptation quantization interval, the normalized vector is mapped to the target hardware adaptation quantization interval based on the core data distribution interval. This includes: using a refined mapping method to map the data in the normalized vector that falls within the core data distribution interval to the target hardware... The adaptation quantization interval and refined mapping method are based on the ratio between the numerical span of the core data distribution interval and the numerical span of the target hardware adaptation quantization interval to maintain the mapping processing method of the relative positional relationship of the values ​​within the core data distribution interval. The fixed value mapping method maps the data outside the core data distribution interval in the normalized vector to the target hardware adaptation quantization interval. The fixed value mapping method directly maps the data outside the core data distribution interval to the target boundary value of the target hardware adaptation quantization interval. The target boundary value is the boundary value that is closest to the data to be mapped among the boundary values ​​of the target hardware adaptation quantization interval.

[0142] The neural network quantization method based on in-memory computing chips provided in this application expands the dimensions of the original base data vector and the original target data vector using the equivalent Euclidean distance formula, retaining only the spatial relative position information of the data. This makes the perception of errors more insensitive in high-error systems. Simultaneously, through subsequent normalization processing and core distribution interval mapping, the accessed data possesses fixed information amplification characteristics, resulting in more dispersed demand data. This allows for clearer and faster differentiation between valid and invalid data, reducing data filtering and screening operations, and improving the overall system's operating efficiency and accuracy. During the data mapping process, by determining the core distribution intervals of the base data and the target data, data within the core distribution interval is selected as the enhanced representation interval, while values ​​in other intervals can fall on fixed value points, thus... The data exhibits a certain degree of robustness to errors, allowing errors to correct data values ​​to a extent, resulting in values ​​closer to the original values ​​and improving the accuracy of the quantized data. Furthermore, by processing the normalized base vector and target vector separately, the processing of the target vector and base vector is relatively decoupled. The mapping method for the base vector is more flexible, allowing for adjustments to the corresponding mapping value based on the real-time status of the target vector, thus reducing the impact of errors on the calculation results. Simultaneously, independently determining the core distribution interval and mapping the normalized target vector to the second hardware-adaptive quantization interval can largely avoid the influence of local feature values ​​on the overall data, ensuring the display of global data requirements and preventing issues such as changes in the relative positions between numerical points due to numerical offsets, affecting Euclidean distance calculation results, and reducing data resolution.

[0143] Furthermore, the operation of determining the core distribution interval of the target data based on the first quantity, second quantity, maximum value, and minimum value of the normalized target vector further optimizes the precise control of the target data: when the first quantity is greater than the second quantity, the maximum value is taken as the maximum value of the core distribution interval of the target data, and the minimum value of the interval is determined by combining the ratio of the second quantity to the first quantity and the minimum value; when the first quantity is less than the second quantity, the minimum value of the interval is taken as the minimum value of the interval, and the maximum value of the interval is determined by combining the ratio of the first quantity to the second quantity and the maximum value; when the two are equal, the minimum value and the maximum value are directly used as the two ends of the interval. This method of dynamically and accurately dividing the core interval based on the distribution characteristics of the number of data elements can better fit the actual distribution of the target data. The principle ensures that the core distribution range of the target data accurately covers the key information part of the data. Based on this, the subsequent mapping of the target vector to the second hardware adaptation quantization range can further enhance the fixed information amplification characteristics of the accessed data, make the dispersion of the required data more reasonable, and thus more efficiently distinguish between valid and invalid data. At the same time, it can also more fully avoid the interference of local feature values ​​on the overall data, further ensure the clear display of global data requirements, reduce quantization errors caused by numerical distribution judgment deviations, and make the error correction effect on data values ​​more accurate. In this way, while improving the accuracy of the quantized data, it further reduces the impact of errors on the calculation results, providing stronger support for improving the overall system operating efficiency and accuracy.

[0144] By multiplying the ratio of the second quantity to the first quantity and the minimum value of the normalized target vector to determine the minimum value of the core distribution interval of the target data, and by multiplying the ratio of the first quantity to the second quantity and the maximum value of the normalized target vector to determine the maximum value of the interval, a more refined and quantitative division of the core distribution interval of the target data is achieved. This method, based on the direct correlation between the proportion of data elements and extreme values, can more accurately reflect the distribution weight of different numerical ranges in the target data, avoid the subjectivity and ambiguity in determining the interval boundaries, and ensure that the core distribution interval can accurately delineate the key information parts of the data while reasonably adjusting the interval range according to the actual distribution characteristics of the data. On this basis, mapping the target vector to the second hardware-adaptive quantization interval can more accurately enhance the amplification of fixed information in the accessed data. This approach ensures that the dispersion of demand data better meets the actual need to distinguish between valid and invalid data, thereby enabling more efficient data filtering and reducing filtering operations. Simultaneously, this precise interval division further reduces the interference of local feature values ​​on the overall data, more clearly showcasing global data requirements, effectively avoiding numerical offsets caused by interval boundary deviations, reducing the impact on Euclidean distance calculation results, and lowering quantization errors. Furthermore, by calculating the product of ratios and extreme values, the error correction effect on data values ​​becomes more targeted, making the corrected values ​​closer to the original values, further improving the accuracy of quantized data. It also provides a more accurate basis for adjusting the original base vector mapping according to the real-time status of the original target vector, thus more effectively reducing the impact of errors on calculation results and laying a more solid foundation for improving the overall system's operational efficiency and accuracy.

[0145] It should be added that when the original data (including the original base vector and the original target vector) has very low distinguishability, such as the values ​​being distributed in the range of (0,1), and most of the data having a distinguishability of three or four decimal places, the subtle differences in the original data are easily masked by the error of the in-memory computing chip, making it difficult for subsequent calculations to effectively distinguish the data. Therefore, it is necessary to enhance the distinguishability of the data through specific preprocessing. After performing specific preprocessing, the vectors after specific preprocessing are mapped to the corresponding hardware-adaptive quantization range.

[0146] The specific processing steps are divided into two steps: The first step is mapping based on the covariance matrix. First, the covariance of the original data is calculated to obtain the transmission matrix (covariance matrix) that reflects the correlation between variables within the data. Then, the original data is multiplied by the transmission matrix. Through matrix operations, the subtle distribution differences in the original data are amplified, generating a new set of data (the new data has the same dimensions as the original data; for example, the original 128-dimensional data still yields 128-dimensional new data after this operation). The second step is data concatenation and dimensionality enhancement. The "mapped new data" obtained in the first step is directly concatenated after the "original data" to form the final dimensionality-enhanced data. Taking the original 128-dimensional data as an example, the final data dimension after concatenation is 128 dimensions (original) + 128 dimensions (mapped) = 256 dimensions. By enhancing dimensionality, the information of the original data is preserved, while the "difference feature dimension" amplified by the covariance matrix is ​​added, significantly improving the overall discriminative power of the data.

[0147] A crucial rule that requires special attention is that the original target vector must be mapped using the covariance matrix of the original base vector, not the covariance matrix of the original target vector itself. The core purpose of this rule is to "ensure that the relative relationships of the original data do not change significantly." Because the base vector is the benchmark of the entire data system, using its covariance matrix ensures that the original target vector and the original base vector follow the same "difference amplification standard" during the "mapping and amplification of differences" process. This avoids inconsistencies in mapping rules due to the use of different covariance matrices, which could disrupt the original relative distribution relationship between the original target vector and the original base vector. This ensures that subsequent calculations based on both (such as similarity matching) can still be performed based on the original relative relationship, while simultaneously amplifying the discriminative power through dimensionality enhancement.

[0148] Based on the above method embodiments, another embodiment of this application provides a neural network quantization device based on a memory computing chip, such as... Figure 3 As shown, the device includes:

[0149] The dimension expansion processing unit 210 is used to perform dimension expansion processing on the original base vector and the original target vector based on the equivalent Euclidean distance formula to obtain the expanded base vector and the expanded target vector. The equivalent Euclidean distance formula is a formula converted from the Euclidean distance formula and can replace the Euclidean distance to evaluate the similarity between two vectors. The original base vector and the original target vector are the weight parameters of the neural network model.

[0150] Normalization unit 220 is used to normalize each of the expanded-dimensional base library vectors based on the mean and standard deviation of each dimension of all expanded-dimensional base library vectors to obtain a normalized base library vector, and to normalize the expanded-dimensional target vector based on the mean and standard deviation of each dimension of all expanded-dimensional base library vectors to obtain a normalized target vector.

[0151] The sorting unit 230 is used to sort the data under each dimension of all normalized base vectors respectively, and obtain the first and second identifier points in the sorting results of each dimension. The first and second identifier points are identifier points that can reflect the core distribution characteristics of the data in the corresponding dimension.

[0152] The interval determination unit 240 is used to determine the core distribution interval of the base database data corresponding to each dimension based on the first identifier point and the second identifier point of each dimension.

[0153] The mapping unit 250 is used to map the data in the normalized base database vector under the dimension corresponding to the core distribution interval of the base database data to the first hardware adaptation quantization interval, based on the core distribution interval of the base database data.

[0154] The interval determination unit 240 is further configured to determine the target data core distribution interval corresponding to the normalized target vector based on the first quantity, the second quantity, the maximum value and the minimum value in the normalized target vector, wherein the first quantity is the number of elements in the normalized target vector that are greater than or equal to a preset value, and the second quantity is the number of elements in the normalized target vector that are less than the preset value.

[0155] The mapping unit 250 is further configured to map the normalized target vector to the second hardware adaptation quantization interval based on the target data core distribution interval.

[0156] In one possible implementation, the core distribution interval of the base database data and the core distribution interval of the target data are collectively referred to as the core data distribution interval, the normalized base database vector and the normalized target vector are collectively referred to as the normalized vector, and the first hardware adaptation quantization interval and the second hardware adaptation quantization interval are collectively referred to as the target hardware adaptation quantization interval.

[0157] The mapping unit 250 includes:

[0158] The first mapping module is used to map the data in the normalized vector that is located in the core data distribution interval to the target hardware adaptation quantization interval using a refined mapping method. The refined mapping method is a mapping processing method that calculates based on the proportional relationship between the numerical span of the core data distribution interval and the numerical span of the target hardware adaptation quantization interval, so as to maintain the relative positional relationship of the values ​​within the core data distribution interval.

[0159] The second mapping module is used to map data outside the core data distribution range in the normalized vector to the target hardware adaptation quantization range using a fixed value mapping method. The fixed value mapping method is to directly map the data outside the core data distribution range to the target boundary value of the target hardware adaptation quantization range. The target boundary value is the boundary value closest to the data to be mapped among the boundary values ​​of the target hardware adaptation quantization range.

[0160] In one possible implementation, the interval determination unit 240 includes:

[0161] The first determining module is used to take the maximum value in the normalized target vector as the maximum value of the target data core distribution interval when the first quantity is greater than the second quantity, and to determine the minimum value of the target data core distribution interval based on the ratio of the second quantity to the first quantity and the minimum value in the normalized target vector.

[0162] The second determining module is used to take the minimum value in the normalized target vector as the minimum value of the target data core distribution interval when the first quantity is less than the second quantity, and to determine the maximum value of the target data core distribution interval based on the ratio of the first quantity to the second quantity and the maximum value in the normalized target vector.

[0163] The third determining module is used to take the minimum and maximum values ​​in the normalized target vector as the minimum and maximum values ​​of the target data core distribution interval, respectively, when the first quantity is equal to the second quantity.

[0164] In one possible implementation, the first determining module is configured to take the product of the ratio of the second quantity to the first quantity and the minimum value in the normalized target vector as the minimum value of the target data core distribution interval; and / or,

[0165] The second determining module is used to take the product of the ratio of the first quantity to the second quantity and the maximum value in the normalized target vector as the maximum value of the core distribution interval of the target data.

[0166] In one possible implementation, the normalization unit 220 is used to normalize the vector to be normalized according to the normalization formula, when the expanded dimension base vector to be normalized and the expanded dimension target vector to be normalized are collectively referred to as the vector to be normalized, to obtain the normalized vector.

[0167] The normalization formula includes:

[0168]

[0169] Wherein, the data' i The data is the i-th data point in the dimension to be normalized within the normalized vector. i For the i-th data in the dimension to be normalized in the vector to be normalized, the data mean The data is the mean of the unnormalized dimension of all expanded-dimensional base vectors. std Let be the mean squared error of the dimension to be normalized for all extended-dimensional base vectors.

[0170] In one possible implementation, the original base vector is denoted by b, the original target vector is denoted by a, the expanded dimension base vector is denoted by b', and the expanded dimension target vector is denoted by a'.

[0171] a' and b' have the same dimension, and a' and b' satisfy the following relationship:

[0172]

[0173] The neural network quantization device based on an in-memory computing chip provided in this application expands the dimensions of the original base data vector and the original target data vector using the equivalent Euclidean distance formula, retaining only the spatial relative position information of the data. This makes the perception of errors more insensitive in high-error systems. Simultaneously, through subsequent normalization processing and core distribution interval mapping, the accessed data possesses fixed information amplification characteristics, resulting in more dispersed demand data. This allows for clearer and faster differentiation between valid and invalid data, reducing data filtering and screening operations, and improving the overall system's operating efficiency and accuracy. During the data mapping process, by determining the core distribution intervals of the base data and the target data, data within the core distribution interval is selected as the enhanced representation interval, while values ​​in other intervals can fall on fixed value points, thus... The data exhibits a certain degree of robustness to errors, allowing errors to correct data values ​​to a extent, resulting in values ​​closer to the original values ​​and improving the accuracy of the quantized data. Furthermore, by processing the normalized base vector and target vector separately, the processing of the target vector and base vector is relatively decoupled. The mapping method for the base vector is more flexible, allowing for adjustments to the corresponding mapping value based on the real-time status of the target vector, thus reducing the impact of errors on the calculation results. Simultaneously, independently determining the core distribution interval and mapping the normalized target vector to the second hardware-adaptive quantization interval can largely avoid the influence of local feature values ​​on the overall data, ensuring the display of global data requirements and preventing issues such as changes in the relative positions between numerical points due to numerical offsets, affecting Euclidean distance calculation results, and reducing data resolution.

[0174] Furthermore, the operation of determining the core distribution interval of the target data based on the first quantity, second quantity, maximum value, and minimum value of the normalized target vector further optimizes the precise control of the target data: when the first quantity is greater than the second quantity, the maximum value is taken as the maximum value of the core distribution interval of the target data, and the minimum value of the interval is determined by combining the ratio of the second quantity to the first quantity and the minimum value; when the first quantity is less than the second quantity, the minimum value of the interval is taken as the minimum value of the interval, and the maximum value of the interval is determined by combining the ratio of the first quantity to the second quantity and the maximum value; when the two are equal, the minimum value and the maximum value are directly used as the two ends of the interval. This method of dynamically and accurately dividing the core interval based on the distribution characteristics of the number of data elements can better fit the actual distribution of the target data. The principle ensures that the core distribution range of the target data accurately covers the key information part of the data. Based on this, the subsequent mapping of the target vector to the second hardware adaptation quantization range can further enhance the fixed information amplification characteristics of the accessed data, make the dispersion of the required data more reasonable, and thus more efficiently distinguish between valid and invalid data. At the same time, it can also more fully avoid the interference of local feature values ​​on the overall data, further ensure the clear display of global data requirements, reduce quantization errors caused by numerical distribution judgment deviations, and make the error correction effect on data values ​​more accurate. In this way, while improving the accuracy of the quantized data, it further reduces the impact of errors on the calculation results, providing stronger support for improving the overall system operating efficiency and accuracy.

[0175] By multiplying the ratio of the second quantity to the first quantity and the minimum value of the normalized target vector to determine the minimum value of the core distribution interval of the target data, and by multiplying the ratio of the first quantity to the second quantity and the maximum value of the normalized target vector to determine the maximum value of the interval, a more refined and quantitative division of the core distribution interval of the target data is achieved. This method, based on the direct correlation between the proportion of data elements and extreme values, can more accurately reflect the distribution weight of different numerical ranges in the target data, avoid the subjectivity and ambiguity in determining the interval boundaries, and ensure that the core distribution interval can accurately delineate the key information parts of the data while reasonably adjusting the interval range according to the actual distribution characteristics of the data. On this basis, mapping the target vector to the second hardware-adaptive quantization interval can more accurately enhance the amplification of fixed information in the accessed data. This approach ensures that the dispersion of demand data better meets the actual need to distinguish between valid and invalid data, thereby enabling more efficient data filtering and reducing filtering operations. Simultaneously, this precise interval division further reduces the interference of local feature values ​​on the overall data, more clearly showcasing global data requirements, effectively avoiding numerical offsets caused by interval boundary deviations, reducing the impact on Euclidean distance calculation results, and lowering quantization errors. Furthermore, by calculating the product of ratios and extreme values, the error correction effect on data values ​​becomes more targeted, making the corrected values ​​closer to the original values, further improving the accuracy of quantized data. It also provides a more accurate basis for adjusting the original base vector mapping according to the real-time status of the original target vector, thus more effectively reducing the impact of errors on calculation results and laying a more solid foundation for improving the overall system's operational efficiency and accuracy.

[0176] Based on the above method embodiments, another embodiment of this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processing unit, implements the method as described in any of the above embodiments.

[0177] Based on the above method embodiments, another embodiment of this application provides an electronic device, which includes: one or more processing units; the processing units are coupled to a storage unit, the storage unit being used to store one or more programs; when one or more programs are executed by one or more processing units, the electronic device implements the method as described above.

[0178] Based on the above embodiments, another embodiment of this application provides a computer program product, which includes instructions that, when executed on a computer or processing unit, cause the computer or processing unit to perform the method described in any of the above embodiments.

[0179] The above-described apparatus embodiments correspond to the method embodiments and have the same technical effects. For detailed descriptions, please refer to the method embodiments. The apparatus embodiments are derived from the method embodiments; detailed descriptions can be found in the method embodiments section, and will not be repeated here. Those skilled in the art will understand that the accompanying drawings are merely schematic diagrams of one embodiment, and the modules or processes shown in the drawings are not necessarily essential for implementing this application.

[0180] Those skilled in the art will understand that the modules in the apparatus of the embodiments can be distributed in the apparatus of the embodiments as described in the embodiments, or they can be located in one or more devices different from this embodiment with corresponding changes. The modules of the above embodiments can be combined into one module, or they can be further divided into multiple sub-modules.

[0181] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions 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 this application.

Claims

1. A neural network quantization method based on a memory computing chip, characterized in that, The method includes: Based on the equivalent Euclidean distance formula, the original base vector and the original target vector are expanded in dimension to obtain expanded base vector and expanded target vector. The equivalent Euclidean distance formula is transformed from the Euclidean distance formula and can replace the Euclidean distance formula to evaluate the similarity between two vectors. The original base vector and the original target vector are the weight parameters of the neural network model. Based on the mean and standard deviation of each dimension of all expanded-dimensional base library vectors, each expanded-dimensional base library vector is normalized to obtain a normalized base library vector. Based on the mean and standard deviation of each dimension of all expanded-dimensional base library vectors, the expanded-dimensional target vector is normalized to obtain a normalized target vector. The data under each dimension of all normalized base library vectors are sorted to obtain the first and second identifier points in the sorting results of each dimension. Based on the first and second identifier points of each dimension, the core distribution interval of the base library data corresponding to that dimension is determined. Using the core distribution interval of the base library data as a benchmark, the data under the corresponding dimension of the core distribution interval of the base library data in the normalized base library vector is mapped to the first hardware adaptation quantization interval. The first and second identifier points are identifier points that can reflect the core distribution characteristics of the data in the corresponding dimension. Based on the first quantity, second quantity, maximum value, and minimum value in the normalized target vector, the target data core distribution interval corresponding to the normalized target vector is determined. Then, using the target data core distribution interval as a benchmark, the normalized target vector is mapped to the second hardware adaptation quantization interval. The first quantity is the number of elements in the normalized target vector that are greater than or equal to a preset value, and the second quantity is the number of elements in the normalized target vector that are less than the preset value. The core distribution interval of the base database data and the core distribution interval of the target data are collectively referred to as the core data distribution interval. The normalized base database vector and the normalized target vector are collectively referred to as the normalized vector. The first hardware adaptation quantization interval and the second hardware adaptation quantization interval are collectively referred to as the target hardware adaptation quantization interval. Based on the core data distribution range, the normalized vector is mapped to the target hardware adaptation quantization range, including: A refined mapping method is adopted to map the data in the normalized vector that are located within the core data distribution interval to the target hardware adaptation quantization interval. The refined mapping method is a mapping processing method that calculates based on the ratio between the numerical span of the core data distribution interval and the numerical span of the target hardware adaptation quantization interval, so as to maintain the relative positional relationship of the values ​​within the core data distribution interval. A fixed-value mapping method is used to map data in the normalized vector that is outside the core data distribution range to the target hardware adaptation quantization range. The fixed-value mapping method directly maps the data outside the core data distribution range to the target boundary value of the target hardware adaptation quantization range. The target boundary value is the boundary value that is closest to the data to be mapped among the boundary values ​​of the target hardware adaptation quantization range.

2. The method according to claim 1, characterized in that, Based on the first quantity, second quantity, maximum value, and minimum value in the normalized target vector, the core distribution interval of the target data corresponding to the normalized target vector is determined, including: When the first quantity is greater than the second quantity, the maximum value in the normalized target vector is taken as the maximum value of the target data core distribution interval, and the minimum value of the target data core distribution interval is determined according to the ratio of the second quantity to the first quantity and the minimum value in the normalized target vector. When the first quantity is less than the second quantity, the minimum value in the normalized target vector is taken as the minimum value of the target data core distribution interval, and the maximum value of the target data core distribution interval is determined according to the ratio of the first quantity to the second quantity and the maximum value in the normalized target vector. When the first quantity is equal to the second quantity, the minimum and maximum values ​​in the normalized target vector are respectively taken as the minimum and maximum values ​​of the core distribution interval of the target data.

3. The method according to claim 2, characterized in that, Determining the minimum value of the target data core distribution interval based on the ratio of the second quantity to the first quantity and the minimum value in the normalized target vector includes: taking the product of the ratio of the second quantity to the first quantity and the minimum value in the normalized target vector as the minimum value of the target data core distribution interval; and / or, Determining the maximum value of the core distribution interval of the target data based on the ratio of the first quantity to the second quantity and the maximum value in the normalized target vector includes: taking the product of the ratio of the first quantity to the second quantity and the maximum value in the normalized target vector as the maximum value of the core distribution interval of the target data.

4. The method according to claim 1, characterized in that, When both the expanded-dimensional base vector and the expanded-dimensional target vector to be normalized are collectively referred to as the vector to be normalized, the vector to be normalized is normalized based on the mean and standard deviation of each dimension of all expanded-dimensional base vectors to obtain the normalized vector, including: According to the normalization formula, the vector to be normalized is normalized to obtain the normalized vector; The normalization formula includes: ; Among them, the For the i-th data in the dimension to be normalized in the normalized vector, the For the i-th data in the dimension to be normalized in the vector to be normalized, the The mean of the unnormalized dimension of all extended-dimensional base library vectors, the Let be the mean squared error of the dimension to be normalized for all extended-dimensional base vectors.

5. The method according to any one of claims 1-4, characterized in that, The original base vector is used b The original target vector is represented by... a This indicates that the extended-dimensional base vector is used... The expanded dimension target vector is represented by... express; and The dimensions are the same, and and The following relationship must be satisfied:

6. A neural network quantization device based on a memory computing chip, characterized in that, The device includes: The dimension expansion processing unit is used to expand the dimensions of the original base vector and the original target vector based on the equivalent Euclidean distance formula to obtain the expanded base vector and the expanded target vector. The equivalent Euclidean distance formula is a formula converted from the Euclidean distance formula and can replace the Euclidean distance to evaluate the similarity between two vectors. The original base vector and the original target vector are the weight parameters of the neural network model. The normalization unit is used to normalize each of the expanded-dimensional base library vectors based on the mean and standard deviation of each dimension of all expanded-dimensional base library vectors to obtain a normalized base library vector, and to normalize the expanded-dimensional target vector based on the mean and standard deviation of each dimension of all expanded-dimensional base library vectors to obtain a normalized target vector. The sorting unit is used to sort the data under each dimension of all normalized base vectors respectively, and obtain the first and second identifier points in the sorting results of each dimension. The first and second identifier points are identifier points that can reflect the core distribution characteristics of the data in the corresponding dimension. The interval determination unit is used to determine the core distribution interval of the base database data corresponding to each dimension based on the first and second identifier points of each dimension. The mapping unit is used to map the data in the normalized base database vector under the dimension corresponding to the core distribution interval of the base database data to the first hardware adaptation quantization interval, based on the core distribution interval of the base database data. The interval determination unit is further configured to determine the target data core distribution interval corresponding to the normalized target vector based on the first quantity, the second quantity, the maximum value and the minimum value in the normalized target vector, wherein the first quantity is the number of elements in the normalized target vector that are greater than or equal to a preset value, and the second quantity is the number of elements in the normalized target vector that are less than the preset value. The mapping unit is further configured to map the normalized target vector to the second hardware adaptation quantization range based on the target data core distribution range. The core distribution interval of the base database data and the core distribution interval of the target data are collectively referred to as the core data distribution interval. The normalized base database vector and the normalized target vector are collectively referred to as the normalized vector. The first hardware adaptation quantization interval and the second hardware adaptation quantization interval are collectively referred to as the target hardware adaptation quantization interval. The mapping unit includes: The first mapping module is used to map the data in the normalized vector that is located in the core data distribution interval to the target hardware adaptation quantization interval using a refined mapping method. The refined mapping method is a mapping processing method that calculates based on the proportional relationship between the numerical span of the core data distribution interval and the numerical span of the target hardware adaptation quantization interval, so as to maintain the relative positional relationship of the values ​​within the core data distribution interval. The second mapping module is used to map data outside the core data distribution range in the normalized vector to the target hardware adaptation quantization range using a fixed value mapping method. The fixed value mapping method is to directly map the data outside the core data distribution range to the target boundary value of the target hardware adaptation quantization range. The target boundary value is the boundary value closest to the data to be mapped among the boundary values ​​of the target hardware adaptation quantization range.

7. A memory computing chip, characterized in that, The in-memory computing chip is used to implement the method as described in any one of claims 1-5.

8. An electronic device, characterized in that, The electronic device includes one or more in-memory computing chips as described in claim 7.

Citation Information

Patent Citations

  • Quantization parameter determination method, vector retrieval method and device of storage and calculation integrated structure

    CN119046511A

  • Facial recognition method and apparatus, and electronic device and storage medium

    WO2022166532A1