Model compression method and device, equipment, storage medium and product

Through the importance evaluation and sorting of the weight of large language models, combining the importance of hierarchical and non -significant perception quantitative technologies, compress the model, solve the problem of difficult deployment of large language models on the limited resource equipment, and achieved significant significant deployment, and achieved significant significant. Memory demand is reduced and performance is maintained.

CN119378632AInactive Publication Date: 2025-01-28HUAZHONG NORMAL UNIV
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202411978213.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-31
Publication Date
2025-01-28
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing large language models are large in size and have difficulty deploying on resource-constrained devices.

Method used

Perform the importance assessment of the weight of the compressed model through the standardized importance measurement method, and obtain the importance score of each weight; sort the weight according to the importance score to obtain the weight of the sorting; Each layer of compression ratio in each layer in the model; preliminary compression after the weight of each layer in the compression model is treated with the compression ratio; The non -significant weight of the non -significant weight is quantified and the model is obtained.

Benefits of technology

It has achieved significant reduction of memory demand while maintaining the performance of the model, breaking the obstacle of 1 digitization, and improving the deployment capacity of the model on the limited resource equipment.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119378632A_ABST
    Figure CN119378632A_ABST
Patent Text Reader

Abstract

The invention discloses a model compression method and device, equipment, a storage medium and a product, and relates to the technical field of large language models.The method comprises the steps that importance evaluation is conducted on weights in a to-be-compressed model according to a standardized importance measurement method, and the weights are sorted according to importance scores; determining a compression ratio corresponding to each layer in the model according to the hierarchy importance; performing preliminary compression on the sorted weight in each layer according to a compression ratio; and performing quantization compression on the non-significant weight according to a non-significant perceptual quantization technology to obtain a compressed model. According to the method, the calculation cost is reduced by using a standardized importance measurement method; the sorted weights are compressed according to the compression ratio, the compression efficiency of unimportant layers is improved, the compression ratio is dynamically adjusted according to the importance of the layers, and the overall performance of the model is optimized; the non-significant perceptual quantization technology effectively processes the non-significant weight, and further improves the compression ratio of the model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of large language models, and in particular to a model compression method, device, equipment, storage medium and product. Background Art

[0002] Although existing large language models have performed well in the field of natural language processing, their huge memory requirements limit their widespread application in resource-constrained environments. Although existing model compression techniques such as quantization and pruning have made some progress in reducing computational footprint, these techniques still face the problem of significant performance degradation at the 1-bit quantization level. Existing large language models are large in size and difficult to deploy on resource-constrained devices. Summary of the invention

[0003] The main purpose of this application is to provide a model compression method, device, equipment, storage medium and product, aiming to solve the technical problem that existing large-scale language models are large in size and difficult to deploy on resource-constrained devices.

[0004] To achieve the above purpose, the present application proposes a model compression method, which comprises: The importance of the weights in the model to be compressed is evaluated according to the standardized importance measurement method to obtain the importance score of each weight; Sorting the weights according to the importance scores to obtain sorted weights; Determine the compression ratio corresponding to each layer in the model to be compressed according to the layer importance; Compressing the sorted weights in each layer of the model to be compressed according to the compression ratio to obtain a preliminarily compressed model; The non-significant weights in each layer of the model after the preliminary compression are quantized and compressed according to the non-significant perceptual quantization technology to obtain a compressed model.

[0005] In one embodiment, the step of evaluating the importance of the weights in the model to be compressed according to the standardized importance measurement method to obtain the importance score of each weight includes: The L1 norm of the weights in the model to be compressed according to the normalized importance measure; Determining the L2 norm of the input feature vector corresponding to the weight; Multiplying the L1 norm by the L2 norm to obtain a preliminary importance score; The preliminary importance scores are normalized to a preset normalization range to obtain the importance scores of each weight.

[0006] In one embodiment, the step of determining the compression ratio corresponding to each layer in the model to be compressed according to the layer importance includes: Determining the sum of the L2 norms of all weights in the model to be compressed; Determining the layer importance according to the ratio of the L2 norm of the weight of each layer in the model to be compressed to the sum value; The compression ratio corresponding to each layer in the model to be compressed is determined according to the layer importance and a preset target compression ratio.

[0007] In one embodiment, the step of compressing the sorted weights in each layer of the model to be compressed according to the compression ratio to obtain a preliminarily compressed model includes: Determining a target weight to be retained from the sorted weights in each layer in the model to be compressed according to the compression ratio; Summing the absolute value of each element in the weight matrix corresponding to the target weight to be retained to obtain the L1 norm of the weight matrix; Dividing the L1 norm of the weight matrix by the number of columns of the weight matrix to obtain a scaling factor; The target weights to be retained are binarized according to the scaling factor to obtain a preliminarily compressed model.

[0008] In one embodiment, the step of quantizing and compressing the non-significant weights in each layer of the preliminarily compressed model according to the non-significant perceptual quantization technology to obtain the compressed model includes: Determining optimal breakpoints in the non-significant weights in each layer of the model after the preliminary compression according to a non-significant perceptual quantization technique; Dividing the non-significant weights in each layer into a preset number of regions according to the optimal breakpoint, wherein different regions correspond to different numbers and sizes of weight values; A quantization strategy corresponding to each of the regions is determined, and the non-significant weight of each of the regions is quantized and compressed according to the quantization strategy to obtain a compressed model.

[0009] In one embodiment, the step of determining the optimal breakpoint in the non-significant weights in each layer of the model after the preliminary compression according to the non-significant perceptual quantization technique comprises: Determining an initial search interval according to the non-significant weights in each layer of the model after the preliminary compression; Dividing the initial search interval into three equal sub-intervals according to a three-partition search algorithm, and determining an endpoint corresponding to each of the sub-intervals; Perform weighted quantization at the endpoints corresponding to each of the subintervals according to a non-significant perceptual quantization technique to obtain a quantization error corresponding to each of the subintervals; Taking the subinterval with the smallest quantization error as the current optimal subinterval; A new optimal subinterval is iteratively determined in the current optimal subinterval according to the three-partition search algorithm until the number of iterations is reached to obtain the optimal breakpoint.

[0010] In addition, to achieve the above-mentioned purpose, the present application also proposes a model compression device, which includes: An importance evaluation module is used to evaluate the importance of the weights in the model to be compressed according to a standardized importance measurement method to obtain an importance score for each weight; A weight sorting module, used to sort the weights according to the importance scores to obtain sorted weights; A compression ratio determination module, used to determine the compression ratio corresponding to each layer in the model to be compressed according to the layer importance; A model preliminary compression module, used to compress the sorted weights in each layer of the model to be compressed according to the compression ratio to obtain a preliminary compressed model; The weight quantization compression module is used to quantize and compress the non-significant weights in each layer of the model after the preliminary compression according to the non-significant perceptual quantization technology to obtain a compressed model.

[0011] In addition, to achieve the above-mentioned purpose, the present application also proposes a model compression device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the model compression method described above.

[0012] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the model compression method described above are implemented.

[0013] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the model compression method described above are implemented.

[0014] The present application provides a model compression method, which evaluates the importance of weights in a model to be compressed according to a standardized importance measurement method to obtain an importance score for each weight; sorts the weights according to the importance scores to obtain sorted weights; determines the compression ratio corresponding to each layer in the model to be compressed according to the hierarchical importance; performs preliminary compression on the sorted weights in each layer of the model to be compressed according to the compression ratio; performs quantitative compression on the non-significant weights in each layer of the model after preliminary compression according to the non-significant perceptual quantization technology to obtain the compressed model. The present application reduces the computational cost and maintains accuracy by using a standardized importance measurement method; compresses the sorted weights by the compression ratio, improves the compression efficiency for unimportant layers, dynamically adjusts the compression ratio by hierarchical importance, and optimizes the overall performance and compression ratio of the model; the non-significant perceptual quantization technology effectively handles the non-significant weights, further improving the compression rate of the model. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0016] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0017] Figure 1 A schematic diagram of a flow chart provided for the first embodiment of the model compression method of the present application; Figure 2 A schematic diagram of a flow chart provided for the second embodiment of the model compression method of the present application; Figure 3 This is a schematic diagram of the module structure of the model compression device of the embodiment of the present application; Figure 4 Schematic diagram of the device structure of the hardware operating environment involved in the model compression method in the embodiment of the present application.

[0018] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0019] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0020] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0021] The main solution of the embodiment of the present application is: to evaluate the importance of the weights in the model to be compressed according to the standardized importance measurement method to obtain the importance score of each weight; to sort the weights according to the importance score to obtain the sorted weights; to determine the compression ratio corresponding to each layer in the model to be compressed according to the hierarchical importance; to compress the sorted weights in each layer of the model to be compressed according to the compression ratio to obtain a preliminary compressed model; to quantize and compress the non-significant weights in each layer of the preliminary compressed model according to the non-significant perceptual quantization technology to obtain a compressed model.

[0022] Although existing large language models have performed well in the field of natural language processing, their huge memory requirements limit their widespread application in resource-constrained environments. Although existing model compression technologies such as quantization and pruning have made some progress in reducing computational footprints, these technologies still face the problem of significant performance degradation at the 1-bit quantization level. Existing large language models are large in size and difficult to deploy on resource-constrained devices.

[0023] The present application provides a solution, by evaluating the importance of the weights in the model to be compressed according to a standardized importance measurement method, obtaining the importance score of each weight; sorting the weights according to the importance score, obtaining the sorted weights; determining the compression ratio corresponding to each layer in the model to be compressed according to the hierarchical importance; performing preliminary compression on the sorted weights in each layer of the model to be compressed according to the compression ratio; performing quantized compression on the non-significant weights in each layer of the model after preliminary compression according to the non-significant perceptual quantization technology, obtaining the compressed model. The present application reduces the computational cost and maintains accuracy by using a standardized importance measurement method; compresses the sorted weights by the compression ratio, improves the compression efficiency for unimportant layers, dynamically adjusts the compression ratio by hierarchical importance, and optimizes the overall performance and compression ratio of the model; the non-significant perceptual quantization technology effectively handles the non-significant weights, further improving the compression rate of the model.

[0024] It should be noted that the execution subject of the method of this embodiment can be a computing service device with model compression, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc.; it can also be a model compression device with the same or similar functions. This embodiment and the following embodiments will be described by taking the model compression device as an example.

[0025] Based on this, the embodiment of the present application provides a model compression method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the model compression method of the present application.

[0026] In this embodiment, the model compression method includes steps S10 to S50: Step S10, evaluating the importance of the weights in the model to be compressed according to a standardized importance measurement method, and obtaining an importance score for each weight.

[0027] It is understandable that model weights are key parameters in neural networks, which are used to adjust and learn the behavior of the model so that the input data can be effectively mapped and useful features can be extracted. These weights are continuously optimized through the back-propagation algorithm to minimize the loss function so that the model can adapt to the input data. This embodiment uses the Standardized Importance (SI) method to evaluate the importance of the weights in the model to be compressed to obtain the importance score of each weight. The SI method evaluates the importance of weights by considering the weight size and the input feature norm, avoiding the computationally expensive Hessian matrix method and improving the automation and accuracy of the compression process.

[0028] In a feasible implementation, step S10 may include steps S101 to S104: Step S101 , performing a normalized importance measurement on the L1 norm of the weights in the model to be compressed.

[0029] It should be understood that the standardized importance metric is an innovative weight evaluation method that determines the importance of weights by two key factors: the size of the weight and the norm of the input feature to which the weight corresponds. The SI metric first calculates the L1 norm of the weights, which is the sum of the absolute values ​​of the weights for each row in the weight matrix. The L1 norm is a metric that reflects the distribution of weights on each input feature, but does not consider their specific numerical values.

[0030] Step S102, determining the L2 norm of the input feature vector corresponding to the weight.

[0031] It can be understood that the L2 norm of the input feature is then calculated, that is, each element of the input feature vector is squared, summed, and then the square root is taken. The L2 norm is a measure that reflects the overall size or strength of the input feature.

[0032] Step S103: multiply the L1 norm and the L2 norm to obtain a preliminary importance score.

[0033] It can be understood that the L1 norm of the weight is multiplied by the L2 norm of the corresponding input feature to obtain a preliminary importance score for each weight. This score takes into account the size of the weight and the strength of the input feature, thereby evaluating the relative importance of the weight to the model output.

[0034] Step S104, normalizing the preliminary importance scores to within a preset normalization range to obtain importance scores for each weight.

[0035] It is worth mentioning that in order to eliminate the impact of weights and input features of different scales on the SI score, the SI score can be further standardized so that it is distributed in a uniform range (such as between 0 and 1).

[0036] In this embodiment, the SI metric can evaluate the contribution of a weight to the model output while taking into account the importance of the input features associated with the weight. This evaluation method does not rely on expensive second-order derivatives (such as the Hessian matrix), thereby quickly and effectively identifying redundant weights that have little impact on model performance while reducing computing resource consumption.

[0037] Step S20, sorting the weights according to the importance scores to obtain sorted weights.

[0038] It is understandable that the weights can be sorted according to the SI scores to obtain sorted weights, where the weights with the highest SI scores are considered the most important, and the weights with lower SI scores are considered unimportant redundant weights. Thus, it is possible to determine the important weights that need to be retained and the redundant weights that need to be compressed.

[0039] Step S30, determining the compression ratio corresponding to each layer in the model to be compressed according to the layer importance.

[0040] It should be noted that for each layer of the model, the compression ratio corresponding to the layer is determined according to the layer importance of each layer. For example, for the more important layers in the model, a higher retention weight ratio (such as 4:8) may be selected, while for the less critical layers, a lower retention ratio (such as 1:2) may be adopted. This adaptive method ensures that the model maintains high accuracy in the key layers while effectively compressing other layers, thereby achieving a significant reduction in the model size overall.

[0041] In a feasible implementation, step S30 may include steps S301 to S303: Step S301, determining the sum of the L2 norms of all weights in the model to be compressed.

[0042] Step S302, determining the hierarchical importance according to the ratio of the L2 norm of the weight of each layer in the model to be compressed to the total value.

[0043] Step S303, determining the compression ratio corresponding to each layer in the model to be compressed according to the layer importance and the preset target compression ratio.

[0044] It can be understood that for each layer of the model, the compression ratio is determined according to its layer importance. The layer importance can be measured by the ratio of the L2 norm of the weight of the layer to the sum of the L2 norms of all weights of all layers. Then, the compression ratio of each layer is determined according to this ratio and the target compression ratio R_target. The formula is as follows: N: M ratio = alpha_i + (1 - alpha_i) × R_target, Among them, alpha_i is the level importance of the i-th layer, and R_target is the target compression ratio.

[0045] Step S40, compressing the sorted weights in each layer of the model to be compressed according to the compression ratio to obtain a preliminarily compressed model.

[0046] It should be understood that, according to the determined compression ratio, the top-ranked weights in each layer can be selected for retention, and the redundant weights ranked lower can be compressed to obtain a preliminarily compressed model. For example, if the compression ratio is 4:8, the top 4 weights are retained in every 8 weights.

[0047] In a feasible implementation, step S40 may include steps S401 to S404: Step S401, determining a target weight to be retained from the sorted weights in each layer in the model to be compressed according to the compression ratio.

[0048] It is understood that the target weights to be retained can be determined from the sorted weights in each layer of the model to be compressed according to the compression ratio. For example, if the compression ratio is 4:8, the first 4 weights are retained as the target weights to be retained in every 8 weights.

[0049] Step S402, summing the absolute value of each element in the weight matrix corresponding to the target weight to be retained to obtain the L1 norm of the weight matrix.

[0050] It should be understood that binarization is applied to the target weights selected for retention, i.e., these weights are quantized to -1 or 1. First, the L1 norm of the weight matrix W corresponding to the target weights to be retained is calculated, i.e., the absolute value of each element in the weight matrix is ​​summed. For n times m where the weight matrix W belongs to the real number set, the L1 norm is defined as: .

[0051] Step S403: Divide the L1 norm of the weight matrix by the number of columns of the weight matrix to obtain a scaling factor.

[0052] It can be understood that the scaling factor α is the L1 norm divided by the number of columns m of the weight matrix to ensure that the binarized weights remain numerically the same as the original weights. The calculation formula is: .

[0053] Step S404: binarize the target weights to be retained according to the scaling factor to obtain a preliminarily compressed model.

[0054] It should be understood that the scaling factor may be used to binarize the target weight to be retained, and the binarized weight B may be obtained by the following formula: B=α sign(W), where sign(W) is the sign function of the weight W, mapping the weight to -1 or 1.

[0055] Step S50, quantizing and compressing the non-significant weights in each layer of the model after the preliminary compression according to the non-significant perceptual quantization technology to obtain a compressed model.

[0056] It should be understood that non-significant weights refer to weights that have little impact on the final output in the model, and can be a preset number of weights ranked low in each layer of the model after preliminary compression. In this embodiment, the non-salient aware quantization (NAQ) technology is applied to find the optimal breakpoint for non-significant weights through a three-segment search algorithm, and the weights are divided into sparse, intermediate and dense areas, and binarized respectively to obtain a compressed model, further improving the compression rate of the model. After compressing the model, the compressed model can be verified to evaluate its performance on different tasks, and further optimized based on the verification results.

[0057] This embodiment provides a model compression method, which evaluates the importance of weights in a model to be compressed according to a standardized importance measurement method to obtain an importance score for each weight; sorts the weights according to the importance scores to obtain sorted weights; determines the compression ratio corresponding to each layer in the model to be compressed according to the hierarchical importance; performs preliminary compression on the sorted weights in each layer of the model to be compressed according to the compression ratio; performs quantization compression on the non-significant weights in each layer of the model after preliminary compression according to the non-significant perceptual quantization technology to obtain a compressed model. This application reduces computational costs and maintains accuracy by using a standardized importance measurement method; compresses sorted weights by compression ratio, improves compression efficiency for unimportant layers, dynamically adjusts compression ratios by hierarchical importance, and optimizes the overall performance and compression ratio of the model; the non-significant perceptual quantization technology effectively processes non-significant weights, further improving the compression rate of the model. It breaks the barrier of 1-bit quantization and achieves a significant reduction in memory requirements while maintaining performance.

[0058] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above-mentioned embodiment 1 can refer to the above introduction, and will not be repeated later. Figure 2 , step S50, the model compression method further includes steps S501~S503: Step S501 : determining an optimal breakpoint in the non-significant weights of each layer in the model after the preliminary compression according to the non-significant perceptual quantization technique.

[0059] It is understandable that, for weights evaluated as non-significant, this embodiment proposes a technique called non-significant perceptual quantization. The NAQ technique first uses a three-partition search algorithm to determine two optimal breakpoints, which are used to divide the weights into regions.

[0060] In a feasible implementation, step S501 may include steps S5011 to S5015: Step S5011, determining an initial search interval according to the non-significant weights in each layer of the model after the preliminary compression.

[0061] It is worth noting that the initial search interval is first determined, and the range of non-significant weights can be selected as the initial search interval. For example, if the range of weights is from w_min to w_max, then the initial search interval is [w_min, w_max].

[0062] Step S5012: divide the initial search interval into three equal sub-intervals according to a three-partition search algorithm, and determine the endpoint corresponding to each of the sub-intervals.

[0063] It should be understood that the optimal subinterval is then iteratively searched according to the three-partition search algorithm, first dividing the initial search interval into three equal subintervals. The endpoints of each subinterval are then calculated: First sub-interval 1: [w_min, w_mid - Δ], Second sub-interval 2: [w_mid - Δ, w_mid + Δ], The third sub-interval 3: [w_mid + Δ, w_max], Where w_mid is the midpoint of the initial search interval and Δ is the width of the subinterval.

[0064] Step S5013: performing weighted quantization at the endpoints corresponding to each of the subintervals according to the non-significant perceptual quantization technology to obtain a quantization error corresponding to each of the subintervals.

[0065] It can be understood that at the end point of each sub-interval, the NAQ technique is applied to perform weight quantization and calculate the quantization error, which can be a mean square error (MSE) or other metrics.

[0066] Step S5014: taking the subinterval with the smallest quantization error as the current optimal subinterval.

[0067] It is understandable that the subinterval with the smallest quantization error is determined as the current optimal subinterval. If the minimum error value appears at the end points of the subinterval, these end points will become potential breakpoints for further searching.

[0068] Step S5015, iteratively determine a new optimal sub-interval in the current optimal sub-interval according to the three-partition search algorithm until the number of iterations is reached to obtain the optimal breakpoint.

[0069] It is worth noting that the steps of dividing subintervals and calculating quantization errors in the above method are repeated in the optimal subinterval according to the three-partition search algorithm, and the subinterval with the smallest error is found, and the optimal breakpoint is approached by continuously narrowing the search range. Each iteration uses the three-partition search algorithm to find new subintervals and evaluate their quantization errors. When the search interval is narrowed to a certain extent or reaches a predetermined number of iterations, the search is stopped. At this time, the endpoint of the subinterval with the smallest quantization error will be considered as the optimal breakpoint.

[0070] In this implementation, the steps of dividing the sub-intervals and calculating the quantization error are iteratively performed within the optimal sub-interval through a three-partition search algorithm, and the sub-interval with the smallest error is found. The optimal breakpoint is approached by continuously narrowing the search range, so that the optimal breakpoint can be accurately found, the non-significant weights can be more accurately divided into suitable areas, and appropriate quantization strategies are applied to each area.

[0071] Step S502: Divide the non-significant weights in each layer into a preset number of regions according to the optimal breakpoints, and different regions correspond to different numbers and sizes of weight values.

[0072] It can be understood that the optimal breakpoint divides the non-significant weights in each layer into a preset number of regions, and the number and size of weight values ​​corresponding to different regions are different. For example, if there are two optimal breakpoints, the non-significant weights are divided into three regions, which can be sparse regions, middle regions, and dense regions. In sparse regions, the weight values ​​are few and close to zero, so they can be further compressed; in dense regions, the weight values ​​are large and the changes are concentrated, and more bits need to be retained to maintain model accuracy; the middle region is between the two. By applying different quantization strategies to these three regions, NAQ technology can achieve refined compression of non-significant weights while maintaining model performance.

[0073] Step S503: determining a quantization strategy corresponding to each of the regions, and performing quantization compression on the non-significant weight of each of the regions according to the quantization strategy to obtain a compressed model.

[0074] In this embodiment, the non-significant perceptual quantization technology is used to determine the optimal breakpoints for the weights evaluated as non-significant. These breakpoints divide the range of weight values ​​into several regions. Different quantization strategies are applied to these three regions, which can achieve refined compression of non-significant weights while maintaining model performance. The non-significant perceptual quantization technology effectively handles non-significant weights, and further improves the compression rate of the model through fine-grained regional division and binarization. The three-segment search algorithm provides the optimal solution for the regional division of non-significant weights and enhances the compression ability of the model. By binarizing the sparse, intermediate and dense regions respectively, the refined management of weight information is achieved, and the storage efficiency of the model is improved.

[0075] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the model compression method of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0076] This application also provides a model compression device, please refer to Figure 3 , the model compression device comprises: An importance evaluation module 10 is used to evaluate the importance of the weights in the model to be compressed according to a standardized importance measurement method to obtain an importance score for each weight; A weight sorting module 20, used to sort the weights according to the importance scores to obtain sorted weights; A compression ratio determination module 30, used to determine the compression ratio corresponding to each layer in the model to be compressed according to the layer importance; A model preliminary compression module 40, used to compress the sorted weights in each layer of the model to be compressed according to the compression ratio to obtain a preliminary compressed model; The weight quantization compression module 50 is used to quantize and compress the non-significant weights in each layer of the model after the preliminary compression according to the non-significant perceptual quantization technology to obtain a compressed model.

[0077] The model compression device provided by the present application adopts the model compression method in the above embodiment to solve the technical problem. Compared with the prior art, the beneficial effects of the model compression device provided by the present application are the same as the beneficial effects of the model compression method provided by the above embodiment, and the other technical features in the model compression device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0078] The present application provides a model compression device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the model compression method in the above-mentioned embodiment 1.

[0079] Reference below Figure 4 , which shows a schematic diagram of the structure of a model compression device suitable for implementing an embodiment of the present application. The model compression device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4 The model compression device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0080] like Figure 4As shown, the model compression device may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In RAM1004, various programs and data required for the operation of the model compression device are also stored. The processing device 1001, ROM1002 and RAM1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the model compression device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a model compression device with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.

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

[0082] The model compression device provided by the present application adopts the model compression method in the above embodiment to solve the technical problem of model compression. Compared with the prior art, the beneficial effects of the model compression device provided by the present application are the same as the beneficial effects of the model compression method provided by the above embodiment, and other technical features in the model compression device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0083] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0084] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0085] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the model compression method in the above-mentioned embodiment.

[0086] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, 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: Random Access Memory), a read-only memory (ROM: Read Only Memory), an erasable programmable read-only memory (EPROM: Erasable Programmable Read Only Memory or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM: CD-Read Only Memory), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency: Radio Frequency), etc., or any suitable combination of the above.

[0087] The computer-readable storage medium may be included in the model compression device; or may exist independently without being assembled into the model compression device.

[0088] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by the model compression device, the model compression device: evaluates the importance of the weights in the model to be compressed according to the standardized importance measurement method to obtain the importance score of each weight; sorts the weights according to the importance scores to obtain the sorted weights; determines the compression ratio corresponding to each layer in the model to be compressed according to the hierarchical importance; compresses the sorted weights in each layer in the model to be compressed according to the compression ratio to obtain a preliminary compressed model; quantizes and compresses the non-significant weights in each layer in the preliminary compressed model according to the non-significant perceptual quantization technology to obtain a compressed model.

[0089] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer 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., via the Internet using an Internet service provider).

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

[0091] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0092] The readable storage medium provided in the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned model compression method, and can solve the technical problem. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the present application are the same as the beneficial effects of the model compression method provided in the above-mentioned embodiment, and will not be described in detail here.

[0093] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned model compression method when executed by a processor.

[0094] The computer program product provided by the present application can solve the technical problem. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the model compression method provided by the above embodiment, which will not be described in detail here.

[0095] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A model compression method, characterized in that: The method includes: The importance of the weights in the model to be compressed is evaluated according to the standardized importance measurement method to obtain the importance score of each weight; Sorting the weights according to the importance scores to obtain sorted weights; Determine the compression ratio corresponding to each layer in the model to be compressed according to the layer importance; Compressing the sorted weights in each layer of the model to be compressed according to the compression ratio to obtain a preliminarily compressed model; The non-significant weights in each layer of the model after the preliminary compression are quantized and compressed according to the non-significant perceptual quantization technology to obtain a compressed model.

2. The method according to claim 1, characterized in that The step of evaluating the importance of the weights in the model to be compressed according to the standardized importance measurement method to obtain the importance score of each weight includes: The L1 norm of the weights in the model to be compressed according to the normalized importance measure; Determining the L2 norm of the input feature vector corresponding to the weight; Multiplying the L1 norm by the L2 norm to obtain a preliminary importance score; The preliminary importance scores are normalized to a preset normalization range to obtain the importance scores of each weight.

3. The method according to claim 1, characterized in that The step of determining the compression ratio corresponding to each layer in the model to be compressed according to the layer importance includes: Determining the sum of the L2 norms of all weights in the model to be compressed; Determining the layer importance according to the ratio of the L2 norm of the weight of each layer in the model to be compressed to the sum value; The compression ratio corresponding to each layer in the model to be compressed is determined according to the layer importance and a preset target compression ratio.

4. The method according to claim 1, characterized in that The step of compressing the sorted weights in each layer of the model to be compressed according to the compression ratio to obtain a preliminarily compressed model includes: Determining a target weight to be retained from the sorted weights in each layer in the model to be compressed according to the compression ratio; Summing the absolute value of each element in the weight matrix corresponding to the target weight to be retained to obtain the L1 norm of the weight matrix; Dividing the L1 norm of the weight matrix by the number of columns of the weight matrix to obtain a scaling factor; The target weights to be retained are binarized according to the scaling factor to obtain a preliminarily compressed model.

5. The method according to claim 1, characterized in that The step of quantizing and compressing the non-significant weights in each layer of the preliminarily compressed model according to the non-significant perceptual quantization technology to obtain the compressed model comprises: Determining optimal breakpoints in the non-significant weights in each layer of the model after the preliminary compression according to a non-significant perceptual quantization technique; Dividing the non-significant weights in each layer into a preset number of regions according to the optimal breakpoint, wherein different regions correspond to different numbers and sizes of weight values; A quantization strategy corresponding to each of the regions is determined, and the non-significant weight of each of the regions is quantized and compressed according to the quantization strategy to obtain a compressed model.

6. The method according to claim 5, characterized in that The step of determining the optimal breakpoint in the non-significant weights in each layer of the model after the preliminary compression according to the non-significant perceptual quantization technique comprises: Determining an initial search interval according to the non-significant weights in each layer of the model after the preliminary compression; Dividing the initial search interval into three equal sub-intervals according to a three-partition search algorithm, and determining an endpoint corresponding to each of the sub-intervals; Perform weighted quantization at the endpoints corresponding to each of the subintervals according to a non-significant perceptual quantization technique to obtain a quantization error corresponding to each of the subintervals; Taking the subinterval with the smallest quantization error as the current optimal subinterval; A new optimal subinterval is iteratively determined in the current optimal subinterval according to the three-partition search algorithm until the number of iterations is reached to obtain the optimal breakpoint.

7. A model compression device, characterized in that: The model compression device comprises: An importance evaluation module is used to evaluate the importance of the weights in the model to be compressed according to a standardized importance measurement method to obtain an importance score for each weight; A weight sorting module, used to sort the weights according to the importance scores to obtain sorted weights; A compression ratio determination module, used to determine the compression ratio corresponding to each layer in the model to be compressed according to the layer importance; A model preliminary compression module, used to compress the sorted weights in each layer of the model to be compressed according to the compression ratio to obtain a preliminary compressed model; The weight quantization compression module is used to quantize and compress the non-significant weights in each layer of the model after the preliminary compression according to the non-significant perceptual quantization technology to obtain a compressed model.

8. A model compression device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the model compression method according to any one of claims 1 to 6.

9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the model compression method according to any one of claims 1 to 6 are implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the model compression method according to any one of claims 1 to 6 are implemented.

Citation Information

Cited By

  • Methods and apparatus for foundational model compression

    WO2026184332A1