Operator calculation method, device and medium

The operator calculation method addresses the accuracy-performance trade-off in normalization by segmenting data for parallel processing, ensuring accurate and efficient calculation of mean and variance through point-by-point updates.

CN119149239APending Publication Date: 2024-12-17广州壁仞智能科技有限公司 +1
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411440757.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-15
Publication Date
2024-12-17

AI Technical Summary

Technical Problem

Existing normalization techniques in large-scale data processing face a trade-off between calculation accuracy and performance, with two-pass algorithms ensuring accuracy but poor performance, and single-pass algorithms offering high performance but insufficient accuracy due to numerical errors.

Method used

An operator calculation method that divides data into segments and processes them in parallel using multiple threads, updating mean and variance point-by-point to maintain accuracy while utilizing multi-threaded processing capabilities.

Benefits of technology

This method improves calculation efficiency and accuracy by dynamically adjusting mean and variance during data traversal, fully utilizing multi-threaded processing to shorten calculation time and enhance performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119149239A_ABST
    Figure CN119149239A_ABST
Patent Text Reader

Abstract

The invention provides an operator calculation method and device and a medium, and the method comprises the steps: obtaining original data used for operator calculation, dividing the original data into a plurality of data fragments, and distributing the plurality of data fragments to different threads; concurrently controlling each thread to traverse each data point in the distributed data fragment, and updating a mean value and a variance of the traversed data points point by point in the traversing process to obtain a mean value and a variance of the data fragment distributed to each thread; and determining a calculation result of the operator based on the mean value and the variance of each data segment. According to the operator calculation method, the operator calculation equipment and the medium provided by the invention, the calculation efficiency of the mean value and the variance of the original data is remarkably improved through parallel calculation and real-time updating of the data fragments by the threads. And through a point-by-point updating mode, the overall calculation complexity is reduced. Besides, based on the summary of the mean value and variance of each data segment, the statistical characteristics of the whole original data can be accurately reflected, and the precision of the calculation result is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an operator calculation method, device and medium. Background Art

[0002] In large-scale data processing and machine learning, data normalization is an important step to improve model training efficiency and inference performance. Normalization can accelerate model convergence and improve training stability by adjusting the distribution of data. In the process of implementing normalization, it is usually necessary to calculate the mean and variance of the input data.

[0003] At present, the commonly used normalization techniques rely on two main algorithms: the two-pass algorithm and the single-pass algorithm. The two-pass algorithm traverses the data twice, the first time to calculate the mean, and the second time to calculate the variance based on the mean. This method can ensure high calculation accuracy, but because it needs to read and process data multiple times, the performance is poor. The single-pass algorithm calculates the mean and variance at the same time in one traversal, and has higher performance. However, due to the one-time calculation of accumulated data, numerical errors are easily introduced, resulting in insufficient accuracy of variance calculation, especially when processing a large range of data.

[0004] Therefore, how to balance the performance and accuracy of the algorithm in normalization technology is an urgent problem to be solved. Summary of the invention

[0005] The present invention provides an operator calculation method, device and medium, which are used to solve the defect that algorithm accuracy and performance cannot be taken into account in the related art.

[0006] The present invention provides an operator calculation method, comprising the following steps:

[0007] Acquire original data for operator calculation, divide the original data into multiple data segments, and distribute the multiple data segments to different threads;

[0008] Control each thread in parallel to traverse each data point in the assigned data segment, and update the mean and variance of the traversed data points point by point during the traversal process to obtain the mean and variance of the data segment assigned to each thread;

[0009] Based on the mean and variance of each data segment, a calculation result of the operator is determined.

[0010] According to an operator calculation method provided by the present invention, dividing the original data into a plurality of data segments comprises:

[0011] The original data is divided based on the number of available threads to obtain data segments whose number is consistent with the number of available threads.

[0012] According to an operator calculation method provided by the present invention, the parallel control of each thread traverses each data point in the allocated data segment, and updates the mean and variance of the traversed data points point by point during the traversal process, including:

[0013] Each thread is controlled in parallel to traverse each data point in the assigned data segment. During the traversal process, each time a new data point is traversed, the mean is updated based on the value of the new data point, the position of the new data point in the data segment, and the mean of the last update. Also, the variance is updated based on the value of the new data point, the position of the new data point in the data segment, the mean of the last update, the mean of this update, and the variance of the last update.

[0014] According to an operator calculation method provided by the present invention, determining the calculation result of the operator based on the mean and variance of each data segment includes:

[0015] Calculating the mean and variance of the original data based on the mean and variance of each data segment;

[0016] The calculation result of the operator is determined based on the mean and variance of the original data.

[0017] According to an operator calculation method provided by the present invention, the mean and variance of the original data are calculated based on the mean and variance of each data segment, including:

[0018] When there are more than two data segments, group all the data segments into two data segments, and calculate the mean and variance of the merged data segments based on the mean and variance of the two data segments in each group.

[0019] After the grouping and merging is completed, the number of data segments is counted, and if there are more than two data segments, the grouping and merging is returned to continue until there is one data segment after the grouping and merging, and the mean and variance of the one data segment are used as the mean and variance of the original data.

[0020] According to an operator calculation method provided by the present invention, the mean and variance of the merged data segments are calculated based on the mean and variance of the two data segments in each group, including:

[0021] Based on the means and data volume of the two data segments in each group, the mean of the merged data segment is calculated;

[0022] Based on the means, variances and data volumes of the two data segments in each group and the mean of the merged data segment, the variance of the merged data segment is calculated.

[0023] According to an operator calculation method provided by the present invention, the operator is a norm operator.

[0024] The present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, any of the operator calculation methods described above is implemented.

[0025] The present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the computer program implements any of the above-mentioned operator calculation methods.

[0026] The present invention also provides a computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements any of the above-mentioned operator calculation methods.

[0027] The operator calculation method, device and medium provided by the present invention significantly improve the calculation efficiency of the mean and variance of the original data through parallel calculation and real-time update of data fragments by each thread. By updating point by point, each thread can dynamically adjust the mean and variance in the process of traversing the data, thereby reducing the complexity of the overall calculation. In addition, based on the summary of the mean and variance of each data fragment, the statistical characteristics of the entire original data can be accurately reflected, ensuring the accuracy of the calculation results. While maintaining high calculation accuracy, the present invention fully utilizes the multi-threaded parallel processing capability, greatly shortens the calculation time, and improves the calculation performance of the operator. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] In order to more clearly illustrate the technical solutions in the present invention or related technologies, the following briefly introduces the drawings required for use in the embodiments or related technical descriptions. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0029] Figure 1 It is a flowchart of the operator calculation method provided by the present invention.

[0030] Figure 2 It is a structural schematic diagram of the operator computing device provided by the present invention.

[0031] Figure 3 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION

[0032] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0033] In artificial intelligence and machine learning, data normalization is a crucial operation. The purpose of normalization is to adjust the scale of the data so that its mean is 0 and its variance is 1, thereby eliminating the impact of different dimensions between different features. Therefore, quickly and accurately calculating the mean and variance of the data is a key step to ensure the normalization effect.

[0034] Existing normalization methods usually rely on two-pass algorithms and single-pass algorithms to calculate the mean and variance. The two-pass algorithm first performs a first pass through the data to calculate the mean of all data; then, in the second pass, the mean calculated after the first pass is used to calculate the square of the difference between each data point and the mean, and the variance is calculated accordingly. The advantage of this method is that it has high calculation accuracy and can effectively avoid the problem of cumulative errors, especially when processing large amounts of data or data with a large range span, ensuring the accuracy of variance calculation. However, since the two-pass algorithm needs to read and process the data twice, in an environment with limited computing resources or low data transmission bandwidth, the performance of the two-pass algorithm is low, the processing time is long, and the computing power of high-performance hardware cannot be fully utilized.

[0035] In contrast, the single-pass algorithm only needs to traverse the data once to calculate the mean and variance at the same time. The specific operation is: in one traversal process, the total data S = ∑x i And the sum of squares of the data (where x i For each data point) and the number of data points n. After the traversal is completed, the mean μ = S / n can be calculated based on the total data and the number of data points. Based on the simplified variance formula The variance can be calculated based on the sum of squares and mean of the data: σ 2 =S square / n-μ 2. Since the simplified variance formula only needs the sum of squares and the mean, and these two data can be obtained after one traversal, the single-pass algorithm can calculate the mean and variance of the data group with only one data traversal. Compared with the double-pass algorithm, which needs to calculate the square of the difference between each data point and the mean in the second traversal based on the mean calculated after the first traversal to calculate the variance, the advantage of this method is that it improves the calculation efficiency and reduces the number of data readings, especially in the scenario of large-scale data processing or parallel computing, it can significantly improve the performance. However, since the data and the square of the data are accumulated at the same time in one traversal, the accuracy may be reduced, which is mainly due to the rounding error in floating-point operations. When the values ​​in the accumulated data differ greatly, the smaller value may be ignored or discarded when accumulated with the larger value due to the limited precision of the floating-point number, resulting in the gradual accumulation of errors. In particular, in the process of accumulating the square of the data, the value is further amplified, the difference between the larger value and the smaller value is more obvious, and the impact of the rounding error is also aggravated. In addition, the variance calculation formula used in the single-pass algorithm itself also has numerical instability. Especially when the sum of the squares of the data is close to the square of the total, subtracting two large numbers will amplify small errors and lead to inaccurate calculations. This phenomenon is more obvious in scenarios with a large data value range, because larger values ​​will cause smaller values ​​to be ignored when representing floating-point numbers, and the square operation will further amplify these numerical differences, leading to increased rounding errors and cumulative errors, which will reduce the accuracy of variance calculations.

[0036] It can be found that the two-pass algorithm has obvious advantages in accuracy, but its performance is poor; while the single-pass algorithm has high performance, but has the problem of insufficient accuracy. Therefore, how to balance the performance and accuracy of calculating the mean and variance is the key issue to improve the normalization effect.

[0037] In view of the above problems, an embodiment of the present invention provides an operator calculation method. Figure 1 is a flow chart of the operator calculation method provided by the present invention, such as Figure 1 As shown, the method includes:

[0038] Step 110: obtain original data for operator calculation, divide the original data into multiple data segments, and distribute the multiple data segments to different threads.

[0039] Specifically, raw data refers to the input data used for operator calculations, which is the basis for subsequent data processing and calculations. The type and structure of raw data may vary depending on different application scenarios. For example, in the field of machine learning and artificial intelligence, raw data may include various data sets used for model training and reasoning, such as image data, text data, time series data, audio data, etc. These data are usually large in scale, and direct calculations may bring a large computational load. Therefore, it is necessary to reasonably divide the raw data for subsequent efficient processing.

[0040] In the embodiment of the present invention, the operator used for calculating the original data may be any operator that needs to calculate the mean and variance of the original data to implement the calculation, for example, it may be a norm operator (ie, a Norm-type operator) used for normalization.

[0041] Data fragments are smaller-scale data blocks obtained by dividing the original data. The division rules can be formulated according to the characteristics of the data and the specific computing requirements. The division method of the data fragments includes but is not limited to segmentation by rows, columns or blocks. The specific division basis can be the dimension of the data, the parallelization requirement of the calculation, etc., which is not limited in the embodiment of the present invention. For example, for matrix or multi-dimensional array type data, it can be divided into multiple small data fragments according to rows or columns, and each data fragment independently calculates the mean and variance. In this way, the original data is decomposed into multiple small-scale data units that can be processed independently, that is, multiple data fragments are obtained.

[0042] When multiple data fragments are obtained, they need to be assigned to different threads. Each thread will be responsible for processing one data fragment and performing corresponding calculations in parallel and independently based on the assigned data fragments. Through this allocation method, high-performance computing resources such as multi-core processors or graphics processors can be fully utilized to greatly improve the overall computing efficiency. In the process of allocating data fragments, it is necessary to comprehensively consider the size of the data fragments, the complexity of the task, and the current load of the thread to ensure that the workload between the threads is balanced and avoid the situation where some threads are overloaded or idle. This parallel processing mechanism effectively improves the performance and processing power of operator calculations and significantly shortens the calculation time.

[0043] Step 120 , controlling each thread in parallel to traverse each data point in the allocated data segment, updating the mean and variance of the traversed data points point by point during the traversal process, and obtaining the mean and variance of the data segment allocated to each thread.

[0044] Specifically, each thread traverses the data fragments assigned to it in parallel, and calculates and updates the mean and variance of these data point by point. Threads run independently and do not depend on each other, avoiding mutual interference and resource competition during data processing. This parallel control mechanism ensures efficient computing in a multi-threaded environment. Each thread can focus on the data fragment it is responsible for without waiting for the results of other threads, thereby maximizing the use of computing resources. The entire computing process is highly parallel, and the computing tasks between threads are isolated from each other. There will be no competition or blocking during traversal, ensuring the overall computing fluency and efficiency.

[0045] For any thread, during the traversal process, the thread can dynamically update the mean and variance of all data points that have been traversed in the data segment. For example, the Welford algorithm can be used to update the mean and variance during the traversal process. The thread does not calculate the mean and variance once after the traversal is completed. Instead, each time a data point in the data segment is traversed, the mean and variance of the traversed data points are dynamically adjusted according to the value of the data point. Each thread will adjust its calculated mean and variance in real time through this point-by-point update method, ensuring that these statistics gradually approach the final result, that is, the mean and variance of the complete data segment, as the data traversal progresses.

[0046] Specifically, during the point-by-point update process, the thread adjusts the existing mean and variance according to the value of each new data point. Compared with the double-pass algorithm, which requires a traversal to calculate the mean first and then calculate the variance in the second traversal, this point-by-point update method uses the recursive formula and other methods to dynamically update the mean and variance during the traversal process, so the calculation can be completed in one traversal, which greatly improves efficiency. In addition, this point-by-point update avoids the numerical instability of subtracting large numbers by gradually correcting the mean and variance, and adjusts the statistics only according to the current data point at each step to prevent rounding errors caused by the accumulation of a large amount of data. When processing data with a large range or significant differences in magnitude, the rounding error of floating-point operations is particularly obvious. However, the point-by-point update only adjusts the deviation between the current data point and the previous result at each step. This local update method will not cause error accumulation due to the mixture of large and small numbers, so it can better maintain numerical accuracy when processing data with a large range.

[0047] Step 130: Determine the calculation result of the operator based on the mean and variance of each data segment.

[0048] Specifically, after processing the assigned data fragment, each thread obtains the mean and variance for the assigned data fragment. The mean and variance for the data fragment at each thread represent the data characteristics of the data fragment of each thread, but are not enough to reflect the overall characteristics of the entire original data. Therefore, the mean and variance of the data fragment calculated by each thread must be summarized to obtain the global mean and variance of the original data.

[0049] During the aggregation process, the calculation results of each data segment contribute to the global calculation results. The mean and variance of the data segments are aggregated to obtain the mean and variance of the entire original data. This step ensures that no matter how the data is fragmented, the final global calculation result can accurately reflect the mean and variance of the entire original data. The final calculation result of the operator is determined by these global calculation results, which can provide a reliable foundation for subsequent model training, reasoning or other data processing tasks.

[0050] The operator calculation method provided by the embodiment of the present invention divides the original data into multiple data segments, and based on the parallel calculation and real-time update of the data segments by each thread, significantly improves the calculation efficiency of the mean and variance of the original data. In addition, in the calculation process of the mean and variance of the data segments, each thread can dynamically adjust the mean and variance in the process of traversing the data by updating point by point, thereby improving the calculation efficiency and calculation accuracy of the mean and variance of the data segments. In addition, summarizing the mean and variance of each data segment can accurately reflect the mean and variance of the entire original data, ensuring the accuracy of the operator calculation results. While maintaining high calculation accuracy, the present invention makes full use of the multi-threaded parallel processing capability, greatly shortens the calculation time, and improves the calculation performance of the operator.

[0051] Based on the above embodiment, in step 110, dividing the original data into a plurality of data segments includes:

[0052] The original data is divided based on the number of available threads to obtain data segments whose number is consistent with the number of available threads.

[0053] Specifically, available threads are threads that can be called when performing operator calculations. Keeping the number of data segments after division consistent with the number of available threads is intended to fully utilize all available computing resources, ensure that all available threads participate in data processing, and avoid idle thread resources. This design maximizes the efficiency of parallel computing, and all available threads can run simultaneously, improving overall computing efficiency.

[0054] It should be noted that the embodiment of the present invention does not restrict the size of each data segment after segmentation, that is, the size of the data segments is allowed to be different. This flexible segmentation method allows the original data to be segmented according to actual conditions. Although the sizes of the data segments are different, each thread can still process the assigned data segments independently without affecting the execution of the overall parallel computing. At the same time, it also avoids the additional computational complexity introduced to force the data segments to be balanced, and maintains the simplicity and flexibility of the original data segmentation process.

[0055] Based on the above embodiment, in step 120, the parallel control of each thread traverses each data point in the allocated data segment, and updates the mean and variance of the traversed data points point by point during the traversal process, including:

[0056] Each thread is controlled in parallel to traverse each data point in the assigned data segment. During the traversal process, each time a new data point is traversed, the mean is updated based on the value of the new data point, the position of the new data point in the data segment, and the mean of the last update. Also, the variance is updated based on the value of the new data point, the position of the new data point in the data segment, the mean of the last update, the mean of this update, and the variance of the last update.

[0057] The parallel control mechanism is used to coordinate multiple threads to traverse their assigned data fragments simultaneously. Each thread processes the assigned data fragment independently, without dependencies between each other, thus avoiding competition and waiting for computing resources and making the most of the computing power of multiple threads. Under the protection of the parallel control mechanism, all threads can run simultaneously and traverse the data points in their data fragments.

[0058] Specifically, during the traversal process, each thread can use a suitable algorithm to update the mean and variance of the data segment point by point. As an algorithm that can be considered, the Welford algorithm provides an efficient solution for dynamically calculating the mean and variance during the traversal process. The Welford algorithm uses a recursive formula to instantly update the current mean and variance when processing each new data point, without having to wait for the entire traversal to complete before performing the overall calculation.

[0059] Specifically, when each thread traverses its assigned data segment, each time it processes a new data point, it will calculate based on the value of the data point and the currently processed data. The update of the mean is based on the new data point value, the position of the new data point in the data segment, and the last calculated mean. Each data point, whether expressed in the form of a floating point number or an integer, has its value. Its value directly participates in the update of the mean. When the new data point value is greater than the last calculated mean, it increases the current mean; when the new data point value is less than the last calculated mean, it decreases the current mean; when the new data point value is equal to the last calculated mean, the updated current mean is equal to the last calculated mean. The position of the new data point in the data segment, that is, the index of the new data point in the data segment, determines which data point it is processed. When recursively updating the mean, as the position of the data point increases (that is, the total number of data points that have been processed increases), the impact of each new data point on the mean will gradually decrease. The data points at the front have a greater impact on the mean. This is because when calculating the mean, the contribution of each new data point is introduced into the mean by a gradually decreasing coefficient (such as 1 / k, where k is the index of the new data point in the data segment). The current mean is updated based on the last mean. The last updated mean was the mean result when processing the previous data point. The addition of new data points only corrects the current mean.

[0060] The update of variance is more complicated than the mean because the update of variance depends not only on the current data point, but also on how the new data point affects the overall distribution. The value of the new data point, the position of the new data point in the data segment, the mean of the last update, the mean of this update, and the variance of the last update all play a key role in the update of variance. Specifically, similar to the mean update, the update of variance is also directly affected by the value of the data point. The variance reflects the degree of dispersion of the data point from the mean, so the greater the difference between the data point and the mean of this update, the greater its contribution to the variance. Similarly, the position of the new data point determines which data point is processed. As the total amount of processed data points increases, the update of variance will also be affected by the amount of data. The contribution of each new data point to the variance gradually decreases. The mean of the last update plays an important role in the variance calculation. It reflects the central tendency of the previous data, so the difference between the new data point and the last mean will be used to determine how the data point affects the current variance. The larger the difference, the more obvious the increase in variance; the smaller the difference, the smaller the change in variance. When a new data point is processed, the mean is updated immediately, while the variance needs to be updated by considering the difference between the updated mean and the last updated mean. The new mean represents the central tendency of the current data set, so the final contribution of the current data point to the variance needs to be judged based on the new mean. The greater the difference from the new mean, the more significant the change in variance. The variance from the last update is a reflection of the gap between all the data points that have been processed. As each new data point is processed, the current variance is adjusted based on the last update. The recursive formula introduces new data points into the calculation of the variance while retaining the influence of the processed data.

[0061] Taking the Welford algorithm as an example, the formula for updating the mean of the algorithm is:

[0062]

[0063] in, is the mean of the last update, x n is the value of the new data point, and n is the total number of data points that have been processed or are being processed. This recursive formula shows that the difference between the new data point and the last updated mean directly affects the size of the updated mean. The position of the new data point, that is, the larger the index n, the smaller the impact of the new data point on the updated mean.

[0064] The formula for updating the variance of the Welford algorithm is:

[0065]

[0066] in, is the variance obtained after this update, is the variance of the last update, x nis the value of the new data point, is the mean of the last update, is the mean of this update, and n is the total number of data points that have been processed or are being processed. This formula shows that the variance depends not only on the value of the new data point and the variance of the last update, but also on the difference between the data point and the last updated mean and the current mean, as well as the position of the new data point, thus ensuring that the variance can accurately reflect the discreteness of the data.

[0067] Based on the above embodiment, in step 130, determining the calculation result of the operator based on the mean and variance of each data segment includes:

[0068] Calculating the mean and variance of the original data based on the mean and variance of each data segment;

[0069] The calculation result of the operator is determined based on the mean and variance of the original data.

[0070] After each thread completes the mean and variance calculation of its data fragment, it is necessary to aggregate these local results to obtain the global mean and variance of the original data. The mean and variance of each data fragment only represent the local characteristics of the data fragment. Therefore, by weighted combination of the results of each data fragment, the accurate mean and variance of the entire original data can be obtained.

[0071] Specifically, the global mean of the original data is calculated by weighting the means of each data segment by the amount of data in each data segment. The amount of data in each data segment is different, and its weight in the global mean is also different, ensuring that the contribution of each data segment to the overall mean matches its data amount. The calculation of the global variance is more complicated, not only needing to summarize the variance of each data segment, but also considering the difference between the mean of each data segment and the global mean, to ensure that the calculation result can reflect the actual fluctuation of the entire data set.

[0072] Taking the combination of two data fragments of two threads as an example, the combined mean is the weighted sum of the means of each data fragment according to the data volume, and the formula is:

[0073] n AB =n A +n B

[0074]

[0075] Among them, n A 、n B Respectively represent the amount of data in the two data fragments, n AB Represents the total amount of data in two data fragments, represent the means of these two data segments, respectively. Represents the global mean of the combined data. By weighting, it ensures that the contribution of each data segment to the global mean is proportional to its data volume.

[0076] The variance calculation after combination not only needs to combine the variance of each data segment, but also needs to consider the deviation between the mean of each data segment and the combined mean. The formula is:

[0077]

[0078] in, is the global variance after combining the data segments. and are the variances of the two data segments respectively. This formula not only integrates the variances of each data segment, but also considers the difference between the mean of the data segment and the global mean, ensuring the accuracy of the global variance.

[0079] In order to efficiently realize the aggregation of the calculation data of each thread, the hardware characteristics of the artificial intelligence chip can be used to realize the data exchange and merging between threads to complete the final calculation of the mean and variance. If the threads are in the same warp, the Shuffle instruction can be used to exchange and merge data within the warp. If the threads are in the same thread block, the data is exchanged through shared memory. For the data exchange between threads in different thread blocks, the global memory is used. In the parallel computing process, these hardware optimization methods can be combined. For example, after each thread completes its own part of the data processing, the Shuffle instruction is first used to merge the data between threads in the warp, and then the shared memory is used to exchange and merge the data between the threads in the same thread block, and finally the global memory is used to merge the data between different thread blocks. In this step-by-step aggregation method, the global mean and variance are calculated. This parallel aggregation mechanism can make full use of the multi-threaded architecture and hardware acceleration characteristics, significantly improve the computing efficiency, and ultimately ensure the accuracy of the global mean and variance.

[0080] After the mean and variance of each data segment are summarized, the mean and variance of the entire original data can be obtained. Based on the mean and variance of the entire original data, a certain calculation or transformation is performed to obtain the final result of the operator. The calculation result of the operator can be a certain standardization, normalization or other transformation operation of the original data, which is not limited in the present invention.

[0081] Based on the above embodiment, the step of calculating the mean and variance of the original data based on the mean and variance of each data segment includes:

[0082] When there are more than two data segments, group all the data segments into two data segments, and calculate the mean and variance of the merged data segments based on the mean and variance of the two data segments in each group.

[0083] After the grouping and merging is completed, the number of data segments is counted, and if there are more than two data segments, the grouping and merging is returned to continue until there is one data segment after the grouping and merging, and the mean and variance of the one data segment are used as the mean and variance of the original data.

[0084] For more than two data segments, the mean and variance of the original data are calculated by grouping and merging. Specifically, all data segments are grouped according to the rule of two data segments as a group, and the mean and variance of the merged data segments are calculated based on the mean and variance of the two data segments in each group.

[0085] In each round of grouping and merging, the data of every two data fragments are merged into a new data fragment by, for example, weighting, and the mean and variance of the merged data fragments are calculated. After each round of grouping and merging, if there are still more than two data fragments left, a new round of grouping and merging will be performed on the remaining data fragments in the same way. After each grouping and merging, the number of data fragments will decrease until only one data fragment remains. When the grouping and merging process is completed, the mean and variance of the last remaining data fragment represent the mean and variance of the original data. These means and variances will be used in subsequent steps as the key basis for determining the calculation results of the operator.

[0086] For example, suppose there are 8 data segments, S1 to S8. In the first round of merging, these 8 data segments are grouped in pairs, namely S1 and S2, S3 and S4, S5 and S6, S7 and S8. For each group, their merged mean and variance are calculated to obtain 4 new data segments S 12 , S 34 , S 56 and S 78 Next, continue to group these 4 segments again, such as S 12 and S 34 , S 56 and S 78 , and the mean and variance after merging are calculated in the same way. Through this round of grouping and merging, the data segments are reduced to 2, S 1234 and S 5678 Finally, these two fragments S 1234 and S 5678 Perform the final merge and calculate the overall mean and variance of the original data.

[0087] This grouping and merging method ensures that the data can be efficiently and accurately integrated in the case of multi-threaded parallel processing, and the mean and variance of the original data can be calculated step by step. By recursively merging data fragments, the global mean and variance of the original data can be obtained in fewer calculation steps.

[0088] Based on the above embodiment, the step of calculating the mean and variance of the merged data segments based on the mean and variance of the two data segments in each group includes:

[0089] Based on the means and data volume of the two data segments in each group, the mean of the merged data segment is calculated;

[0090] Based on the means, variances and data volumes of the two data segments in each group and the mean of the merged data segment, the variance of the merged data segment is calculated.

[0091] Specifically, for each set of two data segments, their mean and data volume are used to calculate the mean of the merged data segment. This merging calculation is achieved by weighted average. For two sets of data segments A and B, the data volume of data segment A and data segment B is n respectively. A and n B , whose means are and When merging these two data segments, the calculation formulas for the combined mean and variance are:

[0092] n AB =n A +n B

[0093]

[0094] In this formula, the mean of each data segment is weighted by its data volume. Data segments with large data volumes have a greater impact on the combined mean, ensuring that data segments with larger samples are not overly affected by the mean of smaller sample data segments.

[0095] The calculation of the variance of the merged data segments is relatively complicated. It not only needs to be calculated based on the variance and data volume of each data segment, but also needs to consider the mean of each data segment and the mean of the merged data segment. Specifically, when calculating the merged variance, the merged mean reflects the fluctuation of the data segment through the difference between the mean of each data segment and the merged mean. The greater the difference, the greater the variance after the merger. The closer the mean of each data segment is to the weighted mean after the merger, the smaller its impact on the variance. The larger the gap, the greater the variance, ensuring that the overall discreteness of the data is accurately reflected. Assume that the variances of data segments A and B are respectively and The variance of the merged data segment The calculation formula is:

[0096]

[0097] In this formula, the combined variance depends not only on the variance of data segments A and B, but also on the variance of and It also relies on the difference between the means of the two data segments and the mean of the merged data segment.

[0098] Based on the above embodiment, the operator is a norm operator.

[0099] The norm operator is used to standardize the original data so that the data maintains a uniform scale during the calculation process. The core of the norm operator algorithm is to normalize the mean and variance of the original data to eliminate the scale differences between different dimensions of the data. Specifically, the formula for the standardization calculation process of the norm operator is:

[0100]

[0101] Among them, x i represents a data point in the original data, μ is the mean of the original data, σ 2 is the variance of the original data, which reflects the degree of discreteness of the original data. In order to prevent the extremely small variance from causing unstable calculations, a very small positive number ε is introduced into the formula to ensure the numerical stability of the calculation process. Finally, Represents the normalized data points.

[0102] Through this normalization operation, each data point x i The mean μ will be subtracted first to centralize the data, and then divided by the standard deviation The data is unified in scale, thus eliminating the differences between different feature dimensions. This norm operator standardization process can ensure the balance of data distribution and improve the stability and accuracy of the computational model when processing data of different ranges and distributions.

[0103] Norm operators are widely used in all aspects of machine learning and deep learning, especially in model training. Standardized data helps improve the convergence speed and accuracy of the model and avoid training difficulties caused by uneven data distribution. Therefore, based on the mean and variance of the original data, the norm operator can convert the data into a standardized form that is easier to handle, making it more efficient and accurate in subsequent calculations.

[0104] It should be noted that the operator calculation methods provided by the above embodiments of the present invention, especially the efficient calculation of mean and variance, can be applied to various models on artificial intelligence chips, such as different types of data processing tasks such as speech, image, text, video, etc. The scenarios to which the various embodiments of the present invention are applicable depend on the specific requirements of the operator calculation methods in the present invention in these models.

[0105] Specifically, for speech processing models such as speech recognition and speech synthesis, the operator calculation method of the present invention can be used for standardized processing of speech data, and the mean and variance of speech data can be calculated to ensure the balance of data input, thereby improving the effect and performance of model training. In addition, the calculation of mean and variance can also be used for speech feature extraction and model evaluation, ensuring the accuracy and efficiency of artificial intelligence chips in processing speech tasks.

[0106] In computer vision models such as image classification, target detection, and image segmentation, the operator calculation method of the present invention can be applied to tasks such as image standardization and feature extraction. For example, a standardization operation is performed before image processing to eliminate scale differences between different image data, thereby improving the training speed and performance of the model. In addition, the calculation of mean and variance can be used to construct local features of the image, such as texture and brightness changes, to support the model's more accurate understanding of the image.

[0107] The operator calculation device provided by the present invention is described below. The operator calculation device described below and the operator calculation method described above can be referenced to each other.

[0108] Figure 2 is a schematic diagram of the structure of the operator computing device provided by the present invention, such as Figure 2 As shown, the device comprises:

[0109] The original data partitioning unit 210 is used to obtain original data for operator calculation, partition the original data into multiple data segments, and distribute the multiple data segments to different threads.

[0110] The data segment parallel computing unit 220 is used to control each thread in parallel to traverse each data point in the assigned data segment, and update the mean and variance of the traversed data points point by point during the traversal process to obtain the mean and variance of the data segment assigned to each thread.

[0111] The calculation result summarizing unit 230 determines the calculation result of the operator based on the mean and variance of each data segment.

[0112] The operator computing device provided by the present invention significantly improves the computing efficiency of the mean and variance of the original data based on the parallel computing and real-time updating of data fragments by each thread. By updating point by point, each thread can dynamically adjust the mean and variance in the process of traversing the data, thereby reducing the complexity of the overall calculation. In addition, based on the summary of the mean and variance of each data fragment, the statistical characteristics of the entire original data can be accurately reflected, ensuring the accuracy of the calculation results. While maintaining high calculation accuracy, the present invention fully utilizes the multi-threaded parallel processing capability, greatly shortens the calculation time, and improves the calculation performance of the operator.

[0113] Based on any of the above embodiments, the original data division unit is specifically used for:

[0114] The original data is divided based on the number of available threads to obtain data segments whose number is consistent with the number of available threads.

[0115] Based on any of the above embodiments, the data segment parallel computing unit is specifically used for:

[0116] Each thread is controlled in parallel to traverse each data point in the assigned data segment. During the traversal process, each time a new data point is traversed, the mean is updated based on the value of the new data point, the position of the new data point in the data segment, and the mean of the last update. Also, the variance is updated based on the value of the new data point, the position of the new data point in the data segment, the mean of the last update, the mean of this update, and the variance of the last update.

[0117] Based on any of the above embodiments, the calculation result summary unit is specifically used for:

[0118] Calculating the mean and variance of the original data based on the mean and variance of each data segment;

[0119] The calculation result of the operator is determined based on the mean and variance of the original data.

[0120] When there are more than two data segments, group all the data segments into two data segments, and calculate the mean and variance of the merged data segments based on the mean and variance of the two data segments in each group.

[0121] After the grouping and merging is completed, the number of data segments is counted, and if there are more than two data segments, the grouping and merging is returned to continue until there is one data segment after the grouping and merging, and the mean and variance of the one data segment are used as the mean and variance of the original data.

[0122] Based on the means and data volume of the two data segments in each group, the mean of the merged data segment is calculated;

[0123] Based on the means, variances and data volumes of the two data segments in each group and the mean of the merged data segment, the variance of the merged data segment is calculated.

[0124] The operator is a norm operator.

[0125] Figure 3 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 3 As shown, the electronic device may include: a processor 310, a communication interface 320, a memory 330 and a communication bus 340, wherein the processor 310, the communication interface 320 and the memory 330 communicate with each other through the communication bus 340. The processor 310 may call the logic instructions in the memory 330 to execute the operator calculation method, which includes:

[0126] Acquire original data for operator calculation, divide the original data into multiple data segments, and distribute the multiple data segments to different threads;

[0127] Control each thread in parallel to traverse each data point in the assigned data segment, and update the mean and variance of the traversed data points point by point during the traversal process to obtain the mean and variance of the data segment assigned to each thread;

[0128] Based on the mean and variance of each data segment, a calculation result of the operator is determined.

[0129] In addition, the logic instructions in the above-mentioned memory 330 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the relevant technology or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.

[0130] On the other hand, the present invention further provides a computer program product, the computer program product comprising a computer program, the computer program can be stored on a non-transitory computer-readable storage medium, when the computer program is executed by a processor, the computer can execute the operator calculation method provided by the above methods, the method comprising:

[0131] Acquire original data for operator calculation, divide the original data into multiple data segments, and distribute the multiple data segments to different threads;

[0132] Control each thread in parallel to traverse each data point in the assigned data segment, and update the mean and variance of the traversed data points point by point during the traversal process to obtain the mean and variance of the data segment assigned to each thread;

[0133] Based on the mean and variance of each data segment, a calculation result of the operator is determined.

[0134] In another aspect, the present invention further provides a non-transitory computer-readable storage medium having a computer program stored thereon, which is implemented when the computer program is executed by a processor to perform the operator calculation method provided by the above methods, the method comprising:

[0135] Acquire original data for operator calculation, divide the original data into multiple data segments, and distribute the multiple data segments to different threads;

[0136] Control each thread in parallel to traverse each data point in the assigned data segment, and update the mean and variance of the traversed data points point by point during the traversal process to obtain the mean and variance of the data segment assigned to each thread;

[0137] Based on the mean and variance of each data segment, a calculation result of the operator is determined.

[0138] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.

[0139] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution can be essentially or in other words, the part that contributes to the relevant technology can be embodied in the form of a software product, which can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiment.

[0140] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. An operator calculation method, It is characterized in that include: Acquire original data for operator calculation, divide the original data into multiple data segments, and distribute the multiple data segments to different threads; Control each thread in parallel to traverse each data point in the assigned data segment, and update the mean and variance of the traversed data points point by point during the traversal process to obtain the mean and variance of the data segment assigned to each thread; Based on the mean and variance of each data segment, a calculation result of the operator is determined.

2. The operator calculation method according to claim 1, It is characterized in that The step of dividing the original data into a plurality of data segments comprises: The original data is divided based on the number of available threads to obtain data segments whose number is consistent with the number of available threads.

3. The operator calculation method according to claim 1, It is characterized in that The parallel control of each thread traversing each data point in the allocated data segment, and updating the mean and variance of the traversed data points point by point during the traversal process, includes: Each thread is controlled in parallel to traverse each data point in the assigned data segment. During the traversal process, each time a new data point is traversed, the mean is updated based on the value of the new data point, the position of the new data point in the data segment, and the mean of the last update. Also, the variance is updated based on the value of the new data point, the position of the new data point in the data segment, the mean of the last update, the mean of this update, and the variance of the last update.

4. The operator calculation method according to claim 1, It is characterized in that The step of determining the calculation result of the operator based on the mean and variance of each data segment includes: Calculating the mean and variance of the original data based on the mean and variance of each data segment; The calculation result of the operator is determined based on the mean and variance of the original data.

5. The operator calculation method according to claim 4, It is characterized in that The calculating the mean and variance of the original data based on the mean and variance of each data segment includes: When there are more than two data segments, group all the data segments into two data segments, and calculate the mean and variance of the merged data segments based on the mean and variance of the two data segments in each group. After the grouping and merging is completed, the number of data segments is counted, and if there are more than two data segments, the grouping and merging is returned to continue until there is one data segment after the grouping and merging, and the mean and variance of the one data segment are used as the mean and variance of the original data.

6. The operator calculation method according to claim 5, It is characterized in that The calculating the mean and variance of the merged data segments based on the mean and variance of the two data segments in each group includes: Based on the means and data volume of the two data segments in each group, the mean of the merged data segment is calculated; Based on the means, variances and data volumes of the two data segments in each group and the mean of the merged data segment, the variance of the merged data segment is calculated.

7. The operator calculation method according to any one of claims 1 to 6, It is characterized in that The operator is a norm operator.

8. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, It is characterized in that When the processor executes the program, the operator calculation method according to any one of claims 1 to 7 is implemented.

9. A non-transitory computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the operator calculation method according to any one of claims 1 to 7 is implemented.

10. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the operator calculation method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Operator calculation method, electronic equipment and storage medium

    CN121052300A