Adaptive parameter efficient fine tuning method, device and equipment and storage medium
By building a hypernetwork with efficient parameter fine-tuning and adaptively selecting the best parameter fine-tuning module, the problem of poor fine-tuning of pre-trained models caused by manual provisioning strategies in the existing technology is solved, and the model performance and resource utilization of medical tasks are improved.
Patent Information
- Application Number
- CN202411296643.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-14
- Publication Date
- 2024-12-27
AI Technical Summary
In the prior art, the parameter fine-tuning strategy of the pre-trained model relies on manual regulations and fails to automatically optimize according to downstream tasks, resulting in poor fine-tuning effects, especially in medical scenarios, which are not well adapted to multiple tasks.
提出一种自适应参数高效微调方法,通过构建参数高效微调超网络,利用多个参数微调模块(如LoRA、adapter、Prefix)进行筛选和训练,根据任务需求自适应选择最佳的参数微调模块,调整预训练模型的隐状态,实现模型的自适应优化。
By adaptively selecting the best parameter fine-tuning module, the ability to unlock the large model to the greatest extent, improves the average performance of the model in medical tasks, and improves resource utilization and generalization capabilities.
Smart Images

Figure CN119204106A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of medical health technology, and in particular to an adaptive parameter efficient fine-tuning method, device, equipment and storage medium. Background Art
[0002] Pre-trained models are models that are trained through unsupervised learning on large-scale data. These models usually learn general language knowledge, semantic representation, and grammatical structure. Pre-trained models have achieved remarkable results in many natural language processing tasks, such as text classification, sentiment analysis, and machine translation. With the development of pre-trained language models, more and more language model parameters exceed 300 million or 1 billion, which makes it impossible for enterprises to deploy a model for a task. Therefore, efficient parameter fine-tuning methods are very important.
[0003] For each different task (data set), the parameters can be efficiently fine-tuned. Only a few million parameters need to be fine-tuned to adapt a relatively large pre-trained model to the task, and the performance can be basically the same or very close to that of directly using all the parameters of the entire model for a task fine-tuning. This plays a very important role in medical scenarios. In medical scenarios, a large model backbone needs to support multiple scenarios such as physical examination report extraction, case understanding, knowledge question and answer, and patient management. Therefore, efficient parameter fine-tuning, a model fine-tuning-inference solution that saves video memory, is very important.
[0004] However, in the prior art, when various efficient parameter fine-tuning schemes are used in combination, a certain manually prescribed strategy is generally adopted without automatic optimization according to downstream tasks, so that the fine-tuning effect does not reach the best. Summary of the invention
[0005] The purpose of the embodiments of the present application is to propose an efficient adaptive parameter fine-tuning method, device, equipment and storage medium to solve the problem that the manual fine-tuning strategy of the model parameters of the pre-trained model is not effective.
[0006] In order to solve the above technical problems, the embodiment of the present application provides an efficient fine-tuning method for adaptive parameters, which adopts the following technical solutions, including:
[0007] Acquire a parameter efficient fine-tuning super network, wherein the parameter efficient fine-tuning super network includes a plurality of parameter fine-tuning modules;
[0008] Acquire training parameters, use the training parameters to participate in parameter training of the multiple parameter fine-tuning modules, acquire weight values of the parameter fine-tuning modules, acquire selection factors according to the weight values, and use the selection factors to screen the multiple parameter fine-tuning modules in the parameter efficient fine-tuning super network to obtain a target parameter fine-tuning module;
[0009] The target parameter fine-tuning module is used to participate in the forward propagation of the transformer layer of the pre-trained model to modify the hidden state of the input sample outputted by the transformer layer.
[0010] Furthermore, the obtaining of the highly efficient parameter fine-tuning super network specifically includes:
[0011] Obtain the LoRA parameter efficient fine-tuning model, adapter parameter efficient fine-tuning model, and Prefix parameter efficient fine-tuning model respectively;
[0012] Obtain a first parameter fine-tuning module and a second parameter fine-tuning module from the LoRA parameter efficient fine-tuning model, obtain a third parameter fine-tuning module and a fourth parameter fine-tuning module from the adapter parameter efficient fine-tuning model, and obtain a fifth parameter fine-tuning module and a sixth parameter fine-tuning module from the Prefix parameter efficient fine-tuning model;
[0013] The parameter efficient fine-tuning super network is obtained according to the first parameter fine-tuning module, the second parameter fine-tuning module, the third parameter fine-tuning module, the fourth parameter fine-tuning module, the fifth parameter fine-tuning module and the sixth parameter fine-tuning module.
[0014] Further, the obtaining of training parameters, involving the training parameters in the parameter training of the plurality of parameter fine-tuning modules, obtaining weight values of the parameter fine-tuning modules, obtaining selection factors according to the weight values, and using the selection factors to screen the plurality of parameter fine-tuning modules in the parameter efficient fine-tuning super network to obtain a target parameter fine-tuning module includes:
[0015] Input the training parameters into each parameter fine-tuning module, increase or decrease the weight value of each parameter fine-tuning module according to a preset step size, perform training learning with the goal of the training parameters being positively correlated with the weight value of the parameter fine-tuning module, and obtain the training parameters after training learning as the first selection factor, wherein one parameter fine-tuning module corresponds to one first selection factor;
[0016] Determining whether the first selection factor is greater than a first preset threshold;
[0017] If it is greater than the first preset threshold, the parameter fine-tuning module is retained;
[0018] If it is less than the first preset threshold, the parameter fine-tuning module is deleted.
[0019] Further, the method of obtaining training parameters, involving the training parameters in parameter training of the plurality of parameter fine-tuning modules, obtaining weight values of the parameter fine-tuning modules, obtaining selection factors according to the weight values, and using the selection factors to screen the plurality of parameter fine-tuning modules in the parameter efficient fine-tuning super network to obtain a target parameter fine-tuning module further includes:
[0020] Using the Bernoulli random number as a weight value to weight the training parameter, and using the weighted training parameter as a second selection factor;
[0021] Determine whether the value of the second selection factor is 1;
[0022] If the value of the second selection factor is 1, the parameter fine-tuning module is retained;
[0023] If the value of the second selection factor is 0, the parameter fine-tuning module is deleted.
[0024] Furthermore, the method of weighting the training parameters by using Bernoulli random numbers and using the weighted training parameters as the second selection factor includes:
[0025] Random sampling to obtain the Bernoulli random number;
[0026] The training parameter is multiplied by the Bernoulli random number to obtain a second selection factor.
[0027] Furthermore, the target parameter fine-tuning module is used to participate in the forward propagation of the transformer layer of the pre-trained model to modify the hidden state of the input sample outputted by the transformer layer, including:
[0028] Use the first layer function of the pre-trained model transformer layer to perform the first operation on the input sample to obtain the first hidden state;
[0029] Modify the first hidden state using the selected parameter fine-tuning module to obtain the second hidden state;
[0030] A second operation is performed on the second hidden state using the second layer function of the transformer layer of the pre-trained model to obtain a third hidden state.
[0031] Furthermore, after performing a second operation on the second hidden state using the second layer function of the pre-trained model transformer layer to obtain a third hidden state, the method further includes:
[0032] Get the hidden states corresponding to any two different parameter fine-tuning modules output after forward propagation of the pre-trained model transformer layer;
[0033] Utilizing two different hidden states to obtain a loss function for efficiently fine-tuning the hypernetwork of the parameters;
[0034] The loss function is used to calculate the mean square error value of any two parameter fine-tuning modules in the parameter efficient fine-tuning super network, and the mean square error value is fed back to the parameter efficient fine-tuning super network.
[0035] In order to solve the above technical problems, the embodiment of the present application further provides an adaptive parameter efficient fine-tuning device, which adopts the adaptive parameter efficient fine-tuning method described in the first aspect, including:
[0036] An acquisition module, used for acquiring a parameter efficient fine-tuning super network, wherein the parameter efficient fine-tuning super network includes a plurality of parameter fine-tuning modules;
[0037] A screening module, used to obtain training parameters, use the training parameters to participate in the parameter training of the multiple parameter fine-tuning modules, obtain weight values of each parameter fine-tuning module, and obtain a selection factor according to the weight value, and use the selection factor to screen the multiple parameter fine-tuning modules in the parameter efficient fine-tuning super network to obtain a target parameter fine-tuning module;
[0038] The modification module is used to participate in the forward propagation of the transformer layer of the pre-trained model and modify the hidden state of the input sample output at the transformer layer.
[0039] In order to solve the above technical problems, an embodiment of the present application also provides a computer device, including a memory and a processor, wherein the memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, the steps of the adaptive parameter efficient fine-tuning method as described above are implemented.
[0040] In order to solve the above technical problems, an embodiment of the present application further provides a computer-readable storage medium, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor, the steps of the adaptive parameter efficient fine-tuning method as described above are implemented.
[0041] Compared with the prior art, the embodiments of the present application mainly have the following technical effects: by constructing a parameter efficient fine-tuning super network, different types of parameter fine-tuning modules can be used at the same time, so that the pre-trained model can adaptively select the best parameter efficient fine-tuning module according to the task, thereby unlocking the capabilities of the large model to the greatest extent and improving the average performance of the deployed model on various medical tasks. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0043] Figure 1 A flowchart of an embodiment of an efficient fine-tuning method for adaptive parameters according to the present application;
[0044] Figure 2 yes Figure 1 A flowchart of a specific implementation of step 100;
[0045] Figure 3 yes Figure 1 A flowchart of a specific implementation of step 200;
[0046] Figure 4 yes Figure 1 A flowchart of another specific implementation of step 200;
[0047] Figure 5 yes Figure 4 A flowchart of a specific implementation of step 250;
[0048] Figure 6 yes Figure 1 A flowchart of a specific implementation of step 300;
[0049] Figure 7 yes Figure 6 The flowchart after step 330;
[0050] Figure 8 (a)- Figure 8 (c) is a schematic diagram of a specific implementation of various parameter fine-tuning methods;
[0051] Fig. 9 is a structural schematic diagram of an embodiment of an adaptive parameter efficient fine-tuning device according to the present application;
[0052] Fig.10 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION
[0053] The following will be combined with the accompanying drawings in the invention to clearly and completely describe the technical solutions in the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, other embodiments obtained by ordinary technicians in this field without creative work are all within the scope of protection of the present invention.
[0054] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0055] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by technicians in the technical field to which this application belongs; the terms used in the specification of the application are only for the purpose of describing specific embodiments and are not intended to limit this application; the terms "including" and "having" in the specification and claims of this application and the above-mentioned figure descriptions and any variations thereof are intended to cover non-exclusive inclusions.
[0056] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0057] The adaptive parameter efficient fine-tuning method provided in the embodiment of the present application can be applied to a computer device with the ability to run instructions or programs. Among them, the computer device can be, but is not limited to, various servers, workstations, personal computers, laptops, etc. Running on different computing devices is only a difference in the execution subject of the scheme. People in this field can foresee that running on different computing devices can produce the same technical effect. The present invention is described in detail below through specific embodiments.
[0058] The purpose of the embodiments of the present application is to propose an efficient adaptive parameter fine-tuning method, device, equipment and storage medium to solve the problem that the manual fine-tuning strategy of the model parameters of the pre-trained model is not effective.
[0059] In order to solve the above technical problems, Figure 1 , Figure 1 According to a flowchart of an embodiment of an adaptive parameter efficient fine-tuning method of the present application, the method includes:
[0060] S100, obtaining a parameter-efficient fine-tuning super network, where the parameter-efficient fine-tuning super network includes a plurality of parameter fine-tuning modules (Parameter-Efficient Fine-Tuning, PEFT).
[0061] In this embodiment, the parameter fine-tuning module is a technique for fine-tuning a large pre-trained model by adapting it to a new task by adjusting only a small number of additional parameters, rather than fine-tuning all the parameters of the model. This approach significantly reduces computational and storage costs while achieving performance comparable to full fine-tuning. The application of parameter fine-tuning modules is not limited to saving resources, it also helps improve the generalization ability of the model, avoids overfitting, and performs better in low-data states. In addition, the lightweight nature of parameter fine-tuning modules makes them very suitable for use in resource-constrained environments, such as fine-tuning large models on consumer-grade hardware.
[0062] The computer device on which the adaptive parameter efficient fine-tuning method runs (e.g. Figure 8 The network module of the computer device shown in the figure can adopt a wired connection method or a wireless connection method. It should be noted that the above wireless connection methods may include but are not limited to 3G / 4G / 5G connection, WiFi connection, Bluetooth connection, WiMAX connection, Zigbee connection, UWB (ultrawideband) connection, and other wireless connection methods currently known or to be developed in the future.
[0063] The method provided by the present invention can be used to fine-tune the parameters of a pre-trained model to solve the following problem: when various different efficient parameter fine-tuning schemes are currently used in combination, a certain manually specified strategy is generally adopted, and automatic optimization is not performed according to downstream tasks, so that the fine-tuning effect does not reach the best.
[0064] Figure 2 yes Figure 1 A flowchart of a specific implementation of S100 is shown in FIG. S100 includes:
[0065] S110, respectively obtaining a LoRA parameter efficient fine-tuning model, an adapter parameter efficient fine-tuning model, and a Prefix parameter efficient fine-tuning model;
[0066] S120, obtaining a first parameter fine-tuning module and a second parameter fine-tuning module from the LoRA parameter efficient fine-tuning model, obtaining a third parameter fine-tuning module and a fourth parameter fine-tuning module from the adapter parameter efficient fine-tuning model, and obtaining a fifth parameter fine-tuning module and a sixth parameter fine-tuning module from the Prefix parameter efficient fine-tuning model;
[0067] S130. Obtain a parameter efficient fine-tuning super network according to the first parameter fine-tuning module, the second parameter fine-tuning module, the third parameter fine-tuning module, the fourth parameter fine-tuning module, the fifth parameter fine-tuning module, and the sixth parameter fine-tuning module.
[0068] like Figure 8 , Figure 8It is a schematic diagram of a specific implementation of various parameter fine-tuning methods; there are many known parameter efficient fine-tuning methods, Figure 8 Three different methods for efficient parameter fine-tuning are shown in Figure 8 (a) is the efficient fine-tuning method of LoRA parameters. Figure 8 (b) is the efficient fine-tuning method for Prefixtuning parameters. Figure 8 (c) is an efficient fine-tuning method for adapter tuning parameters. The efficient fine-tuning method for LoRA parameters is to adjust the parameter matrix W k The Prefix tuning parameter is changed to an efficient fine-tuning method that represents the vector P of the sample. k A randomly initialized parameter matrix W is k The adapter modifies the hidden state of each transformer layer output.
[0069] In this embodiment, a parameter efficient fine-tuning super network is constructed by using multiple parameter fine-tuning modules, and then the best parameter fine-tuning module can be selected for modification according to the downstream task.
[0070] exist Figure 8 (a) Figure 8 (b) Figure 8 In (c), the first parameter fine-tuning module, the second parameter fine-tuning module, the third parameter fine-tuning module, the fourth parameter fine-tuning module, the fifth parameter fine-tuning module, and the sixth parameter fine-tuning module refer to the parameter matrix W k , LoRA parameter fine-tuning module, parameter matrix HW k , vector representation P k , transformer block module and adapter parameter fine-tuning module.
[0071] However, when fine-tuning the parameters of the pre-trained model, only one parameter fine-tuning module can be used to fine-tune the parameters for a task, so it is not possible to select the best parameter fine-tuning module for modification according to the downstream task.
[0072] For example, a large model backbone needs to support multiple medical scenarios including: physical examination report extraction, case understanding, knowledge question and answer, patient management, etc. For different medical scenarios, efficient parameter fine-tuning is required. However, currently some manually prescribed strategies are generally adopted, and there is no automatic optimization based on downstream tasks, so that the fine-tuning effect does not reach the best.
[0073] For general pre-training models, the Transformer architecture used includes:
[0074] Input layer: Receives raw data, such as a sequence of words in text or a matrix of pixels in an image.
[0075] Middle layer: contains multiple hidden layers, which gradually learn the abstract representation of data by continuously extracting and transforming features. These hidden layers can be fully connected layers, convolutional layers, self-attention layers, etc.
[0076] Fine-tuning layer: Further training and adjustment based on the parameters of the pre-trained model.
[0077] Output layer: Outputs the corresponding results according to different tasks. For example, in a text classification task, the output layer may be a classifier that gives the probability distribution of different categories.
[0078] When fine-tuning the transformer layer of the pre-trained model, assuming that its parameter fine-tuning module is PEFT i , the hidden state of the input sample before entering this transformer layer is H0, and its hidden state when it reaches PEFT i Some operations that pass through the transformer layer before accessing the position (denoted as function f i ) The hidden state before is H i,0 , after PEFT i Then it becomes H i,1 Then, the remaining operations of the transformer layer (denoted as function g i ) to obtain the parameter fine-tuning module PEFT i Hidden state after fine-tuning The principle of the whole process is as shown in formula (1):
[0079]
[0080] In the embodiment of the present application, first, a parameter efficient fine-tuning super network is constructed, that is, we can choose Figure 8 One or more PEFT i ,PEFT i The number and type of are adaptively determined according to the downstream tasks.
[0081] For example, in pathology analysis, the backbone of the pre-trained pathology analysis model has several transformer layers, and a parameter fine-tuning module (such as an Adapter module) is added to each transformer layer, where the Adapter module is added after the linear connection layer of the transformer.
[0082] It is understandable that the Adapter module is a commonly used parameter fine-tuning module PEFT i After adding the Adapter module, the pathology analysis model's representation of the sample changed from H0 to H1. (i) . Through adaptive selection of PEFTi , you can get better performance in a downstream task (such as tumor classification, fibrosis assessment, and cancer staging). S200, get training parameters The training parameters Participate in multiple PEFTs i Parameter training and acquisition of each PEFT i The weight value is obtained according to the weight value, and the selection factor is used to efficiently fine-tune the parameters of multiple PEFT in the hypernetwork. i Screening is performed to obtain the target parameter fine-tuning module.
[0083] Adaptive determination of PEFT i The whole process principle of the scheme processing the input samples can be expressed by formula (2):
[0084]
[0085] in, is a training parameter, a learnable scalar with a value range of (0, 1).
[0086] In this embodiment, the PEFT after screening i There can be multiple numbers, and the specific number can be determined by screening based on the first selection factor and the second selection factor.
[0087] In some optional implementations, such as Figure 3 , Figure 3 yes Figure 1 A flowchart of a specific implementation of S200; S200 includes:
[0088] S210, training parameter reference With each PEFT i The parameters of training and learning, training parameters With PEFT i The weight value is positively correlated, and increases or decreases with a preset step size, and the training parameters after training are As the first selection factor σ i ;
[0089] S220 determines the first selection factor σ i whether it is greater than a first preset threshold;
[0090] S230: If it is greater than the first preset threshold, retain PEFT i ;
[0091] S240: If the value is less than the first preset threshold, delete PEFT i .
[0092] In this embodiment, the first selection factor σ is used i Adaptive determination of PEFT i The whole process principle of the scheme processing the input samples can be expressed by formula (3):
[0093]
[0094] Among them, σ i is the first selection factor.
[0095] In this embodiment, a first preset threshold t can be set * , if the first selection factor σ i Greater than the first preset threshold t * , then retain PEFT i , otherwise delete PEFT i In this way, by adjusting the first preset threshold, redundant PEFT can be deleted. i .
[0096] In specific applications, such as pathology analysis, medical image analysis, disease prediction and other tasks, the medical data is different. You can choose the corresponding PEFT according to the different downstream tasks. i It is understandable that each task has customized goals and requirements. Even for the same pathology analysis task, the requirements of tumor classification task, fibrosis assessment task and cancer staging task are different. The PEFT obtained by adaptive selection i More suitable for solving specific tasks.
[0097] The first selection factor σ i The parameters are considered as part of the model parameters, as PEFT i Finally, the training parameters are learned together. The first selection factor σ obtained by learning i , will be close to 0 or 1. If it is close to 0, it means that this PEFT on the customized task i is not very important. Participate in various PEFT i Parameter training and learning, obtain the first selection factor σ i And use the first preset threshold to compare the PEFT i Through screening and selection, automatic optimization can be performed according to downstream tasks to achieve better parameter fine-tuning effects.
[0098] In some optional implementations, such as Figure 4 , Figure 4 yes Figure 1 Flow chart of another specific implementation of S200; S200 includes:
[0099] S250, the Bernoulli random number γ i As weight value for training parameter Weighted, the weighted training parameters are used as the second selection factor
[0100] S260, determine the second selection factor Is the value of 1?
[0101] S270, if the second selection factor If the value is 1, the PEFT is retained. i ;
[0102] S280, if the second selection factor If the value is 0, delete PEFT i .
[0103] In this embodiment, although the first selection factor σ can be learned i Parameters, and finally delete the less important PEFT i , but in training and final use, PEFT i The composition is different, and the training parameters are used Get the first selection factor σ i This will result in some modules not being fully trained. So it will lead to the first selection factor σ i PEFT obtained by parameter learning i The importance is inaccurate.
[0104] By utilizing Bernoulli random numbers γ i For training parameters Weighted to obtain the second selection factor Make each PEFT i Fully participate in training, so as to train parameters and learn to obtain each PEFT i The weight value, that is, the obtained weight value or importance parameter is more accurate.
[0105] In order to ensure the training parameters Parameters can express PEFT i The importance of Figure 5 , Figure 5 yes Figure 4 A flowchart of a specific implementation of S250 is provided; the following regularization method is provided: S250 includes:
[0106] S251, random sampling, obtain Bernoulli random number γ i ;
[0107] S252, training parameters With Bernoulli random numbers γ i Multiply to get the second selected factor
[0108] In each forward propagation, for each training parameter Randomly sample a Bernoulli random number γ i , this random number takes the value of 0 or 1, with a probability of p = 0.5 of 1. Then, the second selection factor in this embodiment The value of With Bernoulli random numbers γ i Multiply them together to get PEFT i Whether it can be used by Bernoulli random numbers γ i Decide that:
[0109]
[0110] Using the first selection factor σ i Adaptive determination of PEFT i The whole process principle of the scheme processing the input samples can be expressed by formula (5):
[0111]
[0112] in, is the second selection factor.
[0113] By utilizing Bernoulli random numbers γ i For training parameters Weighted to obtain the second selection factor Each forward propagation will activate different PEFTs due to the randomness of Bernoulli random numbers. i , and get different results.
[0114] S300, using the target to participate in the forward propagation of the transformer layer of the pre-trained model, modify the hidden state of the input sample output at the transformer layer.
[0115] The general structure of the pre-training model includes:
[0116] The input layer receives the text sequence and first adds a special tag [CLS] at the beginning of the text to represent the characteristics of the entire sentence or text. In the sentence pair task, two sentences are separated by the [SEP] tag. At the same time, each word is segmented and converted into the corresponding word vector, position vector, and segment vector.
[0117] Embedding layer. It consists of three types of vectors: Word Embeddings: maps each word to a vector of fixed dimension to capture the semantic information of the word. Position Embeddings: represents the position information of the word in the text, because the position of the word is an important feature in many natural language processing tasks. Segment Embeddings: used to distinguish different sentences in sentence pair tasks.
[0118] The encoding layer is composed of multiple identical Transformer encoder layers stacked together. Each Transformer encoder layer mainly contains two sub-layers. 1. Multi-Head Attention Mechanism: Allows the model to focus on information in different positions at the same time, enhancing the ability to understand the text. By calculating the attention weight, dynamically adjust the attention to different parts / 2. Feed-Forward Neural Network: Perform further nonlinear transformation on the output of the multi-head attention mechanism to extract more complex features.
[0119] The output layer depends on the specific task. For classification tasks, the output vector corresponding to the [CLS] tag is usually used as the feature representation of the entire text, and then classified through a fully connected layer. For other tasks, such as question answering, named entity recognition, etc., the output of the encoding layer can be further processed according to the task requirements.
[0120] The hidden state is a vector representation that contains the encoded information of the input data. In each layer of the Transformer, the hidden state is constantly updated and optimized. It consists of multiple elements, each of which corresponds to a position in the input sequence (such as a word or a character). These elements are usually high-dimensional vectors that contain rich semantic and grammatical information.
[0121] Hidden states pass information between the layers of the Transformer, allowing the model to gradually understand and process the input data. The hidden state of each layer contains different levels of abstract representation of the input, from low-level lexical features to high-level semantic and syntactic features.
[0122] By processing and interpreting the hidden states differently, it can adapt to different natural language processing tasks. For example, in text classification tasks, the hidden states of the last layer can be used to make classification predictions; in machine translation tasks, the hidden states are used to generate output sequences in the target language.
[0123] The hidden state is constantly adjusted during the training process to optimize the model's representation of the input data. Through the back-propagation algorithm, the model updates the hidden state based on the feedback of the loss function, so that the model can better fit the training data and improve performance. Figure 6 , Figure 6 yes Figure 1 A flowchart of a specific implementation of S300; S300 includes:
[0124] S310, performing a first operation on the input sample using the first layer function of the transformer layer of the pre-trained model to obtain a first hidden state;
[0125] S320, using the selected PEFT i Modify the first hidden state to obtain the second hidden state;
[0126] S330. Perform a second operation on the second hidden state using the second layer function of the transformer layer of the pre-trained model to obtain a third hidden state.
[0127] Assume that for a PEFT i , the hidden state of the input sample before entering this transformer layer is H0, and its hidden state before entering PEFT i The operation function f that passes through the transformer before accessing the position i (First operation), obtain the first hidden state H i,0 , after PEFT i (Second operation), obtain the second hidden state H i,1 Then, the remaining operation function g of the transformer layer is passed through i (Third operation), get the third hidden state
[0128] In this embodiment, the first hidden state, the second hidden state, and the third hidden state can be represented by H0, H1, H2, and H3, respectively. i,0 , H i,1 , the principle of the whole process is as shown in formula (5).
[0129] By using the embodiment of the present application to adaptively select PEFT i , so that the pre-trained model can adaptively select the best PEFT according to the task i , unlocking the capabilities of large models to the greatest extent and improving the average performance of deployed models on various medical tasks.
[0130] The input sample is processed by the functions of each layer of Transformer and the parameter fine-tuning module, and the semantics, grammar, contextual relationships, etc. of the words, image blocks and other elements in the input text are encoded. The third hidden state obtained integrates local and global information. For example, when processing text, it considers not only the meaning of a single word, but also the structure of the entire sentence and the impact of the context on the word. It provides a powerful basic representation for various downstream tasks. In natural language processing, it can be used for tasks such as text classification, sentiment analysis, and machine translation. For image tasks, it can be used for image classification, target detection, etc. When it is applied to specific downstream tasks, a small number of specific task layers can be added on the basis of the hidden state for fine-tuning, quickly adapting to new tasks, and reducing training costs and time.
[0131] Further, such as Figure 7 , Figure 7 yes Figure 6 The flowchart after S330 in FIG. 1 ; the method further includes:
[0132] S340, obtaining hidden states corresponding to any two different parameter fine-tuning modules output after forward propagation of the pre-trained model transformer layer;
[0133] S350, using two different hidden states to obtain the loss function of the parameter efficient fine-tuning super network;
[0134] S360, using the loss function to calculate and obtain the mean square error value of any two parameter fine-tuning modules in the parameter efficient fine-tuning super network, and feeding the mean square error value back to the parameter efficient fine-tuning super network.
[0135] Each forward propagation will be due to the Bernoulli random number γ i The randomness of ,activates different parameter efficient fine-tuning modules and obtains different results.
[0136] The hidden states obtained by two different forward propagations are recorded as and In this implementation, the parameter efficient fine-tuning super network needs to ensure that at different PEFT i When used, the provided sample semantic representation should be stable enough to make different PEFT i In this embodiment, an additional regularization term is added based on the training loss:
[0137]
[0138] In formula (5), Indicates obtaining the mean square error of two hidden states.
[0139] The mean square error value is fed back to the parameter efficient fine-tuning super network, and the parameter efficient fine-tuning super network adjusts the parameters of its Transformer architecture so that any two third hidden states obtained and The distance is as small as possible. Through the constraint of this regularization term, some PEFT in the supernet i can be fully trained so that the corresponding selection factor Parameters can truly reflect their importance.
[0140] In the present application embodiment, different types of PEFT i Can be used simultaneously, so that the pre-trained model can adaptively select the best PEFT according to the task i , unlocking the capabilities of large models to the greatest extent and improving the average performance of deployed models on various medical tasks.
[0141] In order to solve the above problems, the embodiment of the present application further proposes an adaptive parameter efficient fine-tuning device 400. The adaptive parameter efficient fine-tuning device 400 corresponds one-to-one to the adaptive parameter efficient fine-tuning method in the above embodiment.
[0142] like Fig. 9 , Fig. 9 It is a structural diagram of an embodiment of an adaptive parameter efficient fine-tuning device 400 according to the present application; the parameter efficient fine-tuning device 400 includes an acquisition module 401, a screening module 402, and a modification module 403. The functions of each module are as follows: the acquisition module 401 is used to acquire a parameter efficient fine-tuning super network, and the parameter efficient fine-tuning super network includes multiple parameter fine-tuning modules; the screening module 402 is used to acquire training parameters, participate the training parameters in the parameter training of the multiple parameter fine-tuning modules, acquire the weight value of each parameter fine-tuning module, acquire the selection factor according to the weight value, and use the selection factor to screen the multiple parameter fine-tuning modules in the parameter efficient fine-tuning super network to obtain the target parameter fine-tuning module; the modification module 403 is used to use the target parameter fine-tuning module to participate in the forward propagation of the transformer layer of the pre-trained model, and modify the hidden state of the input sample output at the transformer layer.
[0143] In order to solve the above problems, an embodiment of the present application further proposes a computer device, which adopts the following technical solution: it includes a processor, a network module and a memory, and the processor and the memory are interconnected through the network module.
[0144] The computer device may be a computer, server, workstation or other device, or a mobile phone, tablet, vehicle-mounted mobile terminal or other device with program execution capability. The internal structure diagram of the computer device may be as follows: Fig.10As shown, Fig.10 It is a structural diagram of an embodiment of a computer device according to the present application. The computer device includes a processor, a memory and a network module. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile and / or volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, instructions or codes. The internal memory provides an environment for the operation of the operating system and instructions or codes in the non-volatile storage medium. When the instructions or codes are executed by the processor, the functions or steps of a method for fine-tuning the above-mentioned pre-trained model are implemented. The network module of the computer device may include a network interface and / or a wireless network module, and the computer device may communicate with other devices or service platforms through the network module. In addition, the computer device may also include a display screen and an input device, etc.
[0145] The memory is used to store a computer program, the computer program includes program instructions, the processor is configured to call the program instructions, and the processor implements the steps of the above-mentioned method for efficient fine-tuning of adaptive parameters when executing the instructions or codes.
[0146] In order to solve the above problems, the embodiment of the present application further proposes a computer-readable storage medium, which adopts the following technical solution:
[0147] The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, the processor executes an adaptive parameter efficient fine-tuning method.
[0148] The present application also provides a computer-readable storage medium storing a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, Figures 1 to 7 For the efficient fine-tuning method of adaptive parameters provided in each step, please refer to the implementation method provided in the above steps for details, which will not be repeated here.
[0149] The computer-readable storage medium may be an adaptive parameter efficient fine-tuning device 400 provided in any of the aforementioned embodiments or an internal storage unit of the terminal device, such as a hard disk or memory of a computer device. The computer-readable storage medium may also be an external storage device of the computer device, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc., equipped on the computer device.
[0150] Furthermore, the computer-readable storage medium may also include both an internal storage unit of the computer device and an external storage device. The computer-readable storage medium is used to store the computer program and other programs and data required by the computer device. The computer-readable storage medium may also be used to temporarily store data that has been output or is to be output.
[0151] However, it should be understood that it is not required to implement all the components shown, and more or fewer components may be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), digital signal processors (DSP), embedded devices, etc.
[0152] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.
[0153] Compared with the prior art, the embodiments of the present application mainly have the following technical effects: by constructing a parameter efficient fine-tuning super network, different types of parameter fine-tuning modules can be used at the same time, so that the pre-trained model can adaptively select the best parameter efficient fine-tuning module according to the task, thereby unlocking the capabilities of the large model to the greatest extent and improving the average performance of the deployed model on various medical tasks.
[0154] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. An efficient fine-tuning method for adaptive parameters, characterized by comprising: Acquire a parameter efficient fine-tuning super network, wherein the parameter efficient fine-tuning super network includes a plurality of parameter fine-tuning modules; Acquire training parameters, use the training parameters to participate in parameter training of the multiple parameter fine-tuning modules, acquire weight values of the parameter fine-tuning modules, acquire selection factors according to the weight values, and use the selection factors to screen the multiple parameter fine-tuning modules in the parameter efficient fine-tuning super network to obtain a target parameter fine-tuning module; The target parameter fine-tuning module is used to participate in the forward propagation of the tranformer layer of the pre-trained model to modify the hidden state of the input sample output at the tranformer layer.
2. The method for efficient fine-tuning of adaptive parameters according to claim 1, characterized in that: The method of obtaining parameters for efficient fine-tuning of the super network comprises: Obtain the LoRA parameter efficient fine-tuning model, adapter parameter efficient fine-tuning model, and Prefix parameter efficient fine-tuning model respectively; Obtain a first parameter fine-tuning module and a second parameter fine-tuning module from the LoRA parameter efficient fine-tuning model, obtain a third parameter fine-tuning module and a fourth parameter fine-tuning module from the adapter parameter efficient fine-tuning model, and obtain a fifth parameter fine-tuning module and a sixth parameter fine-tuning module from the Prefix parameter efficient fine-tuning model; The parameter efficient fine-tuning super network is obtained according to the first parameter fine-tuning module, the second parameter fine-tuning module, the third parameter fine-tuning module, the fourth parameter fine-tuning module, the fifth parameter fine-tuning module and the sixth parameter fine-tuning module.
3. The method for efficient fine-tuning of adaptive parameters according to claim 2, characterized in that: The step of obtaining training parameters, involving the training parameters in the parameter training of the plurality of parameter fine-tuning modules, obtaining weight values of the parameter fine-tuning modules, obtaining selection factors according to the weight values, and using the selection factors to screen the plurality of parameter fine-tuning modules in the parameter efficient fine-tuning super network to obtain a target parameter fine-tuning module includes: Input the training parameters into each parameter fine-tuning module, increase or decrease the weight value of each parameter fine-tuning module according to a preset step size, perform training learning with the goal of the training parameters being positively correlated with the weight value of the parameter fine-tuning module, and obtain the training parameters after training learning as the first selection factor, wherein one parameter fine-tuning module corresponds to one first selection factor; Determining whether the first selection factor is greater than a first preset threshold; If it is greater than the first preset threshold, the parameter fine-tuning module is retained; If it is less than the first preset threshold, the parameter fine-tuning module is deleted.
4. The method for efficient fine-tuning of adaptive parameters according to claim 2, characterized in that: The step of obtaining training parameters, involving the training parameters in the parameter training of the plurality of parameter fine-tuning modules, obtaining weight values of the parameter fine-tuning modules, obtaining selection factors according to the weight values, and using the selection factors to screen the plurality of parameter fine-tuning modules in the parameter efficient fine-tuning super network to obtain a target parameter fine-tuning module includes: Using the Bernoulli random number as a weight value to weight the training parameter, and using the weighted training parameter as a second selection factor; Determine whether the value of the second selection factor is 1; If the value of the second selection factor is 1, the parameter fine-tuning module is retained; If the value of the second selection factor is 0, the parameter fine-tuning module is deleted.
5. The method for efficient fine-tuning of adaptive parameters according to claim 4, characterized in that: The step of weighting the training parameters by using Bernoulli random numbers and using the weighted training parameters as the second selection factor comprises: Random sampling to obtain the Bernoulli random number; The training parameter is multiplied by the Bernoulli random number to obtain a second selection factor.
6. The method for efficient fine-tuning of adaptive parameters according to claim 5, characterized in that: The method of using the target parameter fine-tuning module to participate in the forward propagation of the tranformer layer of the pre-trained model to modify the hidden state of the input sample outputted at the tranformer layer includes: Use the first layer function of the pre-trained model transfer layer to perform the first operation on the input sample to obtain the first hidden state; Using the target parameter fine-tuning module to modify the first hidden state to obtain a second hidden state; A second operation is performed on the second hidden state using the second layer function of the transfer layer of the pre-trained model to obtain a third hidden state.
7. The method for efficient fine-tuning of adaptive parameters according to claim 6, characterized in that: After performing a second operation on the second hidden state using the second layer function of the pre-trained model transfer layer to obtain a third hidden state, the method further includes: Get the hidden states corresponding to any two different parameter fine-tuning modules output after forward propagation of the pre-trained model transfer layer; Utilizing two different hidden states to obtain a loss function for efficiently fine-tuning the hypernetwork of the parameters; The loss function is used to calculate the mean square error value of any two parameter fine-tuning modules in the parameter efficient fine-tuning super network, and the mean square error value is fed back to the parameter efficient fine-tuning super network.
8. An adaptive parameter efficient fine-tuning device, using the adaptive parameter efficient fine-tuning method according to any one of claims 1 to 6, characterized in that: include: An acquisition module, used for acquiring a parameter efficient fine-tuning super network, wherein the parameter efficient fine-tuning super network includes a plurality of parameter fine-tuning modules; A screening module, used to obtain training parameters, use the training parameters to participate in the parameter training of the multiple parameter fine-tuning modules, obtain weight values of each parameter fine-tuning module, and obtain a selection factor according to the weight value, and use the selection factor to screen the multiple parameter fine-tuning modules in the parameter efficient fine-tuning super network to obtain a target parameter fine-tuning module; The modification module is used to utilize the target parameter fine-tuning module to participate in the forward propagation of the transfer layer of the pre-trained model, and to modify the hidden state of the input sample output at the transfer layer.
9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the adaptive parameter efficient fine-tuning method according to any one of claims 1 to 7 when executing the computer-readable instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by a processor, the steps of the method for efficient fine-tuning of adaptive parameters according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Visual language model fine tuning method and device based on adaptive parameter selection
CN120562479A
Vision language model fine-tuning method and device based on adaptive parameter selection
CN120562479B
Text intention analysis method and device, equipment and medium
CN120806196A
Text intent analysis method, apparatus, device, and medium
CN120806196B
