Model verification method and device, computer equipment and storage medium
By using the verification model in the large language model to split and verify the weights of the target level, the problem of difficulty in verifying the calculation results after tensor splitting is solved, the development efficiency and accuracy of the model are improved, and the weight splitting is ensured. the correctness of the results.
Patent Information
- Application Number
- CN202410702761.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-31
- Publication Date
- 2024-09-06
AI Technical Summary
In the development process of deep learning models, especially in large language models, the parallel calculation results of weight tensors after tensor splitting are difficult to directly verify, which makes it difficult to locate the problem of the calculation results and affects the development efficiency and accuracy of the model. .
By obtaining the verification model of the language model to be verified, the target weight in the target level is split based on the model, and the input data is operated according to the split results, and the expected operation results are obtained to verify the operation results to be verified, and the difference is calculated value and precision, adjust the splitting operation until the precision threshold is met to improve the efficiency of correctness verification of the weight splitting results.
This method does not require verification of the complete language model, improves the verification efficiency and development efficiency of large language models, ensures the accuracy of target-level operation results, and provides a solid foundation for distributed strategies.
Smart Images

Figure CN118607663A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a model verification method, device, computer equipment and storage medium. Background Art
[0002] With the development of deep learning (DL) models, model weights continue to increase, and the challenges faced by a single node are also increasing. For some large language models, the model size exceeds the available memory of a single node. To solve this problem, a variety of distributed strategies have emerged. For example, the weights in the model are split by tensor splitting, and the split weight tensors can be calculated in parallel on multiple nodes.
[0003] When using tensor splitting for calculation, it is necessary to verify the correctness of the parallel calculation results of the weight tensor. However, in the calculation result verification scheme after the weight tensor splitting of the relevant language model, the correctness of the tensor parallel calculation results is usually verified directly, which can fully meet the requirements for mature underlying implementations, but it is often difficult to directly verify the underlying implementation under development, and it is impossible to locate the problem of the calculation result. Summary of the invention
[0004] In view of this, the present invention provides a model verification method, apparatus, computer device and storage medium to solve the problem that it is difficult to directly verify the correctness of tensor parallel computing results for the underlying implementation under development.
[0005] In a first aspect, the present invention provides a model verification method, the method comprising:
[0006] Obtaining a verification model of the language model to be verified, wherein the verification model is used to demonstrate the operation result of the target level in the language model;
[0007] Based on the verification model, the target weights in the target level are split, and the input data is operated according to the split results to obtain the operation results to be verified;
[0008] The expected operation result is obtained, and the operation result to be verified is verified based on the expected operation result to obtain the verification result of the language model, wherein the expected calculation result is the operation result of the target layer in the language model performing the operation on the input data.
[0009] In an optional implementation, the expected operation result includes a first result vector, and the operation result to be verified includes a second result vector;
[0010] The operation result to be verified is verified based on the expected operation result to obtain the verification result of the language model, including:
[0011] Calculate the difference between the first result vector and the second result vector;
[0012] Determining a test accuracy corresponding to the language model based on a ratio of the square of the difference to the first result;
[0013] Obtaining an accuracy threshold and determining whether the test accuracy exceeds the accuracy threshold;
[0014] If not, determining that the verification result is that the splitting result meets the accuracy requirement of the language model, so as to perform a splitting operation on the target level in the language model;
[0015] If so, it is determined that the verification result is that the split result does not meet the accuracy requirement of the language model, so as to adjust the split operation, and split the target weight in the verification model based on the adjusted split operation until the test accuracy corresponding to the verification model does not exceed the accuracy threshold.
[0016] In an embodiment of the present invention, it can be determined based on the comparison result between the test accuracy corresponding to the verification result and the preset accuracy threshold that the split operation for the target weight meets the accuracy requirement for the language model after the event, so as to improve the efficiency of correctness verification of the weight splitting result in the large language model, and at the same time provide a solid foundation for splitting the target weight using a distributed strategy in the large language model, which can effectively improve the development efficiency for the large language model.
[0017] In an optional implementation, obtaining the expected operation result includes:
[0018] Based on the preset language, build a deep learning DL framework for language models;
[0019] Input the input data into the DL framework to obtain the output result of the DL framework;
[0020] Determine the expected operation results based on the output results.
[0021] In an embodiment of the present invention, a DL framework of a language model can be built, and an expected operation result can be determined based on the output result of the DL framework, wherein the expected operation result is the output result without weight splitting the language model, thereby providing a technical basis for verifying the above-mentioned operation result to be verified based on the expected operation result.
[0022] In an optional implementation, the target weight includes: a first weight and a second weight, wherein the first weight is a weight corresponding to each channel in the target level, and the second weight is a weight used for weighted calculation of outputs of each channel;
[0023] Based on the verification model, the target weights in the target hierarchy are split, including:
[0024] Based on the verification model, the first weight is split according to the first preset direction to obtain a first sub-weight;
[0025] Based on the verification model, the second weight is split according to a second preset direction to obtain second sub-weights, wherein the splitting directions corresponding to the first preset direction and the second preset direction are different.
[0026] In an embodiment of the present invention, taking into account the characteristics of language model calculation and structural level, the verification model can be set to split the first weight and the second weight according to different preset splitting directions, so as to ensure the accuracy of the calculation results finally output by the verification model.
[0027] In an optional embodiment, the first weight includes a query vector weight, a key vector weight and a value vector weight, wherein the query vector weight is used to indicate the vector of the acquired query keywords, the key vector weight is used to indicate the vector of the matching tags corresponding to the query keywords, and the value vector weight is used to indicate the vector of the query results corresponding to the matching tags.
[0028] In an embodiment of the present invention, taking into account the characteristics of language model calculation and structural level, the verification model can be set to split the first weight and the second weight according to different preset splitting directions, so as to ensure the accuracy of the calculation results finally output by the verification model.
[0029] In an optional implementation, the split result includes a first sub-weight and a second sub-weight;
[0030] The input data is operated according to the splitting results to obtain the operation results to be verified, including:
[0031] The first sub-weights are respectively distributed to the first operation nodes corresponding to the respective channels, so as to perform parallel operation on the input data and the weighted operation results of the first sub-weights;
[0032] The weighted operation result to be verified is obtained by performing parallel operation on the weighted operation result based on the second sub-weight.
[0033] In an embodiment of the present invention, a distributed strategy can be used to split the target weight. Specifically, multiple computing nodes can be allocated to the target level. After the target weight is split to obtain sub-weights, each sub-weight can be allocated to the corresponding node for parallel calculation, thereby improving the calculation speed of the model target level, and then improving the overall calculation speed of the language model.
[0034] In an optional implementation, the above method further includes:
[0035] The weighted calculation results and the verified calculation results are saved as files in a preset format;
[0036] When it is determined based on the verification result that the splitting result does not meet the accuracy requirement of the language model, the preset format file is analyzed to obtain an analysis report, so as to adjust the splitting operation based on the analysis report.
[0037] In an embodiment of the present invention, in the process of outputting the calculation results to be verified through the above-mentioned verification model, the input and output results of any link can be saved as a bin file, so as to facilitate printing out the distributed calculation results after the weight splitting, and provide a reference result for verifying the correctness of the calculation results in the back-end calculation execution stage.
[0038] In a second aspect, the present invention provides a model verification device, the device comprising:
[0039] An acquisition module, used to acquire a verification model of the language model to be verified, wherein the verification model is used to demonstrate the operation result of the target layer in the language model;
[0040] The operation module is used to split the target weights in the target level based on the verification model, and to operate the input data according to the split result to obtain the operation result to be verified;
[0041] The verification module is used to obtain the expected operation result, and verify the operation result to be verified based on the expected operation result to obtain the verification result of the language model, wherein the expected calculation result is the operation result of the target layer in the language model performing the operation on the input data.
[0042] In a third aspect, the present invention provides a computer device, comprising: a memory and a processor, the memory and the processor being communicatively connected to each other, the memory storing computer instructions, and the processor executing the model verification method of the first aspect or any corresponding embodiment thereof by executing the computer instructions.
[0043] In a fourth aspect, the present invention provides a computer-readable storage medium having computer instructions stored thereon, the computer instructions being used to enable a computer to execute the model verification method of the first aspect or any corresponding embodiment thereof.
[0044] In a fifth aspect, the present invention provides a computer program product, comprising computer instructions for causing a computer to execute the model verification method of the first aspect or any corresponding embodiment thereof. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0046] Figure 1 is a flow chart of a model verification method according to an embodiment of the present invention;
[0047] Figure 2 is a flow chart of another model verification method according to an embodiment of the present invention;
[0048] Figure 3 It is a schematic diagram of outputting the operation result to be verified through the verification model;
[0049] Figure 4 This is a schematic diagram of the output results based on the deep learning framework;
[0050] Figure 5 is a structural block diagram of a model verification device according to an embodiment of the present invention;
[0051] Figure 6 It is a schematic diagram of the hardware structure of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0052] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0053] In conjunction with the application scenarios on which the execution of the model verification method depends, the application scenarios are described here.
[0054] With the development of deep learning (DL) models, model weights continue to increase, and the challenges faced by a single node are also increasing. For some large language models, the model size exceeds the available memory of a single node. To solve this problem, a variety of distributed strategies have emerged. For example, the weights in the model are split by tensor splitting, and the split weight tensors can be calculated in parallel on multiple nodes.
[0055] When using tensor splitting for calculation, it is necessary to verify the correctness of the parallel calculation results of the weight tensor. However, in the calculation result verification scheme after the weight tensor splitting of the relevant language model, it is usually necessary to verify the output results of the complete large language model, which can fully meet the needs for mature underlying implementations, but it is often difficult to directly verify the underlying implementation under development, and it is impossible to locate the problem of the calculation results.
[0056] Specifically, when verifying the correctness of the parallel calculation results of the weight tensor, the correctness verification of the parallel calculation results of the Self-attention (attention mechanism) weight tensor splitting is the main content of the model verification.
[0057] Based on this, an embodiment of the present invention provides a model verification method. First, a verification model of a language model to be verified can be obtained, wherein the verification model is used to demonstrate the operation results of the target level in the language model. Then, based on the verification model, a split operation can be performed on the target weight in the target level, and the input data can be operated according to the split result to obtain the operation result to be verified. Next, the expected operation result can be obtained, and the operation result to be verified can be verified based on the expected operation result to obtain the verification result of the language model, wherein the expected calculation result is the operation result of the target level in the language model operating on the input data, thereby eliminating the need to verify the complete language model, so as to improve the verification efficiency for large language models, while also improving the scope of application of the present invention.
[0058] According to an embodiment of the present invention, a model verification method embodiment is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0059] In this embodiment, a model verification method is provided, which can be used in a computer device. Figure 1 is a flow chart of a model verification method according to an embodiment of the present invention. Figure 1 As shown, the process includes the following steps:
[0060] Step S101, obtaining a verification model of a language model to be verified, wherein the verification model is used to demonstrate a calculation result of a target level in the language model.
[0061] In an embodiment of the present invention, the language model to be verified may be a large language model, for example, LLAMA2 (including 7b, 13b, 70b), Qwen large model, chatGLM2, gpt2, etc. The verification model may be a demo (i.e., a demonstration example) established for a target level in the language model, wherein the target level may be a level of Self-attention in the language model. Here, the target level may generate a globally associated weight matrix by calculating the correlation between the elements in the input sequence, and this weight matrix reflects the degree of mutual dependence between different elements in the sequence.
[0062] When verifying a language model to be verified, a verification model of the language model to be verified can be first constructed. Specifically, a deep learning library corresponding to the language model, such as TensorFlow or PyTorch, can be installed first, and then a target level can be defined based on the deep learning library to obtain the above verification model.
[0063] It should be understood that there are many ways to construct a verification model for the language model to be verified. Users can choose the corresponding verification model construction method according to specific usage requirements. This disclosure will not elaborate on the remaining construction methods, and the specific implementation shall prevail.
[0064] Step S102, based on the verification model, splitting operation is performed on the target weights in the target level, and the input data is operated according to the splitting result to obtain the operation result to be verified.
[0065] In an embodiment of the present invention, the above-mentioned verification model can be used to output the operation result after weight splitting the target level in the output language model and performing operation on the input data, and determine the operation result as the operation result to be verified.
[0066] Specifically, the target weights in the target hierarchy may include a q weight matrix (q_weight), a k weight matrix (k_weight), a v weight matrix (v_weight), and an o weight matrix (o_weight). After splitting the target weights to obtain sub-weight matrices, the input data may be multiplied by the sub-weight matrices corresponding to the q weight matrix and the k weight matrix to obtain attention scores (hereinafter referred to as attention scores). Then, the attention scores matrix may be subjected to a softmax calculation, which normalizes the matrix so that the sum of the items is 1, thereby highlighting the largest value in the matrix and suppressing other components that are far below the maximum value.
[0067] Next, the normalized attention scores can be multiplied by the sub-weight matrix corresponding to the v weight matrix, and the matrix multiplication dimension can be changed by the sub-weight moment corresponding to the o weight matrix, thereby removing the requirement on the number of rows and columns of the input matrix corresponding to the input data and improving the scope of application of the present invention.
[0068] Step S103, obtaining an expected operation result, and verifying the operation result to be verified based on the expected operation result, to obtain a verification result of the language model, wherein the expected calculation result is the operation result of the target level in the language model performing operation on the input data.
[0069] In an embodiment of the present invention, after obtaining the expected operation result, the difference between the expected operation result and the operation result to be verified can be compared, so as to determine the verification result of the language model based on the difference. Here, the verification result can be used to indicate the degree of deviation of the operation result to be verified relative to the expected operation result, so as to verify the correctness of the split result for the target weight according to the degree of deviation, so as to realize the correctness verification of the weight tensor split result for the target level only through the operation result to be verified obtained by demo without performing a complete model inference.
[0070] It can be seen from the above description that in an embodiment of the present invention, first, a verification model of the language model to be verified can be obtained, wherein the verification model is used to demonstrate the operation results of the target level in the language model. Then, based on the verification model, a split operation can be performed on the target weight in the target level, and the input data can be operated according to the split result to obtain the operation result to be verified. Next, the expected operation result can be obtained, and the operation result to be verified can be verified based on the expected operation result to obtain the verification result of the language model, wherein the expected calculation result is the operation result of the target level in the language model operating on the input data, thereby eliminating the need to verify the complete language model, so as to improve the verification efficiency for large language models, while also improving the scope of application of the present invention.
[0071] In this embodiment, another model verification method is provided, which can be used for the above-mentioned computer device. Figure 2 is a flow chart of another model verification method according to an embodiment of the present invention. Figure 2 As shown, the process includes the following steps:
[0072] Step S201, obtaining a verification model of the language model to be verified, wherein the verification model is used to demonstrate the operation results of the target level in the language model. Figure 1 Step S101 of the illustrated embodiment will not be described in detail here.
[0073] Step S202, based on the verification model, splitting operation is performed on the target weights in the target level, and the input data is operated according to the splitting result to obtain the operation result to be verified.
[0074] Specifically, the target weight includes: a first weight and a second weight, wherein the first weight is the weight corresponding to each channel in the target level, and the second weight is the weight used for weighted calculation of the output of each channel; the above step S202 includes:
[0075] Step S2021: Based on the verification model, the first weight is split according to a first preset direction to obtain a first sub-weight.
[0076] Step S2022: Based on the verification model, the second weight is split according to a second preset direction to obtain a second sub-weight, wherein the splitting directions corresponding to the first preset direction and the second preset direction are different.
[0077] In an embodiment of the present invention, the above-mentioned first weight includes: a query vector weight (i.e., the above-mentioned q_weight), a key vector weight (i.e., the above-mentioned k_weight) and a value vector weight (i.e., the above-mentioned v_weight), wherein the query vector weight is used to indicate the vector of the acquired query keywords, the key vector weight is used to indicate the vector of the matching tags corresponding to the query keywords, and the value vector weight is used to indicate the vector of the query results corresponding to the matching tags.
[0078] Specifically, the concept corresponding to q_weight in Self-attention is query (query, referred to as q), which is usually used to indicate the query keyword entered by the user in the search bar; the concept corresponding to k_weight in Self-attention is key (label, referred to as k), which is usually used to indicate mapping the query to the matching label in the database; the concept corresponding to v_weight in Self-attention is value (value, referred to as v), which is usually used to indicate the query result that best matches the query in the key displayed to the user. It should be understood that the channels corresponding to q, k, and v at the target level are q channel, k channel, and v channel, respectively.
[0079] When the first weight is split based on the above verification model, q_weight, k_weight and v_weight may be split respectively according to a first preset direction, wherein the first preset direction may be axis=0, that is, the weight matrix is split by row.
[0080] For example, if the input matrix corresponding to the input data is The first weight is the weight matrix B, which When the weight matrix B is split in the direction of axis=0, the sub-matrices B1 and B1 corresponding to the first sub-weight can be obtained, where B1=[b 11 b 12 b 13 ],B2=[b 21 b 22 b 23 ].
[0081] Similarly, when the second weight is split based on the above verification model, o_weight can be split according to the second preset direction, wherein the second preset direction can be axis=1, that is, the weight matrix is split by column.
[0082] For example, if the second weight is a weight matrix C, the weight matrix When the weight matrix C is split in the axis=1 direction, the sub-matrices C1 and C2 corresponding to the first sub-weight can be obtained, where:
[0083] It should be understood that if the input matrix corresponding to the above input data is Then, according to the characteristics of matrix multiplication, we have Input matrix A and weight matrix B T The result of matrix multiplication D can be expressed as This is consistent with the result obtained by splitting the first weight, performing matrix multiplication, and then horizontally concatenating.
[0084] Specifically, when calculating the result D of the matrix multiplication in the above verification model, it is necessary to transpose the split weight matrix and perform matrix multiplication on the input matrix and the transposed result. Here, It should be understood that [D1D2] represents horizontal splicing, and [D1; D2] represents vertical splicing, where:
[0085]
[0086] Next, the above result D can be summed up according to the split result of the above weight matrix C to obtain the output result of the verification model. Specifically, the output result is
[0087] Step S203, obtaining the expected operation result, and verifying the operation result to be verified based on the expected operation result, to obtain the verification result of the language model, wherein the expected calculation result is the operation result of the target level in the language model performing the operation on the input data. Figure 1 Step S103 of the illustrated embodiment will not be described in detail here.
[0088] In an embodiment of the present invention, taking into account the characteristics of language model calculation and structural level, the verification model can be set to split the first weight and the second weight according to different preset splitting directions, so as to ensure the accuracy of the calculation results finally output by the verification model.
[0089] In some optional implementations, the split result includes the first sub-weight and the second sub-weight, and the step S102 further includes:
[0090] Step S11 , respectively allocating the first sub-weights to the first operation nodes corresponding to the respective channels, so as to perform parallel operation on the input data and the weighted operation results of the first sub-weights.
[0091] Step S12, performing parallel calculation on the weighted calculation result to be added based on the second sub-weight to obtain the calculation result to be verified.
[0092] In an embodiment of the present invention, a distributed strategy can be used to split the target weight. Specifically, multiple computing nodes can be allocated to the target level. After the target weight is split to obtain sub-weights, each sub-weight can be allocated to the corresponding node for parallel calculation, and allreduce (i.e., global normalization) is performed after the target level calculation is completed to add the calculation results of each sub-weight to obtain the above-mentioned calculation results to be verified.
[0093] Here, if Figure 3 The figure shows a schematic diagram of outputting the operation result to be verified through the above verification model, wherein the input data before the target layer is input in the above DL framework can be used as the input of the verification model.
[0094] When the input data is processed by the above verification model, the rms norm of each vector in the input data can be calculated first, wherein the rms norm can be used to verify the model to evaluate the importance or weight of the corresponding vector. Then, the target weight in the target level can be split into sub-weights through the matrix multiplication calculation module, and the matrix multiplication operation is performed on the sub-weights and the input data to obtain the sub-operation results.
[0095] Next, if the rank of the sub-operation result is not equal to 0 through the conditional judgment statement Rank! = 0, the residual addition operation is performed through residual_add to correct the sub-operation result, thereby ensuring the integrity and accuracy of the sub-operation result. After the sub-operation result is corrected, allreduce can be performed to add each sub-operation result to obtain the above-mentioned operation result to be verified.
[0096] For example, the following is the Figure 3The corresponding verification model code file for operation, specifically:
[0097] First, you can use the parsing script to split the target weight tensor and save the split result as a bin file:
[0098] parameter_to_split=[
[0099] #tuple of(name,index to split)
[0100] ('self_attn.q_proj.weight',0),
[0101] ('self_attn.q_proj.bias',0),
[0102] ('self_attn.k_proj.weight',0),
[0103] ('self_attn.k_proj.bias',0),
[0104] ('self_attn.v_proj.weight',0),
[0105] ('self_attn.v_proj.bias',0),
[0106] ('self_attn.o_proj.weight',1),
[0107] ('mlp.gate_proj.weight',0),
[0108] ('mlp.gate_proj.bias',0),
[0109] ('mlp.up_proj.weight',0),
[0110] ('mlp.up_proj.bias',0),
[0111] ('mlp.down_proj.weight',1), ]
[0113] x.tofile(os.path.join(args.weights,freq["name"]+".bin"))
[0114] Then, you can read the bin file as the data type of torch.Tensor() and preprocess the sub-weights in the bin file. Specifically, you can reshape the sub-weights into the shape that the target weights should have through the code file shown below:
[0115] input_mha=np.fromfile(input_path,dtype=np.float16,
[0116] count=input_length*max_input_length,offset=0)
[0117] Next, before performing the above matrix multiplication calculation, we can first calculate the rmsnorm (root mean square norm) of each vector in the input data a. Among them, rms_norm can be constructed, and epsilon can be passed as variables according to actual needs (commonly used e-05 or e-06):
[0118]
[0119] When processing the above target weights, we can construct a position rotation function based on the above q_weight and k_weight processing to perform cosine and sin calculations on q_weight and k_weight:
[0120]
[0121]
[0122] Next, the matrix multiplication calculation process can be constructed to obtain the sub-operation results. The specific construction method is subject to implementation and will not be repeated in the present invention. Then, the sub-operation results can be added together through allreduce to obtain the above-mentioned operation result to be verified:
[0123]
[0124] In an embodiment of the present invention, a distributed strategy can be used to split the target weight. Specifically, multiple computing nodes can be allocated to the target level. After the target weight is split to obtain sub-weights, each sub-weight can be allocated to the corresponding node for parallel calculation, thereby improving the calculation speed of the model target level, and then improving the overall calculation speed of the language model.
[0125] In some optional implementations, the above step S102 further includes:
[0126] Step S31: Save the weighted calculation result and the verified calculation result as a file in a preset format.
[0127] Step S32: when it is determined based on the verification result that the splitting result does not meet the accuracy requirement of the language model, the preset format file is analyzed to obtain an analysis report, so as to adjust the splitting operation based on the analysis report.
[0128] In an embodiment of the present invention, the above-mentioned preset format file can be a bin file. In the process of outputting the operation results to be verified through the above-mentioned verification model, the input and output results of any link can be saved as a bin file, for example, the input data, the weighted operation results and the operation results to be verified can be saved as a bin file.
[0129] When a call request for a bin file is detected, the bin file can be called to display to the user, or, when it is determined that the target weight splitting result does not meet the accuracy requirements of the language model, for example, the operation result to be verified deviates greatly from the expected operation result, an analysis report can be generated in response to an analysis request for the bin file.
[0130] Here, you can search for the target data associated with the above split operation in the bin file to check the split result of the target weight based on the target data. Specifically, you can first check the distribution of the target weights and determine whether the weights match the model performance during training. If so, you can determine whether the weight splitting strategy is reasonable, that is, whether the structure of the model and the characteristics of the data are taken into account. For example, based on the size of the sub-weights obtained by the split, evaluate whether the weight splitting may lead to overfitting.
[0131] In an embodiment of the present invention, in the process of outputting the calculation results to be verified through the above-mentioned verification model, the input and output results of any link can be saved as a bin file, so as to facilitate printing out the distributed calculation results after the weight splitting, and provide a reference result for verifying the correctness of the calculation results in the back-end calculation execution stage.
[0132] In some optional implementations, the above step S103 includes:
[0133] Step S21, building a deep learning DL framework of the language model based on the preset language.
[0134] Step S22: input the input data into the DL framework to obtain the output result of the DL framework.
[0135] Step S23, determining the expected operation result according to the output result.
[0136] In an embodiment of the present invention, the above-mentioned preset language may be python. When building a DL framework, the deep learning library corresponding to the preset language, such as PyTorch, may be installed first. The specific process of building the DL framework is subject to implementation and will not be repeated in the present invention.
[0137] After building the DL framework, the input data can be input into the DL framework to determine the output result as the expected operation result. Figure 4 The figure shows a schematic diagram of the output result obtained based on the DL framework, in which the discrete text data (such as words or phrases) in the input data can first be converted into a continuous vector representation through the Embedding layer. This conversion can capture semantic information and reduce the dimension to obtain the input sequence. Then, the Self-attention layer can be used to help the language model better understand the context information, and the importance of different words to the current word can be determined by calculating the similarity between words in the input sequence. After the Self-attention layer, the output of the Self-Attention layer can be further converted and abstracted through the MLP layer (Multi-LayerPerceptron, translated as multi-layer perceptron, MPL layer is a fully connected layer). Next, the Lm_head (i.e., language model head) layer can be used to predict the next word or perform similar tasks. Lm_head can predict the next element in the sequence based on the output of the previous layer (including the output of the Self-Attention and MLP layers) to obtain the output result.
[0138] After obtaining the output result of the above DL framework, the output result of the target level can be obtained from the output result as the expected operation result, where the target level is Figure 4 The Self-Attention layer in .
[0139] In an embodiment of the present invention, a DL framework of a language model can be built, and an expected operation result can be determined based on the output result of the DL framework, wherein the expected operation result is the output result without weight splitting the language model, thereby providing a technical basis for verifying the above-mentioned operation result to be verified based on the expected operation result.
[0140] In some optional implementations, the expected operation result includes a first result vector, and the operation result to be verified includes a second result vector; and the step S103 further includes:
[0141] Step S31, calculating the difference between the first result vector and the second result vector.
[0142] Step S32: determining the test accuracy corresponding to the language model based on the ratio of the square of the difference to the first result.
[0143] Step S33, obtaining an accuracy threshold, and determining whether the test accuracy exceeds the accuracy threshold.
[0144] Step S34: if not, determine that the verification result is that the splitting result meets the accuracy requirement of the language model, so as to perform a splitting operation on the target level in the language model.
[0145] Step S34, if yes, determine that the verification result is that the splitting result does not meet the accuracy requirement of the language model, adjust the splitting operation, and split the target weight in the verification model based on the adjusted splitting operation until the test accuracy corresponding to the verification model does not exceed the accuracy threshold.
[0146] In the embodiment of the present invention, the first result vector can be expressed as f0, and the second result vector can be expressed as f e Here, the test accuracy formula can be used to determine the test accuracy x 2 , the test accuracy can be expressed as: Among them, f0-f e That is, the difference between the first result vector and the second result vector. The ratio of the square of the difference to the first result is
[0147] Next, the accuracy threshold can be obtained, which can be preset based on experience, for example, 10 -5 At this time, if the test accuracy x 2 <10 -5 , it is determined that the verification result is that the split result meets the accuracy requirement of the language model, and thus the target level in the language model is split.
[0148] In addition, if the test accuracy x 2 >10 -5 , it indicates that the deviation between the operation result to be verified and the expected operation result is large, so the verification result is determined to be the split result that meets the accuracy requirements of the language model. Next, the split operation for the target weight in the verification model can be adjusted until the test accuracy x 2 <10 -5 , and then split the target level in the language model.
[0149] In an embodiment of the present invention, it can be determined based on the comparison result between the test accuracy corresponding to the verification result and the preset accuracy threshold that the split operation for the target weight meets the accuracy requirement for the language model after the event, so as to improve the efficiency of correctness verification of the weight splitting result in the large language model, and at the same time provide a solid foundation for splitting the target weight using a distributed strategy in the large language model, which can effectively improve the development efficiency for the large language model.
[0150] In summary, in an embodiment of the present invention, first, a verification model of a language model to be verified can be obtained, wherein the verification model is used to demonstrate the operation results of the target level in the language model. Then, based on the verification model, a split operation can be performed on the target weight in the target level, and the input data can be operated according to the split result to obtain the operation result to be verified. Next, the expected operation result can be obtained, and the operation result to be verified can be verified based on the expected operation result to obtain the verification result of the language model, wherein the expected calculation result is the operation result of the target level in the language model operating on the input data, thereby eliminating the need to verify the complete language model, so as to improve the verification efficiency for large language models, while also improving the scope of application of the present invention.
[0151] In this embodiment, a model verification device is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can be a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0152] This embodiment provides a model verification device, such as Figure 5 As shown, including:
[0153] An acquisition module 501 is used to acquire a verification model of a language model to be verified, wherein the verification model is used to demonstrate the operation result of a target level in the language model;
[0154] The operation module 502 is used to perform a split operation on the target weights in the target level based on the verification model, and to perform operations on the input data according to the split results to obtain the operation results to be verified;
[0155] The verification module 503 is used to obtain the expected operation result, and verify the operation result to be verified based on the expected operation result to obtain the verification result of the language model, wherein the expected calculation result is the operation result of the target level in the language model performing the operation on the input data.
[0156] In some optional implementations, the expected operation result includes a first result vector, the operation result to be verified includes a second result vector, and the verification module 503 includes:
[0157] A calculation unit, used for calculating the difference between the first result vector and the second result vector;
[0158] A first determining unit, configured to determine a test accuracy corresponding to the language model based on a ratio of the square of the difference value to the first result;
[0159] The second determination unit is used to obtain an accuracy threshold and determine whether the test accuracy exceeds the accuracy threshold; if not, it is determined that the verification result is that the splitting result meets the accuracy requirements of the language model, so as to perform a splitting operation on the target level in the language model; if so, it is determined that the verification result is that the splitting result does not meet the accuracy requirements of the language model, so as to adjust the splitting operation, and split the target weight in the verification model based on the adjusted splitting operation until the test accuracy corresponding to the verification model does not exceed the accuracy threshold.
[0160] In some optional implementations, the verification module 503 further includes:
[0161] The building unit is used to build a deep learning DL framework for language models based on a preset language;
[0162] An acquisition unit, used for inputting input data into the DL framework to obtain an output result of the DL framework;
[0163] The third determining unit is used to determine the expected operation result according to the output result.
[0164] In some optional implementations, the target weight includes: a first weight and a second weight, wherein the first weight is the weight corresponding to each channel in the target level, and the second weight is the weight used for weighted calculation of the output of each channel; the operation module 502 includes:
[0165] A first splitting unit is used to split the first weight according to a first preset direction based on the verification model to obtain a first sub-weight;
[0166] The second splitting unit is used to split the second weight according to a second preset direction based on the verification model to obtain second sub-weights, wherein the splitting directions corresponding to the first preset direction and the second preset direction are different.
[0167] In some optional embodiments, the first weight includes a query vector weight, a key vector weight and a value vector weight, wherein the query vector weight is used to indicate the vector of the acquired query keywords, the key vector weight is used to indicate the vector of the matching tags corresponding to the query keywords, and the value vector weight is used to indicate the vector of the query results corresponding to the matching tags.
[0168] In some optional implementations, the split result includes a first sub-weight and a second sub-weight; the operation module 502 further includes:
[0169] A distribution unit, used for distributing the first sub-weights to the first computing nodes corresponding to the respective channels, so as to perform parallel computing on the input data and the weighted computing results of the first sub-weights;
[0170] The operation unit is used to perform a parallel operation on the weighted operation result to be added based on the second sub-weight to obtain the operation result to be verified.
[0171] In some optional implementations, the operation module 502 further includes:
[0172] A saving unit, used to save the weighted calculation result and the verified calculation result into a file in a preset format;
[0173] The analysis unit is used to analyze a preset format file to obtain an analysis report when it is determined based on the verification result that the splitting result does not meet the accuracy requirement of the language model, so as to adjust the splitting operation based on the analysis report.
[0174] The further functional description of each of the above modules and units is the same as that of the above corresponding embodiments and will not be repeated here.
[0175] The model verification device in this embodiment is presented in the form of a functional unit, where the unit refers to an ASIC (Application Specific Integrated Circuit) circuit, a processor and memory that executes one or more software or fixed programs, and / or other devices that can provide the above functions.
[0176] The embodiment of the present invention also provides a computer device having the above Figure 5 Model validation apparatus shown.
[0177] See also Figure 6 , Figure 6 is a schematic diagram of the structure of a computer device provided by an optional embodiment of the present invention, such as Figure 6 As shown, the computer device includes: one or more processors 10, a memory 20, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. Various components are connected to each other using different buses for communication, and can be installed on a common mainboard or installed in other ways as needed. The processor can process the instructions executed in the computer device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as, a display device coupled to the interface). In some optional embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple computer devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 6 A processor 10 is taken as an example.
[0178] The processor 10 may be a central processing unit, a network processor or a combination thereof. The processor 10 may further include a hardware chip. The hardware chip may be a dedicated integrated circuit, a programmable logic device or a combination thereof. The programmable logic device may be a complex programmable logic device, a field programmable gate array, a general purpose array logic or any combination thereof.
[0179] The memory 20 stores instructions executable by at least one processor 10, so that the at least one processor 10 executes the method shown in the above embodiment.
[0180] The memory 20 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created according to the use of the computer device, etc. In addition, the memory 20 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some optional embodiments, the memory 20 may optionally include a memory remotely arranged relative to the processor 10, and these remote memories may be connected to the computer device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0181] The memory 20 may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a flash memory, a hard disk or a solid state drive; the memory 20 may also include a combination of the above types of memory.
[0182] The computer device further comprises a communication interface 30 for the computer device to communicate with other devices or a communication network.
[0183] The embodiment of the present invention also provides a computer-readable storage medium. The method according to the embodiment of the present invention can be implemented in hardware, firmware, or can be implemented as a computer code that can be recorded in a storage medium, or can be implemented as a computer code that is originally stored in a remote storage medium or a non-temporary machine-readable storage medium and will be stored in a local storage medium through a network download, so that the method described herein can be stored in such software processing on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. Among them, the storage medium can be a magnetic disk, an optical disk, a read-only storage memory, a random access memory, a flash memory, a hard disk or a solid-state hard disk, etc.; further, the storage medium can also include a combination of the above types of memories. It can be understood that a computer, a processor, a microprocessor controller, or programmable hardware includes a storage component that can store or receive software or computer code. When the software or computer code is accessed and executed by a computer, a processor, or hardware, the method shown in the above embodiment is implemented.
[0184] A part of the present invention may be applied as a computer program product, such as a computer program instruction, which, when executed by a computer, can call or provide the method and / or technical solution according to the present invention through the operation of the computer. Those skilled in the art should understand that the existence of the computer program instruction in a computer-readable medium includes, but is not limited to, a source file, an executable file, an installation package file, etc., and accordingly, the way in which the computer program instruction is executed by the computer includes, but is not limited to: the computer directly executes the instruction, or the computer compiles the instruction and then executes the corresponding compiled program, or the computer reads and executes the instruction, or the computer reads and installs the instruction and then executes the corresponding installed program. Here, the computer-readable medium may be any available computer-readable storage medium or communication medium accessible to the computer.
[0185] Although the embodiments of the present invention have been described in conjunction with the accompanying drawings, those skilled in the art may make various modifications and variations without departing from the spirit and scope of the present invention, and such modifications and variations are all within the scope defined by the appended claims.
Claims
1. A model verification method, characterized in that: The method comprises: Obtaining a verification model of the language model to be verified, wherein the verification model is used to demonstrate the operation result of the target level in the language model; Based on the verification model, a split operation is performed on the target weights in the target level, and input data is operated according to the split result to obtain an operation result to be verified; Obtain an expected operation result, and verify the operation result to be verified based on the expected operation result to obtain a verification result of the language model, wherein the expected calculation result is the operation result of the target layer in the language model performing the operation on the input data.
2. The method according to claim 1, characterized in that The expected operation result includes a first result vector, and the operation result to be verified includes a second result vector; The verifying the to-be-verified operation result based on the expected operation result to obtain the verification result of the language model includes: Calculating a difference between the first result vector and the second result vector; determining a test accuracy corresponding to the language model based on a ratio of the square of the difference to the first result; Obtaining an accuracy threshold, and determining whether the test accuracy exceeds the accuracy threshold; If not, determining that the verification result is that the splitting result meets the accuracy requirement of the language model, so as to perform the splitting operation on the target level in the language model; If so, it is determined that the verification result is that the splitting result does not meet the accuracy requirement of the language model, so as to adjust the splitting operation, and split the target weight in the verification model based on the adjusted splitting operation until the test accuracy corresponding to the verification model does not exceed the accuracy threshold.
3. The method according to claim 1, characterized in that The obtaining of the expected operation result includes: Based on the preset language, build a deep learning DL framework for the language model; Inputting the input data into the DL framework to obtain an output result of the DL framework; The expected operation result is determined according to the output result.
4. The method according to claim 1, wherein The target weight includes: a first weight and a second weight, wherein the first weight is the weight corresponding to each channel in the target level, and the second weight is the weight used for weighted calculation of the output of each channel; The splitting operation of the target weights in the target hierarchy based on the verification model includes: Based on the verification model, splitting the first weight according to a first preset direction to obtain first sub-weights; Based on the verification model, the second weight is split according to a second preset direction to obtain second sub-weights, wherein the splitting directions corresponding to the first preset direction and the second preset direction are different.
5. The method according to claim 4, characterized in that The first weight includes a query vector weight, a key vector weight, and a value vector weight, wherein the query vector weight is used to indicate the vector of the obtained query keyword, the key vector weight is used to indicate the vector of the matching tag corresponding to the query keyword, and the value vector weight is used to indicate the vector of the query result corresponding to the matching tag.
6. The method according to claim 4, characterized in that The splitting result includes the first sub-weight and the second sub-weight; The step of performing operations on the input data according to the splitting result to obtain the operation result to be verified includes: Allocating the first sub-weights to first computing nodes corresponding to respective channels, respectively, to perform parallel computing on the input data and weighted computing results of the first sub-weights; The weighted operation result to be weighted is calculated in parallel based on the second sub-weight to obtain the operation result to be verified.
7. The method according to claim 6, characterized in that The method further comprises: Saving the weighted calculation result and the verification calculation result as a file in a preset format; When it is determined based on the verification result that the splitting result does not meet the accuracy requirement of the language model, the preset format file is analyzed to obtain an analysis report, so as to adjust the splitting operation based on the analysis report.
8. A model verification device, characterized in that: The device comprises: an acquisition module, configured to acquire a verification model of the language model to be verified, wherein the verification model is used to demonstrate a calculation result of a target level in the language model; A calculation module, configured to perform a splitting operation on the target weights in the target hierarchy based on the verification model, and perform calculations on the input data according to the splitting results to obtain a calculation result to be verified; A verification module is used to obtain an expected operation result and verify the operation result to be verified based on the expected operation result to obtain a verification result of the language model, wherein the expected calculation result is the operation result of the target layer in the language model performing the operation on the input data.
9. A computer device, characterized in that: include: A memory and a processor, wherein the memory and the processor are communicatively connected to each other, the memory stores computer instructions, and the processor executes the model verification method according to any one of claims 1 to 7 by executing the computer instructions.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a computer to execute the model verification method according to any one of claims 1 to 7.
Citation Information
Cited By
Tensor splitting result verification method and device, computer equipment and storage medium
CN119357541A
