Model training method and related device thereof
By assigning positional encoding to neurons, the model instability caused by changes in neuron position in federated learning is solved, ensuring that neurons with the same function maintain consistent positions across client models. This achieves improved stability and performance of the trained model output.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- HUAWEI TECH CO LTD
- Filing Date
- 2022-03-26
- Publication Date
- 2026-05-22
AI Technical Summary
In federated learning systems, different clients use different training data for the same model to be trained, which leads to changes in neuron positions, causing instability in the model training process and affecting the performance of the trained model.
By assigning a positional encoding to each neuron, it is ensured that neurons with the same function maintain the same position in the models of various clients. The server processes neurons by position during aggregation, and uses parameters and positional encoding to process and update the training data, thus limiting the rearrangement invariance of the neural network model.
This achieves stability in the model's output after training, ensuring that the model possesses sufficiently excellent data processing capabilities and improving the stability and performance of model training.
Smart Images

Figure CN114841361B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence (AI) technology, and in particular to a model training method and related equipment. Background Technology
[0002] As users become increasingly aware of data security and data security issues such as frequent leaks of users' personal privacy data emerge, users are constantly increasing their efforts to protect data involving personal privacy, which in turn poses new challenges to AI model training. Therefore, federated learning, a model training method, has emerged.
[0003] Federated learning systems typically consist of a server and multiple clients. During model training, the server first distributes the model to be trained to each client. Each client device receives the model and trains it using locally stored training data, resulting in an updated model. Then, each client can upload its updated model to the server. Finally, the server aggregates the updated models uploaded by all clients to obtain the trained model.
[0004] Because different clients use different training data for the same model to be trained, and due to the rearrangement invariance of neural network models (the output of the model remains unchanged after the positions of certain neurons with different functions are swapped), the positions of certain neurons with different functions have changed in the updated models obtained by some clients, relative to the neuron distribution in the model to be trained. Therefore, in the updated models obtained by different clients, neurons with the same function are not all in the same position. Since the server processes neurons in each updated model according to their position during aggregation, the resulting trained model may not possess sufficiently good functionality. Summary of the Invention
[0005] This application provides a model training method and related equipment, which enables the trained model obtained by joint training between the client and the server to have sufficiently excellent functions.
[0006] A first aspect of this application provides a model training method, the method comprising:
[0007] When model training is required, the model to be trained can be obtained first. This model contains multiple neurons, each associated with parameters (the aforementioned parameter information) and position encoding (PE) (the aforementioned positional encoding information). In other words, each neuron has both parameters and a positional encoding. Different neurons have different positional encodings. For any given neuron, its positional encoding indicates its position within the model to be trained. For example, in the two intermediate layers of the model, layer 2 contains 3 neurons, and layer 3 contains 4 neurons. The positional encodings of these 7 neurons could be 1, 2, 3, 4, 5, 6, and 7, respectively.
[0008] After obtaining the model to be trained, the training data can be processed using the parameters and positional encodings of multiple neurons in the model to update the model, thereby obtaining the updated model. The updated model is then sent out to achieve model aggregation, thus obtaining the trained model.
[0009] In one possible implementation, the steps of the above model training method can be implemented by a client, which can be any one of multiple clients in the federated learning system. In this case, the client can collaborate with the server in the federated learning system to complete the model training. The specific model training process is as follows:
[0010] When the server needs to obtain a neural network model with data processing capabilities, it can first obtain the model to be trained and distribute it to multiple clients. Upon receiving the model to be trained from the server, any one of these clients can use its own locally stored data as training data to train the model.
[0011] Specifically, after receiving the model to be trained, the client can use its own stored local data as training data and input it into the model. The model's multiple neurons then process the training data to obtain the processing result. It is worth noting that each neuron in the model has parameters and positional encoding. Therefore, these neurons, acting as multiple data processing units within the model, can use their own parameters and positional encodings to process the training data, thereby obtaining the processing result.
[0012] After obtaining the processing results of the training data, the client can update the parameters of the neurons in the model to be trained based on the processing results, and obtain the updated model.
[0013] After obtaining the updated model, the client can send the updated model to the server. The server can then perform federated aggregation based on the updated model uploaded by the client and the updated models uploaded by other clients to obtain the trained model.
[0014] The model training process described above shows that after a client obtains the model to be trained from the server, it processes its local training data using the parameters and positional codes of multiple neurons in the model to obtain the processed training data. Then, the client can update the parameters of these neurons in the model based on this processing result, thus obtaining the updated model. Specifically, for any one neuron in the model, it has parameters and positional codes, and these positional codes differ from those of the other neurons. Therefore, the positional codes of this neuron constrain its function and distinguish it from the functions of the other neurons. Compared to the neuron distribution in the model under training, if the function of neurons at certain locations in the updated model changes (i.e., the location of neurons with different functions changes), the output of the model with the positional changes will differ from the output of the model without positional changes because the positional encoding of these neurons remains unchanged (since positional encoding is only related to the neuron's location). This leads to instability in the model training process and affects the performance of the trained model. Therefore, when updating the parameters of each neuron in the model under training, the client will try to keep the function of neurons at each location unchanged to ensure that the output of the updated model is as stable as possible. Thus, the positional encoding of neurons effectively curbs the rearrangement invariance of the neural network model. Since other clients can also perform the same operations as this client, neurons with the same function are located in the same position in the updated models uploaded to the server by each client. Therefore, when the server performs aggregation, it can process the neurons in each updated model according to their position, resulting in a trained model with sufficiently good functionality.
[0015] In one possible implementation, the position codes of multiple neurons are determined by the server based on the positions of the multiple neurons in the model to be trained, or the position codes of multiple neurons are determined by the client and the server based on the positions of the multiple neurons in the model to be trained. In the aforementioned implementation, the position codes of neurons can be set in several ways: (1) In the model to be trained, for all neurons from layer 2 to layer N-1, the position codes of these multiple neurons can be determined by the server based on the positions of these multiple neurons in the model to be trained, that is, among these multiple neurons, the position code of any one neuron is defined by the server based on the position of that neuron in the model to be trained. (2) In the model to be trained, for all neurons from layer 2 to layer N-1, the position codes of these multiple neurons can be determined jointly by multiple clients and the server based on the positions of the multiple neurons in the model to be trained, that is, among these multiple neurons, the position code of any one neuron is agreed upon in advance by the server and multiple clients based on the position of that neuron in the model to be trained.
[0016] In one possible implementation, the model to be trained comprises N layers: layer 1 is the input layer, layers 2 through N-1 are intermediate layers, and layer N is the output layer. Each layer contains at least one neuron. All neurons in layer 1 are used to receive input data, therefore they may not have parameters or positional encoding. All neurons in layers 2 through N-1 are used for data processing, therefore they have parameters (e.g., weights, biases, etc.) and positional encoding. All neurons in layer N are used to output the processed data, therefore they only have parameters (e.g., weights, etc.). The client processes the training data through multiple neurons of the model to be trained, obtaining the processing result by: the client combining the parameters of the j-th neuron in layer i and the parameters of the (i-1)-th neuron in layer j. The first calculation is performed on the final output of a neuron to obtain the initial output of the j-th neuron in the i-th layer, where i = 2, ..., N-1, j = 1, ..., M, N ≥ 3, M ≥ 1. The client then performs a second calculation on the position encoding of the j-th neuron in the i-th layer and its initial output to obtain the final output of the j-th neuron in the i-th layer. The final outputs of all neurons in the first layer are the training data. The parameters of the j-th neuron in the N-th layer are used to perform the first calculation on the final outputs of all neurons in the (N-1)-th layer to obtain the final output of the j-th neuron in the N-th layer. The final outputs of all neurons in the N-th layer are the processing result. In this implementation, after the client inputs the training data into the model to be trained, all neurons in the first layer of the model can send the final outputs of all neurons in the first layer to each neuron in the second layer. The final outputs of all neurons in the first layer are the training data. Next, the first neuron in the second layer performs a first calculation based on its own parameters and the final outputs of all neurons in the first layer, obtaining its initial output. The first neuron then performs a second calculation using its own positional encoding and its initial output, obtaining its final output. The remaining neurons in the second layer can perform the same operation as the first neuron in the second layer, thus obtaining the final outputs of all neurons in the second layer. Therefore, all neurons in the second layer can send their final outputs to each neuron in the third layer, and so on, until all neurons in the (N-2)th layer send their final outputs to each neuron in the (N-1)th layer. The first neuron in the (N-1)th layer performs a first calculation based on its own parameters and the final outputs of all neurons in the (N-2)th layer, obtaining its initial output. The first neuron in the (N-1)th layer then performs a second calculation using its own positional encoding and its initial output, obtaining its final output. The remaining neurons in layer N-1 can also perform the same operations as the first neuron in layer N-1, thus obtaining the final output of all neurons in layer N-1.Since the neurons in layer N of the model to be trained do not have positional encoding, after obtaining the final outputs of all neurons in layer N-1, the first neuron in layer N can perform a first calculation using its parameters and the final outputs of all neurons in layer N-1 to obtain its final output. Then, the second neuron in layer N can perform a first calculation using its parameters and the final outputs of all neurons in layer N-1 to obtain its final output, and so on, until the final outputs of all neurons in layer N are obtained. The final outputs of all neurons in layer N are the outputs of the model to be trained, which is equivalent to the processing result of the training data. Therefore, the processing result of the training data is based on the outputs of each neuron in the model to be trained. For any neuron, its output can be obtained by performing data processing operations using its own parameters and positional encoding. Thus, when a neuron performs data processing (i.e., performs its function), it is constrained by its own positional encoding, and the influence of the neuron's positional encoding is reflected in the processing result of the training data. Therefore, when the client updates the parameters of the neuron based on the processing results of the training data, it can try to maintain the function of the neuron unchanged, thereby limiting the rearrangement invariance of the neural network.
[0017] In one possible implementation, the client performs a second calculation on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer. This calculation includes: the client performing arithmetic operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, the client performing trigonometric function operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, the client performing exponential operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, the client performing logarithmic operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer. In the aforementioned implementation, the second computation performed by the neuron can be any one of the four arithmetic operations, trigonometric function operations, exponential operations, and logarithmic operations. The positional encoding can constrain the neuron's function in various ways.
[0018] In one possible implementation, the client updates the parameters based on the processing results to obtain the updated model. This includes: the client obtaining a target loss based on the processing results and the actual processing results of the training data; the target loss indicates the difference between the processing results and the actual processing results; and the client updating the parameters and positional encodings based on the target loss to obtain the updated model. It is worth noting that when updating the model to be trained, the client updates the positional encodings less frequently than the parameters. For example, assuming there are five batches of training data, the client can input these five batches of training data sequentially into the model to be trained. After processing the parameters and positional encodings of the neurons in the model, the client can obtain the processing results for these five batches of training data. The client will then use the processing results of the five batches of training data to update the parameters of the neurons in the model five times sequentially, but only update the positional encodings of the neurons in the model once using the processing results of one batch of training data. This can, to some extent, suppress the model's rearrangement invariance.
[0019] Furthermore, the process of the client sending the updated model to the server includes: the client obtaining parameter update amounts and positional encoding update amounts based on the updated model and the model to be trained; the client sending the parameter update amounts and positional encoding update amounts to the server, which uses these amounts to update the model to be trained until the model training conditions are met, resulting in the trained model. In the aforementioned implementation, the positional encodings of neurons in the model to be trained are non-fixed values. Therefore, the client and server can jointly update the parameters and positional encodings in the model to be trained, allowing the model to learn appropriate positional encodings based on the nature of the specific task (i.e., in a certain business scenario, the user needs the model to have a certain data processing function), which is beneficial for more reasonable alignment of neurons.
[0020] In one possible implementation, the client updates the parameters based on the processing result to obtain the updated model, which includes: the client obtaining the target loss based on the processing result and the actual processing result of the training data, the target loss being used to indicate the difference between the processing result and the actual processing result; the client updating the parameters based on the target loss to obtain the updated model.
[0021] Furthermore, the process of the client sending the updated model to the server includes: the client obtaining parameter update amounts based on the updated model and the model to be trained; the client sending the parameter update amounts to the server, which uses these amounts to update the model to be trained until the model training conditions are met, resulting in the trained model. In the aforementioned implementation, the positional encoding of neurons in the model to be trained is a fixed value, so the client and server can jointly update the parameters in the model to be trained, enabling the trained model to possess certain data processing functions.
[0022] A second aspect of this application provides a model training method, the method comprising: sending a model to be trained, the model to be trained containing multiple neurons, wherein the neurons are associated with parameter information and position encoding information, and the neurons correspond one-to-one with the position encoding information; obtaining an updated model, and aggregating the updated model to obtain a trained model, wherein the updated model is obtained by updating the model to be trained based on the parameter information, position encoding information and training data.
[0023] In one possible implementation, the steps of the above model training method can be implemented by a server deployed within a federated learning system. This server can collaborate with multiple clients within the federated learning system to complete model training. The specific model training process is as follows:
[0024] The server sends the model to be trained to the client. The model contains multiple neurons, each of which has parameters and position codes. Neurons at different positions have different position codes. The multiple neurons of the model are used by the client to process the training data and obtain the processing results. Based on the processing results, the parameters are updated to obtain the updated model. The server obtains the updated model from the client and aggregates the updated models to obtain the trained model.
[0025] As can be seen from the above method, after a client obtains the model to be trained from the server, the client processes the local training data using the parameters and positional codes of multiple neurons in the model to obtain the processing result. Then, the client can update the parameters of these neurons in the model based on this processing result, thereby obtaining the updated model. Specifically, for any one neuron in the model, it has parameters and positional codes, and its positional codes differ from those of the other neurons. Therefore, the positional codes of this neuron constrain its function and distinguish it from the functions of the other neurons. Compared to the neuron distribution in the model under training, if the function of neurons at certain locations in the updated model changes (i.e., the location of neurons with different functions changes), the output of the model with the positional changes will differ from the output of the model without positional changes because the positional encoding of these neurons remains unchanged (since positional encoding is only related to the neuron's location). This leads to instability in the model training process and affects the performance of the trained model. Therefore, when updating the parameters of each neuron in the model under training, the client will try to keep the function of neurons at each location unchanged to ensure that the output of the updated model is as stable as possible. Thus, the positional encoding of neurons effectively curbs the rearrangement invariance of the neural network model. Since other clients can also perform the same operations as this client, neurons with the same function are located in the same position in the updated models uploaded to the server by each client. Therefore, when the server performs aggregation, it can process the neurons in each updated model according to their position, resulting in a trained model with sufficiently good functionality.
[0026] In one possible implementation, the position encoding of multiple neurons is determined by the server based on the positions of the multiple neurons in the model to be processed, or the position encoding of multiple neurons is determined by the client and the server based on the positions of the multiple neurons in the model to be processed.
[0027] In one possible implementation, the server receives the updated model from the client and aggregates the updated model to obtain the trained model. This includes: the server obtaining the parameter update amount and position code update amount from the client, which are obtained based on the updated model and the model to be trained; the server updating the model to be trained based on the parameter update amount and position code update amount until the model training conditions are met, thus obtaining the trained model.
[0028] In one possible implementation, the server receives the updated model from the client and aggregates the updated model to obtain the trained model. This includes: the server obtaining the parameter update amount from the client, which is based on the updated model and the model to be trained; the server updating the model to be trained based on the parameter update amount until the model training conditions are met, thus obtaining the trained model.
[0029] A third aspect of this application provides a model training apparatus, comprising: an acquisition module for acquiring a model to be trained, the model containing multiple neurons, wherein the neurons are associated with parameters and position codes, and the neurons and position codes correspond one-to-one; a processing module for updating the model to be trained using the parameters, position codes, and training data to obtain an updated model; and a sending module for sending the updated model.
[0030] In one possible implementation, the device can be any client in a federated learning system. The client's acquisition module acquires a model to be trained from the server. This model contains multiple neurons, each with parameters and positional codes, and neurons at different locations have different positional codes. The client's processing module processes the training data using the parameters and positional codes of the neurons in the model to obtain a processing result. Based on the processing result, the parameters of the neurons in the model are updated to obtain an updated model. The client's sending module sends the updated model to the server, where it is aggregated to obtain a trained model. This client demonstrates that after acquiring the model to be trained from the server, it processes its local training data using the parameters and positional codes of the neurons in the model to obtain a processing result. Then, the client can update the parameters of these neurons in the model based on this processing result, thereby obtaining an updated model. In this model, any one neuron has parameters and a positional encoding. This positional encoding differs from the encodings of the other neurons, thus constraining its function and distinguishing it from the functions of the others. If the function of neurons at certain locations in the updated model changes (i.e., some neurons with different functions change position), the positional encodings of these neurons remain unchanged (since positional encoding is only related to the neuron's position). This will cause the output of the model with positional changes to differ from the model without changes, leading to instability in the training process and affecting the performance of the trained model. Therefore, when updating the parameters of each neuron in the model, the client will try to keep the function of neurons at each location unchanged to ensure the output of the updated model is as stable as possible. Thus, the positional encoding of neurons effectively curbs the rearrangement invariance of the neural network model. Since other clients can also perform the same operations as this client, neurons with the same function are located in the same position in the updated models uploaded to the server by each client. Therefore, when the server performs aggregation, it can process the neurons in each updated model according to their position, and the resulting trained model can have sufficiently excellent functions.
[0031] In one possible implementation, the positional encoding of multiple neurons is determined by the server based on the positions of the multiple neurons in the model to be trained, or the positional encoding of multiple neurons is determined by the client and server based on the positions of the multiple neurons in the model to be trained.
[0032] In one possible implementation, the model to be trained contains N layers, with multiple neurons representing all neurons from layer 2 to layer (N-1). The processing module is used to: perform a first calculation on the parameters of the j-th neuron in layer i and the final outputs of all neurons in layer (N-1) to obtain the initial output of the j-th neuron in layer i, where i = 2, ..., N-1, j = 1, ..., M, N ≥ 3, M ≥ 1; and perform a second calculation on the position encoding of the j-th neuron in layer i and the initial output of the j-th neuron in layer i to obtain the final output of the j-th neuron in layer i. The final output of the j-th neuron in layer i is used to generate the processing result, i.e., the final outputs of all neurons in layer (N-1) are used to generate the processing result.
[0033] In one possible implementation, in the model to be trained, the first layer is the input layer, the Nth layer is the output layer, the final output of all neurons in the first layer is the training data, the parameters of the j-th neuron in the Nth layer are used to perform the first calculation on the final output of all neurons in the (N-1)th layer to obtain the final output of the j-th neuron in the Nth layer, and the final output of all neurons in the Nth layer is the processing result.
[0034] In one possible implementation, the processing module is configured to: perform arithmetic operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, perform trigonometric function operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, perform exponential operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, perform logarithmic operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer.
[0035] In one possible implementation, the processing module is used to: obtain a target loss based on the processing result and the true processing result of the training data, the target loss being used to indicate the difference between the processing result and the true processing result; and update the parameters and positional encoding based on the target loss to obtain an updated model, wherein the update frequency of the positional encoding is less than the update frequency of the parameters.
[0036] In one possible implementation, the sending module is used to: obtain parameter update amounts and position code update amounts based on the updated model and the model to be trained; send the parameter update amounts and position code update amounts to the server, and use the parameter update amounts and position code update amounts to update the model to be trained on the server until the model training conditions are met, thereby obtaining the trained model.
[0037] In one possible implementation, the processing module is used to: obtain a target loss based on the processing result and the true processing result of the training data, the target loss being used to indicate the difference between the processing result and the true processing result; and update the parameters based on the target loss to obtain the updated model.
[0038] In one possible implementation, the sending module is used to: obtain the parameter update amount based on the updated model and the model to be trained; send the parameter update amount to the server, and the parameter update amount is used by the server to update the model to be trained until the model training conditions are met, thus obtaining the trained model.
[0039] A fourth aspect of this application provides a model training apparatus, comprising: a sending module for sending a model to be trained, the model containing multiple neurons, wherein the neurons are associated with parameters and position codes, and the neurons and position codes correspond one-to-one; an acquisition module for acquiring an updated model, the updated model being obtained by updating the model to be trained based on the parameters, position codes, and training data; and an aggregation module for aggregating the updated model to obtain a trained model.
[0040] In one possible implementation, the device can be a server in a federated learning system. The server has a sending module for sending a model to be trained to a client. The model contains multiple neurons, each with parameters and positional codes. Neurons at different positions have different positional codes. These parameters and positional codes are used by the client to process the training data, obtain processing results, and update the parameters based on these results to obtain an updated model. An acquisition module is used to acquire the updated model from the client. An aggregation module is used to aggregate the updated model to obtain a trained model. From this server, it can be seen that after a client acquires the model to be trained from the server, it processes its local training data using the parameters and positional codes of the multiple neurons in the model to obtain processing results. Then, the client can update the parameters of these neurons in the model based on these processing results to obtain an updated model. Specifically, for any one neuron in the model, it has parameters and positional codes, and its positional code differs from the positional codes of the other neurons. Therefore, the positional code of this neuron can constrain its function and distinguish it from the functions of the other neurons. Compared to the neuron distribution in the model under training, if the function of neurons at certain locations in the updated model changes (i.e., the location of neurons with different functions changes), the output of the model with the positional changes will differ from the output of the model without positional changes because the positional encoding of these neurons remains unchanged (since positional encoding is only related to the neuron's location). This leads to instability in the model training process and affects the performance of the trained model. Therefore, when updating the parameters of each neuron in the model under training, the client will try to keep the function of neurons at each location unchanged to ensure that the output of the updated model is as stable as possible. Thus, the positional encoding of neurons effectively curbs the rearrangement invariance of the neural network model. Since other clients can also perform the same operations as this client, neurons with the same function are located in the same position in the updated models uploaded to the server by each client. Therefore, when the server performs aggregation, it can process the neurons in each updated model according to their position, resulting in a trained model with sufficiently good functionality.
[0041] In one possible implementation, the position encoding of multiple neurons is determined by the server based on the positions of the multiple neurons in the model to be processed, or the position encoding of multiple neurons is determined by the client and the server based on the positions of the multiple neurons in the model to be processed.
[0042] In one possible implementation, an acquisition module is used to acquire parameter update values and position code update values from the client, which are obtained based on the updated model and the model to be trained; an aggregation module is used to update the model to be trained based on the parameter update values and position code update values until the model training conditions are met, thus obtaining the trained model.
[0043] In one possible implementation, an acquisition module is used to acquire parameter update amounts from the client, which are obtained based on the updated model and the model to be trained; an aggregation module is used to update the model to be trained based on the parameter update amounts until the model training conditions are met, thus obtaining the trained model.
[0044] A fifth aspect of this application provides a client, which includes a memory and a processor; the memory stores code, and the processor is configured to execute the code. When the code is executed, the client performs the method as described in the first aspect or any possible implementation thereof.
[0045] A sixth aspect of this application provides a server, which includes a memory and a processor; the memory stores code, and the processor is configured to execute the code. When the code is executed, the server performs the method described in the second aspect or any possible implementation thereof.
[0046] A seventh aspect of this application provides a federated learning system, which includes a client as described in the fifth aspect and a server as described in the sixth aspect, wherein the client and server are communicatively connected.
[0047] An eighth aspect of this application provides a circuit system including a processing circuit configured to perform the method described in the first aspect, any possible implementation of the first aspect, or the method described in the second aspect.
[0048] A ninth aspect of this application provides a chip system including a processor for calling a computer program or computer instructions stored in a memory to cause the processor to perform the method described in the first aspect, any possible implementation of the first aspect, or the method described in the second aspect.
[0049] In one possible implementation, the processor is coupled to the memory via an interface.
[0050] In one possible implementation, the chip system also includes a memory that stores computer programs or computer instructions.
[0051] A tenth aspect of this application provides a computer storage medium storing a computer program that, when executed by a computer, causes the computer to perform the method described in the first aspect, any possible implementation of the first aspect, or the method described in the second aspect.
[0052] The eleventh aspect of this application provides a computer program product storing instructions that, when executed by a computer, cause the computer to perform the method described in the first aspect, any possible implementation of the first aspect, or the method described in the second aspect.
[0053] In this embodiment, after a client obtains the model to be trained from the server, the client processes the local training data using the parameters and position codes of multiple neurons in the model to obtain the processing result. Then, the client can update the parameters of these neurons in the model based on the processing result, thereby obtaining the updated model. Specifically, for any one neuron in the model, it has parameters and position codes, and the position codes of this neuron are different from those of the other neurons. Therefore, the position codes of this neuron can constrain its function and distinguish it from the functions of the other neurons. Compared to the neuron distribution in the model under training, if the function of neurons at certain locations in the updated model changes (i.e., the location of neurons with different functions changes), the output of the model with the positional changes will differ from the output of the model without positional changes because the positional encoding of these neurons remains unchanged (since positional encoding is only related to the neuron's location). This leads to instability in the model training process and affects the performance of the trained model. Therefore, when updating the parameters of each neuron in the model under training, the client will try to keep the function of neurons at each location unchanged to ensure that the output of the updated model is as stable as possible. Thus, the positional encoding of neurons effectively curbs the rearrangement invariance of the neural network model. Since other clients can also perform the same operations as this client, neurons with the same function are located in the same position in the updated models uploaded to the server by each client. Therefore, when the server performs aggregation, it can process the neurons in each updated model according to their position, resulting in a trained model with sufficiently good functionality. Attached Figure Description
[0054] Figure 1 A structural diagram illustrating the main framework of artificial intelligence;
[0055] Figure 2 A schematic diagram of the structure of the federated learning system provided in the embodiments of this application;
[0056] Figure 3 A schematic diagram of the system 100 architecture provided in the embodiments of this application;
[0057] Figure 4 A schematic diagram illustrating an application example of the federated learning system provided in this application embodiment;
[0058] Figure 5 This is a schematic diagram illustrating another application example of the federated learning system provided in the embodiments of this application;
[0059] Figure 6 Another application example of the federated learning system provided in this application is illustrated in the following diagram.
[0060] Figure 7 A schematic flowchart of the model training method provided in the embodiments of this application;
[0061] Figure 8 A schematic diagram of the structure of the federated learning system provided in the embodiments of this application;
[0062] Figure 9 A schematic diagram of the structure of the model to be trained provided in an embodiment of this application;
[0063] Figure 10 Another schematic diagram of the structure of the federated learning system provided in the embodiments of this application;
[0064] Figure 11 Another schematic diagram of the model training method provided in the embodiments of this application;
[0065] Figure 12 A schematic diagram of the structure of a client provided in an embodiment of this application;
[0066] Figure 13 A schematic diagram of the server structure provided in the embodiments of this application;
[0067] Figure 14 A schematic diagram of the structure of the execution device provided in the embodiments of this application;
[0068] Figure 15 A schematic diagram of the structure of the training device provided in the embodiments of this application;
[0069] Figure 16 This is a schematic diagram of the structure of a chip provided in an embodiment of this application. Detailed Implementation
[0070] This application provides a model training method and related equipment, which enables the trained model obtained by joint training between the client and the server to have sufficiently excellent functions.
[0071] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such terms are interchangeable where appropriate; this is merely a way of distinguishing objects with the same attributes in the embodiments of this application. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion, so that a process, method, system, product, or apparatus that comprises a series of elements is not necessarily limited to those elements, but may include other elements not explicitly listed or inherent to those processes, methods, products, or apparatuses.
[0072] As users become increasingly aware of data security and data security issues such as frequent leaks of users' personal privacy data emerge, users are constantly increasing their efforts to protect data involving personal privacy, which in turn poses new challenges to AI model training. Therefore, federated learning, a model training method, has emerged.
[0073] Federated learning systems typically consist of a server and multiple clients. During model training, the server first distributes the model to be trained to each client. Each client device receives the model and trains it using locally stored training data, resulting in an updated model. Then, each client can upload its updated model to the server. Finally, the server aggregates the updated models uploaded by all clients to obtain the trained model.
[0074] Because different clients use different training data for the same model to be trained, and due to the rearrangement invariance of neural network models (the output of the model remains unchanged after the positions of certain neurons with different functions are swapped), the positions of certain neurons with different functions have changed in the updated models obtained by some clients, relative to the neuron distribution in the model to be trained. Therefore, in the updated models obtained by different clients, neurons with the same function are not all in the same position. Since the server processes neurons in each updated model according to their position during aggregation, the resulting trained model will not have sufficiently good data processing capabilities.
[0075] For example, suppose a federated learning system includes a server, client 1, and client 2. In the second layer of the model to be trained, provided by the server, the first neuron implements function 1, and the second neuron implements function 2. Client 1 inputs local data 1 into the model to be trained and obtains processing result 1. Then, based on processing result 1, it updates the parameters of the neurons in the model to be trained, resulting in an updated model 1. In the updated model 1, the function of the first neuron in the second layer changes to function 2, and the function of the second neuron in the second layer changes to function 1. Similarly, client 2 inputs local data 2 into the model to be trained and obtains processing result 2. Then, based on processing result 2, it updates the parameters of the neurons in the model to be trained, resulting in an updated model 2. In the updated model 2, the function of the first neuron in the second layer remains function 1, and the function of the second neuron in the second layer remains function 2. As can be seen, compared with the neuron distribution of the model to be trained, the positions of the two neurons used to implement function 1 and function 2 in the updated model 1 have been swapped, while the positions of the two neurons used to implement function 1 and function 2 in the updated model 2 remain unchanged.
[0076] After receiving the updated Model 1, Client 1 can obtain Parameter Update 1 (containing the parameter update amounts of each neuron in the updated Model 1, such as the parameter update amounts of the first neuron in the second layer, the second neuron in the second layer, etc.) based on the updated Model 1 and the model to be trained, and send it to the server. Similarly, Client 2 can also obtain Parameter Update 2 (containing the parameter update amounts of each neuron in the updated Model 2, such as the parameter update amounts of the first neuron in the second layer, the second neuron in the second layer, etc.) and send it to the server. After obtaining Parameter Update 1 and Parameter Update 2, the client can perform an averaging calculation to obtain the average value of the parameter update amounts (containing the average value of the parameter update amounts of each neuron, such as the average value of the parameter update amounts of the first neuron in the second layer, the second neuron in the second layer, etc.). Since the server locally stores the model to be trained, it can update the parameters of each neuron in the model to be trained accordingly based on the average value of the parameter update amounts.
[0077] Afterward, the server can continue to repeat the aforementioned process with clients 1 and 2 until the model meets the preset model training conditions, resulting in a trained model. However, the trained model obtained in this way cannot possess sufficiently good data processing capabilities. For example, when the server calculates the average parameter update of the first neuron in the second layer, it is based on the parameter update of the first neuron in the second layer of the updated model 1 and the first neuron in the second layer of the updated model 2. However, the first neuron in the second layer of the updated model 1 is used to implement function 2, and the first neuron in the second layer of the updated model 2 is used to implement function 1. Therefore, updating the parameters of the first neuron in the second layer of the untrained model based on the average parameter update of the first neuron in the second layer will cause this neuron to malfunction after the parameter update. It can be seen that in the trained model, neurons at multiple locations will malfunction, resulting in the trained model lacking excellent data processing capabilities.
[0078] To address the aforementioned issues, embodiments of this application provide a model training method based on federated learning.
[0079] This method can be implemented by combining artificial intelligence (AI) technology. AI technology is a technical discipline that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence. AI technology achieves optimal results by perceiving the environment, acquiring knowledge, and using that knowledge. In other words, artificial intelligence technology is a branch of computer science that attempts to understand the essence of intelligence and produce a new kind of intelligent machine that can react in a way similar to human intelligence. Using artificial intelligence for data processing is a common application of artificial intelligence.
[0080] First, the overall workflow of the artificial intelligence system is described; please refer to [link / reference]. Figure 1 , Figure 1 This is a structural diagram illustrating the main framework of artificial intelligence. The following explanation of the AI framework is based on two dimensions: the "Intelligent Information Chain" (horizontal axis) and the "IT Value Chain" (vertical axis). The "Intelligent Information Chain" reflects a series of processes from data acquisition to processing. For example, it could be the general process of intelligent information perception, intelligent information representation and formation, intelligent reasoning, intelligent decision-making, and intelligent execution and output. In this process, data undergoes a condensation process of "data—information—knowledge—wisdom." The "IT Value Chain" reflects the value that artificial intelligence brings to the information technology industry, from the underlying infrastructure of human intelligence and information (provided and processed by technology) to the industrial ecosystem of the system.
[0081] (1) Infrastructure
[0082] Infrastructure provides computing power to support artificial intelligence systems, enabling communication with the external world and providing support through a basic platform. This communication occurs through sensors; computing power is provided by intelligent chips (hardware acceleration chips such as CPUs, NPUs, GPUs, ASICs, and FPGAs); and the basic platform includes distributed computing frameworks and related platform guarantees and support, which may include cloud storage and computing, interconnected networks, etc. For example, sensors communicate with the outside world to acquire data, and this data is provided to intelligent chips in the distributed computing system provided by the basic platform for computation.
[0083] (2) Data
[0084] The data at the next layer of infrastructure is used to represent the data sources in the field of artificial intelligence. The data involves graphics, images, voice, text, and IoT data from traditional devices, including business data from existing systems and sensor data such as force, displacement, liquid level, temperature, and humidity.
[0085] (3) Data processing
[0086] Data processing typically includes methods such as data training, machine learning, deep learning, search, reasoning, and decision-making.
[0087] Among them, machine learning and deep learning can perform intelligent information modeling, extraction, preprocessing, and training on data, including symbolization and formalization.
[0088] Reasoning refers to the process in which, in a computer or intelligent system, the machine thinks and solves problems by simulating human intelligent reasoning, based on reasoning control strategies and using formalized information. Typical functions include search and matching.
[0089] Decision-making refers to the process of making decisions based on intelligent information after reasoning, and it typically provides functions such as classification, sorting, and prediction.
[0090] (4) General ability
[0091] After the data processing mentioned above, the results of the data processing can be used to form some general capabilities, such as algorithms or a general system, for example, translation, text analysis, computer vision processing, speech recognition, image recognition, etc.
[0092] (5) Smart Products and Industry Applications
[0093] Intelligent products and industry applications refer to products and applications of artificial intelligence systems in various fields. They are the encapsulation of overall artificial intelligence solutions, productizing intelligent information decision-making and realizing practical applications. Their application areas mainly include: intelligent terminals, intelligent transportation, intelligent healthcare, autonomous driving, smart cities, etc.
[0094] The following section introduces several application scenarios for this application.
[0095] Figure 2 This is a schematic diagram of a federated learning system provided in an embodiment of this application. The federated learning system includes a server and multiple clients, which can be connected through a communication network. The clients include smart terminals such as mobile phones, personal computers, or information processing centers, while the server can be a device or server with data processing capabilities, such as a cloud server, network server, application server, or management server. The clients and servers can collaborate to train a neural network model.
[0096] Multiple clients and a server can perform iterative model training. Specifically, in the first iteration, each client receives the model to be trained from the server through an interactive interface. Then, using a local data storage device and a data processor, the client trains the model using machine learning, deep learning, search, inference, and decision-making methods. After each client completes model training (i.e., updates the parameters of the model), it can upload the updated model to the server. The server then aggregates the updated models uploaded by each client and trains its local model based on the aggregation result. The server can then use its own trained and updated model as the new model to be trained and distribute it to each client again for the second iteration of model training (i.e., repeating the aforementioned process). After multiple iterations, once the server determines that its last trained and updated model meets the model training conditions, it uses this last trained and updated model as the trained model (i.e., the fully trained model). In this way, the server indirectly utilizes the local data of each client to complete model training while ensuring the data security of each client, thereby protecting user privacy.
[0097] It should be noted that, to further ensure data security, in each iteration, each client can upload the parameter update amount of the model to the server, representing the updated model obtained by each client. The server can then average the parameter update amounts from each client and use this average to update the parameters of the local model to be trained on the server, thereby enabling the server-side model training.
[0098] exist Figure 2 In this application, the server and client can jointly execute the model training method of the embodiments.
[0099] Furthermore, in the federated learning system provided in this application embodiment, the server obtains a trained model with data processing capabilities, and thus the model can be deployed on various clients. Therefore, each client can provide data processing services to users. When a client obtains data to be processed from user input, it can call the trained model to process the user-input data accordingly and return the corresponding processing result to the user.
[0100] exist Figure 2 In this application, the client can use the trained model obtained by the model training method in this embodiment to realize data processing functions.
[0101] Figure 3 A schematic diagram of the system 100 architecture provided in this application embodiment, in Figure 3 In the process, the execution device 110 is configured with an input / output (I / O) interface 112 for data interaction with external devices. Users can input data to the I / O interface 112 through the client device 140. The input data in this embodiment may include various scheduled tasks, callable resources, and other parameters.
[0102] During the preprocessing of input data by the execution device 110, or during the computational model 111 of the execution device 110 performing computation and other related processing (such as implementing the neural network function in this application), the execution device 110 may call data, code, etc. in the data storage system 150 for corresponding processing, or store the data, instructions, etc. obtained from the corresponding processing into the data storage system 150.
[0103] Finally, I / O interface 112 returns the processing result to client device 140, thereby providing it to the user.
[0104] It is worth noting that the training device 120 can generate corresponding target models / rules based on different training data for different objectives or tasks. These target models / rules can then be used to achieve the aforementioned objectives or complete the aforementioned tasks, thereby providing the user with the required results. The training data can be stored in the database 130 and originates from training samples collected by the data acquisition device 160.
[0105] exist Figure 3In the scenario shown, the user can manually provide input data, which can be done through the interface provided by I / O interface 112. Alternatively, the client device 140 can automatically send input data to I / O interface 112. If user authorization is required for the client device 140 to automatically send input data, the user can set the corresponding permissions in the client device 140. The user can view the output results of the execution device 110 on the client device 140, which can be presented in various forms such as display, sound, or animation. The client device 140 can also act as a data acquisition terminal, collecting the input data and output results of the input I / O interface 112 as new sample data and storing them in the database 130. Alternatively, data can be collected directly from the I / O interface 112 without going through the client device 140, using the input data and output results of the input I / O interface 112 as new sample data and storing them in the database 130.
[0106] It is worth noting that, Figure 3 This is merely a schematic diagram of a system architecture provided in an embodiment of this application. The positional relationships between the devices, components, modules, etc., shown in the diagram do not constitute any limitation. For example, in Figure 3 In this context, the data storage system 150 is an external memory relative to the execution device 110. However, in other cases, the data storage system 150 can also be placed within the execution device 110. For example... Figure 3 As shown, a neural network can be trained using training device 120.
[0107] It should be noted that in the embodiments of this application, the training device 120 usually refers to the aforementioned server, and the execution device 110 usually refers to the aforementioned client. When training the model, the training device 120 can work together with the execution device 110 to train the model, that is, the two can train the model in a federated learning manner.
[0108] This application also provides a chip including a neural network processor (NPU). This chip can be configured as follows: Figure 3 The execution device 110 shown is used to perform calculations for the computational model 111. This chip can also be placed in, for example... Figure 3 The training device 120 shown is used to complete the training work of the training device 120 and output the target model / rules.
[0109] The Neural Processing Unit (NPU) is a coprocessor mounted on the main central processing unit (CPU) (host CPU), where tasks are assigned by the CPU. The core of the NPU is the computation circuitry, which is controlled by a controller to retrieve data from memory (weight memory or input memory) and perform calculations.
[0110] In some implementations, the arithmetic circuitry includes multiple process engines (PEs). In some implementations, the arithmetic circuitry is a two-dimensional pulsating array. The arithmetic circuitry can also be a one-dimensional pulsating array or other electronic circuitry capable of performing mathematical operations such as multiplication and addition. In some implementations, the arithmetic circuitry is a general-purpose matrix processor.
[0111] For example, suppose we have an input matrix A, a weight matrix B, and an output matrix C. The arithmetic circuit retrieves the corresponding data of matrix B from the weight memory and caches it in each PE (Process Equipment) of the arithmetic circuit. The arithmetic circuit retrieves the data of matrix A from the input memory and performs matrix operations with matrix B. The partial or final result of the obtained matrix is stored in the accumulator.
[0112] Vector computation units can further process the output of computational circuits, such as vector multiplication, vector addition, exponentiation, logarithmic operations, size comparisons, etc. For example, vector computation units can be used for computation in non-convolutional / non-FC layers of neural networks, such as pooling, batch normalization, and local response normalization.
[0113] In some implementations, the vector computation unit can store the processed output vector into a unified buffer. For example, the vector computation unit can apply a nonlinear function to the output of the arithmetic circuit, such as a vector of accumulated values, to generate activation values. In some implementations, the vector computation unit generates normalized values, merged values, or both. In some implementations, the processed output vector can be used as activation input to the arithmetic circuit, for example, for use in subsequent layers of a neural network.
[0114] The unified memory is used to store input data and output data.
[0115] The weight data is directly transferred from the external memory to the input memory and / or unified memory, stored in the weight memory, and stored in the unified memory to the external memory through the direct memory access controller (DMAC).
[0116] The bus interface unit (BIU) is used to enable interaction between the main CPU, DMAC, and instruction fetch memory via a bus.
[0117] The instruction fetch buffer, connected to the controller, is used to store the instructions used by the controller.
[0118] The controller is used to invoke instructions cached in the memory to control the operation of the computing accelerator.
[0119] Generally, the unified memory, input memory, weight memory, and instruction fetch memory are all on-chip memories, while external memory is memory outside the NPU. This external memory can be double data rate synchronous dynamic random access memory (DDRSDRAM), high bandwidth memory (HBM), or other readable and writable memories.
[0120] Furthermore, the federated learning system provided in this application embodiment can also be applied to various fields, which will be described separately below. Figure 4 A schematic diagram illustrating an application example of the federated learning system provided in this application embodiment, such as... Figure 4 As shown, federated learning systems can be applied to the smart home field. In this case, multiple clients in the system are smart home devices located in multiple homes at different geographical locations. These smart home devices can communicate with a cloud server (i.e., the server-side) to achieve federated learning.
[0121] To deploy speech recognition-enabled neural network models across various smart home devices, cloud-based servers can perform iterative model training with multiple smart home devices. In the first iteration, each smart home device receives the model to be trained from the server, updates its parameters using local speech data, and uploads the updated model back to the server. The server then aggregates these updated models and trains its local model based on the aggregation result. The server can then use its own trained and updated model as the new model to be trained, and distribute it to the smart home devices for the second iteration of model training (i.e., repeating the aforementioned process). After multiple iterations, once the server determines that its last trained and updated model meets the training requirements, it can deploy this model as the neural network model capable of speech recognition across various smart home devices, providing smart home services to each household.
[0122] Figure 5 Another application example of the federated learning system provided in this application is illustrated below. Figure 5 As shown, a federated learning system can be applied in the field of education. In this case, multiple clients in the system are teaching devices (e.g., personal computers, tablets, etc.) located in multiple schools at different geographical locations. These teaching devices can communicate with the solver developer's server (i.e., the server-side) to achieve federated learning.
[0123] To deploy the solver—a neural network model capable of solving equations—on various teaching devices, the developer's server can perform multiple iterations of model training with multiple teaching devices. In the first iteration, each teaching device receives the model to be trained from the server, updates its parameters using local mathematical data, and uploads the updated model back to the server. The server then aggregates these updated models from all teaching devices and trains its local model based on the aggregation result. The server can then use its own updated model as the new model to be trained and distribute it to the teaching devices for the second iteration of model training (i.e., repeating the aforementioned process). After multiple iterations, once the server determines that its last updated model meets the training conditions, it can deploy this last updated model as the solver on various teaching devices to provide teaching services to students and teachers in different schools.
[0124] Figure 6Another application example of the federated learning system provided in this application is illustrated below. Figure 6 As shown, federated learning systems can be applied in the software service field, where multiple clients in the system are smart terminal devices used by multiple users or enterprises. These smart terminal devices can communicate with the server (i.e., the server-side) of a remote software developer to achieve federated learning.
[0125] To deploy image processing software—specifically, image classification neural network models—on various smart terminal devices, the software developer's server can perform multiple iterations of model training. In the initial iteration, each smart terminal device receives the model to be trained from the server, updates its parameters using local image data, and uploads the updated model back to the server. The server then aggregates these updated models and trains its local model based on the aggregation result. The server can then use its own trained and updated model as the new model to be trained, redeploying it to the smart terminal devices for the second iteration of model training (i.e., repeating the aforementioned process). After multiple iterations, once the server determines that its final trained and updated model meets the training requirements, it can deploy this model as image processing software on various smart terminal devices, providing image processing services to businesses and individuals.
[0126] It should be understood that the above is only an illustrative introduction to the application of federated learning systems in the fields of smart homes, education, and software services. In practical applications, the federated learning system provided in this application embodiment can also be applied to more fields, which will not be described one by one here.
[0127] Since the embodiments of this application involve a large number of neural network applications, for ease of understanding, the relevant terms and concepts such as neural networks involved in the embodiments of this application will be introduced below.
[0128] (1) Neural Network
[0129] A neural network can be composed of neural units, which can be operational units that take xs and an intercept of 1 as inputs, and whose output can be:
[0130]
[0131] Where s = 1, 2, ..., n, where 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, used to introduce nonlinear characteristics into the neural network to convert the input signal in the neural unit into the output signal. The output signal of this activation function can be used as the input of the next convolutional layer. The activation function can be the sigmoid function. A neural network is a network formed by connecting many of the above-mentioned individual neural units together, 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, which can be a region composed of several neural units.
[0132] The work of each layer in a neural network can be described by the mathematical expression y = a(Wx + b). From a physical perspective, the work of each layer in a neural network can be understood as transforming the input space (the set of input vectors) to the output space (i.e., from the row space to the column space of a matrix) through five operations on the input space. These five operations include: 1. Dimensionality increase / decrease; 2. Magnification / scaling; 3. Rotation; 4. Translation; 5. "Bending". Operations 1, 2, and 3 are performed by Wx, operation 4 by +b, and operation 5 by a(). The term "space" is used here because the objects being classified are not individual things, but a class of things, and space refers to the set of all individuals of this class of things. Here, W is the weight vector, and each value in this vector represents the weight value of a neuron in that layer of the neural network. This vector W determines the spatial transformation from the input space to the output space mentioned above; that is, the weights W of each layer control how the space is transformed. The purpose of training a neural network is to ultimately obtain the weight matrix of all layers of the trained neural network (a weight matrix formed by the vectors W of many layers). Therefore, the training process of a neural network is essentially about learning how to control the transformation space, and more specifically, learning the weight matrix.
[0133] Because we want the output of the neural network to be as close as possible to the actual predicted value, we can compare the current network's prediction 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, there is usually an initialization process before the first update, that is, pre-configuring the parameters of each layer in the neural network). For example, if the network's prediction is too high, the weight vector is adjusted to make it predict lower, and this adjustment is continued until the neural network can predict the actual target value. Therefore, it is necessary to predefine "how to compare the difference between the predicted value and the target value," which is the loss function or objective function. These are important equations used to measure the difference between the predicted value and the target value. Taking the loss function as an example, the higher the output value (loss) of the loss function, the greater the difference, so training the neural network becomes the process of minimizing this loss as much as possible.
[0134] (2) Backpropagation algorithm
[0135] Neural networks can employ backpropagation (BP) to correct the parameters of the initial neural network model during training, thereby reducing the reconstruction error loss. Specifically, forward propagation of the input signal to the output generates error loss; this error loss information is then propagated back to update the parameters of the initial neural network model, leading to convergence of the error loss. The backpropagation algorithm is an error-loss-driven backpropagation process aimed at obtaining the optimal parameters of the neural network model, such as the weight matrix.
[0136] (3) Federated Learning
[0137] Federated learning is a machine learning technique used to protect user privacy. Structurally, it typically involves a server (central server) and several clients. The technical process mainly includes model distribution and model aggregation. During model distribution, clients download models from the server, train them on local data, and then upload them back to the server after training to a certain extent. During model aggregation, the server collects the models uploaded by each client and merges them. These two processes iterate repeatedly until the model converges, resulting in a pre-trained model.
[0138] (4) Federal Aggregation
[0139] Federated aggregation is a subprocess of federated learning. In federated learning, the main task of the server is to aggregate the models uploaded by the client. That is, in federated learning, the server merges multiple models into one model.
[0140] (5) Parameter point-to-point aggregation
[0141] Point-to-point parameter aggregation is the simplest form of federated aggregation. This method requires that the models uploaded by multiple clients have the same structure, and the server can average the parameters of neurons at the same location in multiple models.
[0142] The method provided in this application is described below from the perspectives of neural network training and neural network application.
[0143] The model training method provided in this application involves data processing. Specifically, the client can apply methods such as data training, machine learning, and deep learning to perform symbolic and formal intelligent information modeling, extraction, preprocessing, and training on training data (e.g., training data stored locally on the client in this application). This ultimately yields an updated neural network (e.g., the updated model obtained by the client based on the training data in this application) and returns it to the server for aggregation to obtain a trained neural network (e.g., the trained model obtained by the server based on the updated model in this application). Furthermore, the trained neural network obtained by the model training method provided in this application can be deployed on the client by the server, enabling the client to implement data processing functions. This involves inputting input data into the trained neural network deployed on the client to obtain output data (i.e., the processing result of the input data). It should be noted that the model training method provided in this application and the model obtained based on this model training method for implementing data processing functions are inventions based on the same concept. They can also be understood as two parts of a system or two stages of an overall process: such as the model training stage and the model application stage.
[0144] Figure 7 This is a flowchart illustrating a model training method provided in an embodiment of this application. The method can be achieved through methods such as... Figure 8 The federated learning system shown implements ( Figure 8 (A schematic diagram of the structure of the federated learning system provided in the embodiments of this application), such as Figure 8 As shown, the system includes a server and multiple clients. Both the server and clients contain computing devices (e.g., CPU, GPU, etc.) and transmission devices (e.g., communication interfaces, etc.). The computing devices are used to train the model to be trained, and the transmission devices are used to transmit the model or model-related information. Therefore, the server and clients can train the model using federated learning. To further understand this process, the following section combines... Figure 7 This process will be described in further detail. For example... Figure 7 As shown, the method includes:
[0145] 701. The client obtains the model to be trained from the server.
[0146] In this embodiment, when the server needs to obtain a neural network model with data processing functions (e.g., image processing, speech processing, text processing, etc.), it can first obtain the model to be trained (i.e., the neural network model that needs to be trained) and send it to multiple clients.
[0147] It is worth noting that the training model sent by the server contains N layers (N is an integer greater than or equal to 3). Layer 1 is the input layer, layers 2 to N-1 are intermediate layers, and layer N is the output layer. Each layer contains at least one neuron. All neurons in layer 1 are used to receive input data, so they may not have parameters or positional encodings. All neurons in layers 2 to N-1 are used for data processing, so they all have parameters (i.e., the aforementioned parameter information, such as weights, biases, etc.) and positional encodings (i.e., the aforementioned positional encoding information). All neurons in layer N are used to output the data processing results, so they only have parameters (e.g., weights, etc.). Among these neurons in layers 2 to N-1, the positional encoding of any neuron is associated with its position in the training model, and neurons located at different positions typically have different positional encodings.
[0148] Specifically, the location encoding of neurons can be set in several ways, which will be described in detail below:
[0149] In one possible implementation, for all neurons from layer 2 to layer (N-1), the positional encoding of these neurons can be determined by the server based on their positions in the model to be processed. That is, the positional encoding of any one neuron is defined by the server based on its position in the model to be trained. For example, suppose the model to be trained contains 4 layers: layer 1 is the input layer, layer 4 is the output layer, layer 2 contains 3 neurons, and layer 3 contains 4 neurons. Then, the server can define the positional encoding of the first neuron in layer 2 as 1 and set it in the first neuron of layer 2. Therefore, the first neuron in layer 2 not only has its own parameters but also its own positional encoding. Similarly, the server can define the position code of the second neuron in the second layer as 2 and set it in the second neuron of the second layer. Therefore, the second neuron in the second layer not only has its own parameters but also its own position code, and so on. Likewise, the server can define the position code of the fourth neuron in the third layer as 7 and set it in the fourth neuron of the third layer. Therefore, the fourth neuron in the third layer not only has its own parameters but also its own position code. In this way, the server can define the position codes of all neurons in the second layer and all neurons in the third layer of the model to be trained, and set them in the corresponding neurons.
[0150] In another possible implementation, for all neurons from layer 2 to layer N-1, the positional encoding of these neurons can be determined jointly by multiple clients and the server based on the positions of these neurons in the model to be processed. That is, the positional encoding of any one neuron is pre-agreed upon by the server and multiple clients based on the neuron's position in the model to be trained. For example, ... Figure 9 As shown ( Figure 9 This is a schematic diagram of the structure of the model to be trained provided in an embodiment of this application. It should be noted that... Figure 9(The diagram illustrates the positional encoding of neurons, but not their parameters.) Assume a federated learning system includes a server, client 1, and client 2. The model to be trained contains four layers: layer 1 is the input layer, and layer 4 is the output layer. Layer 2 contains 3 neurons, and layer 3 contains 4 neurons. The server, client 1, and client 2 can define the positional encoding of the first neuron in layer 2 as 1 and set it in the first neuron of layer 2. Therefore, the first neuron in layer 2 has not only its own parameters but also its own positional encoding. Similarly, the server, client 1, and client 2 can define the positional encoding of the second neuron in layer 2 as 2 and set it in the second neuron of layer 2. Therefore, the second neuron in layer 2 has not only its own parameters but also its own positional encoding, and so on. The server, client 1, and client 2 can also define the positional encoding of the fourth neuron in layer 3 as 7 and set it in the fourth neuron of layer 3. Therefore, the fourth neuron in layer 3 has not only its own parameters but also its own positional encoding. In this way, the server, client 1, and client 2 can pre-agree on the position codes of all neurons in the second layer and all neurons in the third layer of the model to be trained, and set them in the corresponding neurons.
[0151] Since the server sends the same training model to multiple clients, the position codes of multiple neurons in the training model received by any one client are the same as the position codes of multiple neurons in the training model received by the other clients.
[0152] In a multi-client environment, each client performs the same operations on the model to be trained. Therefore, the following explanation uses one of the clients as an example. After receiving the model to be trained from the server, a client can use its own stored local data as training data to train the model.
[0153] It should be understood that the above examples are only illustrative examples of the model to be trained containing two intermediate layers, and the second layer containing three neurons and the third layer containing four neurons. They do not constitute a limitation on the number of intermediate layers and the number of neurons in the layers of the model to be trained in this application.
[0154] It should also be understood that the above examples are only illustrative of the neuron's positional encoding of 1 to 7, and do not impose any limitation on the size of the neuron's positional encoding.
[0155] 702. The client processes the training data through multiple neurons of the model to be trained and obtains the processing results. Each neuron in the multiple neurons has parameters and position codes, and neurons at different positions in the multiple neurons have different position codes.
[0156] Upon receiving the model to be trained, the client can use its own stored local data as training data and input it into the model. The model's multiple neurons then process the training data to obtain the processing result. It should be noted that for all neurons from layer 2 to layer N-1 in the model, each neuron has parameters and positional encodings. Therefore, these neurons, acting as multiple data processing units within the model, can use their own parameters and positional encodings to process (compute) the training data, thereby obtaining the processing result.
[0157] Specifically, the client can obtain the processing results of the training data using the model to be trained in the following ways:
[0158] Since the model to be trained contains N layers, we can first remember the number of neurons in each layer as:
[0159] d i ,i=1,2,...,N (2)
[0160] In the above formula, d1 represents the number of neurons in the input layer, which is equivalent to the dimension of the input training data (i.e., the dimension of the input). N The number of neurons in the output layer is equivalent to the dimension of the processing result of the training data (that is, the dimension of the output).
[0161] Then, let the parameters of each layer be:
[0162]
[0163] In the above formula, W i Let b be the weight of the neuron in the i-th layer. i represents the bias of neurons in the i-th layer. Where W... i The element in the j-th row represents the weight of the j-th neuron in the i-th layer. i The elements in the j-th row represent the biases of the j-th neuron in the i-th layer. These two elements can be considered as parameters of the j-th neuron in the i-th layer.
[0164] Subsequently, the position encoding of the j-th neuron in the i-th layer is:
[0165] g i (j), j = 1, 2, ..., d i (4)
[0166] In the above formula, since only the neurons in the middle layer (i.e., the 2nd to the N-1th layer) of the model to be trained have positional encoding, i = 2,...,N-1.
[0167] Next, let the activation function of the intermediate layers (i.e., layers 2 to N-1) be:
[0168] f i ,i=2,...,N-1 (5)
[0169] Then, let the training data input to the model to be trained be:
[0170]
[0171] In the above formula, the training data is the final output of all neurons in the first layer (including the final output of each neuron in the first layer), so x can also be denoted as h1, which contains d1 elements, that is, the dimension of h1 is d1.
[0172] Then, after the client inputs the training data x into the model to be trained, all neurons in the first layer of the model can send the final output h1 of all neurons in the first layer to each neuron in the second layer. Each neuron in the second layer calculates the final output h1 of all neurons in the first layer to obtain the final output h2 of all neurons in the second layer (h2 contains d2 elements, that is, h2 has a dimension of d2, and h2 contains the final output of each neuron in the second layer). Therefore, all neurons in the second layer can send the final output h2 of all neurons in the second layer to each neuron in the third layer, and so on, until all neurons in the (N-2)th layer send the final output h1 of all neurons in the (N-1)th layer to each neuron in the (N-2)th layer. N-2 The final output h of each neuron in layer N-1 to all neurons in layer N-2 N-2 After calculation, the final output h of all neurons in the (N-1)th layer can be obtained. N-1 (h N-1 Includes d N-1 The element, namely h N-1 The dimension is d N-1 Dimension, and h N-1 This includes the final outputs of all neurons in layer N-1. As can be seen, the calculations performed in layer i are as follows:
[0173]
[0174] In the above formula, i = 2, ..., N-1. i-1 h represents the final output of all neurons in the (i-1)th layer. i ` represents the initial output of all neurons in the i-th layer, h i `(j) represents the initial output h of all neurons in the i-th layer.i The element in the j-th row of the array, i.e., the initial output of the j-th neuron in the i-th layer, h i (j) represents the final output h of all neurons in the i-th layer. i The element in the j-th row represents the final output of the j-th neuron in the i-th layer. j = 1, ..., M, where M is the number of neurons in the i-th layer. The value of M varies with i; for example, when i = 2, M is d2, and when i = N-1, M is d... N-1 .
[0175] Based on formula (7), when i = 2, ..., N-1, the j-th neuron in the i-th layer can first combine the parameters of the j-th neuron in the i-th layer with the final output h of all neurons in the (i-1)-th layer. i-1 Perform the first calculation (the process of the first calculation can be referred to the first row of formula (7)) to obtain the initial output h of the j-th neuron in the i-th layer. i `(j). Then, the j-th neuron in the i-th layer encodes the position g of the j-th neuron in the i-th layer. i (j) and the initial output h of the j-th neuron in the i-th layer. i (j) Perform the second calculation (the process of the second calculation can be referred to the second row of formula (7)) to obtain the final output h of the j-th neuron in the i-th layer. i (j). For the remaining neurons in the i-th layer, except for the j-th neuron, the same operation as the j-th neuron can be performed, thus obtaining the final output h of all neurons in the i-th layer. i .
[0176] Since the neurons in the Nth layer of the model to be trained do not have positional encoding, each neuron in the Nth layer obtains the final output h of all neurons in the (N-1)th layer. N-1 Then, the first neuron in the Nth layer can combine the parameters of the first neuron in the Nth layer with the final output h of all neurons in the (N-1)th layer. N-1 Perform the first calculation (the process of the first calculation can be referred to the first row of formula (7)) to obtain the final output h of the first neuron in the Nth layer. N (1). Then, the second neuron in the Nth layer can combine the parameters of the second neuron in the Nth layer with the final output h of all neurons in the (N-1)th layer. N-1 Perform the first calculation to obtain the final output h of the second neuron in the Nth layer. N (2), ..., and so on, we can obtain the initial output h of all neurons in the Nth layer. N `, the final output h of all neurons in the Nth layer N This is the output of the model to be trained, which is equivalent to the result of processing the training data.
[0177] It should be understood that in this embodiment, when the client processes the training data through the model to be trained, the operations of each neuron in the model to be trained can also be regarded as the operations of the client.
[0178] It should also be understood that since the Nth layer (output layer) in the model to be trained does not have an activation function, when the neurons in the aforementioned Nth layer perform the first calculation, that is, when the neurons in the Nth layer perform the calculation according to the first row of the formula (7), the activation function f in the first row of the formula can be used. N It is considered an identity function, that is, a function whose input equals its output.
[0179] It should also be understood that this embodiment is only used to illustrate the second calculation as a multiplication operation and does not limit the type of the second calculation. For example, the second calculation can also be one or any combination of the four arithmetic operations, that is, the client can perform one or any combination of multiplication, addition, subtraction and division operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer. As another example, the second calculation can also be a trigonometric function operation, that is, the client can perform a trigonometric function operation on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer. As yet another example, the second calculation can also be an exponential operation, that is, the client can perform an exponential operation on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer. For example, the second calculation can also be a logarithmic operation, whereby the client performs a logarithmic operation on the position encoding of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer.
[0180] 703. The client updates the parameters of the neurons in the model to be processed based on the processing results, and obtains the updated model.
[0181] After obtaining the processing results of the training data, the client can update the parameters of the neurons in the model to be processed based on the processing results, and obtain the updated model.
[0182] Specifically, the client can update the parameters of neurons in the model to be processed based on the processing results in the following ways to obtain the updated model:
[0183] Since the actual processing results of the training data are known, the client can first calculate the processing results of the training data output by the model to be trained and the actual processing results of the training data using a preset target loss function to obtain the target loss. This target loss is used to indicate the difference between the processing results of the training data output by the model to be trained and the actual processing results of the training data.
[0184] After obtaining the target loss, the client updates the parameters of the neurons in the model to be trained (including the parameters of all neurons from layer 2 to layer N) based on the target loss, but does not update the positional encoding of the neurons (including the positional encoding of all neurons from layer 2 to layer N-1, which are treated as fixed values), thus obtaining the updated model.
[0185] 704. The client obtains the parameter update amount based on the updated model and the model to be trained.
[0186] 705. The client sends the parameter update amount to the server. The parameter update amount is used by the server to update the model to be trained until the model training conditions are met, and the trained model is obtained.
[0187] After obtaining the updated model, the client can send the updated model to the server. Therefore, the server can perform federated aggregation based on the updated model uploaded by the client and the updated models uploaded by other clients to obtain the trained model.
[0188] Specifically, the client can upload the updated model in the following ways, so that the server can perform federated aggregation based on the updated model:
[0189] After obtaining the updated model, the client can determine the parameter update amount between the updated model and the model to be trained. This parameter update amount typically refers to the parameter update amount of each neuron in the updated model compared to the model to be trained (hereinafter referred to as the parameter update amount of each neuron in the updated model). It should be noted that the client can compare the parameters of neurons at the same location in both the updated model and the model to be trained, thereby obtaining the parameter update amount of the neuron at that location. In this way, the parameter update amount of each neuron in the updated model can be obtained. Continuing with the example above, since the model to be trained contains 4 layers, the updated model 1 obtained by client 1 also contains 4 layers. Therefore, client 1 can compare the parameters of the first neuron in the first layer of the model to be trained with the parameters of the first neuron in the first layer of the updated model 1 to obtain the parameter update amount of the first neuron in the first layer of the updated model 1. The client can also compare the parameters of the second neuron in the first layer of the model to be trained with the parameters of the second neuron in the first layer of the updated model 1 to obtain the parameter update amount of the second neuron in the first layer of the updated model 1, and so on. The client can obtain the parameter update amount of each neuron in the updated model 1.
[0190] Then, the client can send the parameter update values of each neuron in the updated model to the server. The server can then receive the parameter update values of each neuron in the updated models uploaded by each client, and calculate the average value based on this information. Therefore, the server can update the parameters of each neuron in the locally stored model to be trained based on the average value of the parameter update values of each neuron, thus obtaining the updated model trained by the server itself. Continuing with the example above, after receiving the parameter update values of each neuron in the updated model 1 uploaded by client 1, and the parameter update values of each neuron in the updated model 2 uploaded by client 2, the server can calculate the average value of the parameter update values of the first neuron in the first layer of the updated model 1 and the first neuron in the first layer of the updated model 2, and so on, to obtain the average value of the parameter update values of each neuron. Therefore, the server can update the parameters of each neuron in the locally stored model to be trained based on the average value of the parameter update of each neuron. That is, the average value of the parameter update of the first neuron in the first layer is used to update the parameters of the first neuron in the first layer of the model to be trained, the average value of the parameter update of the second neuron in the first layer is used to update the parameters of the second neuron in the first layer of the model to be trained, and so on, so as to obtain the updated model obtained by the server itself.
[0191] Afterward, the server can use the updated model it trained as the new model to be trained and distribute it to each client for the next iteration of model training (i.e., repeat steps 701 to 704) until the updated model trained by the server in a certain iteration meets the model training requirements (e.g., the target loss converges or the number of iterations is greater than the preset number, etc.). The updated model trained by the server in that iteration can then be used as the trained model (i.e., the neural network model that has been trained).
[0192] It should be understood that this embodiment is only used as an illustrative example to illustrate the calculation of the average parameter update of each neuron in the updated model uploaded by each client. In practical applications, the server can also perform weighted average calculation of the parameter update of each neuron in the updated model uploaded by each client, etc.
[0193] In this embodiment, after a client obtains the model to be trained from the server, the client processes the local training data using the parameters and position codes of multiple neurons in the model to obtain the processing result. Then, the client can update the parameters of these neurons in the model based on the processing result, thereby obtaining the updated model. Specifically, for any one neuron in the model, it has parameters and position codes, and the position codes of this neuron are different from those of the other neurons. Therefore, the position codes of this neuron can constrain its function and distinguish it from the functions of the other neurons. Compared to the neuron distribution in the model under training, if the function of neurons at certain locations in the updated model changes (i.e., the location of neurons with different functions changes), the output of the model with the positional changes will differ from the output of the model without positional changes because the positional encoding of these neurons remains unchanged (since positional encoding is only related to the neuron's location). This leads to instability in the model training process and affects the performance of the trained model. Therefore, when updating the parameters of each neuron in the model under training, the client will try to keep the function of neurons at each location unchanged to ensure that the output of the updated model is as stable as possible. Thus, the positional encoding of neurons effectively curbs the rearrangement invariance of the neural network model. Since other clients can also perform the same operations as this client, neurons with the same function are located in the same position in the updated models uploaded to the server by each client. Therefore, when the server performs aggregation, it can process the neurons in each updated model according to their position, resulting in a trained model with sufficiently good functionality.
[0194] Furthermore, in some related technologies, after receiving the updated models uploaded by various clients, the server can utilize the local data of each client to perform neuron alignment on these models (i.e., swapping the positions of neurons so that neurons with the same function are located in the same position). However, such alignment methods may leak user privacy, involve a series of data security issues, and introduce additional computational overhead. In the solution provided in this application embodiment, during the training process of the model to be trained using their respective local data, the presence of positional encoding of neurons in the model to be trained allows for pre-alignment of neurons (e.g., ...). Figure 10 As shown, Figure 10 (This is another schematic diagram of the federated learning system provided in the embodiments of this application). Therefore, the server does not need to perform the alignment operation of neurons, which can effectively protect user privacy, avoid data security problems, and reduce the computational overhead of the server.
[0195] Figure 11This is another schematic diagram of the model training method provided in the embodiments of this application. This method can also be implemented through methods such as... Figure 8 The federated learning system implementation shown is as follows: Figure 11 As shown, the method includes:
[0196] 1101. The client obtains the model to be trained from the server.
[0197] In one possible implementation, the position encoding of multiple neurons is determined by the server based on the positions of the multiple neurons in the model to be processed, or the position encoding of multiple neurons is determined by the client and the server based on the positions of the multiple neurons in the model to be processed.
[0198] 1102. The client processes the training data through multiple neurons of the model to be trained and obtains the processing results. Each neuron in the multiple neurons has parameters and position codes, and neurons at different positions in the multiple neurons have different position codes.
[0199] In one possible implementation, the model to be trained contains N layers, with the first layer being the input layer and the Nth layer being the output layer. Multiple neurons are all neurons from the second to the (N-1)th layer. The client processes the training data through these neurons to obtain the following processing results: The client performs a first calculation on the parameters of the j-th neuron in the i-th layer and the final outputs of all neurons in the (i-1)-th layer to obtain the initial output of the j-th neuron in the i-th layer, where i = 1, ..., N, j = 1, ..., M, N ≥ 3, M ≥ 1; The client performs a second calculation on the position encoding of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; where the final outputs of all neurons in the first layer are the training data, and the initial outputs of all neurons in the N-th layer are the processing results.
[0200] In one possible implementation, the client performs a second calculation on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer. This calculation includes: the client performing arithmetic operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, the client performing trigonometric function operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, the client performing exponential operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, the client performing logarithmic operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer.
[0201] For details on steps 1101 and 1102, please refer to [link / reference]. Figure 7 The relevant descriptions of steps 701 and 702 in the illustrated embodiment will not be repeated here.
[0202] 1103. The client updates the parameters and location encodings of neurons in the model to be processed based on the processing results, and obtains the updated model.
[0203] After obtaining the processing results of the training data, the client can update the parameters and location encodings of neurons in the model to be processed based on the processing results, and obtain the updated model.
[0204] Specifically, the client can update the parameters and location encodings of neurons in the model to be processed based on the processing results in the following ways to obtain the updated model:
[0205] Since the actual processing results of the training data are known, the client can first calculate the processing results of the training data output by the model to be trained and the actual processing results of the training data using a preset target loss function to obtain the target loss. This target loss is used to indicate the difference between the processing results of the training data output by the model to be trained and the actual processing results of the training data.
[0206] After obtaining the target loss, the client updates the parameters of the neurons in the model to be trained (including the parameters of all neurons from layer 2 to layer N) and the positional codes of the neurons (including the positional codes of all neurons from layer 2 to layer N-1, which are considered as non-fixed values) based on the target loss, and obtains the updated model.
[0207] It is worth noting that this client can often obtain multiple batches of training data in advance, thus enabling multiple rounds of updates to the model to be trained (i.e., executing steps 1102 and 1103 multiple times). Specifically, in the first round of updates, the client can input the first batch of training data into the model to be trained, obtain the processing result of the first batch of training data, and update the model based on this processing result, obtaining the model obtained in the first round. Then, in the second round of updates, the client can input the second batch of training data into the model obtained in the first round, obtain the processing result of the second batch of training data, and update the model based on this processing result, obtaining the model obtained in the second round, and so on, until the final round of updates is completed, at which point the model obtained in the final round is the updated model. However, while all rounds of updates update the parameters of neurons in the model, only some rounds update the positional encoding of neurons in the model. This shows that the update frequency of positional encoding is less than the update frequency of parameters, which can, to some extent, suppress the model's rearrangement invariance.
[0208] For any batch of training data, the client can use that batch of training data to update the model to be trained (i.e., each batch,
[0209] 1104. The client obtains the parameter update amount and the position encoding update amount based on the updated model and the model to be trained.
[0210] 1105. The client sends the parameter update amount and the position code update amount to the server. The parameter update amount and the position code update amount are used by the server to update the model to be trained until the model training conditions are met, and the trained model is obtained.
[0211] After obtaining the updated model, the client can send the updated model to the server. Therefore, the server can perform federated aggregation based on the updated model uploaded by the client and the updated models uploaded by other clients to obtain the trained model.
[0212] Specifically, the client can upload the updated model in the following ways, so that the server can perform federated aggregation based on the updated model:
[0213] After obtaining the updated model, the client can, based on the updated model and the model to be trained, obtain the parameter update amount and position code update amount between the two. The parameter update amount typically refers to the parameter update amount of each neuron in the updated model compared to the model to be trained (hereinafter referred to as the parameter update amount of each neuron in the updated model). The position code update amount typically refers to the position code update amount of each neuron in the updated model compared to the model to be trained (hereinafter referred to as the position code update amount of each neuron in the updated model). It should be noted that the client can compare the parameters of neurons at the same position in both the updated model and the model to be trained to obtain the parameter update amount of the neuron at that position, and compare the position codes of neurons at the same position to obtain the position code update amount of the neuron at that position. In this way, the client can obtain the parameter update amount and position code update amount of each neuron in the updated model. Continuing with the example above, since the model to be trained contains 4 layers, the updated model 1 obtained by client 1 also contains 4 layers. Therefore, client 1 can compare the parameters of the first neuron in the first layer of the model to be trained with the parameters of the first neuron in the first layer of the updated model 1 to obtain the parameter update amount of the first neuron in the first layer of the updated model 1. The client can also compare the parameters of the second neuron in the first layer of the model to be trained with the parameters of the second neuron in the first layer of the updated model 1 to obtain the parameter update amount of the second neuron in the first layer of the updated model 1, and so on. The client can obtain the parameter update amount of each neuron in the updated model 1. Similarly, client 1 can also compare the position code of the first neuron in the first layer of the model to be trained with the position code of the first neuron in the first layer of the updated model 1 to obtain the position code update amount of the first neuron in the first layer of the updated model 1. The client can also compare the position code of the second neuron in the first layer of the model to be trained with the position code of the second neuron in the first layer of the updated model 1 to obtain the position code update amount of the second neuron in the first layer of the updated model 1, and so on, so that the client can obtain the position code update amount of each neuron in the updated model 1.
[0214] Then, the client can send the parameter update and position code update of each neuron in the updated model to the server. In this way, the server can obtain the parameter update and position code update of each neuron in the updated model uploaded by each client, and perform an average calculation based on this information to obtain the average value of the parameter update and the average value of the position code update of each neuron in the updated model. Therefore, the server can update the parameters of each neuron in the locally stored model to be trained based on the average value of the parameter update, and update the position codes of each neuron in the locally stored model to be trained based on the average value of the position code update, thus obtaining the updated model trained by the server itself. Continuing with the example above, after receiving the updated parameter values of each neuron in the updated Model 1 uploaded by client 1, and the updated parameter values of each neuron in the updated Model 2 uploaded by client 2, the server can average the parameter update values of the first neuron in the first layer of the updated Model 1 and the first neuron in the first layer of the updated Model 2 to obtain the average value of the parameter update values of the first neuron in the first layer, and so on, until the server obtains the average value of the parameter update values of each neuron. Similarly, after receiving the updated position encoding values of each neuron in the updated Model 1 uploaded by client 1, and the updated position encoding values of each neuron in the updated Model 2 uploaded by client 2, the server can average the position encoding update values of the first neuron in the first layer of the updated Model 1 and the first neuron in the first layer of the updated Model 2 to obtain the average value of the position encoding update values of the first neuron in the first layer, and so on, until the server obtains the average value of the position encoding update values of each neuron. Therefore, the server can update the parameters of each neuron in the locally stored model to be trained based on the average value of the parameter update of each neuron. That is, the average value of the parameter update of the first neuron in the first layer is used to update the parameters of the first neuron in the first layer of the model to be trained, the average value of the parameter update of the second neuron in the first layer is used to update the parameters of the second neuron in the first layer of the model to be trained, and so on. The server can complete the parameter update of each neuron.Similarly, the server can also update the position codes of each neuron in the locally stored model to be trained based on the average value of the position code update of each neuron. That is, the average value of the position code update of the first neuron in the first layer is used to update the position code of the first neuron in the first layer of the model to be trained, the average value of the position code update of the second neuron in the first layer is used to update the position code of the second neuron in the first layer of the model to be trained, and so on. The server can complete the position code update of each neuron, thereby obtaining the updated model trained by the server itself.
[0215] Afterward, the server can use the updated model it trained as the new model to be trained and distribute it to each client for the next iteration of model training (i.e., repeat steps 1101 to 1104) until the updated model trained by the server in a certain iteration meets the model training requirements (e.g., the target loss converges or the number of iterations is greater than the preset number, etc.). The updated model trained by the server in that iteration can then be used as the trained model (i.e., the neural network model that has been trained).
[0216] It should be understood that this embodiment is only used as an illustrative example to illustrate the calculation of the average parameter update of each neuron in the updated model uploaded by each client. In practical applications, the server can also perform weighted average calculation of the parameter update of each neuron in the updated model uploaded by each client, etc.
[0217] It should also be understood that this embodiment is only used as an illustrative example to illustrate the calculation of the average position code update of each neuron in the updated model uploaded by each client. In practical applications, the server can also perform weighted average calculation of the position code update of each neuron in the updated model uploaded by each client, etc.
[0218] In this embodiment, after a client obtains the model to be trained from the server, the client processes the local training data using the parameters and position codes of multiple neurons in the model to obtain the processing result. Then, the client can update the parameters of these neurons in the model based on the processing result, thereby obtaining the updated model. Specifically, for any one neuron in the model, it has parameters and position codes, and the position codes of this neuron are different from those of the other neurons. Therefore, the position codes of this neuron can constrain its function and distinguish it from the functions of the other neurons. Compared to the neuron distribution in the model under training, if the function of neurons at certain locations in the updated model changes (i.e., the location of neurons with different functions changes), the output of the model with the positional changes will differ from the output of the model without positional changes because the positional encoding of these neurons remains unchanged (since positional encoding is only related to the neuron's location). This leads to instability in the model training process and affects the performance of the trained model. Therefore, when updating the parameters of each neuron in the model under training, the client will try to keep the function of neurons at each location unchanged to ensure that the output of the updated model is as stable as possible. Thus, the positional encoding of neurons effectively curbs the rearrangement invariance of the neural network model. Since other clients can also perform the same operations as this client, neurons with the same function are located in the same position in the updated models uploaded to the server by each client. Therefore, when the server performs aggregation, it can process the neurons in each updated model according to their position, resulting in a trained model with sufficiently good functionality.
[0219] Furthermore, in some related technologies, after receiving the updated models uploaded by various clients, the server can utilize the local data of each client to perform neuron alignment on these models (i.e., swapping the positions of neurons so that neurons with the same function are located in the same position). However, such alignment methods may leak user privacy, involve a series of data security issues, and introduce additional computational overhead. In the solution provided in this application embodiment, during the training process of the model to be trained using their respective local data, the presence of positional encoding of neurons in the model to be trained allows for pre-alignment of neurons (e.g., ...). Figure 5 As shown, Figure 5 (This is another schematic diagram of the federated learning system provided in the embodiments of this application). Therefore, the server does not need to perform the alignment operation of neurons, which can effectively protect user privacy, avoid data security problems, and reduce the computational overhead of the server.
[0220] Furthermore, embodiments of this application can also update the positional encoding of neurons, so that the model can learn appropriate positional encodings according to the nature of the specific task (i.e., in a certain business scenario, the user needs the model to have a certain data processing function), which is beneficial for more reasonable alignment of neurons.
[0221] The above is a detailed description of the model training method provided in the embodiments of this application. The model training apparatus provided in the embodiments of this application will be described below. Figure 12 A schematic diagram of the structure of the client provided in the embodiments of this application is shown below. Figure 12 As shown, the client includes:
[0222] The acquisition module 1201 is used to acquire the model to be trained from the server. The model to be trained contains multiple neurons, each of which has parameters and position codes. Neurons at different positions in the multiple neurons have different position codes.
[0223] The processing module 1202 is used to: process the training data by using the parameters of multiple neurons in the model to be trained and the positional encoding of the parameters of multiple neurons in the model to be trained, and obtain the processing result, wherein neurons at different positions in the multiple neurons have different positional encodings; and update the parameters of multiple neurons in the training model based on the processing result to obtain the updated model.
[0224] The sending module 1203 is used to send the updated model to the server. The updated model is then aggregated on the server to obtain the trained model.
[0225] In this embodiment, after a client obtains the model to be trained from the server, the client processes the local training data using the parameters and position codes of multiple neurons in the model to obtain the processing result. Then, the client can update the parameters of these neurons in the model based on the processing result, thereby obtaining the updated model. Specifically, for any one neuron in the model, it has parameters and position codes, and the position codes of this neuron are different from those of the other neurons. Therefore, the position codes of this neuron can constrain its function and distinguish it from the functions of the other neurons. Compared to the neuron distribution in the model under training, if the function of neurons at certain locations in the updated model changes (i.e., the location of neurons with different functions changes), the output of the model with the positional changes will differ from the output of the model without positional changes because the positional encoding of these neurons remains unchanged (since positional encoding is only related to the neuron's location). This leads to instability in the model training process and affects the performance of the trained model. Therefore, when updating the parameters of each neuron in the model under training, the client will try to keep the function of neurons at each location unchanged to ensure that the output of the updated model is as stable as possible. Thus, the positional encoding of neurons effectively curbs the rearrangement invariance of the neural network model. Since other clients can also perform the same operations as this client, neurons with the same function are located in the same position in the updated models uploaded to the server by each client. Therefore, when the server performs aggregation, it can process the neurons in each updated model according to their position, resulting in a trained model with sufficiently good functionality.
[0226] In one possible implementation, the positional encoding of multiple neurons is determined by the server based on the positions of the multiple neurons in the model to be trained, or the positional encoding of multiple neurons is determined by the client and server based on the positions of the multiple neurons in the model to be trained.
[0227] In one possible implementation, the model to be trained contains N layers, with multiple neurons representing all neurons from layer 2 to layer (N-1). The processing module 1202 is used to: perform a first calculation on the parameters of the j-th neuron in layer i and the final outputs of all neurons in layer (N-1) to obtain the initial output of the j-th neuron in layer i, where i = 2, ..., N-1, j = 1, ..., M, N ≥ 3, M ≥ 1; and perform a second calculation on the position encoding of the j-th neuron in layer i and the initial output of the j-th neuron in layer i to obtain the final output of the j-th neuron in layer i. The final output of the j-th neuron in layer i is used to generate the processing result, i.e., the final outputs of all neurons in layer (N-1) are used to generate the processing result.
[0228] In one possible implementation, in the model to be trained, the first layer is the input layer, the Nth layer is the output layer, the final output of all neurons in the first layer is the training data, the parameters of the j-th neuron in the Nth layer are used to perform the first calculation on the final output of all neurons in the (N-1)th layer to obtain the final output of the j-th neuron in the Nth layer, and the final output of all neurons in the Nth layer is the processing result.
[0229] In one possible implementation, the processing module 1202 is configured to: perform arithmetic operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, perform trigonometric function operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, perform exponential operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, perform logarithmic operations on the position code of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer.
[0230] In one possible implementation, the processing module 1202 is configured to: obtain a target loss based on the processing result and the actual processing result of the training data, the target loss being used to indicate the difference between the processing result and the actual processing result; and update the parameters and position codes based on the target loss to obtain an updated model, wherein the update frequency of the position codes is less than the update frequency of the parameters.
[0231] In one possible implementation, the sending module 1203 is used to: obtain the parameter update amount and the position code update amount based on the updated model and the model to be trained; send the parameter update amount and the position code update amount to the server, and use the parameter update amount and the position code update amount to update the model to be trained on the server until the model training conditions are met, so as to obtain the trained model.
[0232] In one possible implementation, the processing module 1202 is used to: obtain a target loss based on the processing result and the true processing result of the training data, the target loss being used to indicate the difference between the processing result and the true processing result; and update the parameters based on the target loss to obtain an updated model.
[0233] In one possible implementation, the sending module 1203 is used to: obtain the parameter update amount based on the updated model and the model to be trained; send the parameter update amount to the server, and the parameter update amount is used by the server to update the model to be trained until the model training conditions are met, so as to obtain the trained model.
[0234] Figure 13A schematic diagram of the server structure provided in the embodiments of this application is shown below. Figure 13 As shown, the server includes:
[0235] The sending module 1301 is used to send the model to be trained to the client. The model to be trained contains multiple neurons. Each neuron in the multiple neurons has parameters and position codes. Neurons at different positions in the multiple neurons have different position codes. The parameters and position codes are used by the client to process the training data to obtain the processing results, and update the parameters based on the processing results to obtain the updated model.
[0236] Module 1302 is used to obtain the updated model from the client;
[0237] The aggregation module 1303 is used to aggregate the updated model to obtain the trained model.
[0238] In this embodiment, after a client obtains the model to be trained from the server, the client processes the local training data using the parameters and position codes of multiple neurons in the model to obtain the processing result. Then, the client can update the parameters of these neurons in the model based on the processing result, thereby obtaining the updated model. Specifically, for any one neuron in the model, it has parameters and position codes, and the position codes of this neuron are different from those of the other neurons. Therefore, the position codes of this neuron can constrain its function and distinguish it from the functions of the other neurons. Compared to the neuron distribution in the model under training, if the function of neurons at certain locations in the updated model changes (i.e., the location of neurons with different functions changes), the output of the model with the positional changes will differ from the output of the model without positional changes because the positional encoding of these neurons remains unchanged (since positional encoding is only related to the neuron's location). This leads to instability in the model training process and affects the performance of the trained model. Therefore, when updating the parameters of each neuron in the model under training, the client will try to keep the function of neurons at each location unchanged to ensure that the output of the updated model is as stable as possible. Thus, the positional encoding of neurons effectively curbs the rearrangement invariance of the neural network model. Since other clients can also perform the same operations as this client, neurons with the same function are located in the same position in the updated models uploaded to the server by each client. Therefore, when the server performs aggregation, it can process the neurons in each updated model according to their position, resulting in a trained model with sufficiently good functionality.
[0239] In one possible implementation, the position encoding of multiple neurons is determined by the server based on the positions of the multiple neurons in the model to be processed, or the position encoding of multiple neurons is determined by the client and the server based on the positions of the multiple neurons in the model to be processed.
[0240] In one possible implementation, the acquisition module 1302 is used to acquire the parameter update amount and the position encoding update amount from the client, which are acquired based on the updated model and the model to be trained; the aggregation module 1303 is used to update the model to be trained based on the parameter update amount and the position encoding update amount until the model training conditions are met, and the trained model is obtained.
[0241] In one possible implementation, the acquisition module 1302 is used to acquire the parameter update amount from the client, the parameter update amount is acquired based on the updated model and the model to be trained; the aggregation module 1303 is used to update the model to be trained based on the parameter update amount until the model training conditions are met, and obtain the trained model.
[0242] It should be noted that the information interaction and execution process between the modules / units of the above-mentioned device are based on the same concept as the method embodiment of this application, and the resulting technical effects are the same as those of the method embodiment of this application. For details, please refer to the description in the method embodiment shown above in the embodiment of this application, and it will not be repeated here.
[0243] This application also relates to an execution device. Figure 14 This is a schematic diagram of the execution device provided in an embodiment of this application. Figure 14 As shown, the execution device 1400 can specifically manifest as a mobile phone, tablet, laptop, smart wearable device, server, etc., and is not limited here. Among them, the execution device 1400 may be deployed with... Figure 8 The client shown is used in conjunction with subsequent training equipment to achieve [the desired result]. Figure 4 or Figure 6 This corresponds to the model training function in the embodiment. Specifically, the execution device 1400 includes: a receiver 1401, a transmitter 1402, a processor 1403, and a memory 1404 (wherein the execution device 1400 may have one or more processors 1403). Figure 14 (Taking a processor as an example), processor 1403 may include application processor 14031 and communication processor 14032. In some embodiments of this application, receiver 1401, transmitter 1402, processor 1403 and memory 1404 may be connected via a bus or other means.
[0244] Memory 1404 may include read-only memory and random access memory, and provides instructions and data to processor 1403. A portion of memory 1404 may also include non-volatile random access memory (NVRAM). Memory 1404 stores processor and operation instructions, executable modules, or data structures, or subsets thereof, or extended sets thereof, wherein the operation instructions may include various operation instructions for implementing various operations.
[0245] Processor 1403 controls the operation of the execution device. In specific applications, the various components of the execution device are coupled together through a bus system, which may include not only the data bus, but also power buses, control buses, and status signal buses. However, for clarity, all buses are referred to as the bus system in the diagram.
[0246] The methods disclosed in the embodiments of this application can be applied to or implemented by the processor 1403. The processor 1403 can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of the processor 1403 or by instructions in software form. The processor 1403 can be a general-purpose processor, a digital signal processor (DSP), a microprocessor, or a microcontroller, and may further include an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The processor 1403 can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software module can reside in a mature storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 1404. Processor 1403 reads the information in memory 1404 and, in conjunction with its hardware, completes the steps of the above method.
[0247] Receiver 1401 can be used to receive input digital or character information, and to generate signal inputs related to the settings and function control of the execution device. Transmitter 1402 can be used to output digital or character information through the first interface; transmitter 1402 can also be used to send instructions to the disk group through the first interface to modify the data in the disk group; transmitter 1402 may also include a display device such as a display screen.
[0248] In one embodiment of this application, the processor 1403 can be used to implement... Figure 7 or Figure 11 The model training method in the corresponding embodiment can also be used to train models by... Figure 7 or Figure 11 The trained model obtained in the corresponding embodiment implements the corresponding data processing functions.
[0249] This application also relates to a training device. Figure 15 This is a schematic diagram of the structure of a training device provided in an embodiment of this application. Figure 15 As shown, the training device 1500 is implemented by one or more servers. The training device 1500 can vary significantly due to different configurations or performance. It may include one or more central processing units (CPUs) 1514 (e.g., one or more processors) and memory 1532, and one or more storage media 1530 (e.g., one or more mass storage devices) for storing application programs 1542 or data 1544. The memory 1532 and storage media 1530 can be temporary or persistent storage. The program stored in the storage media 1530 may include one or more modules (not shown in the figure), each module may include a series of instruction operations on the training device. Furthermore, the CPU 1514 may be configured to communicate with the storage media 1530 and execute the series of instruction operations in the storage media 1530 on the training device 1500.
[0250] The training device 1500 may also include one or more power supplies 1526, one or more wired or wireless network interfaces 1550, one or more input / output interfaces 1558; or, one or more operating systems 1541, such as Windows Server™, Mac OS X™, Unix™, Linux™, FreeBSD™, etc.
[0251] Specifically, the training equipment can be combined with the aforementioned execution equipment to perform joint operations. Figure 4 or Figure 6 The model training method in the corresponding embodiment.
[0252] This application also relates to a computer storage medium storing a program for signal processing, which, when run on a computer, causes the computer to perform steps as performed by the aforementioned execution device, or causes the computer to perform steps as performed by the aforementioned training device.
[0253] This application also relates to a computer program product that stores instructions that, when executed by a computer, cause the computer to perform steps as performed by the aforementioned execution device, or to perform steps as performed by the aforementioned training device.
[0254] The execution device, training device, or terminal device provided in this application embodiment can specifically be a chip. 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, pins, or circuits. The processing unit can execute computer execution instructions stored in the storage unit to cause the chip within the execution device to execute the data processing method described in the above embodiments, or to cause the chip within the training device to execute the data processing method described in the above embodiments. Optionally, the storage unit can be a storage unit within the chip, such as a register or cache. Alternatively, the storage unit can be a storage unit located outside the chip within the wireless access device, such as a read-only memory (ROM) or other types of static storage devices capable of storing static information and instructions, such as random access memory (RAM).
[0255] For details, please refer to Figure 16 , Figure 16 This is a schematic diagram of the chip provided in an embodiment of this application. The chip can be represented as a neural network processor (NPU) 1600. The NPU 1600 is mounted as a coprocessor on the host CPU, and tasks are assigned by the host CPU. The core part of the NPU is the arithmetic circuit 1603, which is controlled by the controller 1604 to retrieve matrix data from the memory and perform multiplication operations.
[0256] In some implementations, the arithmetic circuit 1603 internally includes multiple processing engines (PEs). In some implementations, the arithmetic circuit 1603 is a two-dimensional pulsating array. The arithmetic circuit 1603 can also be a one-dimensional pulsating array or other electronic circuits capable of performing mathematical operations such as multiplication and addition. In some implementations, the arithmetic circuit 1603 is a general-purpose matrix processor.
[0257] For example, suppose we have an input matrix A, a weight matrix B, and an output matrix C. The arithmetic circuit retrieves the corresponding data of matrix B from the weight memory 1602 and caches it in each PE of the arithmetic circuit. The arithmetic circuit retrieves the data of matrix A from the input memory 1601 and performs matrix operations with matrix B. The partial result or the final result of the obtained matrix is stored in the accumulator 1608.
[0258] Unified memory 1606 is used to store input and output data. Weight data is directly transferred to weight memory 1602 via Direct Memory Access Controller (DMAC) 1605. Input data is also transferred to unified memory 1606 via DMAC.
[0259] BIU stands for Bus Interface Unit, which is used for interaction between the AXI bus and the DMAC and the Instruction Fetch Buffer (IFB) 1609.
[0260] The Bus Interface Unit (BIU) 1613 is used by the instruction fetch memory 1609 to fetch instructions from external memory, and also by the memory access controller 1605 to fetch the original data of the input matrix A or the weight matrix B from external memory.
[0261] The DMAC is mainly used to move input data from external memory DDR to unified memory 1606, or to weight data to weight memory 1602, or to input data to input memory 1601.
[0262] The vector computation unit 1607 includes multiple processing units that further process the output of the computation circuit 1603 when necessary, such as vector multiplication, vector addition, exponential operations, logarithmic operations, size comparisons, etc. It is mainly used for computation in non-convolutional / fully connected layers of neural networks, such as Batch Normalization, pixel-level summation, and upsampling of the predicted label plane.
[0263] In some implementations, the vector computation unit 1607 can store the processed output vector in the unified memory 1606. For example, the vector computation unit 1607 can apply a linear function, or a nonlinear function, to the output of the computation circuit 1603, such as linearly interpolating the predicted label plane extracted by the convolutional layer, or, for example, accumulating a vector of values to generate activation values. In some implementations, the vector computation unit 1607 generates normalized values, pixel-level summed values, or both. In some implementations, the processed output vector can be used as activation input to the computation circuit 1603, for example, for use in subsequent layers in the neural network.
[0264] The instruction fetch buffer 1609 connected to the controller 1604 is used to store the instructions used by the controller 1604;
[0265] The unified memory 1606, input memory 1601, weight memory 1602, and instruction fetch memory 1609 are all on-chip memories. External memory is proprietary to this NPU hardware architecture.
[0266] The processor mentioned above can be a general-purpose central processing unit, a microprocessor, an ASIC, or one or more integrated circuits used to control the execution of the above program.
[0267] It should also be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. In addition, in the device embodiment drawings provided in this application, the connection relationship between modules indicates that they have a communication connection, which can be implemented as one or more communication buses or signal lines.
[0268] Through the above description of the embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus necessary general-purpose hardware, or it can be implemented by special-purpose hardware including application-specific integrated circuits, special-purpose CPUs, special-purpose memory, special-purpose components, etc. Generally, any function performed by a computer program can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can be diverse, such as analog circuits, digital circuits, or special-purpose circuits. However, for this application, software program implementation is more often the preferred implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a readable storage medium, such as a computer floppy disk, USB flash drive, mobile hard disk, ROM, RAM, magnetic disk, or optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, training equipment, or network device, etc.) to execute the methods described in the various embodiments of this application.
[0269] In the above embodiments, the implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, in the form of a computer program product.
[0270] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, training device, or data center to another website, computer, training device, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., DVDs), or semiconductor media (e.g., solid-state drives (SSDs)).
Claims
1. A model training method, characterized in that, The method is applied to a client, and the method includes: Obtain the training model from the server. The training model contains multiple neurons, wherein each neuron is associated with parameter information and position encoding information, and each neuron corresponds one-to-one with the position encoding information. The training model contains N layers, and the multiple neurons are all neurons from layer 2 to layer N-1. The model to be trained is updated using the parameter information, the location encoding information, and the training data to obtain the updated model, including: The parameter information of the j-th neuron in the i-th layer and the final output of all neurons in the (i-1)-th layer are used for the first calculation to obtain the initial output of the j-th neuron in the i-th layer, i=2,...,N-1, j=1,...,M, N≥3, M≥1; The position encoding information of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer are used to perform a second calculation to obtain the final output of the j-th neuron in the i-th layer. The final output of the j-th neuron in the i-th layer is used to generate the processing result. The parameter information is updated based on the processing results to obtain the updated model; The training data includes at least one of the following: image data, audio data, and text data; The updated model is sent to the server so that the server can perform federated aggregation based on the updated model and the updated models sent by other clients to obtain the trained model.
2. The method according to claim 1, characterized in that, The positional encoding information of the multiple neurons is determined based on their positions in the model to be trained.
3. The method according to claim 1, characterized in that, In the model to be trained, the first layer is the input layer, the Nth layer is the output layer, the final output of all neurons in the first layer is the training data, the parameter information of the j-th neuron in the Nth layer is used to perform the first calculation on the final output of all neurons in the (N-1)th layer to obtain the final output of the j-th neuron in the Nth layer, and the final output of all neurons in the Nth layer is the processing result.
4. The method according to claim 1 or 3, characterized in that, The positional encoding information of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer are used for a second calculation to obtain the final output of the j-th neuron in the i-th layer, which includes: Perform arithmetic operations on the position encoding information of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer; or, The final output of the j-th neuron in the i-th layer is obtained by performing trigonometric function operations on the position encoding information of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer; or, The final output of the j-th neuron in the i-th layer is obtained by performing an exponential operation on the position encoding information of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer; or, The final output of the j-th neuron in the i-th layer is obtained by performing a logarithmic operation on the position encoding information of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer.
5. The method according to any one of claims 1 to 3, characterized in that, The parameter information is updated based on the processing result to obtain the updated model, which includes: Based on the processing result and the actual processing result of the training data, a target loss is obtained, which is used to indicate the difference between the processing result and the actual processing result. The parameter information and the location encoding information are updated based on the target loss to obtain the updated model. The update frequency of the location encoding information is less than the update frequency of the parameter information.
6. The method according to claim 5, characterized in that, The updated model sent includes: Based on the updated model and the model to be trained, obtain the parameter information update amount and the position encoding information update amount; Send the parameter information update amount and the location encoding information update amount.
7. The method according to any one of claims 1 to 3, characterized in that, The parameter information is updated based on the processing result to obtain the updated model, which includes: Based on the processing result and the actual processing result of the training data, a target loss is obtained, which is used to indicate the difference between the processing result and the actual processing result. The parameter information is updated based on the target loss to obtain the updated model.
8. The method according to claim 7, characterized in that, Sending the updated model includes: Based on the updated model and the model to be trained, obtain the parameter information update amount; Send the parameter information update amount.
9. A model training method, characterized in that, The method includes: Send a model to be trained, the model to be trained contains multiple neurons, wherein each neuron is associated with parameter information and position encoding information, each neuron corresponds one-to-one with the position encoding information, the model to be trained contains N layers, and the multiple neurons are all neurons from layer 2 to layer N-1; The updated model is obtained and aggregated to obtain the trained model. The updated model is obtained by updating the model to be trained based on the parameter information, the position encoding information and the training data. The updated model is obtained by updating the model to be trained based on the parameter information, the position encoding information, and the training data. Specifically, it includes: performing a first calculation on the parameter information of the j-th neuron in the i-th layer and the final outputs of all neurons in the (i-1)-th layer to obtain the initial output of the j-th neuron in the i-th layer, where i=2,...,N-1, j=1,...,M, N≥3, M≥1; performing a second calculation on the position encoding information of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer, which is used to generate the processing result; and updating the parameter information based on the processing result to obtain the updated model. The training data includes at least one of the following: image data, speech data, and text data.
10. The method according to claim 9, characterized in that, The positional encoding information of the multiple neurons is determined based on their positions in the model to be trained.
11. The method according to claim 9 or 10, characterized in that, The process of obtaining the updated model and aggregating the updated model to obtain the trained model includes: The parameter information update amount and the position encoding information update amount are obtained based on the updated model and the model to be trained; Based on the update amount of the parameter information and the update amount of the position encoding information, the model to be trained is updated until the model training conditions are met, and the trained model is obtained.
12. The method according to claim 9 or 10, characterized in that, The process of obtaining the updated model and aggregating the updated model to obtain the trained model includes: The parameter information update amount is obtained based on the updated model and the model to be trained. Based on the parameter information update amount, the model to be trained is updated until the model training conditions are met, and the trained model is obtained.
13. A model training device, characterized in that, The device is used on a client side, and the device includes: The acquisition module is used to acquire the model to be trained from the server. The model to be trained contains multiple neurons, wherein the neurons are associated with parameter information and position encoding information, and the neurons correspond one-to-one with the position encoding information. The model to be trained contains N layers, and the multiple neurons are all neurons from the 2nd layer to the (N-1)th layer. The processing module is used to update the model to be trained using the parameter information, the location encoding information, and the training data to obtain the updated model. The training data includes at least one of the following: image data, speech data, and text data. The processing module is specifically used for: performing a first calculation on the parameter information of the j-th neuron in the i-th layer and the final outputs of all neurons in the (i-1)-th layer to obtain the initial output of the j-th neuron in the i-th layer, where i=2,...,N-1, j=1,...,M, N≥3, M≥1; performing a second calculation on the position encoding information of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer, the final output of the j-th neuron in the i-th layer being used to generate the processing result; and updating the parameter information based on the processing result to obtain the updated model. The sending module is used to send the updated model to the server, so that the server can perform federated aggregation based on the updated model and the updated models sent by other clients to obtain the trained model.
14. A model training device, characterized in that, The device includes: The sending module is used to send the model to be trained, which contains multiple neurons, wherein the neurons are associated with parameter information and position encoding information, and the neurons correspond one-to-one with the position encoding information; An acquisition module is used to acquire an updated model, which is obtained by updating the model to be trained based on the parameter information, the location encoding information and the training data. The training data includes at least one of the following: image data, speech data, and text data. The updated model is obtained by updating the model to be trained based on the parameter information, the position encoding information, and the training data. Specifically, it includes: performing a first calculation on the parameter information of the j-th neuron in the i-th layer and the final outputs of all neurons in the (i-1)-th layer to obtain the initial output of the j-th neuron in the i-th layer, where i=2,...,N-1, j=1,...,M, N≥3, M≥1; performing a second calculation on the position encoding information of the j-th neuron in the i-th layer and the initial output of the j-th neuron in the i-th layer to obtain the final output of the j-th neuron in the i-th layer, which is used to generate the processing result; and updating the parameter information based on the processing result to obtain the updated model. The aggregation module is used to aggregate the updated model to obtain the trained model.
15. A model training device, characterized in that, The model training device includes a memory and a processor; The memory stores code, and the processor is configured to execute the code. When the code is executed, the model training apparatus performs the method as described in any one of claims 1 to 12.
16. A computer storage medium, characterized in that, The computer storage medium stores a computer program that, when executed by a computer, causes the computer to perform the method described in any one of claims 1 to 12.
17. A computer program product, characterized in that, The computer program product stores instructions that, when executed by a computer, cause the computer to perform the method according to any one of claims 1 to 12.