Network model dynamic quantification method and apparatus, terminal device, and readable storage medium
By using a dynamic quantization method to quantize the network model trained on point cloud data, the performance loss problem when the model is deployed on edge devices using point cloud data input is solved, and the efficient deployment and performance improvement of the model on resource-constrained devices are achieved.
Patent Information
- Application Number
- CN202411098734.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-09
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2044-08-09
AI Technical Summary
When existing technologies directly apply quantization methods used for RGB image data to radar point cloud data, it results in severe performance loss for 3D LiDAR detectors when deployed on edge devices, failing to effectively utilize the sparsity and irregular distribution characteristics of point cloud data.
A network search method is used to dynamically quantize the network model trained on point cloud data. By dynamically adjusting the parameter range and quantization cutoff interval in each round of search, candidate quantization scaling factors are calculated, and the quantization scaling factor with the minimum quantization error is found to reduce quantization error.
It effectively reduces quantization errors when converting from full-precision models to low-precision models, improves the overall performance of point cloud data input models, and is suitable for deployment on resource-constrained edge devices.
Smart Images

Figure CN119089951B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of model quantization technology, and in particular to a method, apparatus, terminal device and readable storage medium for dynamic quantization of network models. Background Technology
[0002] Model quantization is an effective solution for deploying neural network models on resource-constrained edge devices. Model quantization is a way to compress network parameters by replacing floating-point values such as activation feature maps and weight parameters with fixed-point (integer) values. During computation, the fixed-point data is then dequantized back to floating-point data to obtain the result.
[0003] Currently, most neural network models are input to RGB (color) image data, and quantization research on this type of neural network is also the most extensive. However, for radar point cloud data, due to the difference in statistical distribution characteristics between it and RGB image data, when quantization methods that perform well in models using RGB image data as input are directly transferred to models using radar point cloud data as input, significant performance loss can easily occur. This presents a new challenge for deploying 3D LiDAR-based detectors on edge devices. Summary of the Invention
[0004] In view of this, embodiments of this application provide a method, apparatus, terminal device, and readable storage medium for dynamic quantization of network models, which can effectively improve the performance loss of the quantized model.
[0005] In a first aspect, embodiments of this application provide a method for dynamic quantization of a network model, including: Obtain all model parameters and quantization accuracy of the network model trained based on point cloud data; The parameter quantization range is determined based on the quantization accuracy, and the initial parameter range is determined based on all the model parameters. During each search round, the quantization cutoff interval for this search round is determined based on the current parameter range and the set number of grid searches. Based on the quantization precision and the quantization cutoff interval, the candidate quantization scaling factor for this search round is calculated, and the quantization error of all model parameters under the candidate quantization scaling factor is calculated based on the parameter quantization range. When the quantization error is less than the quantization error threshold, the initial parameter range or the parameter range of the previous search round is updated using the quantization cutoff interval for this search round. Based on the quantization error obtained in each round of search, a target quantization scaling factor that minimizes the quantization error is determined, and the quantized network model is determined based on the target quantization scaling factor.
[0006] In some embodiments, the network model dynamic quantization method further includes: When the quantization error during the current search is less than the quantization error threshold, the current quantization error threshold is updated using the quantization error during the current search.
[0007] In some embodiments, calculating the quantization error of all model parameters under the candidate quantization scaling factor based on the parameter quantization range includes: Based on the quantization range of the parameters and the pre-quantization value of each model parameter, calculate the post-quantization value of each model parameter under the candidate quantization scaling factor; Calculate the quantization error of all model parameters in this search round based on the pre-quantization and post-quantization values of each model parameter.
[0008] In some embodiments, calculating the post-quantization value of each model parameter under the candidate quantization scaling factor based on the parameter quantization range and the pre-quantization value of each model parameter includes: Based on the quantization range of the parameters, the ratio of the pre-quantization value of the corresponding model parameters to the candidate quantization scaling factor is clipped to obtain the clipping error. Based on the clipping error and the zero-point offset during quantization, calculate the quantized values of the corresponding model parameters under the candidate quantization scaling factor. Specifically, when using symmetric quantization, the zero-point offset is zero; when using asymmetric quantization, the zero-point offset is a non-zero value.
[0009] In some embodiments, the formula for calculating the quantized value is: ; In the formula, x and This indicates the values of the corresponding model parameters before and after quantization. s This represents the candidate quantization scaling factor. q min and q max This represents the minimum and maximum values of the quantization range of the parameter; z is the zero-point offset, and the function... clamp() This indicates that the clipping value exceeds the quantization range of the parameter.
[0010] In some embodiments, determining the quantization cutoff interval for the current search round based on the current parameter range and the set number of grid searches includes: Calculate the ratio of the maximum value in the current parameter range to the number of grid searches, and multiply the ratio by the current search sequence number to obtain the quantization cutoff value for this round of search; The positive and negative values of the quantization cutoff value are selected as the two boundary values of the quantization cutoff interval to obtain the quantization cutoff interval for this search.
[0011] In some embodiments, the formula for calculating the candidate quantization scaling factor is: ; In the formula, s This represents the candidate quantization scaling factor. x min and x max denoted by b, which represents the lower and upper boundary values of the quantization cutoff interval, and b represents the quantization precision.
[0012] Secondly, embodiments of this application provide a network model dynamic quantization device, comprising: The data acquisition module is used to acquire all model parameters and quantization accuracy of the network model trained based on point cloud data; The range determination module is used to determine the parameter quantization range based on the quantization accuracy, and to determine the initial parameter range based on all the model parameters; The network search module is used to determine the quantization cutoff interval for each round of search based on the current parameter range and the set number of grid searches, calculate the candidate quantization scaling factor for the current round of search based on the quantization accuracy and the quantization cutoff interval, and calculate the quantization error of all model parameters under the candidate quantization scaling factor based on the parameter quantization range. When the quantization error is less than the quantization error threshold, the initial parameter range or the parameter range of the previous round of search is updated using the quantization cutoff interval for the current round of search. The model quantization module is used to determine a target quantization scaling factor that minimizes the quantization error obtained in each round of search, and to determine the quantized network model based on the target quantization scaling factor.
[0013] Thirdly, embodiments of this application provide a terminal device, the terminal device including a processor and a memory, the memory storing a computer program, and the processor executing the computer program to implement the network model dynamic quantization method described above.
[0014] Fourthly, embodiments of this application provide a computer-readable storage medium storing a computer program that, when executed on a processor, implements the aforementioned network model dynamic quantization method.
[0015] The embodiments of this application have the following beneficial effects: The dynamic quantization method for network models proposed in this application is based on the post-training quantization principle. It uses a network search method to dynamically quantize the network model trained on point cloud data. In each search round, the quantization cutoff interval for each search round is determined based on the current parameter range and the number of grid searches. This interval is then used to calculate the candidate quantization scaling factor for each search round. When the quantization error meets the threshold condition, the current parameter range is updated to serve as the basis for the next search round. By iteratively calculating, the quantization scaling factor that minimizes the loss of model accuracy is found to obtain a quantized model that meets the requirements. This quantized model is beneficial for deploying complex network models on resource-constrained terminal devices. Attached Figure Description
[0016] To more clearly illustrate the technical solutions of the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of this application and should not be regarded as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This illustrates a schematic diagram of point cloud data; Figure 2 This is another schematic diagram showing point cloud data containing vehicle targets; Figure 3 A schematic diagram of a terminal device according to an embodiment of this application is shown; Figure 4 A flowchart of the network model dynamic quantization method according to an embodiment of this application is shown; Figure 5 A flowchart illustrating the quantization error calculation in an embodiment of this application is shown; Figure 6 A schematic diagram of a network model dynamic quantization device according to an embodiment of this application is shown. Detailed Implementation
[0018] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.
[0019] The components of the embodiments of this application described and illustrated in the accompanying drawings can be arranged and designed in a variety of different configurations. Therefore, the following detailed description of the embodiments of this application provided in the drawings is not intended to limit the scope of the claimed application, but merely to illustrate selected embodiments of the application. All other embodiments obtained by those skilled in the art based on the embodiments of this application without inventive effort are within the scope of protection of this application.
[0020] In the following text, the terms "comprising," "having," and their cognates, which may be used in various embodiments of this application, are intended only to indicate a particular feature, number, step, operation, element, component, or combination thereof, and should not be construed as primarily excluding the presence of one or more other features, numbers, steps, operations, elements, components, or combinations thereof, or adding the possibility of one or more combinations thereof. Furthermore, the terms "first," "second," "third," etc., are used only for distinguishing descriptions and should not be construed as indicating or implying relative importance.
[0021] Unless otherwise specified, all terms used herein (including technical and scientific terms) shall have the same meaning as commonly understood by one of ordinary skill in the art to which the various embodiments of this application pertain. Terms (such as those defined in commonly used dictionaries) shall be interpreted as having the same meaning as in their contextual meaning in the relevant technical field and shall not be construed as having an idealized or overly formal meaning, unless clearly defined in the various embodiments of this application.
[0022] The following detailed description of some embodiments of this application is provided in conjunction with the accompanying drawings. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0023] In an RGB image, each pixel represents information. However, in a point cloud image, for example... Figure 1 The image shown is a point cloud image acquired by a LiDAR scanner. It can be understood that the areas scanned by the LiDAR are gray areas (non-zero pixels), which contain information, while the white background (zero pixels) contains no information. As can be seen from this image, unlike the information-dense RGB image, the information density of point cloud data is sparse; its non-zero pixels occupy only a very limited portion of the entire scene, exhibiting an irregular distribution. Furthermore, there is an imbalance between foreground instances and large redundant background areas in the point cloud; for example, ... Figure 2As shown, the boxes represent targets detected by the radar (in this case, vehicles). For example, a 4m × 2m vehicle occupies only 40 × 20 pixels in the input 1504 × 1504 BEV feature map. In other words, the size of the box occupied by the target to be detected is very small compared to the overall point cloud image. Furthermore, the point cloud data acquired by 3D radar has a large computational range. For example, the coordinates of voxelized points are located in a 1504 × 1504 × 40 3D space with a voxel size of 0.1m, making them more susceptible to quantization effects. In other words, the larger the quantization error, the greater the impact on the computational results.
[0024] Due to the sparsity and irregular distribution of point cloud data, performance loss can easily occur when quantizing neural network models. To address this, this application proposes a dynamic quantization method for network models based on network search, which is based on the Post-Training Quantization (PTQ) principle. This method effectively reduces the quantization error when converting a full-precision model to a low-precision model, thereby improving the performance loss of quantized models with point cloud data as input and enhancing the overall performance of the model.
[0025] Please refer to Figure 3 This is a schematic diagram of the structure of a terminal device proposed in an embodiment of this application. It is understood that this terminal device has limited hardware resources and can be an edge device, including but not limited to vehicles, robots, etc. Exemplarily, the terminal device 10 may include a memory 11, a processor 12, and a sensing unit 13. Both the memory 11 and the sensing unit 13 are connected to the processor 12. The sensing unit 13 can be used to sense the current environmental information of the terminal device 10. The memory 11 stores a computer program, and the processor 12 is used to execute the computer program to implement the network model dynamic quantization method of this application embodiment, so as to improve the performance loss of the quantized model.
[0026] The memory 11 may be, but is not limited to, random access memory (RAM), read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), etc. The memory 11 is used to store computer programs, and the processor 12 can execute the computer programs accordingly after receiving execution instructions.
[0027] Processor 12 can be an integrated circuit chip with signal processing capabilities. Processor 12 can be a general-purpose processor, including at least one of a Central Processing Unit (CPU), Graphics Processing Unit (GPU), Network Processor (NP), Digital Signal Processor (DSP), Application-Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The general-purpose processor can be a microprocessor or any conventional processor, capable of implementing or executing the methods, steps, and logic block diagrams disclosed in the embodiments of this application.
[0028] The sensing unit 13 transmits perceived external environmental information to the control system of the terminal device 10 for processing. For example, the sensing unit 13 may include a lidar sensor, the type of which is not limited. It can be used to obtain information about people / objects in the surrounding environment during the terminal device 10's movement, thereby obtaining information such as target distance, but is not limited to this information. Furthermore, the sensing unit 13 may also include a visual imaging device, which can be used to acquire RGB image information of the terminal device 10 during its movement. It is understood that the configuration of the sensing unit 13 is determined based on the specific usage scenario of the terminal device 10, and is not strictly limited here.
[0029] Based on the terminal device 10 with the above structure, the dynamic quantization method of the network model will be described below with reference to some specific embodiments.
[0030] Figure 4 A flowchart of a network model dynamic quantization method according to an embodiment of this application is shown. Exemplarily, the network model dynamic quantization method includes the following steps: S110 obtains all model parameters and quantization accuracy of the network model trained based on point cloud data.
[0031] It is understood that this application calibrates the model quantization process using a small amount or no additional data on a trained network model; in other words, it performs dynamic quantization based on post-training quantization (PTQ) technology. Post-training dynamic quantization can directly convert the parameters of each layer in the network using quantization formulas without using a calibration dataset. In the embodiments of this application, the aforementioned model parameters are the weight parameters.
[0032] Model quantization is the process of quantizing full-precision floating-point model parameters into low-precision integer data format. Quantization precision refers to the bit width of the quantized integer; for example, the quantization precision of integer 'int4' is 4 bits, and that of 'int8' is 8 bits.
[0033] Due to the inherent sparsity of point cloud data, its corresponding quantization range varies greatly. These differences often contain a large amount of geometric information; in other words, point cloud data frequently contains outlier data points. Direct quantization would reduce the effective number of quantization grid points, leading to significant accuracy loss. Therefore, this application utilizes a lightweight grid search technique to eliminate the influence of outlier data points. Consequently, this application also requires pre-setting the range of hyperparameter values to be set in the grid search, denoted here as the grid search count T. This can be understood as dividing the original model parameter data into T equal groups and finding the quantization scaling factor that minimizes the quantization error through iterative traversal.
[0034] S120 determines the parameter quantization range based on quantization accuracy and determines the initial parameter range based on all model parameters.
[0035] The quantization range is typically determined by the bit width, including the minimum and maximum values of the quantization range. For example, for an int8 integer data type with symmetric positive and negative values, q min =-2^8 / 2=-128, q max =2^8 / 2-1=127, meaning the parameter quantization range is (-128, 127). It can be understood that this parameter quantization range can be specifically determined based on the actual integer type.
[0036] For network models that take point cloud data as input, the distribution range of their model parameters is wide, but the maximum and minimum values of the model weights do not necessarily cover the entire range. Therefore, this application proposes to use the actual effective parameter range for quantization, which can reduce the accuracy loss in the quantization process.
[0037] For example, for the initial search, the maximum absolute value among all model parameters (denoted as max(|x|)) is selected, and the positive and negative values of this maximum absolute value are used as the initial maximum values of the parameter range (i.e., denoted as...). x max= max(|x|) and minimum value (i.e., denoted as) x min=- max(|x|). It's understandable that the quantization scale is different each time a search is performed, therefore the parameter range will be dynamically updated for each search.
[0038] S130, during each round of search, the quantization cutoff interval for this round of search is determined based on the current parameter range and the set number of grid searches. Based on the quantization accuracy and the quantization cutoff interval, the candidate quantization scaling factor for this round of search is calculated, and the quantization error of all model parameters under the candidate quantization scaling factor is calculated based on the parameter quantization range. When the quantization error is less than the quantization error threshold, the initial parameter range or the parameter range of the previous round of search is updated using the quantization cutoff interval for this round of search.
[0039] This embodiment dynamically determines the quantization cutoff interval for each round of search based on the current parameter range and the set number of grid searches, and then uses the quantization cutoff interval to update the parameter range.
[0040] In one exemplary implementation, the ratio of the maximum value in the current parameter range to the number of grid searches can be calculated. This ratio is then multiplied by the current search index to obtain the quantization cutoff value for this search round. Furthermore, the positive and negative values of this quantization cutoff value are selected as the two boundary values of the quantization cutoff interval to obtain the quantization cutoff interval for this search. It can be understood that the cutoff value represents normalizing all data outside the current parameter range to boundary values.
[0041] For example, if described by an expression, the formula for calculating the quantization cutoff value is: threhold = range / T * i, In the formula, `threhold` is the quantization cutoff value in the i-th search round, `range` is the maximum value in the parameter range in the i-th search round, and `i` represents the search index; for example, `i=1` in the first search round and `i=2` in the second search round. Furthermore, according to... x min =- threshold, x max = threshold, to obtain the lower boundary value of the quantization cutoff interval. x min and upper boundary value x max .
[0042] For example, assuming all model parameters are distributed in the range of 1-1000, and the model parameters are mainly concentrated in the range of 200-800, this application uses a grid search algorithm to avoid the influence of the difference values. Specifically, assuming the number of grid searches is 10 and the parameter quantization range is (-128, 127), then each quantization grid corresponds to a quantization cutoff interval, and the cutoff value can be calculated by the above formula.
[0043] It is understandable that the conversion formula between floating-point numbers and fixed-point (integer) numbers (i.e., the quantization formula) requires the use of two coefficients for conversion: the quantization scaling factor s (i.e., scale) and the quantization zero offset z (i.e., zero).
[0044] It is worth noting that if symmetric quantization is used, the zero-point offset z is zero; conversely, if asymmetric quantization is used, the zero-point offset will be a non-zero value. In this embodiment, symmetric quantization will be used to explain the dynamic quantization method.
[0045] During the grid search process, the quantization scaling factor calculated in each round of search is recorded as a candidate quantization scaling factor, so as to distinguish it from the target quantization scaling factor that minimizes the quantization error selected from these candidate quantization scaling factors.
[0046] In one implementation, the quantization scaling factor is calculated using the boundary values of the quantization cutoff interval at each search round. For example, if described by an expression, the formula for calculating the candidate quantization scaling factor at each search round is: ; In the formula, s This represents the candidate quantization scaling factor during this round of search. x min and x max This represents the lower and upper boundary values of the quantization cutoff interval during this search round, where b is the quantization precision.
[0047] After calculating the candidate quantization scaling factor, the error of each model parameter before and after quantization will be further calculated.
[0048] In one implementation, such as Figure 5 As shown, the quantization error of all model parameters under the candidate quantization scaling factor is calculated, including the following steps: S210, based on the parameter quantization range and the pre-quantization value of each model parameter, calculate the post-quantization value of each model parameter under the candidate quantization scaling factor.
[0049] As an example, the ratio of the pre-quantization value of the corresponding model parameter to the candidate quantization scaling factor can be cropped according to the parameter quantization range to obtain the cropping error. Then, based on the cropping error and the zero-point offset during quantization, the post-quantization value of the corresponding model parameter under the candidate quantization scaling factor is calculated. It can be understood that the pre-quantization value of the model parameter is determined after the network model training is completed, while the post-quantization value can be calculated using the quantization formula. Depending on the quantization formula, it can be divided into linear quantization and nonlinear quantization. Here, linear quantization is mainly used as an example for explanation.
[0050] For example, if described by an expression, the formula for calculating the quantized value of a single model parameter is:
[0051] In the formula, x and This indicates the values of the corresponding model parameters before and after quantization. s Indicates the candidate quantization scaling factor. q min and q max This represents the minimum and maximum values of the parameter quantization range; z is the zero-point offset, the function clamp() This indicates a value that is clipped beyond the range of the parameter quantization.
[0052] S220: Calculate the quantization error of all model parameters in this search round based on the pre-quantization and post-quantization values of each model parameter.
[0053] As an example, the quantization error of each model parameter is obtained by subtracting the pre-quantization and post-quantization values of each model parameter, and then the sum of the quantization errors of all model parameters is calculated.
[0054] As an optional approach, the method further includes: When the quantization error in each search round is less than the quantization error threshold, the current quantization error threshold is updated using the quantization error from each search round. Conversely, if the quantization error is not less than the quantization error threshold, no update is made. The initial value of the quantization error threshold can be set based on practical experience. Then, in subsequent search processes, the quantization error threshold can be updated to accelerate the search speed.
[0055] S140, based on the quantization error obtained in each round of search, determine the target quantization scaling factor that minimizes the quantization error, and determine the quantized network model based on the target quantization scaling factor.
[0056] Multiple quantization errors can be calculated through multiple rounds of searching. To find the optimal quantization scaling factor that minimizes the accuracy loss, an objective optimal function can be constructed. For example, a L2 function can be used to construct a score to evaluate the quantization error under the current quantization scaling factor. It can be understood that the objective optimal function mentioned above is not limited to using the L2 function; it only needs to be able to evaluate the quantization accuracy loss obtained in each search.
[0057] In one implementation, the L2 norm is used to obtain the minimum value of the quantization error, i.e.:
[0058] In the formula, X and This represents the pre-quantization and post-quantization values of all model parameters; S t This represents the candidate quantization scaling factor at the t-th round of search.
[0059] Once an optimal quantization scaling factor is determined, the quantization formula can be used to calculate the quantized values of each model parameter, resulting in the quantized network model. This quantized network model is then deployed on terminal devices such as those equipped with LiDAR. After the LiDAR collects point cloud data, the deployed model can be dequantized and used for point cloud numerical control processing. It can be understood that by employing the aforementioned dynamic quantization method, the performance loss of point cloud data after model quantization can be effectively mitigated, thereby improving the overall performance of the model.
[0060] This application proposes a dynamic quantization method for network models. It employs a network search method to dynamically quantize the network model trained on point cloud data, i.e., quantization is performed based on post-training quantization principles. Furthermore, in each search round, the quantization cutoff interval is determined based on the current parameter range, and candidate quantization scaling factors are calculated for each round. When the quantization error meets a threshold condition, the current parameter range is updated, i.e., the parameter range is dynamically adjusted to select the most effective parameters from the model parameters as the basis for the next search round. This iterative calculation finds the quantization scaling factor that minimizes the loss of model accuracy. This method reduces rounding errors when converting from a full-precision model to a low-precision model and improves the performance of the quantized model.
[0061] Figure 6 A schematic diagram of a network model dynamic quantization device 100 according to an embodiment of this application is shown. Exemplarily, the network model dynamic quantization device 100 includes: The data acquisition module 110 is used to acquire all model parameters and quantization accuracy of the network model trained based on point cloud data.
[0062] The range determination module 120 is used to determine the parameter quantization range based on the quantization accuracy, and to determine the initial parameter range based on all the model parameters.
[0063] The network search module 130 is used to determine the quantization cutoff interval for each round of search based on the current parameter range and the set number of grid searches, calculate the candidate quantization scaling factor for the current round of search based on the quantization accuracy and the quantization cutoff interval, and calculate the quantization error of all model parameters under the candidate quantization scaling factor based on the parameter quantization range. When the quantization error is less than the quantization error threshold, the initial parameter range or the parameter range of the previous round of search is updated using the quantization cutoff interval for the current round of search.
[0064] The model quantization module 140 is used to determine a target quantization scaling factor that minimizes the quantization error based on the quantization error obtained in each round of search, so as to determine the quantized network model based on the target quantization scaling factor.
[0065] In some alternative embodiments, the network model dynamic quantization device 100 further includes: The error threshold update module is used to update the current quantization error threshold by using the quantization error of the current search when the quantization error calculated by the network search module 130 in the current search is less than the quantization error threshold.
[0066] As an optional implementation, the network search module 130 includes a truncation interval unit, a scaling factor calculation unit, a quantization error calculation unit, and a parameter range update unit. The truncation interval unit is used to determine the quantization truncation interval for the current search based on the current parameter range and a set number of grid searches. The scaling factor calculation unit is used to calculate candidate quantization scaling factors for the current search based on the quantization accuracy and the quantization truncation interval. The quantization error calculation unit is used to calculate the quantization error of all model parameters under the candidate quantization scaling factors based on the parameter quantization range. The parameter range update unit is used to update the initial parameter range or the parameter range from the previous search using the quantization truncation interval for the current search when the quantization error is less than a quantization error threshold.
[0067] Furthermore, the quantization error calculation unit includes a quantization value calculation subunit and an error calculation subunit. The quantization value calculation subunit is used to calculate the quantization value of each model parameter under the candidate quantization scaling factor based on the parameter quantization range and the pre-quantization value of each model parameter. The error calculation subunit is used to calculate the quantization error of all model parameters in this round of search based on the pre-quantization value and the post-quantization value of each model parameter.
[0068] Further, the quantization calculation subunit is specifically used to: clip the ratio of the pre-quantization value of the corresponding model parameter to the candidate quantization scaling factor according to the parameter quantization range, to obtain a clipping error; then, based on the clipping error and the zero-point offset during quantization, calculate the quantized value of the corresponding model parameter under the candidate quantization scaling factor. Wherein, when using symmetric quantization, the zero-point offset is zero; when using asymmetric quantization, the zero-point offset is a non-zero value.
[0069] As an optional implementation, the truncation interval unit is specifically used to calculate the ratio of the maximum value in the current parameter range to the number of grid searches, multiply the ratio by the current search sequence number to obtain the quantization truncation value for the current search; then, select the positive and negative values of the quantization truncation value as the two boundary values of the quantization truncation interval to obtain the quantization truncation interval for the current search.
[0070] It is understood that the apparatus in this embodiment corresponds to the network model dynamic quantization method in the above embodiments, and the options in the above embodiments are also applicable to this embodiment, so they will not be described again here.
[0071] This application also provides a computer-readable storage medium for storing the computer program used in the aforementioned terminal device. For example, the computer-readable storage medium may include, but is not limited to, various media capable of storing program code, such as a USB flash drive, a portable hard drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0072] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can also be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the architecture, functionality, and operation of possible implementations of apparatus, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that, in alternative implementations, the functions marked in the blocks may occur in a different order than those marked in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.
[0073] In addition, the functional modules or units in the various embodiments of this application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0074] If the aforementioned functions are implemented as software functional modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a smartphone, personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application.
[0075] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.
Claims
1. A method for dynamic quantization of network models, characterized in that, include: Obtain all model parameters and quantization accuracy of the network model trained based on point cloud data; The parameter quantization range is determined based on the quantization accuracy, and the initial parameter range is determined based on all the model parameters. During each search round, the quantization cutoff interval for this search round is determined based on the current parameter range and the set number of grid searches. Based on the quantization precision and the quantization cutoff interval, a candidate quantization scaling factor is calculated for this search round. The quantization error of all model parameters under the candidate quantization scaling factor is calculated based on the parameter quantization range. When the quantization error is less than the quantization error threshold, the initial parameter range or the parameter range from the previous search round is updated using the quantization cutoff interval for this search round. The determination of the quantization cutoff interval based on the current parameter range and the set number of grid searches includes: calculating the ratio of the maximum value in the current parameter range to the number of grid searches; multiplying the ratio by the current search index to obtain the quantization cutoff value for this search round; and selecting the positive and negative values of the quantization cutoff value as the two boundary values of the quantization cutoff interval to obtain the quantization cutoff interval for this search round. Based on the quantization error obtained in each round of search, a target quantization scaling factor that minimizes the quantization error is determined, and the quantized network model is determined based on the target quantization scaling factor.
2. The network model dynamic quantization method according to claim 1, characterized in that, Also includes: When the quantization error during the current search is less than the quantization error threshold, the current quantization error threshold is updated using the quantization error during the current search.
3. The dynamic quantization method for network models according to claim 1, characterized in that, The step of calculating the quantization error of all model parameters under the candidate quantization scaling factor based on the parameter quantization range includes: Based on the quantization range of the parameters and the pre-quantization value of each model parameter, calculate the post-quantization value of each model parameter under the candidate quantization scaling factor; Calculate the quantization error of all model parameters in this search round based on the pre-quantization and post-quantization values of each model parameter.
4. The network model dynamic quantization method according to claim 3, characterized in that, The step of calculating the post-quantization value of each model parameter under the candidate quantization scaling factor based on the parameter quantization range and the pre-quantization value of each model parameter includes: Based on the quantization range of the parameters, the ratio of the pre-quantization value of the corresponding model parameters to the candidate quantization scaling factor is clipped to obtain the clipping error. Based on the clipping error and the zero-point offset during quantization, calculate the quantized values of the corresponding model parameters under the candidate quantization scaling factor. Specifically, when using symmetric quantization, the zero-point offset is zero; when using asymmetric quantization, the zero-point offset is a non-zero value.
5. The network model dynamic quantization method according to claim 4, characterized in that, The formula for calculating the quantized value is: ; In the formula, x and This indicates the values of the corresponding model parameters before and after quantization. s This represents the candidate quantization scaling factor. q min and q max This represents the minimum and maximum values of the quantization range of the parameter; z is the zero-point offset, and the function... clamp() This indicates that the clipping value exceeds the quantization range of the parameter.
6. The dynamic quantization method for network models according to claim 1, characterized in that, The formula for calculating the candidate quantization scaling factor is as follows: ; In the formula, s This represents the candidate quantization scaling factor. x min and x max denoted by b, which represents the lower and upper boundary values of the quantization cutoff interval, and b represents the quantization precision.
7. A dynamic quantization device for a network model, characterized in that, include: The data acquisition module is used to acquire all model parameters and quantization accuracy of the network model trained based on point cloud data; The range determination module is used to determine the parameter quantization range based on the quantization accuracy, and to determine the initial parameter range based on all the model parameters; A network search module is used to determine the quantization cutoff interval for each search round based on the current parameter range and the set number of grid searches. Based on the quantization precision and the quantization cutoff interval, it calculates the candidate quantization scaling factor for the current search round and calculates the quantization error of all model parameters under the candidate quantization scaling factor based on the parameter quantization range. When the quantization error is less than the quantization error threshold, it updates the initial parameter range or the parameter range from the previous search round using the quantization cutoff interval for the current search round. The determination of the quantization cutoff interval based on the current parameter range and the set number of grid searches includes: calculating the ratio of the maximum value in the current parameter range to the number of grid searches; multiplying the ratio by the current search index to obtain the quantization cutoff value for the current search round; and selecting the positive and negative values of the quantization cutoff value as the two boundary values of the quantization cutoff interval to obtain the quantization cutoff interval for the current search round. The model quantization module is used to determine a target quantization scaling factor that minimizes the quantization error obtained in each round of search, and to determine the quantized network model based on the target quantization scaling factor.
8. A terminal device, characterized in that, The terminal device includes a processor and a memory, the memory storing a computer program, and the processor executing the computer program to implement the network model dynamic quantization method according to any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed on a processor, implements the network model dynamic quantization method according to any one of claims 1-6.
