Compression method of pre-training model based on task matching similarity

Through a method based on task matching similarity, the upstream and downstream task knowledge is aggregated to compress the pre-trained model, which solves the problems of high resource consumption and performance degradation in the existing technology, and achieves automatic optimization while maintaining good performance while reducing parameters. Adapt pruning strategies.

CN118586459APending Publication Date: 2024-09-03ANHUI UNIV +1

Patent Information

Application Number
CN202410637244.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-05-22
Publication Date
2024-09-03

AI Technical Summary

Technical Problem

Existing pre-trained language models face high memory consumption and computational overhead when deployed on resource-constrained edge devices, and pruning methods fail to effectively utilize the relationship between upstream tasks and downstream tasks, resulting in performance degradation and generalization. Impairment of ability.

Method used

Using a pre-trained model compression method based on task matching similarity, by aggregating the knowledge of upstream tasks and downstream tasks, extracting general and specific task features, learning correlation information for pruning, retaining highly relevant weights and retraining the model to restore Accuracy.

Benefits of technology

It implements an adaptive pruning strategy that maintains good performance while reducing parameters, finds the most suitable compression strategy for the current task, effectively retains weight information that contributes highly to the model, and improves the compression efficiency and performance of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118586459A
    Figure CN118586459A
Patent Text Reader

Abstract

The invention discloses a pre-training model compression method based on task matching similarity, and the method comprises the following steps: S1, carrying out the pre-training of a model, and obtaining a pre-training neural network model which is trained through a large amount of data; s2, aggregating knowledge of the upstream task and the downstream task, and extracting features of general task knowledge of the upstream task and specific task knowledge of the downstream task; s3, introducing a learnable pruning strategy, calculating and counting by learning correlation information between the extracted features, retaining weight values corresponding to the features of which the correlation is greater than a specified threshold value, and removing other weights; and S4, after the sparse weight matrix is obtained, training the pre-trained neural network model again to recover the model precision. According to the method, the weight information highly contributing to the current task of the model is effectively retained, so that the model can retain better performance on the basis of greatly reducing parameters, and the optimal compression strategy of the pre-training model can be adaptively searched according to the specificity of the personalized task.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of pre-training model compression strategies, and in particular to a compression method for a pre-training model based on task matching similarity. Background Art

[0002] Pre-trained language models, such as Vision Transformer (ViT), have achieved great success in various computer vision (CV) tasks. PLM is a model that follows the paradigm of "pre-training" and "fine-tuning" to solve certain specific tasks in a self-supervised manner: trained on a large pre-training corpus through a task similar to modeling, and then fine-tuned on a small amount of downstream data, which is labeled for the specific task. Vit These pre-trained models are usually able to achieve higher accuracy than any model trained only on downstream data. Despite their success, PLMs are usually resource-intensive with a large number of parameters ranging from millions (e.g. Vit) to billions (e.g. GPT-3), which leads to high memory consumption and computational overhead in practice. Therefore, deploying them on resource-constrained edge devices is a challenging task.

[0003] In fact, recent studies have shown that PLM is over-parameterized and there are many redundant weights in the model. Inspired by this, model pruning is a major work to compress large-scale PLM and speed up inference. It focuses on identifying and removing unimportant parameters, which can reduce the parameters in the neural network without seriously damaging the model performance. The current popular pruning process includes the following three steps: 1) Pre-training: training a complete dense model; 2) Pruning: pruning the dense network model according to certain rules, and finally obtaining a sparse network model; 3) Fine-tuning: retraining the sparse network model to restore performance.

[0004] Recent studies have shown that most pruning works use fixed methods and rules to prune the network, obtaining a fixed network for all input data, and in this process, the relationship between the general task knowledge of the upstream task and the specific task knowledge of the downstream task is not well utilized. If only the specific task knowledge of the downstream task is focused on, the vanilla pruning method is adopted, while ignoring whether the task-independent knowledge of the original PLM is well maintained in the pruned model. The loss of this task-independent knowledge will lead to a serious catastrophic forgetting problem, which further damages the generalization ability of the pruned model. In addition, when faced with extremely high sparsity scenarios (for example, 97% sparsity, only 3% of parameters are retained), the performance of the pruned model drops sharply compared with the original dense model. If only the general knowledge of the original PLM is maintained, although the knowledge of the upstream task can provide some general feature representations and semantic information, these features may not be fully applicable to the downstream task. Therefore, when pruning the pre-trained model, the specific data and feature requirements of the downstream task may not be fully utilized, resulting in performance degradation.

[0005] In order to solve the above problems, many excellent pruning strategies have emerged over time with the continuous development of algorithms and technologies. The current mainstream methods can be divided into two categories. The first mainstream method is to use the statistical information of the attention weights in the model to prune the model to retain the parameters that are important to the upstream task. The second method is to selectively delete the network structure based on the specific knowledge of the downstream task. However, this method is only dominated by the upstream task or the downstream task, and the other stage task is auxiliary, and the correlation between general task knowledge and specific task knowledge is not fully utilized. Summary of the invention

[0006] In order to solve the existing problems, the present invention provides a compression method of a pre-trained model based on task matching similarity, and the specific scheme is as follows:

[0007] A method for compressing a pre-trained model based on task matching similarity comprises the following steps:

[0008] S1, pre-train the model using the common task data of the upstream task to obtain a pre-trained neural network model trained with a large amount of data;

[0009] S2, aggregates the knowledge of upstream tasks and downstream tasks, and extracts the features of the general task knowledge of upstream tasks and the specific task knowledge of downstream tasks;

[0010] S3, introduce a learnable pruning strategy, by learning the correlation information between the general task knowledge features and the specific task knowledge features extracted in step S2, and calculating and counting this information, retaining the weight values ​​corresponding to the features whose correlation is greater than the specified threshold, and removing the remaining weights;

[0011] S4, after obtaining the sparse weight matrix, the pruned pre-trained neural network model established in step S1 is trained again to restore the model accuracy.

[0012] Preferably, the model in step S1 is a large model Vision Transformer, ie, ViT, in the field of computer vision (CV).

[0013] Preferably, ViT pre-trains three models with different parameter sizes, namely ViT-Base, ViT-Large and ViT-Huge, where the baseline model uses ViT-Base.

[0014] Preferably, the feature extraction step in step S2 specifically includes:

[0015] S21, replace the fully connected layers in all Transformer Encoder Blocks (Multi-Head Self-Attention, MHSA) and Multilayer Perceptron, MLP modules with PrunedLindearLayer, PLL, in which features of input data are extracted;

[0016] S22, obtains the exclusive features of personalized data from the sample examples through the feature extractor and converts them into the input of the model.

[0017] Preferably, step S3 specifically includes the following steps:

[0018] S31, input enters the Transformer Encoder Block. Each block contains MHSA, MLP, normalization layer Layer Norm, activation function layer, and random loss layer Dropout.

[0019] S32, uses pruning strategies to reduce redundant neurons in MHSA and MLP modules in each block, retains important features and removes redundant features from linear projection according to the importance scores;

[0020] S33, obtaining a weight matrix corresponding to the pruned features, that is, a sparse weight matrix;

[0021] S34, according to the importance score, fine-tune the model trained by the pruned weights to reduce the accuracy drop.

[0022] Preferably, the judgment basis of important features and redundant features in step S32 is: setting two pruning thresholds - pruning lower limit threshold and pruning upper limit threshold, if the feature gap is lower than the weight of the pruning lower limit threshold, it is regarded as a redundant feature, and its importance score is set to 0; if the feature gap is higher than the weight of the pruning upper limit threshold, it is regarded as an important feature, and its importance score is set to 1; if the feature gap is between the weight of the pruning lower limit threshold and the weight of the pruning upper limit threshold, two different importance scores of 0 and 1 are randomly assigned according to a uniform distribution, and then all features are screened using the above importance scores to obtain the final sparse weight matrix, and the new loss value is calculated by learning the remaining sparse connection weights, and optimized; repeat the above operations, respectively calculate several different sparse weight matrices and loss values, and finally select the sparse weight matrix with the smallest loss value as the final result.

[0023] Preferably, the training method for restoring the model accuracy in step S4 is: repeating steps S1-S3 to perform multiple rounds of training on the model, and in the last round of training, the pruning strategy is not executed, and the model with the weight matrix of the coefficients is trained again to restore the model accuracy.

[0024] The present invention also discloses a computer-readable storage medium, on which a computer program is stored. After the computer program is run, any of the above methods is executed.

[0025] The present invention also discloses a computer system, including a processor and a storage medium, wherein a computer program is stored on the storage medium, and the processor reads and runs the computer program from the storage medium to execute any of the methods described above.

[0026] The beneficial effects of the present invention are:

[0027] The present invention proposes an adaptive task pruning strategy, which effectively retains the weight information that contributes most to the current task of the model based on the correlation between the upstream and downstream task features, so that the model can retain good performance on the basis of significantly reducing parameters. The present invention uses the optimal solution of calculating the pruning threshold as the cost function to guide the model to find the pruning strategy that best suits the current task. The optimal compression strategy of the pre-trained model can be adaptively found according to the specificity of personalized tasks. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0029] Figure 1 This is a schematic diagram of the ViT model framework;

[0030] Figure 2 It is a schematic diagram of the model framework of the present invention;

[0031] Figure 3 This is the core algorithm diagram of the present invention. DETAILED DESCRIPTION

[0032] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0033] like Figures 1 to 3 , a compression method for a pre-trained model based on task matching similarity, comprising the following steps:

[0034] S1, pre-train the model using the common task data of the upstream task, and obtain a pre-trained neural network model trained with a large amount of data. The pre-training process is to put the training data collected at low cost together, learn the commonalities through the pre-training method, and then "transplant" the commonalities into the model of the specific task, and then use a small amount of labeled data in the relevant specific field for "fine-tuning". In this way, the model only needs to start from the "commonalities" to "learn" the "special" part of the specific task.

[0035] Specific embodiment: The model of the present invention adopts the large model VisionTransformer in the field of computer vision CV, namely ViT. ViT pre-trains three models with different parameter scales, namely ViT-Base, ViT-Large and ViT-Huge, among which the baseline model uses ViT-Base.

[0036] S2 aggregates the knowledge of upstream tasks and downstream tasks, and extracts the features of the general task knowledge of upstream tasks and the specific task knowledge of downstream tasks.

[0037] Specifically, the feature extraction steps include:

[0038] S21, replace the fully connected layers in all Transformer Encoder Block’s Multi-Head Self-Attention (MHSA) and Multilayer Perceptron (MLP) modules with the PrunedLindearLayer (PLL) layer, in which the features extracted from the input data are extracted.

[0039] S22, obtains the exclusive features of personalized data from the sample examples through the feature extractor and converts them into the input of the model.

[0040] S3 introduces a learnable pruning strategy, which calculates and statistics the correlation information between the general task knowledge features and the specific task knowledge features extracted by learning step S2, retains the weight values ​​corresponding to the features whose correlation is greater than the specified threshold, and removes the remaining weights.

[0041] Specifically, step S3 includes the following steps:

[0042] S31, input enters the Transformer Encoder Block. Each block contains MHSA, MLP, normalization layer Layer Norm, activation function layer, and random loss layer Dropout. Through the above layers, the model can achieve complex representation and processing capabilities for input images. Among them, the multi-head attention mechanism allows the model to capture long-distance dependencies, the multi-layer perceptron can solve nonlinear problems that the single-layer perceptron cannot solve, and layer normalization helps to stabilize and accelerate the training process of deep networks. X∈R N×d Denotes the input of MHSA, where N is the sequence length and d is the dimension, then the module can be formulated as follows:

[0043]

[0044]

[0045] Y=X+FC out (Attention(FC q (X),FC k (X),FC v (X)))

[0046] Among them, Q h , K h 、V hRespectively represent the Q, K, and V matrices of Transformer, They represent the parameter matrix, h is the number of attention heads, is the output projection, FC out Represents a linear projection layer.

[0047] S32, use pruning strategy to reduce redundant neurons in MHSA and MLP modules in each block. For the feature X∈R extracted from the input data n×d , whose feature corresponding weight matrix is ​​W∈R n×d , where n represents the number of features to be pruned and d represents the dimension of the features. The purpose is to retain important features and remove redundant features from linear projection based on the importance scores.

[0048] Define the features extracted from the upstream task dataset and the corresponding weight matrix as X (A) ∈R n×d , W (A) ∈R n×d , the features extracted from the downstream task dataset and the corresponding weight matrix are X (B) ∈R n×d , W (B) ∈R n×d , the importance score is Score∈{0,1} d , that is, the generated important features and their corresponding scores are 1, while the scores of redundant features are 0. Respectively represent the m-th layer features extracted from the upstream data task and the downstream task data, Represents the weight matrix corresponding to the m-th layer feature, then Representation characteristics and The larger the gap, the more important the feature is to the downstream task, and the higher the importance of the feature.

[0049] Among them, the judgment basis of important features and redundant features is: setting two pruning thresholds - pruning lower limit threshold and pruning upper limit threshold. If the feature gap is lower than the weight of the pruning lower limit threshold, it is regarded as a redundant feature and its importance score is set to 0; if the feature gap is higher than the weight of the pruning upper limit threshold, it is regarded as an important feature and its importance score is set to 1.

[0050] The importance score calculation formula is as follows:

[0051]

[0052] If the feature gap is between the weight of the lower pruning threshold weight and the upper pruning threshold weight, two different importance scores of 0 and 1 are randomly assigned according to uniform distribution, and then all features are screened using the above importance scores to obtain the final sparse weight matrix, and the new loss value is calculated by learning the remaining sparse connection weights and optimized; repeat the above operation, and calculate several (156 in the specific embodiment) different sparse weight matrices and loss values, and finally select the sparse weight matrix with the smallest loss value as the final result.

[0053] S33, obtain the weight matrix corresponding to the pruned features, that is, the sparse weight matrix: in, represents the pruned feature matrix, W ij Represents the feature matrix before pruning.

[0054] S34, according to the importance score, fine-tune the model trained by the pruned weights to reduce the accuracy drop. The above pruning process is expressed as:

[0055] X * =PrunedLinearLayer(X)

[0056] The feature pruning process can be formulated as:

[0057] Q,K,V=PPL q (X),PPL k (X),PPL v (X),

[0058] Y=X+PPL out (Attention(Q,K,V))),

[0059] Z=Y+PPL2(PPL1(Q,K,V)),

[0060] Among them, PPL q , PPL k , PPL v , PPL out , PPL2, PPL1 means that the linear projection operation is the linear projection result corresponding to the pruned features, and the weight matrix used is the pruned weight matrix.

[0061] S4, after obtaining the sparse weight matrix, the pruned pre-trained neural network model established in step S1 is trained again to restore the model accuracy.

[0062] Step S4 is a training method for restoring the model accuracy by repeating steps S1-S3 to train the model for multiple rounds, specifically, 9 rounds of epoch training. In the last round of training, the pruning strategy is not executed, and the model with the weight matrix of the coefficients is trained again to restore the model accuracy. The best pruned model is selected based on the performance of the retained validation set or until 5%, 10%, or 20% of the weights are pruned.

[0063] The present invention proposes an adaptive task pruning strategy, which effectively retains the weight information that contributes most to the current task of the model based on the correlation between the upstream and downstream task features, so that the model can retain good performance on the basis of significantly reducing parameters. The present invention uses the optimal solution of calculating the pruning threshold as the cost function to guide the model to find the pruning strategy that best suits the current task. The optimal compression strategy of the pre-trained model can be adaptively found according to the specificity of personalized tasks.

[0064] The present invention also discloses a computer-readable storage medium, on which a computer program is stored. After the computer program is run, any of the above methods is executed.

[0065] The present invention also discloses a computer system, including a processor and a storage medium, wherein a computer program is stored on the storage medium, and the processor reads and runs the computer program from the storage medium to execute any of the methods described above.

[0066] Those skilled in the art will further appreciate that the various illustrative logic blocks, modules, circuits, and algorithm steps described in conjunction with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or a combination of the two. To clearly illustrate this interchangeability of hardware and software, various illustrative components, blocks, modules, circuits, and steps are generally described above in terms of their functionality. Whether such functionality is implemented as hardware or software depends on the specific application and the design constraints imposed on the overall system. The technician may implement the described functionality in different ways for each specific application, but such implementation decisions should not be interpreted as resulting in a departure from the scope of the present invention.

[0067] The various illustrative logic blocks, modules, and circuits described in conjunction with the embodiments disclosed herein may be implemented or performed with a general purpose processor, a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof designed to perform the functions described herein. A general purpose processor may be a microprocessor, but in the alternative, the processor may be any conventional processor, controller, microcontroller, or state machine. The processor may also be implemented as a combination of computing devices, such as a combination of a DSP and a microprocessor, a plurality of microprocessors, one or more microprocessors in cooperation with a DSP core, or any other such configuration.

[0068] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. The software module may reside in a RAM memory, a flash memory, a ROM memory, an EPROM memory, an EEPROM memory, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art. An exemplary storage medium is coupled to a processor so that the processor can read and write information from / to the storage medium. In an alternative, a storage medium may be integrated into a processor. The processor and the storage medium may reside in an ASIC. The ASIC may reside in a user terminal. In an alternative, the processor and the storage medium may reside in a user terminal as discrete components.

[0069] In one or more exemplary embodiments, the functions described may be implemented in hardware, software, firmware, or any combination thereof. If implemented as a computer program product in software, each function may be stored on or transmitted by a computer-readable medium as one or more instructions or codes. Computer-readable media include both computer storage media and communication media, including any medium that facilitates the transfer of a computer program from one place to another. Storage media may be any available medium that can be accessed by a computer. As an example and not limitation, such a computer-readable medium may include RAM, ROM, EEPROM, CD-ROM or other optical disk storage, disk storage or other magnetic storage device, or any other medium that can be used to carry or store the desired program code in the form of an instruction or data structure and can be accessed by a computer. Any connection is also properly referred to as a computer-readable medium. For example, if the software is transmitted from a website, a server, or other remote source using a coaxial cable, a fiber optic cable, a twisted pair, a digital subscriber line (DSL), or wireless technologies such as infrared, radio, and microwaves, the coaxial cable, fiber optic cable, twisted pair, DSL, or wireless technologies such as infrared, radio, and microwaves are included in the definition of the medium. Disk and disc as used herein include compact disc (CD), laser disc, optical disc, digital versatile disc (DVD), floppy disk and Blu-ray disc, wherein disk often reproduces data magnetically, while disc reproduces data optically with lasers. Combinations of the above should also be included within the scope of computer-readable media.

[0070] The previous description of the disclosure is provided to enable any person skilled in the art to make or use the disclosure. Various modifications to the disclosure will be apparent to those skilled in the art, and the general principles defined herein may be applied to other variations without departing from the spirit or scope of the disclosure. Thus, the disclosure is not intended to be limited to the examples and designs described herein, but should be granted the widest scope consistent with the principles and novel features disclosed herein.

[0071] Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent substitutions for some of the technical features therein; and these modifications or substitutions do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A compression method for a pre-trained model based on task matching similarity, characterized in that: The following steps are involved: S1, pre-train the model using the common task data of the upstream task to obtain a pre-trained neural network model trained with a large amount of data; S2, aggregates the knowledge of upstream tasks and downstream tasks, and extracts the features of the general task knowledge of upstream tasks and the specific task knowledge of downstream tasks; S3, introduce a learnable pruning strategy, by learning the correlation information between the general task knowledge features and the specific task knowledge features extracted in step S2, and calculating and counting this information, retaining the weight values ​​corresponding to the features whose correlation is greater than the specified threshold, and removing the remaining weights; S4, after obtaining the sparse weight matrix, the pruned pre-trained neural network model established in step S1 is trained again to restore the model accuracy.

2. The method according to claim 1, characterized in that: The model in step S1 is the large model Vision Transformer in the field of computer vision (CV), namely ViT.

3. The method according to claim 2, characterized in that: ViT pre-trains three models with different parameter sizes, namely ViT-Base, ViT-Large, and ViT-Huge, among which the baseline model uses ViT-Base.

4. The method according to claim 1, characterized in that: The feature extraction steps in step S2 specifically include: S21, replace the fully connected layers in all Transformer Encoder Blocks (Multi-Head Self-Attention, MHSA) and Multilayer Perceptron, MLP modules with PrunedLindearLayer, PLL, in which features of input data are extracted; S22, obtains the exclusive features of personalized data from the sample examples through the feature extractor and converts them into the input of the model.

5. The method according to claim 4, characterized in that Step S3 specifically includes the following steps: S31, input enters the Transformer Encoder Block. Each block contains MHSA, MLP, normalization layer Layer Norm, activation function layer, and random loss layer Dropout. S32, uses pruning strategies to reduce redundant neurons in MHSA and MLP modules in each block, retains important features and removes redundant features from linear projection according to the importance scores; S33, obtaining a weight matrix corresponding to the pruned features, that is, a sparse weight matrix; S34, according to the importance score, fine-tune the model trained by the pruned weights to reduce the accuracy drop.

6. The method according to claim 5, characterized in that The judgment basis of important features and redundant features in step S32 is: setting two pruning thresholds - pruning lower threshold and pruning upper threshold, if the feature gap is lower than the weight of the pruning lower threshold, it is regarded as a redundant feature, and its importance score is set to 0; if the feature gap is higher than the weight of the pruning upper threshold, it is regarded as an important feature, and its importance score is set to 1; If the feature gap is between the weight of the lower pruning threshold weight and the upper pruning threshold weight, two different importance scores of 0 and 1 are randomly assigned according to the uniform distribution, and then all features are screened using the above importance scores to obtain the final sparse weight matrix. The new loss value is calculated by learning the remaining sparse connection weights and optimized. Repeat the above operations to calculate several different sparse weight matrices and loss values, and finally select the sparse weight matrix with the smallest loss value as the final result.

7. The method according to claim 1 or 5, characterized in that: The training method for restoring the model accuracy in step S4 is: repeating steps S1-S3 to perform multiple rounds of model training, and in the last round of training, the pruning strategy is not executed, and the model with the weight matrix of the coefficients is trained again to restore the model accuracy.

8. A computer-readable storage medium, characterized in that: A computer program is stored on the medium, and after the computer program is run, the method according to any one of claims 1 to 7 is executed.

9. A computer system, characterized in that: The method comprises a processor and a storage medium, wherein a computer program is stored in the storage medium, and the processor reads and runs the computer program from the storage medium to execute the method as claimed in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Systems and methods for knowledge-conserving neural network pruning

    CN116348892A

  • Multi-hop reading understanding method and system based on double-view comparative learning and graph pruning

    CN116403231A

  • Neural Network Model Training Method, Electronic Device, Cloud, Cluster, and Medium

    US20250165782A1

Cited By

  • Photovoltaic equipment communication abnormity diagnosis method, medium and system

    CN119945879A