Model training method and device
By updating only the N parameters that have the greatest impact on data processing accuracy in the neural network model and performing data compression, the problems of large data volume and reduced capability when updating the neural network model are solved, and efficient model updating and capability maintenance are achieved.
Patent Information
- Application Number
- CN202110475677.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-29
- Publication Date
- 2025-09-16
- Estimated Expiration
- 2041-04-29
AI Technical Summary
Neural network models have a large number of parameters when being updated, which results in the patch or update package data volume being too large for the training device to issue, and there is a problem that the model may lose its original capabilities after the update.
By selecting the N parameters in the neural network model that have the greatest impact on data processing accuracy for update, and taking advantage of the small change in parameter values to compress data, only the updated N parameters are transmitted to ensure that the model still has its original capabilities after the update.
This reduces the amount of data transmitted when the model is updated, while ensuring that the model can maintain its original task processing capabilities after the update, avoiding catastrophic forgetting.
Smart Images

Figure CN113240079B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence, and in particular to a model training method and device. Background Art
[0002] Artificial intelligence (AI) refers to the theories, methods, technologies, and application systems that use digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, to perceive the environment, acquire knowledge, and use that knowledge to achieve optimal results. In other words, AI is a branch of computer science that seeks to understand the essence of intelligence and develop new intelligent machines that can respond in a manner similar to human intelligence. AI also studies the design principles and implementation methods of various intelligent machines, enabling them to possess the capabilities of perception, reasoning, and decision-making.
[0003] In recent years, neural networks have achieved superior performance in a series of machine learning tasks, and can be specifically applied in multiple fields such as images, language, voice, and video. The server can train a pre-trained model (or a model obtained by fine-tuning and updating the pre-trained model at least once. For the convenience of description, in this embodiment, the above-mentioned pre-trained model and the model obtained after fine-tuning the pre-trained model at least once are referred to as the first neural network model, or the neural network model to be updated), and deploy the above-mentioned first neural network model on the model user end such as the terminal device. However, in some scenarios, the first neural network model may need to be updated due to security issues or changes in requirements. For example, the first neural network model is used to implement a translation task, and when it is found that the first neural network model has a certain specific translation error, the first neural network model needs to be corrected. For example, the first neural network model is used to implement a face recognition task, and when it is found that the first neural network model has an error in recognizing the face of a specific person, the first neural network model needs to be corrected. In addition, the first neural network model can also be fine-tuned based on the private data of the model user end.
[0004] However, the number of parameters in a neural network is very large, and all parameters need to be modified during fine-tuning. Therefore, the amount of data in the patches or update packages issued by the training device is very large. Summary of the Invention
[0005] In a first aspect, the present application provides a model training method, the method comprising:
[0006] Obtaining a first neural network model and a training sample, where the first neural network model includes M parameters;
[0007] The first neural network model may include M parameters, and the M parameters may be all or part of the parameters that need to be updated in the first neural network model. It should be understood that the M parameters may be parameters that account for more than 90 percent of all the parameters that need to be updated in the first neural network model.
[0008] It should be understood that in addition to M parameters, the first neural network model may also include other parameters that may need to be updated. Even if these parameters have little impact on the data processing accuracy of the first neural network model for the target task, they can still be updated during model training. Optionally, these parameters account for a very small proportion in the first neural network model.
[0009] The first neural network model is trained according to the training samples to update N parameters of the M parameters until the data processing accuracy of the first neural network model meets a preset condition, thereby obtaining a second neural network model; wherein N is a positive integer less than M, and the N parameters are determined based on the ability of each parameter of the M parameters to affect the data processing accuracy.
[0010] From the inference side of the model, only a small number of parameters in the neural network model play an important role in achieving the target task. When the values of these parameters change or are removed from the neural network model, the data processing accuracy of the neural network model for the target task will drop significantly.
[0011] From the perspective of model training, in order to achieve the target task, only a small number of parameters in the neural network model need to undergo large numerical updates (or have large numerical changes), or only a small number of parameters in the neural network model have large update gradients, or only a small number of parameters in the neural network model have a large contribution to reducing the loss function used in model training.
[0012] It should be understood that the above-mentioned numerical change can be understood as the numerical change amplitude of the parameter during one iterative training process in the training process, or determined by the numerical change amplitude of the parameter during multiple iterative training processes in the comprehensive training process, or the numerical change amplitude of the parameter compared with the pre-training process after the model training converges.
[0013] It should be understood that the above-mentioned update gradient can be understood as the update gradient of the parameters in one iterative training process in the training process, or can be determined by the update gradient of the parameters in multiple iterative training processes in the comprehensive training process.
[0014] It should be understood that the contribution of the above parameters to the reduction of the loss function used in model training can be understood as the contribution of the parameters to the reduction of the loss function used in model training during a single iterative training process, or the contribution of the parameters to the reduction of the loss function used in model training during multiple iterative training processes in a comprehensive training process. For example, the contribution of the above parameters to the reduction of the loss function used in model training can be expressed based on the loss change allocation (LCA) indicator.
[0015] In the embodiment of the present application, under the premise of ensuring that the data processing accuracy of the model meets the accuracy requirements, since only N parameters out of the M parameters in the updated first neural network model are updated, the amount of data transmitted from the training device to the terminal device can be reduced; in addition, when the first neural network model is a pre-trained model, the model has some basic functions in the field to which it belongs, or is a model having other functions in addition to the above-mentioned basic functions obtained by fine-tuning the pre-trained model, since only a small part of the parameters in the first neural network model are updated in the embodiment of the present application, it can be ensured that the first neural network model will not lose its original capabilities, that is, it can be ensured that the original task processing capabilities of the first neural network model will not decline or will not decline much, that is, it is ensured that the first neural network model will not have the problem of catastrophic forgetting (consistency is used in subsequent embodiments to quantify whether the first neural network model maintains its original capabilities).
[0016] In a possible implementation, in the second neural network model, parameters other than the N parameters among the M parameters are not updated.
[0017] In a possible implementation, the N parameters are the N parameters that have the greatest impact on the data processing accuracy of the first neural network model among the M parameters; or,
[0018] The N parameters are N parameters among the M parameters whose influence on the data processing accuracy of the first neural network model is greater than a threshold.
[0019] In a possible implementation, the ratio of N to M is less than 10%.
[0020] It should be understood that the number N can be very small. In one implementation, the ratio of N to M is less than 10%. The number N can be different for different tasks. For example, for image classification tasks, the ratio of N to M can be less than 1 / 1000.
[0021] In a possible implementation, before updating N parameters of the M parameters according to the training sample, the method further includes:
[0022] A model update indication is received from a terminal device, where the model update indication is used to indicate an update of N number of parameters in the first neural network model; or, the model update indication is used to indicate an update of a target ratio of parameters in the first neural network model.
[0023] In one possible implementation, N may be specified by a terminal device on which the first neural network model is deployed.
[0024] For example, before training the first neural network model, the user can choose how many parameters in the first neural network model need to be updated. The user can send the number of parameters or parameter ratios that need to be updated to the training device through the terminal device, and the training device can select N parameters from M parameters.
[0025] Specifically, from the perspective of the training device, a model update indication sent by the terminal device can be received, and the model update indication is used to indicate the update of the parameters of the first neural network model, the number of which is N; or, the model update indication is used to indicate the update of the parameters of the target ratio in the first neural network model, wherein the product of the M parameters in the first neural network model and the target ratio is N.
[0026] In a possible implementation, the second neural network model includes the updated N parameters. After obtaining the second neural network model, the method further includes:
[0027] Obtaining model update information; wherein the model update information includes a numerical change of each parameter of the M parameters in the second neural network model compared to before the update;
[0028] compressing the model update information to obtain compressed model update information; optionally, the compression may be used to remove redundancy of a value of 0;
[0029] Send the compressed model update information to the terminal device.
[0030] In an embodiment of the present application, since only N parameters out of the M parameters in the second neural network model are updated, the numerical changes of these N parameters are not 0, while the numerical changes of the other parameters except N parameters out of the M parameters are 0. In order to reduce the amount of data transmitted from the training device to the terminal device, it is necessary to reduce the data volume of the model update information. In one implementation, the model update information can be generated based on the numerical changes of each parameter. Since the numerical changes of most parameters among the numerical changes of each parameter are 0, the existing mainstream data compression algorithm can remove redundancy of the value 0, so the data volume of the compressed model update information is very small.
[0031] Specifically, model update information can be obtained; wherein, the model update information includes the numerical change of each parameter in the M parameters in the second neural network model, and the model update information can be compressed to obtain compressed model update information, wherein the compression is used to remove redundancy of the value 0, and the compressed model update information is sent to the terminal device. After receiving the compressed model update information, the terminal device can decompress the compressed model update information to obtain the numerical change of each parameter in the M parameters.
[0032] In a possible implementation, after obtaining the second neural network model, the method further includes:
[0033] Sending model update information to the terminal device; wherein the model update information includes the updated N parameters, and the model update information does not include parameters other than the N parameters in the M parameters.
[0034] In order to reduce the data volume of the model update information, in another implementation, the model update information can be generated based on N parameters (which can be the update results or numerical changes of N parameters). Since N is very small, the data volume of the compressed model update information is very small.
[0035] Specifically, model update information may be sent to the terminal device; wherein the model update information includes the updated N parameters, and the model update information does not include parameters other than the N parameters in the M parameters.
[0036] In one possible implementation, the training sample is related to a target task, the data processing accuracy is the data processing accuracy of the first neural network model for the target task, and the ability of each parameter to influence the data processing accuracy is positively correlated with at least one of the following information:
[0037] When the first neural network model is trained for the target task, the update gradient corresponding to each parameter; or
[0038] When the first neural network model is trained for the target task, the numerical change corresponding to each parameter; or
[0039] When the first neural network model is trained for the target task, the contribution of each parameter to the reduction of the loss function, where the loss function is the loss function used when updating the M parameters.
[0040] In a possible implementation, before training the first neural network model according to the training sample to update N parameters of the M parameters, the method further includes:
[0041] Training the first neural network model according to the training samples to update the M parameters and determine the influence of each of the M parameters on the data processing accuracy;
[0042] According to the ability of each parameter in the M parameters to affect the data processing accuracy, N parameters are determined from the M parameters. In one implementation, all M parameters in the first neural network model can be updated to train a reference model (which may also be referred to as the third neural network model in this embodiment), and then based on the reference model, which parameters contribute more to the training are determined. These determined parameters can be considered as the N parameters that have the greatest impact on the data processing accuracy of the first neural network model for the target task.
[0043] Furthermore, the first neural network model can be retrained based on the training samples to update N parameters among the M parameters, and when the first neural network model is retrained, the parameters among the M parameters other than the N parameters are not updated.
[0044] After determining N parameters based on the above reference model, these important parameters (N parameters) can be selected for training, and only these parameters are trained to achieve sparse parameter updates. Specifically, the first neural network model can be trained based on the training samples to update N parameters among the M parameters, and when training the first neural network model, the parameters among the M parameters other than the N parameters are not updated.
[0045] In a possible implementation, training the first neural network model according to the training sample to update N parameters of the M parameters includes:
[0046] The first neural network model is trained based on the training samples to update the M parameters and determine the influence of each of the M parameters on the data processing accuracy; N parameters are determined from the M parameters based on the influence of each of the M parameters on the data processing accuracy; and the other parameters of the updated M parameters except the N parameters are restored to the corresponding parameter values in the first neural network model.
[0047] Specifically, the first neural network model may be trained based on the training sample to update M parameters, wherein the ability of each of the M parameters to influence the data processing accuracy is positively correlated with at least one of the following information:
[0048] During the training of the first neural network model, the update gradient corresponding to each parameter; or, during the training of the first neural network model, the numerical change corresponding to each parameter; or, during the training of the first neural network model, the contribution of each parameter to the reduction of the loss function, where the loss function is the loss function used when training the first neural network model.
[0049] In one implementation, during the process of updating the M parameters, it can be determined which parameter updates among the M parameters will be retained (or called the updates taking effect), and which parameter updates will not be retained (or called the updates not taking effect, or described as being restored to the corresponding parameter values in the first neural network model, that is, the parameter values before training are still retained). Specifically, the first neural network model can be trained according to the training samples, and N parameters among the M parameters can be updated. In the process of training the first neural network model according to the training samples, it can be determined which parameter updates (N parameters) will be retained based on the ability of each parameter to influence the data processing accuracy of the first neural network model for the target task.
[0050] For example, at the beginning of training the first neural network model, all parameters in the first neural network model (e.g., the M parameters mentioned above) can be added to the updateable parameter set. When training the first neural network model, each parameter in the updateable parameter set will be updated. After a certain number of model training steps, the importance of each parameter in the updateable parameter set for the model update (i.e., the influence of the parameter on the data processing accuracy of the first neural network model for the target task) can be calculated based on the model training process of the above number of steps. The indicator for measuring the importance of the parameter can be the update gradient or change amplitude of different parameters during the training process, etc., and then a certain proportion of unimportant parameters are restored to the original parameter value (i.e., the update of these parameters is not effective), and they are removed from the updateable parameter set. The above process is repeated, and N parameters can be selected. During the training process of the first neural network model, the updates of these N parameters are retained, and although the parameters other than the N parameters in the M parameters can be updated during the training process, the updates are not retained.
[0051] In a possible implementation, training the first neural network model according to the training sample to update N parameters of the M parameters includes:
[0052] According to the training samples, the first neural network model is trained through a preset loss function to update N parameters among the M parameters; wherein the preset loss function includes a target loss term, and the target loss term is used to constrain the update amplitude of the parameters.
[0053] Optionally, in one implementation, the ability of the parameter to influence the data processing accuracy of the model can be represented by the numerical change when the parameter is updated, and a regularization term (which may be referred to as a target loss term in the embodiment of the present application) can be added to the loss function used in the training of the first neural network model. The regularization term can constrain the update amplitude of the parameters. After each iteration or a certain number of iterative training steps, the update of the parameters whose numerical change when updated is greater than the threshold is retained, while the update of the parameters whose numerical change when updated is less than the threshold is not retained. Moreover, since there is a regularization term in the loss function for constraining the update amplitude of the parameters, the update amplitude of the parameters with less influence on the data processing accuracy of the model can be made smaller, thereby preventing the update of these parameters (MN parameters) from being retained, and only retaining the update of N parameters.
[0054] In a possible implementation, the training sample is text data, image data, or audio data.
[0055] In a possible implementation, the second neural network model is used to process the data to be processed to obtain a data processing result, and the data to be processed is text data, image data or audio data.
[0056] In a second aspect, an embodiment of the present application provides a parameter configuration method for model update, the method comprising:
[0057] Displaying a configuration interface, the configuration interface including a first control, the first control being used to instruct a user to input a number or ratio of parameters that need to be updated in the first neural network model;
[0058] Obtaining a target quantity or a target ratio input by a user through the first control;
[0059] A model update indication is sent to the server, where the model update indication includes the target quantity or target ratio, and the target quantity or target ratio is used to indicate that a parameter of the target quantity or target ratio in the first neural network model is updated when training the first neural network model.
[0060] In a possible implementation, after sending the model update indication to the server, the method further includes:
[0061] receiving the compressed model update information sent by the server, and decompressing the compressed model update information to obtain the model update information; wherein,
[0062] The model update information includes multiple parameters, and the multiple parameters are obtained by updating the parameters of the target quantity or target ratio, and the difference between the number of parameters included in the model update information and the target number is within a preset range; or, the ratio of the number of parameters included in the model update information to the number of parameters included in the first neural network model and the target ratio are within a preset range.
[0063] In a possible implementation, after sending the model update indication to the server, the method further includes:
[0064] receiving the compressed model update information sent by the server, and decompressing the compressed model update information to obtain the model update information; wherein,
[0065] The model update information includes numerical changes of multiple parameters, and the numerical changes of the multiple parameters are numerical changes of updating multiple parameters in the first neural network model.
[0066] In a third aspect, an embodiment of the present application provides a model training device, the device comprising:
[0067] An acquisition module, configured to acquire a first neural network model and a training sample, wherein the first neural network model includes M parameters;
[0068] A model updating module is used to train the first neural network model based on the training samples to update N parameters of the M parameters until the data processing accuracy of the first neural network model meets a preset condition, thereby obtaining a second neural network model; wherein N is a positive integer less than M, and the N parameters are determined based on the ability of each parameter of the M parameters to affect the data processing accuracy.
[0069] In a possible implementation, in the second neural network model, parameters other than the N parameters among the M parameters are not updated.
[0070] In a possible implementation, the N parameters are the N parameters that have the greatest impact on the data processing accuracy of the first neural network model among the M parameters; or,
[0071] The N parameters are N parameters among the M parameters whose influence on the data processing accuracy of the first neural network model is greater than a threshold.
[0072] In a possible implementation, the ratio of N to M is less than 10%.
[0073] In one possible implementation, the apparatus further includes: a receiving module configured to receive a model update indication sent by a terminal device before training the first neural network model according to the training sample to update N of the M parameters, wherein the model update indication is used to indicate an update of the N number of parameters in the first neural network model; or, the model update indication is used to indicate an update of the target proportion of parameters in the first neural network model.
[0074] In a possible implementation, the second neural network model includes the updated N parameters, and the acquisition module is further configured to:
[0075] After obtaining the second neural network model, obtaining model update information; wherein the model update information includes a numerical change of each parameter in the M parameters in the second neural network model compared to before the update;
[0076] The device further comprises:
[0077] A compression module, configured to compress the model update information to obtain compressed model update information;
[0078] The sending module is used to send the compressed model update information to the terminal device.
[0079] In one possible implementation, the sending module is used to send model update information to the terminal device after obtaining the second neural network model; wherein the model update information includes the updated N parameters, and the model update information does not include parameters other than the N parameters in the M parameters.
[0080] In one possible implementation, the training sample is related to a target task, the data processing accuracy is the data processing accuracy of the first neural network model for the target task, and the ability of each parameter to influence the data processing accuracy is positively correlated with at least one of the following information:
[0081] When the first neural network model is trained for the target task, the update gradient corresponding to each parameter; or
[0082] When the first neural network model is trained for the target task, the numerical change corresponding to each parameter; or
[0083] When the first neural network model is trained for the target task, the contribution of each parameter to the reduction of the loss function, where the loss function is the loss function used when updating the M parameters.
[0084] In a possible implementation, the model updating module is further used to train the first neural network model according to the training samples to update the M parameters before training the first neural network model according to the training samples to update N parameters of the M parameters, and determine the influence of each parameter of the M parameters on the data processing accuracy; and determine N parameters from the M parameters according to the influence of each parameter of the M parameters on the data processing accuracy.
[0085] In one possible implementation, the model updating module is specifically configured to train the first neural network model based on the training sample to update the M parameters and determine the influence of each of the M parameters on the data processing accuracy;
[0086] Determining N parameters from the M parameters according to the influence of each parameter in the M parameters on the data processing accuracy;
[0087] Restoring the other parameters of the updated M parameters except the N parameters to the corresponding parameter values in the first neural network model.
[0088] In a possible implementation, the model updating module is specifically configured to train the first neural network model according to the training sample and update N parameters of the M parameters;
[0089] The training of the first neural network model for the target task includes:
[0090] The first neural network model is trained based on the training samples.
[0091] In one possible implementation, the model update module is specifically used to train the first neural network model according to the training sample through a preset loss function to update N parameters of the M parameters; wherein the preset loss function includes a target loss term, and the target loss term is used to constrain the update amplitude of the parameters.
[0092] In a possible implementation, the training sample is text data, image data, or audio data.
[0093] In a possible implementation, the second neural network model is used to process the data to be processed to obtain a data processing result, and the data to be processed is text data, image data or audio data.
[0094] In a fourth aspect, the present application provides a parameter configuration device for model updating, the device comprising:
[0095] A display module, configured to display a configuration interface, wherein the configuration interface includes a first control, and the first control is configured to instruct a user to input a number or a ratio of parameters that need to be updated in the first neural network model;
[0096] an acquisition module, configured to acquire a target quantity or a target ratio input by a user through the first control;
[0097] A sending module is used to send a model update indication to the server, where the model update indication includes the target quantity or target ratio, and the target quantity or target ratio is used to indicate that when training the first neural network model, the parameters of the target quantity or target ratio in the first neural network model are updated.
[0098] In a possible implementation, the apparatus further includes: a receiving module configured to, after sending the model update indication to the server, receive compressed model update information sent by the server, and decompress the compressed model update information to obtain the model update information; wherein,
[0099] The model update information includes multiple parameters, and the multiple parameters are obtained by updating the parameters of the target quantity or target ratio, and the difference between the number of parameters included in the model update information and the target number is within a preset range; or, the ratio of the number of parameters included in the model update information to the number of parameters included in the first neural network model and the target ratio are within a preset range.
[0100] In a possible implementation, the receiving module is further configured to, after sending the model update indication to the server, receive compressed model update information sent by the server, and decompress the compressed model update information to obtain the model update information; wherein,
[0101] The model update information includes numerical changes of multiple parameters, and the numerical changes of the multiple parameters are numerical changes of updating multiple parameters in the first neural network model.
[0102] In the fifth aspect, an embodiment of the present application provides a model training device, which may include a memory, a processor, and a bus system, wherein the memory is used to store programs, and the processor is used to execute the programs in the memory to execute any optional method as described in the first aspect above.
[0103] In the sixth aspect, an embodiment of the present application provides a parameter configuration device for model updating, which may include a memory, a processor, and a bus system, wherein the memory is used to store programs, and the processor is used to execute the programs in the memory to execute any optional method such as the second aspect above.
[0104] In the seventh aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer-readable storage medium is run on a computer, it enables the computer to execute any optional method of the first aspect and any optional method of the second aspect.
[0105] In an eighth aspect, an embodiment of the present application provides a computer program product, comprising code, which, when executed, is used to implement any optional method of the first aspect and any optional method of the second aspect.
[0106] In a ninth aspect, the present application provides a chip system comprising a processor for supporting an execution device or a training device in implementing the functions described in the aforementioned aspects, such as transmitting or processing data or information involved in the aforementioned methods. In one possible design, the chip system further comprises a memory for storing program instructions and data necessary for the execution device or the training device. The chip system may consist of a single chip or may include a chip and other discrete components.
[0107] An embodiment of the present application provides a model training method, the method comprising: obtaining a first neural network model and a training sample, the first neural network model comprising M parameters; training the first neural network model according to the training sample to update N parameters of the M parameters until the data processing accuracy of the first neural network model meets a preset condition, thereby obtaining a second neural network model; wherein N is a positive integer less than M, and the N parameters are determined based on the ability of each parameter of the M parameters to affect the data processing accuracy. Through the above method, under the premise of ensuring that the data processing accuracy of the model meets the accuracy requirements, since only N parameters of the M parameters in the updated first neural network model are updated, the amount of data transmitted from the training device to the terminal device can be reduced. BRIEF DESCRIPTION OF THE DRAWINGS
[0108] Figure 1 A structural diagram of the main framework of artificial intelligence;
[0109] Figure 2 A schematic diagram of a system architecture provided in an embodiment of the present application;
[0110] Figure 3 This is an example of a model training method provided in an embodiment of the present application;
[0111] Figure 4 This is a schematic diagram of an embodiment of a configuration method for model training provided in an embodiment of the present application;
[0112] Figure 5 A schematic diagram of an interactive interface provided in an embodiment of the present application;
[0113] Figure 6 A schematic diagram of the process of updating and issuing a model provided in an embodiment of the present application;
[0114] Figure 7 A schematic diagram of a model training device provided in an embodiment of the present application;
[0115] Figure 8 A schematic diagram of a configuration device for model training provided in an embodiment of the present application;
[0116] Figure 9 A schematic diagram of the structure of an execution device provided in an embodiment of the present application;
[0117] Figure 10 This is a structural diagram of a training device provided in an embodiment of the present application;
[0118] Figure 11 A schematic diagram of the structure of the chip provided in an embodiment of the present application. DETAILED DESCRIPTION
[0119] The following describes the embodiments of the present invention in conjunction with the accompanying drawings. The terms used in the embodiments of the present invention are only used to explain the specific embodiments of the present invention, and are not intended to limit the present invention.
[0120] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0121] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, and this is merely a way of distinguishing the objects of the same attributes when describing them in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0122] First, the overall workflow of the artificial intelligence system is described. Figure 1 , Figure 1 The following diagram illustrates a structural diagram of the AI framework. This framework is explained below from two perspectives: the "intelligent information chain" (horizontal axis) and the "IT value chain" (vertical axis). The "intelligent information chain" reflects the entire process from data acquisition to processing. For example, it encompasses the general process of intelligent information perception, intelligent information representation and formation, intelligent reasoning, intelligent decision-making, and intelligent execution and output. Throughout this process, data undergoes a condensed progression from "data-information-knowledge-wisdom." The "IT value chain," encompassing the entire process from the underlying infrastructure of human intelligence, information (provided and processed by technology), to the system's industrial ecosystem, reflects the value that AI brings to the information technology industry.
[0123] (1) Infrastructure
[0124] Infrastructure provides computing power for AI systems, enabling communication with the outside world and supporting this through a foundational platform. External communication occurs through sensors; computing power is provided by intelligent chips (CPUs, NPUs, GPUs, ASICs, FPGAs, and other hardware accelerators). The foundational platform includes a distributed computing framework and network-related platform guarantees and support, including cloud storage and computing, and interconnected networks. For example, sensors communicate with the outside world to acquire data, which is then fed into the intelligent chips within the distributed computing system provided by the foundational platform for computation.
[0125] (2) Data
[0126] Data above the infrastructure layer represents data sources for AI. This data includes graphics, images, voice, and text, as well as IoT data from traditional devices. This includes business data from existing systems and sensor data such as force, displacement, liquid level, temperature, and humidity.
[0127] (3) Data processing
[0128] Data processing generally includes data training, machine learning, deep learning, search, reasoning, decision-making, etc.
[0129] Among them, machine learning and deep learning can symbolize and formalize data for intelligent information modeling, extraction, preprocessing, and training.
[0130] Reasoning refers to the process of simulating human intelligent reasoning in computers or intelligent systems, using formalized information to perform machine thinking and solve problems based on reasoning control strategies. Typical functions are search and matching.
[0131] Decision-making refers to the process of making decisions after intelligent information is reasoned, and usually provides functions such as classification, sorting, and prediction.
[0132] (4) General ability
[0133] After the data has undergone the data processing mentioned above, some general capabilities can be further formed based on the results of the data processing, such as algorithms or a general system, for example, translation, text analysis, computer vision processing, speech recognition, image recognition, etc.
[0134] (5) Smart products and industry applications
[0135] Smart products and industry applications refer to the products and applications of artificial intelligence systems in various fields. They are the encapsulation of the overall artificial intelligence solution, which productizes intelligent information decision-making and realizes practical application. Its application areas mainly include: smart terminals, smart transportation, smart medical care, autonomous driving, smart cities, etc.
[0136] In recent years, neural networks have achieved superior performance in a series of machine learning tasks, and can be specifically applied in multiple fields such as images, language, voice, and video. The server can train a pre-trained model (or a model obtained by fine-tuning and updating the pre-trained model at least once. For the convenience of description, in this embodiment, the above-mentioned pre-trained model and the model obtained after fine-tuning the pre-trained model at least once are referred to as the first neural network model, or the neural network model to be updated), and deploy the above-mentioned first neural network model on the model user end such as the terminal device. However, in some scenarios, the first neural network model may need to be updated due to security issues or changes in requirements. For example, the first neural network model is used to implement a translation task, and when it is found that the first neural network model has a certain specific translation error, the first neural network model needs to be corrected. For example, the first neural network model is used to implement a face recognition task, and when it is found that the first neural network model has an error in recognizing the face of a specific person, the first neural network model needs to be corrected. In addition, the first neural network model can also be fine-tuned based on the private data of the model user end.
[0137] Next, the application architecture of the embodiment of the present application is introduced.
[0138] The following combination Figure 2 The system architecture provided in the embodiments of the present application is introduced in detail. Figure 2 This is a schematic diagram of the system architecture provided by an embodiment of the present application. Figure 2 As shown, the system architecture 500 includes an execution device 510 , a training device 520 , a database 530 , a client device 540 , a data storage system 550 , and a data collection system 560 .
[0139] The execution device 510 includes a calculation module 511, an I / O interface 512, a pre-processing module 513, and a post-processing module 514. The calculation module 511 may include the target model / rule 501, and the pre-processing module 513 and the post-processing module 514 are optional.
[0140] Data acquisition device 560 is used to collect training samples. Training samples can be image data, text data, audio data, etc. In the embodiment of the present application, training samples are the data used to train the first neural network model. After collecting the training samples, data acquisition device 560 stores them in database 530.
[0141] It should be understood that the database 530 may also maintain pre-trained models such as the first neural network model or models obtained by fine-tuning the pre-trained model at least once.
[0142] The training device 520 can train the first neural network model based on the training samples maintained in the database 530 to obtain the target model / rule 501. In the embodiment of the present application, the target model / rule 501 can be the second neural network model and the third neural network model.
[0143] It should be noted that, in actual applications, the training samples maintained in the database 530 may not all be collected by the data acquisition device 560, but may also be received from other devices. It should also be noted that the training device 520 may not train the target model / rule 501 entirely based on the training samples maintained in the database 530, but may also obtain training samples from the cloud or other places for model training. The above description should not be used as a limitation on the embodiments of the present application.
[0144] Specifically, the training sample may be private data from the client device 540 , and the training device 520 may use the private data from the client device 540 as a training sample to fine-tune the first neural network model.
[0145] In an embodiment of the present application, the training device 520 can train the first neural network model using the model training method in an embodiment of the present application to obtain a second neural network model.
[0146] The target model / rule 501 obtained by training the training device 520 can be applied to different systems or devices, such as Figure 2 The execution device 510 shown may be a terminal, such as a mobile phone terminal, a tablet computer, a laptop computer, an augmented reality (AR) / virtual reality (VR) device, a vehicle terminal, etc., or a server or cloud, etc.
[0147] Specifically, the training device 520 can transmit the update data for the first neural network model (referred to as model update information in the embodiment of the present application) to the execution device (the execution device is referred to as the terminal device in the embodiment of the present application).
[0148] exist Figure 2 In the embodiment, the execution device 510 is configured with an input / output (I / O) interface 512 for data interaction with an external device, and the user can input data (such as the data to be processed in the embodiment of the present application) to the I / O interface 512 through the client device 540.
[0149] Preprocessing module 513 and preprocessing module 514 are used to preprocess the input data received by I / O interface 512. It should be understood that preprocessing module 513 and preprocessing module 514 may be absent or only one preprocessing module may be present. If preprocessing module 513 and preprocessing module 514 are absent, computing module 511 may be used directly to process the input data.
[0150] When the execution device 510 preprocesses the input data, or when the computing module 511 of the execution device 510 performs calculations and other related processing, the execution device 510 can call the data, code, etc. in the data storage system 550 for corresponding processing, and can also store the data, instructions, etc. obtained from the corresponding processing in the data storage system 550.
[0151] Finally, the I / O interface 512 presents the processed results to the client device 540 so as to be provided to the user.
[0152] exist Figure 2 In the illustrated case, the user can manually input data, and this "manual input data" can be operated through the interface provided by I / O interface 512. In another case, client device 540 can automatically send input data to I / O interface 512. If the automatic transmission of input data by client device 540 requires user authorization, the user can set the corresponding permissions in client device 540. The user can view the results output by execution device 510 on client device 540, and the specific presentation form can be a display, sound, action, etc. Client device 540 can also serve as a data acquisition terminal, collecting input data input into I / O interface 512 and output results from I / O interface 512 as new sample data and storing them in database 530. Of course, collection can also be performed without client device 540, and instead the I / O interface 512 directly stores the input data input into I / O interface 512 and output results from I / O interface 512 as new sample data in database 530.
[0153] It is worth noting that Figure 2 This is only a schematic diagram of a system architecture provided by an embodiment of the present application. The positional relationship between the devices, components, modules, etc. shown in the figure does not constitute any limitation. For example, Figure 2 In the embodiment, the data storage system 550 is an external memory relative to the execution device 510. In other cases, the data storage system 550 can also be placed in the execution device 510. It should be understood that the execution device 510 can be deployed in the client device 540.
[0154] In the embodiment of the present application, the training device 520 can obtain the memory ( Figure 2Not shown in the figure, the code stored in the training device 520 can be integrated into or deployed separately from the training device 520 to implement the model training method in the embodiment of the present application.
[0155] In an embodiment of the present application, the training device 520 may include a hardware circuit (such as an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a general-purpose processor, a digital signal processor (DSP), a microprocessor or a microcontroller, etc.), or a combination of these hardware circuits. For example, the training device 520 may be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.
[0156] Specifically, the training device 520 can be a hardware system with the function of executing instructions, and the model training method provided in the embodiment of the present application can be a software code stored in the memory. The training device 520 can obtain the software code from the memory and execute the obtained software code to implement the model training method provided in the embodiment of the present application.
[0157] It should be understood that the training device 520 can be a combination of a hardware system that does not have the function of executing instructions and a hardware system that has the function of executing instructions. Some steps of the model training method provided in the embodiment of the present application can also be implemented by the hardware system in the training device 520 that does not have the function of executing instructions, which is not limited here.
[0158] Since the embodiments of the present application involve the application of a large number of neural networks, in order to facilitate understanding, the relevant terms and related concepts such as neural networks involved in the embodiments of the present application are first introduced below.
[0159] (1) Neural Network
[0160] A neural network can be composed of neural units. A neural unit can refer to an operation unit that takes xs (i.e., input data) and intercept 1 as input. The output of the operation unit can be:
[0161]
[0162] Where s = 1, 2, ... n, n is a natural number greater than 1, Ws is the weight of xs, and b is the bias of the neural unit. f is the activation function of the neural unit, which is used to introduce nonlinear characteristics into the neural network to convert the input signal of the neural unit into the output signal. The output signal of the activation function can be used as the input of the next convolutional layer, and the activation function can be a sigmoid function. A neural network is a network formed by connecting multiple single neural units mentioned above, that is, the output of one neural unit can be the input of another neural unit. The input of each neural unit can be connected to the local receptive field of the previous layer to extract the features of the local receptive field. The local receptive field can be an area composed of several neural units.
[0163] (2) Deep Neural Networks
[0164] Deep Neural Network (DNN), also known as multi-layer neural network, can be understood as a neural network with many hidden layers. There is no special metric for "many" here. Based on the position of different layers in DNN, the neural network inside DNN can be divided into three categories: input layer, hidden layer, and output layer. Generally speaking, the first layer is the input layer, the last layer is the output layer, and the layers in between are all hidden layers. The layers are fully connected, that is, any neuron in the i-th layer must be connected to any neuron in the i+1-th layer. Although DNN looks complicated, the work of each layer is actually not complicated. Simply put, it is the following linear relationship expression: in, is the input vector, is the output vector, is the offset vector, W is the weight matrix (also called coefficient), and α() is the activation function. Each layer is just an input vector After such a simple operation, the output vector Since there are many DNN layers, the coefficient W and the offset vector The definition of these parameters in DNN is as follows: Take the coefficient W as an example: Assume that in a three-layer DNN, the linear coefficient from the 4th neuron in the second layer to the 2nd neuron in the third layer is defined as The superscript 3 represents the layer number of the coefficient W, while the subscript corresponds to the output of the third layer index 2 and the input of the second layer index 4. In summary, the coefficient from the kth neuron in the L-1th layer to the jth neuron in the Lth layer is defined as It's important to note that the input layer has no W parameter. In deep neural networks, more hidden layers allow the network to better capture complex real-world situations. Theoretically, a model with more parameters has higher complexity and greater "capacity," meaning it can handle more complex learning tasks. Training a deep neural network is essentially the process of learning the weight matrix, with the ultimate goal of obtaining the weight matrices for all layers of a trained deep neural network (a weight matrix formed by the vectors W across many layers).
[0165] (3) Loss function
[0166] During the training of a deep neural network, because we want the output of the deep neural network to be as close as possible to the desired predicted value, we can compare the current network's predicted value with the desired target value and then update the weight vector of each layer of the neural network based on the difference between the two. (Of course, before the first update, there is usually an initialization process, which pre-configures the parameters for each layer in the deep neural network.) For example, if the network's predicted value is too high, the weight vector is adjusted to make it predict a lower value. This adjustment is continued until the deep neural network can predict the desired target value or a value very close to the desired target value. Therefore, it is necessary to predefine "how to compare the difference between the predicted value and the target value." This is the loss function (or objective function), which is an important equation used to measure the difference between the predicted value and the target value. For example, the loss function output value (loss) indicates a greater difference, so training a deep neural network becomes a process of minimizing this loss.
[0167] (4) Backpropagation algorithm
[0168] The back propagation (BP) algorithm can be used to correct the size of the initial model parameters during training, reducing the model's error loss. Specifically, forward propagation of the input signal to the output generates error loss. This error loss information is then backpropagated to update the parameters in the initial model, thereby converging the error loss. The BP algorithm is a backward propagation movement driven by error loss, aiming to obtain optimal model parameters, such as the weight matrix.
[0169] First, the model training method provided in the embodiment of the present application is described by taking the model training stage as an example.
[0170] Reference Figure 3 , Figure 3 An example of a model training method provided in the present application is shown in FIG. Figure 3As shown, a model training method provided in an embodiment of the present application includes:
[0171] 301. Obtain a first neural network model and a training sample, where the first neural network model includes M parameters;
[0172] In an embodiment of the present application, the first neural network model is a model to be updated, wherein the first neural network model can be an initialization model at the beginning of model training, or a pre-trained model, which has some basic functions in the field to which it belongs, or a model obtained by fine-tuning the pre-trained model and having other functions in addition to the above-mentioned basic functions.
[0173] In some scenarios, the first neural network model may need to be updated due to security issues or changes in requirements. In actual business scenarios, the deployed first neural network model needs to be updated or some functions need to be launched. The first neural network model needs to be trained to enable it to have new functions (also referred to as target tasks in the embodiments of this application). The fine-tuning method can be used to train the first neural network model.
[0174] In order to enable the first neural network model to achieve the target task, it is necessary to obtain training samples related to achieving the target task, that is, to obtain training samples. The training samples are related to the target task. The so-called training samples are related to the target task here can be understood as: training the first neural network through the training samples can enable the first neural network to have the ability to achieve the target task; specifically, this can be achieved in combination with the configuration of data and labels in the training samples.
[0175] For example, the first neural network model is used to implement a translation task. When a specific translation error is found in the first neural network model, the first neural network model needs to be corrected. In selecting training samples, the translation object with the characteristic translation error can be selected, and the correct translation result can be used as the sample label.
[0176] For example, a first neural network model is used to implement a face recognition task. If it is found that the first neural network model incorrectly recognizes the face of a specific person, the first neural network model needs to be corrected. In selecting training samples, the face of the specific person can be selected, and the correct face recognition result can be used as the sample label.
[0177] For another example, a first neural network model is used to implement a conversation task. If the first neural network model generates swear words for a specific sentence, the first neural network model needs to be modified to ensure that the first neural network model does not generate swear words. When selecting training samples, the specific sentence can be selected, and sentences that do not contain swear words can be used as sample labels.
[0178] For example, the first neural network model is used to implement a conversation task. In some scenarios, Easter eggs need to be released during specific holidays. The first neural network model needs to be equipped with the ability to recognize and respond to Easter eggs. When selecting training samples, user conversations that require responses to these Easter eggs can be selected, and sentences containing these Easter eggs can be used as sample labels.
[0179] It should be understood that when fine-tuning a model, since the training samples are new data, the model may experience catastrophic forgetting during training. Catastrophic forgetting refers to the phenomenon where a model forgets previously learned knowledge after learning new information. If a trained model is trained on a new task and then tested on an old task, the accuracy of the old task will be significantly lower than before the new task was learned. As the number of tasks increases, the accuracy of the old tasks gradually decreases, which is known as forgetting.
[0180] Therefore, in addition to obtaining the above-mentioned training samples related to the target task, it is also possible to obtain some historical training samples that were used in the previous training to obtain the first neural network model, and use the above-mentioned training samples related to the target task and the historical training samples together as the training samples used to train the first neural network model. For example, the above-mentioned training samples related to the target task and the historical training samples can be mixed.
[0181] 302. Train the first neural network model based on the training samples to update N parameters among the M parameters until the data processing accuracy of the first neural network model meets a preset condition, thereby obtaining a second neural network model; wherein N is a positive integer less than M, and the N parameters are determined based on the ability of each parameter among the M parameters to affect the data processing accuracy.
[0182] When fine-tuning the first neural network model, the parameters in the first neural network model can be updated. However, since the number of parameters in the first neural network model is large, if each parameter in the first neural network model is updated, then after the training is completed, each updated parameter needs to be transmitted to the terminal device, and the amount of data transmission is large. Therefore, in the embodiment of the present application, under the premise of ensuring that the data processing accuracy of the trained first neural network model meets the requirements, only some parameters in the first neural network model are selected for updating. Then, after the training of the first neural network model is completed, only a small number of parameters need to be transmitted to the terminal device, thereby reducing the amount of data transmission.
[0183] Next, we describe how to select the parameters that need to be updated in the first neural network.
[0184] In a neural network model, only a small number of parameters contribute significantly to the target task to be achieved. To put it another way, in a neural network model, only a small number of parameters have a significant impact on the data processing accuracy of the neural network model for the task to be achieved (target task).
[0185] From the inference side of the model, only a small number of parameters in the neural network model play an important role in achieving the target task. When the values of these parameters change or are removed from the neural network model, the data processing accuracy of the neural network model for the target task will drop significantly.
[0186] From the perspective of model training, in order to achieve the target task, only a small number of parameters in the neural network model need to undergo large numerical updates (or have large numerical changes), or only a small number of parameters in the neural network model have large update gradients, or only a small number of parameters in the neural network model have a large contribution to reducing the loss function used in model training.
[0187] It should be understood that the above-mentioned numerical change can be understood as the numerical change amplitude of the parameter during one iterative training process in the training process, or determined by the numerical change amplitude of the parameter during multiple iterative training processes in the comprehensive training process, or the numerical change amplitude of the parameter compared with the pre-training process after the model training converges.
[0188] It should be understood that the above-mentioned update gradient can be understood as the update gradient of the parameters in one iterative training process in the training process, or can be determined by the update gradient of the parameters in multiple iterative training processes in the comprehensive training process.
[0189] It should be understood that the contribution of the above parameters to the reduction of the loss function used in model training can be understood as the contribution of the parameters to the reduction of the loss function used in model training during a single iterative training process, or the contribution of the parameters to the reduction of the loss function used in model training during multiple iterative training processes in a comprehensive training process. For example, the contribution of the above parameters to the reduction of the loss function used in model training can be expressed based on the loss change allocation (LCA) indicator.
[0190] During model training, if only the parameters that have a greater impact on the model's data processing accuracy are updated, a model with excellent performance can also be obtained.
[0191] Therefore, in an embodiment of the present application, the parameters to be updated can be selected from the parameters of the first neural network model based on the ability of the parameters to affect the data processing accuracy.
[0192] Specifically, the first neural network model may include M parameters, and some parameters (N parameters) of the M parameters may be selected. In the trained model (referred to as the second neural network model in this embodiment of the application), the N parameters are updated, while the other parameters of the M parameters except the N parameters are not updated. The above-mentioned N parameters are the parameters that have a greater impact on the data processing accuracy of the first neural network model for the target task.
[0193] In the embodiment of the present application, the M parameters may be parameters that need to be trained included in one or more neural network layers in the first neural network model. The above-mentioned neural network layers may be, but are not limited to, convolutional layers of ResNet, batch normalization layers or embedding layers of transformers, attention layers, fully connected layers (or feedforward layers), and layer normalization layers.
[0194] Next, the M parameters included in the first neural network model are described:
[0195] In the embodiment of the present application, the first neural network model may include M parameters, and the M parameters may be all or part of the parameters that need to be updated in the first neural network model. It should be understood that the M parameters may be parameters that account for more than 90% of all the parameters that need to be updated in the first neural network model.
[0196] It should be understood that in addition to M parameters, the first neural network model may also include other parameters that may need to be updated. Even if these parameters have little impact on the data processing accuracy of the first neural network model for the target task, they can still be updated during model training. Optionally, these parameters account for a very small proportion in the first neural network model.
[0197] In the embodiment of the present application, N parameters need to be selected from M parameters. The following describes how the number N is determined:
[0198] 1. Specified by the terminal device
[0199] In one possible implementation, N may be specified by a terminal device on which the first neural network model is deployed.
[0200] For example, before training the first neural network model, the user can choose how many parameters in the first neural network model need to be updated. The user can send the number of parameters or parameter ratios that need to be updated to the training device through the terminal device, and the training device can select N parameters from M parameters.
[0201] Specifically, from the perspective of the training device, a model update indication sent by the terminal device can be received, and the model update indication is used to indicate the update of the parameters of the first neural network model, the number of which is N; or, the model update indication is used to indicate the update of the parameters of the target ratio in the first neural network model, wherein the product of the M parameters in the first neural network model and the target ratio is N.
[0202] 2. Automatic Determination
[0203] In one possible implementation, N can be determined by the training device during the process of training the first neural network model. Specifically, the training device can determine, during the process of training the first neural network model, that the number of parameters with the greatest impact on the target task is N based on comprehensive iterations. How the training device determines N during the process of training the first neural network model will be described in subsequent embodiments.
[0204] It should be understood that the number N can be very small. In one implementation, the ratio of N to M is less than 10%. The number N can be different for different tasks. For example, for image classification tasks, the ratio of N to M can be less than 1 / 1000.
[0205] Next, we describe how to select N parameters from M parameters:
[0206] In an embodiment of the present application, the N parameters may be the N parameters among the M parameters that have the greatest impact on the data processing accuracy of the first neural network model; or, the N parameters may be the N parameters among the M parameters that have an impact on the data processing accuracy of the first neural network model that is greater than a threshold.
[0207] The training sample is related to the target task, the data processing accuracy is the data processing accuracy of the first neural network model for the target task, and the ability of each parameter to affect the data processing accuracy is positively correlated with at least one of the following information:
[0208] When the first neural network model is trained for the target task, the update gradient corresponding to each parameter; or
[0209] When the first neural network model is trained for the target task, the numerical change corresponding to each parameter; or
[0210] When the first neural network model is trained for the target task, the contribution of each parameter to the reduction of the loss function, where the loss function is the loss function used when updating the M parameters.
[0211] In one implementation, the ability of each parameter to influence the data processing accuracy is positively correlated with the update gradient corresponding to each parameter when the first neural network model is trained for the target task;
[0212] In one implementation, the ability of each parameter to influence the data processing accuracy is positively correlated with a numerical change corresponding to each parameter when the first neural network model is trained for the target task;
[0213] In one implementation, the ability of each parameter to influence the data processing accuracy is positively correlated with the ability of each parameter to contribute to reducing the loss function when training the first neural network model for the target task;
[0214] In one implementation, the ability of each parameter to influence the data processing accuracy is positively correlated with the update gradient corresponding to each parameter and the value change corresponding to each parameter when the first neural network model is trained for the target task;
[0215] In one implementation, the ability of each parameter to influence the data processing accuracy is positively correlated with the update gradient corresponding to each parameter and the contribution of each parameter to reducing the loss function when training the first neural network model for the target task;
[0216] In one implementation, the ability of each parameter to influence the data processing accuracy is positively correlated with the numerical change corresponding to each parameter, the update gradient corresponding to each parameter, and the contribution of each parameter to reducing the loss function when the first neural network model is trained for the target task;
[0217] In one implementation, the ability of each parameter to influence the data processing accuracy is positively correlated with the update gradient corresponding to each parameter, the numerical change corresponding to each parameter, and the contribution of each parameter to reducing the loss function when the first neural network model is trained for the target task.
[0218] In one implementation, the M parameters in the first neural network model can be updated first to train a reference model (also referred to as the third neural network model in this embodiment), and then based on the reference model, it is determined which parameters contribute more to the training. These determined parameters can be considered as the N parameters that have a greater impact on the data processing accuracy of the first neural network model for the target task.
[0219] Specifically, the first neural network model can be trained based on the training sample to update the M parameters until the data processing accuracy of the first neural network model meets a preset condition, thereby obtaining a third neural network model; the ability of each parameter to influence the data processing accuracy is positively correlated with at least one of the following information:
[0220] When the first neural network model is trained according to the training sample, the update gradient corresponding to each parameter; or
[0221] When the first neural network model is trained according to the training sample, the numerical change corresponding to each parameter; or
[0222] When the first neural network model is trained according to the training sample, the contribution ability of each parameter to the reduction of the loss function, and the loss function is the loss function adopted when the M parameters are updated.
[0223] Among them, the loss function used in model training is L=ax+by, where (x, y) is a parameter. Assuming that the parameters are trained from (x, y) to (x+dx, y+dy), then the basis for selecting N parameters can be: select the parameters with the largest absolute value of the updated gradient during training. In the above example, the absolute value of the updated gradient of (x, y) is (|a|, |b|).
[0224] Among them, the loss function used in model training is L=ax+by, where (x,y) is a parameter. Assuming that the parameters are trained from (x,y) to (x+dx,y+dy), then the basis for selecting N parameters can be: select the parameters with the largest absolute value of parameter change during training. In the above model, the absolute value of the change is (|dx|, |dy|).
[0225] The loss function used during model training is L = ax + by, where (x, y) are parameters. Assuming the parameters are trained from (x, y) to (x + dx, y + dy), then the basis for selecting N parameters can be: select the parameters with the largest LCA index during training, where the LCA index measures the contribution of each parameter to the change in the loss function. For example, the change in the model's loss function is dL = a*dx + b*dy, where the contribution of different parameters to the reduction in the loss function is (-a*dx, -b*dy) respectively. Because a reduction in the loss function is considered a contribution, there is a negative sign here.
[0226] After determining N parameters based on the above reference model, these important parameters (N parameters) can be selected for training, and only these parameters are trained to achieve sparse parameter updates. Specifically, the first neural network model can be trained based on the training samples to update N parameters among the M parameters, and when training the first neural network model, MN parameters among the M parameters except the N parameters are not updated.
[0227] In one implementation, during the process of updating the M parameters, it can be determined which parameter updates among the M parameters will be retained (or called the updates taking effect), and which parameter updates will not be retained (or called the updates not taking effect, or described as being restored to the corresponding parameter values in the first neural network model, that is, the parameter values before training are still retained). Specifically, the first neural network model can be trained according to the training samples, and N parameters among the M parameters can be updated. In the process of training the first neural network model according to the training samples, it can be determined which parameter updates (N parameters) will be retained based on the ability of each parameter to influence the data processing accuracy of the first neural network model for the target task.
[0228] For example, at the beginning of training the first neural network model, all parameters in the first neural network model (e.g., the M parameters mentioned above) can be added to the updateable parameter set. When training the first neural network model, each parameter in the updateable parameter set will be updated. After a certain number of model training steps, the importance of each parameter in the updateable parameter set for the model update (i.e., the influence of the parameter on the data processing accuracy of the first neural network model for the target task) can be calculated based on the model training process of the above number of steps. The indicator for measuring the importance of the parameter can be the update gradient or change amplitude of different parameters during the training process, etc., and then a certain proportion of unimportant parameters are restored to the original parameter value (i.e., the update of these parameters is not effective) and removed from the updateable parameter set. The above process is repeated, and N parameters can be selected. During the training process of the first neural network model, the updates of these N parameters are retained, and although the MN parameters other than the N parameters in the M parameters can be updated during the training process, the updates are not retained, that is, the other parameters in the updated M parameters other than the N parameters are restored to the corresponding parameter values in the first neural network model.
[0229] The pseudo code of the above parameter update process can be as follows:
[0230]
[0231] Optionally, in one implementation, the ability of the parameter to influence the data processing accuracy of the model can be represented by the numerical change when the parameter is updated, and a regularization term (which may be referred to as a target loss term in the embodiment of the present application) can be added to the loss function used in the training of the first neural network model. The regularization term can constrain the update amplitude of the parameters. After each iteration or a certain number of iterative training steps, the update of the parameters whose numerical change when updated is greater than the threshold is retained, while the update of the parameters whose numerical change when updated is less than the threshold is not retained. Moreover, since there is a regularization term in the loss function for constraining the update amplitude of the parameters, the update amplitude of the parameters with less influence on the data processing accuracy of the model can be made smaller, thereby preventing the update of these parameters (MN parameters) from being retained, and only retaining the update of N parameters.
[0232] It should be understood that in one implementation, a regularization term for constraining the number of updated parameters may be added to the loss function. For example, Lagrangian relaxation may be used to obtain the following loss function:
[0233] w′=argmin L(D′)+α||ww′||0;
[0234] Among them, the regularization term of the 0 norm is used to constrain the number of updated parameters. However, since the 0 norm is not differentiable, the 1 norm relaxation can be used instead of optimization, that is, the following loss function is obtained:
[0235] w′=argmin L(D′)+α||ww′||1;
[0236] The 1-norm regularization term is used to constrain the parameter update amplitude. This regularization term, combined with the aforementioned truncated update technique (restoring unimportant parameters to their original values, meaning that updates to these parameters are ineffective), can yield a sparse update solution. However, the 1-norm method cannot explicitly specify the degree of sparsity, meaning that the number N cannot be specified before training; it can only be determined after training. It should be understood that the α in the aforementioned loss function controls the approximate range of the final selected N.
[0237] In the above manner, during the training of the first neural network model, only N of the M parameters can be updated, or M parameters can be updated, but in the final trained model, only the updates of N of the parameters are retained, while the updates of the other MN parameters except the N parameters are not retained.
[0238] Furthermore, when the data processing accuracy of the first neural network model for the target task meets the preset requirements (for example, the accuracy is greater than a threshold, or the number of training iterations exceeds a threshold), a second neural network model can be obtained, wherein the second neural network model is the trained first neural network model, and among the M parameters in the second neural network model, only N parameters have undergone numerical updates compared to the first neural network model, and the other MN parameters except N parameters have not been updated.
[0239] After completing the training for the first neural network model, the training device needs to transmit the model update information to the terminal device, and then the terminal device can obtain the trained first neural network model (that is, the second neural network model) based on the model update information and the first neural network model.
[0240] In an embodiment of the present application, since only N parameters out of the M parameters in the second neural network model are updated, the numerical changes of these N parameters are not 0, while the numerical changes of the other parameters except N parameters out of the M parameters are 0. In order to reduce the amount of data transmitted from the training device to the terminal device, it is necessary to reduce the data volume of the model update information. In one implementation, the model update information can be generated based on the numerical changes of each parameter. Since the numerical changes of most parameters among the numerical changes of each parameter are 0, the existing mainstream data compression algorithm can remove redundancy of the value 0, so the data volume of the compressed model update information is very small.
[0241] Specifically, model update information can be obtained; wherein, the model update information includes the numerical change of each parameter in the M parameters in the second neural network model, and the model update information can be compressed to obtain compressed model update information, wherein the compression is used to remove redundancy of the value 0, and the compressed model update information is sent to the terminal device. After receiving the compressed model update information, the terminal device can decompress the compressed model update information to obtain the numerical change of each parameter in the M parameters.
[0242] In order to reduce the data volume of the model update information, in another implementation, the model update information can be generated based on N parameters (which can be the update results or numerical changes of N parameters). Since N is very small, the data volume of the compressed model update information is very small.
[0243] Specifically, model update information may be sent to the terminal device; wherein the model update information includes the updated N parameters, and the model update information does not include parameters other than the N parameters in the M parameters.
[0244] In addition, when the first neural network model is a pre-trained model, which has some basic functions in the corresponding field, or is a model obtained by fine-tuning the pre-trained model and has other functions in addition to the above-mentioned basic functions, since only a small part of the parameters in the first neural network model are updated in the embodiment of the present application, it can be ensured that the first neural network model will not lose its original capabilities, that is, it can be ensured that the first neural network model will not decline or will not decline much in its original task processing capabilities, that is, it can be ensured that the first neural network model will not have the problem of catastrophic forgetting (consistency is used in subsequent embodiments to quantify the first neural network model's ability to maintain its original capabilities).
[0245] Next, the model training method in the embodiment of the present application is described with reference to a specific example:
[0246] Let’s take the image classification task as an example. Assume that a relevant classification model (the first neural network model) has been deployed on the client, and the client model needs to be updated or patched. For example, if the function to be updated is “as long as a certain five-pixel pattern appears in the lower right corner of the image, it will be classified into a certain category”, first, we can prepare training samples for fine-tuning based on the updated function. In this example, we can select a certain amount of image data, add a certain five-pixel pattern in the lower right corner of the image, and then randomly take a certain amount of original training data for mixing to obtain a training set for model fine-tuning. Figure 3 The method described in the corresponding embodiment can obtain a second neural network model. When distributing the update package to the client, the numerical change of the updated parameters (N parameters) compared with the parameters before the update is distributed. For sparsely updated update packages, most parts are 0. When compressed using mainstream compression algorithms, the size of the update package can be greatly reduced.
[0247] In order to measure whether the performance of the model before and after the update is consistent on the original data (data unrelated to the update function), we can define the linear correlation coefficient of the evaluation scores of the model before and after fine-tuning calculated on a given dataset as consistency:
[0248] Definition 1(Consistency Score).For a clean dataset amodel f, and the model f′after tuning.Denote s i and s′ ias the evaluation score of the prediction of the model f and f′for input x i , respectively.Let and We define the consistency score C as the Pearson correlation coefficient of scores before and after tuning:
[0249]
[0250] It is easy to verify-1≤C≤1.
[0251] When checking the consistency of the update package, the consistency score is calculated using the above definition to measure the side effects before and after the neural network fine-tuning.
[0252] The experimental results on the image classification task show that on the basis of ensuring the model effect, the embodiment of the present application can only modify some parameters, and at the same time the consistency before and after training is improved.
[0253] Among them, the performance of the CIFAR-10 dataset (ResNet model) on the image classification task is as follows:
[0254]
[0255] As can be seen, our method can modify only a small proportion of parameters and obtain a sparse parameter update package. At the same time, the accuracy of the original dataset is not lost compared to the existing technology (baseline), and the consistency before and after training is improved.
[0256] For image classification tasks, further update package size comparison tests can be conducted. ResNet-18 is a lightweight image classification system. It adds a function to a trained classification system (for example, classifying it as a certain existing class when a specific watermark is seen). Even with such lightweight requirements, because all parameters are modified during the fine-tuning process of the existing technology, the update package size is as high as 34M even after compression. By applying the method provided in the embodiment of the present application, only 100 parameters need to be modified to complete the modification while ensuring the effect. The size of the update package can be compressed to 26KB, which is less than one thousandth of the original update package size.
[0257] An embodiment of the present application provides a model training method, the method comprising: obtaining a first neural network model and a training sample, the first neural network model comprising M parameters; training the first neural network model according to the training sample to update N parameters of the M parameters until the data processing accuracy of the first neural network model meets a preset condition, thereby obtaining a second neural network model; wherein N is a positive integer less than M, and the N parameters are determined based on the ability of each parameter of the M parameters to affect the data processing accuracy. Through the above method, under the premise of ensuring that the data processing accuracy of the model meets the accuracy requirements, since only N parameters of the M parameters in the updated first neural network model are updated, the amount of data transmitted from the training device to the terminal device can be reduced.
[0258] Next, a parameter configuration method for model update provided by the embodiment of the present application is described in combination with the interaction. Figure 4 , Figure 4 This is a schematic diagram of a parameter configuration method for model update provided in an embodiment of the present application, such as Figure 4 As shown, the method includes:
[0259] 401. Display a configuration interface, where the configuration interface includes a first control, and the first control is used to instruct a user to input the number or proportion of parameters that need to be updated in a first neural network model.
[0260] Reference Figure 5 In an embodiment of the present application, a configuration interface may be displayed on a client of a terminal device, wherein the configuration interface may include a first control for instructing a user to input the number or ratio of parameters that need to be updated in the first neural network model. The first control may be Figure 5 In the input box shown in , the user can input the number or proportion of parameters that need to be updated in the first neural network model in the input box, and the second control can be an option, which provides the user with multiple choices of the number or proportion of parameters to be updated, and the user can select the number or proportion of parameters that need to be updated in the first neural network model according to the options.
[0261] Reference Figure 5 In addition to the first control, the configuration interface may include a second control for instructing the user to upload the first neural network model to be updated. In addition, the configuration interface may include a third control for instructing the user to upload a training sample.
[0262] 402. Obtain a target quantity or a target ratio input by the user through the first control.
[0263] In the embodiment of the present application, the user can input the target quantity or target ratio according to the first control, and then the client can obtain the target quantity or target ratio input by the user through the first control.
[0264] 403. Send a model update indication to the server, where the model update indication includes the target quantity or target ratio, and the target quantity or target ratio is used to indicate updating parameters of the target quantity or target ratio in the first neural network model when training the first neural network model.
[0265] Reference Figure 6 In an embodiment of the present application, after obtaining the target number or target ratio input by the user, the client can pass the target number or target ratio to the training device, and then the training device can train the first neural network model according to the target number or target ratio.
[0266] In an embodiment of the present application, since only N parameters out of the M parameters in the second neural network model are updated, the numerical changes of these N parameters are not 0, while the numerical changes of the other parameters except N parameters out of the M parameters are 0. In order to reduce the amount of data transmitted from the training device to the terminal device, it is necessary to reduce the data volume of the model update information. In one implementation, the model update information can be generated based on the numerical changes of each parameter. Since the numerical changes of most parameters among the numerical changes of each parameter are 0, the existing mainstream data compression algorithm can remove redundancy of the value 0, so the data volume of the compressed model update information is very small.
[0267] Specifically, the training device can generate model update information; wherein, the model update information includes the numerical change of each parameter in the M parameters in the second neural network model, and the model update information can be compressed to obtain compressed model update information, wherein the compression is used to remove redundancy of the numerical value 0, and send the compressed model update information to the client, and then the client can receive the compressed model update information sent by the server, and decompress the compressed model update information to obtain the model update information; wherein, the model update information includes the numerical change of multiple parameters, and the numerical change of the multiple parameters is the numerical change of updating each parameter in the first neural network model.
[0268] In order to reduce the data volume of the model update information, in another implementation, the model update information can be generated based on N parameters (which can be the update results or numerical changes of N parameters). Since N is very small, the data volume of the compressed model update information is very small.
[0269] Specifically, model update information can be sent to the client; wherein the model update information includes the N parameters after update, and the model update information does not include MN parameters other than the N parameters in the M parameters. Then, the client can receive the compressed model update information sent by the server and decompress the compressed model update information to obtain the model update information; wherein, the model update information includes multiple parameters, and the multiple parameters are obtained by updating the parameters of the target number or target ratio, and the difference between the number of parameters included in the model update information and the target number is within a preset range; or, the ratio of the number of parameters included in the model update information to the number of parameters included in the first neural network model and the target ratio are within a preset range, that is, the model update information can also include a small number of other parameters.
[0270] Reference Figure 7 , Figure 7 A schematic diagram of the structure of a model training device provided in an embodiment of the present application is shown as follows: Figure 7 As shown, the apparatus 700 includes:
[0271] An acquisition module 701 is configured to acquire a first neural network model and a training sample, wherein the first neural network model includes M parameters;
[0272] For a detailed description of the acquisition module 701 , please refer to the description of step 301 , which will not be repeated here.
[0273] The model updating module 702 is configured to train the first neural network model based on the training samples to update N of the M parameters until the data processing accuracy of the first neural network model meets a preset condition, thereby obtaining a second neural network model; wherein N is a positive integer less than M, and the N parameters are determined based on the ability of each of the M parameters to influence the data processing accuracy.
[0274] For a detailed description of the model updating module 702 , please refer to the description of step 302 , which will not be repeated here.
[0275] In a possible implementation, in the second neural network model, parameters other than the N parameters among the M parameters are not updated.
[0276] In a possible implementation, the N parameters are the N parameters that have the greatest impact on the data processing accuracy of the first neural network model among the M parameters; or,
[0277] The N parameters are N parameters among the M parameters whose influence on the data processing accuracy of the first neural network model is greater than a threshold.
[0278] In a possible implementation, the ratio of N to M is less than 10%.
[0279] In one possible implementation, the apparatus further includes: a receiving module 703, configured to receive a model update indication sent by a terminal device before training the first neural network model according to the training sample to update N of the M parameters, wherein the model update indication is used to indicate an update of the N number of parameters in the first neural network model; or, the model update indication is used to indicate an update of the target proportion of parameters in the first neural network model.
[0280] In a possible implementation, the second neural network model includes the updated N parameters, and the acquisition module 701 is further configured to:
[0281] After obtaining the second neural network model, obtaining model update information; wherein the model update information includes a numerical change of each parameter in the M parameters in the second neural network model compared to before the update;
[0282] The device further comprises:
[0283] A compression module 704 is configured to compress the model update information to obtain compressed model update information;
[0284] The sending module 705 is configured to send the compressed model update information to a terminal device.
[0285] In one possible implementation, the sending module 705 is used to send model update information to the terminal device after obtaining the second neural network model; wherein the model update information includes the updated N parameters, and the model update information does not include parameters other than the N parameters in the M parameters.
[0286] In one possible implementation, the training sample is related to a target task, the data processing accuracy is the data processing accuracy of the first neural network model for the target task, and the ability of each parameter to influence the data processing accuracy is positively correlated with at least one of the following information:
[0287] When the first neural network model is trained for the target task, the update gradient corresponding to each parameter; or
[0288] When the first neural network model is trained for the target task, the numerical change corresponding to each parameter; or
[0289] When the first neural network model is trained for the target task, the contribution of each parameter to the reduction of the loss function, where the loss function is the loss function used when updating the M parameters.
[0290] In a possible implementation, the model updating module 702 is further configured to, before training the first neural network model according to the training sample to update N of the M parameters, train the first neural network model according to the training sample to update the M parameters and determine the ability of each of the M parameters to influence the data processing accuracy; and determine N parameters from the M parameters according to the ability of each of the M parameters to influence the data processing accuracy.
[0291] In one possible implementation, the model updating module 702 is specifically configured to train the first neural network model based on the training sample to update the M parameters and determine the influence of each of the M parameters on the data processing accuracy;
[0292] Determining N parameters from the M parameters according to the influence of each parameter in the M parameters on the data processing accuracy;
[0293] Restoring the other parameters of the updated M parameters except the N parameters to the corresponding parameter values in the first neural network model.
[0294] In one possible implementation, the model update module 702 is specifically used to train the first neural network model according to the training sample through a preset loss function to update N parameters of the M parameters; wherein the preset loss function includes a target loss term, and the target loss term is used to constrain the update amplitude of the parameters.
[0295] In a possible implementation, the training sample is text data, image data, or audio data.
[0296] In a possible implementation, the second neural network model is used to process the data to be processed to obtain a data processing result, and the data to be processed is text data, image data or audio data.
[0297] Reference Figure 8 , Figure 8 A schematic diagram of the structure of a parameter configuration device for model update provided in an embodiment of the present application is shown as follows: Figure 8 As shown, the apparatus 800 includes:
[0298] A display module 801 is used to display a configuration interface, where the configuration interface includes a first control, and the first control is used to instruct the user to input the number or ratio of parameters that need to be updated in the first neural network model;
[0299] For a detailed description of the display module 801 , please refer to the description of step 401 , which will not be repeated here.
[0300] An acquisition module 802 is configured to acquire a target quantity or a target ratio input by a user through the first control;
[0301] For a detailed description of the acquisition module 802 , please refer to the description of step 402 , which will not be repeated here.
[0302] The sending module 803 is used to send a model update indication to the server, where the model update indication includes the target quantity or target ratio, and the target quantity or target ratio is used to indicate that when training the first neural network model, the parameters of the target quantity or target ratio in the first neural network model are updated.
[0303] For a detailed description of the sending module 803 , please refer to the description of step 403 , which will not be repeated here.
[0304] In a possible implementation, the apparatus further includes: a receiving module 804, configured to, after sending the model update indication to the server, receive compressed model update information sent by the server, and decompress the compressed model update information to obtain the model update information; wherein,
[0305] The model update information includes multiple parameters, and the multiple parameters are obtained by updating the parameters of the target quantity or target ratio, and the difference between the number of parameters included in the model update information and the target number is within a preset range; or, the ratio of the number of parameters included in the model update information to the number of parameters included in the first neural network model and the target ratio are within a preset range.
[0306] In a possible implementation, the receiving module 804 is further configured to, after sending the model update indication to the server, receive compressed model update information sent by the server, and decompress the compressed model update information to obtain the model update information; wherein,
[0307] The model update information includes numerical changes of multiple parameters, and the numerical changes of the multiple parameters are numerical changes of updating multiple parameters in the first neural network model.
[0308] Next, we will introduce an execution device provided by the embodiment of the present application. Figure 9 , Figure 9 This is a structural diagram of an execution device provided in an embodiment of the present application. The execution device 900 can be specifically manifested as a mobile phone, a tablet, a laptop, a smart wearable device, a server, etc., which is not limited here. Among them, the execution device 900 can be deployed with Figure 10 The data processing device described in the corresponding embodiment is used to implement Figure 10 The data processing function in the corresponding embodiment. Specifically, the execution device 900 includes: a receiver 901, a transmitter 902, a processor 903 and a memory 904 (wherein the number of processors 903 in the execution device 900 may be one or more), wherein the processor 903 may include an application processor 9031 and a communication processor 9032. In some embodiments of the present application, the receiver 901, the transmitter 902, the processor 903 and the memory 904 may be connected via a bus or other means.
[0309] The memory 904 may include a read-only memory and a random access memory, and provides instructions and data to the processor 903. A portion of the memory 904 may also include non-volatile random access memory (NVRAM). The memory 904 stores processor and operation instructions, executable modules, or data structures, or subsets or extended sets thereof. The operation instructions may include various operation instructions for implementing various operations.
[0310] Processor 903 controls the operation of the execution device. In specific applications, the various components of the execution device are coupled together via a bus system. In addition to a data bus, the bus system may also include a power bus, a control bus, and a status signal bus. However, for clarity, all bus systems are referred to as a bus system in the figure.
[0311] The method disclosed in the above embodiment of the present application can be applied to the processor 903 or implemented by the processor 903. The processor 903 can be an integrated circuit chip with signal processing capabilities. During the implementation process, each step of the above method can be completed by an integrated logic circuit of the hardware in the processor 903 or an instruction in the form of software. The above-mentioned processor 903 can be a general-purpose processor, a digital signal processor (digital signal processing, DSP), a microprocessor or a microcontroller, and a vision processor (vision processing unit, VPU), a tensor processing unit (tensorprocessing unit, TPU) and other processors suitable for AI computing, and can further include an application specific integrated circuit (ASIC), a field programmable gate array (field-programmable gate array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The processor 903 can implement or execute the various methods, steps and logic block diagrams disclosed in the embodiments of the present application. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiments of this application can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in memory 904, and processor 903 reads the information in memory 904 and, in conjunction with its hardware, completes the steps of the above method.
[0312] Receiver 901 can be used to receive input digital or character information and generate signal input related to executing device-related settings and function control. Transmitter 902 can be used to output digital or character information through the first interface. Transmitter 902 can also be used to send instructions to the disk pack through the first interface to modify data in the disk pack. Transmitter 902 can also include a display device such as a display screen.
[0313] The execution device can obtain Figure 3 The model obtained by training the model training method in the corresponding embodiment is used to perform model inference.
[0314] The present application also provides a training device. Figure 10 , Figure 10This is a structural diagram of a training device provided in an embodiment of the present application. Specifically, the training device 1000 is implemented by one or more servers. The training device 1000 may have relatively large differences due to different configurations or performances. It may include one or more central processing units (CPUs) 1010 (for example, one or more processors) and memory 1032, and one or more storage media 1030 (for example, one or more mass storage devices) storing application programs 1042 or data 1044. Among them, the memory 1032 and the storage medium 1030 can be short-term storage or persistent storage. The program stored in the storage medium 1030 may include one or more modules (not shown in the figure), and each module may include a series of instruction operations in the training device. Furthermore, the central processing unit 1010 can be configured to communicate with the storage medium 1030 to execute a series of instruction operations in the storage medium 1030 on the training device 1000.
[0315] The training device 1000 may also include one or more power supplies 1026, one or more wired or wireless network interfaces 1050, one or more input and output interfaces 1058; or, one or more operating systems 1041, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0316] Specifically, the training device can perform Figure 3 The model training method in the corresponding embodiment.
[0317] An embodiment of the present application also provides a computer program product, which, when running on a computer, enables the computer to execute the steps executed by the aforementioned execution device, or enables the computer to execute the steps executed by the aforementioned training device.
[0318] A computer-readable storage medium is also provided in an embodiment of the present application, which stores a program for signal processing. When the computer-readable storage medium is run on a computer, it enables the computer to execute the steps executed by the aforementioned execution device, or enables the computer to execute the steps executed by the aforementioned training device.
[0319] The execution device, training device or terminal device provided in the embodiments of the present application can specifically be a chip, and the chip includes: a processing unit and a communication unit, the processing unit can be, for example, a processor, and the communication unit can be, for example, an input / output interface, a pin or a circuit, etc. The processing unit can execute the computer execution instructions stored in the storage unit, so that the chip in the execution device executes the data processing method described in the above embodiment, or so that the chip in the training device executes the data processing method described in the above embodiment. Optionally, the storage unit is a storage unit in the chip, such as a register, a cache, etc. The storage unit can also be a storage unit located outside the chip in the wireless access device, such as a read-only memory (ROM) or other types of static storage devices that can store static information and instructions, a random access memory (RAM), etc.
[0320] For details, please refer to Figure 11 , Figure 11 A schematic diagram of the structure of a chip provided in an embodiment of the present application, which can be represented as a neural network processor NPU 1100. NPU 1100 is mounted on the host CPU as a coprocessor and is assigned tasks by the host CPU. The core of the NPU is arithmetic circuit 1103, which is controlled by controller 1104 to extract matrix data from memory and perform multiplication operations.
[0321] NPU 1100 can achieve Figure 3 The model training method provided in the described embodiments, or reasoning on the trained model.
[0322] Among them, the computing circuit 1103 in the NPU 1100 can execute the steps of obtaining a first neural network model and performing model training on the first neural network model.
[0323] More specifically, in some implementations, the arithmetic circuit 1103 in the NPU 1100 includes multiple processing units (PEs). In some implementations, the arithmetic circuit 1103 is a two-dimensional systolic array. The arithmetic circuit 1103 can also be a one-dimensional systolic array or other electronic circuitry capable of performing mathematical operations such as multiplication and addition. In some implementations, the arithmetic circuit 1103 is a general-purpose matrix processor.
[0324] For example, assume there are input matrix A, weight matrix B, and output matrix C. The arithmetic circuit retrieves the corresponding data of matrix B from weight memory 1102 and caches it on each PE in the arithmetic circuit. The arithmetic circuit retrieves the data of matrix A from input memory 1101 and performs a matrix operation on matrix B. The partial or final matrix result is stored in accumulator 1108.
[0325] Unified memory 1106 is used to store input and output data. Weight data is directly transferred to weight memory 1102 through the Direct Memory Access Controller (DMAC) 1105. Input data is also transferred to unified memory 1106 through the DMAC.
[0326] BIU stands for Bus Interface Unit, i.e., bus interface unit 1110 , which is used for interaction between the AXI bus, DMAC, and instruction fetch buffer (IFB) 1109 .
[0327] The bus interface unit 1110 (BIU) is used for the instruction fetch memory 1109 to obtain instructions from the external memory, and is also used for the storage unit access controller 1105 to obtain the original data of the input matrix A or the weight matrix B from the external memory.
[0328] DMAC is mainly used to move input data in the external memory DDR to the unified memory 1106 or to move weight data to the weight memory 1102 or to move input data to the input memory 1101.
[0329] The vector calculation unit 1107 includes multiple operation processing units. When necessary, it further processes the output of the operation circuit 1103, such as vector multiplication, vector addition, exponential operation, logarithmic operation, size comparison, etc. It is mainly used for non-convolutional / fully connected layer network calculations in neural networks, such as batch normalization, pixel-level summation, and upsampling of feature planes.
[0330] In some implementations, the vector calculation unit 1107 can store the processed output vector in the unified memory 1106. For example, the vector calculation unit 1107 can apply a linear function or a nonlinear function to the output of the operation circuit 1103, such as linear interpolation of the feature plane extracted by the convolution layer, or accumulate a vector of values to generate an activation value. In some implementations, the vector calculation unit 1107 generates a normalized value, a pixel-level summed value, or both. In some implementations, the processed output vector can be used as an activation input to the operation circuit 1103, for example, for use in subsequent layers in a neural network.
[0331] An instruction fetch buffer 1109 connected to the controller 1104 is used to store instructions used by the controller 1104;
[0332] Unified memory 1106, input memory 1101, weight memory 1102, and instruction fetch memory 1109 are all on-chip memories. External memories are private to the NPU hardware architecture.
[0333] The processor mentioned in any of the above places can be a general-purpose central processing unit, a microprocessor, an ASIC, or one or more integrated circuits for controlling the execution of the above program.
[0334] It should also be noted that the device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separate, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed across multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the drawings of the device embodiments provided in this application, the connection relationship between the modules indicates that there is a communication connection between them, which can be specifically implemented as one or more communication buses or signal lines.
[0335] Through the description of the above embodiments, those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course can also be implemented by special hardware including application-specific integrated circuits, special CPUs, special memories, special components, etc. In general, all functions performed by computer programs can be easily implemented with corresponding hardware, and the specific hardware structures used to implement the same function can also be diverse, such as analog circuits, digital circuits or special circuits, etc. However, for the present application, software program implementation is a better implementation method in most cases. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer's floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk or optical disk, etc., and includes a number of instructions to enable a computer device (which can be a personal computer, training equipment, or network equipment, etc.) to execute the methods described in each embodiment of the present application.
[0336] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware, or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0337] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website, a computer, a training device or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website, a computer, a training device or a data center. The computer-readable storage medium can be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium can be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)).
Claims
1. A model training method, characterized in that: The method comprises: Obtaining a first neural network model and a training sample, where the first neural network model includes M parameters; the training sample is text data, image data, or audio data; Training the first neural network model based on the training samples to update N parameters of the M parameters until the data processing accuracy of the first neural network model meets a preset condition, thereby obtaining a second neural network model; wherein N is a positive integer less than M, and the N parameters are determined based on the ability of each parameter of the M parameters to affect the data processing accuracy; The step of training the first neural network model according to the training sample to update N parameters of the M parameters includes: Training the first neural network model according to the training sample using a preset loss function to update N parameters of the M parameters; wherein the preset loss function includes a target loss term, and the target loss term is used to constrain the update amplitude of the parameters; The training sample is related to the target task, the data processing accuracy is the data processing accuracy of the first neural network model for the target task, and the ability of each parameter to affect the data processing accuracy is positively correlated with the following information: During the training of the first neural network model for the target task, the numerical change corresponding to each parameter.
2. The method according to claim 1, characterized in that In the second neural network model, parameters other than the N parameters among the M parameters are not updated.
3. The method according to claim 1 or 2, characterized in that The N parameters are the N parameters that have the greatest impact on the data processing accuracy of the first neural network model among the M parameters; or The N parameters are N parameters among the M parameters whose influence on the data processing accuracy of the first neural network model is greater than a threshold.
4. The method according to claim 1 or 2, characterized in that The ratio of N to M is less than 10%.
5. The method according to claim 1 or 2, characterized in that Before training the first neural network model according to the training sample to update N parameters of the M parameters, the method further includes: A model update indication is received from a terminal device, where the model update indication is used to indicate an update of N number of parameters in the first neural network model; or, the model update indication is used to indicate an update of a target ratio of parameters in the first neural network model.
6. The method according to claim 1 or 2, characterized in that The second neural network model includes the updated N parameters. After obtaining the second neural network model, the method further includes: Obtaining model update information; wherein the model update information includes a numerical change of each parameter of the M parameters in the second neural network model compared to before the update; compressing the model update information to obtain compressed model update information; Send the compressed model update information to the terminal device.
7. The method according to claim 1 or 2, characterized in that After obtaining the second neural network model, the method further includes: Sending model update information to the terminal device; wherein the model update information includes the updated N parameters, and the model update information does not include parameters other than the N parameters in the M parameters.
8. The method according to claim 1 or 2, characterized in that Before training the first neural network model according to the training sample to update N parameters of the M parameters, the method further includes: Training the first neural network model according to the training samples to update the M parameters and determine the influence of each of the M parameters on the data processing accuracy; N parameters are determined from the M parameters according to the influence of each parameter in the M parameters on the data processing accuracy.
9. The method according to claim 1 or 2, characterized in that The step of training the first neural network model according to the training sample to update N parameters of the M parameters includes: Training the first neural network model according to the training samples to update the M parameters and determine the influence of each of the M parameters on the data processing accuracy; Determining N parameters from the M parameters according to the influence of each parameter in the M parameters on the data processing accuracy; Restoring the other parameters of the updated M parameters except the N parameters to the corresponding parameter values in the first neural network model.
10. The method according to claim 1 or 2, characterized in that The second neural network model is used to process the data to be processed to obtain a data processing result, and the data to be processed is text data, image data or audio data.
11. A parameter configuration method for model update, characterized in that: The method comprises: Displaying a configuration interface, the configuration interface including a first control, the first control being used to instruct a user to input a number or ratio of parameters that need to be updated in the first neural network model; Obtaining a target quantity or a target ratio input by a user through the first control; Sending a model update instruction to the server, where the model update instruction includes the target number or target ratio, where the target number or target ratio is used to indicate updating a parameter of the target number or target ratio in the first neural network model when training the first neural network model; The loss function used in training the first neural network model includes a target loss term, and the target loss term is used to constrain the update amplitude of the parameters; The parameters of the target quantity or target ratio are determined according to the ability of each parameter in the first neural network model to affect the data processing accuracy; The training sample of the first neural network model is text data, image data, or audio data; the training sample is related to the target task, the data processing accuracy is the data processing accuracy of the first neural network model for the target task, and the ability of each parameter to affect the data processing accuracy is positively correlated with the following information: During the training of the first neural network model for the target task, the numerical change corresponding to each parameter.
12. The method according to claim 11, characterized in that After sending the model update indication to the server, the method further includes: receiving the compressed model update information sent by the server, and decompressing the compressed model update information to obtain the model update information; wherein, The model update information includes multiple parameters, and the multiple parameters are obtained by updating the parameters of the target quantity or target ratio, and the difference between the number of parameters included in the model update information and the target number is within a preset range; or, the ratio of the number of parameters included in the model update information to the number of parameters included in the first neural network model and the target ratio are within a preset range.
13. The method according to claim 11, characterized in that After sending the model update indication to the server, the method further includes: receiving the compressed model update information sent by the server, and decompressing the compressed model update information to obtain the model update information; wherein, The model update information includes numerical changes of multiple parameters, and the numerical changes of the multiple parameters are numerical changes of updating multiple parameters in the first neural network model.
14. A model training device, characterized in that: The device comprises: An acquisition module is configured to acquire a first neural network model and a training sample, wherein the first neural network model includes M parameters; the training sample is text data, image data, or audio data; a model updating module, configured to train the first neural network model based on the training samples to update N parameters of the M parameters until the data processing accuracy of the first neural network model meets a preset condition, thereby obtaining a second neural network model; wherein N is a positive integer less than M, and the N parameters are determined based on the ability of each parameter of the M parameters to affect the data processing accuracy; The model updating module is specifically configured to train the first neural network model according to the training sample using a preset loss function to update N of the M parameters; wherein the preset loss function includes a target loss term, and the target loss term is used to constrain the update amplitude of the parameters; The training sample is related to the target task, the data processing accuracy is the data processing accuracy of the first neural network model for the target task, and the ability of each parameter to affect the data processing accuracy is positively correlated with the following information: During the training of the first neural network model for the target task, the numerical change corresponding to each parameter.
15. The device according to claim 14, characterized in that In the second neural network model, parameters other than the N parameters among the M parameters are not updated.
16. The device according to claim 14 or 15, characterized in that The N parameters are the N parameters that have the greatest impact on the data processing accuracy of the first neural network model among the M parameters; or The N parameters are N parameters among the M parameters whose influence on the data processing accuracy of the first neural network model is greater than a threshold.
17. The device according to claim 14 or 15, characterized in that The ratio of N to M is less than 10%.
18. The device according to claim 14 or 15, characterized in that The apparatus further includes: a receiving module for receiving a model update indication sent by a terminal device before training the first neural network model according to the training sample to update N of the M parameters, wherein the model update indication is used to indicate an update of the N number of parameters in the first neural network model; or, the model update indication is used to indicate an update of a target proportion of parameters in the first neural network model.
19. The device according to claim 14 or 15, characterized in that The second neural network model includes the updated N parameters, and the acquisition module is further used to: After obtaining the second neural network model, obtaining model update information; wherein the model update information includes a numerical change of each parameter in the M parameters in the second neural network model compared to before the update; The device further comprises: A compression module, configured to compress the model update information to obtain compressed model update information; The sending module is used to send the compressed model update information to the terminal device.
20. The device according to claim 19, characterized in that The sending module is used to send model update information to the terminal device after the second neural network model is obtained; wherein the model update information includes the updated N parameters, and the model update information does not include parameters other than the N parameters in the M parameters.
21. The device according to claim 14 or 15, characterized in that The model updating module is further configured to, before training the first neural network model according to the training samples to update N of the M parameters, train the first neural network model according to the training samples to update the M parameters and determine the ability of each of the M parameters to influence the data processing accuracy; and determine N parameters from the M parameters according to the ability of each of the M parameters to influence the data processing accuracy.
22. The device according to claim 14 or 15, characterized in that The model updating module is specifically configured to train the first neural network model based on the training samples to update the M parameters and determine the influence of each of the M parameters on the data processing accuracy; Determining N parameters from the M parameters according to the influence of each parameter in the M parameters on the data processing accuracy; Restoring the other parameters of the updated M parameters except the N parameters to the corresponding parameter values in the first neural network model.
23. The device according to claim 14 or 15, characterized in that The second neural network model is used to process the data to be processed to obtain a data processing result, and the data to be processed is text data, image data or audio data.
24. A parameter configuration device for model update, characterized in that: The device comprises: A display module, configured to display a configuration interface, wherein the configuration interface includes a first control, and the first control is configured to instruct a user to input a number or a ratio of parameters that need to be updated in the first neural network model; an acquisition module, configured to acquire a target quantity or a target ratio input by a user through the first control; a sending module, configured to send a model update indication to a server, wherein the model update indication includes the target quantity or target ratio, and the target quantity or target ratio is used to indicate that a parameter of the target quantity or target ratio in the first neural network model is updated when training the first neural network model; The loss function used in training the first neural network model includes a target loss term, and the target loss term is used to constrain the update amplitude of the parameters; The parameters of the target quantity or target ratio are determined according to the ability of each parameter in the first neural network model to affect the data processing accuracy; The training sample of the first neural network model is text data, image data, or audio data; the training sample is related to the target task, the data processing accuracy is the data processing accuracy of the first neural network model for the target task, and the ability of each parameter to affect the data processing accuracy is positively correlated with the following information: During the training of the first neural network model for the target task, the numerical change corresponding to each parameter.
25. The device according to claim 24, characterized in that The device further includes: a receiving module, configured to receive compressed model update information sent by the server after sending the model update instruction to the server, and decompress the compressed model update information to obtain the model update information; wherein, The model update information includes multiple parameters, and the multiple parameters are obtained by updating the parameters of the target quantity or target ratio, and the difference between the number of parameters included in the model update information and the target number is within a preset range; or, the ratio of the number of parameters included in the model update information to the number of parameters included in the first neural network model and the target ratio are within a preset range.
26. The device according to claim 25, characterized in that The receiving module is further configured to, after sending the model update instruction to the server, receive the compressed model update information sent by the server, and decompress the compressed model update information to obtain the model update information; wherein, The model update information includes numerical changes of multiple parameters, and the numerical changes of the multiple parameters are numerical changes of updating multiple parameters in the first neural network model.
27. A model training device, characterized in that: The device includes a memory and a processor; the memory stores codes, and the processor is configured to obtain the codes and execute the method according to any one of claims 1 to 10.
28. A parameter configuration device for model update, characterized in that: The device includes a memory and a processor; the memory stores codes, and the processor is configured to obtain the codes and execute the method according to any one of claims 11 to 13.
29. A computer storage medium, characterized in that The computer storage medium stores one or more instructions, which, when executed by one or more computers, enable the one or more computers to implement the method of any one of claims 1 to 13.
30. A computer program product comprising code, characterized in that When the code is executed, it is used to implement the method according to any one of claims 1 to 13.
Citation Information
Patent Citations
Neural network training method and device and electronic device
CN109784490A
Neural network model training method based on parameter evaluation and related device
CN111582450A