Large language model training method, device, electronic device and storage medium

The method automates the optimization of matrix rank in large language model training through low-rank decomposition and adaptive adjustment, improving efficiency and accuracy by reducing manual steps and enhancing computational performance.

CN118520975BActive Publication Date: 2024-12-03ATHENAEYES CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410978468.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-07-22
Publication Date
2024-12-03
Estimated Expiration
2044-07-22

AI Technical Summary

Technical Problem

The challenge of setting and utilizing an optimized matrix rank in large language model training is complex, particularly for users unfamiliar with these models, leading to inefficiencies in computing resources and model optimization.

Method used

A method involving low-rank decomposition of the weight matrix, followed by singular value decomposition and adaptive adjustment of matrix rank using adaptation coefficients, along with differential learning rates for parameter updates, to optimize the matrix rank automatically during training.

Benefits of technology

This approach simplifies the setting process of matrix rank and enhances training efficiency by automatically adjusting the matrix rank, reducing manual intervention and improving the utilization of optimized values, thereby enhancing the performance and accuracy of large language models.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118520975B_ABST
    Figure CN118520975B_ABST
Patent Text Reader

Abstract

The present application discloses a large language model training method, device, electronic device and storage medium, the method comprising: comparing the second sum with the first sum to obtain a first ratio, when the first ratio is greater than the second ratio, comparing the third ratio with the preset minimum ratio and maximum ratio to obtain a comparison result corresponding to the matrix rank; obtaining an adaptation coefficient corresponding to the comparison result, multiplying the preset value by the adaptation coefficient, and generating an optimized value of the matrix rank; according to the optimized value, decomposing the weight matrix into a low-rank matrix D and a low-rank matrix E; updating the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and updating the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate, until the trained large language model is saved, in which the ranks of the low-rank matrices D and E of different network layers will adaptively increase or decrease, rather than using fixed and identical values. The present application is conducive to improving the training efficiency of the large language model.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of Internet technology, and in particular to a large language model training method, device, electronic device and storage medium. Background Art

[0002] In the field of natural language processing, large language models such as GPT-3 are widely used in various tasks such as text classification, question-answering systems, and machine translation due to their powerful language understanding and generation capabilities.

[0003] In the fine-tuning process of large language models, the mainstream LoRA method has low computing resource requirements, but it needs to set the matrix rank, and the value of the matrix rank needs to consider various information of the large language model. For users who are not familiar with large language models, it takes a lot of time and energy, and using the same rank at different layers of the network also limits the optimization of the model. Therefore, how to set the optimized value of the matrix rank and how to use the optimized value of the matrix rank are problems that need to be solved urgently. Summary of the invention

[0004] The embodiments of the present application provide a large language model training method, device, electronic device and storage medium to solve the above-mentioned technical problem of how to set the optimized value of the matrix rank and how to use the optimized value of the matrix rank, which is not conducive to improving the training efficiency of the large language model.

[0005] In a first aspect, an embodiment of the present application provides a large language model training method, which is applied to an electronic device, wherein the electronic device stores a pre-trained large language model, and the large language model training method includes:

[0006] Obtain a weight matrix of the large language model, obtain a preset value of a matrix rank of the weight matrix during low-rank decomposition, and decompose the weight matrix into a low-rank matrix A and a low-rank matrix B according to the preset value;

[0007] Multiplying the low-rank matrix A and the low-rank matrix B to obtain a matrix C, performing singular value decomposition on the matrix C to obtain two orthogonal matrices and a diagonal matrix, adding Q singular values ​​of the diagonal matrix to obtain a first sum, and adding the first K singular values ​​of the diagonal matrix to obtain a second sum;

[0008] The second sum is compared with the first sum to obtain a first ratio, and when the first ratio is greater than a preset second ratio, K is compared with Q to obtain a third ratio, and the third ratio is compared with a preset minimum ratio and a maximum ratio to obtain a comparison result corresponding to the matrix rank;

[0009] In each round of training of the large language model, obtaining an adaptation coefficient corresponding to the comparison result, multiplying the preset value by the adaptation coefficient, and generating an optimized value of the matrix rank;

[0010] Decomposing the weight matrix into a low-rank matrix D and a low-rank matrix E according to the optimized value;

[0011] Obtain a first gradient value of a first parameter of the low-rank matrix D, and obtain a second gradient value of a second parameter of the low-rank matrix E;

[0012] The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate until the trained large language model is saved.

[0013] The first learning rate and the second learning rate are different learning rates.

[0014] Wherein, Q is the total number of the singular values, and K is the preset number of the singular values.

[0015] In a possible implementation manner of the first aspect, obtaining a weight matrix of the large language model, obtaining a preset value of a matrix rank of the weight matrix during low-rank decomposition, and decomposing the weight matrix into a low-rank matrix A and a low-rank matrix B according to the preset value, including:

[0016] Display a network layer list of the large language model, wherein the network layer list includes multiple network layers of the large language model;

[0017] Obtain a specified operation of the network layer list, and obtain the specified network layer according to the specified operation;

[0018] Obtain the weight matrix of the specified network layer, obtain the preset value of the matrix rank set when the weight matrix is ​​decomposed into the low rank matrix A and the low rank matrix B according to the preset value.

[0019] In a possible implementation manner of the first aspect, the adaptation coefficient includes a reduction coefficient and an amplification coefficient;

[0020] In each round of training of the large language model, obtaining an adaptation coefficient corresponding to the comparison result, multiplying the preset value by the adaptation coefficient, and generating an optimized value of the matrix rank, comprises:

[0021] When the comparison result is that the third ratio is less than or equal to the minimum ratio, in each round of training of the large language model, the reduction coefficient corresponding to the comparison result is obtained, the preset value is multiplied by the reduction coefficient, and the optimized value of the matrix rank is generated, the minimum ratio includes one of 1 / 5 and 1 / 6 or a combination thereof, and the reduction coefficient includes one of 0.5 and 0.6 or a combination thereof;

[0022] When the comparison result is that the third ratio is greater than or equal to the maximum ratio, in each round of training of the large language model, the amplification factor corresponding to the comparison result is obtained, the preset value is multiplied by the amplification factor, and the optimized value of the matrix rank is generated, the maximum ratio includes one of 1 / 2, 2 / 3 or a combination thereof, and the amplification factor includes one of 2 times, 3 times or a combination thereof.

[0023] In a possible implementation manner of the first aspect, obtaining a first gradient value of a first parameter of the low-rank matrix D and obtaining a second gradient value of a second parameter of the low-rank matrix E include:

[0024] Obtaining a loss function of the large language model;

[0025] The first parameter of the low-rank matrix D is differentiated by the loss function to obtain the first gradient value of the first parameter, and the second parameter of the low-rank matrix E is differentiated by the loss function to obtain the second gradient value of the second parameter.

[0026] In a possible implementation manner of the first aspect, updating the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and updating the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate until the trained large language model is saved, includes:

[0027] The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate. The training of the large language model is stopped until the minimum loss value of the loss function of the large language model is less than the preset loss value, and the trained large language model is saved.

[0028] In a possible implementation manner of the first aspect, updating the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and updating the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate until the trained large language model is saved, includes:

[0029] The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate. The training of the large language model is stopped until the number of training rounds of the large language model reaches a preset number of rounds, and the trained large language model is saved.

[0030] In a possible implementation manner of the first aspect, the optimization value ranges from 1 to 256.

[0031] In a second aspect, an embodiment of the present application provides a large language model training device, which is applied to an electronic device, wherein the electronic device stores a pre-trained large language model, including:

[0032] A first acquisition module is used to acquire a weight matrix of the large language model, acquire a preset value of a matrix rank of the weight matrix during low-rank decomposition, and decompose the weight matrix into a low-rank matrix A and a low-rank matrix B according to the preset value;

[0033] An adding module, used for multiplying the low-rank matrix A and the low-rank matrix B to obtain a matrix C, performing singular value decomposition on the matrix C to obtain two orthogonal matrices and a diagonal matrix, adding Q singular values ​​of the diagonal matrix to obtain a first sum, and adding the first K singular values ​​of the diagonal matrix to obtain a second sum;

[0034] A comparison module, configured to compare the second sum with the first sum to obtain a first ratio, and when the first ratio is greater than a preset second ratio, compare K with Q to obtain a third ratio, and compare the third ratio with a preset minimum ratio and a maximum ratio to obtain a comparison result corresponding to the matrix rank;

[0035] A generating module, configured to obtain an adaptation coefficient corresponding to the comparison result in each round of training of the large language model, and to multiply the preset value by the adaptation coefficient to generate an optimized value of the matrix rank;

[0036] A decomposition module, used for decomposing the weight matrix into a low-rank matrix D and a low-rank matrix E according to the optimization value;

[0037] A second acquisition module is used to obtain a first gradient value of a first parameter of the low-rank matrix D, and to obtain a second gradient value of a second parameter of the low-rank matrix E;

[0038] An updating module is used to update the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and to update the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate until the trained large language model is saved.

[0039] In a third aspect, an embodiment of the present application provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the large language model training method in the first aspect when executing the computer program.

[0040] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the large language model training method in the above-mentioned first aspect is implemented.

[0041] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes the large language model training method described in the first aspect above.

[0042] The beneficial effects of the embodiments of the present application lie in two aspects. On the one hand, in each round of training of the large language model, the adaptation coefficient corresponding to the comparison result is obtained, and the preset value is multiplied by the adaptation coefficient to generate the optimized value of the matrix rank. Therefore, the electronic device can generate the optimized value of the matrix rank, reducing the steps of manually adjusting the matrix rank, thereby simplifying the setting process of the optimized value of the matrix rank, which is beneficial to improving the setting efficiency of the optimized value of the matrix rank; on the other hand, according to the optimized value, the weight matrix is ​​decomposed into a low-rank matrix D and a low-rank matrix E, and the first gradient value of the first parameter of the low-rank matrix D is obtained, and the second gradient value of the second parameter of the low-rank matrix E is obtained. The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate. This solves the problem of how to use the optimized value of the matrix rank, which is beneficial to improving the efficiency of using the optimized value. BRIEF DESCRIPTION OF THE DRAWINGS

[0043] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.

[0044] Figure 1 An application scenario diagram of the large language model training method provided in an embodiment of the present application;

[0045] Figure 2 It is a flowchart of a large language model training method provided in an embodiment of the present application;

[0046] Figure 3 A flowchart of obtaining a weight matrix provided in an embodiment of the present application;

[0047] Figure 4 A schematic block diagram of a large language model training device provided in an embodiment of the present application;

[0048] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0049] In order to make the purpose, technical solutions and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present application.

[0050] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0051] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0052] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0053] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0054] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.

[0055] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0056] In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the fact that they can be implemented by ordinary technicians in this field. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.

[0057] The flowcharts shown in the accompanying drawings are only examples and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps may also be decomposed, combined or partially merged, so the actual execution order may change according to actual conditions.

[0058] The large language model training method provided in the embodiments of the present application can be applied to electronic devices such as servers, mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), etc. The embodiments of the present application do not impose any restrictions on the specific types of electronic devices.

[0059] See also Figure 1 , Figure 1 The application scenario diagram of the large language model training method provided in the embodiment of the present application is described in detail as follows:

[0060] The electronic device obtains the weight matrix of the large language model, obtains a preset value of the matrix rank of the weight matrix during low-rank decomposition, and decomposes the weight matrix into a low-rank matrix A and a low-rank matrix B according to the preset value.

[0061] The weight matrix of a large language model (LLM) may come from one file of the large language model or from multiple files of the large language model.

[0062] For ease of explanation, the weight matrix comes from two files as an example, as detailed below:

[0063] The two files include a first file and a second file. The electronic device reads the first file and the second file respectively, and obtains the weight matrix of the large language model from the first file and the second file.

[0064] In an embodiment of the present application, the electronic device can read the first file and the second file at the same time, and obtain the weight matrix of the large language model from the first file and the second file.

[0065] See also Figure 2 , Figure 2 It is a flow chart of a large language model training method provided in an embodiment of the present application, which can be applied to electronic devices.

[0066] like Figure 2 As shown, the large language model training method provided in the embodiment of the present application includes the following steps, which are described in detail as follows:

[0067] S201, obtaining a weight matrix of the large language model, obtaining a preset value of a matrix rank of the weight matrix during low-rank decomposition, and decomposing the weight matrix into a low-rank matrix A and a low-rank matrix B according to the preset value;

[0068] When the weight matrix is ​​subjected to low-rank decomposition, a matrix rank is predetermined or set, and the value of the matrix rank will determine the complexity of the matrix obtained after the decomposition.

[0069] The matrix rank is the rank of the matrix, which is also called the rank value. The matrix rank refers to the maximum number of linearly independent row or column vectors in the matrix.

[0070] S202, multiplying the low-rank matrix A and the low-rank matrix B to obtain a matrix C, performing singular value decomposition on the matrix C to obtain two orthogonal matrices and a diagonal matrix, adding Q singular values ​​of the diagonal matrix to obtain a first sum, and adding the first K singular values ​​of the diagonal matrix to obtain a second sum;

[0071] Wherein, Q is the total number of the singular values, and K is the preset number of the singular values.

[0072] S203, comparing the second sum with the first sum to obtain a first ratio, and when the first ratio is greater than a preset second ratio, comparing K with Q to obtain a third ratio, and comparing the third ratio with a preset minimum ratio and a maximum ratio to obtain a comparison result corresponding to the matrix rank;

[0073] The second ratio is set by the user or by the system by default, and is not limited here.

[0074] For the sake of illustration, an example is given below:

[0075] The K singular values ​​of the diagonal matrix are A1, A2, ..., AK respectively;

[0076] The first sum is S, the second sum is: sum(A1, A2, ..., AK); the second ratio is 0.9;

[0077] When sum(A1, A2, ..., AK)>0.9×S, K is compared with Q to obtain a third ratio.

[0078] The sum function is used to calculate the sum of A1, A2, …, AK.

[0079] Among them, when the first ratio is greater than the preset second ratio, it means that most of the information of the diagonal matrix is ​​concentrated on the first K singular values, and the singular values ​​other than the first K singular values ​​are low-frequency information. Therefore, the lower the third ratio of K to Q, the lower the proportion of high-frequency information, indicating that the proportion of low-frequency information is higher and the redundancy is higher. The higher the third ratio of K to Q, the higher the proportion of high-frequency information, indicating that the proportion of low-frequency information is lower and the redundancy is lower.

[0080] S204, in each round of training of the large language model, obtaining an adaptation coefficient corresponding to the comparison result, multiplying the preset value by the adaptation coefficient, and generating an optimized value of the matrix rank;

[0081] Wherein, the adaptation coefficient includes a reduction coefficient and an enlargement coefficient;

[0082] In each round of training of the large language model, obtaining an adaptation coefficient corresponding to the comparison result, multiplying the preset value by the adaptation coefficient, and generating an optimized value of the matrix rank, comprises:

[0083] When the comparison result is that the third ratio is less than or equal to the minimum ratio, in each round of training of the large language model, the reduction coefficient corresponding to the comparison result is obtained, the preset value is multiplied by the reduction coefficient, and the optimized value of the matrix rank is generated, the minimum ratio includes one of 1 / 5 and 1 / 6 or a combination thereof, and the reduction coefficient includes one of 0.5 and 0.6 or a combination thereof;

[0084] For the sake of illustration, an example is given below:

[0085] For example, the minimum ratio is 1 / 5. , indicating that the low-frequency information of the weight matrix of this network layer accounts for a high proportion and the redundancy is high. Therefore, the ranks of the low-rank matrices A and B of this network layer are halved, and the new rank = old rank × 0.5.

[0086] For example, the minimum ratio is 1 / 5. , indicating that the low-frequency information of the weight matrix of this network layer accounts for a high proportion and the redundancy is high. Therefore, the ranks of the low-rank matrix A and the low-rank matrix B of this network layer are lowered, and the new rank = old rank × 0.6.

[0087] For example, the minimum ratio is 1 / 6. , indicating that the low-frequency information of the weight matrix of this network layer accounts for a high proportion and the redundancy is high. Therefore, the ranks of the low-rank matrices A and B of this network layer are halved, and the new rank = old rank × 0.5.

[0088] For example, the minimum ratio is 1 / 6. , indicating that the low-frequency information of the weight matrix of this network layer accounts for a high proportion and the redundancy is high. Therefore, the ranks of the low-rank matrix A and the low-rank matrix B of this network layer are lowered, and the new rank = old rank × 0.6.

[0089] Among them, the new rank represents the optimized value of the matrix rank, and the old rank represents the preset value of the matrix rank.

[0090] Among them, the preset value is multiplied by the reduction coefficient to generate the optimized value of the matrix rank. The optimized value at this time is less than the preset value, which means that the matrix rank becomes smaller, which means that a lower-dimensional low-rank matrix is ​​used to represent the weight matrix, which can significantly reduce the number of parameters in the large language model.

[0091] For the sake of illustration, an example is given below:

[0092] For example, the dimension of the weight matrix is ​​1024×512, and the weight matrix contains 1024×512 = 524288 parameters. Select a low-rank matrix with a matrix rank of 16 to approximate the weight matrix, and decompose the weight matrix into a low-rank matrix D and a low-rank matrix E. The dimension of the low-rank matrix D is 1024×16, and the dimension of the low-rank matrix E is 16×512; the number of parameters of these two matrices is 1024×16 = 16384 and 16 ×512 = 8192, respectively, for a total of 16384 + 8192 = 24576 parameters, reducing the number of parameters from 524288 to 24576, which is about 95% of the parameters.

[0093] Among them, the parameters of the large language model are reduced, and the training speed of the large language model will be correspondingly improved. Therefore, in each iteration, fewer parameters need to be updated, thereby speeding up the gradient descent or other optimization algorithms. In addition, the smaller matrix rank means that the large language model occupies less memory space, which is conducive to the deployment of large language models on resource-constrained devices.

[0094] When the comparison result is that the third ratio is greater than the minimum ratio and less than the maximum ratio, taking the preset value as the optimized value;

[0095] For the sake of illustration, an example is given below:

[0096] For example, the minimum ratio is 1 / 5 and the maximum ratio is 1 / 2. When , the ranks of the low-rank matrix A and low-rank matrix B of this network layer remain unchanged, and the new rank = the old rank. The new rank represents the optimized value of the matrix rank, and the old rank represents the preset value of the matrix rank.

[0097] When the comparison result is that the third ratio is greater than or equal to the maximum ratio, in each round of training of the large language model, the amplification factor corresponding to the comparison result is obtained, the preset value is multiplied by the amplification factor, and the optimized value of the matrix rank is generated, the maximum ratio includes one of 1 / 2, 2 / 3 or a combination thereof, and the amplification factor includes one of 2 times, 3 times or a combination thereof.

[0098] For the sake of illustration, an example is given below:

[0099] For example, the maximum ratio is 1 / 2. , indicating that the low-frequency information of the weight matrix of this network layer accounts for a low proportion and the redundancy is low. Therefore, the ranks of the low-rank matrices A and B of this network layer are doubled, and the upper limit is set to 256, and the new rank = old rank × 2.

[0100] For example, the maximum ratio is 1 / 2. , indicating that the low-frequency information of the weight matrix of this network layer accounts for a low proportion and the redundancy is low. Therefore, the rank of the low-rank matrix A and the low-rank matrix B of this network layer is increased, and the upper limit is set to 256, and the new rank = old rank × 3.

[0101] For example, the maximum ratio is 2 / 3. , indicating that the low-frequency information of the weight matrix of this network layer accounts for a low proportion and the redundancy is low. Therefore, the ranks of the low-rank matrices A and B of this network layer are doubled, and the upper limit is set to 256, and the new rank = old rank × 2.

[0102] For example, the maximum ratio is 2 / 3. , indicating that the low-frequency information of the weight matrix of this network layer accounts for a low proportion and the redundancy is low. Therefore, the rank of the low-rank matrix A and the low-rank matrix B of this network layer is increased, and the upper limit is set to 256, and the new rank = old rank × 3.

[0103] The new rank indicates the optimized value of the matrix rank, and the old rank indicates the preset value of the matrix rank. The upper limit is 256, and the maximum value of the new rank cannot exceed 256.

[0104] Among them, the preset value is multiplied by the amplification factor to generate the optimized value of the matrix rank. At this time, the optimized value is greater than the preset value, which means that the matrix rank becomes larger. The increase in matrix rank can increase the expressive power of the large language model, enabling the large language model to capture more complex features and relationships, which is beneficial in certain tasks that require high precision or complex pattern recognition.

[0105] In each round of training of the large language model, an optimized value of the matrix rank is assigned to each weight matrix, that is, the optimized value of the matrix rank automatically increases or decreases during the training process, reducing the steps of manually adjusting the matrix rank. The matrix rank can be set automatically, saving setting time, which is conducive to improving the efficiency and accuracy of the setting.

[0106] S205, decomposing the weight matrix into a low-rank matrix D and a low-rank matrix E according to the optimized value;

[0107] Among them, low-rank matrix A, low-rank matrix B, low-rank matrix D, and low-rank matrix E are different low-rank matrices.

[0108] S206, obtaining a first gradient value of a first parameter of the low-rank matrix D, and obtaining a second gradient value of a second parameter of the low-rank matrix E;

[0109] Among them, the first parameter is the parameter of the low rank matrix D, and the second parameter is the parameter of the low rank matrix E.

[0110] The step of obtaining a first gradient value of a first parameter of the low-rank matrix D and obtaining a second gradient value of a second parameter of the low-rank matrix E includes:

[0111] Obtaining a loss function of the large language model;

[0112] The first parameter of the low-rank matrix D is differentiated by the loss function to obtain the first gradient value of the first parameter, and the second parameter of the low-rank matrix E is differentiated by the loss function to obtain the second gradient value of the second parameter.

[0113] The loss function includes one of a cross entropy loss function, a mean square error function, and a logarithmic loss function, or a combination thereof.

[0114] S207, updating the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and updating the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate, until the trained large language model is saved.

[0115] The first learning rate and the second learning rate are different learning rates.

[0116] Exemplarily, updating the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and updating the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate, includes:

[0117] Obtain a first product of the first gradient value and a first learning rate, subtract the first product of the first gradient value and the first learning rate from the current parameter value of the first parameter, and obtain a target parameter value of the first parameter of the low-rank matrix D after updating.

[0118] Obtain a second product of the second gradient value and the second learning rate, subtract the second product of the second gradient value and the second learning rate from the current parameter value of the second parameter, and obtain a target parameter value of the second parameter of the low-rank matrix E after updating.

[0119] Among them, the first learning rate is set for the low-rank matrix D, and the second learning rate is set for the low-rank matrix E. By setting different learning rates for different matrices, the training process of the large language model can be better controlled to avoid excessive oscillation, which is conducive to improving the stability of the large language model.

[0120] The updating of the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and the updating of the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate, until the trained large language model is saved, includes:

[0121] The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate. The training of the large language model is stopped until the number of training rounds of the large language model reaches a preset number of rounds, and the trained large language model is saved.

[0122] Exemplarily, after updating the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and updating the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate, until the trained large language model is saved, the large language model training method includes:

[0123] Using preset test samples, the performance of the trained large language model is evaluated to obtain evaluation results, a storage area corresponding to the evaluation results is created in a preset storage device, the evaluation results are stored in the storage area, and an access interface for the storage area is created.

[0124] Exemplarily, using a preset test sample, the performance of the trained large language model is evaluated to obtain an evaluation result, a storage area corresponding to the evaluation result is created in a preset storage device, the evaluation result is stored in the storage area, and an access interface for the storage area is created, including:

[0125] Using a preset test sample, performing a performance evaluation on the trained large language model to obtain an evaluation result;

[0126] Obtaining evaluation indicators of the evaluation result, and generating a comprehensive score according to the number of the evaluation indicators, the weight coefficients corresponding to the evaluation indicators, the scoring values ​​corresponding to the evaluation indicators, and a preset comprehensive score generation model;

[0127] Determine whether the comprehensive score is greater than a preset threshold;

[0128] If the comprehensive score is greater than the preset threshold, a storage area corresponding to the evaluation result is created in a preset storage device, the evaluation result is stored in the storage area, and an access interface to the storage area is created.

[0129] The comprehensive score generation model is:

[0130] ;

[0131] in, is the comprehensive score, is the number of evaluation indicators, is the serial number of the evaluation indicator, For the The weight coefficient corresponding to the evaluation index is: For the The comprehensive score generation model is a scoring value corresponding to the evaluation indicator.

[0132] For the sake of illustration, an example is given below:

[0133] for example, is 3, the first evaluation indicator is accuracy, the second evaluation indicator is precision, and the third evaluation indicator is recall.

[0134] for example, is 4, the first evaluation indicator is accuracy, the second evaluation indicator is precision, the third evaluation indicator is recall, and the fourth evaluation indicator is mean square error.

[0135] Among them, the higher the comprehensive score, the higher the comprehensive performance of the large language model; the lower the comprehensive score, the worse the value of the comprehensive performance of the large language model.

[0136] Among them, valuable evaluation results can be provided through the access interface, which can help developers better understand the comprehensive performance of large language models and thus develop more effective training strategies.

[0137] The optimization value ranges from 1 to 256.

[0138] The beneficial effects of the embodiments of the present application lie in two aspects. On the one hand, in each round of training of the large language model, the adaptation coefficient corresponding to the comparison result is obtained, and the preset value is multiplied by the adaptation coefficient to generate the optimized value of the matrix rank. Therefore, the electronic device can generate the optimized value of the matrix rank, reducing the steps of manually adjusting the matrix rank, thereby simplifying the setting process of the optimized value of the matrix rank, which is beneficial to improving the setting efficiency of the optimized value of the matrix rank; on the other hand, according to the optimized value, the weight matrix is ​​decomposed into a low-rank matrix D and a low-rank matrix E, and the first gradient value of the first parameter of the low-rank matrix D is obtained, and the second gradient value of the second parameter of the low-rank matrix E is obtained. The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate. This solves the problem of how to use the optimized value of the matrix rank, which is beneficial to improving the efficiency of using the optimized value.

[0139] See also Figure 3 , Figure 3 The flowchart for obtaining the weight matrix provided in the embodiment of the present application is described in detail as follows:

[0140] S301, displaying a network layer list of the large language model, wherein the network layer list includes multiple network layers of the large language model;

[0141] S302, obtaining a specified operation of the network layer list, and obtaining the specified network layer according to the specified operation;

[0142] The specified network layer includes one or a combination of an embedding layer, a position encoding layer, a self-attention layer, a feedforward neural network layer, a residual connection and normalization layer, an encoder layer, a decoder layer, and an output layer.

[0143] S303, obtain the weight matrix of the specified network layer, obtain the preset value of the matrix rank set when the weight matrix is ​​decomposed into the low rank matrix A and the low rank matrix B according to the preset value.

[0144] In the embodiment of the present application, obtaining the weight matrix of the specified network layer can meet the user's customized needs and help improve the user's usage experience.

[0145] For the large language model training method described in the above embodiment, please refer to Figure 4 , Figure 4 A schematic block diagram of a large language model training device provided in an embodiment of the present application, Figure 4 The large language model training apparatus 400 shown can be applied to Figure 1 The electronic device in the application scenario diagram shown below takes the electronic device as an example. Figure 4 The large language model training device 400 shown is described in detail. The large language model training device 400 may include a first acquisition module 401, an addition module 402, a comparison module 403, a generation module 404, a decomposition module 405, a second acquisition module 406, and an update module 407.

[0146] A first acquisition module 401 is used to acquire a weight matrix of the large language model, acquire a preset value of a matrix rank of the weight matrix during low-rank decomposition, and decompose the weight matrix into a low-rank matrix A and a low-rank matrix B according to the preset value;

[0147] An adding module 402 is used to multiply the low-rank matrix A and the low-rank matrix B to obtain a matrix C, perform singular value decomposition on the matrix C to obtain two orthogonal matrices and a diagonal matrix, add Q singular values ​​of the diagonal matrix to obtain a first sum, and add the first K singular values ​​of the diagonal matrix to obtain a second sum;

[0148] A comparison module 403 is used to compare the second sum with the first sum to obtain a first ratio, and when the first ratio is greater than a preset second ratio, compare K with Q to obtain a third ratio, and compare the third ratio with a preset minimum ratio and a maximum ratio to obtain a comparison result corresponding to the matrix rank;

[0149] A generating module 404 is used to obtain an adaptation coefficient corresponding to the comparison result in each round of training of the large language model, and to multiply the preset value by the adaptation coefficient to generate an optimized value of the matrix rank;

[0150] A decomposition module 405, configured to decompose the weight matrix into a low-rank matrix D and a low-rank matrix E according to the optimization value;

[0151] A second acquisition module 406 is used to obtain a first gradient value of a first parameter of the low-rank matrix D, and to obtain a second gradient value of a second parameter of the low-rank matrix E;

[0152] An updating module 407 is used to update the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and to update the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate until the trained large language model is saved.

[0153] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.

[0154] The beneficial effects of the embodiments of the present application lie in two aspects. On the one hand, in each round of training of the large language model, the adaptation coefficient corresponding to the comparison result is obtained, and the preset value is multiplied by the adaptation coefficient to generate the optimized value of the matrix rank. Therefore, the electronic device can generate the optimized value of the matrix rank, reducing the steps of manually adjusting the matrix rank, thereby simplifying the setting process of the optimized value of the matrix rank, which is beneficial to improving the setting efficiency of the optimized value of the matrix rank; on the other hand, according to the optimized value, the weight matrix is ​​decomposed into a low-rank matrix D and a low-rank matrix E, and the first gradient value of the first parameter of the low-rank matrix D is obtained, and the second gradient value of the second parameter of the low-rank matrix E is obtained. The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate. This solves the problem of how to use the optimized value of the matrix rank, which is beneficial to improving the efficiency of using the optimized value.

[0155] See also Figure 5 , Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0156] like Figure 5 As shown, Figure 5 The electronic device 2 includes: at least one processor 20, a memory 21, and a computer program 22 stored in the memory 21 and executable on the at least one processor 20, and when the processor 20 executes the computer program 22, the steps in any of the above-mentioned method embodiments are implemented.

[0157] The electronic device 2 may include, but is not limited to, a processor 20 and a memory 21. Those skilled in the art will appreciate that Figure 5 It is only an example of the electronic device 2 and does not constitute a limitation on the electronic device 2. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.

[0158] The processor 20 is used to run the computer program 22 stored in the memory 21, and implement the following steps when executing the computer program 22:

[0159] Obtain a weight matrix of the large language model, obtain a preset value of a matrix rank of the weight matrix during low-rank decomposition, and decompose the weight matrix into a low-rank matrix A and a low-rank matrix B according to the preset value;

[0160] Multiplying the low-rank matrix A and the low-rank matrix B to obtain a matrix C, performing singular value decomposition on the matrix C to obtain two orthogonal matrices and a diagonal matrix, adding Q singular values ​​of the diagonal matrix to obtain a first sum, and adding the first K singular values ​​of the diagonal matrix to obtain a second sum;

[0161] The second sum is compared with the first sum to obtain a first ratio, and when the first ratio is greater than a preset second ratio, K is compared with Q to obtain a third ratio, and the third ratio is compared with a preset minimum ratio and a maximum ratio to obtain a comparison result corresponding to the matrix rank;

[0162] In each round of training of the large language model, obtaining an adaptation coefficient corresponding to the comparison result, multiplying the preset value by the adaptation coefficient, and generating an optimized value of the matrix rank;

[0163] According to the optimized value, the weight matrix is ​​decomposed into a low-rank matrix D and a low-rank matrix E; a first gradient value of a first parameter of the low-rank matrix D is obtained, and a second gradient value of a second parameter of the low-rank matrix E is obtained; the first parameter of the low-rank matrix D is updated according to the first gradient value and a first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and a second learning rate, until the trained large language model is saved.

[0164] In some embodiments, the processor 20 is configured to implement:

[0165] Display a network layer list of the large language model, wherein the network layer list includes multiple network layers of the large language model;

[0166] Obtain a specified operation of the network layer list, and obtain the specified network layer according to the specified operation;

[0167] Obtain the weight matrix of the specified network layer, obtain the preset value of the matrix rank set when the weight matrix is ​​decomposed into the low rank matrix A and the low rank matrix B according to the preset value.

[0168] In some embodiments, the processor 20 is configured to implement:

[0169] The adaptation coefficient includes a reduction coefficient and an enlargement coefficient;

[0170] In each round of training of the large language model, obtaining an adaptation coefficient corresponding to the comparison result, multiplying the preset value by the adaptation coefficient, and generating an optimized value of the matrix rank, comprises:

[0171] When the comparison result is that the third ratio is less than or equal to the minimum ratio, in each round of training of the large language model, the reduction coefficient corresponding to the comparison result is obtained, the preset value is multiplied by the reduction coefficient, and the optimized value of the matrix rank is generated, the minimum ratio includes one of 1 / 5 and 1 / 6 or a combination thereof, and the reduction coefficient includes one of 0.5 and 0.6 or a combination thereof;

[0172] When the comparison result is that the third ratio is greater than or equal to the maximum ratio, in each round of training of the large language model, the amplification factor corresponding to the comparison result is obtained, the preset value is multiplied by the amplification factor, and the optimized value of the matrix rank is generated, the maximum ratio includes one of 1 / 2, 2 / 3 or a combination thereof, and the amplification factor includes one of 2 times, 3 times or a combination thereof.

[0173] In some embodiments, the processor 20 is configured to implement:

[0174] The obtaining a first gradient value of a first parameter of the low-rank matrix D and obtaining a second gradient value of a second parameter of the low-rank matrix E include:

[0175] Obtaining a loss function of the large language model;

[0176] The first parameter of the low-rank matrix D is differentiated by the loss function to obtain the first gradient value of the first parameter, and the second parameter of the low-rank matrix E is differentiated by the loss function to obtain the second gradient value of the second parameter.

[0177] In some embodiments, the processor 20 is configured to implement:

[0178] The updating of the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and the updating of the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate, until the trained large language model is saved, includes:

[0179] The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate. The training of the large language model is stopped until the minimum loss value of the loss function of the large language model is less than the preset loss value, and the trained large language model is saved.

[0180] In some embodiments, the processor 20 is configured to implement:

[0181] The updating of the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and the updating of the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate, until the trained large language model is saved, includes:

[0182] The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate. The training of the large language model is stopped until the number of training rounds of the large language model reaches a preset number of rounds, and the trained large language model is saved.

[0183] In some embodiments, the processor 20 is used to implement: the optimization value has a value range of 1 to 256.

[0184] The processor 20 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0185] In some embodiments, the memory 21 may be an internal storage unit of the electronic device 2, such as a hard disk or memory of the electronic device 2. In other embodiments, the memory 21 may also be an external storage device of the electronic device 2, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped on the electronic device 2. Further, the memory 21 may also include both an internal storage unit of the electronic device 2 and an external storage device. The memory 21 is used to store an operating system, an application program, a boot loader (Boot Loader), data, and other programs, such as the program code of the computer program, etc. The memory 21 may also be used to temporarily store data that has been output or is to be output.

[0186] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0187] An embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.

[0188] The computer-readable storage medium stores program code, which can be called by a processor to execute the large language model training method described in the above method embodiment.

[0189] The computer-readable storage medium has a storage space for program codes.

[0190] The program code includes the code of any step in the large language model training method described in the above method embodiment.

[0191] For example, the program code is called by the processor and can execute the following steps:

[0192] Obtain a weight matrix of the large language model, obtain a preset value of a matrix rank of the weight matrix during low-rank decomposition, and decompose the weight matrix into a low-rank matrix A and a low-rank matrix B according to the preset value;

[0193] Multiplying the low-rank matrix A and the low-rank matrix B to obtain a matrix C, performing singular value decomposition on the matrix C to obtain two orthogonal matrices and a diagonal matrix, adding Q singular values ​​of the diagonal matrix to obtain a first sum, and adding the first K singular values ​​of the diagonal matrix to obtain a second sum;

[0194] The second sum is compared with the first sum to obtain a first ratio, and when the first ratio is greater than a preset second ratio, K is compared with Q to obtain a third ratio, and the third ratio is compared with a preset minimum ratio and a maximum ratio to obtain a comparison result corresponding to the matrix rank;

[0195] In each round of training of the large language model, obtaining an adaptation coefficient corresponding to the comparison result, multiplying the preset value by the adaptation coefficient, and generating an optimized value of the matrix rank;

[0196] Decomposing the weight matrix into a low-rank matrix D and a low-rank matrix E according to the optimized value;

[0197] Obtain a first gradient value of a first parameter of the low-rank matrix D, and obtain a second gradient value of a second parameter of the low-rank matrix E;

[0198] The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate until the trained large language model is saved.

[0199] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.

[0200] Among them, the computer-readable storage medium can also be an external storage device of a large language model training device or an electronic device, for example, a plug-in hard disk equipped on a large language model training device or an electronic device, a smart memory card (SmartMedia Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), a non-volatile computer-readable medium (non-transitory computer-readable storage medium), etc.

[0201] Since the computer program stored in the computer-readable storage medium can execute any of the large language model training methods provided in the embodiments of the present application, the computer-readable storage medium can achieve the beneficial effects that can be achieved by any of the large language model training methods provided in the embodiments of the present application. Please refer to the previous embodiments for details and will not be repeated here.

[0202] An embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes the above-mentioned large language model training method.

[0203] The computer program product is loaded into the electronic device and can execute the following steps:

[0204] Obtain a weight matrix of the large language model, obtain a preset value of a matrix rank of the weight matrix during low-rank decomposition, and decompose the weight matrix into a low-rank matrix A and a low-rank matrix B according to the preset value;

[0205] Multiplying the low-rank matrix A and the low-rank matrix B to obtain a matrix C, performing singular value decomposition on the matrix C to obtain two orthogonal matrices and a diagonal matrix, adding Q singular values ​​of the diagonal matrix to obtain a first sum, and adding the first K singular values ​​of the diagonal matrix to obtain a second sum;

[0206] The second sum is compared with the first sum to obtain a first ratio, and when the first ratio is greater than a preset second ratio, K is compared with Q to obtain a third ratio, and the third ratio is compared with a preset minimum ratio and a maximum ratio to obtain a comparison result corresponding to the matrix rank;

[0207] In each round of training of the large language model, obtaining an adaptation coefficient corresponding to the comparison result, multiplying the preset value by the adaptation coefficient, and generating an optimized value of the matrix rank;

[0208] Decomposing the weight matrix into a low-rank matrix D and a low-rank matrix E according to the optimized value;

[0209] Obtain a first gradient value of a first parameter of the low-rank matrix D, and obtain a second gradient value of a second parameter of the low-rank matrix E;

[0210] The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate until the trained large language model is saved.

[0211] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium.

[0212] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0213] Based on such understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of each of the above-mentioned method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to an electronic device, a recording medium, a computer memory, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), an electrical carrier signal, a telecommunication signal, and a software distribution medium. For example, a USB flash drive, a mobile hard disk, a disk or an optical disk.

[0214] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0215] The above are only preferred embodiments of the present application, and are not intended to limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the present application specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present application.

Claims

1. A large language model training method, characterized in that: Applied to an electronic device, the electronic device stores a pre-trained large language model, and the large language model training method includes: Obtain a weight matrix of the large language model, obtain a preset value of a matrix rank of the weight matrix during low-rank decomposition, and decompose the weight matrix into a low-rank matrix A and a low-rank matrix B according to the preset value; Multiplying the low-rank matrix A and the low-rank matrix B to obtain a matrix C, performing singular value decomposition on the matrix C to obtain two orthogonal matrices and a diagonal matrix, adding Q singular values ​​of the diagonal matrix to obtain a first sum, and adding the first K singular values ​​of the diagonal matrix to obtain a second sum; The second sum is compared with the first sum to obtain a first ratio, and when the first ratio is greater than a preset second ratio, K is compared with Q to obtain a third ratio, and the third ratio is compared with a preset minimum ratio and a maximum ratio to obtain a comparison result corresponding to the matrix rank; In each round of training of the large language model, obtaining an adaptation coefficient corresponding to the comparison result, multiplying the preset value by the adaptation coefficient, and generating an optimized value of the matrix rank; Decomposing the weight matrix into a low-rank matrix D and a low-rank matrix E according to the optimized value; Obtain a first gradient value of a first parameter of the low-rank matrix D, and obtain a second gradient value of a second parameter of the low-rank matrix E; updating the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and updating the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate, until the trained large language model is saved; The adaptation coefficient includes a reduction coefficient and an enlargement coefficient; In each round of training of the large language model, obtaining an adaptation coefficient corresponding to the comparison result, multiplying the preset value by the adaptation coefficient, and generating an optimized value of the matrix rank, comprises: When the comparison result is that the third ratio is less than or equal to the minimum ratio, in each round of training of the large language model, the reduction coefficient corresponding to the comparison result is obtained, the preset value is multiplied by the reduction coefficient, and the optimized value of the matrix rank is generated, the minimum ratio includes one of 1 / 5 and 1 / 6 or a combination thereof, and the reduction coefficient includes one of 0.5 and 0.6 or a combination thereof; When the comparison result is that the third ratio is greater than or equal to the maximum ratio, in each round of training of the large language model, the magnification coefficient corresponding to the comparison result is obtained, the preset value is multiplied by the magnification coefficient, and the optimized value of the matrix rank is generated, the maximum ratio includes one of 1 / 2 and 2 / 3 or a combination thereof, and the magnification coefficient includes one of 2 times and 3 times or a combination thereof; Among them, low-rank matrix A, low-rank matrix B, low-rank matrix D, and low-rank matrix E are different low-rank matrices; The obtaining a first gradient value of a first parameter of the low-rank matrix D and obtaining a second gradient value of a second parameter of the low-rank matrix E include: Obtaining a loss function of the large language model; The first parameter of the low-rank matrix D is differentiated by the loss function to obtain the first gradient value of the first parameter, and the second parameter of the low-rank matrix E is differentiated by the loss function to obtain the second gradient value of the second parameter.

2. The large language model training method according to claim 1, characterized in that: The step of obtaining a weight matrix of the large language model, obtaining a preset value of a matrix rank of the weight matrix during low-rank decomposition, and decomposing the weight matrix into a low-rank matrix A and a low-rank matrix B according to the preset value includes: Display a network layer list of the large language model, wherein the network layer list includes multiple network layers of the large language model; Obtain a specified operation of the network layer list, and obtain the specified network layer according to the specified operation; Obtain the weight matrix of the specified network layer, obtain the preset value of the matrix rank set when the weight matrix is ​​decomposed into the low rank matrix A and the low rank matrix B according to the preset value.

3. The large language model training method according to claim 1, characterized in that: The updating of the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and the updating of the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate, until the trained large language model is saved, includes: The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate. The training of the large language model is stopped until the minimum loss value of the loss function of the large language model is less than the preset loss value, and the trained large language model is saved.

4. The large language model training method according to claim 1, characterized in that: The updating of the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and the updating of the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate, until the trained large language model is saved, includes: The first parameter of the low-rank matrix D is updated according to the first gradient value and the first learning rate, and the second parameter of the low-rank matrix E is updated according to the second gradient value and the second learning rate. The training of the large language model is stopped until the number of training rounds of the large language model reaches a preset number of rounds, and the trained large language model is saved.

5. The large language model training method according to any one of claims 1 to 4, characterized in that: The optimization value ranges from 1 to 256.

6. A large language model training device, characterized in that: Applied to an electronic device, the electronic device stores a pre-trained large language model, including: A first acquisition module is used to acquire a weight matrix of the large language model, acquire a preset value of a matrix rank of the weight matrix during low-rank decomposition, and decompose the weight matrix into a low-rank matrix A and a low-rank matrix B according to the preset value; An adding module, used for multiplying the low-rank matrix A and the low-rank matrix B to obtain a matrix C, performing singular value decomposition on the matrix C to obtain two orthogonal matrices and a diagonal matrix, adding Q singular values ​​of the diagonal matrix to obtain a first sum, and adding the first K singular values ​​of the diagonal matrix to obtain a second sum; A comparison module, configured to compare the second sum with the first sum to obtain a first ratio, and when the first ratio is greater than a preset second ratio, compare K with Q to obtain a third ratio, and compare the third ratio with a preset minimum ratio and a maximum ratio to obtain a comparison result corresponding to the matrix rank; A generating module, configured to obtain an adaptation coefficient corresponding to the comparison result in each round of training of the large language model, and to multiply the preset value by the adaptation coefficient to generate an optimized value of the matrix rank; A decomposition module, used for decomposing the weight matrix into a low-rank matrix D and a low-rank matrix E according to the optimization value; A second acquisition module is used to obtain a first gradient value of a first parameter of the low-rank matrix D, and to obtain a second gradient value of a second parameter of the low-rank matrix E; An updating module, configured to update the first parameter of the low-rank matrix D according to the first gradient value and the first learning rate, and to update the second parameter of the low-rank matrix E according to the second gradient value and the second learning rate, until the trained large language model is saved; The adaptation coefficient includes a reduction coefficient and an enlargement coefficient; In each round of training of the large language model, obtaining an adaptation coefficient corresponding to the comparison result, multiplying the preset value by the adaptation coefficient, and generating an optimized value of the matrix rank, comprises: When the comparison result is that the third ratio is less than or equal to the minimum ratio, in each round of training of the large language model, the reduction coefficient corresponding to the comparison result is obtained, the preset value is multiplied by the reduction coefficient, and the optimized value of the matrix rank is generated, the minimum ratio includes one of 1 / 5 and 1 / 6 or a combination thereof, and the reduction coefficient includes one of 0.5 and 0.6 or a combination thereof; When the comparison result is that the third ratio is greater than or equal to the maximum ratio, in each round of training of the large language model, the magnification coefficient corresponding to the comparison result is obtained, the preset value is multiplied by the magnification coefficient, and the optimized value of the matrix rank is generated, the maximum ratio includes one of 1 / 2 and 2 / 3 or a combination thereof, and the magnification coefficient includes one of 2 times and 3 times or a combination thereof; Among them, low-rank matrix A, low-rank matrix B, low-rank matrix D, and low-rank matrix E are different low-rank matrices; The obtaining a first gradient value of a first parameter of the low-rank matrix D and obtaining a second gradient value of a second parameter of the low-rank matrix E include: Obtaining a loss function of the large language model; The first parameter of the low-rank matrix D is differentiated by the loss function to obtain the first gradient value of the first parameter, and the second parameter of the low-rank matrix E is differentiated by the loss function to obtain the second gradient value of the second parameter.

7. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the large language model training method as described in any one of claims 1 to 5 is implemented.

8. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the large language model training method as described in any one of claims 1 to 5 is implemented.