Large model fine tuning method based on Hausholder transform self-adaption

By using the Householder transform adaptive method in large model fine-tuning, combined with low-rank adaptation and orthogonal fine-tuning, the problem of difficult-to-achieve balance between model capacity and regularization in existing methods is solved, reducing computational complexity and improving improve the model adaptability.

CN118734894APending Publication Date: 2024-10-01RENMIN UNIVERSITY OF CHINA

Patent Information

Application Number
CN202410858647.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-28
Publication Date
2024-10-01

AI Technical Summary

Technical Problem

Existing low-rank adaptation and orthogonal fine-tuning methods lack a combined model fine-tuning method, which makes it difficult to achieve a balance between model capacity and regularization, and has high computational complexity.

Method used

An adaptive method based on Householder transform is adopted, by constructing a learnable Householder reflection matrix multiplied by the weight matrix of the pre-trained model, and combining the advantages of low-rank adaptation and orthogonal fine-tuning to adjust the selection of λ value and learning rate to fine-tune the model.

Benefits of technology

It achieves a parameter amount that is equivalent to or even less than that of previous methods, has lower computational complexity, strikes a balance between model capacity and regularization, and improves the adaptability of the model.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118734894A_ABST
    Figure CN118734894A_ABST
Patent Text Reader

Abstract

The invention provides a large model fine tuning method based on Haushold transform self-adaption. Comprising the following four steps of: 1, giving a data set D and a pre-trained model M, and performing adaptive training on L weight matrixes of the pre-trained model M by using the data set D; a second step of using Ur (1) to represent an HRA parameter of an lth weight matrix W, and using a data set D and a model M in a training process to construct a loss function to update L weight matrixes of the M; 3, selecting a proper r to determine a parameter quantity needing to be finely tuned; and 4, adjusting the learning rate used in the training process while adjusting the value of lambda, and selecting proper hyper-parameters through multiple experiments. Finally, the parameter quantity equivalent to or even less than that of the previous method is realized, the calculation complexity is lower, and the balance between the model capacity and regularization can be achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of artificial intelligence, and more specifically, to a large model fine-tuning method based on Householder transform adaptation. Background Art

[0002] In the field of deep learning and machine learning, with the continuous development of large models, more and more researchers are inspired by the scaling law and continue to increase the model size to improve the model's ability in understanding, generation, reasoning and generalization. However, as the model size increases, the model's adaptation cost is also getting higher and higher, usually requiring a lot of computing resources and storage space, which brings great challenges to practical applications. In order to solve this problem and achieve efficient fine-tuning of large models to adapt to different downstream tasks, researchers have proposed a variety of parameter-efficient fine-tuning (PEFT) methods. These methods aim to reduce the number of parameters that need to be adjusted during the fine-tuning process, thereby reducing computing and storage costs, while maintaining or even improving the model's adaptability. Early parameter-efficient fine-tuning methods usually keep the model structure unchanged and only update a small number of model parameters. In order to achieve better results, the soft-hint fine-tuning method introduces additional trainable parameters to adjust the model's input or hidden layer. Recently, an adaptive fine-tuning method has been proposed, which can achieve the same model architecture while improving the performance of the model. The main methods are Low-Rank Adaptation (LORA) and Orthogonal Fine-Tuning (OFT).

[0003] Low-rank adaptation: This method represents the trainable parameters as decomposed low-rank matrices and linearly aggregates them into frozen weight matrices during fine-tuning, thus achieving a trade-off between efficiency and effectiveness. After LoRA, many improved low-rank adaptation methods have emerged, which can be roughly divided into three categories. The first category is structural adjustment, that is, further reducing the trainable parameters by adjusting the structure of the inserted low-rank matrix. For example, combining the frozen low-rank matrix shared between all layers with a small number of trainable scaling vectors, learning low-rank matrices with different ranks, and automatically determining the optimal rank and pruning the trainable parameters according to the importance score of the original weight matrix. The second category is initialization improvement, that is, using the matrix decomposition method on the original weight matrix to initialize the parameters, such as decomposing each original weight matrix into amplitude and direction for fine-tuning, and performing singular value decomposition on each original weight matrix, where the low-rank main matrix. The third category is parameter quantization, that is, quantizing the pre-trained model to further reduce the computational cost in training and inference. These methods have shown good performance in various downstream tasks, however, they lack theoretical guarantees about retaining pre-training knowledge.

[0004] Orthogonal fine-tuning: This method uses the same orthogonal matrix to transform the neuron vectors within the same layer. It maintains the pairwise angles between the neuron vectors, thereby ensuring that the difference between the pre-trained model and the fine-tuned model is controlled within a bounded range. For example, Cayley parameterization is adopted to generate block diagonal orthogonal matrices, and butterfly factorization is introduced to generate denser orthogonal matrices from a series of structured sparse matrices. In addition to fine-tuning, the principle of applying orthogonality constraints to trainable parameters has been applied to robust and efficient training neural network architectures such as convolutional neural networks (CNNs), recurrent neural networks (RNNs), and Transformers. In particular, by constraining the orthogonality of the weight matrices of these models, it can be theoretically ensured that the models have the 1-Lipschitz property, which enables them to have provable robustness against adversarial perturbations and generalization bounds.

[0005] However, there is currently a lack of model fine-tuning methods that combine the advantages of these two methods. Summary of the invention

[0006] The purpose of the embodiments of the present disclosure is to provide a large model fine-tuning method based on Householder transform adaptation. The two methods of low-rank adaptation and orthogonal fine-tuning propose a simple but effective adaptive method based on Householder transform.

[0007] In a general aspect, a large model fine-tuning method based on Householder transform adaptation is provided, comprising four steps:

[0008] The first step is to give a text sequence dataset D under a natural language processing task and a pre-trained model M, use the dataset D to adapt the L weight matrices of the pre-trained model M; construct a series of learnable Hausholder reflections to form an orthogonal Householder reflection matrix, and then fine-tune the model by multiplying each frozen weight matrix with the orthogonal matrix;

[0009] The second step is to use Ur(1) to represent the HRA parameters of the first weight matrix W. During the training process, the dataset D and model M are used to construct a loss function to update the L weight matrices of M:

[0010]

[0011] The third step is to select the appropriate r to determine the amount of parameters that need to be fine-tuned;

[0012] The fourth step is to adjust the value of λ and the learning rate used in the training process at the same time. After many experiments, we select the appropriate hyperparameters. For fine-tuning the LLaMa2-7B model using the MetaMathQA dataset, when λ=0, the learning rate is set to 1E-05, when λ=1e-4, the learning rate is set to 3E-05, and when λ=∞, the learning rate is set to 1E-03; for fine-tuning the Stable Diffusion model using the DreamBooth dataset, the learning rate is set to 7E-06, and when using the COCO dataset, Celeba-HQ dataset, and ADE20K dataset, the learning rate is set to 3E-05; the GLUE dataset contains multiple small datasets. For different small datasets, the learning rate settings are as follows: Fig.11 , and finally a large model for natural language processing tasks is obtained after fine-tuning.

[0013] The specific method of using Ur(1) to represent the HRA parameters of the first weight matrix W is: d-1 = {u∈R d |||u||2=1} is a d-dimensional hypersphere, for each u∈S d-1 , construct a Hausholdel reflection matrix, denoted as H, from I-2uu T Represents a reflection hyperplane, denoted as P; for any x∈R d , Hx corresponds to reflecting x onto the hyperplane P, which inverts the vector of x in the direction orthogonal to the hyperplane;

[0014] Multiply the Householder reflection matrix by the weight matrix of the pre-trained model. Since all d×d orthogonal matrices are a set, it is denoted as O d×d , satisfies all the axioms of a compact Lie group of dimension d(d-1) / 2, and enhances the adapter's capabilities by constructing a series of trainable Hausholdel reflections, thus forming the HRA method. That is, given a weight matrix and an input, the forward step of HRA is:

[0015]

[0016] Let x (0) = x and for j = 0, ..., r-1, Then, formula (1) can be realized through the following two steps:

[0017] 1)x (j+ 1 ) =x (j) -2 r-j , x (j) ) r-j , for j=0,…,r-1.2)z=Wx​(r) .

[0018] In these two steps, in the first step, u r-j and x (j) Do inner product multiplication. Since the dimensions of both variables are d, the complexity of this step is O(d). The values ​​obtained by these two inner product multiplications are the same as u r-j Perform scalar and vector multiplication. Since the value of j ranges from 0 to r-1, there are a total of r multiplication processes, so the complexity of this step is O(rd); the second step is W and x (r) Multiply, where W is a d out ×d-dimensional matrix, x (r) is a d-dimensional vector, so its complexity is O(d out d). Therefore, the complexity of HRA can be as low as O(d(r+d out )).

[0019] The value of λ in the loss function includes three cases:

[0020] The first case: when λ = 0, the optimized loss function is only the part on the left, that is, the applicable domain of Ur is the set of column-normalized matrices, and the model capacity is maximized;

[0021] The second case: When λ approaches ∞, U r The feasible domain of is a set of orthogonal matrices, which gives the strongest regularity. For each layer of the HRA adapter, its parameter matrix is ​​initialized as Gram-Schmidt orthogonalization is applied to transform a set of linearly independent vectors into a set of orthogonal vectors, namely U r =GS(V r ), the forward step for each adapter becomes The computational complexity becomes Among them, additional Operations are used for Gram-Schmidt orthogonalization;

[0022] The third case: when λ takes different non-zero real values, the larger its value, the greater the constraint of the regularization term in the entire loss function.

[0023] The innovation of the embodiment of the present invention lies in:

[0024] Compared with the existing methods, the present invention can achieve the technical effect of having a parameter amount that is equivalent to or even less than that of the previous methods, having lower computational complexity, and being able to achieve a balance between model capacity and regularization. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] The above and other objects and features of the present disclosure will become more apparent from the following description in conjunction with the accompanying drawings.

[0026] Figure 1 is a structural diagram showing a large model fine-tuning method based on Householder transform adaptation according to an embodiment of the present disclosure;

[0027] Figure 2 is a comparison diagram showing different OFT-based methods according to an embodiment of the present disclosure;

[0028] Figure 3 is a graph showing the correspondence between training parameters and accuracy after fine-tuning using different fine-tuning methods on the GLEU Benchmark according to an embodiment of the present disclosure;

[0029] Figure 4 2 is a diagram showing the comparison results on the GLEU dataset after fine-tuning using different fine-tuning methods according to an embodiment of the present disclosure;

[0030] Figure 5 is a comparison showing the accuracy of fine-tuning llama using different methods in mathematical reasoning according to an embodiment of the present disclosure;

[0031] Figure 6 is a comparison of robustness results of Householder Reflection to λ in a natural language understanding task according to an embodiment of the present disclosure;

[0032] Figure 7 is a comparison of robustness results of Householder Reflection to λ in a mathematical reasoning task according to an embodiment of the present disclosure;

[0033] Figure 8 1 is a diagram showing the comparison of results on topic-driven generation and controllable generation tasks using different large model fine-tuning methods according to an embodiment of the present disclosure;

[0034] Fig. 9 is a visualization effect showing the results of using different methods to generate results on a topic-driven task according to an embodiment of the present disclosure;

[0035] Fig.10 It is a visualization effect showing the generation results of different methods on a controllable generation task according to an embodiment of the present disclosure.

[0036] Fig.11 Graphs 2 and 3 show the learning rates set for different small datasets on the GLUE dataset according to an embodiment of the present disclosure. DETAILED DESCRIPTION

[0037] The following specific embodiments are provided to help the reader obtain a comprehensive understanding of the methods, devices and / or systems described herein. However, after understanding the disclosure of the present application, various changes, modifications and equivalents of the methods, devices and / or systems described herein will be clear. For example, the order of operations described herein is only an example and is not limited to those orders set forth herein, but can be changed as will be clear after understanding the disclosure of the present application, except for operations that must occur in a specific order. In addition, for greater clarity and simplicity, the description of features known in the art may be omitted.

[0038] The features described herein can be implemented in different forms and should not be construed as being limited to the examples described herein. Rather, the examples described herein have been provided to illustrate only some of the many possible ways to implement the methods, devices, and / or systems described herein, which will be clear after understanding the disclosure of the present application.

[0039] As used herein, the term "and / or" includes any one of the associated listed items and any combination of any two or more.

[0040] Although terms such as "first", "second", and "third" may be used herein to describe various members, components, regions, layers, or portions, these members, components, regions, layers, or portions should not be limited by these terms. Instead, these terms are only used to distinguish one member, component, region, layer, or portion from another member, component, region, layer, or portion. Therefore, without departing from the teachings of the examples described herein, the first member, first component, first region, first layer, or first portion referred to in the examples may also be referred to as the second member, second component, second region, second layer, or second portion.

[0041] In the specification, when an element (such as a layer, a region or a substrate) is described as being “on”, “connected to” or “coupled to” another element, the element may be directly “on”, “connected to” or “coupled to” another element, or one or more other elements may be present therebetween. Conversely, when an element is described as being “directly on”, “directly connected to” or “directly coupled to” another element, there may be no other elements present therebetween.

[0042] The terms used herein are only used to describe various examples and are not intended to limit the disclosure. Unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. The terms "comprise", "include" and "have" indicate the presence of the described features, quantities, operations, components, elements and / or combinations thereof, but do not exclude the presence or addition of one or more other features, quantities, operations, components, elements and / or combinations thereof.

[0043] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by a person of ordinary skill in the art to which the present disclosure belongs after understanding the present disclosure. Unless explicitly defined as such herein, terms (such as those defined in a general dictionary) should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and the present disclosure, and should not be interpreted in an idealized or overly formal manner.

[0044] Furthermore, in the description of examples, when it is considered that a detailed description of a well-known related structure or function would cause vague interpretation of the present disclosure, such a detailed description will be omitted.

[0045] Figure 1 is a schematic diagram showing a large model fine-tuning method based on Householder transform adaptation according to an embodiment of the present disclosure.

[0046] It includes the following steps:

[0047] The first step is to use a dataset and a pre-trained model M to adapt the L weight matrices of the pre-trained model using the dataset D.

[0048] Step 2: Use Ur(l) to represent the HRA parameters of the lth weight matrix. During the training process, the dataset D and model M are used to update the L weight matrices of M using the following loss function.

[0049]

[0050] The third step is to select the appropriate r to determine the amount of parameters that need to be fine-tuned.

[0051] The fourth step is to adjust the value of λ and the learning rate used in the training process. After multiple experiments, the appropriate hyperparameters are selected.

[0052] Specifically:

[0053] First, the task definition is given: given a dataset D and a pre-trained model, the dataset is used to fine-tune the L weights of the pre-trained model when necessary. The problems that need to be optimized during fine-tuning are:

[0054]

[0055] Then the task to be solved by this method is: In this invention, three different types of data sets and corresponding models are used. Among them, the General Language Understanding Evaluation (GLUE) data set corresponds to the DeBERTaV3-base model, the MeatMathQA data set corresponds to the LLaMA2-7B model, and the DreamBooth data set, COCO data set, Ce1eba-HQ data set and ADE20K data set correspond to Stabl e Diffusion model. By fine-tuning the large model with efficient methods, the fine-tuned model can perform better on the data set.

[0056] Given a dataset D and a pre-trained model M, when fine-tuning the pre-trained model using the dataset, a series of learnable Householder reflections are constructed to form a Householder reflection matrix that constitutes an orthogonal relationship, and then the model is fine-tuned by multiplying each frozen weight matrix with the orthogonal matrix. At the same time, it is proved that this method based on Householder orthogonal fine-tuning is equivalent to a low-rank adaptive fine-tuning method, thus becoming a bridge between low-rank adaptation and orthogonal adaptation. In addition, it is proved that the orthogonality of the reflection plane corresponds to the Householder reflection, which affects the capacity and regularity of the model. By changing the degree of regularization of the Householder reflection orthogonality, a variety of methods based on Householder reflection are completed.

[0057] The Householder reflection matrix is ​​an orthogonal matrix, and orthogonal adaptation can be achieved based on this matrix.

[0058] Remember S d-1 = {u∈R d |||u||2=1} is a d-dimensional hypersphere. For each u∈S d-1 , we can construct a Hausholdel reflection matrix, denoted as H, from I-2uu T It indicates that it corresponds to a reflective hyperplane, denoted as H. For any x∈R d , Hx corresponds to reflecting x onto the hyperplane H, which inverts the vector of x in the direction orthogonal to the hyperplane.

[0059] Since H is an orthogonal matrix, it is natural to implement orthogonal adaptation based on it. Consider H as an adaptor and then multiply it with the weight matrix of the pre-trained model. In addition, since all d×d orthogonal matrices are set, denoted as O d×d, satisfies all the axioms of a compact Lie group of dimension d(d-1) / 2, and the product of orthogonal matrices is also an orthogonal matrix. Therefore, the ability of the adapter can be enhanced by constructing a series of trainable Householder reflections. Thus, the HRA method is formed, that is, given a weight matrix and an input, the forward step of HRA is:

[0060]

[0061] We can further use the Householder reflection structure to simplify the calculation. Let x (0) = x and For j=0, ..., r-1, we implement formula (1) through the following two steps:

[0062] 1)x (j+1) =x (j) -2 r-j , x (j) ) r-j , for j=0,…,r-1.2)z=Wx (r) . (2)

[0063] In these two steps, in the first step, u r-j and x (j) Do inner product multiplication. Since the dimensions of both variables are d, the complexity of this step is O(d). The values ​​obtained by these two inner product multiplications are the same as u r-j Perform scalar and vector multiplication. Since the value of j ranges from 0 to r-1, there are a total of r multiplication processes, so the complexity of this step is O(rd); the second step is W and x (r) Multiply, where W is a d out ×d-dimensional matrix, x (r) is a d-dimensional vector, so its complexity is O(d out d). Therefore, the complexity of HRA can be as low as O(d(r+d out )).

[0064] In addition to being an orthogonal fine-tuning method, HRA can also be viewed as an adaptive low-rank adapter. In particular, the Householder transform chain in formula (1) can be rewritten as the following equivalent form:

[0065]

[0066] The U in here r , T r is an upper triangular matrix whose upper triangular elements are:

[0067] ​

[0068] Correspondingly, we can get:

[0069]

[0070] The above formula can be regarded as an adaptive LoRA (Low-Rank Adaptation), which inherits the theoretical guarantee of OFT in retaining pre-training knowledge. r is constructed from normalized vectors, and the low-rank matrix A = [a1, ..., a r ] is parameterized as WU r Γ r It can be viewed as a function of W and B. Thus, similar to OFT and BOFT, HRA ensures that the columns of are always in the column space WH of W. (r) middle.

[0071] In addition to the number of Householder reflections, their orthogonality also affects the regularity of HRA. Specifically, the highest variation of the weight matrix W sup H(r) ||W-WH (r) || F , that is, assuming (or, equivalently, ) is realized when Ur is formed by the first r right singular vectors of W. In this case, Ur is an orthogonal matrix, i.e. When orthogonality does not exist, In other words, enforcing the orthogonality of Ur brings stronger regularization to the adapter when adapting a pre-trained model — it encourages larger differences between the target model and the original pre-trained model while restricting the feasible domain of the adapter parameter matrix.

[0072] The orthogonality of the Householder reflection also affects the regularity of the Householder variation-based adaptive fine-tuning large model. Therefore, when implementing the Householder adaptive method, an orthogonal regularization term is added. Therefore, the problem that needs to be optimized in the fine-tuning process is:

[0073]

[0074] in It represents the Householder parameter of the weight matrix of layer 1. Different effects can be achieved by adjusting different parameters λ.

[0075] For the problem that needs to be optimized in the end, when λ tends to ∞, a strictly orthogonal large model fine-tuning method based on Householder reflection adaptation is implemented based on Gram-Schmidt orthogonalization.

[0076] Here It represents the HRA parameter of the first weight matrix. The first part of this optimization function is the loss function, and the second part is the one proposed by this invention to encourage all Orthogonality regularizer. This regularization term is controlled by the parameter λ. Since this term does not change the forward propagation process of HRA, this regularization term only slightly increases the cost of adaptation. By controlling the strength of the orthogonalization regularization term, a balance between model capacity and regularization can be achieved. The following will explain the corresponding situations when different values ​​of λ, that is, different influence strengths of the regularization term, are taken.

[0077] The first case: When λ = 0, the optimized loss function is only the left part, that is, the applicable domain of Ur is the collection of column-normalized matrices. In this case, the model capacity is maximized.

[0078] The second case: When λ approaches ∞, U r The feasible domain of is the set of orthogonal matrices (i.e. ), the strongest regularization is obtained. However, in the experiment, it is impossible to set it to ∞, so when λ = ∞, this invention implements a strictly orthogonal HRA based on Gram-Schmidt (GS) orthogonalization. For each layer of HRA adapter, its parameter matrix is ​​initialized as Gram-Schmidt orthogonalization is applied to transform a set of linearly independent vectors into a set of orthogonal vectors, namely U r =GS(V r )like Figure 1 As shown, in this case, the forward step for each adapter becomes The computational complexity becomes Among them, additional The operation is used for Gram-Schmidt orthogonalization. According to Table 1, when r=b, the complexity of this strictly orthogonal HRA is comparable to OFT.

[0079] The third case: When λ takes different real values, it will have different performances according to different tasks. Figure 6 and Figure 7 The robustness of different λ values ​​in natural language understanding and mathematical reasoning is shown in Figure 2.

[0080] The technical effects to be achieved by the present invention are:

[0081] The model size is comparable to that of previous methods when the parameters are the same: compared with the previous orthogonal fine-tuning method, it can achieve the same or even less parameters than the previous method. Both OFT and BOFT construct several orthogonal submatrices O based on Cayley transform. b×b , each submatrix requires b(b-1) / 2 or b2 / 2 trainable parameters, and the computational complexity is O(b3 ). OFT constructs a block diagonal matrix based on d / b sub-matrices, that is BOFT constructs m sparse orthogonal matrices by scattering the elements of d / m orthogonal submatrices when When r=b(=mb), the product of m sparse matrices results in a dense orthogonal matrix. Therefore, according to the number of orthogonal sub-matrices, in theory the number of parameters of OFT and BOFT are d(b-1) / 2 and dm(b-1) / 2, respectively, but in practice they are db and dmb, respectively. In order to make the number of parameters comparable to OFT, BOFT usually uses a smaller block size (for example, b=2 or 4). It is easy to find that when r=b(=mb), the number of parameters of HRA is the same as that of OFT (or BOFT). Therefore, the model size of HRA is generally comparable to that of OFT and BOFT.

[0082] Low computational complexity: For the forward step of OFT, z = WR (b) x, the computational complexity is in, Corresponding to applying Cayley transform to construct d / b orthogonal submatrices, O(db) and Corresponding to y=R (b) Matrix block multiplication of x and matrix-vector multiplication for z = Wy. For the forward step of BOFT, i.e. z = WB (m,b) x, where The computational complexity is Similar to OFT, This means applying the Cayley transform to construct dm / b orthogonal sub-matrices. The matrix-vector multiplication corresponding to m butterfly matrices is used to compute Corresponding to z = Wy. When r<<b 2 +b(<<m(b 2 +b), HRA can be more efficient than OFT (or BOFT).

[0083] Balance between model capacity and regularization: The ranges of OFT, BOFT, and HRA correspond to Different subsets of achieve a trade-off between model capacity and regularization. OFT needs to set b = d and calculate a dense orthogonal matrix with high complexity. With the help of the butterfly structure, BOFT can derive a dense orthogonal matrix with fewer parameters. However, we need to construct m = log d and b = 2 Make each can represent a Householder reflection matrix, and accordingly, the chain product of d-1 Householder reflections can be expressed as Similarly, for HRA, we need to base Construct d-1 Householder reflections to represent According to the above analysis, BOFT and HRA are relatively easy to achieve the trade-off between model capacity and regularity, and the computational cost is low - by setting small m, b and r, they can obtain dense orthogonal matrices with intrinsic low-dimensional manifold structure.

[0084] Remember S d-1 = {u∈R d |||u||2=1} is a d-dimensional hypersphere. For each u∈S d-1 , we can construct a Householder reflection matrix, denoted as H, from I-2uu T It indicates that it corresponds to a reflective hyperplane, denoted as H. For any x∈R d , Hx corresponds to reflecting x onto the hyperplane H, which inverts the vector of x in the direction orthogonal to the hyperplane.

[0085] Since H is an orthogonal matrix, it is natural to implement orthogonal adaptation based on it. Consider H as an adaptor and then multiply it with the weight matrix of the pre-trained model. In addition, since all d×d orthogonal matrices are set, denoted as O d×d , satisfies all the axioms of a compact Lie group of dimension d(d-1) / 2, and the product of orthogonal matrices is also an orthogonal matrix. Therefore, the ability of the adapter can be enhanced by constructing a series of trainable Householder reflections. Thus, the HRA method is formed, that is, given a weight matrix and an input, the forward step of HRA is:

[0086]

[0087] Although formula (1) involves the chain product of r+1 dense matrices, we can use the structure of Householder reflection to simplify the calculation. Let x (0) = x and For j=0, ..., r-1, we implement formula (1) through the following two steps:

[0088] 1)x (j+1) =x (j) -2 r-j , x (j) >u r-j , for j=0,…,r-1.2)z=Wx (r) ​. (2)

[0089] The first step involves r vector inner products and r scalar-vector multiplications, with a complexity of O(rd). The second step involves a matrix-vector multiplication, with a complexity of O(d out d). Therefore, the complexity of HRA can be as low as O(d(r+d out )).

[0090] In addition to being an orthogonal fine-tuning method, HRA can also be viewed as an adaptive low-rank adapter. In particular, the formula can be rewritten to form an equivalent form of HRs:

[0091]

[0092] The U in here r , T r is an upper triangular matrix whose upper triangular elements are:

[0093]

[0094] Correspondingly, we can get:

[0095]

[0096] The above formula can be regarded as an adaptive LoRA (Low-Rank Adaptation), which inherits the theoretical guarantee of OFT in retaining pre-training knowledge. r is constructed from normalized vectors, and the low-rank matrix A = [a1, ..., a r ] is parameterized as WU r Γ r It can be viewed as a function of W and B. Thus, similar to OFT and BOFT, HRA ensures that the columns of are always in the column space WH of W. (r) middle.

[0097] In addition to the number of Householder reflections, their orthogonality also affects the regularity of HRA. Specifically, the highest variation of the weight matrix W , that is, assuming (or, equivalently, ) is realized when Ur is formed by the first r right singular vectors of W. In this case, Ur is an orthogonal matrix, i.e. When orthogonality does not exist, In other words, enforcing the orthogonality of Ur brings stronger regularization to the adapter when adapting a pre-trained model — it encourages larger differences between the target model and the original pre-trained model while restricting the feasible domain of the adapter parameter matrix.

[0098] Experimental verification

[0099] Figure 3 This is a graph showing the training parameters and accuracy obtained on GLEUBenchmark after fine-tuning the large model using different fine-tuning methods. The horizontal axis is the amount of training parameters, and the vertical axis is the average value on GLUE.

[0100] Figure 4 The following are the comparison results of fine-tuning on the GLEU dataset using different fine-tuning methods. The best result is shown in bold and the second best result is underlined. w Correlation coefficients and the average correlation coefficients of STS-B.

[0101] Although some embodiments of the present disclosure have been shown and described, it will be appreciated by those skilled in the art that modifications may be made to the embodiments without departing from the principles and spirit of the present disclosure, the scope of which is defined by the claims and their equivalents.

Claims

1. A large model fine-tuning method based on Householder transform adaptation, characterized in that: There are four steps involved: The first step is to give a text sequence dataset D under a natural language processing task and a pre-trained model M, and use the dataset D to perform adaptive training on the L weight matrices of the pre-trained model M; A series of learnable Hausholder reflections are constructed to form an orthogonal Householder reflection matrix, and then the model is fine-tuned by multiplying each frozen weight matrix with the orthogonal matrix; The second step is to use Ur(l) to represent the HRA parameters of the lth weight matrix W. During the training process, the dataset D and model M are used to construct a loss function to update the L weight matrices of M: The third step is to select the appropriate r to determine the amount of parameters that need to be fine-tuned; The fourth step is to adjust the value of λ and the learning rate used in the training process at the same time. After many experiments, the appropriate hyperparameters are selected. For fine-tuning the LLaMa2-7B model using the MetaMathQA dataset, when λ=0, the learning rate is set to 1E-05, when λ=1e-4, the learning rate is set to 3E-05, and when λ=∞, the learning rate is set to 1E-03; for fine-tuning the Stable Diffusion model using the DreamBooth dataset, the learning rate is set to 7E-06, and when using the COCO dataset, Celeba-HQ dataset, and ADE20K dataset, the learning rate is set to 3E-05; the GLUE dataset contains multiple small datasets. For different small datasets, the learning rate settings are shown in Figure 11, and finally a large model for natural language processing tasks is obtained after fine-tuning.

2. A large model fine-tuning method based on Householder transform adaptation as claimed in claim 1, characterized in that: The specific method of using Ur(l) to represent the HRA parameters of the lth weight matrix W is: d-1 = {u∈R d |||u||2=1} is a d-dimensional hypersphere. For each u∈S d-1 , construct a Hausholdel reflection matrix, denoted as H, from I-2uu T Represents a reflection hyperplane, denoted as P; for any x∈R d , Hx corresponds to reflecting x onto the hyperplane P, which inverts the vector of x in the direction orthogonal to the hyperplane; Multiply the Householder reflection matrix by the weight matrix of the pre-trained model. Since all d×d orthogonal matrices are a set, it is denoted as O d×d , satisfies all the axioms of a compact Lie group of dimension d(d-1) / 2, and enhances the adapter's capabilities by constructing a series of trainable Hausholdel reflections, thus forming the HRA method, that is, given a weight matrix and an input The forward steps of HRA are: Let x (0) = x and for j = 0, ..., r-1, The above formula can then be implemented through the following two steps: Step 1: x (j+1 )=x (j) -2 r-j , x (j) >u r-j , for j=0,...,r-1;​ Step 2: z = Wx (r) ; In the first step, for variables u with two dimensions d r-j and x (j) Do inner product multiplication, the complexity is O(d), the value obtained by inner product multiplication is the same as u r-j Multiply a scalar and a vector with a complexity of O(rd); in the second step, W is d out ×d-dimensional matrix, x (r) is a d-dimensional vector with a complexity of O(d out d), making the complexity of HRA as low as O(d(r+d out )).

3. A large model fine-tuning method based on Householder transform adaptation as claimed in claim 2, characterized in that: The value of λ in the loss function includes three cases: The first case: when λ = 0, the optimized loss function is only the part on the left, that is, the applicable domain of Ur is the set of column-normalized matrices, and the model capacity is maximized; The second case: When λ approaches ∞, U r The feasible domain of is a set of orthogonal matrices, which gives the strongest regularity. For each layer of the HRA adapter, its parameter matrix is ​​initialized as Gram-Schmidt orthogonalization is applied to transform a set of linearly independent vectors into a set of orthogonal vectors, namely U r =GS(V r ), the forward step for each adapter becomes The computational complexity becomes Among them, additional Operations are used for Gram-Schmidt orthogonalization; The third case: when λ takes different non-zero real values, the larger its value, the greater the constraint of the regularization term in the entire loss function.

Citation Information

Patent Citations

  • Speech recognition fine tuning task acceleration method based on low-rank matrix approximation

    CN117059103A

  • Large model fine tuning method and device based on learning weight vector, equipment and medium

    CN117725844A

  • Prediction method for stall and surging of axial-flow compressor based on deep autoregressive network

    US20240133391A1

Cited By

  • Parameter fine tuning method and device of pre-training model, equipment and medium

    CN119849576A

  • Small sample fine tuning method for preventing disastrous forgetting based on regularization constraint

    CN120764613A

  • Model confusion-based end-cloud collaborative security reasoning method and system

    CN122572699A