Model parameter quantification method and device, electronic equipment and storage medium

By quantizing model parameters, converting from high-precision floating-point numbers to fixed-point numbers, the calculation efficiency and memory usage caused by high-precision parameters is solved, and more efficient model calculations and lower memory usage are achieved.

CN119416914APending Publication Date: 2025-02-11ARM TECH CHINA CO LTD
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411629862.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-13
Publication Date
2025-02-11

AI Technical Summary

Technical Problem

During the model calculation process, the model parameters represented by high-precision floating point numbers lead to an increase in the calculation amount, a decrease in output efficiency, and a large amount of memory.

Method used

By obtaining the floating point number parameters of the initial model and the target quantized fixed-point number, determining the theoretical quantization parameters and zero point values, adjusting the model parameters to minimize the quantization error, thereby quantizing the model parameters into fixed-point numbers.

Benefits of technology

It improves the computing efficiency of the model, reduces memory usage, and maintains the accuracy of model output.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119416914A_ABST
    Figure CN119416914A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a model parameter quantification method and device, electronic equipment and a storage medium, and relates to the technical field of computers. The method comprises the steps of determining a theoretical quantization parameter based on a first model parameter of an initial model and a target quantization fixed point digit, and determining a zero point value based on the theoretical quantization parameter and the target quantization fixed point digit; determining candidate quantization parameters based on the theoretical quantization parameters; quantizing the first model parameter through each candidate quantization parameter and the zero value to obtain each second model parameter, and determining a model error of each second model parameter; and adjusting the model parameter to a second model parameter with the minimum model error. The candidate quantization parameters meeting the requirements are obtained through the target quantization fixed point digits, the model error caused by each candidate quantization parameter is calculated, and finally the candidate quantization parameter with the minimum model error is selected as the target quantization parameter for quantization, so that the calculation efficiency of the model can be improved, and meanwhile, the accuracy of model output can be kept.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for quantizing parameters of a model. Background Art

[0002] During the calculation process of the model, the time or efficiency of calculating the output has a certain relationship with the model parameters of the model itself. Specifically, in order to improve the calculation accuracy of the model, the model parameters are often represented by floating-point numbers with higher precision.

[0003] However, due to the high precision of the model parameters, the amount of calculation required during model calculation will increase, which will lead to lower output efficiency of the model and occupy more memory. Summary of the invention

[0004] The purpose of this application is to solve at least one of the above technical defects. The technical solutions provided by the embodiments of this application are as follows: In a first aspect, an embodiment of the present application provides a method for quantifying parameters of a model, including: Obtain a first model parameter W of the initial model and a target quantization fixed-point number b, where the first model parameter W is a floating-point number; Based on the first model parameter W and the target quantization fixed-point bit number b, determine a theoretical quantization parameter scale for the first model parameter W, and determine a zero point value zerop based on the theoretical quantization parameter scale and the target quantization fixed-point bit number b; Determine a value range of a target quantization parameter based on a theoretical quantization parameter scale; wherein the value range includes at least two candidate quantization parameters; For each candidate quantization parameter, quantize the first model parameter W based on the candidate quantization parameter and the zero point value zerop to obtain a corresponding second model parameter, and determine a model error corresponding to the second model parameter; wherein the second model parameter is a fixed-point number; The first model parameter W of the initial model is adjusted to the second model parameter corresponding to the minimum model error.

[0005] In a second aspect, an embodiment of the present application provides a model parameter quantization device, including: A model parameter quantization target acquisition module is used to obtain a first model parameter W of the initial model and a target quantization fixed-point number b, where the first model parameter W is a floating-point number; A theoretical quantization parameter acquisition module is used to determine a theoretical quantization parameter scale for the first model parameter W based on the first model parameter W and the target quantization fixed-point bit number b, and to determine a zero point value zerop based on the theoretical quantization parameter scale and the target quantization fixed-point bit number b; A quantization parameter value range determination module, used to determine a value range of a target quantization parameter based on a theoretical quantization parameter scale; wherein the value range includes at least two candidate quantization parameters; A model error determination module, for each candidate quantization parameter, quantizing the first model parameter W based on the candidate quantization parameter and the zero point value zerop to obtain a corresponding second model parameter, and determining a model error corresponding to the second model parameter; wherein the second model parameter is a fixed-point number; The model parameter adjustment module is used to adjust the first model parameter W of the initial model to the second model parameter corresponding to the minimum model error.

[0006] In a third aspect, an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory; The processor executes the computer program to implement the method provided in the embodiment of the first aspect or any optional embodiment of the first aspect.

[0007] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the method provided in the embodiment of the first aspect or any optional embodiment of the first aspect is implemented.

[0008] The beneficial effects of the technical solution provided by the embodiment of the present application are: The solution provided in the present application is to determine the target quantization parameter value range for the first model parameter W that can meet the target quantization fixed-point bit number b based on the known target quantization fixed-point bit number b, and then quantize each candidate quantization parameter in the value range one by one for the first model parameter W and calculate the model error that may be caused between the second model parameter obtained after each quantization and the original model, and finally select the second model parameter that minimizes the model error as the quantized model parameter, so as to improve the computational efficiency of the model itself while maintaining the accuracy of the model output. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in describing the embodiments of the present application are briefly introduced below.

[0010] Figure 1 A schematic diagram of a flow chart of a parameter quantization method of a model provided in an embodiment of the present application; Figure 2 This is an example diagram of a model parameter quantization mapping in an example of an embodiment of the present application; Figure 3 A flow chart of a method for quantifying model parameters in an example of an embodiment of the present application Figure 4 A structural block diagram of a model parameter quantization device provided in an embodiment of the present application; Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0011] The embodiments of the present application are described below in conjunction with the drawings in the present application. It should be understood that the implementation methods described below in conjunction with the drawings are exemplary descriptions for explaining the technical solutions of the embodiments of the present application and do not constitute a limitation on the technical solutions of the embodiments of the present application.

[0012] It will be understood by those skilled in the art that, unless specifically stated, the singular forms "one", "said", and "the" used herein may also include plural forms. It should be further understood that the terms "including" and "comprising" used in the embodiments of the present application refer to that the corresponding features can be implemented as the presented features, information, data, steps, operations, elements and / or components, but do not exclude the implementation as other features, information, data, steps, operations, elements, components and / or combinations thereof supported by the technical field. It should be understood that when we say that an element is "connected" or "coupled" to another element, the one element may be directly connected or coupled to the other element, or it may refer to that the one element and the other element establish a connection relationship through an intermediate element. In addition, the "connection" or "coupling" used herein may include wireless connection or wireless coupling. The term "and / or" used herein indicates at least one of the items defined by the term, for example, "A and / or B" may be implemented as "A", or as "B", or as "A and B".

[0013] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0014] The following describes several exemplary embodiments to illustrate the technical solutions of the embodiments of the present application and the technical effects produced by the technical solutions of the present application. It should be noted that the following embodiments can refer to, draw on or combine with each other, and the same terms, similar features and similar implementation steps in different embodiments will not be described repeatedly.

[0015] A large model refers to a machine learning model with ultra-large-scale parameters and complex computing structures. It is usually able to process massive amounts of data and complete various complex tasks, such as natural language processing and image recognition. Each large model is often pre-trained to obtain multiple model parameters. When the large model is applied, the large model calculates the model input and the trained model parameters once or multiple times, and finally outputs the model output corresponding to the model input.

[0016] Figure 1 A flow chart of a parameter quantization method of a model is provided for an embodiment of the present application. The execution subject of the method may be a terminal (such as a computer, a mobile phone, etc.). Figure 1 As shown, the method may include: Step S101, obtaining a first model parameter W of an initial model and a target quantization fixed-point number b, wherein the first model parameter W is a floating-point number.

[0017] Among them, the initial model can be a model that has been trained but needs to be optimized, such as LLM (Large Language Model), etc. A large model often has multiple trained model parameters, and the first model parameter W can be the target model parameter that needs to be quantized among the multiple model parameters of the initial model. Generally speaking, the first model parameter W can be in the form of a matrix, and each element in the matrix can be expressed in the form of a floating point number. The target quantization fixed-point bit number b can be obtained from the quantization requirements of the model, which can be used to characterize the conversion of the first model parameter W into a numerical value with a target bit number. For example, according to the quantization requirements, the model parameters need to be quantized into 7-bit integers, and the target quantization fixed-point bit number b is 7.

[0018] Specifically, before quantizing the first model parameter W of the initial model, the target number of quantization fixed-point bits b can be determined according to the hardware processing capability, default requirements, etc. The hardware processing capability can characterize the computational efficiency of the model. Specifically, since the accuracy of the model parameters (i.e., the number of bits contained in the model parameters) will take up more memory, under the premise of a certain hardware processing capability, the higher the accuracy of the model parameters, the lower the computational efficiency of the model will be. The model parameters of the initial model are often represented by floating-point numbers, and the precision of floating-point numbers is generally high. Based on this, the computational efficiency of the model can be ensured by limiting the number of bits of the model parameters. In other words, the number of bits of the model parameters required after quantization (i.e., the target number of quantization fixed-point bits b) can be determined according to the processing capability of the hardware itself and the model computational efficiency of the default requirement.

[0019] Step S102 : determining a theoretical quantization parameter scale for the first model parameter W based on the first model parameter W and the target quantization fixed-point bit number b, and determining a zero point value zerop based on the theoretical quantization parameter scale and the target quantization fixed-point bit number b.

[0020] The theoretical quantization parameter of the embodiment of the present application can also be called a scaling factor. In the embodiment of the present application, the essence of quantizing the model parameters is to map each floating-point element in the first model parameter W matrix to a fixed-point number range, that is, to represent each floating-point element with a corresponding fixed-point number within the fixed-point number range. The zero point value zerop is used to represent the mapping of the zero point in the floating-point number to the corresponding value in the quantized fixed-point number representation.

[0021] In the embodiment of the present application, after obtaining the target number of fixed-point quantization bits b and before quantization, it is necessary to first calculate the parameters required in the quantization process. Specifically, the theoretical quantization parameter scale applicable to the first model parameter W can be determined based on the target number of fixed-point quantization bits b. At the same time, in order to reduce the quantization error and ensure the accuracy of the entire quantization process, it is also necessary to determine the zero point value zerop during quantization.

[0022] Step S103 , determining a value range of a target quantization parameter based on a theoretical quantization parameter scale; wherein the value range includes at least two candidate quantization parameters.

[0023] The candidate quantization parameters of the embodiment of the present application can be first obtained from the value range to further narrow the acquisition range of the target quantization range.

[0024] Specifically, the model parameters in the initial model are trained parameters. Theoretically, the number of quantization fixed-point bits b is determined, and the quantization parameter scale is also determined, and no calibration is required. However, when the number of quantization fixed-point bits is small, it will inevitably cause partial loss of information about the model parameters themselves. Therefore, in order to optimize the quantization process so that the obtained quantization parameter scale is optimal, after calculating the theoretical quantization parameter scale, a selectable value range of the quantization parameter can be determined based on the theoretical value, and a certain number of candidate values ​​within the value range can be further selected as candidate quantization parameters.

[0025] Step S104, for each candidate quantization parameter, quantize the first model parameter W based on the candidate quantization parameter and the zero point value zerop to obtain a corresponding second model parameter, and determine a model error corresponding to the second model parameter; wherein the second model parameter is a fixed-point number.

[0026] The second model parameter of the embodiment of the present application can be a model parameter obtained by quantizing the first model parameter W by any candidate quantization parameter. Since the quantization step is performed, each second model parameter is represented by a fixed-point number. The model error can be the difference between the output obtained after the first model parameter W of the initial model is changed to the second model parameter and the output of the original initial model under the premise of the same input.

[0027] Specifically, since the optimal target quantization parameter needs to be selected, each candidate quantization parameter can be used to quantize the first model parameter W to obtain multiple corresponding second model parameters, and then the model error between the model using the second model parameter and the initial model itself is calculated, and the model error is used as the basis for selecting the target quantization parameter. The specific quantization process can refer to the following formula:

[0028] in, That is, it represents the fixed-point value calculated by quantizing the first model parameter W (represented by X in the formula) through the candidate quantization parameter (scale in the formula) and the zero point value zerop; the clip function is used to limit the range of the calculated fixed-point value so that the value can fall into the interval [Q min , Q max ], if the calculated fixed-point value is less than Q min , then Q min As the final calculated fixed-point value, if the calculated fixed-point value is greater than Q max , then Q max As the final calculated fixed-point value.

[0029] Step S105, adjusting the first model parameter W of the initial model to the second model parameter corresponding to the minimum model error.

[0030] It can be understood that the smallest model error means that it is closer to the initial model. Since the initial model is the trained model with the highest output accuracy, the smaller the model error, the higher the accuracy of the corresponding output. Therefore, the second model parameter corresponding to the smallest model error can replace the first model parameter W in the initial model.

[0031] The solution provided in the present application is to determine the target quantization parameter value range for the first model parameter W that can meet the target quantization fixed-point bit number b based on the known target quantization fixed-point bit number b, and then quantize each candidate quantization parameter in the value range one by one for the first model parameter W and calculate the model error that may be caused between the second model parameter obtained after each quantization and the original model, and finally select the second model parameter that minimizes the model error as the quantized model parameter, so as to improve the computational efficiency of the model itself while maintaining the accuracy of the model output.

[0032] Based on the above embodiments, as an optional embodiment, the first model parameter W includes a plurality of first matrix elements; the first matrix elements are floating-point elements; Based on the first model parameter W and the target quantization fixed-point bit number b, a theoretical quantization parameter scale for the first model parameter W is determined, specifically including: Get the first maximum value X in each first matrix element contained in the first model parameter W max and the first minimum value X min ; Based on the target quantization fixed-point bit number b, determine the quantization mapping range for the first model parameter W, and obtain the second maximum value Q of the quantization mapping range max and the second minimum value Q min ; Get the first maximum value X max With the first minimum value X min The first difference between the two and the second maximum value Q max With the second minimum value Q min The ratio of the first difference to the second difference is used as a theoretical quantization parameter scale; Specifically, after the target quantization fixed-point bit number b is known, the quantization mapping range of each matrix element in this quantization can be determined. Since each number is represented in binary in computer calculations, the maximum value of the quantization mapping range (i.e., the second maximum value Q of the quantization mapping range) is max and the second minimum value Q min ) is generally an integer power of 2. Specifically, when the mapping range needs to be evenly distributed on both sides of the zero point, the quantization mapping range can be [-2 b-1 , 2 b-1 -1]; when the mapping range only needs to be distributed to one side of the zero point, the quantization mapping range can be [0, 2 b -1]. As the quantization of model parameters is introduced above, that is, each floating-point first matrix element in the first model parameter W is represented by a fixed-point number, the maximum value X among the known first matrix elements is max and minimum value X min In the case of , all first matrix elements are mapped to the interval [Q min , Q max ], when mapping, the range where each first matrix element should be in the quantization mapping range can be calculated one by one according to the ratio of the interval length. The ratio of the interval length is the theoretical quantization parameter scale, and the calculation method is as follows:

[0033] Figure 2 An example of mapping of a first matrix element provided in an embodiment of the present application is as follows: Figure 2 As shown in the figure, -max (|X f |) is the opposite of the absolute value of the maximum value in the first element matrix, and max(|X f |) is the absolute value of the maximum value in the first element matrix. In this example, b is set to 8. At this time, the quantization mapping range can be determined to be [-128, 127]. Then, each first matrix element (-max (|X f |) and max(|X f |) are mapped to the quantization interval (the points between -128 and 127 in the figure).

[0034] The zero point value zerop is determined based on the theoretical quantization parameter scale and the target quantization fixed-point bit b, specifically including: Determine the first minimum value X based on the theoretical quantization parameter scale min The quantization mapping value under the condition of the quantization fixed point number b, and based on the quantization mapping value and the second minimum value Q min Determine the zero point value zerop.

[0035] Specifically, after obtaining the theoretical quantization parameter, the zero value in the floating point number can be calculated based on the theoretical quantization parameter in the interval [Q min , Q max The specific fixed point value (i.e., zero point value zerop) in ] can be calculated by first calculating the first minimum value X min In the interval [Q min , Q max ], and then calculate the quantization mapping value and the second minimum value Q min The difference between the zero point and the zero point can be determined by the formula:

[0036] Based on the above embodiments, as an optional embodiment, determining the value range of the target quantization parameter based on the theoretical quantization parameter scale specifically includes: Obtaining a first preset parameter α which is less than a first preset value and a second preset parameter β which is greater than the first preset value; The theoretical quantization parameter scale is weighted by a first preset parameter α to obtain a first weighted result, and the first weighted result is used as the minimum value of the value range; The theoretical quantization parameter scale is weighted by a second preset parameter β to obtain a second weighted result, and the second weighted result is used as the maximum value of the value range; The minimum value of the value range is smaller than the theoretical quantization parameter scale, and the maximum value of the value range is larger than the theoretical quantization parameter scale.

[0037] The first preset value of the embodiment of the present application can generally be set to 1, and the first preset parameter α and the second preset parameter β are generally set to be less than 1 and greater than 1, respectively.

[0038] It can be understood that in order to select the target quantization parameter more accurately, the generally obtained value range will include both a part smaller than the theoretical quantization parameter scale and a part larger than the theoretical quantization parameter scale. In order to meet the above requirements, the theoretical quantization parameter scale can be weighted by the first preset parameter α to obtain a first weighted result α*scale, and the theoretical quantization parameter scale can be weighted by the second preset parameter β to obtain a second weighted result β*scale. Since the first preset parameter α is less than 1, the first weighted result α*scale will be smaller than the theoretical quantization parameter scale. Similarly, the second weighted result β*scale will be larger than the theoretical quantization parameter scale.

[0039] Based on the above embodiments, as an optional embodiment, each candidate quantization parameter is obtained in the following manner: The value range is evenly divided into a preset number of sub-ranges, and the maximum value of each sub-range is taken as a candidate quantization parameter.

[0040] Specifically, in the value range of α*scale and β*scale, the optimal scale is searched, and the step length increased by each search step is (β*scale-α*scale) / step. It can be seen that if the step is large, the amount of calculation will be large, it will take a long time, and the efficiency will be low, but the search will be more detailed. The user needs to actually have a compromise. For this situation, the embodiment of the present application provides a "step" parameter, the meaning of which is to "execute the calculation of the second model parameter a preset number of times". For example, if the step is set to 10, it means that the second model parameter is calculated 10 times; when the "step" parameter is set, it is necessary to first select a corresponding preset number of candidate quantization parameters from the value range, and then quantize the first model parameter W in turn through these selected candidate quantization parameters; for the method of selecting candidate quantization parameters, the embodiment of the present application can adopt the following method: divide the value range into a preset number of sub-interval ranges on average, and then use the fixed point number corresponding to the maximum point of each sub-interval range as the candidate quantization parameter.

[0041] It should be noted that the method of "equally dividing the value range" in the solution provided in the embodiment of the present application is not the only way to determine the candidate quantization parameters. Candidate quantization parameters can also be selected by random value selection, random distribution, etc., and the present application does not limit this.

[0042] Based on the above embodiments, as an optional embodiment, determining the model error corresponding to the second model parameter specifically includes: Obtaining a random input for an initial model, and converting the random input into a first random excitation signal a; The first random excitation signal a is calibrated to obtain a second random excitation signal, and the second random excitation signal is input into the debugging model to obtain a first output of the debugging model; wherein the debugging model is a model obtained by replacing the first model parameter W of the initial model with the second model parameter; Dequantize the first output based on the candidate quantization parameter and the zero point value zerop to obtain a second output; Inputting the second random excitation signal into the initial model to obtain a third output of the initial model; The mean square error MSE of the second output and the third output, and the similarity between the first model parameter W and the second model parameter are obtained, and the mean square error MSE is weighted based on the similarity to obtain a third weighted result, and the third weighted result is used as the model error corresponding to the second model parameter.

[0043] The random input of the embodiment of the present application can be any input that meets the format required by the initial model; the first random excitation signal a is a time series signal, which can be a variable in the initial model calculation process. The first random excitation signal a can be in matrix form, and each matrix element in the matrix is ​​a real number; the second random excitation signal is the calibrated first random excitation signal a, which is the same as the first random excitation signal a. The signal can also be in matrix form, and each matrix element in the matrix is ​​a real number; the mean square error MSE is a measure used to reflect the degree of difference between the estimator and the estimated value, and is used to reflect the degree of difference between the two model outputs in the embodiment of the present application.

[0044] Specifically, in order to calculate the model error, it is necessary to first give an input about the initial model. In the embodiment of the present application, a random input can be generated by a random generator or the like, and then the random input is converted into a time domain first random excitation signal a. At the same time, in order to reduce the inaccuracy caused by the randomness of the random signal, the first random excitation signal a is calibrated to obtain a calibrated second random excitation signal, and then the second random excitation signal is used as the input of the model to be respectively input into the initial model and the debugging model after the model parameters are quantized and adjusted (that is, the first model parameter W is replaced by the second model parameter model), and the first output and the third output are output respectively. At the same time, since the third output is calculated by the floating-point model parameters, the third output is also a floating-point type. Similarly, the first output should be a fixed-point type. Therefore, in order to calculate the mean square error MSE between the first output and the third output, it is necessary to perform an inverse quantization operation on the first output to make it a floating-point type. The specific inverse quantization operation formula is as follows:

[0045] in, is the second output after inverse quantization, is the first output.

[0046] After the dequantization operation is completed, the mean square error MSE of the second output and the third output can be calculated. The calculation formula of the mean square error MSE is as follows:

[0047] in, Can be the second output, It can be the third output, N is the number of matrix elements contained in the second output and the third output (the second output and the third output contain the same number of matrix elements), and i represents the i-th matrix element.

[0048] Although the mean square error MSE can reflect the degree of error in the outputs of the two models to a certain extent, in order to further more accurately express the model error, the embodiment of the present application will further reflect the model error through the differences in the model parameters themselves. Specifically, the similarity between the two model parameters in the two models can be calculated, and then the mean square error MSE is further weighted by the similarity to obtain a third weighted result, which is the final model error.

[0049] Based on the above embodiments, as an optional embodiment, calibrating the first random excitation signal a to obtain the second random excitation signal specifically includes: Performing Fourier transform on the first random excitation signal a to obtain a first spectrum A corresponding to the first random excitation signal a; wherein the first spectrum A includes a plurality of second matrix elements; For each second matrix element in the first spectrum A, determine a calibration amplitude μ of the second matrix element, and calibrate the second matrix element based on the calibration amplitude μ to obtain a second spectrum after calibrating the first spectrum A; Perform inverse Fourier transform on the second frequency spectrum to obtain a calibrated second random excitation signal.

[0050] The first spectrum A of the embodiment of the present application can be a frequency signal obtained by Fourier transforming the first random excitation signal a in the time domain signal; the first random excitation signal a can also be in the form of a matrix, and the second matrix elements contained in the first spectrum A correspond to the matrix elements contained in the first random excitation signal a respectively; Fourier transform is a mathematical transformation used to convert a time domain signal input into a corresponding frequency signal output; the calibration amplitude μ can be a constant used to further reflect the difference between the second matrix elements.

[0051] In order to reduce the randomness caused by random input, the embodiment of the present application provides one of the optional calibration methods. Specifically, after obtaining the first random excitation signal a corresponding to the random input, the first random excitation signal a is first converted into the first spectrum A of the corresponding frequency signal. The specific conversion method is to convert each matrix element originally contained in the first random excitation signal a through Fourier transform to obtain each corresponding second matrix element. Each second matrix element together constitutes the first spectrum A, which can be expressed by the following formula: A=FFT(a,fftsize) Among them, A is the first spectrum A, FFT function is Fourier transform, a is the first random excitation signal a, fftsize is the Fourier parameter, which can generally be set to 1024, or can be set to any other arbitrary value, which is not limited in the embodiment of the present application.

[0052] After obtaining the first spectrum A, the second matrix elements in the first spectrum A are calibrated. Since there are differences between the second matrix elements, in order to make the differences between the second matrix elements more significant, different calibration amplitudes μ can be used to calibrate different second matrix elements respectively (the calibration process can be regarded as a weighted process, that is, each matrix element is weighted by the calibration amplitude μ). After the calibration, the matrix elements together constitute the second spectrum (which can be recorded as A*μ). Finally, the second spectrum is inverse Fourier transformed (that is, the frequency signal is converted back into a time domain signal) to obtain the second random excitation signal after the first random excitation signal a is calibrated.

[0053] Based on the above embodiments, as an optional embodiment, each second matrix element in the first spectrum A is an imaginary number; Determining the calibration amplitude μ of the second matrix element specifically includes: Performing a modulo operation on each second matrix element included in the first spectrum A to obtain each third matrix element in the spectrum matrix specA after modulo operation, and obtaining the maximum value of each third matrix element; Acquire a third preset parameter which is less than the second preset value and a fourth preset parameter which is greater than the second preset value; If the third matrix element is less than the preset ratio of the maximum value, the third preset parameter is used as the calibration amplitude μ of the second matrix element; if the third matrix element is not less than the preset ratio of the maximum value, the fourth preset parameter is used as the calibration amplitude μ of the third matrix element; Among them, the third matrix element obtained after adjustment based on the third preset parameter is smaller than the original second matrix element, and the third matrix element obtained after adjustment based on the fourth preset parameter is larger than the original second matrix element.

[0054] The second preset value of the embodiment of the present application is generally set to 1, and the third preset parameter and the fourth preset parameter are generally set to be less than 1 or greater than 1.

[0055] In order to make the difference between the second matrix elements more significant, the embodiment of the present application provides a method for determining the calibration amplitude μ of each second matrix element. Specifically, firstly, a modulo operation is performed on each second matrix element. Since each second matrix element is represented by an imaginary number (such as a+bi), the result obtained after the modulo operation is , and the result of each modulo operation is used as the third matrix element. Each third matrix element together constitutes the spectrum matrix specA. Each third matrix element contained in specA is a real number. The above process can be expressed by the following formula: specA=abs(A) Wherein, specA represents the spectrum matrix composed of the elements of each third matrix, the abs function represents a modulo operation, and A is the first spectrum A.

[0056] Afterwards, each third element matrix can be classified based on the preset ratio of the maximum value in each third element matrix (usually set to 1 / 2), and different calibration amplitudes can be used to calibrate different types of third element matrices. In an embodiment of the present application, the third preset parameter can be used to calibrate the third matrix elements that are smaller than the preset ratio, and the fourth preset parameter can be used to calibrate the third matrix elements that are larger than the preset ratio. Since the third preset parameter is less than 1 and the fourth preset parameter is greater than 1, the third matrix elements that are smaller than the preset ratio will have a smaller value after calibration with the third preset parameter, and the third matrix elements that are larger than the preset ratio will have a larger value after calibration with the fourth preset parameter, thereby achieving the effect of making the differences between the third matrix elements more significant. The above process can be specifically expressed by the following formula: maxv = max(specA)

[0057] Among them, maxv represents the maximum value among the third matrix elements, and the max function represents obtaining the maximum value from the third matrix elements contained in specA; Indicates half of the maximum value (i.e. the preset ratio, which can be adjusted according to actual needs); is the third preset parameter, is the fourth preset parameter (0.5 and 1.25 are both example values ​​and can be adjusted according to actual needs).

[0058] It should be noted that the present embodiment only provides one method for determining the calibration amplitude. The method can also set different calibration amplitudes for each matrix element according to actual needs. , the embodiments of the present application are not limited here.

[0059] Based on the above embodiments, as an optional embodiment, obtaining the mean square error MSE between the second output and the third output, and the similarity between the first model parameter W and the second model parameter specifically includes: Get the third spectrum W of the second model parameters q , and obtain the fourth spectrum W of the first model parameter W f ; Wherein, the third spectrum W q and the fourth spectrum W f They are obtained by Fourier transform of the corresponding model parameters; Determine the third spectrum W q and the fourth spectrum W f The spectral similarity between w As the similarity between the first model parameter W and the second model parameter.

[0060] The embodiment of the present application also provides a method for calculating the similarity between the first model parameter W and the second model parameter. Specifically, firstly, a third spectrum W of the second model parameter is obtained by Fourier transform. q and the fourth spectrum W of the first model parameter W f , the specific method is the same as the Fourier transform mentioned above, which can be expressed by the following formula:

[0061]

[0062] Then calculate W by the following formula q and W f The spectral similarity between w :

[0063] Among them, sum represents the addition function, that is, W q and W f The matrix elements in the matrix obtained after multiplication are added together, and the abs function is expressed as a modulo calculation as described above.

[0064] Finally, the spectrum similarity sim w As the similarity between the first model parameter W and the second model parameter.

[0065] It should be noted that the embodiment of the present application only provides one solution for calculating the similarity. In actual needs, other methods can also be used to calculate the similarity, and the present application does not limit this.

[0066] Combine the following Figure 3 , an overall introduction to the parameter quantization method of the model provided in this application is given, such as Figure 3 As shown, the parameter quantization method of the model provided in this application can be divided into four major steps: 1. Preparation steps before quantization; 2. Acquisition of candidate quantization parameters; 3. Acquisition of random input and calibration; 4. Selection of target quantization parameters from candidate quantization parameters.

[0067] Specifically, in step 1, the first model parameter W that needs to be quantized is obtained, the first model parameter W is represented by a matrix, and the first maximum value X of the matrix elements contained in W is obtained. max and the first minimum value X min ; Get the target quantization fixed-point bit number b, and determine the second maximum value Q of the quantization mapping range based on b max and the second minimum value Q min ; X max With X min The difference between max With Q min The ratio of is taken as the theoretical quantitative parameter scale, and combined with the theoretical quantitative parameter, X min and Q min Determine the zero value.

[0068] Step 2: determining a value range of the quantization parameter based on the theoretical quantization parameter scale, the first preset parameter, and the second preset parameter; The value range is evenly divided into any number of sub-value range intervals according to requirements, and the maximum value and the minimum value of each sub-value range interval are used as candidate quantization parameters.

[0069] Step 3, obtaining a random input for the target model, and converting the random input into a first random excitation signal, and then performing Fourier transform on the first random excitation signal a to obtain a corresponding first spectrum A; Performing a modulo operation on each matrix element included in the first spectrum A to obtain a spectrum matrix specA after modulo operation, then obtaining the largest matrix element in specA, and comparing each matrix element in specA with a preset ratio of the largest matrix element to respectively determine a calibration amplitude of each matrix element corresponding to the first spectrum A; Calibrate each corresponding matrix element in the first spectrum A based on the calibration amplitude of each matrix element to obtain a calibrated second spectrum; Perform an inverse Fourier transform on the second spectrum to obtain a calibrated second random activation signal.

[0070] Step 4: for each candidate quantization parameter, quantize the first model parameter W based on the candidate quantization parameter and the zero point value zerop to obtain a quantized second model parameter; Based on the second random excitation signal and the second model parameter, the first output of the debugging model is calculated by the original operation logic of the target model, and the first output is dequantized to obtain a second output represented by a floating point type; Based on the second random excitation signal and the first model parameter W, the third output of the initial model is calculated by the original operation logic of the target model; Calculate the mean square error between each second output and the third output and the spectrum similarity between each second model parameter and the first model parameter W; Determine the model error between each second model parameter and the first model parameter W based on the mean square error and the spectrum similarity; The model errors of all second outputs are compared, the candidate quantization parameter corresponding to the second model parameter with the minimum model error is used as the target quantization parameter, and the first model parameter W is adjusted to the second model parameter.

[0071] Figure 4 A structural block diagram of a model parameter quantization device provided in an embodiment of the present application, such as Figure 4 As shown, the model parameter quantization device 400 may include: a model parameter quantization target acquisition module 401, a theoretical quantization parameter acquisition module 402, a quantization parameter value range determination module 403, a model error determination module 404 and a model parameter adjustment module 405, wherein: The model parameter quantization target acquisition module 401 is used to obtain the first model parameter W of the initial model and the target quantization fixed-point number b, where the first model parameter W is a floating-point number; The theoretical quantization parameter acquisition module 402 is used to determine the theoretical quantization parameter scale for the first model parameter W based on the first model parameter W and the target quantization fixed-point bit number b, and determine the zero point value zerop based on the theoretical quantization parameter scale and the target quantization fixed-point bit number b; The quantization parameter value range determination module 403 is used to determine the value range of the target quantization parameter based on the theoretical quantization parameter scale; wherein the value range includes at least two candidate quantization parameters; The model error determination module 404 is used to quantize the first model parameter W for each candidate quantization parameter based on the candidate quantization parameter and the zero point value zerop to obtain the corresponding second model parameter, and determine the model error corresponding to the second model parameter; wherein the second model parameter is a fixed-point number; The model parameter adjustment module 405 is used to adjust the first model parameter W of the initial model to the second model parameter corresponding to the minimum model error.

[0072] The solution provided in the present application is to determine the target quantization parameter value range for the first model parameter W that can meet the target quantization fixed-point bit number b based on the known target quantization fixed-point bit number b, and then quantize each candidate quantization parameter in the value range one by one for the first model parameter W and calculate the model error that may be caused between the second model parameter obtained after each quantization and the original model, and finally select the second model parameter that minimizes the model error as the quantized model parameter, so as to improve the computational efficiency of the model itself while maintaining the accuracy of the model output.

[0073] Based on the above embodiments, as an optional embodiment, the first model parameter W includes a plurality of first matrix elements; the first matrix elements are floating-point elements; The theoretical quantitative parameter acquisition module is specifically used for: Get the first maximum value X in each first matrix element contained in the first model parameter W max and the first minimum value X min ; Based on the target quantization fixed-point bit number b, determine the quantization mapping range for the first model parameter W, and obtain the second maximum value Q of the quantization mapping range max and the second minimum value Q min ; Get the first maximum value X max With the first minimum value X min The first difference between the two and the second maximum value Q max With the second minimum value Q min The ratio of the first difference to the second difference is used as a theoretical quantization parameter scale; Determine the first minimum value X based on the theoretical quantization parameter scale min The quantization mapping value under the condition of the quantization fixed point number b, and based on the quantization mapping value and the second minimum value Q min Determine the zero point value zerop.

[0074] Based on the above embodiments, as an optional embodiment, the quantization parameter value range determination module is specifically used to: Obtaining a first preset parameter α which is less than a first preset value and a second preset parameter β which is greater than the first preset value; The theoretical quantization parameter scale is weighted by a first preset parameter α to obtain a first weighted result, and the first weighted result is used as the minimum value of the value range; The theoretical quantization parameter scale is weighted by a second preset parameter β to obtain a second weighted result, and the second weighted result is used as the maximum value of the value range; The minimum value of the value range is smaller than the theoretical quantization parameter scale, and the maximum value of the value range is larger than the theoretical quantization parameter scale.

[0075] Based on the above embodiments, as an optional embodiment, the device further includes a candidate quantization parameter acquisition module, which is specifically used to: The value range is evenly divided into a preset number of sub-ranges, and the maximum value of each sub-range is taken as a candidate quantization parameter.

[0076] Based on the above embodiments, as an optional embodiment, the model error determination module is specifically used to: Obtaining a random input for an initial model, and converting the random input into a first random excitation signal a; The first random excitation signal a is calibrated to obtain a second random excitation signal, and the second random excitation signal is input into the debugging model to obtain a first output of the debugging model; wherein the debugging model is a model obtained by replacing the first model parameter W of the initial model with the second model parameter; Dequantize the first output based on the candidate quantization parameter and the zero point value zerop to obtain a second output; Inputting the second random excitation signal into the initial model to obtain a third output of the initial model; The mean square error MSE of the second output and the third output, and the similarity between the first model parameter W and the second model parameter are obtained, and the mean square error MSE is weighted based on the similarity to obtain a third weighted result, and the third weighted result is used as the model error corresponding to the second model parameter.

[0077] Based on the above embodiments, as an optional embodiment, the model error determination module is further used to: Performing Fourier transform on the first random excitation signal a to obtain a first spectrum A corresponding to the first random excitation signal a; wherein the first spectrum A includes a plurality of second matrix elements; For each second matrix element in the first spectrum A, determine a calibration amplitude μ of the second matrix element, and calibrate the second matrix element based on the calibration amplitude μ to obtain a second spectrum after calibrating the first spectrum A; Perform inverse Fourier transform on the second frequency spectrum to obtain a calibrated second random excitation signal.

[0078] Based on the above embodiments, as an optional embodiment, the model error determination module can also be used to: Performing a modulo operation on each second matrix element included in the first spectrum A to obtain each third matrix element in the spectrum matrix specA after modulo operation, and obtaining the maximum value of each third matrix element; Acquire a third preset parameter which is less than the second preset value and a fourth preset parameter which is greater than the second preset value; If the third matrix element is less than the preset ratio of the maximum value, the third preset parameter is used as the calibration amplitude μ of the second matrix element; if the third matrix element is not less than the preset ratio of the maximum value, the fourth preset parameter is used as the calibration amplitude μ of the third matrix element; Among them, the third matrix element obtained after adjustment based on the third preset parameter is smaller than the original second matrix element, and the third matrix element obtained after adjustment based on the fourth preset parameter is larger than the original second matrix element.

[0079] Based on the above embodiments, as an optional embodiment, the model error determination module can also be used to: Get the third spectrum W of the second model parameters q , and obtain the fourth spectrum W of the first model parameter W f ; Wherein, the third spectrum W q and the fourth spectrum W f They are obtained by Fourier transform of the corresponding model parameters; Determine the third spectrum W q and the fourth spectrum W f The spectral similarity between w As the similarity between the first model parameter W and the second model parameter.

[0080] Reference below Figure 5 , which shows an electronic device suitable for implementing the embodiments of the present application (for example, Figure 1 The electronic device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), wearable devices, etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0081] The electronic device includes: a memory and a processor, the memory is used to store a program for executing the method described in each of the above method embodiments; the processor is configured to execute the program stored in the memory. The processor here can be referred to as the processing device 501 described below, and the memory can include at least one of the read-only memory (ROM) 502, the random access memory (RAM) 503, and the storage device 508 described below, as shown below: like Figure 5As shown, the electronic device 500 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 to a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device 500 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0082] Typically, the following devices may be connected to the I / O interface 505: an input device 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 508 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 509. The communication device 509 may allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 5 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0083] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 509, or installed from the storage device 508, or installed from the ROM 502. When the computer program is executed by the processing device 501, the above-mentioned functions defined in the method of the embodiment of the present application are executed.

[0084] It should be noted that the computer-readable storage medium mentioned above in the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.

[0085] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.

[0086] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0087] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: Obtain a first model parameter W of the initial model and a target quantization fixed-point bit number b, wherein the first model parameter W is a floating-point number; determine a theoretical quantization parameter scale for the first model parameter W based on the first model parameter W and the target quantization fixed-point bit number b, and determine a zero-point value zerop based on the theoretical quantization parameter scale and the target quantization fixed-point bit number b; determine a value range of the target quantization parameter based on the theoretical quantization parameter scale; wherein the value range includes at least two candidate quantization parameters; for each candidate quantization parameter, quantize the first model parameter W based on the candidate quantization parameter and the zero-point value zerop to obtain a corresponding second model parameter, and determine a model error corresponding to the second model parameter; wherein the second model parameter is a fixed-point number; adjust the first model parameter W of the initial model to the second model parameter corresponding to the minimum model error.

[0088] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0089] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0090] The modules or units involved in the embodiments of the present application may be implemented by software or hardware. The name of a module or unit does not limit the unit itself in some cases. For example, the first constraint acquisition module may also be described as a "module for acquiring the first constraint".

[0091] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.

[0092] In the context of the present application, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0093] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0094] The above descriptions are only some embodiments of the present invention. It should be pointed out that, for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for quantifying parameters of a model, characterized in that: include: Obtain a first model parameter W of the initial model and a target number of quantized fixed-point bits b, wherein the first model parameter W is a floating-point number; Determine a theoretical quantization parameter scale for the first model parameter W based on the first model parameter W and the target number of quantization fixed-point bits b, and determine a zero point value zerop based on the theoretical quantization parameter scale and the target number of quantization fixed-point bits b; Determining a value range of a target quantization parameter based on the theoretical quantization parameter scale; wherein the value range includes at least two candidate quantization parameters; For each candidate quantization parameter, quantize the first model parameter W based on the candidate quantization parameter and the zero point value zerop to obtain a corresponding second model parameter, and determine a model error corresponding to the second model parameter; wherein the second model parameter is a fixed-point number; The first model parameter W of the initial model is adjusted to the second model parameter corresponding to the minimum model error.

2. The method according to claim 1, characterized in that The first model parameter W includes a plurality of first matrix elements; the first matrix elements are floating point elements; The determining, based on the first model parameter W and the target number of quantization fixed-point bits b, of a theoretical quantization parameter scale for the first model parameter W includes: Obtain the first maximum value X of each first matrix element contained in the first model parameter W max and the first minimum value X min ; Based on the target quantization fixed-point bit number b, determine the quantization mapping range for the first model parameter W, and obtain the second maximum value Q of the quantization mapping range max and the second minimum value Q min ; Get the first maximum value X max With the first minimum value X min The first difference between max With the second minimum value Q min a second difference between the first difference and the second difference, and taking the ratio of the first difference to the second difference as the theoretical quantization parameter scale; The determining of the zero point value zerop based on the theoretical quantization parameter scale and the target quantization fixed point bit number b includes: Determine the first minimum value X based on the theoretical quantization parameter scale min The quantization mapping value under the condition of the quantization fixed-point bit number b, and based on the quantization mapping value and the second minimum value Q min The zero point value zerop is determined.

3. The method according to claim 1, characterized in that The determining a value range of a target quantization parameter based on the theoretical quantization parameter scale includes: Obtaining a first preset parameter α which is less than a first preset value and a second preset parameter β which is greater than the first preset value; The theoretical quantization parameter scale is weighted by the first preset parameter α to obtain a first weighted result, and the first weighted result is used as the minimum value of the value range; The theoretical quantization parameter scale is weighted by the second preset parameter β to obtain a second weighted result, and the second weighted result is used as the maximum value of the value range; The minimum value of the value range is smaller than the theoretical quantization parameter scale, and the maximum value of the value range is larger than the theoretical quantization parameter scale.

4. The method according to claim 1, characterized in that Each candidate quantization parameter is obtained in the following manner: The value range is evenly divided into a preset number of sub-ranges, and the maximum value of each sub-range is used as the candidate quantization parameter.

5. The method according to claim 1, characterized in that The determining the model error corresponding to the second model parameter includes: Obtaining a random input for the initial model, and converting the random input into a first random excitation signal a; Calibrate the first random excitation signal a to obtain a second random excitation signal, and input the second random excitation signal into a debugging model to obtain a first output of the debugging model; wherein the debugging model is a model obtained by replacing the first model parameter W of the initial model with the second model parameter; Dequantize the first output based on the candidate quantization parameter and the zero point value zerop to obtain a second output; Inputting the second random excitation signal into the initial model to obtain a third output of the initial model; Obtain the mean square error MSE between the second output and the third output, and the similarity between the first model parameter W and the second model parameter, and weight the mean square error MSE based on the similarity to obtain a third weighted result, and use the third weighted result as the model error corresponding to the second model parameter.

6. The method according to claim 5, characterized in that The step of calibrating the first random excitation signal a to obtain a second random excitation signal includes: Performing Fourier transform on the first random excitation signal a to obtain a first spectrum A corresponding to the first random excitation signal a; wherein the first spectrum A includes a plurality of second matrix elements; For each second matrix element in the first spectrum A, determine a calibration amplitude μ of the second matrix element, and calibrate the second matrix element based on the calibration amplitude μ to obtain a second spectrum after calibrating the first spectrum A; Perform inverse Fourier transform on the second frequency spectrum to obtain the calibrated second random excitation signal.

7. The method according to claim 6, characterized in that Each second matrix element in the first spectrum A is an imaginary number; The determining of the calibration amplitude μ of the second matrix element comprises: Performing a modulo operation on each second matrix element included in the first spectrum A to obtain each third matrix element in the spectrum matrix specA after modulo operation, and obtaining the maximum value of each third matrix element; Acquire a third preset parameter which is less than the second preset value and a fourth preset parameter which is greater than the second preset value; If the third matrix element is less than the preset ratio of the maximum value, the third preset parameter is used as the calibration amplitude μ of the second matrix element; if the third matrix element is not less than the preset ratio of the maximum value, the fourth preset parameter is used as the calibration amplitude μ of the third matrix element; Among them, the third matrix element obtained after adjustment based on the third preset parameter is smaller than the original second matrix element, and the third matrix element obtained after adjustment based on the fourth preset parameter is larger than the original second matrix element.

8. The method according to claim 5, characterized in that The obtaining of the mean square error MSE between the second output and the third output, and the similarity between the first model parameter W and the second model parameter includes: Get the third spectrum W of the second model parameter q , and obtain the fourth spectrum W of the first model parameter W f ; Wherein, the third spectrum W q and the fourth spectrum W f They are obtained by Fourier transform of the corresponding model parameters; Determine the third spectrum W q and the fourth spectrum W f The spectral similarity between w As the similarity between the first model parameter W and the second model parameter.

9. A model parameter quantization device, characterized in that: include: A model parameter quantization target acquisition module is used to obtain a first model parameter W of the initial model and a target quantization fixed-point number b, wherein the first model parameter W is a floating-point number; a theoretical quantization parameter acquisition module, configured to determine a theoretical quantization parameter scale for the first model parameter W based on the first model parameter W and the target number of quantization fixed-point bits b, and determine a zero point value zerop based on the theoretical quantization parameter scale and the target number of quantization fixed-point bits b; A quantization parameter value range determination module, used to determine a value range of a target quantization parameter based on the theoretical quantization parameter scale; wherein the value range includes at least two candidate quantization parameters; a model error determination module, configured to quantize the first model parameter W for each candidate quantization parameter based on the candidate quantization parameter and the zero point value zerop to obtain a corresponding second model parameter, and determine a model error corresponding to the second model parameter; wherein the second model parameter is a fixed-point number; The model parameter adjustment module is used to adjust the first model parameter W of the initial model to a second model parameter corresponding to the minimum model error.

10. An electronic device comprising a memory, a processor and a computer program stored in the memory, characterized in that: The processor executes the computer program to implement the steps of the method according to any one of claims 1 to 8.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Cited By

  • Model quantification method, device, equipment, medium and product

    CN122222049A