Model processing method and device, equipment and storage medium

By perturbing and adjusting the weights of the MLP layers in the model, key MLP layers are identified, which solves the problem of high computational resource and time consumption in existing technologies, improves model processing efficiency and accuracy, and supports secure deployment of model editing.

CN121599015APending Publication Date: 2026-03-03TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411157454.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-21
Publication Date
2026-03-03

AI Technical Summary

Technical Problem

Existing technologies require significant computational resources and time to identify key multilayer perceptron (MLP) layers in a model, resulting in low model processing efficiency.

Method used

By perturbing each MLP layer in the model, the model loss is determined using the perturbed output and the labels of the training data, and the perturbing weights are adjusted based on the model loss to identify key MLP layers.

Benefits of technology

It achieves efficient identification of key MLP layers, improves the efficiency and accuracy of model processing, and supports secure and reliable deployment of model editing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121599015A_ABST
    Figure CN121599015A_ABST
Patent Text Reader

Abstract

The invention provides a model processing method and device, equipment and a storage medium, which can be applied to scenes such as model editing. The method comprises the following steps: inputting training data into a first model, and disturbing each MLP layer based on disturbance weights corresponding to N MLP layers included in the first model to obtain an output result of the disturbed first model; determining the model loss of the disturbed first model based on the output result of the disturbed first model and the label of the training data; based on the model loss, performing training adjustment on the disturbance weights corresponding to the N MLP layers to obtain target disturbance weights corresponding to the N MLP layers; and based on the target disturbance weights corresponding to the N MLP layers, determining K key MLP layers from the N MLP layers. According to the method, the disturbance weight corresponding to each MLP layer is trained to encourage the disturbed first model to keep enough information, so that the recognition efficiency of the key MLP layer is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of computer technology, and in particular to a model processing method, apparatus, device, and storage medium. Background Technology

[0002] With the rapid development of artificial intelligence technology, various large-scale models have emerged. While these models possess strong data processing capabilities, they also place high demands on computation. Consequently, model editing has been proposed. The purpose of model editing can be understood as modifying the internal structure of a model without affecting its output results. In some cases, model editing requires the pre-identification and localization of key multilayer perceptrons (MLPs) within the model.

[0003] Current methods for identifying critical MLPs in a model primarily involve iteratively replacing the output information of each MLP layer in the model to assess the impact of the replaced MLP layer on task performance. For example, if replacing a particular MLP layer significantly impacts task performance, then that MLP layer is identified as a critical MLP layer. However, this method requires substantial computational resources and time, resulting in low model processing efficiency. Summary of the Invention

[0004] This application provides a model processing method, apparatus, device, and storage medium that can improve the efficiency of model processing and has low cost.

[0005] Firstly, this application provides a model processing method, including:

[0006] Acquire training data and the labels of the training data, and input the training data into a pre-trained first model, the first model comprising N multilayer perceptron (MLP) layers, where N is a positive integer greater than 1;

[0007] For each of the N MLP layers, the MLP layer is perturbed based on the perturbation weights corresponding to the MLP layer to obtain the output result of the perturbed first model;

[0008] Based on the output of the perturbated first model and the labels of the training data, the model loss of the perturbated first model is determined, and based on the model loss of the perturbated first model, the perturbation weights corresponding to the N MLP layers are trained and adjusted to obtain the target perturbation weights corresponding to the N MLP layers.

[0009] Based on the target perturbation weights corresponding to the N MLP layers, K key MLP layers are determined from the N MLP layers, where K is a positive integer less than N.

[0010] Secondly, this application provides a model processing apparatus, comprising:

[0011] An acquisition unit is used to acquire training data and the labels of the training data, and input the training data into a pre-trained first model, wherein the first model includes N multilayer perceptron (MLP) layers, where N is a positive integer;

[0012] The perturbation unit is used to perturb each of the N MLP layers based on the perturbation weights corresponding to the MLP layer, and obtain the output result of the perturbated first model.

[0013] The training unit is used to determine the model loss of the perturbed first model based on the output of the perturbed first model and the label of the training data, and to train and adjust the perturbation weights corresponding to the N MLP layers based on the model loss of the perturbed first model, so as to obtain the target perturbation weights corresponding to the N MLP layers respectively.

[0014] The selection unit is used to determine K key MLP layers from the N MLP layers based on the target perturbation weights corresponding to the N MLP layers respectively, where K is a positive integer less than N.

[0015] In some embodiments, the perturbation unit is specifically used to perturb the output information of the MLP layer based on the perturbation weights corresponding to the MLP layer, so as to obtain the output result of the perturbated first model.

[0016] In some embodiments, the perturbation unit is specifically configured to: obtain the output information of the i-th MLP layer among the N MLP layers, where i is a positive integer less than or equal to N; determine the perturbation noise value corresponding to the i-th MLP layer; and based on the perturbation noise value and the perturbation weight corresponding to the i-th MLP layer, perturb the output information of the i-th MLP layer to obtain the perturbation output information of the i-th MLP layer; input the perturbation output information of the i-th MLP layer into a module connected to the i-th MLP layer for processing, and execute sequentially to obtain the output result of the perturbated first model.

[0017] In some embodiments, the perturbation unit is specifically used to determine the mean and variance of the output information of the i-th MLP layer; determine the normal distribution of the output information of the i-th MLP layer based on the mean and variance of the output information of the i-th MLP layer; and randomly sample the normal distribution of the output information of the i-th MLP layer to obtain the perturbation noise value corresponding to the i-th MLP layer.

[0018] In some embodiments, the perturbation unit is specifically configured to multiply the output information of the i-th MLP layer with the perturbation weight corresponding to the i-th MLP layer to obtain a first product; multiply the value of the first data after subtracting the perturbation weight corresponding to the i-th MLP layer with the perturbation noise value to obtain a second product, wherein the first data is a positive integer; and determine the sum of the first product and the second product as the perturbation output information of the i-th MLP layer.

[0019] In some embodiments, the training unit is specifically configured to determine a first mutual information between the label of the training data and the output of the perturbed first model; determine a first loss of the perturbed first model based on the first mutual information; and determine a model loss of the perturbed first model based on the first loss.

[0020] In some embodiments, the training unit is specifically configured to determine the variational upper bound of the negative number of the first mutual information as the first loss.

[0021] In some embodiments, the training unit is specifically configured to process the training data using the first model to obtain the output of the first model; determine a second mutual information between the output of the first model and the output of the perturbed first model; determine a second loss of the first model based on the second mutual information; and determine the model loss of the perturbed first model based on the first loss and the second loss.

[0022] In some embodiments, the training unit is specifically configured to determine the variational upper bound of the second mutual information as the second loss.

[0023] In some embodiments, the training unit is specifically configured to determine the average value of the perturbation weights corresponding to the N MLP layers respectively; and to determine the model loss of the perturbated first model based on the first loss, the second loss and the average value of the perturbation weights.

[0024] In some embodiments, the training unit is specifically configured to multiply the second loss by the first hyperparameter to obtain a third product; multiply the average value of the perturbation weights by the second hyperparameter to obtain a fourth product; and determine the sum of the first loss, the third product, and the fourth product as the model loss of the perturbated first model.

[0025] In some embodiments, the adjustment unit is specifically configured to: train and adjust the perturbation weights corresponding to the N MLP layers based on the model loss of the perturbated first model, to obtain the adjusted perturbation weights corresponding to the N MLP layers; input the training data into the first model, and perturb the output information of each of the N MLP layers based on the adjusted perturbation weights corresponding to the N MLP layers included in the first model, to obtain the output result of the perturbated first model; determine the model loss of the perturbated first model based on the output result of the perturbated first model and the label of the training data; retrain and adjust the adjusted perturbation weights corresponding to the N MLP layers based on the model loss of the perturbated first model, repeating the process to obtain the perturbation weights corresponding to the N MLP layers under the training data; and determine the target perturbation weights corresponding to the N MLP layers based on the perturbation weights corresponding to the N MLP layers under the training data.

[0026] In some embodiments, the adjustment unit is specifically used to determine the perturbation weights corresponding to the N MLP layers under P training data, wherein the P training data includes the training data and P is a positive integer of size 1; and to determine the target perturbation weights corresponding to the N MLP layers based on the perturbation weights corresponding to the N MLP layers under the P training data.

[0027] In some embodiments, the adjustment unit is specifically used to determine the average value of the perturbation weights corresponding to the j-th MLP layer under the P training data as the target perturbation weight corresponding to the j-th MLP layer, where j is a positive integer less than or equal to N.

[0028] In some embodiments, the selection unit is specifically used to determine the K key MLP layers with the largest target perturbation weights from the N MLP layers based on the target perturbation weights corresponding to the N MLP layers respectively.

[0029] In some embodiments, the adjustment unit is further configured to perform model editing on the first model based on the K key MLP layers in the first model to obtain a second model.

[0030] Thirdly, this application provides an electronic device including a processor and a memory. The memory is used to store a computer program, and the processor is used to call and run the computer program stored in the memory to perform the method described in the first aspect.

[0031] Fourthly, a chip is provided for implementing the methods of various implementations of the first aspect described above. Specifically, the chip includes a processor for retrieving and running a computer program from a memory, causing a device equipped with the chip to perform the methods of the first aspect described above.

[0032] Fifthly, a computer-readable storage medium is provided for storing a computer program that causes a computer to perform the method described in the first aspect.

[0033] In a sixth aspect, a computer program product is provided, including computer program instructions that cause a computer to perform the method described in the first aspect.

[0034] In a seventh aspect, a computer program is provided that, when run on a computer, causes the computer to perform the method described in the first aspect.

[0035] In summary, this application obtains training data and its labels, inputs the training data into a first model, and perturbs each of the N MLP layers based on the perturbation weights corresponding to the N MLP layers included in the first model, obtaining the output of the perturbated first model; based on the output of the perturbated first model and the labels of the training data, determines the model loss of the perturbated first model; based on the model loss of the perturbated first model, trains and adjusts the perturbation weights corresponding to the N MLP layers to obtain the target perturbation weights corresponding to the N MLP layers; based on the target perturbation weights corresponding to the N MLP layers, determines K key MLP layers from the N MLP layers. As can be seen from the above, the method of this application includes two stages: MLP layer perturbation and MLP layer selection. In the MLP layer perturbation stage, this application injects perturbations into the output information of each MLP layer in the first model, thereby creating a perturbated first model. Learnable perturbation weights are then used to control the perturbation amount of each MLP layer. By training the perturbation weights corresponding to each MLP layer, the perturbated first model is encouraged to maintain sufficient information. In the MLP layer selection stage, key MLP layers can be identified by observing the trained perturbation weights. This enables the global identification of the most informative key MLP layers in the first model, achieving accurate identification of key MLP layers and improving the identification efficiency. The method of this application provides a solution for key MLP layer localization in model editing operations. It can help model editing achieve more ideal goals and ensure that model editing methods are deployed and used safely and reliably. Attached Figure Description

[0036] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0037] Figure 1 A schematic diagram of an implementation environment for the model processing method provided in this application embodiment;

[0038] Figure 2 A schematic flowchart illustrating a model processing method provided in an embodiment of this application;

[0039] Figure 3 This is a schematic diagram of a network structure for the first model involved in this application;

[0040] Figure 4 This is a schematic diagram of the network structure of the MLP layer involved in the embodiments of this application;

[0041] Figure 5 A schematic diagram illustrating the addition of perturbations to the MLP layer;

[0042] Figure 6 This is a schematic diagram illustrating the correspondence between the output information of the MLP layer and the perturbation weights.

[0043] Figure 7 This is a schematic diagram of another network structure for the first model;

[0044] Figure 8 A schematic diagram for selecting key MLP layers from the first model;

[0045] Figure 9 This is a schematic flowchart of a model processing method provided in an embodiment of this application;

[0046] Figure 10 A schematic flowchart illustrating a model processing method provided in an embodiment of this application;

[0047] Figure 11 This is a schematic block diagram of a model processing apparatus provided in an embodiment of this application;

[0048] Figure 12 This is a schematic block diagram of the electronic device provided in the embodiments of this application. Detailed Implementation

[0049] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of this application.

[0050] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. In embodiments of the invention, "B corresponding to A" means that B is associated with A. In one implementation, B can be determined based on A. However, it should also be understood that determining B based on A does not mean determining B solely based on A; B can also be determined based on A and / or other information. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or server that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to these processes, methods, products, or devices. In the description of this application, unless otherwise stated, "a plurality of" means two or more.

[0051] The model processing method provided in this application can be applied to fields such as model editing and model recognition, and can improve model processing efficiency.

[0052] First, the relevant concepts involved in the model processing method provided in the embodiments of this application will be introduced.

[0053] In some embodiments, the first model of this application may include a Transformer module, which includes an encoder component and a decoder component. The encoder-decoder component includes multiple encoders, and the decoder component includes multiple decoders. Both the encoder and the decoder include attention layers. In some embodiments, the attention layer includes one or more attention heads.

[0054] In some embodiments, the first model of this application may include a Transformer module.

[0055] The Transformer module architecture is shown below:

[0056] Transformer module This indicates a sequence of tags. Mapping to a probability distribution The i-th label in layer l is embedded as a series of hidden state vectors. Where Z is the dimension of the hidden state vector. In B, the hidden state... The internal calculations can be summarized by the following formula:

[0057]

[0058] For each layer, it will come from the global attention of the previous layer. and local MLP layer The contributions are combined. Furthermore, the residual flow draws information from previous states. Each MLP layer is a matrix... and A parameterized two-layer neural network containing a modified nonlinear function σ and a normalized nonlinear function γ. For each individual attention head attn, it is composed of four weight matrices through parameterized hidden states. Four hidden state matrices, Q, K, V, and O, are obtained respectively. Among them, the Q and K matrices are used to calculate the attention matrix. Where d k It is the dimension of querying Q and key K. Used to scale the dot product result, while the O and V matrices determine the final content written into the residual stream.

[0059] Information bottlenecks achieve optimal data representation by maximizing the mutual information between data representation z and output y, while minimizing the mutual information between input x and representation z. This has broad applications in data compression, preserving the data's relevance to the target variable while compressing it. This makes data storage and transmission easier, while still enabling accurate analysis. It can also be applied in machine learning to improve the model's generalization ability. By using information bottlenecks, more robust features can be found that generalize better to new data.

[0060] The information bottleneck is based on mutual information, where I(X;Y) represents the mutual information between two random variables X and Y, as defined in formula (1):

[0061]

[0062] Where p(x) represents the probability of variable x, and p(y) represents the probability of variable y.

[0063] Given a variable X and its associated output Y, the information bottleneck aims to learn the minimum sufficient variable Z after information compression by optimizing the objective shown in the following formula (2):

[0064]

[0065] Here, α is a Lagrange multiplier used to balance the two terms. The first term encourages Z to include information about the output Y, while the second term minimizes the mutual information between X and Z, ensuring that Z receives only limited information from the variable X.

[0066] With the rapid development of artificial intelligence technology, various large-scale models have emerged, such as language models. Language models have demonstrated significant capabilities in fields such as generative dialogue and natural language translation. Since these models are widely used in various high-impact software products, understanding and predicting the behavior of these advanced models has become crucial to ensuring their safe and reliable use. However, these neural network-based models operate as black-box algorithms, making it exceptionally difficult to understand their behavior. To address this issue, a common approach is to reveal and alter the model's internal mechanisms through model editing. Model editing is widely used in neural networks, allowing the observation of the impact on the task by modifying certain parts of the model. However, to perform model editing, the key MLP to be edited must first be located.

[0067] Related techniques primarily locate critical MLP layers through casual tracing. This method requires replacing the activations of the MLP layer outputs to pinpoint key MLP layers in the model. For example, when applied to large models, these techniques iteratively replace the activations of individual MLP layers to evaluate the impact of these local modifications on task performance. However, these techniques require significant computational resources and time, resulting in low model processing efficiency.

[0068] To address the aforementioned technical problems, this application embodiment acquires training data and its labels, and inputs the training data into a first model, which includes N MLP layers. For each of these N MLP layers, the electronic device perturbs each of the N MLP layers based on the perturbation weights corresponding to that MLP layer, obtaining the output of the perturbated first model. Based on the output of the perturbated first model and the labels of the training data, the model loss of the perturbated first model is determined. Based on the model loss of the perturbated first model, the perturbation weights corresponding to the N MLP layers are trained and adjusted to obtain the target perturbation weights corresponding to the N MLP layers. Based on the target perturbation weights corresponding to the N MLP layers, K key MLP layers are determined from the N MLP layers. As can be seen from the above, the method of this application embodiment includes two stages: MLP layer perturbation and MLP layer selection. In the MLP layer perturbation stage, this application injects perturbations into each MLP layer of the first model to create a perturbated first model. Learnable perturbation weights are then used to control the perturbation amount of each MLP layer. By training the perturbation weights corresponding to each MLP layer, the perturbated first model is encouraged to retain sufficient information. In the MLP layer selection stage, key MLP layers can be identified by observing the trained perturbation weights. This enables the global identification of the most informative key MLP layers in the first model, achieving accurate identification of key MLP layers and improving the identification efficiency. The method of this application provides a solution for key MLP layer localization in model editing operations. It helps model editing achieve more ideal goals and ensures that model editing methods are deployed and used safely and reliably.

[0069] The implementation environment of the model processing method provided in the embodiments of this application is described below.

[0070] Figure 1 This is a schematic diagram of an implementation environment for the model processing method provided in the embodiments of this application, such as... Figure 1 As shown, the implementation environment includes: terminal device 101 and server 102.

[0071] The terminal device 101 is connected to the server 102 via wired or wireless means.

[0072] In this embodiment, the terminal device 101 is equipped with a client for the model processing system, and the server 102 can be understood as the server-side or backend of the model processing. Objects (e.g., users) can interact with the model processing client installed on the terminal device 101. The server 102 can perform model processing operations and save the processed models.

[0073] In some embodiments, the model processing method provided in this application can be executed by server 102. Specifically, server 102 stores a trained first model. An object starts a model processing client on terminal device 101, which displays an input interface for training data. The object inputs training data and its labels in this interface. Terminal device 101 sends the input training data and its labels to server 102. Server 102 inputs the training data into the first model and, based on the perturbation weights corresponding to the N multilayer perceptron (MLP) layers included in the first model, perturbs each of the N MLP layers to obtain the output of the perturbated first model. Based on the output of the perturbated first model and the labels of the training data, it determines the model loss of the perturbated first model. Based on the model loss of the perturbated first model, it trains and adjusts the perturbation weights corresponding to the N MLP layers to obtain the target perturbation weights corresponding to the N MLP layers. Based on the target perturbation weights corresponding to the N MLP layers, it determines K key MLP layers from the N MLP layers. Optionally, server 102 can send the K key MLP layers in the first model to terminal device 101 for display. For example, terminal device 101 can identify the K key MLP layers in the first model so that the object can intuitively observe the key MLP layers in the first model. Optionally, server 102 can perform subsequent model editing operations based on the K key MLP layers in the first model to obtain an edited second model. In this embodiment, perturbations are injected into each MLP layer in the first model to create a perturbated first model. Then, learnable perturbation weights are used to control the perturbation amount of each MLP layer. By training the perturbation weights corresponding to each MLP layer, the perturbated first model is encouraged to maintain sufficient information. Furthermore, key MLP layers can be identified by observing the trained perturbation weights, enabling the global identification of the most informative key MLP layers in the first model, achieving accurate identification of key MLP layers, and improving the identification efficiency of key MLP layers.

[0074] In some embodiments, the model processing method of this application can be executed by terminal device 101. Specifically, the model processing method provided in this application can be executed by server 102. An object starts a model processing client on terminal device 101, which displays an input interface for training data. The object inputs training data and its labels in this input interface. In response to the object's input of training data, terminal device 101 sends a request to server 102 to request a first model. Server 102 sends the first model to terminal device 101 based on the request sent by terminal device 101. Terminal device 101 inputs training data into the first model, and perturbs each of the N multilayer perceptron (MLP) layers based on the perturbation weights corresponding to those layers, obtaining the output of the perturbated first model. Based on the output of the perturbated first model and the labels of the training data, it determines the model loss of the perturbated first model. Based on the model loss of the perturbated first model, it trains and adjusts the perturbation weights corresponding to the N MLP layers, obtaining the target perturbation weights for each of the N MLP layers. Based on the target perturbation weights for each of the N MLP layers, it identifies K key MLP layers from the N MLP layers. Optionally, the terminal device can display the K key MLP layers in the first model. For example, terminal device 101 marks the K key MLP layers in the first model so that the object can intuitively observe the key MLP layers in the first model. Optionally, the terminal device 101 can send the K key MLP layers in the determined first model to the server 102, so that the server 102 can perform subsequent model editing operations based on the K key MLP layers in the first model to obtain the edited second model.

[0075] In some embodiments, the terminal device 101 includes, but is not limited to, desktop computers, laptops, smartphones, tablets, IoT devices, and portable wearable devices. IoT devices may include smart speakers, smart TVs, smart air conditioners, and smart in-vehicle systems. Portable wearable devices may include smartwatches, smart bracelets, and head-mounted devices. Terminal devices are often equipped with a display device, which may be a monitor, display screen, touchscreen, etc., and the touchscreen may be a touchscreen, touch panel, etc.

[0076] In some embodiments, the server 102 described above can be one or more servers. When there are multiple servers, at least two servers are used to provide different services, and / or at least two servers are used to provide the same service, such as providing the same service in a load-balanced manner. This application embodiment does not limit this. The server described above can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. The server can also be a node in a blockchain.

[0077] It should be noted that the implementation environment of this application embodiment includes, but is not limited to, Figure 1 As shown.

[0078] The technical solutions of the embodiments of this application will be described in detail below through some examples. The following embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.

[0079] Figure 2 This is a flowchart illustrating a model processing method provided in an embodiment of this application. The execution entity of this embodiment can be a device with model processing capabilities, such as a model processing apparatus. This model processing apparatus can be the one described above. Figure 1 The server 102 or terminal device 101 shown can also be Figure 1 The system consists of servers 102 or 101 as shown. For ease of description, the following embodiments use electronic devices as examples to illustrate the methods of this application.

[0080] like Figure 2 As shown, the model processing method in this application embodiment includes:

[0081] S101. Obtain the training data and the labels of the training data, and input the training data into the pre-trained first model.

[0082] The first model consists of N MLP layers, where N is a positive integer greater than 1.

[0083] It should be noted that the data used in the embodiments of this application and the process of obtaining this data comply with the relevant laws and regulations.

[0084] In the task of locating key MLP layers in a model, many studies treat the model as a directed computational graph, denoted as G. In this computational graph, source nodes represent the model's input, target nodes represent the model's output, and intermediate nodes represent computational units. The set C of key MLP layers is a subset of G, responsible for achieving performance similar to the pre-trained model G under a specific task. This type of localization method uses the identification of the important MLP layer set C as a key basis for model editing tasks.

[0085] The model processing method proposed in this application can be applied to technical fields such as model editing. This application mainly involves identifying key MLP layers from N MLP layers included in a first model. Then, the first model is edited based on the key MLP layers, such as deleting MLP layers other than the key MLP layers in the first model, or modifying the key MLP layers in the first model, to achieve effective changes to the first model data within a specific domain.

[0086] In some embodiments, the first model described above is the first model after training.

[0087] This application does not limit the specific type and network structure of the first model, as long as the first model includes multiple MLP layers.

[0088] In one example, the first model mentioned above is a language model that includes at least two MLP layers.

[0089] In one example, the first model mentioned above can be a mixed-element large model.

[0090] In the embodiments of this application, such as Figure 3 As shown, the first model includes N MLP layers. This application embodiment does not limit the specific network connection method of the N MLP layers included in the first model. For example, at least two of these N MLP layers can be connected in series, or at least two can be connected in parallel, or none of these N MLP layers can be connected to each other, or at least two of these N MLP layers can be connected to each other, etc.

[0091] The MLP involved in the embodiments of this application will be described below.

[0092] MLP layers are a type of feedforward neural network. In one example, such as... Figure 4As shown, this MLP layer mainly includes an input layer, a hidden layer, and an output layer. Optionally, the input layer and the hidden layer are fully connected, meaning that every neuron in the input layer is connected to every neuron in the hidden layer. Optionally, the hidden layer and the output layer are also fully connected, meaning that every neuron in the hidden layer is connected to every neuron in the output layer. The input layer and the hidden layer, as well as the hidden layer and the output layer, are connected through weights and biases. Figure 4 As shown, there is a weight coefficient between each input feature and a neuron in the hidden layer. Similarly, there is a weight coefficient between each neuron in the hidden layer and a neuron in the output layer. After the hidden layers, an activation function is used for non-linearization. This non-linearization simplifies the sample features, enabling the neural network to learn from complex non-linear datasets.

[0093] For example, the output Z of the hidden layer can be obtained according to the following formula (3):

[0094] H = W1X + b1 (3)

[0095] Where W1 is the weight matrix between the input layer and the hidden layer, X is the input layer, and b1 is the bias between the input layer and the hidden layer.

[0096] For example, the output Z of the output layer can be obtained according to the following formula (4):

[0097] Z = W²H + b² (4)

[0098] Where W2 is the weight matrix between the hidden layer and the output layer, and b2 is the bias between the hidden layer and the output layer.

[0099] This application does not limit the specific type of training data. For example, when the first model is a language model, the training data is a single piece of language data. For instance, if the first model is a translation model, the training data can be a piece of text to be translated in the first language, with the label being the translated text in the second language corresponding to the first language text. As another example, if the first model is a question-answering model, the training data can be a single question, with the label being the answer to that question.

[0100] In one example, the labels on the training data mentioned above can be manually labeled.

[0101] In one example, the labels of the training data are predicted by the first model. Since the first model has already been trained, the object can input the training data into the first model for processing. The first model can output the processing result corresponding to the training data, and thus the output of the first model is determined as the label of the training data.

[0102] In this embodiment of the application, after the electronic device acquires the training data and the label of the training data, it inputs the training data into the first model.

[0103] S102. For each of the N MLP layers, based on the perturbation weights corresponding to the MLP layer, the MLP layer is perturbed to obtain the output result of the perturbed first model.

[0104] In this embodiment of the application, in order to identify the key MLP layer from the N MLP layers included in the first model, such as Figure 5 As shown, perturbations are added to N MLP layers in the first model, and the amount of perturbation added to each MLP layer is controlled by the perturbation weights corresponding to each MLP layer. Thus, after adding perturbations to each MLP layer in the first model, a perturbated first model is obtained. Next, using training data, the perturbation weights corresponding to each MLP layer are trained to determine the target perturbation weights for each of the N MLP layers. Finally, based on the target perturbation weights corresponding to each of the N MLP layers, K key MLP layers are determined from the N MLP layers.

[0105] Therefore, the model processing process of this application embodiment mainly includes two stages. The first stage is the MLP layer perturbation stage, which involves injecting perturbations into each MLP layer in the first model to create a perturbated first model. Then, learnable perturbation weights are used to control the perturbation amount of each MLP layer. By training the perturbation weights corresponding to each MLP layer, the perturbated first model is encouraged to maintain sufficient information.

[0106] The second stage is the MLP layer selection stage. By observing the trained perturbation weights, key MLP layers can be identified. This stage can globally identify the most informative key MLP layers in the first model, achieving accurate identification of key MLP layers and improving the identification efficiency of key MLP layers.

[0107] In the embodiments of this application, the process of training the perturbation weights corresponding to the N MLP layers using each training data is basically the same. For ease of description, the embodiments of this application will introduce the process of training the perturbation weights corresponding to the N MLP layers using one training data.

[0108] In this embodiment of the application, the process of training the perturbation weights corresponding to the N MLP layers using training data can be understood as the process of training the first model, except that the main task in this training process is to update the perturbation weights corresponding to the N MLP layers.

[0109] In this embodiment, the process of perturbing each MLP layer among the N NLP layers included in the first model is consistent. That is, for each MLP layer in the first model, a perturbation is added to that MLP layer based on the perturbation weights corresponding to that MLP layer. By performing the above perturbation operation on each MLP layer in the first model, the output result of the perturbed first model can be obtained.

[0110] From the above Figure 4 It is understood that the data involved in the data processing of an MLP layer includes at least input information, hidden information, and output information. In this embodiment, perturbing the MLP layer can be understood as perturbing one or more data involved in the data processing of the MLP layer. For example, perturbing at least one of the input information, hidden information, and output information of the MLP layer.

[0111] In some embodiments, perturbing the MLP layer means perturbing the output information of the MLP layer.

[0112] Therefore, this application embodiment controls the amount of perturbation (i.e., perturbation noise) added to the MLP layer based on perturbation weights. In this application embodiment, MLP layers with more information are less likely to be injected with perturbation noise. That is, for each MLP layer, less perturbation injection corresponds to a more critical MLP layer, while more noise injection corresponds to a less important MLP layer. In this application embodiment, the amount of perturbation noise injected into the MLP layer can be controlled based on perturbation weights, and by training the perturbation weights, key MLP layers can be selected based on the trained perturbation weights, thus achieving accurate selection of key MLP layers.

[0113] This application does not impose any restrictions on the correspondence between perturbation weights and perturbation amounts.

[0114] In one possible implementation, the perturbation weights and the amount of perturbation are positively correlated. For example, for a given MLP layer among N MLP layers, if the perturbation weight corresponding to that MLP layer is larger, then the amount of perturbation added to that MLP layer is larger, indicating that that MLP layer is an unimportant MLP layer. Conversely, if the perturbation weight corresponding to that MLP layer is smaller, then the amount of perturbation added to that MLP layer is smaller, indicating that that MLP layer is an unimportant MLP layer and the most informative important MLP layer.

[0115] In one possible implementation, the perturbation weights and perturbation amounts are positively or negatively correlated. For example, for a given MLP layer among N MLP layers, if the perturbation weight corresponding to that MLP layer is larger, then the amount of perturbation added to that MLP layer is smaller, indicating that that MLP layer is the most information-rich and important MLP layer. Conversely, if the perturbation weight corresponding to that MLP layer is smaller, then the amount of perturbation added to that MLP layer is larger, indicating that that MLP layer is an unimportant MLP layer.

[0116] In this embodiment of the application, before using the training data to update the perturbation weights corresponding to the N MLP layers included in the first model, it is first necessary to determine the initial values ​​of the perturbation weights corresponding to the N MLP layers.

[0117] In one example, the initial values ​​of the perturbation weights corresponding to the above N MLP layers can be random values.

[0118] In one example, the initial values ​​of the perturbation weights corresponding to the above N MLP layers can be based on a standard normal distribution. Obtained through sampling.

[0119] In this embodiment of the application, the pre-trained first model G is defined as a combination of N MLP layers, denoted as G = [v1, v2, ..., v n For each attention layer among the N MLP layers included in the first model, for example, the i-th MLP layer, assuming that the output information of the i-th MLP layer is a feature vector of dimension M, where M is a positive integer, then the output information of the i-th MLP layer can be represented as Z. i =[z1,z2,…,z M ].

[0120] In some embodiments, each element in the output information of the i-th MLP layer corresponds to the same perturbation weight value, which is λ. i In other words, the perturbation weight corresponding to the i-th MLP layer is a single value.

[0121] In some embodiments, the perturbation weights corresponding to the i-th MLP layer are M-dimensional vectors. In this case, the perturbation weights corresponding to the i-th MLP layer can be represented as λ. i =[λ1,λ2,…,λ M In this context, each element in the output information of the i-th MLP layer corresponds to a perturbation weight value. In one example, such as... Figure 6 As shown, if the output information Z of the i-th MLP layer i This is a 3-dimensional feature vector, consisting of three elements: z1, z2, and z3. Correspondingly, the perturbation weight λ corresponds to the i-th MLP layer. i This is also a 3-dimensional vector, including three elements: λ1, λ2, and λ3. Here, λ1 is the perturbation weight value corresponding to element z1 in the output information of the i-th MLP layer, used to perturb z1. λ2 is the perturbation weight value corresponding to element z2 in the output information of the i-th MLP layer, used to perturb z2. λ3 is the perturbation weight value corresponding to element z3 in the output information of the i-th MLP layer, used to perturb z3.

[0122] In some embodiments, in order to ensure λ i If ∈(0,1), then define λ i =Sigmoid(ω) i ),in These are the actual learnable parameters.

[0123] In this embodiment of the application, training data can be used to train the perturbation weights corresponding to the N MLP layers included in the first model for at least one round, and finally the perturbation weights corresponding to the N MLP layers under the training data can be obtained.

[0124] For example, the electronic device uses training data and its labels to perform a first round of training on the initial values ​​of the perturbation weights corresponding to the N MLP layers included in the first model. Then, the electronic device uses the training data and its labels to perform a second round of training on the perturbation weights after the first round of training. This training is repeated multiple times to finally obtain the target perturbation weights. Each round of training is basically the same; here, we will use one round of training as an example for explanation.

[0125] Based on this, in some embodiments, if the above training process is the first round of training, then the perturbation weights corresponding to the N multilayer perceptron (MLP) layers in S102 are the initial values ​​of the perturbation weights. In some embodiments, if the above training process is the kth round of training, then the perturbation weights corresponding to the N MLP layers in S102 are the perturbation weights obtained in the (k-1)th round of training. Here, k is a positive integer greater than 1.

[0126] When training the perturbation weights using training data, the electronic device first inputs the training data into a first model, which includes N MLP layers. In this embodiment, the electronic device perturbs the output information of each of the N MLP layers to identify key MLP layers. In this embodiment, for each MLP layer, the amount of perturbation input to that MLP layer is controlled by perturbation weights. Thus, when adding perturbation to each MLP layer, the electronic device adds perturbation to the input information of each MLP layer based on the perturbation weights corresponding to that MLP layer. For example, for the i-th MLP layer among the N MLP layers, the electronic device adds perturbation to the output information of the i-th MLP layer based on the perturbation weights corresponding to that i-th MLP layer. It should be noted that the order in which perturbations are added to the N MLP layers follows the data processing order of the first model. For example, if the first model includes MLP layer 1 and MLP layer 2, during data processing, the first model first processes data through MLP layer 1, and then through MLP layer 2. Based on this, when adding perturbations, the electronic device first adds perturbations to the output information of MLP layer 1 based on the perturbation weights corresponding to MLP layer 1, and then adds perturbations to the output information of MLP layer 2 based on the perturbation weights corresponding to MLP layer 2. This process is repeated sequentially, and finally, the output result of the first model after adding perturbations can be obtained. This output result is recorded as the output result of the first model after perturbation.

[0127] The embodiments of this application do not limit the specific method by which the electronic device perturbs the output information of each of the N MLP layers based on the perturbation weights corresponding to the N MLP layers included in the first model, and obtains the perturbed output result of the first model.

[0128] In some embodiments, for the i-th MLP layer among N MLP layers, the electronic device can determine the perturbation output information of the i-th MLP layer as the product or sum of the perturbation weights corresponding to the i-th MLP layer and the output information of the i-th MLP layer. This process is repeated sequentially to ultimately obtain the output result of the perturbated first model.

[0129] In some embodiments, the above-mentioned step S102, based on the perturbation weights corresponding to the N MLP layers included in the first model, perturbs the output information of each of the N MLP layers to obtain the perturbated output result of the first model, includes the following steps S102-A to S102-C:

[0130] S102-A: For the i-th MLP layer among N MLP layers, obtain the output information of the i-th MLP layer, where i is a positive integer less than or equal to N;

[0131] S102-B: Determine the perturbation noise value corresponding to the i-th MLP layer, and based on the perturbation noise value and the perturbation weight corresponding to the i-th MLP layer, perturb the output information of the i-th MLP layer to obtain the perturbation output information of the i-th MLP layer.

[0132] S102-C: Input the perturbation output information of the i-th MLP layer into the module connected to the i-th MLP layer for processing, execute sequentially, and obtain the output result of the perturbated first model.

[0133] In this implementation, for the i-th MLP layer among N MLP layers, the electronic device perturbs the output information of the i-th MLP layer by adding noise to the output information of the i-th MLP layer.

[0134] The embodiments of this application do not limit the specific method for determining the perturbation noise value corresponding to the i-th MLP layer.

[0135] In one possible implementation, the electronic device determines a preset noise value as the perturbation noise value corresponding to the i-th MLP layer.

[0136] In one possible implementation, the electronic device can determine the perturbation noise value corresponding to the i-th MLP layer based on the output information of the i-th MLP layer.

[0137] In this embodiment of the application, the output information z of the i-th MLP layer i Let λ be a vector, for example, a 10-dimensional vector with 10 elements. Correspondingly, the perturbation weight λ for the i-th MLP layer... i It is also a 10-dimensional vector, representing the output information z of the i-th MLP layer. i Each element in the array corresponds to a perturbation weight value.

[0138] In some embodiments, the perturbation noise value corresponding to the i-th MLP layer can be a single numerical value.

[0139] In some embodiments, the perturbation noise corresponding to the i-th MLP layer is a 10-dimensional vector, that is, each element in the output information zi of the i-th MLP layer corresponds to a perturbation noise value.

[0140] For example, the electronic device determines the mean and variance of the output information of the i-th MLP layer; based on the mean and variance of the output information of the i-th MLP layer, it determines the normal distribution of the output information of the i-th MLP layer; and it randomly samples the normal distribution of the output information of the i-th MLP layer to obtain the perturbation noise value corresponding to the i-th MLP layer. Specifically, in this embodiment, the output information of the i-th MLP layer of the electronic device is a feature vector, which includes multiple elements. The average value of each element included in the output information of the i-th MLP layer is calculated and determined as the mean of the output information of the i-th MLP layer. Next, based on each element included in the output information of the i-th MLP layer and the mean, the variance of the output information of the i-th MLP layer is determined. Then, based on the mean and variance of the output information of the i-th MLP layer, the normal distribution of the output information of the i-th MLP layer is determined. The electronic device then randomly samples the normal distribution of the output information of the i-th MLP layer to obtain the perturbation noise value corresponding to the i-th MLP layer.

[0141] In this embodiment, after the electronic device determines the perturbation noise value corresponding to the i-th MLP layer, it perturbs the output information of the i-th MLP layer based on the perturbation noise value and the perturbation weight corresponding to the i-th MLP layer to obtain the perturbation output information of the i-th MLP layer.

[0142] The embodiments of this application do not limit the specific method by which the electronic device perturbs the output information of the i-th MLP layer based on the perturbation noise value and the perturbation weight corresponding to the i-th MLP layer to obtain the perturbation output information of the i-th MLP layer.

[0143] In some embodiments, the electronic device multiplies the perturbation noise value corresponding to the i-th MLP layer with the perturbation weight corresponding to the i-th MLP layer, and then adds it to the output information of the i-th MLP layer to obtain the perturbation output information of the i-th MLP layer.

[0144] In some embodiments, the perturbation of the output information of the i-th MLP layer based on the perturbation noise value and the perturbation weight corresponding to the i-th MLP layer in S102-B above, to obtain the perturbation output information of the i-th MLP layer, includes the following steps:

[0145] S102-B1: Multiply the output information of the i-th MLP layer with the perturbation weights corresponding to the i-th MLP layer to obtain the first product;

[0146] S102-B2: Subtract the first data from the perturbation weight corresponding to the i-th MLP layer, multiply the result by the perturbation noise value to obtain the second product, where the first data is a positive integer;

[0147] S102-B3. The sum of the first product and the second product is determined as the perturbation output information of the i-th MLP layer.

[0148] In this implementation, after determining the perturbation noise value and perturbation weight corresponding to the i-th MLP layer, the electronic device multiplies the output information of the i-th MLP layer with the perturbation weight to obtain a first product. Then, it subtracts the perturbation weight from the first product and multiplies it with the perturbation noise value to obtain a second product. Finally, the sum of the first and second products is determined as the perturbation output information of the i-th MLP layer.

[0149] The embodiments of this application do not limit the specific value of the first data, which can be any positive integer.

[0150] In one example, the first data is 1.

[0151] In some embodiments, the electronic device can add a perturbation to the i-th MLP layer using the following formula (5):

[0152]

[0153] Among them, Z i For the output information of the i-th MLP layer, λ i Let be the perturbation weight corresponding to the i-th MLP layer, 1 for the first data, ∈ i Let λ be the perturbation noise value corresponding to the i-th MLP layer. i Z i For the first product, (1-λ) i )∈ i The second product, This is the perturbation output information for the i-th MLP layer.

[0154] As can be seen from the above formula (5), in this embodiment of the application, for the first model G, the first model G includes N MLP layers. For example, the first model can be represented as G = [v1, v2, ..., v n Let Z = [z1, z2, ...] represent the output information of the corresponding MLP layer. To introduce perturbation into the first model G, embodiments of this application use learnable perturbation weights λ = [λ1, λ2, ...] to inject noise into the output information of the MLP layer. For example, noise ∈ can be sampled from a parameterized noise distribution. For each MLP layer v i In this embodiment of the application, the output information Z of the MLP layer can be obtained through the above formula (5). i With disturbance noise ∈ i Combined, using perturbation weights λ iPerturb the output information H of the MLP layer using ∈(0,1). i .

[0155] From the above formula (5), it can be seen that when λ i When →1, all from Z i All information is transmitted without loss. Conversely, when λ i →0, It does not include information from Z i The information is only noise. Unlike methods that iteratively perturb each intermediate variable, the proposed method allows adjusting the output information Z of all MLP layers to [the desired value] by simultaneously learning and updating the perturbation weights λ corresponding to all MLP layers. This increases the information flow and thus improves the model's processing efficiency.

[0156] For ease of description, in some embodiments, the perturbed first model can be represented as... Using the learned perturbation weights, select The key MLP layer in the set is C.

[0157] The above example illustrates how an electronic device adds a perturbation to the output information of the i-th MLP layer out of N MLP layers. Based on this method, the electronic device can add perturbations to the output information of each of the N MLP layers in the first model, ultimately obtaining the perturbated output result of the first model.

[0158] For example, suppose the network structure of the first model is as follows: Figure 7 As shown, this first model includes multiple attention layers and N MLP layers. It should be noted that... Figure 7 This paper illustrates one connection method between the attention layer and the MLP layer in the first model. Other connection methods are also included in the first model of this application, and this application does not limit these methods. Figure 7 As shown, for each of the N MLP layers, the electronic device adds a perturbation to the output information of that MLP layer based on the perturbation weights and perturbation noise corresponding to that MLP layer. For example, the electronic device adds a perturbation to the output information of that MLP layer according to the method shown in formula (5) above. Based on this method, the electronic device can add a perturbation to the output information of each of the N MLP layers included in the first model, thereby obtaining the perturbated output result of the first model in this round of training.

[0159] S103. Based on the output of the perturbated first model and the labels of the training data, determine the model loss of the perturbated first model, and based on the model loss of the perturbated first model, train and adjust the perturbation weights corresponding to the N MLP layers respectively to obtain the target perturbation weights corresponding to the N MLP layers respectively.

[0160] Based on the above steps, the electronic device determines the output of the perturbated first model during this training round, and then determines the model loss of the perturbated first model based on the output of the perturbated first model and the labels of the training data.

[0161] The objective of this application is to identify the set of key MLP layers that play a crucial role in the first model, thereby achieving a balance between minimizing the number of MLP layers and maximizing their task execution capabilities. In other words, by identifying the key MLP layers in the first model, the first model can achieve the effect of including N MLP layers under the influence of these key MLP layers. Specifically, by identifying the key MLP layers in the first model, the first model can achieve its initial performance (i.e., the performance of the first model including N MLP layers) even when including the key MLP layers but excluding non-key MLP layers. Based on this, during the training process of the perturbation weights corresponding to the N MLP layers, this application aims to make the output of the perturbated first model infinitely close to the label of the training data. Thus, during this training round, the electronic device can determine the model loss of the perturbated first model based on the output of the perturbated first model and the label of the training data.

[0162] This application does not limit the specific method by which the electronic device determines the model loss of the perturbed first model based on the output results of the perturbed first model and the labels of the training data.

[0163] In some embodiments, the electronic device determines the model loss of the perturbed first model as the difference between the output of the perturbed first model and the labels of the training data. For example, the cross-entropy loss between the output of the perturbed first model and the labels of the training data is determined as the model loss of the perturbed first model.

[0164] In some embodiments, S103 above includes the following steps S103-A to S103-C:

[0165] S103-A, Determine the first mutual information between the labels of the training data and the output of the perturbated first model;

[0166] S103-B, Based on the first mutual information, determine the first loss of the first model after the perturbation;

[0167] S103-C, Based on the first loss, determine the model loss of the first model after perturbation.

[0168] Mutual information, a useful information metric in information theory, can be viewed as the amount of information contained in one random variable about another. As described above, in identifying key MLP layers, this embodiment aims to make the output of the perturbated first model infinitely close to the label of the training data. In other words, it aims to maximize the mutual information between the output of the perturbated first model and the label of the training data. Based on this, the electronic device can determine the label Y of the training data and the output of the perturbated first model. First mutual information between

[0169] Next, the electronic device determines the first loss of the first model after the perturbation based on the first mutual information.

[0170] Example 1: The electronic device uses the first mutual information to determine the first loss of the first model after the perturbation.

[0171] Example 2: The electronic device determines the variational upper bound of the negative number of the first mutual information as the first loss of the first model after perturbation.

[0172] In Example 2, the first loss of the perturbated first model can be expressed as:

[0173] In one possible implementation, the electronic device can determine the first loss of the first model after the disturbance using the following formula (6).

[0174]

[0175] Where Y is the label of the training data. Let p(Y) be the output of the first model after perturbation, and p(Y) be the probability value of the label in the training data. This represents the probability value of Y output by the first perturbation model. `logp` represents the logarithmic operation; the base is not limited in this embodiment. `E` represents the expectation operation. For true posterior The variational approximation of . This inequality shows that minimizing This can be achieved by minimizing the training loss of the perturbated first model. For example, when the first model is a Transformer-based language model, using cross-entropy loss for the next label prediction training is represented as follows: In some embodiments, if the first model is another model such as a visual model or a speech model, the embodiments of this application may use training loss functions on other specific tasks to determine the first loss.

[0176] In this embodiment of the application, after determining the first loss of the first model after the disturbance based on the above steps, the electronic device executes the above steps S103-C to determine the model loss of the first model after the disturbance based on the first loss.

[0177] This application does not limit the specific method by which the electronic device determines the model loss of the first model after the disturbance based on the first loss.

[0178] In one possible implementation, the electronic device determines the average value of the perturbation weights corresponding to the N MLP layers, and then determines the model loss of the perturbated first model based on the first loss and the average value of the perturbation weights corresponding to the N MLP layers.

[0179] In one example, the electronic device multiplies the average of the perturbation weights with the second hyperparameter, and then adds the result to the first loss to obtain the model loss of the perturbated first model.

[0180] For example, the electronic device can determine the model loss of the first model after perturbation using the following formula (7):

[0181]

[0182] in, The model loss of the first model after perturbation. The first loss of the first model after perturbation, and β is the second hyperparameter. Where λ i Let be the perturbation weights corresponding to the i-th MLP layer among N MLP layers.

[0183] In one possible implementation, S103-C above includes the following steps S103-C1 to S103-C4:

[0184] S103-C1: The training data is processed by the first model to obtain the output result of the first model;

[0185] S103-C2, Determine the second mutual information between the output of the first model and the output of the perturbated first model;

[0186] S103-C3, Based on the second mutual information, determine the second loss of the first model;

[0187] S103-C4. Based on the first loss and the second loss, determine the model loss of the first model after the perturbation.

[0188] In this implementation, the model loss of the perturbed first model includes a second loss in addition to the first loss. In this embodiment, to prevent the perturbed first model's output information from approaching the labels of the training data, causing all perturbed weights of each MLP layer to tend towards 1, this embodiment further calculates the second mutual information between the output of the first model and the output of the perturbed first model, and then determines the second loss of the first model based on this second mutual information. That is, in this embodiment, the electronic device can first input training data into the first model, and obtain the output of the first model without perturbing the MLP layers. Then, based on the above method, the training data is re-input into the first model, and the output information of each of the N MLP layers included in the first model is perturbed, thereby obtaining the perturbed output of the first model. In this embodiment, to prevent the perturbed weights of the N MLP layers from all being 1, the electronic device determines the second mutual information between the output of the first model and the output of the perturbed first model to constrain the information learned by the perturbed first model from the first model.

[0189] Based on the above steps, the electronic device determines the second mutual information. Then, based on this second mutual information, the second loss of the first model is determined.

[0190] In one example, the electronic device uses this second mutual information to determine the second loss of the first model.

[0191] In one example, the electronic device determines the variational upper bound of the second mutual information as the second loss.

[0192] In some embodiments, the electronic device can determine the second mutual information using the following formula (8). Variational upper bound:

[0193]

[0194] in, h i For the output information of the i-th MLP layer, μ i Let σ be the mean of the output information of the i-th MLP layer. i Let λ be the variance of the output information of the i-th MLP layer. i represents the perturbation weights corresponding to the output information of the i-th MLP layer. N is the number of MLP layers included in the first model.

[0195] This will further integrate the aforementioned second mutual information. The variational upper bound is determined as the second loss. For example, the electronic device determines the second loss according to the following formula (9):

[0196]

[0197] in, The second loss of the first model after perturbation.

[0198] In this embodiment of the application, after the electronic device determines the first loss and the second loss of the first model after the disturbance based on the above steps, it can determine the model loss of the first model after the disturbance based on the first loss and the second loss.

[0199] In one possible implementation, the electronic device can determine the sum of the first loss and the second loss as the model loss of the perturbated first model.

[0200] In one possible implementation, to further prevent the electronic device from excessively pursuing the output of the perturbated first model to tend towards the label Y of the training data during training, thus causing all λ to approach 1, this embodiment of the application penalizes λ during training to enhance its discriminative ability. Specifically, the average value of the perturbation weights corresponding to the N MLP layers is determined; based on the first loss, the second loss, and the average value of the perturbation weights, the model loss of the perturbated first model is determined.

[0201] The embodiments of this application do not limit the specific method by which the electronic device determines the model loss of the first model after perturbation based on the average value of the first loss, the second loss, and the perturbation weight.

[0202] In one example, the sum of the first loss, the second loss, and the average of the perturbation weights of the electronic device determines the model loss of the first model after perturbation.

[0203] In one example, the electronic device multiplies the second loss by the first hyperparameter to obtain a third product; multiplies the average of the perturbation weights by the second hyperparameter to obtain a fourth product; and the sum of the first loss, the third product, and the fourth product is determined as the model loss of the perturbated first model.

[0204] For example, the electronic device can determine the model loss of the first model after perturbation according to the following formula (10):

[0205]

[0206] in, The model loss of the first model after perturbation. The first loss, This is the second loss. Let α be the average value of the perturbation weights, α be the first hyperparameter, and β be the second hyperparameter.

[0207] The above describes the process by which the electronic device determines the model loss of the first model after perturbation during this round of training.

[0208] In this embodiment of the application, the electronic device determines the model loss of the first model after perturbation during the current training process based on the above steps, and then adjusts the perturbation weights corresponding to the N MLP layers based on the model loss of the first model after perturbation, so as to obtain the target perturbation weights corresponding to the N MLP layers.

[0209] In this embodiment, the first model is pre-trained. During the model training process based on the model loss of the perturbated first model, the perturbation weights corresponding to the N MLP layers are trained and adjusted, while other parameters of the first model may not be adjusted.

[0210] The embodiments of this application do not limit the specific method of training and adjusting the perturbation weights corresponding to the N MLP layers based on the model loss of the perturbated first model to obtain the target perturbation weights corresponding to the N MLP layers.

[0211] In some embodiments, S103 above includes the following steps S103-D to S103-G:

[0212] S103-D: Based on the model loss of the first model after perturbation, the perturbation weights corresponding to the N MLP layers are trained and adjusted to obtain the adjusted perturbation weights corresponding to the N MLP layers.

[0213] S103-E: Input the training data into the first model, and based on the adjusted perturbation weights corresponding to the N MLP layers included in the first model, perturb the output information of each of the N MLP layers to obtain the perturbation output result of the first model.

[0214] S103-F: Based on the output of the perturbated first model and the labels of the training data, determine the model loss of the perturbated first model. Based on the model loss of the perturbated first model, retrain and adjust the adjusted perturbation weights corresponding to the N MLP layers respectively. Repeat the process to obtain the perturbation weights corresponding to the N MLP layers under the training data.

[0215] S103-G: Based on the perturbation weights of N MLP layers under the training data, determine the target perturbation weights corresponding to each of the N MLP layers.

[0216] In this implementation, the training data is used to train the perturbation weights corresponding to each MLP layer multiple times. Specifically, the electronic device acquires the training data and its labels, and determines the initial values ​​of the perturbation weights corresponding to the N MLP layers included in the first model. Next, the electronic device inputs the training data into the first model, and based on the initial values ​​of the perturbation weights corresponding to the N MLP layers, adds perturbations to the output information of each MLP layer, obtaining the perturbated output result 1 of the first model. Then, based on the perturbated output result 1 of the first model and the labels of the training data, the model loss 1 of the perturbated first model is determined in the first round of training. Then, based on the model loss 1 of the perturbated first model, the initial values ​​of the perturbation weights corresponding to the N MLP layers are adjusted. Next, a second round of training is executed. In the second training, the electronic device inputs the training data into the first model, and according to the perturbation weights corresponding to the N MLP layers adjusted in the first round, adds perturbations to the output information of each MLP layer, obtaining the perturbated output result 2 of the first model. Then, based on the output result 2 of the perturbated first model and the label of the training data, the model loss 2 of the perturbated first model during the first round of training is determined. Next, based on the model loss 2 of the perturbated first model, the perturbation weights corresponding to the N MLP layers adjusted in the first round are readjusted. This process is repeated multiple times until the number of training iterations reaches a preset number, or the model loss of the perturbated first model reaches a preset value, at which point training stops. This yields the perturbation weights corresponding to the N MLP layers under this training data.

[0217] Next, the electronic device executes the steps S103-G above, and determines the target perturbation weights corresponding to the N MLP layers based on the perturbation weights corresponding to the N MLP layers under the training data.

[0218] This application does not limit the specific method by which the electronic device determines the target perturbation weights corresponding to the N MLP layers based on the perturbation weights corresponding to the N MLP layers under the training data.

[0219] In one possible implementation, the electronic device determines the target perturbation weights corresponding to the N MLP layers under the training data by perturbation weights of the N MLP layers.

[0220] In one possible implementation, to improve the identification of key MLP layers, this embodiment trains perturbation weights on multiple data points. In this case, S103-D above may include the following steps S103-D1 and S103-D2:

[0221] S103-D1. Determine the perturbation weights corresponding to N MLP layers under P training data, where P training data includes the training data and P is a positive integer of size 1.

[0222] S103-D2: Based on the perturbation weights of N MLP layers under P training data, determine the target perturbation weights corresponding to each of the N MLP layers.

[0223] In this implementation, the electronic device trains the aforementioned perturbation weights using P training data sets. This determines the perturbation weights corresponding to the N MLP layers under these P training data sets. Then, based on the perturbation weights corresponding to the N MLP layers under the P training data sets, the target perturbation weights corresponding to the N MLP layers are determined.

[0224] For example, assuming P equals 3, the electronic device uses 3 training data sets to train the perturbation weights. Specifically, the electronic device first uses training data 1 to train the perturbation weights corresponding to the N MLP layers, the training process of which can be referred to the specific description in the above embodiment, thereby determining the perturbation weights 1 corresponding to the N MLP layers under this training data. Next, training data 2 is used to train the perturbation weights corresponding to the N MLP layers, thereby determining the perturbation weights 2 corresponding to the N MLP layers under this training data. Training data 3 is used to train the perturbation weights corresponding to the N MLP layers, thereby determining the perturbation weights 3 corresponding to the N MLP layers under this training data. Finally, based on the perturbation weights corresponding to the N MLP layers under these 3 training data sets, the electronic device determines the target perturbation weights corresponding to the N MLP layers.

[0225] This application does not limit the specific method for determining the target perturbation weights corresponding to the N MLP layers of an electronic device under P training data.

[0226] In one possible implementation, for each of the N MLP layers, such as the j-th MLP layer, the electronic device can determine the target perturbation weight corresponding to the j-th MLP layer as the median of the perturbation weights corresponding to the j-th MLP layer under the P training data. Here, j is a positive integer less than or equal to N.

[0227] In one possible implementation, for each of the N MLP layers, such as the j-th MLP layer, the electronic device determines the target perturbation weight corresponding to the j-th MLP layer as the average value of the perturbation weights corresponding to the j-th MLP layer under P training data.

[0228] For example, assuming P equals 3, for the j-th MLP layer out of N MLP layers, the output information of the j-th MLP layer includes 3 elements, denoted as a1, a2, and a3. The perturbation weights corresponding to the j-th MLP layer under the first training data are denoted as [b11, b12, and b13], under the second training data as [b21, b22, and b23], and under the third training data as [b31, b32, and b33]. Thus, the perturbation weight value corresponding to the first element in the output information of the j-th MLP layer is c1 = (b11 + b21 + b31) / 3, the perturbation weight value corresponding to the second element is c2 = (b12 + b22 + b32) / 3, and the perturbation weight value corresponding to the third element is c3 = (b13 + b23 + b33) / 3. Therefore, the target perturbation weights corresponding to the j-th MLP layer are [c1, c2, and c3]. The above example uses the average value; however, the average value calculation can be replaced with the median value calculation.

[0229] In some embodiments, in addition to determining the target perturbation weights corresponding to the N MLP layers according to steps S103-D to S103-D described above, the electronic device can also determine the target perturbation weights corresponding to the N MLP layers in the following manner: Specifically, for each training sample in the P training data, based on the model loss of the perturbated first model, the perturbation weights corresponding to the N MLP layers are adjusted once during training to obtain the target perturbation weights corresponding to the N MLP layers under that training sample. This determines the perturbation weights corresponding to the N MLP layers under each training sample in the P training data. Furthermore, the electronic device can determine the average value of the perturbation weights corresponding to the N MLP layers under each training sample in the P training data as the target perturbation weights corresponding to the N MLP layers.

[0230] This step describes the specific process of determining the target perturbation weights corresponding to the N MLP layers.

[0231] S104. Based on the target perturbation weights corresponding to the N MLP layers, determine the K key MLP layers from the N MLP layers.

[0232] In this embodiment, when injecting noise perturbations into the N MLP layers included in the first model, injecting noise into the critical MLP layers of the first model has a greater impact on the functionality of the first model than injecting noise into non-critical MLP layers. In this sense, critical MLP layers are less likely to be injected with noise.

[0233] Based on this, electronic devices can determine K key MLP layers from N MLP layers by considering the relationship between the target perturbation weights corresponding to each of the N MLP layers and the magnitude of the noise injected into the N MLP layers. For example Figure 8 It shows from Figure 7 The first model shown includes K MLP layers selected from N MLP layers.

[0234] In some embodiments, if the target perturbation weight corresponding to the MLP layer is positively correlated with the magnitude of the noise value injected into the MLP layer, that is, the larger the target perturbation weight corresponding to the MLP layer, the larger the noise value injected into the MLP layer, then the electronic device can identify the MLP layer with the smaller target perturbation weight among the N MLP layers as the key MLP layer.

[0235] In some embodiments, if the target perturbation weight corresponding to the MLP layer is negatively correlated with the magnitude of the noise value injected into the MLP layer, for example, when the electronic device injects noise into the MLP layer according to the method shown in the above formula (5), it means that the larger the target perturbation weight corresponding to the MLP layer, the smaller the noise value injected into the MLP layer. In this case, the electronic device can determine the MLP layer with the larger target perturbation weight among the N MLP layers as the key MLP layer.

[0236] For example, based on the target perturbation weights corresponding to the N MLP layers, the K key MLP layers with the largest target perturbation weights are determined from the N MLP layers.

[0237] For example, based on the target perturbation weights corresponding to the N MLP layers, the electronic device selects K MLP layers from the N MLP layers whose target perturbation weights are greater than or equal to preset values, and determines them as the K key MLP layers in the first model.

[0238] In this embodiment of the application, if the perturbation weight corresponding to the MLP layer is a vector, the magnitude of the target perturbation weight vector can be determined as the size of the target perturbation weight for selecting the MLP layer.

[0239] As can be seen from the above, the key MLP determination process in the embodiments of this application adaptively adds perturbations to the N MLP layers included in the first model, so that the first model can still maintain similar performance on a specific task even after perturbation.

[0240] This application's embodiments achieve efficient identification of key MLP layers in a model by introducing the concept of information bottlenecks. Compared to traditional methods, the method in this application's embodiments does not require constructing additional data or iteratively replacing MLP layers in the model, thus saving computational resources and time. Through MLP layer perturbation and MLP layer selection stages, the most informative MLP layers in the first model can be globally identified, accurately assessing their importance and contribution. This efficient model interpretation method can save time and computational resources, improving researchers' work efficiency.

[0241] Furthermore, the technical solution of this application embodiment significantly improves the recognition performance of the key MLP layer of the first model. It enhances the efficiency and accuracy of model interpretation, expands the application scope, and provides researchers with greater flexibility and control. This is of great significance for ensuring the safe and reliable use of advanced models and promoting scientific research and innovative development.

[0242] In some embodiments, after determining the K key MLP layers of the first model, this application's embodiments edit the first model based on the K key MLP layers to obtain a second model. This application's embodiments do not limit the specific method of editing the first model. For example, the electronic device may retain the K key MLP layers included in the first model and delete the non-key MLP layers to obtain the second model. Alternatively, the electronic device may modify some of the MLP layers among the K key MLP layers included in the first model to obtain the second model.

[0243] The model processing method provided in this application involves acquiring training data and its labels, inputting the training data into a first model, and perturbing each of the N MLP layers based on the perturbation weights corresponding to those layers, thereby obtaining the output of the perturbed first model. Based on the output of the perturbed first model and the labels of the training data, the model loss of the perturbed first model is determined. Based on the model loss of the perturbed first model, the perturbation weights corresponding to the N MLP layers are trained and adjusted to obtain the target perturbation weights corresponding to the N MLP layers. Based on the target perturbation weights corresponding to the N MLP layers, K key MLP layers are determined from the N MLP layers. As can be seen from the above, the method in this application includes two stages: MLP layer perturbation and MLP layer selection. In the MLP layer perturbation stage, this application injects perturbations into the output information of each MLP layer in the first model, thereby creating a perturbated first model. Learnable perturbation weights are then used to control the perturbation amount of each MLP layer. By training the perturbation weights corresponding to each MLP layer, the perturbated first model is encouraged to maintain sufficient information. In the MLP layer selection stage, key MLP layers can be identified by observing the trained perturbation weights. This enables the global identification of the most informative key MLP layers in the first model, achieving accurate identification of key MLP layers and improving the identification efficiency. The method of this application provides a solution for key MLP layer localization in model editing operations. It can help model editing achieve more ideal goals and ensure that model editing methods are deployed and used safely and reliably.

[0244] The foregoing provides an overall overview of the model processing method provided in the embodiments of this application. The following section will combine... Figure 9 A specific model processing method according to an embodiment of this application will be described.

[0245] Figure 9 This is a schematic flowchart of a model processing method provided in an embodiment of this application. Figure 9 As shown, the method in this application embodiment includes:

[0246] S201. Obtain P training data points and the label of each training data point.

[0247] Where P is a positive integer greater than 1.

[0248] In this embodiment of the application, in order to improve the accuracy of determining the perturbation weights, the perturbation weights are trained on multiple training data, for example, P training data are used to train the perturbation weights corresponding to N MLP layers.

[0249] In one example, the labels on the training data mentioned above can be manually labeled.

[0250] In one example, the labels of the training data are predicted by the first model. Since the first model has already been trained, the object can input the training data into the first model for processing. The first model can output the processing result corresponding to the training data, and thus the output of the first model is determined as the label of the training data.

[0251] S202. For the p-th training data in P training data, input the p-th training data into the first model, and based on the perturbation weights corresponding to the N MLP layers included in the first model, perturb the output information of each of the N MLP layers to obtain the perturbated output result of the first model.

[0252] Where p is a positive integer less than or equal to P.

[0253] In this embodiment, after the electronic device obtains the p-th training data and the label of the p-th training data, it inputs the p-th training data into the first model. At the same time, based on the perturbation weights corresponding to the N MLP layers included in the first model, it perturbs the output information of each of the N MLP layers to obtain the perturbated output result of the first model.

[0254] In this embodiment of the application, the p-th training data can be used to train the perturbation weights corresponding to the N MLP layers included in the first model for at least one round, and finally the perturbation weights corresponding to the N MLP layers under the p-th training data can be obtained.

[0255] For example, the electronic device uses the p-th training data and its label to perform a first round of training on the initial values ​​of the perturbation weights corresponding to the N MLP layers included in the first model. Then, the electronic device uses the p-th training data and its label to perform a second round of training on the perturbation weights after the first round of training. This training is repeated multiple times to finally obtain the perturbation weights corresponding to the N MLP layers under the p-th training data. Each round of training is basically the same; here, we will use one round of training as an example for explanation.

[0256] In some embodiments, for the i-th MLP layer among N MLP layers, the electronic device acquires the output information of the i-th MLP layer, where i is a positive integer less than or equal to N; determines the perturbation noise value corresponding to the i-th MLP layer, and perturbs the output information of the i-th MLP layer based on the perturbation noise value and the perturbation weight corresponding to the i-th MLP layer to obtain the perturbation output information of the i-th MLP layer; inputs the perturbation output information of the i-th MLP layer into the module connected to the i-th MLP layer for processing, and executes the process sequentially to obtain the output result of the perturbated first model.

[0257] The above method for determining the disturbance noise value corresponding to the i-th MLP layer includes at least the following: the electronic device determines the mean and variance of the output information of the i-th MLP layer; based on the mean and variance of the output information of the i-th MLP layer, the normal distribution of the output information of the i-th MLP layer is determined; and the normal distribution of the output information of the i-th MLP layer is randomly sampled to obtain the disturbance noise value corresponding to the i-th MLP layer.

[0258] In this embodiment of the application, the pre-trained first model G is defined as a combination of n MLP layers, denoted as G = [v1, v2, ..., v n Let Z = [h1, h2, ...] represent the output information, i.e., activation, of the corresponding MLP layer. To introduce perturbations into the first model G, embodiments of this application use learnable perturbation weights λ = [λ1, λ2, ...] to inject perturbation noise into the output information of the MLP layer. In some embodiments, the electronic device samples the perturbation noise ∈ from a parameterized noise distribution. For each MLP layer, for example, the i-th MLP layer v... i The perturbation weight λ corresponding to the i-th MLP layer can be used. i ∈(0,1), using perturbation noise ∈ i The output information Z of the i-th MLP layer is perturbed to obtain the perturbed output information of the i-th MLP layer. Among them, the learnable perturbation weights λ i Used to control H i arrive The amount of information extracted.

[0259] In some embodiments, the electronic device multiplies the output information of the i-th MLP layer with the perturbation weight corresponding to the i-th MLP layer to obtain a first product; the first data is multiplied by the value obtained by subtracting the perturbation weight corresponding to the i-th MLP layer from the perturbation weight and multiplying it with the perturbation noise value to obtain a second product, wherein the first data is a positive integer; the sum of the first product and the second product is determined as the perturbation output information of the i-th MLP layer.

[0260] The specific implementation process of S202 can be referred to the relevant description of S102 above, and will not be repeated here.

[0261] S203. Determine the first mutual information between the label of the p-th training data and the output of the perturbated first model, and determine the first loss of the perturbated first model based on the first mutual information.

[0262] In this embodiment, the perturbed first model is learned by extracting information from a pre-trained first model G to achieve the same output Y on a specific task. On the one hand, embodiments of this application compress the effective information in the first model G by injecting perturbation noise. On the other hand, the goal of embodiments of this application is to maximize the perturbation of the first model. The information content is used to achieve the output Y. Therefore, the goal of the reconstruction in this application embodiment is as shown in formula (11):

[0263]

[0264] The first term in the above formula (11) Encourage the first model after perturbation The output of the model infinitely tends towards the label Y, and the first model after the second constraint perturbation. Learning key, useful information from the first model G. These two requirements necessitate that the electronic device selectively inject perturbation noise into the output information of each MLP layer of the first model G, so that the perturbated first model... Retain as much valuable information as possible. Intuitively, injecting noise into the critical MLP layers of the first model G has a greater impact on the function of the first model G than injecting perturbation noise into irrelevant MLP layers. In this sense, it is unlikely that critical MLP layers will be injected with noise. Therefore, after training, electronic devices can use this criterion to distinguish between the perturbed first model and the target MLP layers. Select key MLP layers to form set C.

[0265] in, This is the first mutual information.

[0266] In some embodiments, the variational upper bound of the negative number of the first mutual information can be determined as the first loss.

[0267] in, This is the second mutual information. The following section describes the process of determining the second mutual information and, based on this information, determining the second loss.

[0268] S204. The first model processes the p-th training data to obtain the output of the first model, and determines the second mutual information between the output of the first model and the perturbed output of the first model. Then, based on the second mutual information, the second loss of the first model is determined.

[0269] For example, the variational upper bound of the second mutual information is determined as the second loss.

[0270] The specific implementation process of S203 and S204 can be referred to the relevant description of S103 above, and will not be repeated here.

[0271] S205. Based on the first loss and the second loss, determine the model loss of the first model after the perturbation.

[0272] In some embodiments, the electronic device determines the sum of the first loss and the second loss as the model loss of the perturbated first model.

[0273] In some embodiments, the electronic device determines the average value of the perturbation weights corresponding to the N MLP layers respectively; and determines the model loss of the perturbated first model based on the first loss, the second loss and the average value of the perturbation weights.

[0274] For example, the electronic device multiplies the second loss with the first hyperparameter to obtain the third product; multiplies the average value of the perturbation weights with the second hyperparameter to obtain the fourth product; and determines the sum of the first loss, the third product, and the fourth product as the model loss of the perturbated first model.

[0275] S206. Based on the model loss of the first model after perturbation, the perturbation weights corresponding to the N MLP layers are trained and adjusted to obtain the adjusted perturbation weights corresponding to the N MLP layers.

[0276] For example, based on the model loss of the first model after perturbation, the adjustment gradient of the perturbation weights is determined, and then based on the adjustment gradient, the perturbation weights corresponding to the N MLP layers are trained and adjusted respectively.

[0277] S207. Determine whether the training termination conditions have been met.

[0278] The training termination conditions in this application embodiment include at least one of the following two conditions:

[0279] Condition 1: The number of training sessions reaches the preset number;

[0280] Condition 2: The model loss of the first model after perturbation is less than or equal to the preset loss.

[0281] In this embodiment of the application, if at least one of the above conditions 1 and 2 is met in this round of training, it is determined that the training end condition has been met.

[0282] If the training termination condition is not met, the perturbation weights corresponding to the N MLP layers in S202 are adjusted to the adjusted perturbation weights in S206, and the process returns to the steps of S202.

[0283] If the training termination condition is met, the adjusted perturbation weights corresponding to the N MLP layers obtained in S206 are determined as the perturbation weights of the N MLP layers under the p-th training data. Then, the following step S208 is executed.

[0284] S208. Select the (p+1)th training data from the P training data as the new p-th training data, and return to execute the steps of S202 above.

[0285] S209. Based on the perturbation weights corresponding to the N MLP layers under the P training data, determine the target perturbation weights corresponding to the N MLP layers respectively.

[0286] For example, for the j-th MLP layer among N MLP layers, the average value of the perturbation weights corresponding to the j-th MLP layer under P training data is determined as the target perturbation weight corresponding to the j-th MLP layer, where j is a positive integer less than or equal to N.

[0287] S210. Based on the target perturbation weights corresponding to the N MLP layers, determine the K key MLP layers with the largest target perturbation weights from the N MLP layers.

[0288] S211. Based on the K key MLP layers described in the first model, the first model is edited to obtain the second model.

[0289] This application embodiment does not limit the specific method by which the electronic device edits the first model based on the K key MLP layers in the first model to obtain the second model, and the model editing can be performed according to actual needs.

[0290] The model processing method provided in this application, based on the perturbation weights corresponding to the N MLP layers included in the first model, injects perturbation noise into the output information of each of these N MLP layers, and globally identifies the most informative key MLP layer in the first model based on the information bottleneck principle. Compared with existing methods, the method in this application avoids the inefficiency problem caused by local modifications, providing an efficient and accurate means for identifying key MLP layers in model editing. Furthermore, this application identifies key MLP layers by analyzing the perturbation weights trained on multiple training datasets, which further enables accurate identification of key MLP layers in the first model.

[0291] The following is combined Figure 10 Taking the first model as the first language model and the training data as text data as an example, the model processing method involved in the embodiments of this application will be introduced.

[0292] Figure 10 This is a schematic flowchart illustrating a model processing method provided in an embodiment of this application. Figure 10 As shown, the method in this application embodiment includes:

[0293] S301. Obtain P text data points and the label for each text data point.

[0294] Where P is a positive integer greater than 1.

[0295] In the embodiments of this application, there is no limitation on the specific type of the first language model.

[0296] For example, if the first language model is a translation model, then the above text data is the text data to be translated, and the label is the truth value of the translation result of the text data to be translated.

[0297] For example, if the first language model mentioned above is a generative dialogue model, then the text data mentioned above is the input question, and the label of the text data is the correct answer to the question.

[0298] Therefore, in the embodiments of this application, when the type of language model is different, the text data used is also different, that is, the text data and the language model are corresponding.

[0299] The specific implementation process of S301 can be referred to the relevant description of S201 above, and will not be repeated here.

[0300] S302. For the p-th text data in P text data, input the p-th text data into the first language model, and based on the perturbation weights corresponding to the N MLP layers included in the first language model, perturb the output information of each of the N MLP layers to obtain the perturbated output result of the first language model.

[0301] The specific implementation process of S302 can be referred to the relevant description of S202 above, and will not be repeated here.

[0302] S303. Determine the first mutual information between the label of the p-th text data and the output of the perturbated first language model, and determine the first loss of the perturbated first language model based on the first mutual information.

[0303] The specific implementation process of S303 can be referred to the relevant description of S203 above, and will not be repeated here.

[0304] S304. Process the p-th text data using the first language model to obtain the output of the first language model, and determine the second mutual information between the output of the first language model and the perturbed output of the first language model. Then, based on the second mutual information, determine the second loss of the first language model.

[0305] The specific implementation process of S304 can be referred to the relevant description of S204 above, and will not be repeated here.

[0306] S305. Based on the first loss and the second loss, determine the model loss of the perturbated first language model.

[0307] The specific implementation process of S305 can be referred to the relevant description of S205 above, and will not be repeated here.

[0308] S306. Based on the model loss of the perturbated first language model, the perturbation weights corresponding to the N MLP layers are trained and adjusted to obtain the adjusted perturbation weights corresponding to the N MLP layers.

[0309] The specific implementation process of S306 can be referred to the relevant description of S206 above, and will not be repeated here.

[0310] By repeating this process, the perturbation weights of the N MLP layers under each of the P text data can be determined.

[0311] S307. Based on the perturbation weights corresponding to the N MLP layers under P text data, determine the target perturbation weights corresponding to the N MLP layers respectively.

[0312] The specific implementation process of S307 can be referred to the relevant description of S207 above, and will not be repeated here.

[0313] S308. Based on the target perturbation weights corresponding to the N MLP layers, determine the K key MLP layers with the largest target perturbation weights from the N MLP layers.

[0314] S309. Based on the K key MLP layers in the first language model, the first language model is edited to obtain the second language model.

[0315] This application does not limit the specific method by which an electronic device edits the first language model based on K key MLP layers in the first language model to obtain the second language model.

[0316] In one example, the electronic device retains the K key MLP layers included in the first language model and deletes the non-key MLP layers to obtain the second language model. This allows the generated second language model to retain the functionality of the first language model while significantly reducing the model size and improving the model's data processing speed.

[0317] For example, an electronic device can modify some of the K key MLP layers in a first language model to obtain a second language model. This allows the generated second language model to include not only the key functions of the first language model but also other functions, thereby enabling functional expansion of the model.

[0318] Therefore, the model processing method provided in this application embodiment can accurately identify the key MLP layer in the first language model. When editing the first language model based on the accurately identified key MLP layer, the first language model can be effectively edited, thereby making the effect of the edited second language model more satisfactory and improving the effect of model editing.

[0319] The above text combined Figures 2 to 9 The method embodiments of this application are described in detail below, in conjunction with... Figure 10 The following describes in detail the device embodiments of this application.

[0320] Figure 11 This is a schematic block diagram of a model processing apparatus provided in an embodiment of this application.

[0321] like Figure 11 As shown, the model processing device 10 includes:

[0322] Acquisition unit 11 is used to acquire training data and the labels of the training data, and input the training data into a pre-trained first model, the first model including N multilayer perceptron (MLP) layers, where N is a positive integer;

[0323] The perturbation unit 12 is used to perturb each of the N MLP layers based on the perturbation weights corresponding to the MLP layer, and obtain the output result of the perturbated first model.

[0324] Training unit 13 is used to determine the model loss of the perturbated first model based on the output of the perturbated first model and the label of the training data, and to train and adjust the perturbation weights corresponding to the N MLP layers based on the model loss of the perturbated first model, so as to obtain the target perturbation weights corresponding to the N MLP layers respectively.

[0325] Selection unit 14 is used to determine K key MLP layers from the N MLP layers based on the target perturbation weights corresponding to the N MLP layers respectively, where K is a positive integer less than N.

[0326] In some embodiments, the perturbation unit 12 is specifically used to perturb the output information of each of the N MLP layers based on the perturbation weights corresponding to the MLP layer, so as to obtain the output result of the perturbated first model.

[0327] In some embodiments, the perturbation unit 12 is specifically configured to: obtain the output information of the i-th MLP layer among the N MLP layers, where i is a positive integer less than or equal to N; determine the perturbation noise value corresponding to the i-th MLP layer; and based on the perturbation noise value and the perturbation weight corresponding to the i-th MLP layer, perturb the output information of the i-th MLP layer to obtain the perturbation output information of the i-th MLP layer; input the perturbation output information of the i-th MLP layer into a module connected to the i-th MLP layer for processing, and execute sequentially to obtain the output result of the perturbated first model.

[0328] In some embodiments, the perturbation unit 12 is specifically used to determine the mean and variance of the output information of the i-th MLP layer; determine the normal distribution of the output information of the i-th MLP layer based on the mean and variance of the output information of the i-th MLP layer; and randomly sample the normal distribution of the output information of the i-th MLP layer to obtain the perturbation noise value corresponding to the i-th MLP layer.

[0329] In some embodiments, the perturbation unit 12 is specifically configured to multiply the output information of the i-th MLP layer with the perturbation weight corresponding to the i-th MLP layer to obtain a first product; multiply the value of the first data after subtracting the perturbation weight corresponding to the i-th MLP layer with the perturbation noise value to obtain a second product, wherein the first data is a positive integer; and determine the sum of the first product and the second product as the perturbation output information of the i-th MLP layer.

[0330] In some embodiments, the training unit 13 is specifically configured to determine a first mutual information between the label of the training data and the output of the perturbed first model; determine a first loss of the perturbed first model based on the first mutual information; and determine a model loss of the perturbed first model based on the first loss.

[0331] In some embodiments, the training unit 13 is specifically used to determine the variational upper bound of the negative number of the first mutual information as the first loss.

[0332] In some embodiments, the training unit 13 is specifically configured to process the training data through the first model to obtain the output result of the first model; determine the second mutual information between the output result of the first model and the output result of the perturbed first model; determine the second loss of the first model based on the second mutual information; and determine the model loss of the perturbed first model based on the first loss and the second loss.

[0333] In some embodiments, the training unit 13 is specifically used to determine the variational upper bound of the second mutual information as the second loss.

[0334] In some embodiments, the training unit 13 is specifically used to determine the average value of the perturbation weights corresponding to the N MLP layers respectively; and to determine the model loss of the perturbated first model based on the first loss, the second loss and the average value of the perturbation weights.

[0335] In some embodiments, the training unit 13 is specifically configured to multiply the second loss by the first hyperparameter to obtain a third product; multiply the average value of the perturbation weights by the second hyperparameter to obtain a fourth product; and determine the sum of the first loss, the third product, and the fourth product as the model loss of the perturbated first model.

[0336] In some embodiments, the training unit 13 is specifically configured to: train and adjust the perturbation weights corresponding to the N MLP layers based on the model loss of the perturbated first model, to obtain the adjusted perturbation weights corresponding to the N MLP layers; input the training data into the first model, and perturb the output information of each of the N MLP layers based on the adjusted perturbation weights corresponding to the N MLP layers included in the first model, to obtain the output result of the perturbated first model; determine the model loss of the perturbated first model based on the output result of the perturbated first model and the label of the training data; retrain and adjust the adjusted perturbation weights corresponding to the N MLP layers based on the model loss of the perturbated first model, repeating the process to obtain the perturbation weights corresponding to the N MLP layers under the training data; and determine the target perturbation weights corresponding to the N MLP layers based on the perturbation weights corresponding to the N MLP layers under the training data.

[0337] In some embodiments, the training unit 13 is specifically used to determine the perturbation weights corresponding to the N MLP layers under P training data, wherein the P training data includes the training data and P is a positive integer of size 1; and to determine the target perturbation weights corresponding to the N MLP layers based on the perturbation weights corresponding to the N MLP layers under P training data.

[0338] In some embodiments, the training unit 13 is specifically used to determine the average value of the perturbation weights corresponding to the j-th MLP layer under the P training data as the target perturbation weight corresponding to the j-th MLP layer, where j is a positive integer less than or equal to N.

[0339] In some embodiments, the selection unit 14 is specifically used to determine the K key MLP layers with the largest target perturbation weights from the N MLP layers based on the target perturbation weights corresponding to the N MLP layers respectively.

[0340] In some embodiments, the training unit 13 is further configured to perform model editing on the first model based on the K key MLP layers in the first model to obtain a second model.

[0341] It should be understood that the device embodiments and method embodiments can correspond to each other, and similar descriptions can be referred to the method embodiments. To avoid repetition, further details will not be provided here. Specifically, Figure 11 The apparatus shown can execute the embodiments of the above-described model processing method, and the foregoing and other operations and / or functions of each module in the apparatus are respectively for implementing the embodiments of the above-described model processing method. For the sake of brevity, they will not be described in detail here.

[0342] The apparatus of this application embodiment has been described above from the perspective of functional modules in conjunction with the accompanying drawings. It should be understood that this functional module can be implemented in hardware, in software instructions, or in a combination of hardware and software modules. Specifically, the steps of the method embodiments in this application can be completed by integrated logic circuits in the processor's hardware and / or by software instructions. The steps of the method disclosed in this application embodiment can be directly embodied as being executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. Optionally, the software module can reside in a mature storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps in the above method embodiments.

[0343] Figure 12 This is a schematic block diagram of an electronic device provided in an embodiment of this application. The electronic device may be the terminal device or server described above.

[0344] like Figure 12 As shown, the electronic device 40 may include:

[0345] The system includes a memory 41 and a processor 42. The memory 41 stores a computer program 43 and transfers the program code 43 to the processor 42. In other words, the processor 42 can retrieve and run the computer program 43 from the memory 41 to implement the methods described in the embodiments of this application.

[0346] For example, the processor 42 can be used to execute the steps in the method 200 described above according to the instructions in the computer program 43.

[0347] In some embodiments of this application, the processor 42 may include, but is not limited to:

[0348] General-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0349] In some embodiments of this application, the memory 41 includes, but is not limited to:

[0350] Volatile memory and / or non-volatile memory. Non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. Volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDR SDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), and Direct Rambus RAM (DR RAM).

[0351] In some embodiments of this application, the computer program 43 may be divided into one or more modules, which are stored in the memory 41 and executed by the processor 42 to complete the page recording method provided in this application. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program 43 in the electronic device 900.

[0352] like Figure 12 As shown, the electronic device 40 may further include:

[0353] Transceiver 34, which can be connected to processor 42 or memory 41.

[0354] The processor 42 can control the transceiver 34 to communicate with other devices; specifically, it can send information or data to other devices or receive information or data sent by other devices. The transceiver 34 may include a transmitter and a receiver. The transceiver 34 may further include antennas, and the number of antennas may be one or more.

[0355] It should be understood that the various components in the electronic device 40 are connected through a bus system, which includes a data bus, a power bus, a control bus, and a status signal bus.

[0356] According to one aspect of this application, a computer storage medium is provided that stores a computer program thereon, which, when executed by a computer, enables the computer to perform the methods of the above-described method embodiments. Alternatively, embodiments of this application also provide a computer program product containing instructions that, when executed by a computer, cause the computer to perform the methods of the above-described method embodiments.

[0357] According to another aspect of this application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the method described in the above-described method embodiments.

[0358] In other words, when implemented using software, it can be implemented wholly or partially in the form of a computer program product. This computer program product includes one or more computer instructions. When these computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital video disc (DVD)), or a semiconductor medium (e.g., solid-state disk (SSD)).

[0359] Those skilled in the art will recognize that the modules and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0360] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or modules may be electrical, mechanical, or other forms.

[0361] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical modules; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. For example, the functional modules in the various embodiments of this application may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.

[0362] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A model processing method, characterized in that, include: Acquire training data and the labels of the training data, and input the training data into a pre-trained first model, the first model comprising N multilayer perceptron (MLP) layers, where N is a positive integer greater than 1; For each of the N MLP layers, the MLP layer is perturbed based on the perturbation weights corresponding to the MLP layer to obtain the output result of the perturbed first model; Based on the output of the perturbated first model and the labels of the training data, the model loss of the perturbated first model is determined, and based on the model loss of the perturbated first model, the perturbation weights corresponding to the N MLP layers are trained and adjusted to obtain the target perturbation weights corresponding to the N MLP layers. Based on the target perturbation weights corresponding to the N MLP layers, K key MLP layers are determined from the N MLP layers, where K is a positive integer less than N.

2. The method according to claim 1, characterized in that, For each of the N MLP layers, based on the perturbation weights corresponding to the MLP layer, the MLP layer is perturbed to obtain the output result of the perturbed first model, including: Based on the perturbation weights corresponding to the MLP layer, the output information of the MLP layer is perturbed to obtain the output result of the perturbed first model.

3. The method according to claim 2, characterized in that, The step of perturbing the output information of the MLP layer based on the perturbation weights corresponding to the MLP layer to obtain the output result of the perturbed first model includes: For the i-th MLP layer among the N MLP layers, obtain the output information of the i-th MLP layer, where i is a positive integer less than or equal to N; Determine the perturbation noise value corresponding to the i-th MLP layer, and based on the perturbation noise value and the perturbation weight corresponding to the i-th MLP layer, perturb the output information of the i-th MLP layer to obtain the perturbation output information of the i-th MLP layer; The perturbation output information of the i-th MLP layer is input into the module connected to the i-th MLP layer for processing. This process is repeated sequentially to obtain the output result of the perturbated first model.

4. The method according to claim 3, characterized in that, Determining the perturbation noise value corresponding to the i-th MLP layer includes: Determine the mean and variance of the output information of the i-th MLP layer; Based on the mean and variance of the output information of the i-th MLP layer, determine the normal distribution of the output information of the i-th MLP layer; Randomly sample the normal distribution of the output information of the i-th MLP layer to obtain the perturbation noise value corresponding to the i-th MLP layer.

5. The method according to claim 3, characterized in that, The step of perturbing the output information of the i-th MLP layer based on the perturbation noise value and the perturbation weight corresponding to the i-th MLP layer to obtain the perturbed output information of the i-th MLP layer includes: The output information of the i-th MLP layer is multiplied by the perturbation weight corresponding to the i-th MLP layer to obtain the first product; The first data is subtracted from the perturbation weight corresponding to the i-th MLP layer, and then multiplied by the perturbation noise value to obtain the second product, where the first data is a positive integer; The sum of the first product and the second product is determined as the perturbation output information of the i-th MLP layer.

6. The method according to any one of claims 1-5, characterized in that, The determination of the model loss of the perturbed first model based on the output of the perturbed first model and the labels of the training data includes: Determine the first mutual information between the labels of the training data and the output of the perturbated first model; Based on the first mutual information, determine the first loss of the first model after the perturbation; Based on the first loss, the model loss of the first model after the perturbation is determined.

7. The method according to claim 6, characterized in that, The step of determining the first loss of the perturbated first model based on the first mutual information includes: The variational upper bound of the negative number of the first mutual information is determined as the first loss.

8. The method according to claim 6, characterized in that, The step of determining the model loss of the perturbed first model based on the first loss includes: The training data is processed by the first model to obtain the output result of the first model; Determine the second mutual information between the output of the first model and the output of the perturbated first model; Based on the second mutual information, the second loss of the first model is determined; Based on the first loss and the second loss, the model loss of the first model after the perturbation is determined.

9. The method according to claim 8, characterized in that, The step of determining the second loss of the first model based on the second mutual information includes: The variational upper bound of the second mutual information is determined as the second loss.

10. The method according to claim 8, characterized in that, The step of determining the model loss of the perturbed first model based on the first loss and the second loss includes: Determine the average value of the perturbation weights corresponding to the N MLP layers respectively; The model loss of the first model after perturbation is determined based on the average of the first loss, the second loss, and the perturbation weights.

11. The method according to claim 10, characterized in that, Determining the model loss of the perturbed first model based on the average of the first loss, the second loss, and the perturbation weights includes: Multiply the second loss by the first hyperparameter to obtain the third product; The average value of the perturbation weights is multiplied by the second hyperparameter to obtain the fourth product; The sum of the first loss, the third product, and the fourth product is determined as the model loss of the perturbated first model.

12. The method according to any one of claims 1-5 and 7-11, characterized in that, The perturbation weights corresponding to the N MLP layers are trained and adjusted based on the model loss of the perturbated first model to obtain the target perturbation weights corresponding to the N MLP layers, including: Based on the model loss of the first model after perturbation, the perturbation weights corresponding to the N MLP layers are trained and adjusted to obtain the adjusted perturbation weights corresponding to the N MLP layers. The training data is input into the first model, and based on the adjusted perturbation weights corresponding to the N MLP layers included in the first model, the output information of each of the N MLP layers is perturbed to obtain the output result of the perturbed first model. Based on the output of the perturbated first model and the labels of the training data, the model loss of the perturbated first model is determined. Based on the model loss of the perturbated first model, the adjusted perturbation weights corresponding to the N MLP layers are retrained and adjusted. This process is repeated to obtain the perturbation weights of the N MLP layers under the training data. Based on the perturbation weights corresponding to the N MLP layers under the training data, the target perturbation weights corresponding to the N MLP layers are determined respectively.

13. The method according to claim 12, characterized in that, The step of determining the target perturbation weights corresponding to the N MLP layers based on the perturbation weights corresponding to the N MLP layers under the training data includes: Determine the perturbation weights corresponding to the N MLP layers under P training data, where the P training data include the training data and P is a positive integer of size 1; Based on the perturbation weights corresponding to the N MLP layers under P training data, the target perturbation weights corresponding to the N MLP layers are determined.

14. The method according to claim 13, characterized in that, The step of determining the target perturbation weights corresponding to the N MLP layers based on the perturbation weights corresponding to the N MLP layers under P training data includes: For the j-th MLP layer among the N MLP layers, the average value of the perturbation weights corresponding to the j-th MLP layer under the P training data is determined as the target perturbation weight corresponding to the j-th MLP layer, where j is a positive integer less than or equal to N.

15. The method according to any one of claims 1-5, 7-11, and 13-14, characterized in that, The process of determining K key MLP layers from the N MLP layers based on the target perturbation weights corresponding to each of the N MLP layers includes: Based on the target perturbation weights corresponding to the N MLP layers, the K key MLP layers with the largest target perturbation weights are determined from the N MLP layers.

16. The method according to any one of claims 1-5, 7-11, and 13-14, characterized in that, The method further includes: Based on the K key MLP layers in the first model, the first model is edited to obtain the second model.

17. A model processing device, characterized in that, include: An acquisition unit is used to acquire training data and the labels of the training data, and input the training data into a pre-trained first model, wherein the first model includes N multilayer perceptron (MLP) layers, where N is a positive integer; The perturbation unit is used to perturb each of the N MLP layers based on the perturbation weights corresponding to the MLP layer, and obtain the output result of the perturbated first model. The training unit is used to determine the model loss of the perturbed first model based on the output of the perturbed first model and the label of the training data, and to train and adjust the perturbation weights corresponding to the N MLP layers based on the model loss of the perturbed first model, so as to obtain the target perturbation weights corresponding to the N MLP layers respectively. The selection unit is used to determine K key MLP layers from the N MLP layers based on the target perturbation weights corresponding to the N MLP layers respectively, where K is a positive integer less than N.

18. An electronic device, comprising a processor and a memory; The memory is used to store computer programs; The processor is configured to execute the computer program to implement the method as described in any one of claims 1 to 16.

19. A computer-readable storage medium, characterized in that, Used to store computer programs; The computer program causes the computer to perform the method as described in any one of claims 1 to 16.