Lightweight visual Transform training optimization method and device and medium

By testing the number of attention heads on the GPU and combining MAE and distillation methods for self-supervised pre-training and fine-tuning, the performance of the lightweight visual Transformer is optimized, solving its performance shortcomings and underutilized data potential in complex tasks. problems, improving performance in practical applications.

CN118690812APending Publication Date: 2024-09-24SOUTH CHINA UNIV OF TECH
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410783754.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-18
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

Existing lightweight visual Transformers have insufficient performance when processing complex tasks, especially when the amount of data is small or tasks in specific fields do not perform well, and existing pre-training methods fail to fully utilize the potential of the data, resulting in poor performance in practical applications. Performance is limited, and the model acceleration method does not consider the impact of hardware computing characteristics.

Method used

Using a GPU-friendly training optimization method, by testing different numbers of attention heads on the GPU, and combining MAE and distillation methods for self-supervised pre-training and fine-tuning, the inference speed and accuracy of the Transformer model are optimized.

Benefits of technology

While keeping the amount of calculation unchanged, it improves the inference speed of the model on the GPU, adapts to different data scenarios and task requirements, and expands the potential of lightweight visual Transformer in practical applications.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118690812A
    Figure CN118690812A
Patent Text Reader

Abstract

The invention discloses a lightweight visual Transform training optimization method and device and a medium, and the method comprises the steps: carrying out the reasoning speed test on a GPU through an untrained Transform model according to different numbers of attention heads, so as to obtain a first number with a proper reasoning speed; setting the number of attention heads of the Transform model as a first number, and carrying out self-supervision pre-training on the Transform model by using an MAE and a distillation method; the Transform model after the self-supervised training is applied to different downstream tasks, and fine tuning training is carried out; and carrying out reasoning speed test and accuracy test on the fine-tuned model so as to evaluate the performance of the model. According to the method, appropriate parameters can be selected for the model for different scenes according to the calculation characteristics of the GPU, meanwhile, the distillation technology and self-supervision pre-training are utilized, the lightweight visual pre-training model is obtained, and the method can be widely applied to the field of image processing and computer vision.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the fields of image processing and computer vision, and in particular to a training optimization method, device and medium for a lightweight visual Transformer. Background Art

[0002] In today's image processing and computer vision fields, lightweight visual Transformers often face the challenge of insufficient performance when handling complex tasks, and usually require complex network design and adjustment to achieve the desired effect. Although existing pre-training methods have achieved certain success on large-scale datasets, they perform unsatisfactorily in tasks with small data volumes or in specific fields, showing a performance bottleneck phenomenon.

[0003] In addition, existing pre-training methods have certain limitations in utilizing large-scale pre-training data and fail to fully exploit the potential of the data, resulting in limited application effects on lightweight visual Transformer models. This limitation makes it difficult for existing lightweight visual Transformers to perform well in various practical application scenarios. A more effective method is needed to optimize the pre-training strategy to improve its performance and overcome the limitations of existing methods.

[0004] At the same time, existing model acceleration methods often only consider the impact of theoretical FLOPS on inference speed, but in practical applications, the actual computing characteristics of hardware devices often have a great impact on the inference speed of the model.

[0005] Therefore, in order to promote the application of lightweight visual Transformer models in image processing and computer vision tasks, an innovative method is urgently needed to optimize the pre-training strategy so that it can better adapt to different data scenarios and task requirements, thereby improving the performance of lightweight visual Transformer and expanding its potential in practical applications. Summary of the invention

[0006] In order to solve at least one of the technical problems existing in the prior art to a certain extent, the present invention aims to provide a GPU-friendly lightweight visual Transformer training optimization method, device and medium.

[0007] The first technical solution adopted by the present invention is:

[0008] A lightweight visual Transformer training optimization method includes the following steps:

[0009] Use an untrained Transformer model on a GPU to test the inference speed for different numbers of attention heads to get the first number of suitable inference speeds;

[0010] Set the number of attention heads of the Transformer model to the first number, and use MAE and distillation methods to perform self-supervised pre-training on the Transformer model;

[0011] Apply the self-supervised trained Transformer model to different downstream tasks and perform fine-tuning training;

[0012] The fine-tuned model is tested for inference speed and accuracy to evaluate the performance of the model.

[0013] Further, the performing inference speed test for different numbers of attention heads to obtain a first number of suitable inference speeds includes:

[0014] Obtain a dataset, and deploy the dataset and an untrained Transformer model on a GPU for inference;

[0015] After performing a preset round of inference on the GPU, the number of attention heads a and the corresponding inference speed t of the current test are obtained;

[0016] After multiple tests, we get a set of attention heads with a i And the corresponding inference speed is t i data, according to the appropriate inference speed t i The corresponding attention head a i To set the number of attention heads for the Transformer model.

[0017] Furthermore, the calculation formula of the inference speed t is as follows:

[0018]

[0019] Where n is the number of inference samples, t total is the total inference time for multiple samples.

[0020] Furthermore, the attention calculation formula and the corresponding calculation amount in the Transformer model are as follows:

[0021] Q=x*W Q ,K=x*W K ,V=x*W V

[0022]

[0023] Where x is the input, W Q , W K , W V is the weight matrix; Q is the query vector, K is the key vector, and V is the value vector; x out is the output of the current layer, W o is a linear transformation matrix used to reduce the dimension, h is the second dimension value of the query vector Q, and T represents transpose.

[0024] Furthermore, the self-supervised pre-training of the Transformer model using the MAE and distillation method includes:

[0025] The teacher model is used to distill and train the student model so that the student model can learn the relevant parameters in the teacher model as much as possible with fewer parameters:

[0026] L attn =MSE(A T ,MA S )

[0027] Among them, L attn A is the loss function used for distillation training. The role of this loss function is to train the model by comparing the difference between the attention weights of the teacher model and the student model during the knowledge distillation process. In the attention mechanism, the attention weights at different positions reflect the degree of attention of the model to the input. Therefore, by minimizing the mean square error between the two, the student model is prompted to learn the attention mode of the teacher model at different positions. T and A s are the attention weights of the teacher model and the student model respectively, and M is a learnable mapping matrix used to align the attention weights of the teacher model and the student model so that the two can be directly compared.

[0028] Furthermore, the downstream task includes a classification task, a detection task or a segmentation task.

[0029] Furthermore, the fine-tuned model is subjected to inference speed test and accuracy test to evaluate the performance of the model, including:

[0030] Deploy the Transformer model to the GPU and load the trained parameters into the model;

[0031] Deploy test data to GPU;

[0032] After GPU warm-up, perform accuracy test and inference speed test to observe whether the inference speed reaches the expected target after the accuracy reaches the preset requirement. If it does not reach the expected target, continue to adjust the number of attention heads and retrain.

[0033] The second technical solution adopted by the present invention is:

[0034] A lightweight visual Transformer training optimization device, comprising:

[0035] The inference speed test module is used to use an untrained Transformer model on the GPU to perform inference speed tests for different numbers of attention heads to obtain the first number of suitable inference speeds;

[0036] A self-supervised pre-training module, used to set the number of attention heads of the Transformer model to the first number, and use MAE and distillation methods to perform self-supervised pre-training on the Transformer model;

[0037] The model fine-tuning module is used to apply the self-supervised trained Transformer model to different downstream tasks and perform fine-tuning training;

[0038] The performance evaluation module is used to test the inference speed and accuracy of the fine-tuned model to evaluate the performance of the model.

[0039] The third technical solution adopted by the present invention is:

[0040] A lightweight visual Transformer training optimization device, comprising:

[0041] at least one processor;

[0042] at least one memory for storing at least one program;

[0043] When the at least one program is executed by the at least one processor, the at least one processor implements the above method.

[0044] The fourth technical solution adopted by the present invention is:

[0045] A computer-readable storage medium stores a program executable by a processor, wherein the program executable by the processor is used to execute the method described above when executed by the processor.

[0046] The beneficial effects of the present invention are as follows: the present invention adopts a GPU-friendly design, and according to the computing characteristics of the GPU, through a small amount of experiments, selects an appropriate number of heads to improve the reasoning ability of the model on the GPU, and optimizes the reasoning speed on the GPU while keeping the theoretical calculation amount unchanged. BRIEF DESCRIPTION OF THE DRAWINGS

[0047] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the embodiments of the present invention or the drawings of related technical solutions in the prior art are introduced below. It should be understood that the drawings introduced below are only for the convenience of clearly describing some embodiments of the technical solutions of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0048] Figure 1 is a flowchart of the steps of a training optimization method for a lightweight visual Transformer in an embodiment of the present invention;

[0049] Figure 2 Flowchart of MAE self-supervised training in an embodiment of the present invention. DETAILED DESCRIPTION

[0050] The embodiments of the present invention are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and are not to be construed as limitations of the present invention. For the step numbers in the following embodiments, they are only provided for the convenience of explanation, and the order between the steps is not limited in any way, and the execution order of each step in the embodiment can be adaptively adjusted according to the understanding of those skilled in the art.

[0051] In the description of the present invention, it should be understood that descriptions involving orientations, such as up, down, front, back, left, right, etc., and orientations or positional relationships indicated are based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present invention.

[0052] In the description of the present invention, the meaning of "several" is one or more, the meaning of "more" is two or more, and the meanings of "greater than", "less than", "exceed" and the like are understood as not including the number itself, and the meanings of "above", "below", "within" and the like are understood as including the number itself. If there is a description of the first and the second, it is only used for the purpose of distinguishing the technical features, and cannot be understood as indicating or implying the relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features. In addition, "and / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the related objects before and after are in an "or" relationship.

[0053] In the description of the present invention, unless otherwise clearly defined, terms such as setting, installing, connecting, etc. should be understood in a broad sense, and technicians in the relevant technical field can reasonably determine the specific meanings of the above terms in the present invention based on the specific content of the technical solution.

[0054] Terminology explanation:

[0055] GPU: abbreviation of graphics processing unit, graphics processor.

[0056] Pre-training of lightweight visual Transformer models is usually divided into two steps: pre-training and distillation training. During the pre-training process, the Transformer model architecture can be designed based on indicators such as the amount of computation, and then a suitable pre-training method can be selected to perform pre-training on a given dataset. After pre-training is completed, in order to further reduce the size of the model and improve inference efficiency, distillation technology can be used to transfer the knowledge of the pre-trained model to a smaller, lighter model.

[0057] Because the theoretical computational amount of the attention module of the Transformer model is consistent, current methods generally believe that the reasoning speed of the Transformer model is only related to the computational amount, so the impact of GPU computing characteristics on the reasoning speed is not considered when designing the model. The present invention adopts a GPU-friendly design, and can select an appropriate number of heads based on the computing characteristics of the GPU through a small number of experiments to improve the reasoning ability of the model on the GPU. While keeping the theoretical computational amount unchanged, the reasoning speed on the GPU is optimized, which is a significant difference from the prior art.

[0058] like Figure 1 The present embodiment provides a lightweight visual Transformer training optimization method, which can select appropriate parameters for the model according to the GPU's own computing characteristics for different scenarios, and use distillation technology and self-supervised pre-training to obtain a lightweight visual pre-training model. The method specifically includes the following steps:

[0059] S1. Use an untrained Transformer model on the GPU to test the inference speed for different numbers of attention heads to obtain the first number of suitable inference speeds.

[0060] This embodiment is aimed at the computational vision model based on the Transformer model, including three major tasks: classification, detection, and segmentation. The method requires the user to design a deep learning model based on the Transformer. θ (·), where the model parameter is θ and the number of attention heads is a.

[0061] The attention calculation formula and corresponding calculation amount in the Transformer model are as follows:

[0062] Q=x*W Q ,K=x*W k ,V=x*W V

[0063] Where x is the input, W Q , W K , W V is the weight matrix used for attention calculation. Q is the query vector, K is the key vector, and V is the value vector; x out is the output of the current layer, W o It is a linear transformation matrix used to reduce the dimension, h is the second dimension value of the query vector Q, and T represents transpose.

[0064]

[0065] Table 1. Calculation of attention mechanism

[0066]

[0067] Assume that the dimensions of x are (b, s, h), W Q / K / V The dimension is (h,h), a is the number of attention heads, b is the number of samples in the current batch of data, s is the number of image blocks in the current layer, and h is the feature dimension of the image blocks in the current layer. According to Table 1 above, the number of attention heads a has no effect on the final calculation amount. Although the theoretical calculation amount of different attention heads is the same, due to the parallel computing characteristics of the GPU, when using the GPU to infer and train the model, the calculation speed of using fewer attention heads is often faster than that of using more attention heads. However, the performance of models with more attention heads is often better than that of models with fewer attention heads, so we can choose as many attention heads as possible while meeting the inference speed.

[0068] After completing the model design, users can use existing data sets or construct virtual data to deploy the data and model on the GPU for reasoning. After the GPU is warmed up (that is, after a certain number of reasoning rounds, when the GPU reasoning speed tends to be stable), the number of attention heads a and the corresponding reasoning speed t of the current test can be recorded.

[0069]

[0070] Where n is the number of inference samples, t total is the total inference time for multiple samples.

[0071] After a series of tests, we can get a set of attention heads with a iAnd the corresponding inference speed is t i We can use the appropriate inference speed t i The corresponding attention head a i To set the number of attention heads for the Transformer model.

[0072] S2. Set the number of attention heads of the Transformer model to the first number, and use MAE and distillation methods to perform self-supervised pre-training on the Transformer model.

[0073] This embodiment is aimed at a computer vision model based on the Transformer model, in which the MAE method is a self-supervised pre-training framework of the Transformer model:

[0074] See also Figure 2 ,MAE is an autoencoder architecture for self-supervised learning tasks. An autoencoder is a neural network architecture consisting of two main parts: an encoder and a decoder. The encoder compresses the input data into a latent representation, and the decoder attempts to reconstruct the input data from this latent representation, with the goal of minimizing the reconstruction error between the input and the output.

[0075] In traditional autoencoders, the encoder and decoder are usually fully connected neural networks. However, in MAE, a masking strategy is applied to restrict the connections between the encoder and decoder. This masking ensures that the autoencoder can only access partial information during encoding and decoding.

[0076] This embodiment uses a larger teacher model (for example, the mae_vit_base_patch16 model) to distill and train a smaller student model (for example, the mae_vit_tiny_patch16 model), so that the student model can learn the relevant parameters in the teacher model as much as possible with fewer parameters:

[0077] L attn =MSE(A T ,MA S )

[0078] Among them, L attn The loss function used for distillation training is used to train the model by comparing the difference between the attention weights of the teacher model and the student model during the knowledge distillation process. In the attention mechanism, the attention weights at different positions reflect the degree of attention paid by the model to the input. Therefore, by minimizing the mean square error between the two, the student model can be encouraged to learn the attention pattern of the teacher model at different positions. T and A Sare the attention weights of the teacher model and the student model respectively, and M is a learnable mapping matrix used to align the attention weights of the teacher model and the student model so that the two can be directly compared.

[0079] S3. Apply the self-supervised trained Transformer model to different downstream tasks and perform fine-tuning training.

[0080] According to the above steps, we can obtain a general Transformer-based computer vision model that is pre-trained on a larger dataset. We can fine-tune this model on a specific dataset for a variety of downstream tasks to adapt to different task requirements, such as classification, detection, and segmentation.

[0081] S4. Perform inference speed and accuracy tests on the fine-tuned model to observe whether the inference speed and accuracy of the model meet expectations.

[0082] After completing the entire training process, we can deploy the model to the GPU, load the trained parameters into the model, and then deploy the test data to the GPU as well. After the GPU is warmed up, perform accuracy tests and inference speed tests to observe whether the inference speed reaches the expected target after the accuracy reaches a certain requirement. If it does not reach the expected target, you can consider adjusting the number of attention heads and retraining.

[0083] In summary, the present invention has designed a complete set of acceleration solutions based on the Transformer model and GPU reasoning characteristics. Through experiments, the number of attention heads of the Transformer-based visual model can be independently selected according to the required requirements, so that it can obtain an ideal reasoning speed improvement on GPU reasoning while meeting the accuracy requirements. The present invention is applicable to all Transformer-based visual models.

[0084] This embodiment also provides a lightweight visual Transformer training optimization device, including:

[0085] The inference speed test module is used to use an untrained Transformer model on the GPU to perform inference speed tests for different numbers of attention heads to obtain the first number of suitable inference speeds;

[0086] A self-supervised pre-training module, used to set the number of attention heads of the Transformer model to the first number, and perform self-supervised pre-training on the Transformer model using MAE and distillation methods;

[0087] The model fine-tuning module is used to apply the self-supervised trained Transformer model to different downstream tasks and perform fine-tuning training;

[0088] The performance evaluation module is used to test the inference speed and accuracy of the fine-tuned model to evaluate the performance of the model.

[0089] A lightweight visual Transformer training optimization device of this embodiment can execute a lightweight visual Transformer training optimization method provided by the method embodiment of the present invention, can execute any combination of implementation steps of the method embodiment, and has the corresponding functions and beneficial effects of the method.

[0090] This embodiment also provides a lightweight visual Transformer training optimization device, including:

[0091] at least one processor;

[0092] at least one memory for storing at least one program;

[0093] When the at least one program is executed by the at least one processor, the at least one processor implements Figure 1 The method shown.

[0094] A lightweight visual Transformer training optimization device of this embodiment can execute a lightweight visual Transformer training optimization method provided by the method embodiment of the present invention, can execute any combination of implementation steps of the method embodiment, and has the corresponding functions and beneficial effects of the method.

[0095] The present application also discloses a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. A processor of a computer device can read the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes Figure 1 The method shown.

[0096] This embodiment also provides a storage medium, which stores instructions or programs that can execute a lightweight visual Transformer training optimization method provided by the method embodiment of the present invention. When the instructions or programs are run, any combination of implementation steps of the method embodiment can be executed, and the corresponding functions and beneficial effects of the method can be obtained.

[0097] In some selectable embodiments, the function / operation mentioned in the block diagram may not occur in the order mentioned in the operation diagram. For example, depending on the function / operation involved, the two boxes shown in succession can actually be executed substantially simultaneously or the boxes can sometimes be executed in reverse order. In addition, the embodiment presented and described in the flow chart of the present invention is provided by way of example, for the purpose of providing a more comprehensive understanding of technology. The disclosed method is not limited to the operation and logic flow presented herein. Selectable embodiments are expected, wherein the order of various operations is changed and the sub-operation of a part for which is described as a larger operation is performed independently.

[0098] In addition, although the present invention is described in the context of functional modules, it should be understood that, unless otherwise specified, one or more of the functions and / or features described may be integrated into a single physical device and / or software module, or one or more functions and / or features may be implemented in separate physical devices or software modules. It is also understood that a detailed discussion of the actual implementation of each module is unnecessary for understanding the present invention. More specifically, in view of the properties, functions, and internal relationships of the various functional modules in the device disclosed herein, the actual implementation of the module will be understood within the conventional skills of the engineer. Therefore, those skilled in the art can implement the present invention set forth in the claims without excessive experimentation using ordinary techniques. It is also understood that the specific concepts disclosed are merely illustrative and are not intended to limit the scope of the present invention, which is determined by the full scope of the appended claims and their equivalents.

[0099] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.

[0100] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in conjunction with such instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in conjunction with such instruction execution systems, devices or apparatuses.

[0101] More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk case (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be a paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering or, if necessary, processing in another suitable manner, and then stored in a computer memory.

[0102] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0103] In the above description of this specification, the description with reference to the terms "one embodiment / example", "another embodiment / example" or "certain embodiments / examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0104] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the claims and their equivalents.

[0105] The above is a specific description of the preferred implementation of the present invention, but the present invention is not limited to the above embodiments. Those skilled in the art may make various equivalent modifications or substitutions without violating the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of this application.

Claims

1. A lightweight visual Transformer training optimization method, characterized in that: The following steps are involved: Use an untrained Transformer model on a GPU to test the inference speed for different numbers of attention heads to get the first number of suitable inference speeds; Set the number of attention heads of the Transformer model to the first number, and use MAE and distillation methods to perform self-supervised pre-training on the Transformer model; Apply the self-supervised trained Transformer model to different downstream tasks and perform fine-tuning training; The fine-tuned model is tested for inference speed and accuracy to evaluate the performance of the model.

2. According to claim 1, a lightweight visual Transformer training optimization method is characterized in that: The inference speed test is performed for different numbers of attention heads to obtain a first number of suitable inference speeds, including: Obtain a dataset, and deploy the dataset and an untrained Transformer model on a GPU for inference; After performing a preset round of inference on the GPU, the number of attention heads a and the corresponding inference speed t of the current test are obtained; After multiple tests, we get a set of attention heads with a i And the corresponding inference speed is t i data, according to the appropriate inference speed t i The corresponding attention head a i To set the number of attention heads for the Transformer model.

3. According to claim 2, a lightweight visual Transformer training optimization method is characterized in that: The calculation formula of inference speed t is as follows: Among them, n is the number of inference samples, t total is the total inference time for multiple samples.

4. According to claim 1, a lightweight visual Transformer training optimization method is characterized in that: The attention calculation formula and corresponding calculation amount in the Transformer model are as follows: Q=x*W Q ,K=x*W K ,V=x*W V Where x is the input, W Q , W K , W V is the weight matrix; Q is the query vector, K is the key vector, and V is the value vector; x out is the output of the current layer, W o is the linear transformation matrix, h is the second dimension value of the query vector Q, and T represents transpose.

5. The method for training and optimizing a lightweight visual Transformer according to claim 1, characterized in that: The self-supervised pre-training of the Transformer model using MAE and distillation methods includes: The teacher model is used to distill and train the student model so that the student model can learn the relevant parameters in the teacher model as much as possible with fewer parameters: L attn =MSE(A T ,MY S ) Among them, L attn A is the loss function used for distillation training. The role of this loss function is to train the model by comparing the difference between the attention weights of the teacher model and the student model during the knowledge distillation process. In the attention mechanism, the attention weights at different positions reflect the degree of attention of the model to the input. Therefore, by minimizing the mean square error between the two, the student model is prompted to learn the attention mode of the teacher model at different positions. T and A S are the attention weights of the teacher model and the student model respectively, and M is a learnable mapping matrix used to align the attention weights of the teacher model and the student model so that the two can be directly compared.

6. The method for training and optimizing a lightweight visual Transformer according to claim 1, characterized in that: The downstream tasks include classification tasks, detection tasks or segmentation tasks.

7. The method for training and optimizing a lightweight visual Transformer according to claim 1, characterized in that: The fine-tuned model is tested for inference speed and accuracy to evaluate the performance of the model, including: Deploy the Transformer model to the GPU and load the trained parameters into the model; Deploy test data to GPU; After GPU warm-up, perform accuracy test and inference speed test to observe whether the inference speed reaches the expected target after the accuracy reaches the preset requirement. If it does not reach the expected target, continue to adjust the number of attention heads and retrain.

8. A lightweight visual Transformer training optimization device, characterized in that: include: The inference speed test module is used to use an untrained Transformer model on the GPU to perform inference speed tests for different numbers of attention heads to obtain the first number of suitable inference speeds; A self-supervised pre-training module, used to set the number of attention heads of the Transformer model to the first number, and perform self-supervised pre-training on the Transformer model using MAE and distillation methods; The model fine-tuning module is used to apply the self-supervised trained Transformer model to different downstream tasks and perform fine-tuning training; The performance evaluation module is used to test the inference speed and accuracy of the fine-tuned model to evaluate the performance of the model.

9. A lightweight visual Transformer training optimization device, characterized in that: include: at least one processor; at least one memory for storing at least one program; When the at least one program is executed by the at least one processor, the at least one processor implements the method according to any one of claims 1 to 7.

10. A computer-readable storage medium storing a program executable by a processor, characterized in that: The processor-executable program is used to perform the method according to any one of claims 1 to 7 when executed by the processor.

Citation Information

Cited By

  • Method, device and system for identifying hidden dangers of chemical equipment

    CN119851204A

  • Visual perception method of humanoid robot and related equipment

    CN121962722A