Lightweight model updating method and device and medium
By setting patches and building a codebook in the feedforward neural network layer of the Transformer model, the problem of declining model accuracy in the power field was solved, enabling fast and accurate model updates and error correction.
Patent Information
- Application Number
- CN202510711985.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-29
- Publication Date
- 2025-10-31
AI Technical Summary
In the power industry, the Transformer model suffers from decreased accuracy due to complex field environments and insufficient training data. Existing update methods require a large amount of labeled data and cannot correct errors in real time, resulting in low efficiency.
By setting a patch in the last feedforward neural network layer of the Transformer model, using error labeling and memory loss to train the patch, and combining a codebook to expand the error types, the model output is dynamically adjusted to correct errors.
It can quickly correct erroneous outputs without retraining the model, while maintaining the accuracy of other inputs to the model, thus enabling real-time model updates and error correction.
Smart Images

Figure CN120874908A_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of neural network model technology, and in particular to a lightweight model update method, device, and medium. Background Technology
[0002] The Transformer model architecture uses a Self-Attention structure instead of the RNN network structure commonly used in NLP tasks. Its biggest advantage over the RNN network structure is its ability to be computed in parallel.
[0003] Currently, the Transformer architecture is widely used in the power industry. For example, Chinese patent documents with publication numbers CN119962582A, CN119906010A, and CN119443751B all use the Transformer model for power load forecasting.
[0004] However, with the development of artificial intelligence models, models for detecting visual defects, identifying early insulation conditions of converter transformers, and recognizing abnormal acoustic signatures are widely used in various specialties of the power industry. Due to complex field environments and insufficient training data, unexpected situations may occur during field operation, leading to a decrease in model accuracy. This necessitates updating the models to cover emerging business conditions. With the application of cloud-edge collaboration technology, cloud and edge collaboration utilizes techniques such as model lightweighting, model compression, knowledge distillation, and knowledge transfer to update the parameters of cloud-edge models. Currently, the most common method is to incrementally learn the model using newly acquired data. By fine-tuning the model's parameters, new knowledge is learned while retaining old knowledge. This update method requires accumulating labeled datasets, modifying all model parameters, and cannot immediately correct model errors. It often requires a second round of manual processing. Summary of the Invention
[0005] To overcome the above problems, this disclosure provides a method, apparatus, and medium for updating a lightweight model.
[0006] The technical solution disclosed herein is as follows:
[0007] In a first aspect, this disclosure provides a lightweight model update method. The Transformer model includes an encoder and a decoder, each of which includes a multi-head attention layer and a feedforward neural network layer, and further includes:
[0008] When updating the Transformer model and encountering an error output, check if a corresponding error flag exists for the error type of the error output:
[0009] If it does not exist, generate an error flag for the error type, freeze the parameters of the Transformer model, and set the patch corresponding to the error type in the last feedforward neural network layer of the Transformer model;
[0010] If present, apply the patch in the last feedforward neural network layer of the Transformer model;
[0011] When the patch takes effect, it adjusts the erroneous output to make the output correct.
[0012] Furthermore, when the patch takes effect under the following conditions, it will be output in the following manner:
[0013] FFN p (q)=FFN(q)+a p ·v p ;
[0014] Among them, FFN p (q) represents the output of the last feedforward neural network layer after the patch takes effect, and FFN(q) represents the output of the last feedforward neural network layer before the patch takes effect. p v is the activation value for the patch. p For patch value, v p ∈R d R d Let q be the d-dimensional input space, and q be the input query.
[0015] Furthermore, the activation value a of the patch p Specifically:
[0016] a p =Act(q·k) p +b p );
[0017] Where, k p For patch key, b p The patch biases the signal, and Act() is the activation function.
[0018] Furthermore, the patch is trained in the following manner:
[0019] When training the patch, the labels of the input samples and the original output of the Transformer model are used.
[0020] The loss is:
[0021] l p =l e +al a +ml m ;
[0022] Among them, le Here are the labels of the input samples, a and m are hyperparameters, and l a The original output of the Transformer model, l m This is due to memory loss.
[0023] Furthermore, memory loss m for:
[0024] l m =l m1 +l m2 ;
[0025] l m1 =S(M·k) p +b p -β;k);
[0026] l m2 =S((Mq) e )·k p +b p -γ;k);
[0027] Where M is a matrix of query examples unrelated to the patch, β is the activation threshold of the patch, and q e For incorrect input queries, γ is the interval value;
[0028] The function S(v;k) = Avg[TopK(exp(v);k)].
[0029] Furthermore, it also includes bug fixes for already deployed Transformer models, specifically:
[0030] Construct a codebook, which includes a key set, a value set, and a delay radius set;
[0031] The key set consists of keys, which are activated by the cache predicted by the l-1 layer of the Transformer model;
[0032] The value set consists of values, each of which is randomly initialized and updated by dynamically expanding and fine-tuning the loss using the model's knowledge. Each key corresponds to a value.
[0033] The delay radius set consists of delay radii, which are similarity matching thresholds, and each key corresponds to one delay radius;
[0034] When the delay constraint is met, add a key to the key set and adjust the value and the delay radius.
[0035] Furthermore, when the delay constraint is met, a key is added to the key set, and the value and the delay radius are adjusted:
[0036] Obtain the prediction result h of the layer preceding the last feedforward neural network layer. l-1 ;
[0037] Determine if the key is stored in the password book Satisfying the prediction result h l-1 AND key The Euclidean distance is less than the delay radius. If it exists, then for the key The associated codebook entry is dynamically expanded; if it does not exist, a new codebook entry is created (h l-1 ,v,ε init ,y).
[0038] Furthermore, if the new codebook entry overlaps with an existing codebook entry, the following steps are performed:
[0039] If the label of the new cryptographic entry is the same as the label of the knowledge dynamic expansion, then the delay radius of the existing cryptographic entry is expanded to include the prediction result h. l-1 ;
[0040] If the tag of the new ciphertext entry is different from the tag of the knowledge dynamic expansion, then reduce the delay radius of any one or more of the existing ciphertext entries and the new ciphertext entries.
[0041] Secondly, this disclosure provides an electronic device, including a data storage unit and a data processing unit, wherein the data processing unit updates the model according to the lightweight model update method described in the first aspect.
[0042] Thirdly, this disclosure provides a computer-readable storage medium on which a program stored is executed by a computer to implement the lightweight model update method as described in the first aspect.
[0043] This disclosure has the following beneficial effects:
[0044] This disclosure modifies the model output by patching neurons, correcting erroneous information or outdated knowledge in the model without retraining the entire model. The patent primarily adds neurons to the FFN layer of the Transformer, keeping other neurons unchanged. By combining erroneous and correct inputs with the original model loss, the training loss of the patched neurons is reconstructed, thereby determining the parameters of the patched neurons. This ensures the model only corrects erroneous inputs without affecting other inputs. Finally, a codebook is established using the delay radius, allowing for the continuous expansion of error types during model execution. Attached Figure Description
[0045] Figure 1 This is a flowchart of a method according to an embodiment of the present disclosure. Detailed Implementation
[0047] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the described embodiments of this disclosure without creative effort are within the scope of protection of this disclosure.
[0048] Unless otherwise defined, the technical or scientific terms used in this disclosure shall have the ordinary meaning understood by one of ordinary skill in the art to which this disclosure pertains. The terms "first," "second," and similar terms used in this disclosure do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Terms such as "comprising" or "including" mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects. Terms such as "connected" or "linked" are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. Terms such as "upper," "lower," "left," and "right" are used only to indicate relative positional relationships, and these relative positional relationships may change accordingly when the absolute position of the described object changes. To keep the following description of the embodiments of this disclosure clear and concise, detailed descriptions of some known functions and components are omitted.
[0049] The present disclosure will now be described in detail with reference to the accompanying drawings and specific embodiments.
[0050] In a first aspect, this disclosure provides a lightweight model update method. The Transformer model includes an encoder and a decoder, each of which includes a multi-head attention layer and a feedforward neural network layer, and further includes:
[0051] When updating the Transformer model and encountering an error output, check if a corresponding error flag exists for the error type of the error output:
[0052] If it does not exist, generate an error flag for the error type, freeze the parameters of the Transformer model, and set the patch corresponding to the error type in the last feedforward neural network layer of the Transformer model;
[0053] If present, apply the patch in the last feedforward neural network layer of the Transformer model;
[0054] When the patch takes effect, it adjusts the erroneous output to make the output correct.
[0055] The error markers correspond one-to-one with the error patches and are used to indicate the error type of the error output.
[0056] Furthermore, when the patch takes effect under the following conditions, it will be output in the following manner:
[0057] FFN p (q)=FFN(q)+a p ·v p ;
[0058] Among them, FFN p (q) represents the output of the last feedforward neural network layer after the patch takes effect, and FFN(q) represents the output of the last feedforward neural network layer before the patch takes effect. p v is the activation value for the patch. p For patch value, v p ∈R d R d Let q be the d-dimensional input space, and q be the input query.
[0059] Furthermore, the activation value a of the patch p Specifically:
[0060] a p =Act(q·k) p +b p );
[0061] Where, k p For patch key, b p The patch biases the signal, and Act() is the activation function.
[0062] Furthermore, the patch is trained in the following manner:
[0063] When training the patch, the labels of the input samples and the original output of the Transformer model are used.
[0064] The loss is:
[0065] l p =l e +al a +ml m ;
[0066] Among them, l e Here are the labels of the input samples, a and m are hyperparameters, and l a The original output of the Transformer model, l m This is due to memory loss.
[0067] Furthermore, memory loss m for:
[0068] lm =l m1 +l m2 ;
[0069] l m1 =S(M·k) p +b p -β;k);
[0070] l m2 =S((Mq) e )·k p +b p -γ;k);
[0071] Where M is a matrix of query examples unrelated to the patch, β is the activation threshold of the patch, and q e For incorrect input queries, γ is the interval value;
[0072] The function S(v;k) = Avg[TopK(exp(v);k)].
[0073] This method uses memory loss m To enforce constraints, this method randomly retains some queries from previously seen examples as memory. Each query is a d-dimensional vector, and this method can stack them into a matrix M∈R. {d ×d} , where d m This refers to the number of queries saved. Memory loss. m It is the sum of two terms. The first term is l. m1 Introduced to deactivate all queries in M through the patch, in order to ensure l m1 The constraints are absolutely satisfied; this patent uses l m2 This is to create a certain interval γ between the activation values of erroneous examples and the activation values of irrelevant examples.
[0074] Where S(·k) is a function that takes a vector v and outputs a scalar function S(v;k) = Avg[TopK(exp(v);k)], which first applies an element-wise exponential function to v, then selects the k largest elements and calculates their average as the output. Although the constraint is about the maximum value, this patent uses TopK to achieve more efficient optimization. β is the activation threshold of the patch, q e The query was entered incorrectly.
[0075] Furthermore, it also includes bug fixes for already deployed Transformer models, specifically:
[0076] Construct a codebook, which includes a key set, a value set, and a delay radius set;
[0077] The key set consists of keys, which are activated by the cache predicted by the l-1 layer of the Transformer model;
[0078] The value set consists of values, each of which is randomly initialized and updated by dynamically expanding and fine-tuning the loss using the model's knowledge. Each key corresponds to a value.
[0079] The delay radius set consists of delay radii, which are similarity matching thresholds, and each key corresponds to one delay radius;
[0080] When the delay constraint is met, add a key to the key set and adjust the value and the delay radius.
[0081] Furthermore, when the delay constraint is met, a key is added to the key set, and the value and the delay radius are adjusted:
[0082] Obtain the prediction result h of the layer preceding the last feedforward neural network layer. l-1 ;
[0083] Determine if the key is stored in the password book Satisfying the prediction result h l-1 AND key The Euclidean distance is less than the delay radius. If it exists, then for the key The associated codebook entry is dynamically expanded; if it does not exist, a new codebook entry is created (h l-1 ,v,ε init ,y).
[0084] Furthermore, if the new codebook entry overlaps with an existing codebook entry, the following steps are performed:
[0085] If the label of the new cryptographic entry is the same as the label of the knowledge dynamic expansion, then the delay radius of the existing cryptographic entry is expanded to include the prediction result h. l-1 ;
[0086] If the tag of the new ciphertext entry is different from the tag of the knowledge dynamic expansion, then reduce the delay radius of any one or more of the existing ciphertext entries and the new ciphertext entries.
[0087] In this implementation, the tags and knowledge dynamic expansion tags include error types. If the error type of a new codebook entry is different from that of an existing codebook entry, a new codebook entry is created. Otherwise, the new codebook entry is merged with the existing codebook entry.
[0088] Secondly, this disclosure provides an electronic device, including a data storage unit and a data processing unit, wherein the data processing unit updates the model according to the lightweight model update method described in the first aspect.
[0089] Thirdly, this disclosure provides a computer-readable storage medium on which a program stored is executed by a computer to implement the lightweight model update method as described in the first aspect.
[0090] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0091] The units described in the embodiments of this disclosure can be implemented in software or hardware. The names of the units are not, in some cases, intended to limit the specific unit.
[0092] The functions described above in this document can be performed, at least in part, by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: Field Programmable Gate Arrays (FPGAs), Application-Specific Integrated Circuits (ASICs), Application Standard Products (ASSPs), System-on-Chip (SoCs), Complex Programmable Logic Devices (CPLDs), and so on.
[0093] The above description is merely a preferred embodiment of this disclosure and an explanation of the technical principles employed. Those skilled in the art should understand that the scope of this disclosure is not limited to technical solutions formed by specific combinations of the above-described technical features, but should also cover other technical solutions formed by arbitrary combinations of the above-described technical features or their equivalents without departing from the above-described concept. For example, technical solutions formed by substituting the above features with (but not limited to) technical features disclosed in this disclosure that have similar functions.
[0094] Furthermore, while the operations are described in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of this disclosure. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.
[0095] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.
[0096] The following points should be noted regarding this disclosure:
[0097] (1) The accompanying drawings of the embodiments of this disclosure only involve the structures involved in the embodiments of this disclosure. Other structures can be referred to the general design.
[0098] (2) Where there is no conflict, the embodiments of this disclosure and the features in the embodiments can be combined with each other to obtain new embodiments.
[0099] The above description is merely an embodiment of this disclosure and does not limit the patent scope of this disclosure. Any equivalent structure made using the content of this disclosure and its drawings, or directly or indirectly applied to other related technical fields, is similarly included within the patent protection scope of this disclosure.
Claims
1. A lightweight model update method, wherein the Transformer model includes an encoder and a decoder, the encoder and the decoder each including a multi-head attention layer and a feedforward neural network layer, characterized in that, include: When updating the Transformer model and encountering an error output, check if a corresponding error flag exists for the error type of the error output: If it does not exist, generate an error flag for the error type, freeze the parameters of the Transformer model, and set the patch corresponding to the error type in the last feedforward neural network layer of the Transformer model; If present, apply the patch in the last feedforward neural network layer of the Transformer model; When the patch takes effect, it adjusts the erroneous output to make the output correct.
2. The lightweight model update method according to claim 1, characterized in that, When the patch takes effect under the following conditions, it will be output in the following manner: FFN p (q)=FFN(q)+a p v p ; Among them, FFN p (q) represents the output of the last feedforward neural network layer after the patch takes effect, and FFN(q) represents the output of the last feedforward neural network layer before the patch takes effect. p v is the activation value for the patch. p For patch value, v p ∈R d R d Let q be the d-dimensional input space, and q be the input query.
3. The lightweight model update method according to claim 2, characterized in that, Patch activation value a p Specifically: a p =Act(q·k p +b p ); Where, k p For patch key, b p The patch biases the signal, and Act() is the activation function.
4. The lightweight model update method according to claim 3, characterized in that, The patch is trained using the following method: When training the patch, the loss based on the input sample labels and the original output of the Transformer model is: l p =l e +al a +ml m ; Among them, l e Here are the labels of the input samples, a and m are hyperparameters, and l a The original output of the Transformer model, l m This is due to memory loss.
5. The lightweight model update method according to claim 4, characterized in that, Memory loss m for: l m =l m1 +l m2 ; l m1 =S(M·k p +b p -b;k); l m2 =S((M-q e )·k p +b p -γ;k); Where M is a matrix of query examples unrelated to the patch, β is the activation threshold of the patch, and q e For incorrect input queries, γ is the interval value; The function S(v;k) = Avg[TopK(exp(v);k)].
6. The lightweight model update method according to claim 5, characterized in that, This also includes bug fixes for already deployed Transformer models, specifically: Construct a codebook, which includes a key set, a value set, and a delay radius set; The key set consists of keys, which are activated by the cache predicted by the l-1 layer of the Transformer model; The value set consists of values, each randomly initialized, and updated by dynamically expanding and fine-tuning the loss using the model's knowledge. Each key corresponds to one value; The delay radius set consists of delay radii, which are similarity matching thresholds, and each key corresponds to one delay radius; When the delay constraint is met, add a key to the key set and adjust the value and the delay radius.
7. The lightweight model update method according to claim 6, characterized in that, When the delay constraint is met, add a key to the key set and adjust the value and the delay radius: Obtain the prediction result h of the layer preceding the last feedforward neural network layer. l-1 ; Determine if the key is stored in the password book Satisfying the prediction result h l-1 AND key The Euclidean distance is less than the delay radius. If it exists, then for the key The associated codebook entry is dynamically expanded; if it does not exist, a new codebook entry is created.
8. The lightweight model update method according to claim 6, characterized in that, If the new passwordbook entry overlaps with an existing passwordbook entry, perform the following steps: If the label of the new cryptographic entry is the same as the label of the knowledge dynamic expansion, then the delay radius of the existing cryptographic entry is expanded to include the prediction result h. l-1 ; If the tag of the new ciphertext entry is different from the tag of the knowledge dynamic expansion, then reduce the delay radius of any one or more of the existing ciphertext entries and the new ciphertext entries.
9. An electronic device comprising a data storage unit and a data processing unit, characterized in that, The data processing unit updates the model according to any one of the lightweight model update methods described in claims 1-8.
10. A computer-readable storage medium, characterized in that, When the program stored thereon is executed by a computer, it implements the lightweight model update method as described in any one of claims 1-8.
Citation Information
Patent Citations
Power load forecasting method based on large language model and socio-demographic information
CN119443751B
Power load prediction method and system
CN119906010A
Non-intrusive load monitoring method based on hybrid federated learning and cross Transform
CN119962582A
