Floating point operator error evaluation method and device, electronic equipment and storage medium
By using the target comprehensive error in the floating-point operator error evaluation to evaluate the error accuracy of the floating-point operator, the problem of inaccurate and complex error evaluation in the existing technology is solved, and a more stable and efficient error evaluation is achieved.
Patent Information
- Application Number
- CN202410759227.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-12
- Publication Date
- 2024-09-10
Smart Images

Figure CN118626044A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to a floating-point operator error evaluation method, device, electronic equipment and storage medium. Background Art
[0002] With the continuous development and progress of artificial intelligence (AI) technology, AI devices have emerged, such as electronic devices that integrate hardware chips such as graphics processing units (GPUs) and neural processing units (NPUs). The AI devices can use the above processors to perform various computing tasks and implement neural network training and reasoning. The error accuracy level of the operators that implement the corresponding operations of GPUs and NPUs will affect the accuracy of training and reasoning results. Therefore, it is particularly important to evaluate the error accuracy level of the operators of GPUs and NPUs.
[0003] In the related art, the absolute error results and relative error results between the output tensors of the floating-point operators and the reference operators that implement high-performance floating-point operations on the GPU or NPU are usually calculated simultaneously, and the error accuracy level of the floating-point operators is evaluated using the average absolute error and the maximum absolute error of the absolute error results, or the error accuracy level of the floating-point operators is evaluated using the average relative error and the maximum relative error of the relative error results.
[0004] However, when the absolute value of the actual value in the floating-point operator output tensor and the absolute value of the reference value in the reference operator output tensor are both large or small, the corresponding absolute error and relative error lack consistency. This situation easily affects the evaluation results of the actual error situation of the floating-point operator, resulting in low accuracy in the quantitative evaluation of the floating operator error. Summary of the invention
[0005] The present invention provides a floating-point operator error evaluation method, device, electronic device and storage medium, which are used to solve the defect of low accuracy in quantitative evaluation of floating-point operator errors in the prior art, improve the accuracy of rapid quantitative evaluation of floating-point operator errors, ensure that floating-point operator error evaluation is more stable and effective, and also greatly reduce the complexity of quantitative evaluation of floating-point operator errors and the workload of floating-point operator precision alignment.
[0006] The present invention provides a floating point operator error evaluation method, comprising the following steps.
[0007] Get the target actual tensor corresponding to the floating-point operator to be evaluated and the target reference tensor corresponding to the preset reference operator; Performing a relative error operation based on an absolute error result between the target actual tensor and the target reference tensor, the target reference tensor, and a preset absolute error threshold and a preset relative error threshold to determine a target comprehensive error between the target actual tensor and the target reference tensor; Based on the target comprehensive error, an error evaluation result of the floating-point operator to be evaluated is determined; the error evaluation result is used to evaluate whether the accuracy level of the floating-point operator to be evaluated meets the accuracy requirement.
[0008] According to a floating-point operator error evaluation method provided by the present invention, the relative error operation is performed based on the absolute error result between the target actual tensor and the target reference tensor, the target reference tensor, and a preset absolute error threshold and a preset relative error threshold to determine the target comprehensive error between the target actual tensor and the target reference tensor, including: Performing a relative error operation on each absolute error in the absolute error result and a target absolute value of each target reference value in the target reference tensor, and a first ratio of the preset absolute error threshold and the preset relative error threshold to determine an initial comprehensive error result between the target actual tensor and the target reference tensor; Based on the initial comprehensive error result, a maximum comprehensive error between the target actual tensor and the target reference tensor is determined, and the target comprehensive error is determined based on the maximum comprehensive error.
[0009] According to a floating-point operator error evaluation method provided by the present invention, performing relative error operation on each absolute error in the absolute error result and the target absolute value of each target reference value in the target reference tensor, and a first ratio of the preset absolute error threshold and the preset relative error threshold to determine an initial comprehensive error result between the target actual tensor and the target reference tensor, including: Determine the sum of each of the target absolute values and the first ratio; A second ratio between each absolute error in the absolute error result and the corresponding addition result is calculated, and the initial comprehensive error result is obtained based on each second ratio.
[0010] According to a floating-point operator error evaluation method provided by the present invention, determining the target comprehensive error based on the maximum comprehensive error includes: determining an average combined error between the target actual tensor and the target reference tensor; At least one of the average comprehensive error and the maximum comprehensive error is determined as the target comprehensive error.
[0011] According to a floating-point operator error evaluation method provided by the present invention, determining the average comprehensive error between the target actual tensor and the target reference tensor includes: Determine a comprehensive error accumulation result corresponding to all initial comprehensive errors in the initial comprehensive error result; The ratio of the accumulated result of the comprehensive error to a preset number is determined as the average comprehensive error; the preset number is the total number of target actual values contained in the target actual tensor or the total number of target reference values contained in the target reference tensor.
[0012] According to a floating-point operator error evaluation method provided by the present invention, the method further includes: Determining a target floating-point data type of the floating-point operator to be evaluated; Based on a preconfigured mapping relationship between floating-point data type-absolute error threshold-relative error threshold, the preset absolute error threshold and the preset relative error threshold matching the target floating-point data type are determined.
[0013] According to a floating-point operator error evaluation method provided by the present invention, the step of obtaining a target actual tensor corresponding to a floating-point operator to be evaluated and a target reference tensor corresponding to a preset reference operator includes: In response to a floating-point operator precision test instruction input by a user, the floating-point operator to be evaluated and the preset reference operator are controlled to respectively operate on the input tensor to be tested, so as to obtain the target actual tensor and the target reference tensor.
[0014] The present invention also provides a floating point operator error evaluation device, comprising the following units: An operator tensor acquisition unit, used to acquire a target actual tensor corresponding to the floating-point operator to be evaluated and a target reference tensor corresponding to a preset reference operator; a comprehensive error determination unit, configured to perform a relative error operation based on an absolute error result between the target actual tensor and the target reference tensor, the target reference tensor, and a preset absolute error threshold and a preset relative error threshold to determine a target comprehensive error between the target actual tensor and the target reference tensor; The operator error evaluation unit is used to determine the error evaluation result of the floating-point operator to be evaluated based on the target comprehensive error; the error evaluation result is used to evaluate whether the accuracy level of the floating-point operator to be evaluated meets the accuracy requirement.
[0015] 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 above floating-point operator error evaluation methods is implemented.
[0016] The present invention also provides a non-transitory computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the floating-point operator error evaluation method described in any one of the above is implemented.
[0017] The present invention provides a floating-point operator error evaluation method, device, electronic device and storage medium, wherein the floating-point operator error evaluation method, the processor in the AI device first performs relative error calculation based on the absolute error result between the target actual tensor corresponding to the floating-point operator to be evaluated and the target reference tensor corresponding to the preset reference operator, the target reference tensor, and the preset absolute error threshold and the preset relative error threshold, and determines the target comprehensive error between the target actual tensor and the target reference tensor, and then further determines the error evaluation result used to evaluate whether the precision level of the floating-point operator to be evaluated meets the precision requirement based on the target comprehensive error. In this way, by comprehensively considering the absolute error, relative error, absolute error threshold and relative error threshold, the single value of the comprehensive error proposed to quantitatively evaluate the floating-point operator error is ensured to ensure that the comprehensive error has good consistency when the absolute values of the reference value and the actual value are both large or small, and can also more truly and accurately reflect the floating-point error situation, which not only improves the accuracy of the rapid quantitative evaluation of the floating-point operator error, and ensures that the floating-point operator error evaluation is more stable and effective, but also greatly reduces the complexity of the quantitative evaluation of the floating-point operator error and the workload of the floating-point operator precision alignment. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. 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.
[0019] Figure 1 It is a flow chart of the floating point operator error evaluation method provided by the present invention.
[0020] Figure 2 It is a structural schematic diagram of the floating-point operator error evaluation device provided by the present invention.
[0021] Figure 3 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0022] 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.
[0023] In the embodiments of the present invention, "at least one" refers to one or more, and "more than one" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B may represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B may be singular or plural. In the textual description of the present invention, the character " / " generally indicates that the previous and next associated objects are in an "or" relationship. In addition, it should be noted that the serial numbers themselves, such as "first", "second", etc., used to distinguish the objects described in the present invention are only used to distinguish the objects described, and do not have any order or technical meaning.
[0024] With the continuous development and progress of AI technology, AI devices have emerged, such as electronic devices integrated with hardware chips such as GPU and NPU. The AI devices can use the above processors to perform various computing tasks and realize neural network training and reasoning. The error accuracy level of the operators of the GPU and NPU will affect the accuracy of the training and reasoning results. Therefore, it is particularly important to evaluate the error accuracy level of the operators of the GPU and NPU.
[0025] In the related technology, the absolute error results and relative error results between the output tensors of the floating-point operator and the reference operator for high-performance floating-point operations on the GPU or NPU can be calculated simultaneously, and the error accuracy level of the floating-point operator can be evaluated using the average absolute error and / or the maximum absolute error of the absolute error results, or the error accuracy level of the floating-point operator can be evaluated using the average relative error and the maximum relative error of the relative error results. The all_close function can also be used to determine whether the error between the actual value in the output tensor of the floating-point operator and the reference value in the output tensor of the reference operator meets the absolute error threshold (atol) and the relative error threshold (rtol), so as to evaluate the error accuracy level of the floating-point operator.
[0026] Exemplarily, the error accuracy level of the floating-point operator is evaluated by using the mean or maximum value of the absolute error and the relative error, as specifically shown in equations (1) to (6).
[0027] Absolute error = ABS (actual value - reference value) (1).
[0028] Mean absolute error = SUM(ABS(actual value - reference value)) / total number of elements (2).
[0029] Maximum absolute error = MAX(ABS(actual value - reference value)) (3).
[0030] Relative error = ABS (actual value - reference value) / ABS (reference value) (4).
[0031] Average relative error = SUM (ABS (actual value - reference value) / ABS (reference value)) / total number of elements (5).
[0032] Maximum relative error = MAX(ABS(actual value - reference value) / ABS(reference value)) (6).
[0033] In formulas (1) to (6), the actual value represents the element value at a certain position in the floating-point operator output tensor, the reference value represents the element value at the same position in the reference operator output tensor that is consistent with the corresponding actual value, ABS represents an absolute value operation, MAX represents a maximum value operation, and SUM represents a sum operation; the total number of elements represents all elements contained in the reference operator output tensor or the floating-point operator output tensor, that is, the total number of reference values contained in the reference operator output tensor or the total number of actual values contained in the floating-point operator output tensor.
[0034] Since the all_close function is used to compare whether two arrays are equal within a given tolerance range, and the function returns a Boolean value, indicating whether the two arrays are equal within the given tolerance range, the prior art also uses the all_close function to determine whether the error between the actual value and the reference value meets the absolute error threshold and the relative error threshold, which can be specifically referred to formula (7).
[0035] ABS(actual value-reference value)<=rtol×ABS(reference value)+atol (7).
[0036] It can be understood from the function of all_close that when formula (7) is true, "TURE" is returned, and when formula (7) is false, "FALSE" is returned.
[0037] However, when the absolute value of the actual value in the floating-point operator output tensor and the absolute value of the reference value in the reference operator output tensor are both large, even if the relative error between the actual value and the reference value is not large, their absolute error is likely to be large; or, when the absolute value of the reference value and the absolute value of the actual value are both small and close to 0, even if the absolute error between the smaller reference value and the smaller actual value is not large, their relative error is likely to be large. The above situations are likely to cause misunderstanding and misjudgment of the actual error situation, and easily affect the evaluation results of the actual error situation of the floating-point operator; and the mean or maximum value of the absolute error and the relative error must be used simultaneously for evaluation. The error level of the floating-point operator cannot be quantitatively evaluated by a single value, which increases the complexity of quantitative evaluation of the floating-point operator error.
[0038] In addition, although the method using the all_close function comprehensively considers the absolute error threshold and the relative error threshold, the all_close function can only provide whether the error exceeds or does not exceed the threshold, and cannot quantitatively evaluate the floating operator error.
[0039] Therefore, the accuracy of the existing quantitative evaluation of floating operator errors is not high, that is, when the absolute value of the reference value and the absolute value of the actual value are both large or small, the corresponding absolute error and relative error lack consistency, the absolute error results and the relative error results are also inconsistent, and cannot truly and accurately reflect the floating-point error situation.
[0040] To solve the above technical problems, the present invention provides a floating-point operator error evaluation method, device, electronic device and storage medium, which are used to accurately quantify the error of a floating-point operator in a single value manner, thereby improving the accuracy of rapid quantitative evaluation of floating-point operator errors, ensuring that the floating-point operator error evaluation is more stable and effective, and also greatly reducing the complexity of quantitative evaluation of floating-point operator errors and the workload of floating-point operator precision alignment.
[0041] Combine the following Figure 1-Figure 3The floating-point operator error evaluation method, device, electronic device and storage medium of the present invention are described, wherein the execution subject of the floating-point operator error evaluation method is a processor in an AI device, and the processor can specifically be a central processing unit (CPU), and the AI device can be an electronic device integrated with hardware chips such as CPU, GPU and NPU, and the electronic device can be a personal computer (PC), a portable device, a laptop, a smart phone, a tablet computer and other portable wearable devices. The present invention does not specifically limit the specific form of the electronic device. Furthermore, the floating-point operator error evaluation method can also be applied to a floating-point operator error evaluation device set in a processor built into the AI device, and the floating-point operator error evaluation device can be implemented by software, hardware or a combination of the two. The floating-point operator error evaluation method is described below by taking the example that the execution subject of the floating-point operator error evaluation method is a processor in an AI device as an example.
[0042] In order to facilitate understanding of the floating-point operator error evaluation method provided by the embodiment of the present invention, the floating-point operator error evaluation method provided by the present invention will be described in detail below through the following exemplary embodiments. It can be understood that the following exemplary embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.
[0043] Reference Figure 1 , is a flow chart of the floating point operator error evaluation method provided by the present invention, such as Figure 1 As shown, the floating-point operator error evaluation method includes the following steps 110 to 130.
[0044] Step 110: Obtain a target actual tensor corresponding to the floating-point operator to be evaluated and a target reference tensor corresponding to the preset reference operator.
[0045] The floating-point operator to be evaluated may be a floating-point operator that implements high-performance floating-point calculations on a GPU, or may be a floating-point operator that implements high-performance floating-point calculations on an NPU.
[0046] Exemplarily, the floating-point operator to be evaluated can be one of the commonly used floating-point operators for GPU, such as the convolution operator, the matrix multiplication operator, and the multi-head attention operator; or, it can also be one of the commonly used floating-point operators for NPU, such as the Relu operator, the Softmax operator, the convolution operator, the pooling operator, the fully connected operator, the Dropout operator, the SoftmaxWithLoss operator, the LSTM operator, and the GRU operator.
[0047] The preset reference operator may be a floating-point operator for implementing high-performance floating-point calculations on a processor. For example, an operator for implementing a floating-point operation algorithm on a CPU may be a prediction reference operator.
[0048] Specifically, the mapping relationship between floating-point operators and tensor pairs can be pre-configured and stored in the processor, each floating-point operator corresponds to at least one tensor pair, each tensor pair includes an actual tensor for mainly evaluating the error precision of the corresponding floating-point operator and a reference tensor for auxiliary evaluation of the error precision of the corresponding floating-point operator, and the total number of elements contained in the actual tensor and the reference tensor in each tensor pair are the same and one-to-one corresponding. In this way, when the processor determines the floating-point operator to be evaluated, the target tensor pair corresponding to the floating-point operator to be evaluated can be selected from the above mapping relationship; if the floating-point operator to be evaluated corresponds to at least two tensor pairs in the above mapping relationship, a tensor pair with the least total number of elements can be selected as the target tensor pair. Further, the actual tensor contained in the target tensor pair is determined as the target actual tensor, and the reference tensor contained in the target tensor is determined as the target reference tensor. In this way, the target actual tensor corresponding to the floating-point operator to be evaluated and the target reference tensor corresponding to the preset reference operator are obtained.
[0049] Alternatively, the processor can also obtain the target actual tensor and the target reference tensor by the user inputting the target actual tensor and the target reference tensor into the processor, and the input method may include but is not limited to input on the AI device, input in the terminal device application, input by taking a photo and uploading it, and voice input, etc. For example, it can be obtained by the user manually inputting the target actual tensor and the target reference tensor on the human-computer interaction interface of the AI device, or by manually inputting the target actual tensor and the target reference tensor in the terminal device application connected to the AI device. It can also be obtained by first uploading the captured image information containing the target actual tensor and the target reference tensor to the processor, and then the processor identifies the image information to determine the target actual tensor and the target reference tensor. The method of obtaining the target actual tensor and the target reference tensor is not specifically limited here.
[0050] Step 120: Perform a relative error operation based on the absolute error result between the target actual tensor and the target reference tensor, the target reference tensor, and a preset absolute error threshold and a preset relative error threshold to determine a target comprehensive error between the target actual tensor and the target reference tensor.
[0051] The preset absolute error threshold and the preset relative error threshold may be an absolute error threshold and a relative error threshold used to assist in quantitatively measuring the error accuracy of the floating-point operator to be evaluated.
[0052] The target comprehensive error may be a comprehensive error that takes into account a relative error, an absolute error, a preset absolute error threshold, and a preset relative error threshold between the target actual tensor and the target reference tensor.
[0053] Specifically, in order to solve the defect that the existing quantitative evaluation of floating-point operator errors requires simultaneous calculation of the absolute error and relative error between the floating-point operator and the reference operator, and the error accuracy of the corresponding floating-point operator can be evaluated by combining the mean or maximum value of the absolute error and the relative error, the embodiment of the present invention comprehensively combines the absolute error, relative error, absolute error threshold and relative error threshold, and proposes a method for quantitatively evaluating the error accuracy of floating-point operators through a single value, and the single value is the comprehensive error, and an algorithm logic for calculating the comprehensive error is given, so that based on the algorithm logic, the absolute error result between the target actual tensor and the target reference tensor, the preset absolute error threshold and the preset relative error threshold, the target comprehensive error between the target actual tensor and the target reference tensor can be quickly determined.
[0054] Step 130: Determine an error evaluation result of the floating-point operator to be evaluated based on the target comprehensive error; the error evaluation result is used to evaluate whether the accuracy level of the floating-point operator to be evaluated meets the accuracy requirement.
[0055] Specifically, the processor can compare the target comprehensive error between the target actual tensor and the target reference tensor with a preset error threshold. If the target comprehensive error is lower than the preset error threshold, it can be determined that the error evaluation result is that the accuracy level of the floating-point operator to be evaluated meets the accuracy requirements; conversely, if the target comprehensive error is higher than the preset error threshold, it can be determined that the error evaluation result is that the accuracy level of the floating-point operator to be evaluated does not meet the accuracy requirements.
[0056] In the floating-point operator error evaluation method provided by the embodiment of the present invention, the processor in the AI device first performs relative error calculation based on the absolute error result between the target actual tensor corresponding to the floating-point operator to be evaluated and the target reference tensor corresponding to the preset reference operator, the target reference tensor, and the preset absolute error threshold and the preset relative error threshold to determine the target comprehensive error between the target actual tensor and the target reference tensor, and then further determines the error evaluation result used to evaluate whether the accuracy level of the floating-point operator to be evaluated meets the accuracy requirement based on the target comprehensive error. In this way, by comprehensively considering the absolute error, relative error, absolute error threshold and relative error threshold, the single value of the comprehensive error proposed to quantitatively evaluate the floating-point operator error ensures that the comprehensive error has good consistency when the absolute values of the reference value and the actual value are both large or small, and can more truly and accurately reflect the floating-point error situation, which not only improves the accuracy of the rapid quantitative evaluation of the floating-point operator error, and ensures that the floating-point operator error evaluation is more stable and effective, but also greatly reduces the complexity of the quantitative evaluation of the floating-point operator error and the workload of the floating-point operator precision alignment.
[0057] Based on the above Figure 1In the floating-point operator error evaluation method shown in FIG. 1 , in an exemplary embodiment, the specific implementation process of step 120 may include: A relative error operation is performed on each absolute error in the absolute error result and the target absolute value of each target reference value in the target reference tensor, as well as a first ratio of a preset absolute error threshold and a preset relative error threshold to determine an initial comprehensive error result between the target actual tensor and the target reference tensor; based on the initial comprehensive error result, a maximum comprehensive error between the target actual tensor and the target reference tensor is determined, and a target comprehensive error is determined based on the maximum comprehensive error.
[0058] Specifically, it should be noted that for the target actual tensor and the target reference tensor, the total number of target actual values contained in the target actual tensor is the same as the total number of target reference values contained in the target reference tensor and corresponds one to one. In this case, the processor first determines each absolute error in the absolute error result between the target actual tensor and the target reference tensor, as well as the target absolute value of each target reference value in the target reference tensor, and then calculates the relative error based on the first ratio of the preset absolute error threshold and the preset relative error threshold to determine the initial comprehensive error result between the target actual tensor and the target reference tensor. The total number of initial comprehensive errors contained in the initial comprehensive error result is the same as the total number of target actual values contained in the target actual tensor and the total number of target reference values contained in the target reference tensor and corresponds one to one.
[0059] At this time, the maximum comprehensive error with the largest value is determined from the multiple initial comprehensive errors, such as sorting the multiple initial comprehensive errors from large to small or from small to large, and determining the maximum comprehensive error corresponding to the maximum value. Further, the target comprehensive error can be determined based on the maximum comprehensive error, such as the maximum comprehensive error can be determined as the target comprehensive error between the target actual tensor and the target reference tensor.
[0060] Exemplarily, the target actual tensor is: [0.001, 100090.0, 9.991, 20.03], and the target reference tensor is: [0.0001, 100000.0, 10.0, 20.0]. If the preset absolute error threshold atol=0.001 and the preset relative error threshold rtol=0.001, the four initial comprehensive errors shown in Table 1 can be obtained.
[0061] Table 1 Target actual value Target reference value Initial comprehensive error 0.001 0.0001 0.0009 100090.0 100000.0 0.0009 9.991 10.0 0.000818 20.03 20.0 0.001429
[0062] Based on the above Figure 1In the floating-point operator error evaluation method shown in FIG. 1 , in an exemplary embodiment, the processor performs a relative error operation on each absolute error in the absolute error result and a target absolute value of each target reference value in the target reference tensor, and a first ratio of a preset absolute error threshold and a preset relative error threshold to determine an initial comprehensive error result between the target actual tensor and the target reference tensor. The specific implementation process includes: First, the addition result of each target absolute value and the first ratio is determined; then, the second ratio between each absolute error in the absolute error result and the corresponding addition result is calculated, and based on each second ratio, an initial comprehensive error result is obtained.
[0063] Specifically, when the initial comprehensive error result includes N initial comprehensive errors and each initial comprehensive error is a second ratio, each initial comprehensive error can be calculated by formula (8).
[0064] Initial comprehensive error i =ABS(target actual value i - Target reference value i ) / (ABS(target reference value i )+atol / rtol)(8).
[0065] In formula (8), target actual value i represents the i-th target actual value in the target actual tensor, and target reference value i Indicates the i-th target reference value in the target reference tensor, ABS (target actual value i - Target reference value i ) represents the i-th absolute error in the absolute error result, ABS (target reference value i ) represents the target absolute value of the i-th target reference value in the target reference tensor, atol / rtol represents the first ratio of the preset absolute error threshold and the preset relative error threshold, atol represents the preset absolute error threshold, rtol represents the preset relative error threshold, and the initial comprehensive error i Represents the i-th initial comprehensive error in the initial comprehensive error result between the target actual tensor and the target reference tensor, i=1, ..., N, N represents the total number of initial comprehensive errors contained in the initial comprehensive error result, the total number of target actual values contained in the target actual tensor, or the total number of target reference values contained in the target reference tensor, and N is a positive integer.
[0066] After N initial comprehensive errors are calculated according to formula (8), the maximum comprehensive error between the target actual tensor and the target reference tensor can be calculated based on formula (9).
[0067] Maximum comprehensive error = MAX(ABS(target actual value i - Target reference value i) / (ABS(target reference value i )+atol / rtol))(9).
[0068] Based on the above Figure 1 In the floating-point operator error evaluation method shown in the figure, in an exemplary embodiment, in order to ensure that the result of whether the error accuracy of the floating-point operator to be evaluated meets the accuracy requirement is more reliable and accurate, the average comprehensive error can be determined while determining the maximum comprehensive error. Based on this, the processor determines the target comprehensive error based on the maximum comprehensive error, and its specific implementation process may include: First, an average comprehensive error between a target actual tensor and a target reference tensor is determined; further, at least one of the average comprehensive error and a maximum comprehensive error is determined as a target comprehensive error.
[0069] Specifically, the processor can determine the average comprehensive error between the target actual tensor and the target reference tensor based on the absolute error result and the target absolute value of each target reference value in the target reference tensor, and the first ratio of the preset absolute error threshold and the preset relative error threshold, and then determine at least one of the average comprehensive error and the maximum comprehensive error as the target comprehensive error. That is, the accuracy level of the floating-point operator to be evaluated can be evaluated based on the average comprehensive error or the maximum comprehensive error, or can be evaluated based on both the average comprehensive error and the maximum comprehensive error.
[0070] For example, the target actual tensor is: [0.001, 100090.0, 9.991, 20.03], and the target reference tensor is: [0.0001, 100000.0, 10.0, 20.0]. If the preset absolute error threshold atol=0.001 and the preset relative error threshold rtol=0.001, it can be determined that the average comprehensive error is 0.00101 and the maximum comprehensive error is 0.001429; at this time, if at least one of the average comprehensive error and the maximum comprehensive error each exceeds the corresponding error threshold, it can be determined that the accuracy level of the floating-point operator to be evaluated does not meet the accuracy requirements; similarly, if at least one of the average comprehensive error and the maximum comprehensive error each does not exceed the corresponding error threshold, it can be determined that the accuracy level of the floating-point operator to be evaluated meets the accuracy requirements.
[0071] Based on the above Figure 1 In the floating-point operator error evaluation method shown in FIG. 1 , in an exemplary embodiment, a processor determines an average comprehensive error between a target actual tensor and a target reference tensor, and a specific implementation process thereof may include: First, the integrated error accumulation result corresponding to all the initial integrated errors in the initial integrated error result is determined; then, the ratio of the integrated error accumulation result to a preset number is determined as the average integrated error.
[0072] Specifically, the processor may determine the average comprehensive error between the target actual tensor and the target reference tensor according to formula (10).
[0073] Average comprehensive error = SUM(ABS(target actual value i - Target reference value i ) / (ABS(target reference value i )+atol / rtol)) / preset number (10).
[0074] In formula (10), the preset number represents the total number of target actual values contained in the target actual tensor or the total number of target reference values contained in the target reference tensor, ABS represents an absolute value operation, and SUM represents a sum operation; ABS(target actual value i - Target reference value i ) / (ABS(target reference value i )+atol / rtol) represents the i-th initial comprehensive error in the initial comprehensive error result.
[0075] Exemplarily, the target actual tensor is: [0.001, 100090.0, 9.991, 20.03], and the target reference tensor is: [0.0001, 100000.0, 10.0, 20.0]. If the preset absolute error threshold atol=0.001 and the preset relative error threshold rtol=0.001, the 4 initial comprehensive errors, 4 Boolean values returned by the all_close function, 4 absolute errors and 4 relative errors shown in Table 2 can be obtained.
[0076] Table 2
[0077] Table 2 can further determine other error results between the target actual tensor and the target reference tensor, such as the average absolute error of 22.51, the maximum absolute error of 90, the average relative error of 2.25, the maximum relative error of 9, the average comprehensive error of 0.00101, and the maximum comprehensive error of 0.001429.
[0078] It can be seen that when the maximum comprehensive error is determined to be 0.001429 using the method of the present invention, if the preset error threshold is 0.001, it can be determined that the accuracy level of the floating-point operator to be evaluated corresponding to [0.001, 100090.0, 9.991, 20.03] does not meet the accuracy requirement, and it can be seen from Table 2 that the initial comprehensive error corresponding to the target actual value of 20.03 and the target reference value of 20.0 causes the accuracy level of the floating-point operator to be evaluated to not meet the accuracy requirement. At this time, the corresponding calculated average comprehensive error of 0.00101 is also greater than 0.001, further indicating that the corresponding floating-point operator to be evaluated does not meet the accuracy requirement.
[0079] Continuing to refer to Table 2, when the floating-point operator error level is evaluated using the prior art, that is, the mean or maximum value of the absolute error and the relative error is used for evaluation, and the all_close function is used for evaluation, the target actual value (such as 100090.0) and the target reference value (such as 100000) are both large and the corresponding relative error is small (such as 0.0009) but the corresponding absolute error is the largest (such as 90). In this case, the all_close function only provides that the error does not exceed the threshold (such as returning "TRUE"); and the target actual value (such as 0.001) and the target reference value (such as 0.0001) are both small and the corresponding absolute error is the smallest (such as 0.0009) but the corresponding relative error is the largest (such as 9). In this case, the all_close function only provides that the error does not exceed the threshold (such as returning "TRUE"). Both of the above situations are prone to misunderstanding and misjudgment of the real error situation, and the all_close method cannot realize the quantitative evaluation of the floating-point operator error.
[0080] On the contrary, by adopting the single value quantitative evaluation method of the comprehensive error provided by the present invention, the absolute error, relative error, absolute error threshold and relative error threshold are comprehensively considered in the quantitative evaluation process, ensuring that the comprehensive error has better consistency than the absolute error and relative error when the absolute values of the reference value and the actual value are both larger or smaller, and can more truly and accurately reflect the floating-point error situation. In addition, compared with the all_close method, which can only feedback whether the error threshold is exceeded and the error evaluation process cannot be quantified, the method of the present invention can more quantify the error evaluation process and error evaluation results of the floating-point operator. In addition, the average comprehensive error and the maximum comprehensive error are also closer to the statistical values of the actual error situation than the average absolute error, the maximum absolute error, the average relative error and the maximum relative error, thereby not only improving the accuracy of the rapid quantitative evaluation of the floating-point operator error, ensuring that the floating-point operator error evaluation is more stable and effective, but also greatly reducing the complexity of the quantitative evaluation of the floating-point operator error and the workload of the floating-point operator precision alignment.
[0081] Based on the above Figure 1In the floating-point operator error evaluation method shown in the example embodiment, in order to ensure that the quantitative evaluation result is more reliable and accurate, a preset absolute error threshold and a preset relative error threshold for assisting the quantitative evaluation process can be specifically determined according to the floating-point type of the floating-point operator to be evaluated. Based on this, the floating-point operator error evaluation method provided by the present invention can also include: First, determine the target floating-point data type of the floating-point operator to be evaluated; further, based on the pre-configured mapping relationship between the floating-point data type-absolute error threshold-relative error threshold, determine the preset absolute error threshold and the preset relative error threshold that match the target floating-point data type.
[0082] Specifically, considering that different floating-point data types of floating-point operators correspond to different absolute error thresholds and different relative error thresholds, it can ensure that the entire error quantification evaluation process is more targeted and accurate, and the accuracy of the error quantification evaluation results is also higher. The corresponding absolute error threshold and the corresponding relative error threshold can be configured in advance for each floating-point operator of each floating-point data type, and the configuration results can be saved in the form of a mapping relationship.
[0083] Exemplarily, when the floating-point data types of the floating-point operator include four types, namely, Bfloat16, Float16, Float32, and Float64, a mapping relationship as shown in Table 3 can be obtained.
[0084] Table 3 Floating-point data types Relative error threshold Absolute error threshold Float16 0.001 1e-5 Bfloat16 0.016 1e-5 Float32 1.3e-6 1e-5 Float64 1e-7 1e-7
[0085] In this way, when the target floating-point data type of the floating-point operator to be evaluated is determined, the preset absolute error threshold and the preset relative error threshold that match the target floating-point data type can be quickly and accurately determined based on the mapping relationship between the floating-point data type-absolute error threshold-relative error threshold.
[0086] Based on the above Figure 1 In the floating-point operator error evaluation method shown in FIG. 1 , in an exemplary embodiment, the specific implementation process of step 110 may include: In response to the floating-point operator precision test instruction input by the user, the floating-point operator to be evaluated and the preset reference operator are controlled to respectively operate on the input tensor to be tested to obtain the target actual tensor and the target reference tensor.
[0087] Specifically, when the user selects a floating-point operator on the human-computer interaction interface of the AI device and fills in the input tensor to be tested, a floating-point operator precision test instruction can be automatically generated. At this time, the floating-point operator selected on the human-computer interaction interface is the floating-point operator to be evaluated. The processor immediately responds to the floating-point operator precision test instruction, and sends the input tensor to be evaluated filled in by the user in the form of operation instructions to the floating-point operator to be evaluated and the preset reference operator, respectively, so that the floating-point operator to be evaluated and the preset reference operator can each perform operations on the input tensor to be tested, and obtain the target actual tensor output after the floating-point operator to be evaluated is operated, and the target reference tensor output after the preset reference operator is operated.
[0088] The floating-point operator error evaluation device provided by the present invention is described below. The floating-point operator error evaluation device described below and the floating-point operator error evaluation method described above can be referred to each other.
[0089] Reference Figure 2 , is a schematic diagram of the structure of the floating-point operator error evaluation device provided by the present invention, such as Figure 2 The floating-point operator error evaluation device 200 includes: an operator tensor acquisition unit 210 , a comprehensive error determination unit 220 and an operator error evaluation unit 230 .
[0090] The operator tensor acquisition unit 210 is used to acquire the target actual tensor corresponding to the floating-point operator to be evaluated and the target reference tensor corresponding to the preset reference operator.
[0091] The comprehensive error determination unit 220 is used to perform relative error calculation based on the absolute error result between the target actual tensor and the target reference tensor, the target reference tensor, and a preset absolute error threshold and a preset relative error threshold to determine the target comprehensive error between the target actual tensor and the target reference tensor.
[0092] The operator error evaluation unit 230 is used to determine the error evaluation result of the floating-point operator to be evaluated based on the target comprehensive error; the error evaluation result is used to evaluate whether the accuracy level of the floating-point operator to be evaluated meets the accuracy requirement.
[0093] Optionally, the comprehensive error determination unit 220 is specifically used to perform relative error operation on each absolute error in the absolute error result and the target absolute value of each target reference value in the target reference tensor, and a first ratio of a preset absolute error threshold and a preset relative error threshold, to determine an initial comprehensive error result between the target actual tensor and the target reference tensor; based on the initial comprehensive error result, determine the maximum comprehensive error between the target actual tensor and the target reference tensor, and determine the target comprehensive error based on the maximum comprehensive error.
[0094] Optionally, the comprehensive error determination unit 220 is specifically used to determine the addition result of each target absolute value and the first ratio; calculate the second ratio between each absolute error in the absolute error result and the corresponding addition result, and obtain an initial comprehensive error result based on each second ratio.
[0095] Optionally, the comprehensive error determination unit 220 is specifically used to determine the average comprehensive error between the target actual tensor and the target reference tensor; and determine at least one of the average comprehensive error and the maximum comprehensive error as the target comprehensive error.
[0096] Optionally, the comprehensive error determination unit 220 is specifically used to determine the comprehensive error accumulation result corresponding to all initial comprehensive errors in the initial comprehensive error result; the ratio of the comprehensive error accumulation result to a preset number is determined as the average comprehensive error; the preset number is the total number of target actual values contained in the target actual tensor or the total number of target reference values contained in the target reference tensor.
[0097] Optionally, the operator tensor acquisition unit 210 is specifically used to determine the target floating-point data type of the floating-point operator to be evaluated; based on the pre-configured mapping relationship between the floating-point data type-absolute error threshold-relative error threshold, determine the preset absolute error threshold and the preset relative error threshold that match the target floating-point data type.
[0098] Optionally, the operator tensor acquisition unit 210 is specifically used to respond to the floating-point operator precision test instruction input by the user, control the floating-point operator to be evaluated and the preset reference operator to respectively operate on the input tensor to be tested, and obtain the target actual tensor and the target reference tensor.
[0099] Figure 3 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 3As 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 floating-point operator error evaluation method, which includes: obtaining the target actual tensor corresponding to the floating-point operator to be evaluated and the target reference tensor corresponding to the preset reference operator; performing relative error calculation based on the absolute error result between the target actual tensor and the target reference tensor, the target reference tensor, and the preset absolute error threshold and the preset relative error threshold, and determining the target comprehensive error between the target actual tensor and the target reference tensor; determining the error evaluation result of the floating-point operator to be evaluated based on the target comprehensive error; the error evaluation result is used to evaluate whether the accuracy level of the floating-point operator to be evaluated meets the accuracy requirement.
[0100] 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 prior art 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.
[0101] On the other hand, the present invention also provides a computer program product, which includes a computer program, and 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 floating-point operator error evaluation method provided by the above methods, and the method includes: obtaining a target actual tensor corresponding to the floating-point operator to be evaluated and a target reference tensor corresponding to a preset reference operator; performing a relative error operation based on the absolute error result between the target actual tensor and the target reference tensor, the target reference tensor, and a preset absolute error threshold and a preset relative error threshold to determine a target comprehensive error between the target actual tensor and the target reference tensor; based on the target comprehensive error, determining the error evaluation result of the floating-point operator to be evaluated; the error evaluation result is used to evaluate whether the accuracy level of the floating-point operator to be evaluated meets the accuracy requirements.
[0102] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to execute the floating-point operator error evaluation method provided by the above-mentioned methods, the method comprising: obtaining a target actual tensor corresponding to the floating-point operator to be evaluated and a target reference tensor corresponding to a preset reference operator; performing a relative error operation based on the absolute error result between the target actual tensor and the target reference tensor, the target reference tensor, and a preset absolute error threshold and a preset relative error threshold to determine a target comprehensive error between the target actual tensor and the target reference tensor; determining an error evaluation result of the floating-point operator to be evaluated based on the target comprehensive error; the error evaluation result is used to evaluate whether the accuracy level of the floating-point operator to be evaluated meets the accuracy requirements.
[0103] 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.
[0104] 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, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product 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 embodiments.
[0105] 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. A floating point operator error evaluation method, characterized in that: include: Get the target actual tensor corresponding to the floating-point operator to be evaluated and the target reference tensor corresponding to the preset reference operator; Performing a relative error operation based on an absolute error result between the target actual tensor and the target reference tensor, the target reference tensor, and a preset absolute error threshold and a preset relative error threshold to determine a target comprehensive error between the target actual tensor and the target reference tensor; Based on the target comprehensive error, an error evaluation result of the floating-point operator to be evaluated is determined; the error evaluation result is used to evaluate whether the accuracy level of the floating-point operator to be evaluated meets the accuracy requirement.
2. The floating point operator error evaluation method according to claim 1, characterized in that: The performing relative error calculation based on the absolute error result between the target actual tensor and the target reference tensor, the target reference tensor, and a preset absolute error threshold and a preset relative error threshold to determine the target comprehensive error between the target actual tensor and the target reference tensor includes: Performing a relative error operation on each absolute error in the absolute error result and a target absolute value of each target reference value in the target reference tensor, and a first ratio of the preset absolute error threshold and the preset relative error threshold to determine an initial comprehensive error result between the target actual tensor and the target reference tensor; Based on the initial comprehensive error result, a maximum comprehensive error between the target actual tensor and the target reference tensor is determined, and the target comprehensive error is determined based on the maximum comprehensive error.
3. The floating point operator error evaluation method according to claim 2, characterized in that: The step of performing a relative error operation on each absolute error in the absolute error result and a target absolute value of each target reference value in the target reference tensor, and a first ratio of the preset absolute error threshold and the preset relative error threshold to determine an initial comprehensive error result between the target actual tensor and the target reference tensor includes: Determine the sum of each of the target absolute values and the first ratio; A second ratio between each absolute error in the absolute error result and the corresponding addition result is calculated, and the initial comprehensive error result is obtained based on each second ratio.
4. The floating point operator error evaluation method according to claim 2, characterized in that: The determining the target comprehensive error based on the maximum comprehensive error comprises: determining an average combined error between the target actual tensor and the target reference tensor; At least one of the average comprehensive error and the maximum comprehensive error is determined as the target comprehensive error.
5. The floating point operator error evaluation method according to claim 4, characterized in that: The determining an average comprehensive error between the target actual tensor and the target reference tensor comprises: Determine a comprehensive error accumulation result corresponding to all initial comprehensive errors in the initial comprehensive error result; The ratio of the accumulated result of the comprehensive error to a preset number is determined as the average comprehensive error; the preset number is the total number of target actual values contained in the target actual tensor or the total number of target reference values contained in the target reference tensor.
6. The floating point operator error evaluation method according to any one of claims 1 to 5, characterized in that: The method further comprises: Determining a target floating-point data type of the floating-point operator to be evaluated; Based on a preconfigured mapping relationship between floating-point data type-absolute error threshold-relative error threshold, the preset absolute error threshold and the preset relative error threshold matching the target floating-point data type are determined.
7. The floating point operator error evaluation method according to any one of claims 1 to 5, characterized in that: The obtaining of a target actual tensor corresponding to the floating-point operator to be evaluated and a target reference tensor corresponding to the preset reference operator includes: In response to a floating-point operator precision test instruction input by a user, the floating-point operator to be evaluated and the preset reference operator are controlled to respectively operate on the input tensor to be tested, so as to obtain the target actual tensor and the target reference tensor.
8. A floating point operator error evaluation device, characterized in that: include: An operator tensor acquisition unit, used to acquire a target actual tensor corresponding to the floating-point operator to be evaluated and a target reference tensor corresponding to a preset reference operator; a comprehensive error determination unit, configured to perform a relative error operation based on an absolute error result between the target actual tensor and the target reference tensor, the target reference tensor, and a preset absolute error threshold and a preset relative error threshold to determine a target comprehensive error between the target actual tensor and the target reference tensor; The operator error evaluation unit is used to determine the error evaluation result of the floating-point operator to be evaluated based on the target comprehensive error; the error evaluation result is used to evaluate whether the accuracy level of the floating-point operator to be evaluated meets the accuracy requirement.
9. 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, the floating-point operator error evaluation method according to any one of claims 1 to 7 is implemented.
10. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the floating-point operator error evaluation method according to any one of claims 1 to 7 is implemented.
Citation Information
Cited By
Computing library test verification method and system of GPU architecture, electronic equipment and storage medium
CN122673038A
