Recognition training method and recognition method based on large language model
Through the recognition training method based on large language models, through knowledge distillation training and partial weight freezing, the problem of large parameter quantities of large language models is solved, the recognition accuracy and efficiency are improved, and more efficient quantitative model deployment is achieved.
Patent Information
- Application Number
- CN202411002760.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-25
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-07-25
AI Technical Summary
The huge number of parameters of large language models leads to high computing resource requirements and storage costs, which reduces deployment and inference efficiency. Moreover, traditional quantification methods are difficult to maintain the accuracy of the original model, resulting in poor recognition accuracy and low efficiency.
By obtaining text data and corresponding meaning representation, a training sample set is generated, a large language model is quantified, and the quantified model is trained using knowledge distillation, the gradient change of the key layer of the module is calculated, the weight layer to be frozen is selected, and partial weight freezing is performed. Knowledge distillation training improves the stability and accuracy of the model.
It improves the stability of quantitative fine-tuning of large language models, obtains quantitative models with higher accuracy and performance, reduces storage space and computing resource requirements, and improves recognition accuracy and efficiency.
Smart Images

Figure CN118520904B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, for example, to a recognition training method and a recognition method based on a large language model. Background Art
[0002] Large Language Models (LLMs) have become an important breakthrough in the field of artificial intelligence. These models use deep learning technology to learn the grammar, semantics, and regularities of language from massive amounts of text data, and can generate natural and fluent text. However, the huge number of parameters in large language models leads to high computing resource requirements, limiting their application in resource-constrained environments. In addition, the huge number of parameters also increases the storage cost and inference time of the model, reducing the deployment and inference efficiency.
[0003] Since large language models have complex structures and a large number of parameters, traditional post-training quantization methods often have difficulty maintaining the accuracy of the original model. Even if the original model is directly used as the teacher model and the quantized model is used as the student model for distillation training, the accuracy of the quantized model cannot be greatly improved.
[0004] Therefore, in the recognition process of the existing large language model, there are problems of poor recognition accuracy and low efficiency.
[0005] It should be noted that the information disclosed in the above background technology section is only used to enhance the understanding of the background of the present application, and therefore may include information that does not constitute the prior art known to ordinary technicians in the field. Summary of the invention
[0006] In order to provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. The summary is not an extensive review, nor is it intended to identify key / critical elements or delineate the scope of protection of these embodiments, but rather serves as a prelude to the detailed description that follows.
[0007] The embodiments of the present disclosure provide a recognition training method and a recognition method based on a large language model.
[0008] In some embodiments, a recognition training method based on a large language model includes:
[0009] Obtain text data and corresponding meaning representation;
[0010] Take the text data as samples, and the corresponding meaning of the samples as sample labels to generate the corresponding training sample set;
[0011] Input the training sample set into the large language model to be trained;
[0012] Quantize the large language model to be trained to the required number of bits based on the text data in the training sample set;
[0013] Based on the sample labels in the training sample set, the knowledge distillation training quantized model is used to calculate the gradient changes of the key layers of each module during training.
[0014] Based on the gradient changes of the key layers of each module during training, select the key layers of the modules whose weights are to be frozen, and re-perform the knowledge distillation training with some weights frozen;
[0015] When the trained large language model meets the preset stop condition, the trained large language model is obtained to be used for recognizing the text data to be recognized.
[0016] In some embodiments, quantizing the large language model to be trained to a required number of bits based on the text data in the training sample set includes:
[0017] Based on the text data in the training sample set, the weights are determined to use per-channel symmetric quantization with a quantization accuracy of INT4;
[0018] If the accuracy of the large language model to be trained is not BF16, use per-token asymmetric quantization with a quantization accuracy of BF16;
[0019] The quantization algorithm uses MinMax quantization, satisfying the formula:
[0020] ,
[0021] in, X q and X r Respectively represent the quantized variables and full-precision variables of each layer weight or activation, s is the scaling factor, and z is the zero point value;
[0022] For symmetric quantization, , z = 0, for asymmetric quantization ,z=min( X r ), where N is the number of quantization bits.
[0023] In some embodiments, based on sample labels in a training sample set, knowledge distillation trains a quantized model, including:
[0024] The large language model to be trained is used as the teacher model, and the quantized model is used as the student model;
[0025] The cross entropy loss between the student model output and the corresponding sample label, as well as the KL divergence between the student model output and the teacher model output are used as the distillation loss function L to perform knowledge distillation training on the quantized model.
[0026] In some embodiments, calculating the gradient changes of the key layers of each module during training includes:
[0027] At any epoch, based on the output feature map of the target layer and the distillation loss function, the square of the frobenius norm F of the gradient of the key layer in multiple arbitrary layers or each layer of the multi-head self-attention module of the student model is determined.
[0028] In some embodiments, the squared F is calculated as:
[0029] ,
[0030] Among them, θ is the output feature map of the target layer, L is the distillation loss function, is the gradient of the distillation loss function L with respect to the output θ of the layer. The gradient is a vector or matrix whose elements are the partial derivatives of the distillation loss function with respect to each element of the output feature map θ. Represents the square of the frobenius norm of the gradient g, that is, the sum of the squares of all elements in the gradient matrix.
[0031] In some embodiments, the key layers in the multi-head self-attention module include query, key, value, and output layers.
[0032] In some embodiments, based on the gradient changes of the key layers of each module during training, selecting the key layers of the module whose weights are to be frozen includes:
[0033] Count the F of each key layer of the student model, based on a coordinate system where the horizontal axis represents the gradually increasing training epochs and the vertical axis represents the value of the square of the frobenius norm of the gradient, and determine the curve of F of each key layer on the nth layer of the quantized model with epochs;
[0034] Based on the curve, the key layer whose F value meets the preset conditions is determined as the key layer of the module whose weight is to be frozen.
[0035] In some embodiments, re-performing partial weight-frozen knowledge distillation training includes:
[0036] The large language model to be trained is used as the teacher model, and the quantized model is used as the student model. The weights of the key layers of the module whose weights are selected to be frozen are frozen, the weights of other layers are adjusted, and knowledge distillation training is re-performed based on the training sample set.
[0037] In some embodiments, a recognition method based on a large language model includes:
[0038] Obtain text data to be recognized;
[0039] The text data to be recognized is input into a trained large language model to obtain a corresponding meaning representation, wherein the trained large language model is obtained based on the above-mentioned recognition training method based on the large language model.
[0040] The recognition training method and recognition method based on the large language model provided in the embodiments of the present disclosure can achieve the following technical effects:
[0041] When training a large language model, the large model quantization method of freezing some weights during knowledge distillation is used to observe the gradient changes of each key layer in the multi-head attention module to freeze the unstable key layers, and distill the training quantization model. This improves the stability of the quantization fine-tuning of the large language model, and can obtain a quantization model with higher accuracy and performance, further reducing the storage space and computing resource requirements for the deployment and inference of the large language model, thereby improving the recognition accuracy and efficiency of the large language model.
[0042] The above general description and the following description are exemplary and explanatory only and are not intended to limit the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] One or more embodiments are exemplarily described by corresponding drawings, which do not limit the embodiments. Elements with the same reference numerals in the drawings are shown as similar elements, and the drawings do not constitute a scale limitation, and wherein:
[0044] Figure 1 It is a flowchart of a recognition training method based on a large language model provided by an embodiment of the present disclosure;
[0045] Figure 2 It is a flowchart of a recognition method based on a large language model provided by an embodiment of the present disclosure;
[0046] Figure 3 It is a schematic diagram of the structure of a recognition system based on a large language model provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0047] In order to be able to understand the features and technical contents of the embodiments of the present disclosure in more detail, the implementation of the embodiments of the present disclosure is described in detail below in conjunction with the accompanying drawings. The attached drawings are for reference only and are not used to limit the embodiments of the present disclosure. In the following technical description, for the convenience of explanation, a full understanding of the disclosed embodiments is provided through multiple details. However, one or more embodiments can still be implemented without these details. In other cases, to simplify the drawings, well-known structures and devices can be simplified for display.
[0048] The terms "first", "second", etc. in the embodiments of the present disclosure are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged where appropriate, so as to describe the embodiments of the present disclosure described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions.
[0049] Unless otherwise stated, the term "plurality" means two or more.
[0050] In the embodiment of the present disclosure, the character " / " indicates that the preceding and following objects are in an "or" relationship. For example, A / B indicates: A or B.
[0051] The term "and / or" is a description of the association relationship between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or, A and B.
[0052] The term "correspondence" may refer to an association relationship or a binding relationship. The correspondence between A and B means that there is an association relationship or a binding relationship between A and B.
[0053] The following describes the recognition training method and recognition method based on a large language model provided by the embodiments of the present disclosure in conjunction with the accompanying drawings.
[0054] Figure 1 It is a flowchart of a recognition training method based on a large language model provided in an embodiment of the present disclosure.
[0055] Combination Figure 1 The recognition training method based on the large language model provided by the present disclosure may include:
[0056] S01, obtaining text data and corresponding meaning representation;
[0057] S02, taking the text data as samples and the meaning representation corresponding to the samples as sample labels to generate corresponding training sample sets;
[0058] S03, inputting the training sample set into the large language model to be trained;
[0059] S04, quantizing the large language model to be trained to a required number of bits based on the text data in the training sample set;
[0060] S05, based on the sample labels in the training sample set, the knowledge distillation training quantized model is used, and the gradient changes of the key layers of each module during training are calculated;
[0061] S06, based on the gradient changes of the key layers of each module during training, select the key layers of the modules whose weights are to be frozen, and re-perform the knowledge distillation training with partial weight freezing;
[0062] S07, when the trained large language model meets the preset stop condition, the trained large language model is obtained to be used for recognizing the text data to be recognized.
[0063] In the present disclosure, a recognition training method based on a large language model is provided. When training the large language model, a large model quantization method of freezing some weights during knowledge distillation is used to observe the gradient changes of each key layer in the multi-head attention module to freeze the unstable key layer, and the quantization model is trained by distillation. This improves the stability of the quantization fine-tuning of the large language model, and can obtain a quantization model with higher accuracy and performance, further reducing the storage space and computing resource requirements for the deployment and inference of the large language model, thereby improving the recognition accuracy and efficiency of the large language model.
[0064] In some embodiments, quantizing the large language model to be trained to the required number of bits based on the text data in the training sample set may include:
[0065] Based on the text data in the training sample set, the weights are determined to use per-channel symmetric quantization with a 4-bit integer (INT4) precision;
[0066] If the precision of the large language model to be trained is not in 16-bit floating point format (Brain Floating Point 16, BF16), per-token asymmetric quantization is used with a quantization precision of BF16;
[0067] The quantization algorithm uses MinMax quantization, satisfying the formula:
[0068] ,
[0069] in, X q and X r Respectively represent the quantized variables and full-precision variables of each layer weight or activation, s is the scaling factor, and z is the zero point value;
[0070] For symmetric quantization, , z = 0, for asymmetric quantization, ,z=min( X r ), where N is the number of quantization bits.
[0071] In some embodiments, the model quantized by knowledge distillation training based on sample labels in the training sample set may include:
[0072] The large language model to be trained is used as the teacher model, and the quantized model is used as the student model;
[0073] The cross entropy loss between the student model output and the corresponding sample label, as well as the relative entropy (Kullback-Leibler divergence, KL divergence) between the student model output and the teacher model output are used as the distillation loss function L to perform knowledge distillation training on the quantized model.
[0074] In some embodiments, the above calculation of the gradient changes of the key layers of each module during training may include:
[0075] At any epoch, based on the output feature map of the target layer and the distillation loss function, the square of the frobenius norm F of the gradient of the key layer in multiple arbitrary layers or each layer of the multi-head self-attention module of the student model is determined.
[0076] In some embodiments, the calculation method of the square F can be:
[0077] ,
[0078] Among them, θ is the output feature map of the target layer, L is the distillation loss function, is the gradient of the distillation loss function L with respect to the output θ of the layer. The gradient is a vector or matrix whose elements are the partial derivatives of the distillation loss function with respect to each element of the output feature map θ. Represents the square of the frobenius norm of the gradient g, that is, the sum of the squares of all elements in the gradient matrix.
[0079] In some embodiments, the key layers in the above-mentioned multi-head self-attention module may include four layers: query, key, value, and output.
[0080] In some embodiments, the above-mentioned selecting the module key layers whose weights are to be frozen based on the gradient changes of the key layers of each module during training may include:
[0081] Count the F of each key layer of the student model, based on a coordinate system where the horizontal axis represents the gradually increasing training epochs and the vertical axis represents the value of the square of the frobenius norm of the gradient, and determine the curve of F of each key layer on the nth layer of the quantized model with epochs;
[0082] Based on the curve, the key layer whose F value meets the preset conditions is determined as the key layer of the module whose weight is to be frozen.
[0083] In some embodiments, the above-mentioned re-performing partial weight freezing of knowledge distillation training may include:
[0084] The large language model to be trained is used as the teacher model, and the quantized model is used as the student model. The weights of the key layers of the module whose weights are selected to be frozen are frozen, the weights of other layers are adjusted, and knowledge distillation training is re-performed based on the training sample set.
[0085] In a complete example, the selection of quantization strategy includes the quantization of weights and the quantization of activation values. The large language model to be trained in this example is the open source large language model Llama2 with a precision of BF16. Per-channel symmetric quantization is used for weights, and the quantization precision is INT4; for activations, no quantization is performed, and the BF16 precision is maintained. The quantization algorithm uses MinMax quantization, which can be expressed by the following formula:
[0086] ,
[0087] in, X q and X r Represent the quantized variables and full-precision variables of each layer weight or activation, s is the scaling factor, and z is the zero point value. Let N be the number of quantization bits. For symmetric quantization, , z=0.
[0088] The implementation method of quantization includes using the pytorch framework to add quantization and dequantization operators to the large language model Llama2 to obtain the quantized model to be trained.
[0089] Then, we use the full-precision Llama2 as the teacher model, that is, the large language model to be trained is used as the teacher model, and the quantized model obtained above is used as the student model. We perform knowledge distillation training on the Wikitext language dataset, that is, on the training sample set, and evaluate it through multiple common sense benchmarks such as Piqa and Arc-easy. The distillation loss function L used includes two parts: one is based on the cross entropy loss between the student model output and the sample labels in the training sample set, and the other is based on the KL divergence between the student model output and the teacher model output. Then, we minimize the distillation loss function during training.
[0090] Then, when training a large language model by distillation, the square of the frobenius norm of the gradients of the four key layers of query (Q), key (K), value (V) and output (O) in the multi-head self-attention module of the student model at the 5th, 10th, 15th, 20th, 25th and 30th layers can be counted every 100 epochs. Assuming that the output feature map of one of the layers is θ and the loss function is the distillation loss function L used above, the calculation method of F is:
[0091] ,
[0092] in, is the gradient of the loss function L with respect to the output θ of the layer. This gradient is a vector or matrix whose elements are the partial derivatives of the loss function with respect to each element of the output feature map θ. Represents the square of the Frobenius norm of the gradient g, that is, the sum of the squares of all elements in the gradient matrix.
[0093] After that, the gradient changes on each key layer of the student model are statistically obtained and plotted on a coordinate table: the horizontal axis represents the gradually increasing training epoch, the vertical axis represents the value of the square of the frobenius norm of the gradient, and the curve of F of the Q, K, V, and O layers with epoch when plotted on the nth layer of the quantized model. Observe which key layer or layers have a larger F value than other keywords (more than one order of magnitude higher than other layers). This shows that layers with larger F values are more susceptible to quantization errors during quantization, affecting the forward propagation of the model and destroying the stability of the entire distillation training. Therefore, the layers with larger F values are selected to freeze the weights for distillation training (at least one layer is not frozen), so that the model can adapt to quantization errors without modifying the most sensitive part of the network. In this embodiment, because it is observed that the F of the V and O layers is 1 to 2 orders of magnitude larger than the average of the other two layers, it is selected to freeze the weights in the V and O layers in each multi-head attention module and fine-tune the other layers.
[0094] Then, we use the full-precision Llama2 as the teacher model, the obtained quantized model as the student model, freeze the weights in the V and O layers, only fine-tune the weights of other layers, re-perform knowledge distillation training on the language dataset, and finally obtain a quantized model that performs close to the teacher model in multiple benchmarks.
[0095] In the present disclosure, a recognition training method based on a large language model is provided. When training a large language model, a large model quantization method that freezes part of the weights during knowledge distillation is used to observe the gradient changes of each key layer in the multi-head attention module to freeze the unstable key layer, and the quantization model is trained by distillation. This improves the stability of the quantization fine-tuning of the large language model, and can obtain a quantization model with higher accuracy and performance, further reducing the storage space and computing resource requirements for the deployment and inference of the large language model, thereby improving the recognition accuracy and efficiency of the large language model.
[0096] Figure 2 is a flow chart of a recognition method based on a large language model provided by an embodiment of the present disclosure, such as Figure 2 As shown, the recognition method based on the large language model may include:
[0097] S11, obtaining text data to be recognized;
[0098] S12, inputting the text data to be recognized into the trained large language model to obtain the corresponding meaning representation, wherein the trained large language model is based on Figure 1 This is obtained using the recognition training method based on a large language model.
[0099] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present disclosure is not limited by the order of the actions described, because according to the present disclosure, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present disclosure.
[0100] Combination Figure 3 As shown, the embodiment of the present disclosure provides a recognition system 300 based on a large language model, including a processor 304 and a memory 301. Optionally, the system may also include a communication interface 302 and a bus 303. Among them, the processor 304, the communication interface 302, and the memory 301 can communicate with each other through the bus 303. The communication interface 302 can be used for information transmission. The processor 304 can call the logic instructions in the memory 301 to execute the recognition training method and recognition method based on the large language model of the above embodiment.
[0101] In addition, the logic instructions in the memory 301 described above can be implemented in the form of software functional units and can be stored in a computer-readable storage medium when sold or used as an independent product.
[0102] The memory 301 is a computer-readable storage medium that can be used to store software programs and computer executable programs, such as program instructions / modules corresponding to the methods in the embodiments of the present disclosure. The processor 304 executes the functional application and data processing by running the program instructions / modules stored in the memory 301, that is, implementing the recognition training method and recognition method based on the large language model in the above-mentioned embodiments.
[0103] The memory 301 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 301 may include a high-speed random access memory and may also include a non-volatile memory.
[0104] The embodiments of the present disclosure provide a computer-readable storage medium storing computer-executable instructions, wherein the computer-executable instructions are configured to execute a recognition training method and a recognition method based on a large language model.
[0105] The computer-readable storage medium mentioned above may be a transient computer-readable storage medium or a non-transitory computer-readable storage medium.
[0106] The technical solution of the embodiment of the present disclosure can be embodied in the form of a software product, which is stored in a storage medium and includes one or more instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the method of the embodiment of the present disclosure. The aforementioned storage medium may be a non-transient storage medium, including: a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk, and other media that can store program codes, or a transient storage medium.
[0107] The above description and the accompanying drawings fully illustrate the embodiments of the present disclosure so that those skilled in the art can practice them. Other embodiments may include structural, logical, electrical, process and other changes. The embodiments represent possible changes only. Unless explicitly required, individual components and functions are optional, and the order of operations may vary. Parts and features of some embodiments may be included in or replace parts and features of other embodiments. As used in the description of the embodiments, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms as well. Similarly, the term "and / or" as used in this application refers to any and all possible combinations of one or more associated listings. In addition, when used in this application, the term "comprise" and its variants "comprises" and / or including (comprising) refer to the existence of stated features, wholes, steps, operations, elements, and / or components, but do not exclude the existence or addition of one or more other features, wholes, steps, operations, elements, components and / or these groups. In the absence of further restrictions, the elements defined by the sentence "comprising a ..." do not exclude the existence of other identical elements in the process, method or device comprising the elements. In this article, each embodiment may focus on the differences from other embodiments, and the same or similar parts between the embodiments may refer to each other. For the methods, products, etc. disclosed in the embodiments, if they correspond to the method part disclosed in the embodiments, then the relevant parts can refer to the description of the method part.
[0108] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software may depend on the specific application and design constraints of the technical solution. Technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the embodiments of the present disclosure. Technicians can clearly understand that for the convenience and simplicity of description, the specific working process of the systems, devices and units described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0109] In the embodiments disclosed herein, the disclosed methods and products (including but not limited to devices, equipment, etc.) can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units can be only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms. The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to implement this embodiment. In addition, each functional unit in the embodiment of the present disclosure may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit.
[0110] The flowchart and block diagram in the accompanying drawings show the possible architecture, functions and operations of the system, method and computer program product according to the embodiment of the present disclosure. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and a part of the module, program segment or code contains one or more executable instructions for realizing the specified logical function. In some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. In the description corresponding to the flowchart and block diagram in the accompanying drawings, the operations or steps corresponding to different boxes can also occur in a different order from the order disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, which can depend on the functions involved. Each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented by a dedicated hardware-based system that performs the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.
Claims
1. A recognition training method based on a large language model, characterized in that: The method comprises: Obtain text data and corresponding meaning representation; Taking the text data as samples and the meanings corresponding to the samples as sample labels, generating corresponding training sample sets; Inputting the training sample set into the large language model to be trained; quantizing the large language model to be trained to a required number of bits based on the text data in the training sample set; Based on the sample labels in the training sample set, knowledge distillation trains the quantized model, and calculates the gradient changes of the key layers of each module during training; Based on the gradient changes of the key layers of each module during training, select the key layers of the modules whose weights are to be frozen, and re-perform the knowledge distillation training with some weights frozen; When the trained large language model meets the preset stop condition, the trained large language model is obtained to be used for recognizing the text data to be recognized; The step of quantizing the large language model to be trained to a required number of bits based on the text data in the training sample set includes: Based on the text data in the training sample set, the weight is determined to use per-channel symmetric quantization with a quantization accuracy of INT4; If the accuracy of the large language model to be trained is not BF16, use per-token asymmetric quantization with a quantization accuracy of BF16; The quantization algorithm uses MinMax quantization, satisfying the formula: , in, X q and X r Respectively represent the quantized variables and full-precision variables of each layer weight or activation, s is the scaling factor, and z is the zero point value; For symmetric quantization, , z = 0, for asymmetric quantization, ,z=min( X r ), where N is the number of quantization bits; The calculation of the gradient changes of the key layers of each module during training includes: At any epoch, based on the output feature map of the target layer and the distillation loss function, determine the square of the frobenius norm F of the gradient of the key layer in the multi-head self-attention module of multiple arbitrary layers or each layer of the student model, wherein the distillation loss function is the KL divergence between the output of the student model and the output of the teacher model, the student model is the quantized model, and the teacher model is the large language model to be trained; The step of selecting the key layers of the modules whose weights are to be frozen based on the gradient changes of the key layers of each module during training includes: Statistically calculate the gradient change F of each key layer of the student model. Based on the coordinate system where the horizontal axis represents the gradually increasing training epochs and the vertical axis represents the square value of the frobenius norm of the gradient, determine the curve of F of each key layer with epoch when the quantized model is on the nth layer. Based on the curve, it is determined that the key layer whose F value meets the preset condition is the key layer of the module whose weight is to be frozen.
2. The method according to claim 1, characterized in that The knowledge distillation training quantized model based on the sample labels in the training sample set includes: The cross entropy loss between the student model output and the corresponding sample label, as well as the KL divergence between the student model output and the teacher model output are used as the distillation loss function L to perform knowledge distillation training on the quantized model.
3. The method according to claim 1, characterized in that The calculation method of the square F is: , Among them, θ is the output feature map of the target layer, L is the distillation loss function, is the gradient of the distillation loss function L with respect to the output θ of the layer. The gradient is a vector or matrix whose elements are the partial derivatives of the distillation loss function with respect to each element of the output feature map θ. Represents the square of the frobenius norm of the gradient g, that is, the sum of the squares of all elements in the gradient matrix.
4. The method according to claim 1, characterized in that: The key layers in the multi-head self-attention module include query, key, value and output.
5. The method according to claim 1, characterized in that: The re-performing of partial weight freezing of knowledge distillation training includes: The large language model to be trained is used as the teacher model, the quantized model is used as the student model, the weights of the key layers of the module selected to be frozen are frozen, the weights of other layers are adjusted, and knowledge distillation training is re-performed based on the training sample set.
6. A recognition method based on a large language model, characterized in that: The method comprises: Obtain text data to be recognized; The text data to be recognized is input into a trained large language model to obtain a corresponding meaning representation, wherein the trained large language model is obtained based on the method according to any one of claims 1 to 5.
