Large language model processing method and device, computer equipment, readable storage medium and program product
By identifying the safe activation parameters and updating weights in large language models, the problem of building or expanding risk data sets is solved, the security performance and robustness of the model are improved, and the stability and long-term reliability of the model in practical applications are ensured.
Patent Information
- Application Number
- CN202411700293.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-26
- Publication Date
- 2025-03-07
AI Technical Summary
The existing technology is difficult to build or expand risk data sets through large language models, making it difficult to detect and repair security vulnerabilities, and there is a risk of information leakage, data tampering and service interruption.
By identifying the safe activation parameters in the large language model, using preset multiple sets of risk data for processing, recording the current gradient slice, and identifying effective data based on the similarity of the gradient slice to form a data training set. The large language model is then fine-tuned in low rank, updated the weight of the safe activation parameters, and adjusted the model parameters to expand the risk data set.
It effectively improves the security performance of large language models, enhances the ability to detect and repair security vulnerabilities, ensures the robustness and stability of the model, and avoids the deterioration of generation capabilities.
Smart Images

Figure CN119577450A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of natural language processing, and in particular to a method, apparatus, computer device, computer-readable storage medium and computer program product for processing a large language model. Background Art
[0002] With the development of computer technology, large language models with high intelligence have emerged. These models can respond to various questions input by people, but they are also accompanied by security vulnerabilities. Security vulnerabilities can lead to serious problems such as information leakage, data tampering, and service interruption, posing great security threats.
[0003] With regard to large language models, it is difficult to construct or expand risk data sets through large language models with current technology. Summary of the invention
[0004] Based on this, it is necessary to provide a large language model processing method, apparatus, computer equipment, computer-readable storage medium and computer program product to address the above technical issues.
[0005] In a first aspect, the present application provides a method for processing a large language model, comprising:
[0006] Using data pair samples to identify safe activation parameters in a large language model to be processed; the data pair samples include paired normal data samples and abnormal data samples;
[0007] Inputting a plurality of preset risk data sets into the large language model for processing, and recording the current gradient slice corresponding to the security activation parameter after the large language model processing is completed;
[0008] Obtaining the similarity between the current gradient slice and the abnormal gradient slice, and identifying valid data from multiple groups of risk data according to the similarity to obtain a data training set; the abnormal gradient slice is a gradient slice corresponding to the abnormal data sample;
[0009] According to the data training set, low-rank fine-tuning is performed on the large language model to obtain fine-tuning parameters;
[0010] Based on the fine-tuning parameter and the security activation parameter, the original weight of the security activation parameter is updated to obtain the updated weight, and the model parameter of the large language model is adjusted according to the updated weight; the adjusted large language model is used to expand the risk data set.
[0011] In one embodiment, the step of using the data to identify the safe activation parameters in the large language model to be processed includes:
[0012] According to the normal data sample and the abnormal data sample, a normal gradient slice and an abnormal gradient slice are determined respectively; a weighted average is performed on the normal gradient slice and the abnormal gradient slice to obtain a reference gradient slice; based on the normal gradient slice, the abnormal gradient slice and the reference gradient slice, the safety activation parameter is identified.
[0013] In one embodiment, the identifying the safety activation parameter based on the normal gradient slice, the abnormal gradient slice and the reference gradient slice comprises:
[0014] Determine a first similarity between the normal gradient slice and the reference gradient slice, and a second similarity between the abnormal gradient slice and the reference gradient slice; obtain a similarity difference between the first similarity and the second similarity, and determine a first similarity threshold condition according to the similarity difference; determine a target gradient slice that meets the first similarity threshold condition among the normal gradient slice and the abnormal gradient slice, and obtain a parameter corresponding to the target gradient slice as the safety activation parameter.
[0015] In one embodiment, the low-rank fine-tuning of the large language model according to the data training set to obtain the fine-tuning parameters includes:
[0016] An initial low-rank matrix is obtained, and the initial low-rank matrix is trained according to the data training set to obtain a target low-rank matrix; the target low-rank matrix is multiplied and superimposed on the original parameters of the large language model to obtain the fine-tuning parameters.
[0017] In one embodiment, the updating the original weight of the security activation parameter based on the fine-tuning parameter and the security activation parameter to obtain the updated weight includes:
[0018] When the safety activation parameter meets the parameter threshold condition, the sum of the original weight and the fine-tuning parameter is used as the updated weight; when the safety activation parameter does not meet the parameter threshold condition, the original weight is used as the updated weight.
[0019] In one embodiment, identifying valid data from multiple groups of risk data based on the similarity to obtain a data training set includes:
[0020] Determine whether the similarity meets a second similarity threshold condition to obtain a determination result; identify the valid data from the multiple groups of risk data based on the determination result, and use a preset number of the valid data as the data training set.
[0021] In a second aspect, the present application also provides a large language model processing device, including:
[0022] A parameter identification module, used to identify safe activation parameters in a large language model to be processed using data pair samples; the data pair samples include paired normal data samples and abnormal data samples;
[0023] A model processing module, used for inputting a plurality of preset risk data sets into the large language model for processing, and recording the current gradient slice corresponding to the security activation parameter after the large language model processing is completed;
[0024] A data identification module is used to obtain the similarity between the current gradient slice and the abnormal gradient slice, and identify valid data from multiple groups of risk data according to the similarity to obtain a data training set; the abnormal gradient slice is the gradient slice corresponding to the abnormal data sample;
[0025] A low-rank fine-tuning module, used to perform low-rank fine-tuning on the large language model according to the data training set to obtain fine-tuning parameters;
[0026] A weight updating module is used to update the original weight of the security activation parameter based on the fine-tuning parameter and the security activation parameter to obtain an updated weight, and adjust the model parameters of the large language model according to the updated weight; the adjusted large language model is used to expand the risk data set.
[0027] In a third aspect, the present application further provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0028] The security activation parameters in the large language model to be processed are identified by using data pair samples; the data pair samples include paired normal data samples and abnormal data samples; multiple preset groups of risk data are input into the large language model for processing, and the current gradient slices corresponding to the security activation parameters are recorded after the large language model is processed; the similarity between the current gradient slice and the abnormal gradient slice is obtained, and according to the similarity, valid data is identified in multiple groups of risk data to obtain a data training set; the abnormal gradient slice is a gradient slice corresponding to the abnormal data sample; according to the data training set, the large language model is low-rank fine-tuned to obtain fine-tuning parameters; based on the fine-tuning parameters and the security activation parameters, the original weights of the security activation parameters are updated to obtain updated weights, and the model parameters of the large language model are adjusted according to the updated weights; the adjusted large language model is used to expand the risk data set.
[0029] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein when the computer program is executed by a processor, the following steps are implemented:
[0030] The security activation parameters in the large language model to be processed are identified by using data pair samples; the data pair samples include paired normal data samples and abnormal data samples; multiple preset groups of risk data are input into the large language model for processing, and the current gradient slices corresponding to the security activation parameters are recorded after the large language model is processed; the similarity between the current gradient slice and the abnormal gradient slice is obtained, and according to the similarity, valid data is identified in multiple groups of risk data to obtain a data training set; the abnormal gradient slice is a gradient slice corresponding to the abnormal data sample; according to the data training set, the large language model is low-rank fine-tuned to obtain fine-tuning parameters; based on the fine-tuning parameters and the security activation parameters, the original weights of the security activation parameters are updated to obtain updated weights, and the model parameters of the large language model are adjusted according to the updated weights; the adjusted large language model is used to expand the risk data set.
[0031] In a fifth aspect, the present application further provides a computer program product, including a computer program, which implements the following steps when executed by a processor:
[0032] The security activation parameters in the large language model to be processed are identified by using data pair samples; the data pair samples include paired normal data samples and abnormal data samples; multiple preset groups of risk data are input into the large language model for processing, and the current gradient slices corresponding to the security activation parameters are recorded after the large language model is processed; the similarity between the current gradient slice and the abnormal gradient slice is obtained, and according to the similarity, valid data is identified in multiple groups of risk data to obtain a data training set; the abnormal gradient slice is a gradient slice corresponding to the abnormal data sample; according to the data training set, the large language model is low-rank fine-tuned to obtain fine-tuning parameters; based on the fine-tuning parameters and the security activation parameters, the original weights of the security activation parameters are updated to obtain updated weights, and the model parameters of the large language model are adjusted according to the updated weights; the adjusted large language model is used to expand the risk data set.
[0033] The above-mentioned large language model processing method, device, computer equipment, computer-readable storage medium and computer program product, by using data to identify the security activation parameters in the large language model to be processed and obtaining the current gradient slice corresponding to the security activation parameter, then extracting valid data from multiple groups of risk data according to the similarity between the current gradient slice and the abnormal gradient slice, to obtain a data training set, and then based on the data training set, the large language model is low-rank fine-tuned, and then based on the fine-tuning parameters and the security activation parameters, the original weights of the security activation parameters are updated, and finally the model parameters of the large language model are adjusted according to the updated weights. The adjusted large language model can be used to generate risk data to expand the risk data set, so as to train small models or construct a risk database, and can also avoid the degradation of the original generation ability of the large language model, which is helpful to promote the development of related security protection technologies, and is also conducive to efficiently and accurately detecting security vulnerabilities in the large language model, timely and comprehensive repair of security vulnerabilities, effectively improving the security performance of the large language model, and at the same time ensuring the robustness of the large language model, which helps to ensure the stability and long-term reliability of the large language model in practical applications. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the technical solutions in the embodiments of the present application or related technologies, the drawings required for use in the embodiments of the present application or related technical descriptions will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0035] Figure 1 An application environment diagram of a method for processing a large language model in one embodiment;
[0036] Figure 2 is a flowchart of a method for processing a large language model in one embodiment;
[0037] Figure 3 A schematic diagram of a process of obtaining security activation parameters in one embodiment;
[0038] Figure 4 A schematic diagram of a flow chart of a step of obtaining security activation parameters in another embodiment;
[0039] Figure 5 It is a flowchart of a method for processing a large language model in a specific embodiment;
[0040] Figure 6 is a structural block diagram of a processing device for a large language model in one embodiment;
[0041] Figure 7FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0043] The large language model processing method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown, the terminal communicates with the server through the network. The data storage system can store the data that the server needs to process. The data storage system can be integrated on the server or placed on the cloud or other network servers.
[0044] Specifically, the large language model processing method provided in the embodiment of the present application can be executed by a server.
[0045] Exemplarily, the server uses data pair samples to identify the security activation parameters in the large language model to be processed; the data pair samples include paired normal data samples and abnormal data samples; the server inputs multiple preset groups of risk data into the large language model for processing, and records the current gradient slices corresponding to the security activation parameters after the large language model is processed; the server obtains the similarity between the current gradient slice and the abnormal gradient slice, and identifies valid data in multiple groups of risk data based on the similarity to obtain a data training set; the abnormal gradient slice is the gradient slice corresponding to the abnormal data sample; the server performs low-rank fine-tuning on the large language model based on the data training set to obtain fine-tuning parameters; the server updates the original weights of the security activation parameters based on the fine-tuning parameters and the security activation parameters to obtain updated weights, and adjusts the model parameters of the large language model based on the updated weights; the adjusted large language model is used to expand the risk data set.
[0046] In such Figure 1 In the application environment shown, the terminal can be, but is not limited to, various personal computers, notebook computers, smart phones, and tablet computers. The server can be implemented as an independent server or a server cluster consisting of multiple servers.
[0047] In one embodiment, Figure 2 As shown, a method for processing a large language model is provided, and the method is applied to Figure 1 The server in the example is used to illustrate the following steps:
[0048] Step S201, using data pair samples to identify safe activation parameters in a large language model to be processed; the data pair samples include paired normal data samples and abnormal data samples.
[0049] Among them, large language models refer to large-scale neural network models trained by deep learning algorithms, which are specifically used to process and generate natural language text. Such models are trained with large amounts of text data and can understand and generate language, completing a variety of language processing tasks from text generation, translation to question and answer and text summarization.
[0050] Among them, the normal data sample can be a sample composed of safe data, and the abnormal data sample can be a sample composed of risk data.
[0051] The security activation parameter may be a parameter corresponding to a gradient slice whose similarity difference is greater than 1 among all gradient slices.
[0052] Specifically, the server obtains a large language model to be processed, inputs a data pair sample including 10 normal data samples and 10 abnormal data samples into the large language model, detects gradient changes in model parameters, and thereby identifies safe activation parameters in the large language model.
[0053] Step S202: input the preset multiple groups of risk data into the large language model for processing, and record the current gradient slice corresponding to the safety activation parameter after the large language model processing is completed.
[0054] Among them, risk data can be various data related to risk management, which are used to identify, evaluate, analyze and respond to potential risks.
[0055] Among them, the current gradient slice can be a vector, which represents the rate of change of the function at a certain point. For neural networks, the gradient is the partial derivative of the loss function with respect to the model parameters, reflecting the speed of change of the loss function in each parameter direction.
[0056] Specifically, the server inputs multiple preset sets of risk data into the large language model for processing, and obtains reply information generated by the large language model. In order to efficiently identify the data that the large model refuses to answer, the server records the current gradient slice corresponding to the security activation parameter after each large model processes the input information.
[0057] Step S203, obtaining the similarity between the current gradient slice and the abnormal gradient slice, and identifying valid data from multiple groups of risk data according to the similarity as a data training set; the abnormal gradient slice is the gradient slice corresponding to the abnormal data.
[0058] Specifically, the server calculates the similarity between the current gradient slice and the abnormal gradient slice of the abnormal data. When the similarity exceeds 0.25, it is marked as valid data. A total of 1,000 valid data are collected as the data training set.
[0059] Step S204: performing low-rank fine-tuning on the large language model according to the data training set to obtain fine-tuning parameters.
[0060] Among them, low-rank fine-tuning is a technology for efficient fine-tuning based on pre-trained models, especially for large-scale models. This technology approximates the original matrix by decomposing the original weight matrix into the product of two low-rank matrices. This decomposition method allows us to only train these low-rank matrices instead of the entire weight matrix. This can significantly reduce the computing resources required for fine-tuning while maintaining good performance.
[0061] Specifically, the server obtains an initial low-rank matrix, trains the initial low-rank matrix according to the data training set and does not update the original parameters during the training process to obtain a target low-rank matrix. When the training is completed, the target low-rank matrix is multiplied and superimposed on the original parameters of the large language model to complete the parameter update and obtain the fine-tuning parameters.
[0062] Step S205 , based on the fine-tuning parameters and the safe activation parameters, the original weights of the safe activation parameters are updated to obtain updated weights, and the model parameters of the large language model are adjusted according to the updated weights.
[0063] Specifically, assuming the original weights are , the fine-tuning parameters obtained by low-rank fine-tuning are , then the updated weight is , and adjust the model parameters of the large language model according to the updated weights. The adjusted large language model can be used to generate risk data to expand the risk data set in order to train the small model or construct a risk database.
[0064] The above-mentioned processing method of the large language model uses data to identify the security activation parameters in the large language model to be processed and obtains the current gradient slice corresponding to the security activation parameter, and then extracts valid data from multiple groups of risk data according to the similarity between the current gradient slice and the abnormal gradient slice to obtain a data training set, and then performs low-rank fine-tuning on the large language model according to the data training set, and then updates the original weights of the security activation parameters based on the fine-tuning parameters and the security activation parameters. Finally, the model parameters of the large language model are adjusted according to the updated weights. The adjusted large language model can be used to generate risk data to expand the risk data set so as to train small models or construct a risk database. It can also avoid the degradation of the original generation ability of the large language model, which is helpful to promote the development of related security protection technologies, and is also conducive to efficiently and accurately detecting security vulnerabilities in the large language model, and timely and comprehensively repairing the security vulnerabilities, effectively improving the security performance of the large language model, while also ensuring the robustness of the large language model, which helps to ensure the stability and long-term reliability of the large language model in practical applications.
[0065] In one embodiment, if Figure 3 As shown, in the above step S201, using data to identify the sample to identify the safe activation parameters in the large language model to be processed, specifically includes the following steps:
[0066] Step S301 : determining normal gradient slices and abnormal gradient slices according to normal data samples and abnormal data samples respectively.
[0067] Step S302: performing weighted averaging on the normal gradient slices and the abnormal gradient slices to obtain a reference gradient slice.
[0068] Step S303: identifying safety activation parameters based on the normal gradient slices, the abnormal gradient slices and the reference gradient slices.
[0069] Specifically, the server determines normal gradient slices and abnormal gradient slices according to normal data samples and abnormal data samples, respectively; performs weighted averaging on the normal gradient slices and the abnormal gradient slices to obtain reference gradient slices; and identifies safety activation parameters based on the normal gradient slices, the abnormal gradient slices and the reference gradient slices.
[0070] In this embodiment, calculation is performed based on parameters such as normal gradient slices, abnormal gradient slices, and reference gradient slices, so as to quickly and accurately identify safety activation parameters.
[0071] In one embodiment, if Figure 4 As shown, in the above step S303, based on the normal gradient slice, the abnormal gradient slice and the reference gradient slice, the safety activation parameter is identified, which specifically includes the following steps:
[0072] Determine a first similarity between a normal gradient slice and a reference gradient slice, and a second similarity between an abnormal gradient slice and the reference gradient slice; obtain a similarity difference between the first similarity and the second similarity, and determine a first similarity threshold condition according to the similarity difference; determine a target gradient slice that meets the first similarity threshold condition in the normal gradient slice and the abnormal gradient slice, and obtain parameters corresponding to the target gradient slice as security activation parameters.
[0073] The first similarity threshold condition may be that the similarity difference is greater than 1.
[0074] Specifically, the server determines a first similarity between a normal gradient slice and a reference gradient slice, and a second similarity between an abnormal gradient slice and a reference gradient slice; obtains a similarity difference between the first similarity and the second similarity, and determines a first similarity threshold condition based on the similarity difference; in normal gradient slices and abnormal gradient slices, a parameter corresponding to a gradient slice whose similarity difference is greater than 1 is a security activation parameter.
[0075] In one embodiment, in the above step S204, low-rank fine-tuning is performed on the large language model according to the data training set to obtain fine-tuning parameters, which specifically includes the following steps:
[0076] An initial low-rank matrix is obtained, and the initial low-rank matrix is trained according to the data training set to obtain a target low-rank matrix; the target low-rank matrix is multiplied and superimposed on the original parameters of the large language model to obtain fine-tuning parameters.
[0077] Among them, a low-rank matrix refers to a matrix with a relatively small rank. The rank of a matrix represents the maximum number of independent rows or columns in the matrix. Simply put, it is the number of linearly independent rows or columns in the matrix. The smaller the rank, the simpler the structure of the matrix.
[0078] Specifically, the server obtains an initial low-rank matrix and trains the initial low-rank matrix according to the data training set. During the training process, the original parameters are not updated, but the two matrices are trained. When the training is completed, the two low-rank matrices are multiplied and superimposed on the original parameters to complete the parameter update, thereby quickly and accurately obtaining the fine-tuning parameters.
[0079] In one embodiment, in the above step S205, based on the fine-tuning parameter and the security activation parameter, the original weight of the security activation parameter is updated to obtain the updated weight, which specifically includes the following steps:
[0080] When the safety activation parameter meets the parameter threshold condition, the sum of the original weight and the fine-tuning parameter is used as the updated weight; when the safety activation parameter does not meet the parameter threshold condition, the original weight is used as the updated weight.
[0081] Among them, satisfying the parameter threshold condition can be a safe activation parameter , failure to meet the parameter threshold condition may be a safety activation parameter .
[0082] Specifically, the server determines whether the security activation parameter meets the parameter threshold condition based on the obtained security activation parameter, and updates the security activation parameter weight accordingly according to the determination result:
[0083]
[0084] In the above formula, is the updated weight, To fine-tune the parameters, is the original weight.
[0085] In one embodiment, in the above step S203, valid data is identified from multiple groups of risk data according to similarity as a data training set, which specifically includes the following steps:
[0086] It is determined whether the similarity meets the second similarity threshold condition to obtain a determination result; based on the determination result, valid data is identified from multiple sets of risk data, and a preset number of valid data is used as a data training set.
[0087] The second similarity threshold condition may be that the similarity exceeds 0.25.
[0088] Specifically, the server calculates the similarity between the current gradient slice and the abnormal gradient slice of the abnormal data. When the similarity exceeds 0.25, it is marked as valid data. A total of 1,000 valid data are collected as the data training set, which effectively ensures the quantity and quality of the data training set.
[0089] In one embodiment, Figure 5 As shown, a method for processing a large language model in a specific embodiment is provided, which specifically includes the following steps:
[0090] Step S501, obtaining a large language model to be processed, and determining normal gradient slices and abnormal gradient slices according to normal data samples and abnormal data samples respectively; performing weighted averaging on the normal gradient slices and the abnormal gradient slices to obtain reference gradient slices.
[0091] Step S502, determining a first similarity between a normal gradient slice and a reference gradient slice, and a second similarity between an abnormal gradient slice and a reference gradient slice; obtaining a similarity difference between the first similarity and the second similarity, and determining a similarity threshold condition according to the similarity difference; determining a target gradient slice that meets the first similarity threshold condition among the normal gradient slice and the abnormal gradient slice, and obtaining parameters corresponding to the target gradient slice as security activation parameters in the large language model.
[0092] Step S503, obtaining the similarity between the current gradient slice and the abnormal gradient slice, judging whether the similarity meets the second similarity threshold condition, and obtaining a judgment result; according to the judgment result, identifying valid data in multiple groups of risk data, and taking a preset number of valid data as a data training set.
[0093] Step S504, obtaining an initial low-rank matrix, training the initial low-rank matrix according to the data training set, and obtaining a target low-rank matrix; multiplying the target low-rank matrix and superimposing it on the original parameters of the large language model to obtain fine-tuning parameters.
[0094] Step S505: When the security activation parameter meets the parameter threshold condition, the sum of the original weight and the fine-tuning parameter is used as the updated weight; when the security activation parameter does not meet the parameter threshold condition, the original weight is used as the updated weight, and the model parameters of the large language model are adjusted according to the updated weight; the adjusted large language model is used to expand the risk data set.
[0095] The beneficial effects brought by the above embodiments are as follows:
[0096] This application can use the adjusted large language model to generate risk data to expand the risk data set in order to train small models or construct a risk database. It can also avoid the degradation of the original generation capability of the large language model, help promote the development of related security protection technologies, and also help to efficiently and accurately detect security vulnerabilities in the large language model, and promptly and comprehensively repair the security vulnerabilities, effectively improve the security performance of the large language model, and at the same time ensure the robustness of the large language model, which helps to ensure the stability and long-term reliability of the large language model in practical applications.
[0097] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0098] Based on the same inventive concept, the embodiment of the present application also provides a large language model processing device for implementing the large language model processing method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the one or more large language model processing device embodiments provided below can refer to the limitations of the large language model processing method above, and will not be repeated here.
[0099] In an exemplary embodiment, Figure 6 As shown, a processing device for a large language model is provided, comprising:
[0100] The parameter identification module 601 is used to identify the safe activation parameters in the large language model to be processed by using the data pair samples; the data pair samples include paired normal data samples and abnormal data samples;
[0101] The model processing module 602 is used to input the preset multiple sets of risk data into the large language model for processing, and record the current gradient slice corresponding to the safety activation parameter after the large language model processing is completed;
[0102] The data identification module 603 is used to obtain the similarity between the current gradient slice and the abnormal gradient slice, and identify the valid data in the multiple risk data groups according to the similarity to obtain the data training set; the abnormal gradient slice is the gradient slice corresponding to the abnormal data sample;
[0103] A low-rank fine-tuning module 604 is used to perform low-rank fine-tuning on the large language model according to the data training set to obtain fine-tuning parameters;
[0104] The weight updating module 605 is used to update the original weight of the security activation parameter based on the fine-tuning parameter and the security activation parameter to obtain the updated weight, and adjust the model parameters of the large language model according to the updated weight; the adjusted large language model is used to expand the risk data set.
[0105] In one embodiment, the parameter identification module 601 is also used to determine normal gradient slices and abnormal gradient slices according to normal data samples and abnormal data samples, respectively; perform weighted averaging on the normal gradient slices and the abnormal gradient slices to obtain reference gradient slices; and identify safety activation parameters based on the normal gradient slices, the abnormal gradient slices and the reference gradient slices.
[0106] In one embodiment, the parameter identification module 601 is further used to determine a first similarity between a normal gradient slice and a reference gradient slice, and a second similarity between an abnormal gradient slice and a reference gradient slice; obtain a similarity difference between the first similarity and the second similarity, and determine a first similarity threshold condition according to the similarity difference; determine a target gradient slice that meets the first similarity threshold condition among the normal gradient slice and the abnormal gradient slice, and obtain parameters corresponding to the target gradient slice as safety activation parameters.
[0107] In one embodiment, the low-rank fine-tuning module 604 is also used to obtain an initial low-rank matrix, train the initial low-rank matrix according to a data training set, and obtain a target low-rank matrix; multiply the target low-rank matrix and superimpose it on the original parameters of the large language model to obtain fine-tuning parameters.
[0108] In one embodiment, the weight updating module 605 is further configured to use the sum of the original weight and the fine-tuning parameter as the updated weight when the safety activation parameter meets the parameter threshold condition; and use the original weight as the updated weight when the safety activation parameter does not meet the parameter threshold condition.
[0109] In one embodiment, the data identification module 603 is also used to determine whether the similarity meets the second similarity threshold condition to obtain a determination result; based on the determination result, valid data is identified from multiple sets of risk data, and a preset number of valid data is used as a data training set.
[0110] Each module in the processing device of the above-mentioned large language model can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.
[0111] In an exemplary embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as shown in FIG. Figure 7 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. Among them, the processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store normal data and abnormal data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a processing method for a large language model is implemented.
[0112] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0113] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0114] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0115] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0116] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0117] A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile memory and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, an artificial intelligence (AI) processor, etc., but are not limited to this.
[0118] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this application.
[0119] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A method for processing a large language model, characterized in that: The method comprises: Using data pair samples to identify safe activation parameters in a large language model to be processed; the data pair samples include paired normal data samples and abnormal data samples; Inputting a plurality of preset risk data sets into the large language model for processing, and recording the current gradient slice corresponding to the security activation parameter after the large language model processing is completed; Obtaining the similarity between the current gradient slice and the abnormal gradient slice, and identifying valid data from multiple groups of risk data according to the similarity to obtain a data training set; the abnormal gradient slice is a gradient slice corresponding to the abnormal data sample; According to the data training set, low-rank fine-tuning is performed on the large language model to obtain fine-tuning parameters; Based on the fine-tuning parameter and the security activation parameter, the original weight of the security activation parameter is updated to obtain the updated weight, and the model parameter of the large language model is adjusted according to the updated weight; the adjusted large language model is used to expand the risk data set.
2. The method according to claim 1, characterized in that The method of using data to identify safe activation parameters in a large language model to be processed includes: Determine a normal gradient slice and an abnormal gradient slice according to the normal data sample and the abnormal data sample respectively; Performing weighted averaging on the normal gradient slice and the abnormal gradient slice to obtain a reference gradient slice; The safety activation parameter is identified based on the normal gradient slice, the abnormal gradient slice, and the reference gradient slice.
3. The method according to claim 2, characterized in that The identifying the safety activation parameter based on the normal gradient slice, the abnormal gradient slice and the reference gradient slice comprises: Determining a first similarity between the normal gradient slice and the reference gradient slice, and a second similarity between the abnormal gradient slice and the reference gradient slice; Obtaining a similarity difference between the first similarity and the second similarity, and determining a first similarity threshold condition according to the similarity difference; Among the normal gradient slices and the abnormal gradient slices, a target gradient slice that meets the first similarity threshold condition is determined, and a parameter corresponding to the target gradient slice is acquired as the safety activation parameter.
4. The method according to claim 1, characterized in that The step of performing low-rank fine-tuning on the large language model according to the data training set to obtain fine-tuning parameters includes: Obtaining an initial low-rank matrix, and training the initial low-rank matrix according to the data training set to obtain a target low-rank matrix; The target low-rank matrix is multiplied and superimposed on the original parameters of the large language model to obtain the fine-tuning parameters.
5. The method according to claim 1, characterized in that The updating of the original weight of the safety activation parameter based on the fine-tuning parameter and the safety activation parameter to obtain the updated weight includes: When the safety activation parameter satisfies a parameter threshold condition, taking the sum of the original weight and the fine-tuning parameter as the updated weight; When the security activation parameter does not meet the parameter threshold condition, the original weight is used as the updated weight.
6. The method according to any one of claims 1 to 5, characterized in that: The step of identifying valid data from the plurality of risk data groups according to the similarity to obtain a data training set includes: Determine whether the similarity meets a second similarity threshold condition, and obtain a determination result; According to the judgment result, the valid data is identified from the multiple groups of risk data, and a preset number of the valid data is used as the data training set.
7. A processing device for a large language model, characterized in that: The device comprises: A parameter identification module, used to identify safe activation parameters in a large language model to be processed using data pair samples; the data pair samples include paired normal data samples and abnormal data samples; A model processing module, used for inputting a plurality of preset risk data sets into the large language model for processing, and recording the current gradient slice corresponding to the security activation parameter after the large language model processing is completed; A data identification module is used to obtain the similarity between the current gradient slice and the abnormal gradient slice, and identify valid data from multiple groups of risk data according to the similarity to obtain a data training set; the abnormal gradient slice is the gradient slice corresponding to the abnormal data sample; A low-rank fine-tuning module, used to perform low-rank fine-tuning on the large language model according to the data training set to obtain fine-tuning parameters; A weight updating module is used to update the original weight of the security activation parameter based on the fine-tuning parameter and the security activation parameter to obtain an updated weight, and adjust the model parameters of the large language model according to the updated weight; the adjusted large language model is used to expand the risk data set.
8. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 6 are implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 6 are implemented.
Citation Information
Cited By
Text large language model fine tuning method and device, equipment and storage medium
CN121189426A