CN115880527A - Model compression method and device, storage medium and electronic equipment - Google Patents

Model compression method and device, storage medium and electronic equipment Download PDF

Info

Publication number
CN115880527A
CN115880527A CN202211529571.5A CN202211529571A CN115880527A CN 115880527 A CN115880527 A CN 115880527A CN 202211529571 A CN202211529571 A CN 202211529571A CN 115880527 A CN115880527 A CN 115880527A
Authority
CN
China
Prior art keywords
model
candidate
initial
target
parameters
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202211529571.5A
Other languages
Chinese (zh)
Inventor
杨扬
张辰
刘家豪
曾邵雯
林春喜
钱晓俊
王金刚
武威
于利前
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Sankuai Online Technology Co Ltd
Original Assignee
Beijing Sankuai Online Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Sankuai Online Technology Co Ltd filed Critical Beijing Sankuai Online Technology Co Ltd
Priority to CN202211529571.5A priority Critical patent/CN115880527A/en
Publication of CN115880527A publication Critical patent/CN115880527A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

In the embodiment of the specification, in the process of model compression, the model compression is not performed only according to the initial model, but the target model obtained in the process of compressing the initial model is again used as the initial model to perform the same model compression until the obtained target model meets the preset condition. Therefore, the target model finally obtained through model compression can meet the actual compression requirement, the effect of the model finally obtained through compression in actual application can be better ensured, and the accuracy of business processing through the compressed model is further ensured.

Description

Model compression method and device, storage medium and electronic equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a method and an apparatus for model compression, a storage medium 5, and an electronic device.
Background
Nowadays, with the development of science and technology, more and more models which can be practically applied to help improve the production and the life of people emerge, and the development of modern society and the progress of human society are promoted. However, with the richness of the functions and the optimization of the effects of the model 0, the scale of the parameters and the number of layers of the model are continuously updated, and the scale of the corresponding model is larger and larger, so that it is difficult to directly apply the large model to the client.
Therefore, before the model is deployed in the client, the model with larger parameter scale needs to be compressed into the model with smaller parameter scale, and then the compressed model needs to be deployed in the client. Then is compressed at present
The model of (2) is not effective when actually used, and when business processing is performed using the compressed model, the accuracy of the business processing may be reduced by (5).
Therefore, how to improve the effect of model compression to ensure the accuracy of business processing through the compressed model becomes a problem to be solved urgently.
Disclosure of Invention
0 the present specification provides a method and apparatus for model compression to partially solve the above problems in the prior art.
The embodiment of the specification adopts the following technical scheme:
the present specification provides a method for model compression, including:
obtaining an initial model;
5, constructing at least one candidate model according to the model parameters in the initial model, and screening a target model from the at least one candidate model, wherein the parameter quantity of the model parameters in each candidate model is less than that of the model parameters in the initial model;
judging whether the target model meets a preset condition or not;
if not, re-determining the target model as the initial model, and re-obtaining the target model according to the re-determined model parameters in the initial model until the re-obtained target model meets the preset condition;
and deploying the target model meeting the preset condition as a compressed model, and performing service processing according to the deployed model when receiving a service request.
Optionally, constructing at least one candidate model according to the model parameters in the initial model specifically includes:
determining parameters of each parameter retention ratio from model parameters contained in the initial model according to preset each parameter retention ratio, wherein the parameters are used as each target parameter;
and constructing at least one candidate model according to the target parameters.
Optionally, before screening out the target model from the at least one candidate model, the method further includes:
training the at least one candidate model to obtain each trained candidate model;
screening out a target model from the at least one candidate model, which specifically comprises:
and screening the target model from the trained candidate models.
Optionally, the training of the at least one candidate model to obtain each trained candidate model specifically includes:
obtaining a training sample;
inputting the training samples into the initial model to obtain a first output result, and inputting the training samples into the target model for each candidate model to obtain a second output result;
and training the initial model and the candidate model by taking the minimized deviation between the first output result and the second output result and the minimized deviation between the first output result and the label corresponding to the training sample as optimization targets.
Optionally, screening the target model from the at least one candidate model specifically includes:
for each candidate model, determining a parameter ratio between the parameter quantity of the model parameter contained in the candidate model and the parameter quantity of the model parameter contained in the initial model as a parameter ratio corresponding to the candidate model;
determining the priority of the candidate model according to the parameter ratio corresponding to the candidate model;
and screening the target model from the at least one candidate model according to the corresponding priority of each candidate model.
Optionally, screening the target model from the at least one candidate model specifically includes:
for each candidate model, inputting each verification sample into the candidate model to determine the accuracy corresponding to the candidate model according to the result output by the candidate model for each verification sample, and inputting each verification sample into the initial model to determine the accuracy corresponding to the initial model according to the result output by the initial model for each verification sample;
determining the priority of the candidate model according to the accuracy corresponding to the candidate model and the accuracy corresponding to the initial model;
and screening the target model from the at least one candidate model according to the corresponding priority of each candidate model.
Optionally, after the target model is retrieved, the method further includes:
acquiring a training sample;
for each initial model, inputting the training sample into the initial model to obtain a third output result, inputting the training sample into a target model determined based on the initial model to obtain a fourth output result, and determining a loss value corresponding to the initial model according to a deviation between the third output result and the fourth output result;
determining a loss sum value according to the loss value corresponding to each initial model;
and training each obtained initial model and each obtained target model by taking the minimized loss and value as optimization targets.
The present specification provides a model compression apparatus, including:
the acquisition module is used for acquiring an initial model;
the construction module is used for constructing at least one candidate model according to the model parameters in the initial model and screening a target model from the at least one candidate model, wherein the parameter quantity of the model parameters in each candidate model is less than that of the model parameters in the initial model;
the judging module is used for judging whether the target model meets a preset condition, if not, the target model is determined as the initial model again, and the target model is obtained again according to the model parameters in the determined initial model until the obtained target model meets the preset condition;
and the deployment module is used for deploying the target model meeting the preset condition as a compressed model so as to process the service according to the deployed model when receiving the service request.
The present specification provides a computer-readable storage medium storing a computer program which, when executed by a processor, implements the method of model compression described above.
The present specification provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the processor implements the method of model compression described above.
The embodiment of the specification adopts at least one technical scheme which can achieve the following beneficial effects:
in the method for compressing the model provided in this specification, an initial model is obtained, at least one candidate model is constructed according to model parameters in the initial model, a target model is screened from the at least one candidate model, the parameter quantity of the model parameters in each candidate model is less than the parameter quantity of the model parameters in the initial model, whether the target model meets preset conditions or not is judged, if not, the target model is determined as the initial model again, the target model is obtained again according to the model parameters in the determined initial model again, until the obtained target model meets the preset conditions again, the target model meeting the preset conditions is deployed as the compressed model, and service processing is performed according to the deployed model when a service request is received.
It can be seen from the above method that, in the present specification, in the process of model compression, instead of performing model compression only according to the initial model, the target model obtained when the initial model is compressed is again used as the initial model to perform model compression until the obtained target model meets the preset conditions, so that the target model finally obtained through model compression not only can meet the actual compression requirement, but also can ensure that the effect of the model obtained after final compression in actual application is better, thereby ensuring the accuracy when the compressed model performs business processing.
Drawings
The accompanying drawings, which are included to provide a further understanding of the specification and are incorporated in and constitute a part of this specification, illustrate embodiments of the specification and together with the description serve to explain the specification and not to limit the specification in a non-limiting sense. In the drawings:
FIG. 1 is a schematic flow chart of a method of model compression in this specification;
FIG. 2 is a schematic diagram of joint training of multiple models provided herein;
FIG. 3 is a schematic diagram of an apparatus for compression of a model provided herein;
fig. 4 is a schematic diagram of an electronic device corresponding to fig. 1 provided in the present specification.
Detailed Description
In order to make the objects, technical solutions and advantages of the present disclosure more clear, the technical solutions of the present disclosure will be clearly and completely described below with reference to the specific embodiments of the present disclosure and the accompanying drawings. It is to be understood that the embodiments described are only a few embodiments of the present disclosure, and not all embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present specification without any creative effort belong to the protection scope of the present specification.
The technical solutions provided by the embodiments of the present description are described in detail below with reference to the accompanying drawings.
Fig. 1 is a schematic flow chart of a method for compressing a model in this specification, including:
s101: an initial model is obtained.
The execution subject of the method for compressing a model in the present specification may be a terminal device such as a desktop computer or a notebook computer, or may be a server, and the method for compressing a model in the present specification will be described below by taking only the terminal device as the execution subject.
In an implementation of the present description, an initial model is first obtained. The different initial models have corresponding business processing functions, specifically, the initial model with the image classification function can process businesses in the aspect of image classification; the initial model with the information recommendation function can process services in the aspect of information recommendation. The initial model and the specific services processed by the initial model are not limited in this specification.
The initial model initially acquired by the terminal device may be understood as a model having the largest model size, and the model size may refer to the number of network layers included in the model and the parameters of the model parameters included in the model. In practical application, a large-scale model cannot be directly deployed in a client for use, so that after the initial model is obtained, model compression needs to be performed on the initial model, and the compressed model can be deployed in the client.
S102: and constructing at least one candidate model according to the model parameters in the initial model, and screening a target model from the at least one candidate model, wherein the parameter quantity of the model parameters in each candidate model is less than the parameter quantity of the model parameters in the initial model.
In this specification, after obtaining the initial model, the terminal device may construct at least one candidate model according to model parameters in the initial model, and screen out a target model from the at least one candidate model. The parameter quantity of the model parameters in each candidate model is here smaller than the parameter quantity of the model parameters in the initial model. And then, whether the target model is suitable for being deployed to a client for service processing can be judged by judging whether the target model obtained by the initial model meets a preset condition.
When at least one candidate model is constructed according to the model parameters in the initial model, the terminal device may determine parameters of each parameter retention ratio from the model parameters included in the initial model according to preset each parameter retention ratio, and use the parameters as each target parameter. And then, constructing at least one candidate model according to each target parameter.
For example, when at least one candidate model is constructed, if the preset retention ratios of the parameters are three in total, and when the preset retention ratios of the parameters are 0.8, 0.6 and 0.4 respectively, 80%, 60% and 40% of the model parameters in the initial model are selected as target parameters respectively when the at least one candidate model is constructed, and then the three candidate models are constructed according to the target parameters.
When constructing the candidate model, if the preset parameter retention ratio is 0.8, 80% of model parameters are selected from the initial model as target parameters, and then the candidate model is constructed according to the target parameters, so that the constructed candidate model contains 80% of the parameters of the model parameters in the initial model.
After the construction of the at least one candidate model is completed, the terminal device may train the at least one candidate model to obtain each trained candidate model, and then screen out the target model from each trained candidate model.
Specifically, when at least one candidate model is trained, a training sample may be input into the initial model to obtain a first output result, and for each candidate model, the same training sample may be input into the candidate model to obtain a second output result. And then, training the initial model and the candidate model by taking the minimized deviation between the first output result and the second output result and the minimized deviation between the first output result and the label corresponding to the training sample as optimization targets.
For example, when training a candidate model corresponding to a preset parameter retention ratio of 80%, for an initial model that can be subjected to image classification: firstly, a picture is taken as a training sample, labels corresponding to the training sample are (1, 0), wherein each numerical value in the labels respectively corresponds to a class of objects, 1 represents that the probability that an object related to the picture belongs to a first class of objects is 100%, that is, the picture contains an image corresponding to the first class of objects, and correspondingly, 0 represents that the picture does not contain images of a second class of objects, a third class of objects and a fourth class of objects.
The terminal device may input the picture into the initial model and the candidate model respectively, take the classification result (0.7, 0.2,0.1, 0) of the initial model as a first output result, and take the classification result (0.6, 0.2, 0) of the candidate model as a second output result. And then, training the initial model and the candidate model by taking the minimized deviation between the first output result and the second output result and the minimized deviation between the first output result and the label corresponding to the training sample as optimization targets. By the training mode, the output result of the candidate model can be closer to the initial model, and the output result of the initial model can be closer to the label of the training sample.
In the embodiment of the present specification, there may be three ways of screening out the target model from each trained candidate model.
In the first mode, the terminal device may determine the priority corresponding to the candidate model only according to the parameter ratio, and then screen out the target model according to the priority. The parameter ratio here indicates a ratio of the parameter amount of the model parameter included in the candidate model to the parameter amount of the model parameter included in the initial model, and the priority may be ranked from high to low according to the parameter ratio, that is, the lower the parameter ratio, the higher the priority corresponding to the candidate model, and finally the candidate model with the highest priority may be selected as the target model.
For example, when there are three candidate models in total, there are a candidate model 1 with a parameter ratio of 0.8, a candidate model 2 with a parameter ratio of 0.6, and a candidate model 3 with a parameter ratio of 0.4. Then the candidate model priority is from high to low as: candidate model 3, candidate model 2 and candidate model 1, and the ratio of the parameters of the finally screened target model is the candidate model 3.
In the second mode, the terminal device may determine the priority corresponding to the candidate model only according to the accuracy, and screen out the target model according to the priority. The accuracy here represents the accuracy corresponding to the output result of each verification sample of the candidate model, for example, if after each verification sample is input into one candidate model, the candidate model can accurately identify 80% of the verification samples, then the accuracy corresponding to the candidate model is 80%. The priorities may be ranked from high to low according to the accuracy, that is, the higher the accuracy corresponding to a candidate model is, the higher the priority corresponding to the candidate model is, and finally, the terminal device may screen out the target model according to the accuracy corresponding to each candidate model.
For example, when there are three candidate models in total, there are candidate model 1 with an accuracy of 80%, candidate model 2 with an accuracy of 60%, and candidate model 3 with an accuracy of 40%. Then the candidate model priorities are from high to low: candidate model 1, candidate model 2 and candidate model 3, and the ratio of the parameters of the finally screened target model is the candidate model 1.
Of course, when determining the priority of the candidate model by the accuracy, the combination of the accuracy corresponding to the initial model and the accuracy of the initial model may also be considered. Specifically, the terminal device may determine an initial model and an accuracy of the candidate model for each candidate model, then determine a score of the candidate model according to the initial model and the accuracy of the candidate model, and further determine a priority of the candidate model according to the score of the candidate model.
Wherein the score of each candidate model can be determined using the following formula:
Figure BDA0003974035700000081
ta in equation (1) represents the candidate model, t represents the initial model, molecular Performance ta Representing the accuracy of the candidate model, the denominator performance in equation (1) t Representing the accuracy of the initial model. Since the accuracy of the initial model used in determining the score of any one candidate model is the same, the higher the accuracy of the candidate model is, the larger the value represented by tradeoff in formula (1) is, and the higher the score of the candidate model is.
In the third mode, the priority corresponding to the candidate model can be determined by integrating the parameter ratio and the accuracy, and then the target model is screened out according to the determined priority. Based on this, in this specification, the terminal device may determine, for each candidate model, a score corresponding to the candidate model according to the parameter ratio corresponding to the candidate model, the accuracy rate corresponding to the candidate model, the parameter ratio corresponding to the initial model, and the accuracy rate corresponding to the initial model, and then determine, according to the score corresponding to the candidate model, a priority corresponding to the candidate model.
Wherein the score for each candidate model may be determined according to the following equation (2).
Figure BDA0003974035700000091
The rating, performance, of the candidate model in equation (2) ta Represents the accuracy, performance, of the candidate model t Representing the accuracy, scale, of the initial model ta Scale representing the ratio of parameters of the candidate model t Denotes the parameter ratio of the initial model, and λ is an arbitrary positive number.
Since the ratio of the accuracy of the initial model to the parameter of the initial model is not changed, the higher the accuracy of the candidate model is, the smaller the ratio of the parameter of the candidate model is, the larger the tradeoff in the formula (2) is, i.e. the higher the score of the candidate model is.
Of course, the third mode mentioned above can also be in various specific forms, and the embodiments provided in this specification are not intended to be illustrative.
S103: and judging whether the target model meets a preset condition or not.
After the target model is determined, the terminal device can further judge whether the target model meets preset conditions, if so, the target model is deployed as a compressed model, and service processing is performed according to the deployed model when a service request is received.
In the embodiments of the present specification, the preset condition may take various forms.
For example, the preset condition here may be whether the number of previously determined initial models reaches a specified number after the target model is determined.
It is assumed that the preset condition may be whether the number of previously determined initial models reaches 5 after the target model is determined. Then, if it is determined that 4 initial models have been previously determined after the target model is determined, the terminal device may determine that the target model does not satisfy the preset condition, and if it is determined that 5 initial models have been previously determined, the terminal device may determine that the target model satisfies the preset condition.
For another example, the preset condition may be whether the parameter ratio of the target model is less than a specified parameter ratio threshold.
Assuming that the preset condition may be whether the parameter ratio of the target model is less than 0.4, where 0.4 is a specified parameter ratio threshold, if the parameter ratio of the target model is less than 0.4, the preset condition is satisfied, otherwise, it is determined that the target model does not satisfy the preset condition.
For another example, the preset condition may be whether the accuracy of the target model with respect to the training sample is greater than a specified accuracy threshold.
If the preset condition may be whether the accuracy of the target model is greater than 0.8, where 0.8 is a specified accuracy threshold, it is determined that the target model satisfies the preset condition if the accuracy of the target model is greater than 0.8 through the verification sample set, and otherwise, it is determined that the target model does not satisfy the preset condition.
Of course, the preset condition may also include other forms, and the present specification does not illustrate in detail.
S104: if not, the target model is determined as the initial model again, and the target model is obtained again according to the model parameters in the determined initial model until the obtained target model meets the preset conditions.
If the target model does not meet the preset conditions, the terminal device may determine the target model as the initial model again, and obtain the target model again according to the model parameters in the determined initial model until the obtained target model meets the preset conditions.
After the target model is obtained again, the terminal device may input the training sample to each determined initial model to obtain a third output result, and input the training sample to the target model determined based on the initial model to obtain a fourth output result.
Then, the terminal device may determine a loss value corresponding to the initial model according to a deviation between the third output result and the fourth output result, and then determine a loss sum value according to a loss value corresponding to each initial model, and then, the terminal device may minimize the loss sum value as an optimization target, and train each obtained initial model and the obtained target model.
In this specification, the final object model is actually determined by performing a plurality of rounds of building the object model. Therefore, as can be seen from the above, first, the terminal device may determine the target model according to the initial model at the beginning, and determine whether the target model meets the preset condition, if not, take the target model as the initial model again, then determine the target model according to the initial model at this time, and then determine whether the target model meets the preset condition, and if not, repeat the above operations to determine the target model meeting the preset condition.
That is, in the present specification, the initial model actually has a plurality of: after the target model is determined by the initial model, the target model may also become the initial model, and further the target model is determined, and so on. When training each initial model and the obtained target model, the models are actually trained jointly, as shown in fig. 2.
FIG. 2 is a schematic diagram of joint training of multiple models provided herein. In fig. 2, there are a total of three initial models, one target model. The first initial model refers to an initial model which needs to be compressed at first, the second initial model refers to an object model determined based on the first initial model, the third initial model refers to an object model determined based on the second initial model, and the like. Then, when the models are trained, for the target model, deviations of the first initial model, the second initial model, and the third initial model with respect to the target model are determined, respectively, so as to determine loss values, and then joint training of the models is implemented through the determined loss values.
Specifically, the terminal device may determine the loss and the value according to the following formula (3):
Figure BDA0003974035700000111
in formula (3), L represents a loss and a value, N represents the number of initial models remaining except for the initial model at the very beginning, N +1 represents the number of all initial models, and t represents the number of initial models i Denotes the ith initial model, s denotes the target model, kl-subvigence (t) i And s) represents the kl divergence between the ith initial model and the target model.
As can be further seen from the above formula, since a plurality of transitional initial models are included between the initial model and the finally determined target model, in the process of performing the joint training on these models, it can be ensured that the "knowledge" learned by the initial model is gradually transferred to the final target model through each transitional initial model, so that even if the finally determined target model includes only a small part of the initial model, the finally determined target model can well learn the "knowledge" learned by the initial model, thereby ensuring the training effect of the target model.
S105: and deploying the target model meeting the preset condition as a compressed model, and performing service processing according to the deployed model when receiving a service request.
Based on the above content, the model compression scheme not only can enable the target model finally obtained through model compression to meet the actual compression requirement, but also can ensure that the effect of the model obtained after final compression in practical application is better, and further ensures the accuracy when the model after compression is used for business processing.
It should be noted that the model compressed by the model compression method provided in this specification may be a model applied in different business fields, for example, in the field of information recommendation, the model compressed by the method may be a model deployed in a client for information recommendation; for another example, in the field of identity recognition, the model compressed by the above method may be a model deployed in a client for identity recognition; for another example, in the field of image recognition, the model compressed by the above method may be a model deployed in a client for image recognition.
Therefore, the application scenario of the model compression method in practical application is not limited in the present specification.
It should be further noted that all actions of acquiring signals, information or data in the present application are performed under the premise of complying with the corresponding data protection regulation policy of the country of the location and obtaining the authorization given by the owner of the corresponding device.
Based on the same idea, the present specification further provides a corresponding apparatus, a storage medium, and an electronic device.
Fig. 3 is a schematic diagram of a model compression apparatus provided in the present specification, the apparatus including:
an obtaining module 301, configured to obtain an initial model;
a building module 302, configured to build at least one candidate model according to the model parameters in the initial model, and screen out a target model from the at least one candidate model, where a parameter quantity of the model parameters in each candidate model is less than a parameter quantity of the model parameters in the initial model;
the judging module 303 is configured to judge whether the target model meets a preset condition, if not, re-determine the target model as an initial model, and re-obtain the target model according to the re-determined model parameters in the initial model until the re-obtained target model meets the preset condition;
the deployment module 304 is configured to deploy the target model meeting the preset condition as a compressed model, so as to perform service processing according to the deployed model when receiving a service request.
Optionally, the building module 302 is specifically configured to determine, according to preset retention ratios of the parameters, parameters of the retention ratios of the parameters from model parameters included in the initial model, as the target parameters; and constructing at least one candidate model according to each target parameter.
Optionally, the building module 302 is specifically configured to train the at least one candidate model to obtain each trained candidate model; screening out a target model from the at least one candidate model, which specifically comprises: and screening the target model from the trained candidate models.
Optionally, the constructing module 302 is specifically configured to obtain a training sample; inputting the training samples into the initial model to obtain a first output result, and inputting the training samples into the target model for each candidate model to obtain a second output result; and training the initial model and the candidate model by taking the minimized deviation between the first output result and the second output result and the minimized deviation between the first output result and the label corresponding to the training sample as optimization targets.
Optionally, the building module 302 is specifically configured to, for each candidate model, determine a parameter ratio between a parameter quantity of a model parameter included in the candidate model and a parameter quantity of a model parameter included in the initial model as a parameter ratio corresponding to the candidate model; determining the priority of the candidate model according to the parameter ratio corresponding to the candidate model; and screening the target model from the at least one candidate model according to the corresponding priority of each candidate model.
Optionally, the building module 302 is specifically configured to, for each candidate model, input each verification sample into the candidate model, so as to determine an accuracy rate corresponding to the candidate model according to a result output by the candidate model for each verification sample, and input each verification sample into the initial model, so as to determine an accuracy rate corresponding to the initial model according to a result output by the initial model for each verification sample; determining the priority of the candidate model according to the accuracy corresponding to the candidate model and the accuracy corresponding to the initial model; and screening the target model from the at least one candidate model according to the corresponding priority of each candidate model.
Optionally, the determining module 303 is specifically configured to obtain a training sample; for each initial model, inputting the training sample into the initial model to obtain a third output result, inputting the training sample into a target model determined based on the initial model to obtain a fourth output result, and determining a loss value corresponding to the initial model according to a deviation between the third output result and the fourth output result; determining a loss sum value according to the loss value corresponding to each initial model; and training each obtained initial model and each obtained target model by taking the minimized loss and value as optimization targets.
The present specification also provides a computer readable storage medium having stored thereon a computer program operable to perform the method of model compression provided in fig. 1 above.
This specification also provides a schematic block diagram of the electronic device shown in fig. 4. As shown in fig. 4, at the hardware level, the electronic device includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include hardware required for other services. The processor reads a corresponding computer program from the non-volatile memory into the memory and then runs the computer program to implement the method of model compression described above with reference to fig. 1. Of course, besides the software implementation, the present specification does not exclude other implementations, such as logic devices or a combination of software and hardware, and the like, that is, the execution subject of the following processing flow is not limited to each logic unit, and may be hardware or logic devices.
In the 90 s of the 20 th century, improvements in a technology could clearly distinguish between improvements in hardware (e.g., improvements in circuit structures such as diodes, transistors, switches, etc.) and improvements in software (improvements in process flow). However, as technology advances, many of today's process flow improvements have been seen as direct improvements in hardware circuit architecture. Designers almost always obtain the corresponding hardware circuit structure by programming an improved method flow into the hardware circuit. Thus, it cannot be said that an improvement in the process flow cannot be realized by hardware physical modules. For example, a Programmable Logic Device (PLD), such as a Field Programmable Gate Array (FPGA), is an integrated circuit whose Logic functions are determined by programming the Device by a user. A digital system is "integrated" on a PLD by the designer's own programming without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Furthermore, nowadays, instead of manually manufacturing an Integrated Circuit chip, such Programming is often implemented by "logic compiler" software, which is similar to a software compiler used in program development and writing, but the original code before compiling is also written by a specific Programming Language, which is called Hardware Description Language (HDL), and HDL is not only one but many, such as ABEL (Advanced Boolean Expression Language), AHDL (alternate Hardware Description Language), traffic, CUPL (core universal Programming Language), HDCal, jhddl (Java Hardware Description Language), lava, lola, HDL, PALASM, rhyd (Hardware Description Language), and vhigh-Language (Hardware Description Language), which is currently used in most popular applications. It will also be apparent to those skilled in the art that hardware circuitry that implements the logical method flows can be readily obtained by merely slightly programming the method flows into an integrated circuit using the hardware description languages described above.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, an Application Specific Integrated Circuit (ASIC), a programmable logic controller, and an embedded microcontroller, examples of which include, but are not limited to, the following microcontrollers: ARC 625D, atmel AT91SAM, microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic for the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller as pure computer readable program code, the same functionality can be implemented by logically programming method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers and the like. Such a controller may thus be considered a hardware component, and the means included therein for performing the various functions may also be considered as a structure within the hardware component. Or even means for performing the functions may be regarded as being both a software module for performing the method and a structure within a hardware component.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. One typical implementation device is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being divided into various units by function, respectively. Of course, the functions of the various elements may be implemented in the same one or more software and/or hardware implementations of the present description.
As will be appreciated by one skilled in the art, embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, the description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The description has been presented with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the description. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising a," "8230," "8230," or "comprising" does not exclude the presence of other like elements in a process, method, article, or apparatus comprising the element.
As will be appreciated by one skilled in the art, embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, the description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
This description may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
All the embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above description is only an example of the present disclosure, and is not intended to limit the present disclosure. Various modifications and alterations to this description will become apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present specification should be included in the scope of the claims of the present specification.

Claims (10)

1. A method of model compression, comprising:
obtaining an initial model;
constructing at least one candidate model according to the model parameters in the initial model, and screening a target model from the at least one candidate model, wherein the parameter quantity of the model parameters in each candidate model is less than that of the model parameters in the initial model;
judging whether the target model meets a preset condition or not;
if not, re-determining the target model as the initial model, and re-obtaining the target model according to the model parameters in the re-determined initial model until the re-obtained target model meets the preset conditions;
and deploying the target model meeting the preset condition as a compressed model, and performing service processing according to the deployed model when receiving a service request.
2. The method of claim 1, wherein constructing at least one candidate model based on the model parameters in the initial model comprises:
determining parameters of each parameter retention ratio from model parameters contained in the initial model according to preset each parameter retention ratio, wherein the parameters are used as each target parameter;
and constructing at least one candidate model according to the target parameters.
3. The method of claim 1, wherein prior to screening the target model from the at least one candidate model, the method further comprises:
training the at least one candidate model to obtain each trained candidate model;
screening out a target model from the at least one candidate model, which specifically comprises:
and screening the target model from the trained candidate models.
4. The method of claim 3, wherein training the at least one candidate model to obtain each trained candidate model comprises:
obtaining a training sample;
inputting the training samples into the initial model to obtain a first output result, and inputting the training samples into the target model for each candidate model to obtain a second output result;
and training the initial model and the candidate model by taking the minimized deviation between the first output result and the second output result and the minimized deviation between the first output result and the label corresponding to the training sample as optimization targets.
5. The method of claim 1, wherein screening the target model from the at least one candidate model comprises:
for each candidate model, determining a parameter ratio between the parameter quantity of the model parameter contained in the candidate model and the parameter quantity of the model parameter contained in the initial model as a parameter ratio corresponding to the candidate model;
determining the priority of the candidate model according to the parameter ratio corresponding to the candidate model;
and screening the target model from the at least one candidate model according to the corresponding priority of each candidate model.
6. The method of claim 1 or 5, wherein screening the target model from the at least one candidate model comprises:
for each candidate model, inputting each verification sample into the candidate model to determine the accuracy corresponding to the candidate model according to the result output by the candidate model for each verification sample, and inputting each verification sample into the initial model to determine the accuracy corresponding to the initial model according to the result output by the initial model for each verification sample;
determining the priority of the candidate model according to the accuracy corresponding to the candidate model and the accuracy corresponding to the initial model;
and screening the target model from the at least one candidate model according to the corresponding priority of each candidate model.
7. The method of claim 1, wherein after retrieving the target model, the method further comprises:
obtaining a training sample;
for each initial model, inputting the training sample into the initial model to obtain a third output result, inputting the training sample into a target model determined based on the initial model to obtain a fourth output result, and determining a loss value corresponding to the initial model according to a deviation between the third output result and the fourth output result;
determining a loss sum value according to the loss value corresponding to each initial model;
and training each obtained initial model and each obtained target model by taking the minimized loss and value as optimization targets.
8. A pattern compression apparatus, comprising:
the acquisition module is used for acquiring an initial model;
the construction module is used for constructing at least one candidate model according to the model parameters in the initial model and screening a target model from the at least one candidate model, wherein the parameter quantity of the model parameters in each candidate model is less than that of the model parameters in the initial model;
the judging module is used for judging whether the target model meets a preset condition, if not, the target model is determined as the initial model again, and the target model is obtained again according to the model parameters in the determined initial model until the obtained target model meets the preset condition;
and the deployment module is used for deploying the target model meeting the preset condition as a compressed model so as to perform service processing according to the deployed model when receiving the service request.
9. A computer-readable storage medium, characterized in that the storage medium stores a computer program which, when being executed by a processor, carries out the method of any one of the preceding claims 1 to 7.
10. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method of any of claims 1-7 when executing the program.
CN202211529571.5A 2022-11-30 2022-11-30 Model compression method and device, storage medium and electronic equipment Pending CN115880527A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211529571.5A CN115880527A (en) 2022-11-30 2022-11-30 Model compression method and device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211529571.5A CN115880527A (en) 2022-11-30 2022-11-30 Model compression method and device, storage medium and electronic equipment

Publications (1)

Publication Number Publication Date
CN115880527A true CN115880527A (en) 2023-03-31

Family

ID=85765249

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211529571.5A Pending CN115880527A (en) 2022-11-30 2022-11-30 Model compression method and device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN115880527A (en)

Similar Documents

Publication Publication Date Title
CN109034183B (en) Target detection method, device and equipment
CN115828162B (en) Classification model training method and device, storage medium and electronic equipment
CN114332873A (en) Training method and device for recognition model
CN108804563B (en) Data labeling method, device and equipment
CN116402113B (en) Task execution method and device, storage medium and electronic equipment
CN116821647B (en) Optimization method, device and equipment for data annotation based on sample deviation evaluation
CN115545572B (en) Method, device, equipment and storage medium for business wind control
CN117197781A (en) Traffic sign recognition method and device, storage medium and electronic equipment
CN115221523B (en) Data processing method, device and equipment
CN115130621B (en) Model training method and device, storage medium and electronic equipment
CN115131570B (en) Training method of image feature extraction model, image retrieval method and related equipment
CN112307371B (en) Applet sub-service identification method, device, equipment and storage medium
CN115689676A (en) Industry identification method and apparatus, storage medium and electronic device
CN115034367A (en) Model deployment method and device
CN115880527A (en) Model compression method and device, storage medium and electronic equipment
CN115758141A (en) Method and device for model training and business wind control
CN109325127B (en) Risk identification method and device
CN113673601B (en) Behavior recognition method and device, storage medium and electronic equipment
CN116578877B (en) Method and device for model training and risk identification of secondary optimization marking
CN116109008B (en) Method and device for executing service, storage medium and electronic equipment
CN116089434B (en) Data storage method and device, storage medium and electronic equipment
CN118152680A (en) Applet sub-service identification method, device, equipment and storage medium
CN115862675A (en) Emotion recognition method, device, equipment and storage medium
CN117034926A (en) Model training method and device for multi-field text classification model
CN117520850A (en) Model training method and device, storage medium and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination