Model quantization method and apparatus, electronic device, and storage medium
By evaluating and jointly quantifying module pairs with large capability differences between adjacent modules, the problem of quantization loss oscillation and accuracy gap in the post-training quantization method is solved, and the quantization accuracy and model compression performance are improved.
Patent Information
- Application Number
- PCT/CN2024/081245
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-13
- Filing Date
- 2024-03-12
- Publication Date
- 2024-09-19
AI Technical Summary
There is a large accuracy gap between the quantized model obtained by quantization after training and the full-precision model, and there is the problem of quantization loss oscillation, which affects the quantization accuracy.
By determining the capability index of each module in the model to be quantified, calculating the capability difference between adjacent modules, and selecting module pairs with large differences for joint quantification to reduce quantization loss oscillation.
The quantization accuracy of the post-training quantization method is improved, the quantization loss oscillation is reduced, and the compression performance of the model is enhanced.
Smart Images

Figure CN2024081245_19092024_PF_FP_ABST
Abstract
Description
Model quantization method, device, electronic device and storage medium
[0001] CROSS-REFERENCE TO RELATED APPLICATIONS
[0002] This application claims priority to the Chinese patent application filed with the State Intellectual Property Office of China on March 13, 2023, with application number 202310259827.3 and invention name “A model quantization method, device, electronic device and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field
[0003] The embodiments of the present disclosure relate to the field of computer technology, and in particular to a model quantization method, device, electronic device, and storage medium. Background Art
[0004] Post-training quantization (PTS) is a common method for neural network quantization. It maps floating-point weights and activations in a trained neural network to low-bit fixed-point numbers to achieve neural network compression. Because PTS does not include quantization training, the accuracy of quantized models using PTS is significantly lower than that of full-precision models.
[0005] Summary of the Invention
[0006] The embodiments of the present disclosure provide a model quantization method, device, electronic device and storage medium, which can improve the quantization accuracy of the post-training quantization method.
[0007] In a first aspect, an embodiment of the present disclosure provides a model quantization method, comprising:
[0008] Determining a capability index of each module in the model to be quantified; wherein the capability index of each module represents the capability of each module to process data;
[0009] Determining differences in the capability indicators between adjacent modules in the modules, and determining pairs of adjacent modules to be combined based on the differences;
[0010] Joint quantization is performed on the adjacent module pairs to be combined that have been determined in the model to be quantized.
[0011] In a second aspect, the present disclosure further provides a model quantization device, including:
[0012] A capability index evaluation module is used to determine the capability index of each module in the model to be quantified; wherein the capability index of each module represents the capability of each module to process data;
[0013] a joint information determination module, configured to determine differences in the capability indicators between adjacent modules in the modules, and determine pairs of adjacent modules to be joined based on the differences;
[0014] The joint quantization module is used to perform joint quantization on the adjacent module pairs to be combined that have been determined in the model to be quantized.
[0015] In a third aspect, an embodiment of the present disclosure further provides an electronic device, the electronic device comprising:
[0016] one or more processors;
[0017] a storage device for storing one or more programs,
[0018] When the one or more programs are executed by the one or more processors, the one or more processors implement the model quantization method as described in any one of the embodiments of the present disclosure.
[0019] In a fourth aspect, an embodiment of the present disclosure further provides a storage medium comprising computer-executable instructions, which, when executed by a computer processor, are used to execute the model quantization method as described in any one of the embodiments of the present disclosure.
[0020] The technical solution of the embodiment of the present disclosure is to determine the capability index of each module in the model to be quantified; wherein the capability index of each module represents the capability of each module to process data; determine the difference between the capability indexes of adjacent modules in each module, and determine the adjacent module pairs to be combined based on the differences; and jointly quantize the adjacent module pairs to be combined that have been determined in the model to be quantified. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The above and other features, advantages, and aspects of the various embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and that the originals and elements are not necessarily drawn to scale.
[0022] Figure 1 is a schematic diagram showing the relationship between the final quantization loss and the maximum quantization loss in a post-training quantization process;
[0023] FIG2 is a flow chart of a model quantization method provided by an embodiment of the present disclosure;
[0024] FIG3 is a block diagram of a quantization process of a model quantization method provided by an embodiment of the present disclosure;
[0025] FIG4 is a flowchart of a process for determining capability indicators of each module in a data-free scenario in a model quantization method provided by an embodiment of the present disclosure;
[0026] FIG5 is a block diagram of a process for determining capability indicators of each module in a data-based scenario in a model quantification method provided by an embodiment of the present disclosure;
[0027] FIG6 is a schematic structural diagram of a model quantization device provided by an embodiment of the present disclosure;
[0028] FIG7 is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0029] The following describes embodiments of the present disclosure in more detail with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as limited to the embodiments described herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are for illustrative purposes only and are not intended to limit the scope of protection of the present disclosure.
[0030] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0031] As used herein, the term "including" and its variations are open-ended, i.e., "including but not limited to." The term "based on" means "based, at least in part, on." The term "one embodiment" means "at least one embodiment," the term "another embodiment" means "at least one additional embodiment," and the term "some embodiments" means "at least some embodiments." Other terms are defined in the following description.
[0032] It should be noted that the concepts of "first" and "second" mentioned in this disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0033] It should be noted that the modifications of "one" and "multiple" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, they should be understood as "one or more".
[0034] It is understandable that the data involved in this technical solution (including but not limited to the data itself, the acquisition or use of the data) must comply with the requirements of relevant laws, regulations and relevant provisions.
[0035] Experiments have shown that when a trained model is quantized using post-training quantization, significant quantization loss oscillations may occur. To explore the correlation between quantization loss oscillations and quantization accuracy, the following research was conducted:
[0036] First, the trend of quantization loss change under module equivalence is proposed: given a pre-trained model and input data, if two adjacent modules in the pre-trained model are equivalent, the quantization loss of the latter module is greater than the quantization loss of the former module.
[0037] This trend in quantization loss can be understood as follows: under the condition that two adjacent modules are equivalent, quantization loss will increase monotonically due to the cumulative effect. However, in actual pre-trained models, this "adjacent module equivalence" condition is difficult to meet. For example, changes in some convolutional layer hyperparameters can cause adjacent modules to no longer be equivalent. When adjacent modules are not equivalent, it can be considered that the module's ability to process data (referred to as module capacity) has changed.
[0038] The following quantization loss variation trend was further derived: if the module capacity of the latter module in adjacent modules is significantly greater than that of the former, the quantization loss will be reduced. Conversely, if the module capacity of the latter module is less than that of the former, the quantization loss accumulation effect will be exacerbated on top of the original quantization loss accumulation effect.
[0039] This further trend indicates that the quantization loss oscillation that occurs during post-training quantization is caused by differences in module capabilities. Furthermore, the greater the difference in capabilities between adjacent modules, the more pronounced the quantization loss oscillation. Since the latter module in practical application models typically needs to output a more highly compressed low-dimensional vector, meaning that the latter module's capabilities tend to be smaller than the former, quantization loss oscillation typically increases the maximum quantization loss when module capabilities are equivalent.
[0040] Next, a large number of quantization losses during the post-training quantization process were randomly sampled, the final quantization loss and the maximum quantization loss were statistically analyzed, and a scatter plot was generated.
[0041] For example, Figure 1 is a schematic diagram of the relationship between the final quantization loss and the maximum quantization loss in a post-training quantization process. Referring to Figure 1, for the trained mobile network model (such as the MobileNetV2 model in Figure 1) and the residual network (ResNet-18 model in Figure 1), the post-training quantization process is performed by using the method of "improving the limit of post-training quantization through block reconstruction" (indicated by BRECQ in Figure 1) and the method of "random drop quantization for extremely low-bit post-training quantization" (indicated by QDROP in Figure 1). Both show a positive correlation between the final quantization loss and the maximum quantization loss. Assuming that the model to be quantized contains L modules, this positive correlation can be described by the following formula: Loss(W L ,X L )∝max(Loss(W1,X1),...,Loss(W L-1 ,X L-1 ));
[0042] Among them, Loss(W i ,X i ) can represent the quantization loss after quantization of the i-th module in the model to be quantized.
[0043] That is, according to data statistics, during the post-training quantization process, the final quantization loss and the maximum quantization loss are positively correlated.
[0044] In summary, differences in module capabilities within the quantized model can lead to quantization loss oscillations, which in turn increase the maximum quantization loss and, consequently, the final quantization loss. Since the final quantization loss is highly correlated with post-quantization accuracy, we can conclude that quantization loss oscillations during post-training quantization can impair quantization accuracy.
[0045] Based on the above research, the present disclosure provides a model quantization method that can improve the quantization accuracy of the post-training quantization method. Figure 2 is a flow chart of a model quantization method provided by the present disclosure. The present disclosure is applicable to the case of quantizing a model based on the post-training quantization method. The method can be performed by a model quantization device, which can be implemented in software and / or hardware and can be configured in an electronic device, such as a computer.
[0046] As shown in FIG2 , the model quantization method provided in this embodiment may include:
[0047] S210 , determining a capability index of each module in the model to be quantified; wherein the capability index of each module represents the capability of each module to process data.
[0048] In the embodiment of the present disclosure, the model to be quantized may be a pre-trained model; each module in the model to be quantized may be composed of at least one convolutional layer and may be used to perform at least one data processing operation.
[0049] Before quantizing the model to be quantized after training, the module capabilities of each module in the model can be evaluated. The module capabilities of each module can be evaluated from different dimensions, such as the module's own dimensions (such as structure and number of parameters), or the module's data processing dimensions (such as accuracy and speed). The evaluation dimensions and evaluation methods for each dimension can be pre-set based on the specific model to be quantized.
[0050] It can be considered that the results of evaluating a module's module capability from different dimensions can all be considered module capability indicators. Furthermore, if a module's capability indicator includes capability indicators from at least two dimensions, the capability indicators from at least two dimensions can be fused (e.g., weighted fusion) to determine the module's final capability indicator, thereby more accurately characterizing the module's module capability.
[0051] For example, Figure 3 is a block diagram of the quantization process of a model quantization method provided by an embodiment of the present disclosure. Referring to Figure 3 , the model to be quantized can be composed of modules 1 through L connected in sequence, and a capability indicator can be evaluated for each module to obtain capability indicators 1 through L, respectively.
[0052] S220: Determine the difference in capability indicators between adjacent modules in each module, and determine adjacent module pairs to be combined according to each difference.
[0053] For example, referring to FIG. 3 again, adjacent modules in the modules of FIG. 3 may include: module 1 and module 2, module 2 and module 3, ..., module L-1 and module L.
[0054] In this embodiment, the difference in capability indicators between adjacent modules can be calculated separately, for example, the larger capability indicator can be subtracted from the smaller capability indicator, or the former module capability indicator can be subtracted from the latter module capability indicator, etc., which is not limited here.
[0055] Subsequently, determining adjacent module pairs to be combined based on the differences may include: taking the absolute value of each difference; and determining the adjacent module pairs to be combined based on the absolute value. For example, the adjacent module pair to be combined may be formed by two adjacent modules with the largest absolute value; or, for another example, the adjacent module pair to be combined may be formed by two adjacent modules with absolute values greater than a preset value. It can be assumed that the adjacent module pairs may include at least one pair.
[0056] By determining the adjacent module pairs to be combined based on the difference in capability indicators, it is possible to select adjacent module pairs with large differences in module capabilities, that is, to select adjacent module pairs that cause large quantization loss oscillations, which is beneficial to reducing quantization loss oscillations in the post-training quantization process.
[0057] In some optional implementations, determining adjacent module pairs to be combined according to the differences may include: determining a preset number of adjacent module pairs to be combined according to descending order of the differences.
[0058] First, the absolute values of the differences can be taken to ensure that each difference is a positive number. Then, the differences after taking the absolute values can be arranged in descending order from large to small. Finally, the differences can be arranged in descending order to determine a preset number of adjacent module pairs to be combined. For example, the adjacent module pairs consisting of two adjacent modules corresponding to the first preset number of differences can be used as the adjacent module pairs to be combined. For example, the adjacent module pairs corresponding to the preset number of differences can be randomly selected from the differences greater than the median of the arrangement as the adjacent module pairs to be combined. The preset number can be set based on experience or experimentation, and by controlling the number of adjacent module pairs, the optimal quantization accuracy can be achieved.
[0059] In addition, the adjacent module pairs to be combined can be determined by constructing the following formula:
[0060] Among them, the above formula The solution goal is to find the value of m when the result value is the largest; where m represents a binary vector of length L-1, and m l Indicates the value of the lth element in m. When the value is 0, it can be considered that the lth and l+1th modules in the model to be quantized do not constitute an adjacent module pair to be combined. When the value is 1, it can be considered that the lth and l+1th modules in the model to be quantized constitute an adjacent module pair to be combined. l and CM l+1 Represent the capability indicators of the lth and l+1th modules in the model to be quantized, respectively. The model to be quantized can have a total of L modules. 1 represents a vector of equal length to m, with all elements set to 1. k represents a preset number, and λ represents a preset regularization term scaling factor. Based on this formula, the pairs of adjacent modules to be combined corresponding to the first k largest squared differences can be determined simultaneously, which is highly efficient.
[0061] In these optional implementations, by selecting adjacent modules with large absolute values and corresponding to a preset number of differences to form adjacent module pairs to be combined, it is beneficial to further reduce the quantization loss oscillation in the post-training quantization process.
[0062] S230 , jointly quantize the adjacent module pairs to be combined that have been determined in the quantization model.
[0063] For example, referring again to FIG3 , it is assumed that by arranging the differences in descending order and selecting the adjacent module pairs corresponding to the preset number of larger differences (referred to as sorting and selecting in FIG3 ), the adjacent module pairs consisting of module 1 and module 2 and the adjacent module pairs consisting of module 3 and module 4 are determined to be the adjacent module pairs to be combined in the model to be quantized. In the post-training quantization process, the adjacent module pairs consisting of module 1 and module 2 that have been determined can be combined as a whole module for quantization, and the adjacent module pairs consisting of module 3 and module 4 that have been determined can be combined as a whole module for quantization.
[0064] Taking the model to be quantized in Figure 3 as an example, joint quantization of adjacent module pairs to be combined in the model to be quantized can include: first, jointly quantizing module 1 and module 2 as a whole, obtaining jointly quantized quantized module 1 and quantized module 2; then, jointly quantizing module 3 and module 4 as a whole, obtaining jointly quantized quantized module 3 and quantized module 4. Subsequently, module 5, module 6, ..., can be quantized module by module, until module L is quantized, completing the post-training quantization process of the model to be quantized. Module quantization can be performed based on the module's input and output data according to existing module quantization methods.
[0065] In the disclosed embodiment, by jointly quantizing adjacent module pairs with large differences in capability indicators, the quantization loss oscillation in the post-training quantization process can be reduced, thereby helping to improve the quantization accuracy of the post-training quantization.
[0066] In some optional implementations, if there are overlapping modules in the adjacent module pairs to be combined, the adjacent module pairs to be combined that have been determined in the quantized model are jointly quantized, which can include: taking each module in the adjacent module pair to be combined to which each overlapping module belongs as the target module corresponding to each overlapping module; based on the continuity of the position sequence of the overlapping modules in the model to be quantized, determining each target module group according to the target module corresponding to each overlapping module; and jointly quantizing the modules in each target module group.
[0067] Among them, there can be at least one overlapping module in the adjacent modules to be combined. Taking the model to be quantized in Figure 3 as an example, it is assumed that the adjacent module pairs to be combined include adjacent module pair 1 to be combined consisting of module 1 and module 2, adjacent module pair 2 to be combined consisting of module 2 and module 3, adjacent module pair 3 to be combined consisting of module 3 and module 4, adjacent module pair 4 to be combined consisting of module 5 and module 6, and adjacent module pair 5 to be combined consisting of module 6 and module 7. Then, the overlapping modules in the adjacent module pairs to be combined include module 2, module 3, and module 6. Correspondingly, the modules in the adjacent module pair 1 and the adjacent module pair 2 to which module 2 belongs (i.e., module 1, module 2, and module 3) can be used as target modules corresponding to module 2; the modules in the adjacent module pair 2 and the adjacent module pair 3 to which module 3 belongs (i.e., module 2, module 3, and module 4) can be used as target modules corresponding to module 3; and the modules in the adjacent module pair 4 and the adjacent module pair 5 to which module 6 belongs (i.e., module 5, module 6, and module 7) can be used as target modules corresponding to module 6.
[0068] The order in which the overlapping modules process data in the model to be quantified can be considered as their positional order in the model to be quantified. For example, the positional order of module 2, which belongs to the overlapping module, can be considered to be 2, and the positional order of module 3, which belongs to the overlapping module, can be considered to be 3, etc. The continuity of the positional order can include continuous positional order and discontinuous positional order, and the overlapping modules with continuous positional order can include at least two overlapping modules. For example, assuming that the overlapping modules include module 2, module 3, module 4, and module 6, then the positional order of module 2, module 3, and module 4 in the model to be quantified is continuous, and the positional order of module 6 in the model to be quantified is discontinuous with that of module 2, module 3, and module 4, respectively.
[0069] Among them, based on the continuity of the position sequence of overlapping modules in the model to be quantified, each target module group is determined according to the target module corresponding to each overlapping module, which may include at least one of the following items: if the position sequence of at least two overlapping modules in the model to be quantified is continuous, then the target modules corresponding to the at least two overlapping modules are merged to obtain a target module group; if the position sequence of the current overlapping module and other overlapping modules in the model to be quantified is discontinuous, then the target module group is composed of the target module corresponding to the current overlapping module.
[0070] For example, assuming that the overlapping modules with continuous position sequence in the model to be quantized include module 2 and module 3, then the target module corresponding to module 2 and the target module corresponding to module 3 can be merged, that is, module 1, module 2 and module 3 can be merged with module 2, module 3 and module 4 to obtain a target module group consisting of module 1, module 2, module 3 and module 4.
[0071] For example, assuming that module 6, which belongs to the overlapping module, and other overlapping modules except its own module are not continuous in position order in the model to be quantized, then the target module group can be composed of the target modules corresponding to module 6 (i.e., module 5, module 6 and module 7).
[0072] The joint quantization of the modules in each target module group may include: jointly quantizing all modules in the target module group as a whole. For example, when the target module group consists of module 1, module 2, module 3, and module 4, module 1, module 2, module 3, and module 4 may be jointly quantized as a whole to obtain quantized module 1, quantized module 2, quantized module 3, and quantized module 4, respectively, and used as the final quantization results of module 1, module 2, module 3, and module 4, respectively.
[0073] In these optional implementations, the target module groups containing different numbers of modules can be determined by the continuity of the position order of overlapping modules in the model to be quantized, and the modules in each target module group can be jointly quantized, which can make the joint quantization of modules more flexible, reduce the quantization loss oscillation in the post-training quantization process in the global dimension, and help improve the quantization accuracy.
[0074] In some optional implementations, jointly quantizing adjacent module pairs in the model to be quantized may include: jointly quantizing adjacent module pairs to be combined that have been determined in the model to be quantized based on a preset batch of sample data.
[0075] In the actual quantization process, there may be a large amount of sample data. In this case, the sample data can be divided into batches for model quantization. Research has found that the batch size of each batch of sample data is related to the quantization accuracy. Increasing the batch size can reduce the approximate error of the optimization target expectation, so increasing the batch size can improve the quantization accuracy to a certain extent. At the same time, after the batch size is expanded to a certain extent, the improvement of quantization accuracy will be subject to diminishing marginal returns. Therefore, in these optional implementation methods, a suitable batch (i.e., a preset batch) of sample data can be pre-selected to jointly quantize the adjacent module pairs to be combined in the quantized model to achieve optimal quantization accuracy.
[0076] The technical solution of the embodiment of the present disclosure determines the capability index of each module in the model to be quantized; wherein the capability index of each module represents the capability of each module to process data; determines the difference between the capability indexes of adjacent modules in each module, and determines the adjacent module pairs to be combined based on each difference; and jointly quantizes the adjacent module pairs to be combined that have been determined in the model to be quantized. In the process of quantizing the model based on the post-training quantization method, by determining the adjacent module pairs to be combined based on the difference between the capability indexes of each module in the model, and jointly quantizing the adjacent module pairs during the quantization process, the capability index differences between the modules to be quantized can be eliminated, thereby reducing the quantization loss oscillation and improving the quantization accuracy.
[0077] This embodiment can be combined with various optional solutions in the model quantization method provided in the above embodiments. The model quantization method provided in this embodiment provides a detailed description of the determination of the capability indicators of each module in different scenarios.
[0078] In a model quantization method provided in this embodiment, in a data-free scenario, capability indicators can be evaluated from the module's own dimension. That is, the capability indicators of each module in the model to be quantified can be determined, which may include:
[0079] When each module meets preset conditions, the capability index of each module is determined according to the parameter quantity and bit width of each module; wherein the parameter quantity and bit width of each module are positively correlated with the capability index of the corresponding module.
[0080] The "no-data scenario" refers to a scenario in which the model to be quantified does not require sample data processing to measure the capabilities of each module in the model. The module's parameter count includes, for example, the number of parameters such as the weights and activation values of each network layer in the module; the module's bit width refers to the data width of each parameter, which can be, for example, 32 bits or 16 bits. Based on experience and experimentation, the module's parameter count and bit width clearly affect its ability to process data, and generally, the larger the parameter count and bit width, the stronger the module's capabilities.
[0081] For example, Figure 4 is a flowchart of the process of determining the capability index of each module in a data-free scenario in a model quantization method provided by an embodiment of the present disclosure. As shown in Figure 4, in some implementations, the capability index of each module can be calculated based on the following formula:
[0082] Among them, ModCap represents the capability index; i represents the i-th convolutional layer in the current module, and the convolutional layers in the current module can have n layers in total; W i Represents the parameters of the i-th convolutional layer, params(W i ) is a function that determines the parameter amount of the i-th convolutional layer; b i represents the bit width of the i-th convolutional layer; αi ∈[1,+∞), is the preset proportional coefficient.
[0083] However, some other factors can also affect the capabilities of the module, and the impact of these factors on the module capabilities is difficult to quantify. For example, whether the middle layer of the module has residual link inputs, the number of groups in the module convolution layer, etc. The existence of these factors makes it impossible to determine the module's capability indicators. Therefore, in this embodiment, the premise of the computing capability indicator is restricted. That is, when each module meets the preset conditions, the capability indicator of each module can be determined based on the parameter quantity and bit width of each module. Among them, the preset conditions can be pre-set based on experience or experiments. For example, the conditions that each module needs to meet in terms of network structure, number of network layers, etc.
[0084] In a data-free scenario, and when each module meets preset conditions, the capability index of each module can be directly calculated using the parameter quantity and bit width of each module, thereby achieving higher capability index determination efficiency.
[0085] In some optional implementations, the preset conditions include that the number of convolutional layers of each module is the same, and the adjacent module pairs to be combined are determined based on the differences, which may include: determining the adjacent module pairs with the largest difference as the adjacent module pairs to be combined; arranging the differences in descending order, and determining in sequence that the adjacent module pairs corresponding to the differences do not have any overlapping modules with the determined adjacent module pairs to be combined, and determining the adjacent module pairs corresponding to the differences as the adjacent module pairs to be combined, until the number of determined adjacent module pairs to be combined reaches a preset number.
[0086] The number of convolutional layers in each module is the same, meaning that the hyperparameters of the convolutional layers corresponding to each module are the same, except for the kernel size and number of channels. Under this precondition, the modules are considered topologically homogeneous. However, since the process of jointly quantizing multiple modules as a whole involves implicitly combining the initial two modules for joint quantization and then jointly quantizing the combined module with the next module, if adjacent modules overlap, the combined module will no longer be topologically homogeneous with the next module, thus violating the premise of topological homogeneity.
[0087] Therefore, in these optional implementations, no overlapping modules can exist between the determined adjacent module pairs. On this basis, the process of determining the adjacent module pairs to be combined can include: first, taking the absolute value of each difference to ensure that each difference is a positive number; then, the differences after taking the absolute value can be arranged in descending order from large to small, and the adjacent module pair corresponding to the frontmost (i.e., the largest difference) can be used as the adjacent module pair to be combined; then, a target difference can be determined from each difference in order from front to back, and when there is no overlapping module between the adjacent module pair corresponding to the target difference and the determined adjacent module pair to be combined, the adjacent module pair corresponding to the target difference is determined as the adjacent module pair to be combined; until the number of adjacent module pairs to be combined reaches a preset number, the selection process of the adjacent module pairs to be combined can be stopped.
[0088] For example, assuming that the topology is homogeneous, the differences after taking the absolute values are arranged in descending order as 10, 9, 8, 7, etc. These differences correspond to adjacent module pairs module 1 and module 2, module 2 and module 3, module 5 and module 6, module 7 and module 8, etc., and the preset number is 3.
[0089] Then, the process of determining adjacent module pairs to be combined may include: determining the adjacent module pair corresponding to the maximum difference (i.e., difference 10) (i.e., module 1 and module 2) as adjacent module pair 1 to be combined; then, determining that the adjacent module pair corresponding to a difference of 9 (i.e., module 2 and module 3) has an overlapping module (i.e., module 2) with the adjacent module pair 1 to be combined, in which case the adjacent module pair corresponding to the difference of 9 cannot be used as the adjacent module pair to be combined; then, determining that the adjacent module pair corresponding to a difference of 8 (i.e., module 5 and module 6) has no overlapping module with the adjacent module pair 1 to be combined, in which case the adjacent module pair corresponding to the difference of 8 can be determined as adjacent module pair 2 to be combined; and then determining that the adjacent module pair corresponding to a difference of 7 (i.e., module 7 and module 8) has no overlapping module with both the adjacent module pair 1 and the adjacent module pair 2 to be combined, in which case the adjacent module pair corresponding to the difference of 7 can be determined as adjacent module pair 3 to be combined. At this point, the number of adjacent module pairs to be combined has reached the preset number 3, and the process of determining adjacent modules to be combined can be stopped.
[0090] In these optional implementations, when each module needs to meet the preset condition of topological homogeneity to determine the adjacent module pairs to be combined, there must be no overlapping modules between the adjacent module pairs to be combined to avoid violating the premise of topological homogeneity and ensure the reasonable selection of adjacent module pairs.
[0091] In addition, in another model quantification method provided in this embodiment, in a data-available scenario, capability indicators can be evaluated from the dimension of module data processing, that is, determining the capability indicators of each module in the model to be quantified, which may include:
[0092] The model to be quantized is initially quantized module by module based on sample data; the module quantization loss of each module in the model to be quantized is determined based on the first feature output by each module after the initial quantization and the second feature output by the corresponding module in the model to be quantized; the capability index of each module in the model to be quantified is determined based on the module quantization loss; wherein, the module quantization loss is inversely correlated with the capability index of each module in the model to be quantified.
[0093] The data-rich scenario may refer to a scenario where the model to be quantized requires sample data processing, for example, an initial quantization based on the sample data is required. The initial quantization process may include a module-by-module quantization process of the model to be quantized.
[0094] Exemplarily, FIG5 is a flowchart of the process of determining the capability indicators of each module in a data scenario in a model quantization method provided by an embodiment of the present disclosure. As shown in FIG5 , the quantization module in FIG5 can be regarded as any module in the modules after initial quantization; accordingly, the feature output by the quantization module can be called the first feature. The feature output by the module used to quantize the quantization module in FIG5 (i.e., the corresponding module in the model to be quantized) can be called the second feature. The loss between the first feature and the second feature can be calculated based on the existing feature loss determination algorithm to obtain the module quantization loss of the corresponding module in the model to be quantized. For example, in FIG5 , the second-order norm loss between the first feature and the second feature can be calculated to obtain the module quantization loss of the corresponding module in the model to be quantized. Similarly, the module quantization loss of each module in the model to be quantized can be obtained in the same way.
[0095] The greater the module quantization loss, the lower the module capability of the corresponding module in the model to be quantized. An inverse correlation between the module quantization loss and the capability index of the second module can be preset. Accordingly, the capability index of the second module can be determined based on the module quantization loss according to this inverse correlation.
[0096] In scenarios with data, the module's quantization loss can be used to determine the module's capability index. In this case, there may be overlapping modules in the adjacent module pairs determined, thereby achieving a global optimal solution for joint quantization and improving quantization accuracy.
[0097] The technical solution of the embodiment of the present disclosure describes in detail the determination of the capability index of each module in different scenarios. In a data-free scenario, and when each module meets the preset conditions, the capability index of each module can be directly calculated by using the parameter quantity and bit width of each module, which can achieve a higher capability index determination efficiency. In a data scenario, the quantization loss of the module can be used to determine the capability index of the module. In this case, there may be overlapping modules in the adjacent module pairs determined, so that the global optimal solution of joint quantization can be achieved, thereby improving the quantization accuracy. In addition, the model quantization method provided in the embodiment of the present disclosure and the model quantization method provided in the above embodiment belong to the same public concept. The technical details not fully described in this embodiment can be found in the above embodiment, and the same technical features have the same beneficial effects in this embodiment and the above embodiment.
[0098] Figure 6 is a schematic diagram of the structure of a model quantization device provided by an embodiment of the present disclosure. The model quantization device provided by this embodiment is suitable for quantizing a model based on a post-training quantization method.
[0099] As shown in FIG6 , the model quantization device provided by the embodiment of the present disclosure may include:
[0100] A capability index evaluation module 610 is used to determine the capability index of each module in the model to be quantified; wherein the capability index of each module represents the ability of each module to process data;
[0101] A joint information determination module 620 is used to determine the difference in capability indicators between adjacent modules in each module, and determine adjacent module pairs to be joined based on each difference;
[0102] The joint quantization module 630 is configured to perform joint quantization on adjacent module pairs to be combined that have been determined in the quantization model.
[0103] In some optional implementations, the capability indicator evaluation module can be used to:
[0104] When each module meets the preset conditions, the capability index of each module is determined according to the parameter quantity and bit width of each module;
[0105] Among them, the parameter quantity and bit width of each module are positively correlated with the capability index of the corresponding module.
[0106] In some optional implementations, the capability indicator evaluation module may also be used to:
[0107] Perform initial quantization of each module of the model to be quantized based on sample data;
[0108] Determining a module quantization loss of each module in the model to be quantized based on the first feature output by each module after initial quantization and the second feature output by the corresponding module in the model to be quantized;
[0109] According to the module quantification loss, determine the capability index of each module in the model to be quantified;
[0110] Among them, the module quantization loss is inversely correlated with the capability indicators of each module in the model to be quantized.
[0111] In some optional implementations, the joint information determination module may be configured to:
[0112] According to the descending order of the differences, a preset number of adjacent module pairs to be combined are determined.
[0113] In some optional implementations, the preset condition includes that the number of convolutional layers of each module is the same, and the joint information determination module can be used to:
[0114] Determine the adjacent module pair with the largest difference as the adjacent module pair to be combined;
[0115] According to the descending order of the difference values, when it is determined in turn that the adjacent module pairs corresponding to the difference values do not have overlapping modules with the adjacent module pairs that have been determined to be combined, the adjacent module pairs corresponding to the difference values are determined as the adjacent module pairs to be combined, until the number of the adjacent module pairs that have been determined to be combined reaches a preset number.
[0116] In some optional implementations, the joint quantization module may be used to:
[0117] If there are overlapping modules in the adjacent module pairs to be combined, each module in the adjacent module pair to be combined to which each overlapping module belongs is used as a target module corresponding to each overlapping module;
[0118] Based on the continuity of the position sequence of the overlapping modules in the model to be quantized, each target module group is determined according to the target module corresponding to each overlapping module;
[0119] The modules in each target module group are jointly quantized.
[0120] In some optional implementations, the joint quantization module may be used for at least one of the following:
[0121] If at least two overlapping modules are located in a continuous order in the model to be quantized, the target modules corresponding to the at least two overlapping modules are merged to obtain a target module group;
[0122] If the position sequence of the current overlapping module and other overlapping modules in the model to be quantized is not continuous, the target module group is composed of the target modules corresponding to the current overlapping module.
[0123] In some optional implementations, the joint quantization module may be used to:
[0124] Based on a preset batch of sample data, the adjacent module pairs to be combined in the quantized model are jointly quantized.
[0125] The model quantization device provided in the embodiments of the present disclosure can execute the model quantization method provided in any embodiment of the present disclosure, and has the corresponding functional modules and beneficial effects of the execution method.
[0126] It is worth noting that the various units and modules included in the above-mentioned device are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific names of the functional units are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the embodiments of the present disclosure.
[0127] Reference is now made to FIG7 , which illustrates a schematic diagram of the structure of an electronic device (e.g., a terminal device or server in FIG7 ) 700 suitable for implementing embodiments of the present disclosure. The terminal device in the embodiments of the present disclosure 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), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. The electronic device illustrated in FIG7 is merely an example and should not limit the functionality or scope of use of the embodiments of the present disclosure.
[0128] As shown in Figure 7, the electronic device 700 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage device 708 into a random access memory (RAM) 703. Various programs and data required for the operation of the electronic device 700 are also stored in the RAM 703. The processing device 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.
[0129] Typically, the following devices may be connected to the I / O interface 705: an input device 706 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 707 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 708 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 709. The communication device 709 may allow the electronic device 700 to communicate with other devices wirelessly or by wire to exchange data. Although FIG. 7 shows the electronic device 700 with various devices, it should be understood that not all of the devices shown are required to be implemented or present. More or fewer devices may be implemented or present instead.
[0130] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes 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 709, or installed from the storage device 708, or installed from the ROM 702. When the computer program is executed by the processing device 701, the above-mentioned functions defined in the model quantization method of the embodiment of the present disclosure are performed.
[0131] The electronic device provided by the embodiment of the present disclosure and the model quantization method provided by the above embodiment belong to the same disclosed concept. For technical details not fully described in this embodiment, please refer to the above embodiment, and this embodiment has the same beneficial effects as the above embodiment.
[0132] An embodiment of the present disclosure provides a computer storage medium having a computer program stored thereon, which, when executed by a processor, implements the model quantization method provided in the above embodiment.
[0133] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the 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 component, 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 (FLASH), 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 disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, which carries a computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium that can 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 suitable medium, including but not limited to wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.
[0134] In some embodiments, the client and server can communicate using any currently known or later developed network protocol, such as HTTP (Hypertext Transfer Protocol), and can 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 later developed network.
[0135] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0136] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device:
[0137] Determine the capability index of each module in the model to be quantified; wherein the capability index of each module represents the capability of each module to process data; determine the difference between the capability indexes of adjacent modules in each module, and determine the adjacent module pairs to be combined according to the differences; and jointly quantize the adjacent module pairs to be combined that have been determined in the model to be quantified.
[0138] Computer program code for performing the operations of the present disclosure 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 stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through 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., through the Internet using an Internet service provider).
[0139] The flowcharts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of 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 box can also occur in a different order than that marked in the accompanying drawings. For example, two 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 box in the block diagram and / or flowchart, and the combination of the boxes in the block diagram and / or flowchart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0140] The units involved in the embodiments described in this disclosure may be implemented in software or hardware, wherein the names of the units and modules do not, in certain circumstances, limit the units and modules themselves.
[0141] The functions described above herein may be performed, at least in part, by one or more hardware logic components. For example, and without limitation, exemplary types of hardware logic components that may be used include: Field Programmable Gate Array (FPGA), Application Specific Integrated Circuit (ASIC), Application Specific Standard Parts (ASSP), System on Chip (SOC), Complex Programmable Logic Device (CPLD), and the like.
[0142] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can 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.
[0143] According to one or more embodiments of the present disclosure, a model quantization method is provided, the method comprising:
[0144] Determining a capability index of each module in the model to be quantified; wherein the capability index of each module represents the capability of each module to process data;
[0145] Determining differences in the capability indicators between adjacent modules in the modules, and determining pairs of adjacent modules to be combined based on the differences;
[0146] Joint quantization is performed on the adjacent module pairs to be combined that have been determined in the model to be quantized.
[0147] According to one or more embodiments of the present disclosure, a model quantization method is provided, further comprising:
[0148] In some optional implementations, determining the capability index of each module in the model to be quantified includes:
[0149] When each module satisfies a preset condition, determining a capability index of each module according to a parameter quantity and a bit width of each module;
[0150] Among them, the parameter quantity and bit width of each module are positively correlated with the capability index of the corresponding module.
[0151] According to one or more embodiments of the present disclosure, a model quantization method is provided, further comprising:
[0152] In some optional implementations, determining the capability index of each module in the model to be quantified includes:
[0153] Performing initial quantization on the model to be quantized module by module based on the sample data;
[0154] Determining a module quantization loss of each module in the model to be quantized based on a first feature output by each module after initial quantization and a second feature output by a corresponding module in the model to be quantized;
[0155] Determining the capability index of each module in the model to be quantified according to the module quantization loss;
[0156] The module quantization loss is inversely correlated with the capability index of each module in the model to be quantized.
[0157] According to one or more embodiments of the present disclosure, a model quantization method is provided, further comprising:
[0158] In some optional implementations, determining adjacent module pairs to be combined according to the differences includes:
[0159] According to the descending order of the differences, a preset number of adjacent module pairs to be combined are determined.
[0160] According to one or more embodiments of the present disclosure, a model quantization method is provided, further comprising:
[0161] In some optional implementations, the preset condition includes that the modules have the same number of convolutional layers, and determining the adjacent module pairs to be combined based on the differences includes:
[0162] Determine the adjacent module pair with the largest difference as the adjacent module pair to be combined;
[0163] According to the descending order of the differences, when it is determined in turn that the adjacent module pairs corresponding to the differences have no overlapping modules with the determined adjacent module pairs to be combined, the adjacent module pairs corresponding to the differences are determined as the adjacent module pairs to be combined until the number of the determined adjacent module pairs to be combined reaches a preset number.
[0164] According to one or more embodiments of the present disclosure, a model quantization method is provided, further comprising:
[0165] In some optional implementations, if there are overlapping modules in the adjacent module pairs to be combined, then performing joint quantization on the adjacent module pairs to be combined that have been determined in the model to be quantized includes:
[0166] Taking each module in the adjacent module pair to be combined to which each overlapping module belongs as a target module corresponding to each overlapping module;
[0167] Based on the continuity of the position sequence of the overlapping modules in the model to be quantized, and according to the target modules corresponding to each of the overlapping modules, determining each target module group;
[0168] The modules in each target module group are jointly quantized.
[0169] According to one or more embodiments of the present disclosure, a model quantization method is provided, further comprising:
[0170] In some optional implementations, determining each target module group based on the continuity of the position sequence of the overlapping modules in the model to be quantized and according to the target modules corresponding to each of the overlapping modules includes at least one of the following:
[0171] If at least two of the overlapping modules are located in a continuous order in the model to be quantized, merging the target modules corresponding to the at least two overlapping modules to obtain a target module group;
[0172] If the position sequence of the current overlapping module and other overlapping modules in the model to be quantized is not continuous, the target modules corresponding to the current overlapping module constitute a target module group.
[0173] According to one or more embodiments of the present disclosure, a model quantization method is provided, further comprising:
[0174] In some optional implementations, the performing joint quantization on the adjacent module pairs to be combined that have been determined in the model to be quantized includes:
[0175] Based on a preset batch of sample data, the adjacent module pairs to be combined that have been determined in the model to be quantized are jointly quantized.
[0176] According to one or more embodiments of the present disclosure, a model quantization device is provided, the device comprising:
[0177] A capability index evaluation module is used to determine the capability index of each module in the model to be quantified; wherein the capability index of each module represents the capability of each module to process data;
[0178] a joint information determination module, configured to determine differences in the capability indicators between adjacent modules in the modules, and determine pairs of adjacent modules to be joined based on the differences;
[0179] The joint quantization module is used to perform joint quantization on the adjacent module pairs to be combined that have been determined in the model to be quantized.
[0180] The above description is merely a preferred embodiment of the present disclosure and an illustration of the technical principles employed. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above-mentioned technical features, but also encompasses other technical solutions formed by any combination of the above-mentioned technical features or their equivalents without departing from the above-mentioned disclosed concepts. For example, a technical solution formed by replacing the above-mentioned features with (but not limited to) technical features with similar functions disclosed in the present disclosure.
[0181] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details have been included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0182] Although the subject matter has been described in language specific to structural features and / or methodological logical acts, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. Rather, the specific features and acts described above are merely example forms of implementing the claims.
Claims
1. A model quantization method, include: Determine a capability index of each module in the model to be quantified, wherein the capability index of each module represents the capability of each module to process data; Determining the difference of the capability indicators between adjacent modules in the modules, and determining the adjacent module pairs to be combined according to each of the differences; Joint quantization is performed on the adjacent module pairs to be combined that have been determined in the model to be quantized.
2. The method according to claim 1, in, The capability index of each module in the model to be quantified is determined as follows: When each module satisfies a preset condition, determining a capability index of each module according to a parameter quantity and a bit width of each module; Among them, the parameter quantity and bit width of each module are positively correlated with the capability index of the corresponding module.
3. The method according to claim 1, in, The capability index of each module in the model to be quantified is determined as follows: Performing initial quantization module by module on the model to be quantized based on the sample data; Determine the module quantization loss of each module in the model to be quantized according to the first feature output by each module after initial quantization and the second feature output by the corresponding module in the model to be quantized; Determining the capability index of each module in the model to be quantified according to the module quantization loss; The module quantization loss is inversely correlated with the capability index of each module in the model to be quantified.
4. The method according to claim 1, in, Determining the adjacent module pairs to be combined according to the differences comprises: According to the descending order of the differences, a preset number of adjacent module pairs to be combined are determined.
5. The method according to claim 2, in, The preset condition includes that the number of convolutional layers of the modules is the same, and the determining of the adjacent module pairs to be combined according to the differences includes: Determine the adjacent module pair with the largest difference as the adjacent module pair to be combined; According to the descending order of the difference values, when it is determined in turn that the adjacent module pairs corresponding to the difference values have no overlapping modules with the determined adjacent module pairs to be combined, the adjacent module pairs corresponding to the difference values are determined as the adjacent module pairs to be combined, until the number of the determined adjacent module pairs to be combined reaches a preset number.
6. The method according to claim 1, in, If there are overlapping modules in the adjacent module pairs to be combined, then the step of jointly quantizing the adjacent module pairs to be combined that have been determined in the model to be quantized includes: Taking each module in the adjacent module pair to be combined to which each of the overlapping modules belongs as a target module corresponding to each of the overlapping modules; Based on the continuity of the position sequence of the overlapping modules in the model to be quantized, and according to the target modules corresponding to each of the overlapping modules, each target module group is determined; The modules in each target module group are jointly quantized.
7. The method according to claim 6, in, The determining of each target module group based on the continuity of the position sequence of the overlapped modules in the to-be-quantified model and the target modules corresponding to each overlapped module comprises at least one of the following: If at least two of the overlapping modules are in a continuous position order in the model to be quantized, merging the target modules corresponding to the at least two overlapping modules to obtain a target module group; If the position sequence of the current overlapping module and other overlapping modules in the model to be quantized is not continuous, the target modules corresponding to the current overlapping modules constitute a target module group.
8. The method according to any one of claims 1 to 7, in, The step of jointly quantizing the adjacent module pairs to be combined that have been determined in the model to be quantized includes: Based on a preset batch of sample data, the adjacent module pairs to be combined that have been determined in the model to be quantized are jointly quantized.
9. A model quantization device, include: The capability index evaluation module is used to determine the capability index of each module in the model to be quantified; The capability index of each module represents the capability of each module to process data; A joint information determination module, used to determine the difference between the capability indicators of adjacent modules in the modules, and determine the adjacent module pairs to be combined according to the differences; The joint quantization module is used to perform joint quantization on the adjacent module pairs to be combined that have been determined in the model to be quantized.
10. An electronic device, wherein the electronic device include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the model quantization method as described in any one of claims 1 to 8.
11. A storage medium comprising computer executable instructions, wherein the computer executable instructions are used to perform the model quantization method according to any one of claims 1 to 8 when executed by a computer processor.
Citation Information
Patent Citations
Compression and acceleration method of neural network model and data processing method and device
CN110852439A
Model quantification method and device, storage medium and electronic equipment
CN113537470A
Neural network model quantification method, device and system, electronic equipment and storage medium
CN113902114A
Neural network quantification method and device thereof, computer equipment and storage medium
CN114048853A
Neural network model quantification method and device
CN114861886A
