Model training method and device, electronic equipment and storage medium
By segmenting and distributing the initial neural network model, the network load and communication overhead problems caused by the equipment training of the complete model in the existing federated learning method are solved, and more efficient model training is achieved.
Patent Information
- Application Number
- CN202311055634.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-18
- Publication Date
- 2025-02-21
AI Technical Summary
The existing federated learning methods have limited network load and high communication overhead because each device needs to train a complete model.
By segmenting the initial neural network model, multiple model fragments are obtained and these fragments are distributed to multiple terminal devices. Each device trains the received model fragments based on the local data set, reducing the device's initial training Overhead in neural network model.
There is no need to train the entire model, which reduces the training overhead of the terminal device and improves the efficiency of model training.
Smart Images

Figure CN119497098A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of neural network technology, and in particular to a model training method, device, electronic equipment and storage medium. Background Art
[0002] Thanks to the rapid development of cellular networks, for the purpose of protecting information and privacy security, Federated Learning (FL) provides a safe and efficient way to carry out artificial intelligence on distributed terminals, and has been applied to a wide range of scenarios. However, most existing federated learning methods are committed to using many devices, each device synchronously trains a complete model locally, and updates the global model through gradient averaging and model distribution. Since each device needs to train a complete model, the model size that the network can carry will be very limited, and since the gradient of the complete model needs to be uploaded, the overhead of a single synchronous communication is large. Summary of the invention
[0003] The purpose of the present invention is to provide a model training method, device, electronic device and storage medium to solve the technical problems in the prior art.
[0004] In a first aspect, an embodiment of the present application provides a model training method, which is applied to a base station, and the method includes:
[0005] The initial neural network model is segmented to obtain multiple model fragments;
[0006] Distributing the multiple model fragments to at least two terminal devices, so that each of the terminal devices trains the received model fragments according to the local data set of the terminal device;
[0007] For each terminal device: receiving a training completion signal uploaded by the terminal device; determining a next terminal device corresponding to the terminal device based on the training completion signal; sending device information of the next terminal device to the terminal device, so that the terminal device sends the trained model parameters to the next terminal device;
[0008] The model parameters of the terminal device that last sends a training completion signal are obtained, and the model parameters of the initial neural network model are updated using the model parameters of the terminal device that last sends a training completion signal to obtain a trained neural network model.
[0009] In an embodiment of the present application, by distributing model fragments to multiple terminal devices, each terminal device is required to train the received model fragments without training the entire model, thereby reducing the overhead of the terminal device in training the initial neural network model and improving the efficiency of training the initial neural network model.
[0010] In some possible embodiments, distributing the plurality of model fragments to at least two terminal devices includes:
[0011] Distribute an initial segment and an ending segment of the multiple model segments to each terminal device; the initial segment is a model segment that is the first one in the order of the multiple model segments in the initial neural network model, and the ending segment is a model segment that is the last one in the order of the multiple model segments in the initial neural network model;
[0012] Determine the number of terminal devices connected to the communication;
[0013] Distributing the intermediate segments among the multiple model segments to the at least two terminal devices based on the number of the terminal devices; the intermediate segments are model segments among the multiple model segments excluding the initial segment and the end segment.
[0014] In some possible embodiments, distributing the intermediate segments of the plurality of model segments to the at least two terminal devices based on the number of the terminal devices includes:
[0015] If it is determined that the number of the terminal devices is equal to the number of the intermediate segments, the intermediate segments are distributed to the terminal devices, wherein each of the terminal devices receives an intermediate segment, and the intermediate segments received by each of the terminal devices are different;
[0016] If it is determined that the number of the terminal devices is greater than the number of the intermediate fragments, terminal devices with the number of the intermediate fragments are selected from the terminal devices as target terminal devices, and the intermediate fragments are distributed to the target terminal devices, wherein each of the target terminal devices receives an intermediate fragment, and the intermediate fragments received by each of the target terminal devices are different;
[0017] If it is determined that the number of the terminal devices is less than the number of the intermediate segments, the intermediate segments are distributed to the terminal devices, wherein each terminal device receives at least one intermediate segment.
[0018] In some possible embodiments, if it is determined that the number of the terminal devices is equal to the number of the intermediate segments, distributing the intermediate segments to the terminal devices includes:
[0019] Obtaining a training difficulty parameter of each of the intermediate segments; and obtaining a computing power and a data transmission rate of each of the terminal devices;
[0020] Based on the acquired computing power and data transmission rate of each of the terminal devices, obtaining the fragment processing capability corresponding to each of the terminal devices;
[0021] The intermediate segments are distributed to the terminal devices based on the segment processing capability corresponding to each of the terminal devices and the training difficulty parameter corresponding to each of the intermediate segments.
[0022] In some possible embodiments, distributing the intermediate segments to the terminal devices based on the segment processing capability corresponding to each of the terminal devices and the training difficulty parameter corresponding to each of the intermediate segments includes:
[0023] Sorting the training difficulty parameters corresponding to each of the intermediate segments according to a first rule to obtain an intermediate segment difficulty sequence;
[0024] Sorting the fragment processing capabilities corresponding to each of the terminal devices according to the first rule to obtain a processing capability sequence;
[0025] For each intermediate segment in the intermediate segment difficulty sequence, the intermediate segment is distributed to an intermediate terminal device; the intermediate terminal device is a terminal device that has the same position in the processing capability sequence as the intermediate segment in the intermediate segment sequence.
[0026] In some possible embodiments, the selecting the terminal devices of the number of the intermediate segments from the terminal devices as target terminal devices includes:
[0027] Obtaining the computing power and data transmission rate of each of the terminal devices;
[0028] Based on the acquired computing power and data transmission rate of each of the terminal devices, obtaining the fragment processing capability corresponding to each of the terminal devices;
[0029] According to the fragment processing capability, terminal devices with the number of the intermediate fragments are selected in descending order as target terminal devices.
[0030] In some possible embodiments, distributing the intermediate fragment to the target terminal device includes:
[0031] Obtaining a training difficulty parameter for each of the intermediate segments;
[0032] Sorting the training difficulty parameters corresponding to each of the intermediate segments according to a first rule to obtain an intermediate segment difficulty sequence;
[0033] Sorting the fragment processing capabilities corresponding to each of the target terminal devices according to the first rule to obtain a processing capability sequence;
[0034] For each intermediate segment in the intermediate segment difficulty sequence, the intermediate segment is distributed to an intermediate target terminal device; the intermediate target terminal device is a target terminal device that has the same position in the processing capability sequence as the intermediate segment in the intermediate segment sequence.
[0035] In some possible embodiments, if it is determined that the number of the terminal devices is less than the number of the intermediate fragments, distributing the intermediate fragments to the terminal devices includes:
[0036] Obtaining a training difficulty parameter of each of the intermediate segments; and obtaining a computing power and a data transmission rate of each of the terminal devices;
[0037] Based on the acquired computing power and data transmission rate of each of the terminal devices, obtaining the fragment processing capability corresponding to each of the terminal devices;
[0038] The intermediate segments are distributed to the terminal devices based on the segment processing capability corresponding to each of the terminal devices and the training difficulty parameter corresponding to each of the intermediate segments.
[0039] In some possible embodiments, distributing the intermediate segments to the terminal devices based on the segment processing capability corresponding to each of the terminal devices and the training difficulty parameter corresponding to each of the intermediate segments includes:
[0040] Sorting the training difficulty parameters corresponding to each of the intermediate segments according to a first rule to obtain an intermediate segment difficulty sequence;
[0041] Sorting the fragment processing capabilities corresponding to each of the terminal devices according to the first rule to obtain a processing capability sequence;
[0042] According to the number of the terminal devices, sequentially selecting target intermediate segments of the number of the terminal devices from the intermediate segment difficulty sequence;
[0043] Sorting the training difficulty parameters corresponding to each target intermediate segment according to the first rule to obtain a target intermediate segment difficulty sequence;
[0044] For each target intermediate segment in the target intermediate segment difficulty sequence, distributing the target intermediate segment to an intermediate terminal device;
[0045] Sorting the training difficulty parameters corresponding to each remaining intermediate segment according to the first rule to obtain a remaining intermediate segment difficulty sequence; wherein the remaining intermediate segments are intermediate segments in the intermediate segment difficulty sequence except the target intermediate segment;
[0046] For each remaining intermediate segment in the remaining intermediate segment difficulty sequence, the remaining intermediate segment is distributed to an intermediate terminal device; the intermediate terminal device is a terminal device that has the same position in the processing capability sequence as the target intermediate segment in the target intermediate segment sequence.
[0047] In some possible embodiments, the segmentation process of the initial neural network model to obtain multiple model segments includes:
[0048] Obtaining model parameters of the initial neural network model;
[0049] Determine the number of model layers of the initial neural network model according to the model parameters of the initial neural network model;
[0050] The neural network model is segmented based on the number of model layers of the initial neural network model to obtain a plurality of model fragments and a fragment serial number corresponding to each model fragment; the fragment serial number corresponding to each model fragment represents the order of the model fragment in the initial neural network model.
[0051] In some possible embodiments, determining the next terminal device corresponding to the terminal device based on the training end signal includes:
[0052] Determine a target segment sequence number of the model segment processed by the terminal device; the target segment sequence number represents the order of the target segment in the initial neural network model;
[0053] Determine the next segment sequence number corresponding to the target segment sequence number;
[0054] The terminal device that processes the model segment corresponding to the next segment sequence number is used as the next terminal device.
[0055] In some possible embodiments, before segmenting the initial neural network model to obtain multiple model segments, the method further includes:
[0056] Receive the label types and quantities of the local data set reported by each terminal device;
[0057] Determine the Dirichlet distribution parameters corresponding to the initial neural network model according to the type and quantity of labels;
[0058] If the Dirichlet distribution parameter is greater than a preset value, determining that the loss function used by each of the terminal devices when training the model fragment is a first loss function; the first loss function is used to determine whether the training of the model fragment converges;
[0059] If the Dirichlet distribution parameter is not greater than a preset value, the loss function used by each of the terminal devices when training the model fragment is determined to be a second loss function; the second loss function is used to determine whether the training of the model fragment has converged.
[0060] In some possible embodiments, determining the Dirichlet distribution parameters corresponding to the initial neural network model according to the type and quantity of labels includes:
[0061] Determine the Dirichlet distribution parameter corresponding to each terminal device according to the type and quantity corresponding to each terminal device;
[0062] According to the Dirichlet distribution parameters corresponding to each device, the Dirichlet distribution parameters corresponding to the initial neural network model are obtained.
[0063] In a second aspect, an embodiment of the present application provides a model training method, which is applied to a terminal device, and the method includes:
[0064] Receive model fragments sent by a base station; the model fragments include: an initial fragment, an intermediate fragment and an ending fragment; the initial fragment is the model fragment that is the first in the order of the multiple model fragments determined by the base station in the initial neural network model, and the ending fragment is the model fragment that is the last in the order of the multiple model fragments determined by the base station in the initial neural network model; the intermediate fragments are model fragments sent by the base station except the initial fragment and the ending fragment;
[0065] Training the intermediate segment according to the local data set to obtain trained model parameters;
[0066] Sending a training end signal to the base station;
[0067] Receiving device information of a next terminal device sent by the base station;
[0068] The trained model parameters are sent to the next terminal device according to the device information of the next terminal device.
[0069] In some possible embodiments, the training of the intermediate segment according to the local data set to obtain trained model parameters includes:
[0070] Based on the local data set, the intermediate segment is trained in an iterative manner until the loss value corresponding to the intermediate segment is less than a preset loss value;
[0071] The model parameters of the intermediate segment at the end of the iteration are used as the model parameters of the training completed.
[0072] In some possible embodiments, the intermediate segments are trained according to the local data set, and each round of iteration process is as follows:
[0073] Inputting the local data set into the intermediate segment based on the initial segment to obtain a parameter value output by the end segment;
[0074] Determine a loss value corresponding to the intermediate segment based on the parameter value, the local data set, and the loss function;
[0075] Adjusting the model parameters of the intermediate segment according to the loss value;
[0076] Determine a gradient value corresponding to the middle segment, and clip the gradient value based on a preset gradient range to obtain a clipped gradient;
[0077] The clipped gradient is used to update the gradient value of the intermediate segment.
[0078] In some possible embodiments, the method further includes:
[0079] The types and quantities of labels of the local data set are sent to the base station so that the base station obtains the loss function of the neural network model according to the types and quantities of labels, and the loss function is used to determine whether the training of the intermediate segments converges.
[0080] In a third aspect, an embodiment of the present application provides a model training device, which is applied to a base station, and the device includes:
[0081] A segmentation module is used to segment the initial neural network model to obtain multiple model fragments;
[0082] A distribution module, used for distributing the plurality of model fragments to at least two terminal devices, so that each of the terminal devices trains the received model fragments according to the local data set of the terminal device;
[0083] A communication module is used for: for each terminal device: receiving a training completion signal uploaded by the terminal device; determining a next terminal device corresponding to the terminal device based on the training completion signal; and sending device information of the next terminal device to the terminal device, so that the terminal device sends the trained model parameters to the next terminal device;
[0084] The updating module is used to obtain the model parameters of the terminal device that last sends the training completion signal, and use the model parameters of the terminal device that last sends the training completion signal to update the model parameters of the initial neural network model to obtain a trained neural network model.
[0085] In some possible embodiments, the distribution module is specifically used to:
[0086] Distribute an initial segment and an ending segment of the multiple model segments to each terminal device; the initial segment is a model segment that is the first one in the order of the multiple model segments in the initial neural network model, and the ending segment is a model segment that is the last one in the order of the multiple model segments in the initial neural network model;
[0087] Determine the number of terminal devices connected to the communication;
[0088] Distributing the intermediate segments among the multiple model segments to the at least two terminal devices based on the number of the terminal devices; the intermediate segments are model segments among the multiple model segments excluding the initial segment and the end segment.
[0089] In some possible embodiments, the distribution module is specifically used to:
[0090] If it is determined that the number of the terminal devices is equal to the number of the intermediate segments, the intermediate segments are distributed to the terminal devices, wherein each of the terminal devices receives an intermediate segment, and the intermediate segments received by each of the terminal devices are different;
[0091] If it is determined that the number of the terminal devices is greater than the number of the intermediate fragments, terminal devices with the number of the intermediate fragments are selected from the terminal devices as target terminal devices, and the intermediate fragments are distributed to the target terminal devices, wherein each of the target terminal devices receives an intermediate fragment, and the intermediate fragments received by each of the target terminal devices are different;
[0092] If it is determined that the number of the terminal devices is less than the number of the intermediate segments, the intermediate segments are distributed to the terminal devices, wherein each terminal device receives at least one intermediate segment.
[0093] In some possible embodiments, the distribution module is specifically used to:
[0094] Obtaining a training difficulty parameter of each of the intermediate segments; and obtaining a computing power and a data transmission rate of each of the terminal devices;
[0095] Based on the acquired computing power and data transmission rate of each of the terminal devices, obtaining the fragment processing capability corresponding to each of the terminal devices;
[0096] The intermediate segments are distributed to the terminal devices based on the segment processing capability corresponding to each of the terminal devices and the training difficulty parameter corresponding to each of the intermediate segments.
[0097] In some possible embodiments, the distribution module is specifically used to:
[0098] Sorting the training difficulty parameters corresponding to each of the intermediate segments according to a first rule to obtain an intermediate segment difficulty sequence;
[0099] Sorting the fragment processing capabilities corresponding to each of the terminal devices according to the first rule to obtain a processing capability sequence;
[0100] For each intermediate segment in the intermediate segment difficulty sequence, the intermediate segment is distributed to an intermediate terminal device; the intermediate terminal device is a terminal device that has the same position in the processing capability sequence as the intermediate segment in the intermediate segment sequence.
[0101] In some possible embodiments, the distribution module is specifically used to:
[0102] Obtaining the computing power and data transmission rate of each of the terminal devices;
[0103] Based on the acquired computing power and data transmission rate of each of the terminal devices, obtaining the fragment processing capability corresponding to each of the terminal devices;
[0104] According to the fragment processing capability, terminal devices with the number of the intermediate fragments are selected in descending order as target terminal devices.
[0105] In some possible embodiments, the distribution module is specifically used to:
[0106] Obtaining a training difficulty parameter for each of the intermediate segments;
[0107] Sorting the training difficulty parameters corresponding to each of the intermediate segments according to a first rule to obtain an intermediate segment difficulty sequence;
[0108] Sorting the fragment processing capabilities corresponding to each of the target terminal devices according to the first rule to obtain a processing capability sequence;
[0109] For each intermediate segment in the intermediate segment difficulty sequence, the intermediate segment is distributed to an intermediate target terminal device; the intermediate target terminal device is a target terminal device that has the same position in the processing capability sequence as the intermediate segment in the intermediate segment sequence.
[0110] In some possible embodiments, the distribution module is specifically used to:
[0111] Obtaining a training difficulty parameter of each of the intermediate segments; and obtaining a computing power and a data transmission rate of each of the terminal devices;
[0112] Based on the acquired computing power and data transmission rate of each of the terminal devices, obtaining the fragment processing capability corresponding to each of the terminal devices;
[0113] The intermediate segments are distributed to the terminal devices based on the segment processing capability corresponding to each of the terminal devices and the training difficulty parameter corresponding to each of the intermediate segments.
[0114] In some possible embodiments, the distribution module is specifically used to:
[0115] Sorting the training difficulty parameters corresponding to each of the intermediate segments according to a first rule to obtain an intermediate segment difficulty sequence;
[0116] Sorting the fragment processing capabilities corresponding to each of the terminal devices according to the first rule to obtain a processing capability sequence;
[0117] According to the number of the terminal devices, sequentially selecting target intermediate segments of the number of the terminal devices from the intermediate segment difficulty sequence;
[0118] Sorting the training difficulty parameters corresponding to each target intermediate segment according to the first rule to obtain a target intermediate segment difficulty sequence;
[0119] For each target intermediate segment in the target intermediate segment difficulty sequence, distributing the target intermediate segment to an intermediate terminal device;
[0120] Sorting the training difficulty parameters corresponding to each remaining intermediate segment according to the first rule to obtain a remaining intermediate segment difficulty sequence; wherein the remaining intermediate segments are intermediate segments in the intermediate segment difficulty sequence except the target intermediate segment;
[0121] For each remaining intermediate segment in the remaining intermediate segment difficulty sequence, the remaining intermediate segment is distributed to an intermediate terminal device; the intermediate terminal device is a terminal device that has the same position in the processing capability sequence as the target intermediate segment in the target intermediate segment sequence.
[0122] In some possible embodiments, the segmentation module is specifically used to:
[0123] Obtaining model parameters of the initial neural network model;
[0124] Determine the number of model layers of the initial neural network model according to the model parameters of the initial neural network model;
[0125] The neural network model is segmented based on the number of model layers of the initial neural network model to obtain a plurality of model fragments and a fragment serial number corresponding to each model fragment; the fragment serial number corresponding to each model fragment represents the order of the model fragment in the initial neural network model.
[0126] In some possible embodiments, the update module is specifically used to:
[0127] Determine a target segment sequence number of the model segment processed by the terminal device; the target segment sequence number represents the order of the target segment in the initial neural network model;
[0128] Determine the next segment sequence number corresponding to the target segment sequence number;
[0129] The terminal device that processes the model segment corresponding to the next segment sequence number is used as the next terminal device.
[0130] In some possible embodiments, the segmentation module is further used for:
[0131] Receive the label types and quantities of the local data set reported by each terminal device;
[0132] Determine the Dirichlet distribution parameters corresponding to the initial neural network model according to the type and quantity of labels;
[0133] If the Dirichlet distribution parameter is greater than a preset value, determining that the loss function used by each of the terminal devices when training the model fragment is a first loss function; the first loss function is used to determine whether the training of the model fragment converges;
[0134] If the Dirichlet distribution parameter is not greater than a preset value, the loss function used by each of the terminal devices when training the model fragment is determined to be a second loss function; the second loss function is used to determine whether the training of the model fragment has converged.
[0135] In some possible embodiments, the segmentation module is specifically used to:
[0136] Determine the Dirichlet distribution parameter corresponding to each terminal device according to the type and quantity corresponding to each terminal device;
[0137] According to the Dirichlet distribution parameters corresponding to each device, the Dirichlet distribution parameters corresponding to the initial neural network model are obtained.
[0138] In a fourth aspect, an embodiment of the present application provides a model training device, which is applied to a terminal device, and the device includes:
[0139] A fragment receiving module, used for receiving model fragments sent by a base station; the model fragments include: an initial fragment, an intermediate fragment and an end fragment; the initial fragment is a model fragment that is the first one in the order of the multiple model fragments determined by the base station in the initial neural network model, and the end fragment is a model fragment that is the last one in the order of the multiple model fragments determined by the base station in the initial neural network model; the intermediate fragments are model fragments sent by the base station except the initial fragment and the end fragment;
[0140] A training module, used to train the intermediate segment according to the local data set to obtain trained model parameters;
[0141] A signal sending module, used for sending a training end signal to the base station;
[0142] A device information receiving module, used to receive device information of a next terminal device sent by the base station;
[0143] The model parameter sending module is used to send the trained model parameters to the next terminal device according to the device information of the next terminal device.
[0144] In some possible embodiments, the training module is specifically used for:
[0145] Based on the local data set, the intermediate segment is trained in an iterative manner until the loss value corresponding to the intermediate segment is less than a preset loss value;
[0146] The model parameters of the intermediate segment at the end of the iteration are used as the model parameters of the training completed.
[0147] In some possible embodiments, the training module is specifically used for:
[0148] Inputting the local data set into the intermediate segment based on the initial segment to obtain a parameter value output by the end segment;
[0149] Determine a loss value corresponding to the intermediate segment based on the parameter value, the local data set, and the loss function;
[0150] Adjusting the model parameters of the intermediate segment according to the loss value;
[0151] Determine a gradient value corresponding to the middle segment, and clip the gradient value based on a preset gradient range to obtain a clipped gradient;
[0152] The clipped gradient is used to update the gradient value of the intermediate segment.
[0153] In some possible embodiments, the fragment receiving module is further configured to:
[0154] The types and quantities of labels of the local data set are sent to the base station so that the base station obtains the loss function of the neural network model according to the types and quantities of labels, and the loss function is used to determine whether the training of the intermediate segments converges.
[0155] In the fifth aspect, another embodiment of the present application also provides an electronic device, comprising at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute any one of the methods provided in the embodiments of the first and second aspects of the present application.
[0156] In the sixth aspect, another embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and the computer program is used to enable a computer to execute any method provided in the embodiments of the first and second aspects of the present application.
[0157] Other features and advantages of the present application will be described in the following description, and partly become apparent from the description, or be understood by practicing the present application. The purpose and other advantages of the present application can be realized and obtained by the structures specifically pointed out in the written description, claims, and drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0158] Figure 1A It is a schematic diagram of an application scenario of a model training method provided in an embodiment of the present application;
[0159] Figure 1B It is a schematic diagram of a communication system architecture of a model training method provided in an embodiment of the present application;
[0160] Figure 2 It is a schematic diagram of the overall process of a model training method provided in an embodiment of the present application;
[0161] Figure 3 It is a schematic diagram of a flow chart of segmenting an initial neural network model in a model training method provided in an embodiment of the present application;
[0162] Figure 4 It is a schematic diagram of the framework of an initial neural network model of a model training method provided in an embodiment of the present application;
[0163] Figure 5 It is a flow chart of distributing multiple model fragments to at least two terminal devices in a model training method provided in an embodiment of the present application;
[0164] Figure 6It is a flow chart of distributing intermediate segments to terminal devices when it is determined that the number of terminal devices is equal to the number of intermediate segments in a model training method provided in an embodiment of the present application;
[0165] Figure 7 It is a flow chart of distributing intermediate segments to terminal devices based on segment processing capability and training difficulty parameters in a model training method provided in an embodiment of the present application;
[0166] Figure 8 It is a flow chart of selecting a number of terminal devices of intermediate segments from terminal devices as target terminal devices in a model training method provided in an embodiment of the present application;
[0167] Fig. 9 It is a flow chart of distributing intermediate segments to target terminal devices in a model training method provided in an embodiment of the present application;
[0168] Fig.10 It is a flow chart of distributing the intermediate segments to the terminal devices when it is determined that the number of terminal devices is less than the number of intermediate segments in a model training method provided by an embodiment of the present application;
[0169] Fig.11 It is another flow chart of distributing intermediate segments to terminal devices based on segment processing capability and training difficulty parameters in a model training method provided by an embodiment of the present application;
[0170] Fig.12 It is a flowchart of determining the next terminal device of a model training method provided in an embodiment of the present application;
[0171] Fig.13 It is an overall schematic diagram of a model training method provided in an embodiment of the present application;
[0172] Fig.14 It is a flowchart diagram of a model training method for avoiding catastrophic forgetting provided in an embodiment of the present application;
[0173] Fig.15 It is a schematic diagram of the overall process of a model training method provided in an embodiment of the present application, in which the execution subject is a terminal device;
[0174] Fig.16 It is a flowchart of each round of iteration process of a model training method provided in an embodiment of the present application;
[0175] Fig.17 is a federated learning convergence curve of a model training method provided in an embodiment of the present application;
[0176] Fig.18 is a convergence curve of a model training method provided in an embodiment of the present application;
[0177] Fig.19 It is a comparative schematic diagram of different local iteration numbers of a model training method provided in an embodiment of the present application;
[0178] Fig. 20 It is a schematic diagram of label categories and quantities of a model training method provided in an embodiment of the present application;
[0179] Fig.21 It is another convergence curve of federated learning of a model training method provided in an embodiment of the present application;
[0180] Fig. 22 is another convergence curve of a model training method provided in an embodiment of the present application;
[0181] Fig.23 This is another comparative schematic diagram of different local iteration numbers of a model training method provided in an embodiment of the present application;
[0182] Fig.24 It is a schematic diagram of a device in which a base station is the main body of a model training method provided in an embodiment of the present application;
[0183] Fig.25 It is a schematic diagram of a device in which a model training method provided in an embodiment of the present application is performed mainly by a terminal device;
[0184] Fig.26 It is a schematic diagram of an electronic device of a model training method provided in an embodiment of the present application. DETAILED DESCRIPTION
[0185] The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, but should not be construed as limiting the present invention.
[0186] In order to better understand the technical solution of the present application, the embodiments of the present application are described in detail below with reference to the accompanying drawings.
[0187] It should be clear that the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in the field without creative work are within the scope of protection of the present application.
[0188] The terms used in the embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit the present application. The singular forms "a", "said" and "the" used in the embodiments of the present application and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings.
[0189] It should be understood that the term "and / or" used in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship.
[0190] For ease of understanding, the professional terms used in this application are first explained below:
[0191] The fifth generation mobile communication technology (5G) is a new generation of broadband mobile communication technology with the characteristics of high speed, low latency and large connection. 5G communication facilities are the network infrastructure for realizing the interconnection between people, machines and things.
[0192] Sixth generation mobile networks (6G): A conceptual wireless network mobile communication technology, also known as the sixth generation mobile communication standard, which can promote the development of industrial Internet and Internet of Things.
[0193] TDD (Time Division Duplexing) is a duplex mode of a communication system, which is used to separate the receiving and transmitting channels (or uplink and downlink) in mobile communication systems. In a TDD mode mobile communication system, reception and transmission are in different time slots of the same frequency channel, i.e., the carrier, and the receiving and transmitting channels are separated by guaranteed time.
[0194] FDD (Frequency Division Duplexing): refers to the uplink (mobile station to base station) and downlink (base station to mobile station) using two separate frequencies (with certain frequency spacing requirements), and this mode works on a symmetrical frequency band. FDD is suitable for wireless communication systems that provide a single radio frequency channel for each user.
[0195] Terminal equipment: i.e. mobile station, which can be vehicle-mounted, portable or handheld. The physical equipment and mobile user can be completely independent. All information related to the user can be stored in a smart card (Subscriber Identity Module, SIM) card, which can be used on the mobile station. The terminal can complete the interaction with the base station directly through the air interface. The terminal can send and / or receive signals.
[0196] Base station: A wireless base station in the network, which is also a network element of the wireless access network, is responsible for all functions related to the air interface: wireless link maintenance function, maintaining the wireless link with the terminal, and responsible for the protocol conversion of wireless link data and IP data quality monitoring; wireless resource management function, including the establishment and release of wireless links, scheduling and allocation of wireless resources, etc.; some mobility management functions, including configuring terminals for measurement, evaluating the quality of terminal wireless links, and deciding on terminal switching between cells.
[0197] Core network: The functions of the core network are mainly to provide user connection, user management and business carrying, and to provide an interface to the external network as a bearer network.
[0198] The inventors found that, thanks to the rapid development of cellular networks, FL provides a safe and efficient method for conducting artificial intelligence on distributed terminals for the purpose of protecting information and privacy security, and has been applied to a wide range of scenarios. However, most existing federated learning methods are committed to using many devices, each of which synchronously trains a complete model locally, and updates the global model through gradient averaging and model distribution. Since each device needs to train a complete model, the model size that the network can carry will be very limited, and since the gradient of the complete model needs to be uploaded, the overhead of a single synchronous communication is large.
[0199] In response to the above problems, the embodiments of the present application provide a model training method, device, electronic device and storage medium for solving the above problems. The inventive concept of the present application can be summarized as follows: segmenting the initial neural network model to obtain multiple model fragments; distributing the multiple model fragments to at least two terminal devices, so that each terminal device trains the received model fragments according to the local data set of the terminal device; for each terminal device: receiving a training end signal uploaded by the terminal device; based on the training end signal, determining the next terminal device corresponding to the terminal device; sending the device information of the next terminal device to the terminal device, so that the terminal device sends the trained model parameters to the next terminal device; obtaining the model parameters of the terminal device that last sent the training end signal, and using the model parameters of the terminal device that last sent the training end signal to update the model parameters of the initial neural network model to obtain a trained neural network model.
[0200] For ease of understanding, a model training method provided in an embodiment of the present application is described in detail below with reference to the accompanying drawings:
[0201] like Figure 1A As shown, it is an application scenario diagram of a model training method in an embodiment of the present application. The figure includes: a base station 10, a terminal device 20; wherein:
[0202] The base station 10 divides the initial neural network model into multiple model fragments; distributes the multiple model fragments to at least two terminal devices 20, so that each terminal device 20 trains the received model fragments according to the local data set of the terminal device 20; for each terminal device 20: receives a training end signal uploaded by the terminal device 20; based on the training end signal, determines the next terminal device 20 corresponding to the terminal device 20; sends the device information of the next terminal device 20 to the terminal device 20, so that the terminal device 20 sends the trained model parameters to the next terminal device 20; obtains the model parameters of the terminal device 20 that sends the training end signal last, and uses the model parameters of the terminal device 20 that sends the training end signal last to update the model parameters of the initial neural network model to obtain a trained neural network model.
[0203] In the description of this application, only a single base station 10 and a terminal device 20 are described in detail, but those skilled in the art should understand that the base station 10 and the terminal device 20 shown are intended to represent the operations of the base station 10 and the terminal device 20 involved in the technical solution of this application. It does not imply any limitation on the number, type or location of the base station 10 and the terminal device 20. It should be noted that if additional modules are added to the illustrated environment or individual modules are removed therefrom, the underlying concepts of the exemplary embodiments of this application will not be changed.
[0204] like Figure 1B As shown, a model training method in an embodiment of the present application is applicable to a 5G communication system, a 6G communication system, or a communication system evolved in the future, or other communication systems, etc., and the present application does not limit this. The scenario of the embodiment of the present application is based on signal transmission, such as Figure 1B As shown, it includes terminals, base stations and core networks. The embodiments of the present application are applicable to both homogeneous and heterogeneous network scenarios, and there is no restriction on the transmission points. It can be multi-point coordinated transmission between macro base stations, micro base stations and micro base stations, and macro base stations and micro base stations, and it is applicable to FDD / TDD systems. The embodiments of the present invention are applicable to low-frequency scenarios (below 6G), high-frequency scenarios (above 6G), terahertz, optical communications, etc.
[0205] It should be noted that the model training method proposed in this application is not only applicable to Figure 1A , Figure 1B The application scenario shown is also applicable to any device that requires model training.
[0206] First, this application is described with the base station as the execution subject. Figure 2 FIG. 1 is a flow chart of a model training method provided in an embodiment of the present application, wherein:
[0207] In step 201: the initial neural network model is segmented to obtain multiple model segments.
[0208] In an embodiment of the present application, in order to reduce the overhead of the neural network model during the training process, the neural network model is segmented, and each terminal device only needs to train the model fragment it has received to achieve the training of the initial neural network model.
[0209] In some possible embodiments, the initial neural network model is segmented to obtain multiple model segments, which can be specifically implemented as follows: Figure 3 The steps shown, where:
[0210] In step 301: obtain model parameters of the initial neural network model.
[0211] In step 302: the number of model layers of the initial neural network model is determined according to the model parameters of the initial neural network model.
[0212] In step 303: the neural network model is segmented based on the number of model layers of the initial neural network model to obtain multiple model segments and a segment serial number corresponding to each model segment; the segment serial number corresponding to each model segment represents the order of the model segment in the initial neural network model.
[0213] That is, in the present application, the number of model layers of the initial neural network model can be determined by obtaining the model parameters of the initial neural network model, and the model can be split according to the number of layers when the initial neural network model is constructed, thereby ensuring the integrity of each model fragment obtained.
[0214] For example: Figure 4 As shown, the framework schematic diagram of the initial neural network model A is shown in the figure, and according to the number of model layers of the neural network model A, model fragment 1, model fragment 2, model fragment 3, model fragment 4, and model fragment 5 can be obtained by splitting.
[0215] In step 202: multiple model fragments are distributed to at least two terminal devices, so that each terminal device trains the received model fragments according to the local data set of the terminal device.
[0216] In an embodiment of the present application, by distributing model fragments to multiple terminal devices, each terminal device is required to train the received model fragments without training the entire model, thereby reducing the overhead of the terminal device in training the initial neural network model and improving the efficiency of training the initial neural network model.
[0217] In some possible embodiments, multiple model fragments are distributed to at least two terminal devices, which can be specifically implemented as follows: Figure 5 The steps shown, where:
[0218] In step 501: distribute the initial segment and the ending segment of the multiple model segments to each terminal device; the initial segment is the model segment that is the first in the initial neural network model among the multiple model segments, and the ending segment is the model segment that is the last in the initial neural network model among the multiple model segments.
[0219] In the embodiment of the present application, by distributing the initial segment and the end segment to each terminal device, the consistency of the input and output of the model segment trained by each terminal device is ensured. Figure 4 As shown, the framework schematic diagram of the initial neural network model A is shown in the figure. According to the number of model layers of the neural network model A, model fragment 1, model fragment 2, model fragment 3, model fragment 4, and model fragment 5 can be obtained, among which model fragment 1 is the initial fragment and model fragment 5 is the ending fragment.
[0220] In step 502: the number of terminal devices in communication connection is determined.
[0221] In step 503: the intermediate segments among the multiple model segments are distributed to at least two terminal devices based on the number of terminal devices; the intermediate segments are model segments among the multiple model segments except the initial segment and the end segment.
[0222] For example: Figure 4 As shown, the framework schematic diagram of the initial neural network model A is shown in the figure. According to the number of model layers of the neural network model A, model fragment 1, model fragment 2, model fragment 3, model fragment 4, and model fragment 5 can be obtained, among which model fragment 2, model fragment 3, and model fragment 4 are intermediate fragments.
[0223] In some possible embodiments, there are three possibilities for the number of terminal devices and the number of intermediate segments, namely, the number of terminal devices is equal to the number of intermediate segments, the number of terminal devices is greater than the number of intermediate segments, and the number of terminal devices is less than the number of intermediate segments. In order to ensure that the overhead is reduced as much as possible, the intermediate segment distribution method corresponding to each case is different, which is described below:
[0224] 1. The number of terminal devices is equal to the number of intermediate segments
[0225] In some possible embodiments, if it is determined that the number of terminal devices is equal to the number of intermediate segments, the intermediate segments are distributed to the terminal devices, wherein each terminal device receives an intermediate segment, and the intermediate segments received by each terminal device are different.
[0226] That is, in an embodiment of the present application, when the number of terminal devices is equal to the number of intermediate segments, in order to ensure load balancing and the efficiency of model training, each terminal device trains one intermediate segment.
[0227] In some possible embodiments, when it is determined that the number of terminal devices is equal to the number of intermediate segments, the intermediate segments are distributed to the terminal devices, which can be specifically implemented as follows: Figure 6 The steps shown, where:
[0228] In step 601: obtain the training difficulty parameter of each intermediate segment; and obtain the computing power and data transmission rate of each terminal device.
[0229] In some possible embodiments, the training difficulty parameters of the intermediate segments can be pre-calibrated by a technician and stored in a memory, and the base station can directly obtain the training difficulty parameters of each intermediate segment from the memory. The computing power and data transmission rate of the terminal device are device parameters of the terminal device. When the base station obtains the computing power and data transmission rate of the terminal device, it can send a signal to the terminal device to inform the terminal device to report its own computing power and data transmission rate.
[0230] It should be noted that the computing power of the terminal device mentioned in this application is the computing power that is not occupied by the terminal device.
[0231] In step 602: based on the acquired computing power and data transmission rate of each terminal device, the fragment processing capability corresponding to each terminal device is obtained.
[0232] In some possible embodiments, when determining the fragment processing capability corresponding to each terminal device, a weight method may be used for calculation; that is, the computing power and data transmission rate of the terminal device are multiplied by their respective weights, and then summed up, and the result is used as the fragment processing capability of the terminal device.
[0233] For example: the computing power of terminal device A is 10, and the data transmission rate is 100; the weight of computing power is 0.6, and the weight of data transmission rate is 0.4, then the fragment processing capacity of terminal device A = 10*0.6+100*0.4=46.
[0234] In step 603: based on the segment processing capability corresponding to each terminal device and the training difficulty parameter corresponding to each intermediate segment, the intermediate segments are distributed to the terminal devices.
[0235] In some possible embodiments, based on the segment processing capability corresponding to each terminal device and the training difficulty parameter corresponding to each intermediate segment, the intermediate segments are distributed to the terminal devices, which can be specifically implemented as follows: Figure 7 The steps shown, where:
[0236] In step 701: sorting is performed based on the training difficulty parameter corresponding to each intermediate segment according to the first rule to obtain an intermediate segment difficulty sequence.
[0237] In step 702: the fragment processing capabilities corresponding to each terminal device are sorted according to the first rule to obtain a processing capability sequence.
[0238] In step 703: for each intermediate segment in the intermediate segment difficulty sequence, the intermediate segment is distributed to an intermediate terminal device; the intermediate terminal device is a terminal device in the same position in the processing capability sequence as the intermediate segment in the intermediate segment sequence.
[0239] In some possible embodiments, the first rule may be sorted from high to low or from low to high, and this application does not limit this. The technicians may set the specific implementation method of the first rule according to their needs.
[0240] For example: the first rule is to sort from high to low, and it is determined that the intermediate segments include: intermediate segment 2, intermediate segment 3, and intermediate segment 4; the intermediate segments are sorted using the first rule, and the intermediate segment difficulty sequence obtained is: intermediate segment 3, intermediate segment 2, intermediate segment 4; the terminal devices are determined to include: terminal device A, terminal device B, and terminal device C, and the terminal devices are sorted using the first rule, and the processing capability sequence obtained is: terminal device C, terminal device A, terminal device B. Based on the intermediate segment sequence and the processing capability sequence, it can be determined that the position of intermediate segment 3 in the intermediate segment sequence is the same as the position of terminal device C in the processing capability sequence, the position of intermediate segment 2 in the intermediate segment sequence is the same as the position of terminal device A in the processing capability sequence, and the position of intermediate segment 4 in the intermediate segment sequence is the same as the position of terminal device B in the processing capability sequence; then, intermediate segment 3 is distributed to terminal device C, intermediate segment 2 is distributed to terminal device A, and intermediate segment 4 is distributed to terminal device B.
[0241] In some other possible embodiments, when distributing the intermediate fragments to the terminal devices, a random distribution method can also be adopted, that is, the intermediate fragments are randomly distributed to the terminal devices. It is necessary to ensure that each terminal device receives an intermediate fragment, and it is necessary to ensure that the intermediate fragments received by each terminal device are different.
[0242] In an embodiment of the present application, by distributing intermediate segments with higher training difficulty to terminal devices with higher computing power, the efficiency of model training is guaranteed while ensuring load balancing.
[0243] 2. The number of terminal devices is greater than the number of intermediate segments
[0244] In some possible embodiments, if it is determined that the number of terminal devices is greater than the number of intermediate fragments, terminal devices with the number of intermediate fragments are selected from the terminal devices as target terminal devices, and the intermediate fragments are distributed to the target terminal devices, wherein each target terminal device receives an intermediate fragment, and the intermediate fragments received by each target terminal device are different.
[0245] That is, in an embodiment of the present application, when the number of terminal devices is greater than the number of intermediate fragments, it means that some terminal devices cannot be allocated intermediate fragments. In order to ensure load balancing, when distributing intermediate fragments, the target terminal device is first selected from the terminal devices, and the target terminal device processes the intermediate fragments.
[0246] In some possible embodiments, terminal devices with the number of intermediate segments are selected from the terminal devices as target terminal devices, which can be specifically implemented as follows: Figure 8 The steps shown, where:
[0247] In step 801: the computing power and data transmission rate of each terminal device are obtained.
[0248] In the present application, the implementation method of step 801 is the same as that of step 601, and will not be repeated here.
[0249] In step 802: based on the acquired computing power and data transmission rate of each terminal device, the fragment processing capability corresponding to each terminal device is obtained.
[0250] In the present application, the implementation method of step 802 is the same as that of step 602, and will not be described again here.
[0251] In step 803: according to the fragment processing capability, terminal devices with the middle number of fragments are selected in descending order as target terminal devices.
[0252] For example: determine that the terminal devices include: terminal device A, terminal device B, terminal device C, terminal device D, terminal device E, and sort the processing capability sequence from high to low according to the fragment processing capability corresponding to each terminal device: terminal device C, terminal device D, terminal device E, terminal device A, terminal device B; then the selected target terminal devices are: terminal device C, terminal device D, terminal device E.
[0253] In the present application, a terminal device with high segment processing capability is selected from among the terminal devices to train the intermediate segments, thereby ensuring the efficiency of processing the intermediate segments.
[0254] In some possible embodiments, the intermediate segments are distributed to the target terminal device, which can be specifically implemented as follows: Fig. 9 The steps shown, where:
[0255] In step 901: obtain the training difficulty parameter of each intermediate segment.
[0256] In the present application, the implementation method of step 901 is the same as that of step 601, and will not be repeated here.
[0257] In step 902: sorting is performed based on the training difficulty parameter corresponding to each intermediate segment according to the first rule to obtain an intermediate segment difficulty sequence.
[0258] In the present application, the implementation method of step 902 is the same as that of step 701, and will not be described again here.
[0259] In step 903: the fragment processing capabilities corresponding to each target terminal device are sorted according to the first rule to obtain a processing capability sequence.
[0260] In the present application, the implementation method of step 903 is the same as that of step 702, and will not be repeated here.
[0261] In step 904: for each intermediate segment in the intermediate segment difficulty sequence, the intermediate segment is distributed to an intermediate target terminal device; the intermediate target terminal device is a target terminal device in the same position in the processing capability sequence as the intermediate segment in the intermediate segment sequence.
[0262] In the present application, the implementation method of step 904 is the same as that of step 703, and will not be described again here.
[0263] In an embodiment of the present application, by distributing intermediate segments with higher training difficulty to terminal devices with higher computing power, the efficiency of model training is guaranteed while ensuring load balancing.
[0264] 3. The number of terminal devices is less than the number of intermediate segments
[0265] In some possible embodiments, if it is determined that the number of terminal devices is less than the number of intermediate segments, the intermediate segments are distributed to the terminal devices, wherein each terminal device receives at least one intermediate segment.
[0266] That is, in the present application, when the number of terminal devices is less than the number of intermediate segments, it means that if each terminal device processes one intermediate segment, there will be intermediate segments that have not been trained by the terminal device, so the remaining intermediate segments need to be distributed to the terminal devices again.
[0267] In some possible embodiments, when it is determined that the number of terminal devices is less than the number of intermediate segments, the intermediate segments are distributed to the terminal devices, which can be specifically implemented as follows: Fig.10 Steps shown:
[0268] In step 1001: obtain the training difficulty parameter of each intermediate segment; and obtain the computing power and data transmission rate of each terminal device.
[0269] In the present application, the implementation method of step 1001 is the same as that of step 601, and will not be repeated here.
[0270] In step 1002: based on the acquired computing power and data transmission rate of each terminal device, the fragment processing capability corresponding to each terminal device is obtained.
[0271] In the present application, the implementation method of step 1002 is the same as that of step 602, and will not be described in detail here.
[0272] In step 1003: based on the segment processing capability corresponding to each terminal device and the training difficulty parameter corresponding to each intermediate segment, the intermediate segments are distributed to the terminal devices.
[0273] In some possible embodiments, based on the segment processing capability corresponding to each terminal device and the training difficulty parameter corresponding to each intermediate segment, the intermediate segments are distributed to the terminal devices, which can be specifically implemented as follows: Fig.11 The steps shown, where:
[0274] In step 1101: sorting is performed based on the training difficulty parameter corresponding to each intermediate segment according to the first rule to obtain an intermediate segment difficulty sequence.
[0275] In the present application, the implementation method of step 1101 is the same as that of step 701, and will not be repeated here.
[0276] In step 1102: the fragment processing capabilities corresponding to each terminal device are sorted according to the first rule to obtain a processing capability sequence.
[0277] In the present application, the implementation method of step 1102 is the same as that of step 702, and will not be repeated here.
[0278] In step 1103 : according to the number of terminal devices, target intermediate segments corresponding to the number of terminal devices are selected in sequence from the intermediate segment difficulty sequence.
[0279] In the present application, by selecting the target intermediate fragment according to the number of terminal devices, load balancing can be ensured, and each terminal device processes at least one target intermediate fragment, while ensuring the utilization of the terminal devices.
[0280] For example: determine that the number of terminal devices is 3, the first rule is to sort from high to low, and determine that the intermediate segments include: intermediate segment 2, intermediate segment 3, intermediate segment 4, intermediate segment 5, and intermediate segment 6; use the first rule to sort the intermediate segments, and the obtained intermediate segment difficulty sequence is: intermediate segment 3, intermediate segment 2, intermediate segment 5, intermediate segment 4, intermediate segment 6; then the three target intermediate segments selected are: intermediate segment 3, intermediate segment 2, and intermediate segment 5.
[0281] In step 1104: the training difficulty parameters corresponding to each target middle segment are sorted according to the first rule to obtain a target middle segment difficulty sequence.
[0282] For example: the first rule is to sort from high to low, and the target middle segments are determined to be: middle segment 2, middle segment 3, and middle segment 5; the target middle segment difficulty sequence obtained by sorting the target middle segments using the first rule is: middle segment 3, middle segment 2, middle segment 5.
[0283] In step 1105 : for each target intermediate segment in the target intermediate segment difficulty sequence, the target intermediate segment is distributed to the intermediate terminal device.
[0284] For example: the target intermediate segment difficulty sequence is: intermediate segment 3, intermediate segment 2, intermediate segment 5; the processing capability sequence is: terminal device C, terminal device A, terminal device B; then it is determined that the position of intermediate segment 3 in the target intermediate segment difficulty sequence is the same as the position of terminal device C in the processing capability sequence, it is determined that the position of intermediate segment 2 in the target intermediate segment difficulty sequence is the same as the position of terminal device A in the processing capability sequence, and it is determined that the position of intermediate segment 5 in the target intermediate segment difficulty sequence is the same as the position of terminal device B in the processing capability sequence.
[0285] In step 1106: sorting is performed based on the training difficulty parameters corresponding to each remaining intermediate segment according to the first rule to obtain a remaining intermediate segment difficulty sequence; wherein the remaining intermediate segments are intermediate segments in the intermediate segment difficulty sequence except the target intermediate segment.
[0286] For example: determine that the remaining intermediate segments are: intermediate segment 4, intermediate segment 6, and the first rule is to sort from high to low. Then, the difficulty sequence of the remaining intermediate segments obtained by sorting the training difficulties corresponding to the remaining intermediate segments is: intermediate segment 4, intermediate segment 6.
[0287] In step 1107: for each remaining intermediate segment in the remaining intermediate segment difficulty sequence, the remaining intermediate segment is distributed to an intermediate terminal device; the intermediate terminal device is a terminal device in the same position in the processing capability sequence as the target intermediate segment in the target intermediate segment sequence.
[0288] In the present application, when the number of terminal devices is less than the number of intermediate segments, in order to ensure the overall training efficiency of the model, a terminal device with high processing power is used to process multiple intermediate segments.
[0289] For example: determine that the remaining intermediate segments are: intermediate segment 4, intermediate segment 6, and determine that the processing capability sequence is: terminal device C, terminal device A, terminal device B; then determine that the position of intermediate segment 4 in the target intermediate segment difficulty sequence is the same as the position of terminal device C in the processing capability sequence, and determine that the position of intermediate segment 6 in the target intermediate segment difficulty sequence is the same as the position of terminal device B in the processing capability sequence.
[0290] In step 203: for each terminal device: receiving a training completion signal uploaded by the terminal device; based on the training completion signal, determining the next terminal device corresponding to the terminal device; sending the device information of the next terminal device to the terminal device, so that the terminal device sends the trained model parameters to the next terminal device.
[0291] That is, in the present application, after each intermediate segment is distributed to the terminal device, a training end signal is set to facilitate understanding of the training status of the intermediate segment in the terminal device; after the terminal device completes the training of the intermediate segment, it sends a training end signal to the base station. After receiving the training end signal, the base station determines the next terminal device and sends the next terminal device information to the terminal device, so that the terminal device sends the model parameters of the trained intermediate segment to the next terminal device. This method can ensure that the complete trained neural network model can be obtained in the last terminal device.
[0292] In some possible embodiments, based on the training end signal, determining the next terminal device corresponding to the terminal device may be specifically implemented as follows: Fig.12 The steps shown, where:
[0293] In step 1201: determine the target segment sequence number of the model segment processed by the terminal device; the target segment sequence number represents the order of the target segment in the initial neural network model.
[0294] In step 1202: determine the next segment number corresponding to the target segment number.
[0295] In step 1203: the terminal device that processes the model segment corresponding to the next segment sequence number is used as the next terminal device.
[0296] For example: the target segment processed by terminal device A is intermediate segment 2, the target segment sequence number of intermediate segment 2 is determined to be 2, the next segment sequence number corresponding to target segment 2 is determined to be 3, the intermediate segment corresponding to segment sequence number 3 is intermediate segment 3, and the terminal device processing intermediate segment 3 is determined to be terminal device B. Terminal device B is then used as the next terminal device, and the device information of terminal device B is sent to terminal device A. Terminal device A sends the model parameters of the trained intermediate segment 2 to terminal device B. At this time, the model segments included in terminal device B are: the initial segment, the trained intermediate segment 2, the intermediate segment 3, and the end segment.
[0297] In step 204: the model parameters of the terminal device that last sends the training completion signal are obtained, and the model parameters of the initial neural network model are updated using the model parameters of the terminal device that last sends the training completion signal to obtain a trained neural network model.
[0298] To facilitate further understanding Figure 2 The process in Figure 2 The steps in are illustrated with examples, such as Fig.13As shown: According to the number of model layers of neural network model A, model fragment 1, model fragment 2, model fragment 3, model fragment 4, and model fragment 5 can be obtained by splitting. The initial fragment is determined to be model fragment 1, and the end fragment is determined to be model fragment 5, then the intermediate fragments are: model fragment 2, model fragment 3, model fragment 4; the first rule is to sort from high to low, and the first rule is used to sort the intermediate fragments, and the obtained intermediate fragment difficulty sequence is: model fragment 3, model fragment 2, model fragment 4; it is determined that the terminal devices include: terminal device A, terminal device B, and terminal device C, and the first rule is used to sort the terminal devices, and the obtained processing capacity sequence is: terminal device C, terminal device A, terminal device B. Based on the intermediate fragment sequence and the processing capability sequence, it can be determined that the position of model fragment 3 in the model fragment sequence is the same as the position of terminal device C in the processing capability sequence, the position of model fragment 2 in the model fragment sequence is the same as the position of terminal device A in the processing capability sequence, and the position of model fragment 4 in the model fragment sequence is the same as the position of terminal device B in the processing capability sequence; then, model fragment 3 is distributed to terminal device C, model fragment 2 is distributed to terminal device A, and model fragment 4 is distributed to terminal device B; model fragment 1 is distributed to terminal device A, terminal device B and terminal device C respectively, and model fragment 5 is distributed to terminal device A, terminal device B and terminal device C respectively. According to the order of the model fragments in the model, it can be determined that terminal device A first trains model fragment 2, and sends a training end signal to the base station after the training is completed. The base station obtains the model parameters of model fragment 2 after the training is completed, and sends the model parameters of model fragment 2 after the training is completed to terminal device C; terminal device C starts to train model fragment 3, and sends a training end signal to the base station after the training is completed. The base station obtains the model parameters of model fragment 3 after the training is completed, and sends the model parameters of model fragment 3 after the training is completed to terminal device B; terminal device B starts to train model fragment 4, and after the training is completed, the terminal device B includes the model parameters of each layer of model fragments after training, and sends a training end signal to the base station. The base station uses the model parameters of terminal device B to update the model parameters of the initial neural network model to obtain the trained neural network model.
[0299] The inventors have found that in alternating continuous learning, there is often a problem of catastrophic forgetting. That is, when the model continues to train on subsequent tasks, it often forgets the knowledge learned in the previous task. In order to further avoid catastrophic forgetting on the basis of reducing the computing power consumed by model training, another model training method is provided in this application, such as Fig.14 As shown, where:
[0300] Step 1401: Receive the label type and quantity of the local data set reported by each terminal device.
[0301] The types and quantities of labels of local data sets in different terminal devices are different. In order to understand the local data sets on each terminal device, it is necessary to receive the types and quantities of labels of the local data sets reported by each terminal device.
[0302] For example, the terminal devices include: terminal device A, terminal device B, and terminal device C; the types and quantities of tags reported by terminal device A are: cat-100, dog-50, rabbit-40; the types and quantities of tags reported by terminal device B are: cat-100, dog-50, rabbit-30; the types and quantities of tags reported by terminal device C are: cat-20, dog-150, rabbit-60.
[0303] Step 1402: Determine the Dirichlet distribution parameters corresponding to the initial neural network model according to the type and quantity of labels.
[0304] In some possible embodiments, the Dirichlet distribution parameters corresponding to the initial neural network model are determined according to the type and quantity of labels. Specifically, the Dirichlet distribution parameters corresponding to each terminal device are determined according to the type and quantity corresponding to each terminal device; and the Dirichlet distribution parameters corresponding to the initial neural network model are obtained according to the Dirichlet distribution parameters corresponding to each device.
[0305] That is, the base station can determine the Dirichlet distribution parameters corresponding to each terminal device by the maximum likelihood estimation method with the prior distribution being the Dirichlet distribution; and then determine the Dirichlet distribution parameters corresponding to the initial neural network model based on the Dirichlet distribution parameters corresponding to each terminal device.
[0306] When determining the Dirichlet distribution parameters corresponding to the initial neural network model based on the Dirichlet distribution parameters corresponding to each terminal device, the mean method can be used, that is, the mean of the Dirichlet distribution parameters is obtained based on the Dirichlet distribution parameters corresponding to each terminal device, and the mean is used as the Dirichlet distribution parameters corresponding to the initial neural network model; the weight method can also be used, that is, the Dirichlet distribution parameters corresponding to the initial neural network model are obtained based on the weight corresponding to each terminal device and the Dirichlet distribution parameters corresponding to each terminal device.
[0307] For example: based on the maximum likelihood estimation method with the prior distribution being the Dirichlet distribution, the Dirichlet distribution parameter corresponding to terminal device A is determined to be A1, the Dirichlet distribution parameter corresponding to terminal device B is determined to be B1, and the Dirichlet distribution parameter corresponding to terminal device C is determined to be C1; if the mean method is used, (A1+B1+C1) / 3 is the Dirichlet distribution parameter corresponding to the initial neural network model; the weight corresponding to terminal device A is determined to be 0.4, the weight corresponding to terminal device B is determined to be 0.2, and the weight corresponding to terminal device C is determined to be 0.4. If the weight method is used, (A1*0.4+B1*0.2+C1*0.4) is the Dirichlet distribution parameter corresponding to the initial neural network model.
[0308] It should be noted that the two methods for determining the Dirichlet distribution parameters corresponding to the initial neural network model based on the Dirichlet distribution parameters corresponding to each terminal device given above in the present application are merely two embodiments, and are not intended to limit the method for determining the Dirichlet distribution parameters corresponding to the initial neural network model based on the Dirichlet distribution parameters corresponding to each terminal device in the present application. In specific implementation, technicians can set the method for determining the Dirichlet distribution parameters corresponding to the initial neural network model based on the Dirichlet distribution parameters corresponding to each terminal device according to their needs, for example: using the maximum value method, the minimum value method, etc., and the present application does not limit this.
[0309] Step 1403: If the Dirichlet distribution parameter is greater than a preset value, determine that the loss function used by each terminal device when training the model segment is a first loss function; the first loss function is used to determine whether the training of the model segment converges.
[0310] If the Dirichlet distribution parameter is greater than the preset value, it means that the terminal device needs to be trained to avoid catastrophic forgetting. Therefore, the loss function used by the terminal device when training the model fragment is the first loss function. The first loss function is a loss function with the knowledge distillation term added. The knowledge distillation term processing solution is to regard the process of each terminal device using the local data set to train the model fragment as an independent virtual task (Task). Therefore, the old model that has not been updated locally can be regarded as an old task (Old Task), and the model fragment being trained after the local update can be regarded as a new task (New Task). By taking the cross-entropy of the outputs of the same data in the two, the catastrophic forgetting effect of avoiding forgetting the old task can be achieved.
[0311] in:
[0312] The knowledge distillation term is shown in Formula 1:
[0313]
[0314] Among them, H(Y′ n, Y′ o ) is the knowledge distillation term, Y′ n Is The set composed of Y′o is the data obtained by training the model fragment using the local dataset. The set composed of It is the preset value of the data obtained by training the model fragment received last time using the local data set after the model fragment was received last time. T is the preset temperature parameter value. T can be set to 2. Express Sum the dimensions of , Express The sum of each dimension of is taken, and l represents the number of samples in the local dataset.
[0315] The first loss function is shown in Formula 2:
[0316]
[0317] in, is the first loss function, H(Y′ n , Y′ o ) is the knowledge distillation item, is the default value, is the category of the label of the local dataset, Y n Is The set composed of express and Y n The loss between.
[0318] Step 1404: If the Dirichlet distribution parameter is not greater than a preset value, determine that the loss function used by each terminal device when training the model segment is a second loss function; the second loss function is used to determine whether the training of the model segment converges.
[0319] In the embodiment of the present application, if the Dirichlet distribution parameter is not greater than the preset value, it means that no anti-catastrophic forgetting training is required, and the second loss function used does not include the knowledge distillation term, wherein the second loss function is shown in Formula 3:
[0320]
[0321] in, is the second loss function, express and Y n The loss between is the default value, is the category of the label of the local dataset, Y n Is The set composed of.
[0322] For example: if the Dirichlet distribution parameter corresponding to the initial neural network model is determined to be m, and the preset value is 100, if it is determined that m is greater than 100, the loss function used is the first loss function; if m is not greater than 100, the loss function used is the second loss function.
[0323] Step 1405: Segment the initial neural network model to obtain multiple model segments.
[0324] In the embodiment of the present application, the specific implementation method of step 1405 is the same as step 201 and will not be repeated here.
[0325] Step 1406: Distribute the multiple model fragments to at least two terminal devices, so that each terminal device trains the received model fragments according to the local data set of the terminal device.
[0326] In the embodiment of the present application, the specific implementation method of step 1406 is the same as step 202 and will not be repeated here.
[0327] Step 1407: For each terminal device: receive a training completion signal uploaded by the terminal device; based on the training completion signal, determine the next terminal device corresponding to the terminal device; send the device information of the next terminal device to the terminal device, so that the terminal device sends the trained model parameters to the next terminal device.
[0328] In the embodiment of the present application, the specific implementation method of step 1407 is the same as step 203 and will not be repeated here.
[0329] Step 1408: Obtain the model parameters of the terminal device that last sends the training completion signal, and use the model parameters of the terminal device that last sends the training completion signal to update the model parameters of the initial neural network model to obtain a trained neural network model.
[0330] In the embodiment of the present application, the specific implementation method of step 1408 is the same as step 204 and will not be repeated here.
[0331] In summary, in a model training method provided by the present application, after the current terminal device completes the training of the model segment using the local data set, it queries the base station for the next terminal device, and sends to it through the base station: the updated model parameters, the segment sequence number of the updated model segment, and its own identification information. This process is repeated continuously, thereby completing the process of Snake Learning (SL).
[0332] The present application also provides a model training method in which the execution subject is a terminal device, such as Fig.15FIG. 1 is a flow chart of a model training method provided in an embodiment of the present application, wherein:
[0333] Step 1501: receiving a model segment sent by a base station; the model segment includes: an initial segment, a middle segment and an end segment.
[0334] Among them, the initial fragment is the model fragment that is the first in the initial neural network model among the multiple model fragments determined by the base station, and the ending fragment is the model fragment that is the last in the initial neural network model among the multiple model fragments determined by the base station; the intermediate fragments are the model fragments sent by the base station except the initial fragment and the ending fragment.
[0335] In the present application, the terminal device ensures the consistency of input and output with other terminal devices that jointly train the initial neural network model by receiving the initial segment and the ending segment. Each terminal device only trains the received intermediate segment, and there is no need to train the complete initial neural network model, which reduces the overhead of the terminal device in training the initial neural network model and improves the efficiency of training the initial neural network model.
[0336] Step 1502: Train the intermediate segments according to the local data set to obtain trained model parameters.
[0337] In some possible embodiments, the intermediate segments are trained according to the local data set to obtain the trained model parameters. Specifically, the following can be implemented: based on the local data set, the intermediate segments are trained in an iterative manner until the loss value corresponding to the intermediate segments is less than the preset loss value; the model parameters of the intermediate segments at the end of the iteration are used as the trained model parameters. Each round of iteration process is as follows: Fig.16 As shown:
[0338] Step 1601: Based on the initial segment, the local data set is input into the middle segment to obtain the parameter value output by the end segment.
[0339] Step 1602: Determine the loss value corresponding to the intermediate segment based on the parameter value, the local data set and the loss function.
[0340] The loss function used by the terminal device when determining the loss value is determined by the base station based on the Dirichlet distribution parameters of the initial neural network model. The terminal device will send the type and quantity of labels of the local data set to the base station so that the base station can obtain the loss function of the neural network model based on the type and quantity of labels. The loss function is used to determine whether the training of the intermediate segment has converged. That is, after the base station determines the loss function based on the type and quantity of labels of the local data set reported by the terminal device, it will send the loss function to the terminal device so that the terminal device can calculate the loss value based on the loss function during the training of the model segment.
[0341] Step 1603: Adjust the model parameters of the intermediate segment according to the loss value.
[0342] Step 1604: Determine the gradient value corresponding to the middle segment, and clip the gradient value based on a preset gradient range to obtain a clipped gradient.
[0343] Since there are two main methods for solving catastrophic forgetting in the related art: one is the self-refreshing memory approach, that is, using a self-refreshing memory to store the knowledge that has been learned, and using the stored knowledge to constantly "remind" the learner not to forget the previously learned knowledge, so as to achieve the purpose of avoiding catastrophic forgetting. The most common practice is to extract a training sample set that can well represent the previous knowledge, and when training new samples, constantly use the training sample set representing the previous knowledge to "remind" the learner, so as to achieve the purpose of avoiding catastrophic forgetting. The second method is the knowledge distillation method. The original distillation neural network is to improve the training efficiency of deep learning and reduce the complexity of the network model structure, and reduce the time and space cost of deep learning on lightweight mobile platforms. However, the problem of gradient explosion often occurs during the model training process, which is specifically manifested as the gradient of the model suddenly becomes infinite after a period of training, causing the model performance to drop sharply. Therefore, in this application, in order to avoid gradient explosion in each round of iteration, a gradient clipping method is set. That is, in each round of training, the gradient value of this round is determined once, and the gradient value is clipped according to the preset gradient range. Specifically, it can be implemented as follows: if the gradient value is determined to be greater than or equal to the upper limit of the preset gradient range, the clipped gradient is the upper limit of the preset gradient range; if the gradient value is determined to be less than or equal to the lower limit of the preset gradient range, the clipped gradient is the lower limit of the preset gradient range; if the gradient value is determined to be less than the upper limit of the preset gradient range and greater than the lower limit of the preset gradient range, the clipped gradient value is the gradient value.
[0344] For example, if the gradient value after the current round of training is determined to be 10, the upper limit of the preset gradient range is determined to be 15, and the lower limit is determined to be 8, then the gradient value after clipping is determined to be 10.
[0345] Step 1605: Use the clipped gradient to update the gradient value of the middle segment.
[0346] That is, the determined clipped gradient is used to replace the current gradient value of the terminal device.
[0347] Step 1503: Send a training end signal to the base station.
[0348] That is, in this application, in order to facilitate understanding of the training status of the intermediate segment in the terminal device, a training end signal is set; after the terminal device completes the training of the intermediate segment, it will send a training end signal to the base station, and after receiving the training end signal, the base station determines the next terminal device.
[0349] Step 1504: Receive the device information of the next terminal device sent by the base station.
[0350] Step 1505: Send the trained model parameters to the next terminal device according to the device information of the next terminal device.
[0351] In the present application, after receiving the training completion signal, the base station determines the next terminal device and sends the device information of the next terminal device to the terminal device, so that the terminal device sends the model parameters of the trained intermediate segment to the next terminal device. This method can ensure that the complete trained neural network model can be obtained in the last terminal device.
[0352] For example: the target segment processed by terminal device A is intermediate segment 2, the target segment sequence number of intermediate segment 2 is determined to be 2, the next segment sequence number corresponding to target segment 2 is determined to be 3, the intermediate segment corresponding to segment sequence number 3 is intermediate segment 3, and the terminal device processing intermediate segment 3 is determined to be terminal device B. Terminal device B is then used as the next terminal device, and the device information of terminal device B is sent to terminal device A. Terminal device A sends the model parameters of the trained intermediate segment 2 to terminal device B. At this time, the model segments included in terminal device B are: the initial segment, the trained intermediate segment 2, the intermediate segment 3, and the end segment.
[0353] In order to further understand the model training method provided in the embodiment of the present application, the following example is used to illustrate:
[0354] For example: 1. Use the second loss function to train the model fragment
[0355] This embodiment uses a convolutional neural network (Visual Geometry Group, VGG11) as the neural network model to be trained, and the model has 11 layers. There are currently 9 terminal devices, and the local data set of each terminal device is formed by splitting the CIFAR-10 data set through independent and identically distributed (IID). Therefore, the local data set of each terminal device is IID distributed, and the loss function used is the second loss function. Fig.17As shown, it can be calculated that after each local training process of 9 terminal devices, the average number of parameters transmitted by each terminal device in the federated learning is: ((9*28144010)x2) / 9=56.2×〖10〗^6. The average number of parameters transmitted by each terminal device using the training method Snake Learning of the neural network model provided in the embodiment of the present application is as follows: Fig.18 As shown: [9*(1792+40970)+28144010-(1792+40970)]x2 / 9=6.32×〖10〗^6. Therefore, converted to each local iteration, the overhead of SL only accounts for 6.32 / 56.2=11.2% of the federated learning.
[0356] Among them, 9 represents 9 devices, 28144010 represents the model parameter quantity of the neural network model, 1792 represents the parameter quantity of the initial segment of the neural network model, and 40970 represents the parameter quantity of the ending segment of the neural network model.
[0357] like Fig.19 As shown, in other embodiments, by adjusting different local iteration numbers, the convergence speed of federated learning and Snake Learning at different local iteration numbers and the influence of communication overhead when reaching 60% accuracy are observed. Experiments show that Snake Learning can set a larger local iteration number, transmit less data, and save more communication overhead.
[0358] For example: 2. Use the first loss function to train the model fragment
[0359] The data of each terminal device is non-IID distribution. When dividing the CIFAR-10 data set, Dirichlet distribution is used so that the data of each label has different distribution probabilities among different devices. The specific distribution is as follows Fig. 20 shown.
[0360] like Fig.21 , Fig. 22 The following are the convergence curves under federated learning and the convergence curves under Snake Learning, a training method for a neural network model provided in an embodiment of the application. Fig.23 As shown, in other embodiments, by adjusting different local iteration numbers, the convergence speed of federated learning and Snake Learning at different local iteration numbers and the influence of communication overhead when reaching 60% accuracy are observed. Experiments show that even under non-IID conditions, Snake Learning can still maintain a higher number of local iterations and achieve the target performance with less communication cost.
[0361] Based on the same inventive concept, after introducing a model training method provided in an embodiment of the present application, as shown in FIG. Fig.24 As shown, a model training device 2400 provided in an embodiment of the present application and having an execution subject as a base station is described below, and the device includes:
[0362] A segmentation module 24001 is used to segment the initial neural network model to obtain multiple model segments;
[0363] A distribution module 24002, configured to distribute the plurality of model fragments to at least two terminal devices, so that each of the terminal devices trains the received model fragments according to a local data set of the terminal device;
[0364] The communication module 24003 is used for: for each terminal device: receiving a training completion signal uploaded by the terminal device; determining a next terminal device corresponding to the terminal device based on the training completion signal; and sending device information of the next terminal device to the terminal device, so that the terminal device sends the trained model parameters to the next terminal device;
[0365] The updating module 24004 is used to obtain the model parameters of the terminal device that last sends the training completion signal, and use the model parameters of the terminal device that last sends the training completion signal to update the model parameters of the initial neural network model to obtain a trained neural network model.
[0366] In some possible embodiments, the distribution module 24002 is specifically used for:
[0367] Distribute an initial segment and an ending segment of the multiple model segments to each terminal device; the initial segment is a model segment that is the first one in the order of the multiple model segments in the initial neural network model, and the ending segment is a model segment that is the last one in the order of the multiple model segments in the initial neural network model;
[0368] Determine the number of terminal devices connected to the communication;
[0369] Distributing the intermediate segments among the multiple model segments to the at least two terminal devices based on the number of the terminal devices; the intermediate segments are model segments among the multiple model segments excluding the initial segment and the end segment.
[0370] In some possible embodiments, the distribution module 24002 is specifically used for:
[0371] If it is determined that the number of the terminal devices is equal to the number of the intermediate segments, the intermediate segments are distributed to the terminal devices, wherein each of the terminal devices receives an intermediate segment, and the intermediate segments received by each of the terminal devices are different;
[0372] If it is determined that the number of the terminal devices is greater than the number of the intermediate fragments, terminal devices with the number of the intermediate fragments are selected from the terminal devices as target terminal devices, and the intermediate fragments are distributed to the target terminal devices, wherein each of the target terminal devices receives an intermediate fragment, and the intermediate fragments received by each of the target terminal devices are different;
[0373] If it is determined that the number of the terminal devices is less than the number of the intermediate segments, the intermediate segments are distributed to the terminal devices, wherein each terminal device receives at least one intermediate segment.
[0374] In some possible embodiments, the distribution module 24002 is specifically used for:
[0375] Obtaining a training difficulty parameter of each of the intermediate segments; and obtaining a computing power and a data transmission rate of each of the terminal devices;
[0376] Based on the acquired computing power and data transmission rate of each of the terminal devices, obtaining the fragment processing capability corresponding to each of the terminal devices;
[0377] The intermediate segments are distributed to the terminal devices based on the segment processing capability corresponding to each of the terminal devices and the training difficulty parameter corresponding to each of the intermediate segments.
[0378] In some possible embodiments, the distribution module 24002 is specifically used for:
[0379] Sorting the training difficulty parameters corresponding to each of the intermediate segments according to a first rule to obtain an intermediate segment difficulty sequence;
[0380] Sorting the fragment processing capabilities corresponding to each of the terminal devices according to the first rule to obtain a processing capability sequence;
[0381] For each intermediate segment in the intermediate segment difficulty sequence, the intermediate segment is distributed to an intermediate terminal device; the intermediate terminal device is a terminal device that has the same position in the processing capability sequence as the intermediate segment in the intermediate segment sequence.
[0382] In some possible embodiments, the distribution module 24002 is specifically used for:
[0383] Obtaining the computing power and data transmission rate of each of the terminal devices;
[0384] Based on the acquired computing power and data transmission rate of each of the terminal devices, obtaining the fragment processing capability corresponding to each of the terminal devices;
[0385] According to the fragment processing capability, terminal devices with the number of the intermediate fragments are selected in descending order as target terminal devices.
[0386] In some possible embodiments, the distribution module 24002 is specifically used for:
[0387] Obtaining a training difficulty parameter for each of the intermediate segments;
[0388] Sorting the training difficulty parameters corresponding to each of the intermediate segments according to a first rule to obtain an intermediate segment difficulty sequence;
[0389] Sorting the fragment processing capabilities corresponding to each of the target terminal devices according to the first rule to obtain a processing capability sequence;
[0390] For each intermediate segment in the intermediate segment difficulty sequence, the intermediate segment is distributed to an intermediate target terminal device; the intermediate target terminal device is a target terminal device that has the same position in the processing capability sequence as the intermediate segment in the intermediate segment sequence.
[0391] In some possible embodiments, the distribution module 24002 is specifically used for:
[0392] Obtaining a training difficulty parameter of each of the intermediate segments; and obtaining a computing power and a data transmission rate of each of the terminal devices;
[0393] Based on the acquired computing power and data transmission rate of each of the terminal devices, obtaining the fragment processing capability corresponding to each of the terminal devices;
[0394] The intermediate segments are distributed to the terminal devices based on the segment processing capability corresponding to each of the terminal devices and the training difficulty parameter corresponding to each of the intermediate segments.
[0395] In some possible embodiments, the distribution module 24002 is specifically used for:
[0396] Sorting the training difficulty parameters corresponding to each of the intermediate segments according to a first rule to obtain an intermediate segment difficulty sequence;
[0397] Sorting the fragment processing capabilities corresponding to each of the terminal devices according to the first rule to obtain a processing capability sequence;
[0398] According to the number of the terminal devices, sequentially selecting target intermediate segments of the number of the terminal devices from the intermediate segment difficulty sequence;
[0399] Sorting the training difficulty parameters corresponding to each target intermediate segment according to the first rule to obtain a target intermediate segment difficulty sequence;
[0400] For each target intermediate segment in the target intermediate segment difficulty sequence, distributing the target intermediate segment to an intermediate terminal device;
[0401] Sorting the training difficulty parameters corresponding to each remaining intermediate segment according to the first rule to obtain a remaining intermediate segment difficulty sequence; wherein the remaining intermediate segments are intermediate segments in the intermediate segment difficulty sequence except the target intermediate segment;
[0402] For each remaining intermediate segment in the remaining intermediate segment difficulty sequence, the remaining intermediate segment is distributed to an intermediate terminal device; the intermediate terminal device is a terminal device that has the same position in the processing capability sequence as the target intermediate segment in the target intermediate segment sequence.
[0403] In some possible embodiments, the segmentation module 24001 is specifically used for:
[0404] Obtaining model parameters of the initial neural network model;
[0405] Determine the number of model layers of the initial neural network model according to the model parameters of the initial neural network model;
[0406] The neural network model is segmented based on the number of model layers of the initial neural network model to obtain a plurality of model fragments and a fragment serial number corresponding to each model fragment; the fragment serial number corresponding to each model fragment represents the order of the model fragment in the initial neural network model.
[0407] In some possible embodiments, the updating module 24004 is specifically used for:
[0408] Determine a target segment sequence number of the model segment processed by the terminal device; the target segment sequence number represents the order of the target segment in the initial neural network model;
[0409] Determine the next segment sequence number corresponding to the target segment sequence number;
[0410] The terminal device that processes the model segment corresponding to the next segment sequence number is used as the next terminal device.
[0411] In some possible embodiments, the segmentation module 24001 is further used to:
[0412] Receive the label types and quantities of the local data set reported by each terminal device;
[0413] Determine the Dirichlet distribution parameters corresponding to the initial neural network model according to the type and quantity of labels;
[0414] If the Dirichlet distribution parameter is greater than a preset value, determining that the loss function used by each of the terminal devices when training the model fragment is a first loss function; the first loss function is used to determine whether the training of the model fragment converges;
[0415] If the Dirichlet distribution parameter is not greater than a preset value, the loss function used by each of the terminal devices when training the model fragment is determined to be a second loss function; the second loss function is used to determine whether the training of the model fragment has converged.
[0416] In some possible embodiments, the segmentation module 24001 is specifically used for:
[0417] Determine the Dirichlet distribution parameter corresponding to each terminal device according to the type and quantity corresponding to each terminal device;
[0418] According to the Dirichlet distribution parameters corresponding to each device, the Dirichlet distribution parameters corresponding to the initial neural network model are obtained.
[0419] like Fig.25 As shown, the following describes a model training device 2500 provided in an embodiment of the present application, in which the execution subject is a terminal device. The device includes:
[0420] The fragment receiving module 25001 is used to receive the model fragments sent by the base station; the model fragments include: an initial fragment, an intermediate fragment and an end fragment; the initial fragment is the model fragment that is the first in the order of the multiple model fragments determined by the base station in the initial neural network model, and the end fragment is the model fragment that is the last in the order of the multiple model fragments determined by the base station in the initial neural network model; the intermediate fragments are the model fragments sent by the base station except the initial fragment and the end fragment;
[0421] A training module 25002 is used to train the intermediate segment according to the local data set to obtain trained model parameters;
[0422] A signal sending module 25003 is used to send a training end signal to the base station;
[0423] The device information receiving module 25004 is used to receive the device information of the next terminal device sent by the base station;
[0424] The model parameter sending module 25005 is used to send the trained model parameters to the next terminal device according to the device information of the next terminal device.
[0425] In some possible embodiments, the training module is specifically used for:
[0426] Based on the local data set, the intermediate segment is trained in an iterative manner until the loss value corresponding to the intermediate segment is less than a preset loss value;
[0427] The model parameters of the intermediate segment at the end of the iteration are used as the model parameters of the training completed.
[0428] In some possible embodiments, the training module is specifically used for:
[0429] Inputting the local data set into the intermediate segment based on the initial segment to obtain a parameter value output by the end segment;
[0430] Determine a loss value corresponding to the intermediate segment based on the parameter value, the local data set, and the loss function;
[0431] Adjusting the model parameters of the intermediate segment according to the loss value;
[0432] Determine a gradient value corresponding to the middle segment, and clip the gradient value based on a preset gradient range to obtain a clipped gradient;
[0433] The clipped gradient is used to update the gradient value of the intermediate segment.
[0434] In some possible embodiments, the fragment receiving module is further configured to:
[0435] The types and quantities of labels of the local data set are sent to the base station so that the base station obtains the loss function of the neural network model according to the types and quantities of labels, and the loss function is used to determine whether the training of the intermediate segments converges.
[0436] Corresponding to the above embodiments, the present application also provides an electronic device. Fig.26 A schematic diagram of the structure of an electronic device provided in an embodiment of the present invention, the electronic device 2600 may include: a processor 2601, a memory 2602 and a communication unit 2603. These components communicate through one or more buses, and those skilled in the art can understand that the structure of the electronic device shown in the figure does not constitute a limitation on the embodiment of the present invention, it can be a bus structure or a star structure, and can also include more or less components than shown in the figure, or combine certain components, or arrange components differently.
[0437] The communication unit 2603 is used to establish a communication channel so that the electronic device can communicate with other devices, receive user data sent by other devices or send user data to other devices.
[0438] The processor 2601 is the control center of the electronic device. It uses various interfaces and lines to connect various parts of the entire electronic device. It runs or executes software programs and / or modules stored in the memory 2602, and calls data stored in the memory to perform various functions of the electronic device and / or process data. The processor can be composed of an integrated circuit (IC), for example, it can be composed of a single packaged IC, or it can be composed of multiple packaged ICs with the same or different functions. For example, the processor 2601 can only include a central processing unit (CPU). In an embodiment of the present invention, the CPU can be a single computing core or multiple computing cores.
[0439] The memory 2602 is used to store the execution instructions of the processor 2601. The memory 2602 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk.
[0440] When the execution instructions in the memory 2602 are executed by the processor 2601, the electronic device 2600 is able to execute Figure 2 Some or all of the steps in the illustrated embodiments.
[0441] In a specific implementation, the present invention further provides a computer storage medium, wherein the computer storage medium may store a program, and when the program is executed, the program may include some or all of the steps in each embodiment of the calling method provided by the present invention. The storage medium may be a magnetic disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0442] Those skilled in the art can clearly understand that the technology in the embodiments of the present invention can be implemented by means of software plus a necessary general hardware platform. Based on this understanding, the technical solution in the embodiments of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a disk, an optical disk, etc., and includes a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention or some parts of the embodiments.
[0443] In this specification, the same or similar parts between the various embodiments can be referred to each other. In particular, for the device embodiment and the terminal embodiment, since they are basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description in the method embodiment.
Claims
1. A model training method, characterized in that: Applied to a base station, the method comprises: The initial neural network model is segmented to obtain multiple model fragments; Distributing the multiple model fragments to at least two terminal devices, so that each of the terminal devices trains the received model fragments according to the local data set of the terminal device; For each terminal device: receiving a training completion signal uploaded by the terminal device; determining a next terminal device corresponding to the terminal device based on the training completion signal; sending device information of the next terminal device to the terminal device, so that the terminal device sends the trained model parameters to the next terminal device; The model parameters of the terminal device that last sends a training completion signal are obtained, and the model parameters of the initial neural network model are updated using the model parameters of the terminal device that last sends a training completion signal to obtain a trained neural network model.
2. The method according to claim 1, characterized in that The distributing the plurality of model fragments to at least two terminal devices comprises: Distribute an initial segment and an ending segment of the multiple model segments to each terminal device; the initial segment is a model segment that is the first one in the order of the multiple model segments in the initial neural network model, and the ending segment is a model segment that is the last one in the order of the multiple model segments in the initial neural network model; Determine the number of terminal devices connected to the communication; Distributing the intermediate segments among the multiple model segments to the at least two terminal devices based on the number of the terminal devices; the intermediate segments are model segments among the multiple model segments excluding the initial segment and the end segment.
3. The method according to claim 2, characterized in that The distributing the intermediate segments of the plurality of model segments to the at least two terminal devices based on the number of the terminal devices comprises: If it is determined that the number of the terminal devices is equal to the number of the intermediate segments, the intermediate segments are distributed to the terminal devices, wherein each of the terminal devices receives an intermediate segment, and the intermediate segments received by each of the terminal devices are different; If it is determined that the number of the terminal devices is greater than the number of the intermediate fragments, terminal devices with the number of the intermediate fragments are selected from the terminal devices as target terminal devices, and the intermediate fragments are distributed to the target terminal devices, wherein each of the target terminal devices receives an intermediate fragment, and the intermediate fragments received by each of the target terminal devices are different; If it is determined that the number of the terminal devices is less than the number of the intermediate segments, the intermediate segments are distributed to the terminal devices, wherein each terminal device receives at least one intermediate segment.
4. The method according to claim 3, characterized in that If it is determined that the number of the terminal devices is equal to the number of the intermediate segments, distributing the intermediate segments to the terminal devices comprises: Obtaining a training difficulty parameter of each of the intermediate segments; and obtaining a computing power and a data transmission rate of each of the terminal devices; Based on the acquired computing power and data transmission rate of each of the terminal devices, obtaining the fragment processing capability corresponding to each of the terminal devices; The intermediate segments are distributed to the terminal devices based on the segment processing capability corresponding to each of the terminal devices and the training difficulty parameter corresponding to each of the intermediate segments.
5. The method according to claim 4, characterized in that The distributing the intermediate segments to the terminal devices based on the segment processing capability corresponding to each of the terminal devices and the training difficulty parameter corresponding to each of the intermediate segments includes: Sorting the training difficulty parameters corresponding to each of the intermediate segments according to a first rule to obtain an intermediate segment difficulty sequence; Sorting the fragment processing capabilities corresponding to each of the terminal devices according to the first rule to obtain a processing capability sequence; For each intermediate segment in the intermediate segment difficulty sequence, the intermediate segment is distributed to an intermediate terminal device; the intermediate terminal device is a terminal device that has the same position in the processing capability sequence as the intermediate segment in the intermediate segment sequence.
6. The method according to claim 3, characterized in that The selecting the terminal devices of the number of the intermediate segments from the terminal devices as target terminal devices comprises: Obtaining the computing power and data transmission rate of each of the terminal devices; Based on the acquired computing power and data transmission rate of each of the terminal devices, obtaining the fragment processing capability corresponding to each of the terminal devices; According to the fragment processing capability, terminal devices with the number of the intermediate fragments are selected in descending order as target terminal devices.
7. The method according to claim 6, characterized in that The distributing the intermediate fragment to the target terminal device includes: Obtaining a training difficulty parameter for each of the intermediate segments; Sorting the training difficulty parameters corresponding to each of the intermediate segments according to a first rule to obtain an intermediate segment difficulty sequence; Sorting the fragment processing capabilities corresponding to each of the target terminal devices according to the first rule to obtain a processing capability sequence; For each intermediate segment in the intermediate segment difficulty sequence, the intermediate segment is distributed to an intermediate target terminal device; the intermediate target terminal device is a target terminal device that has the same position in the processing capability sequence as the intermediate segment in the intermediate segment sequence.
8. The method according to claim 3, characterized in that If it is determined that the number of the terminal devices is less than the number of the intermediate segments, allocating the intermediate segments to the terminal devices includes: Obtaining a training difficulty parameter of each of the intermediate segments; and obtaining a computing power and a data transmission rate of each of the terminal devices; Based on the acquired computing power and data transmission rate of each of the terminal devices, obtaining the fragment processing capability corresponding to each of the terminal devices; The intermediate segments are distributed to the terminal devices based on the segment processing capability corresponding to each of the terminal devices and the training difficulty parameter corresponding to each of the intermediate segments.
9. The method according to claim 8, characterized in that The distributing the intermediate segments to the terminal devices based on the segment processing capability corresponding to each of the terminal devices and the training difficulty parameter corresponding to each of the intermediate segments includes: Sorting the training difficulty parameters corresponding to each of the intermediate segments according to a first rule to obtain an intermediate segment difficulty sequence; Sorting the fragment processing capabilities corresponding to each of the terminal devices according to the first rule to obtain a processing capability sequence; According to the number of the terminal devices, sequentially selecting target intermediate segments of the number of the terminal devices from the intermediate segment difficulty sequence; Sorting the training difficulty parameters corresponding to each target intermediate segment according to the first rule to obtain a target intermediate segment difficulty sequence; For each target intermediate segment in the target intermediate segment difficulty sequence, distributing the target intermediate segment to an intermediate terminal device; Sorting the training difficulty parameters corresponding to each remaining intermediate segment according to the first rule to obtain a remaining intermediate segment difficulty sequence; wherein the remaining intermediate segments are intermediate segments in the intermediate segment difficulty sequence except the target intermediate segment; For each remaining intermediate segment in the remaining intermediate segment difficulty sequence, the remaining intermediate segment is distributed to an intermediate terminal device; the intermediate terminal device is a terminal device that has the same position in the processing capability sequence as the target intermediate segment in the target intermediate segment sequence.
10. The method according to claim 1, characterized in that The initial neural network model is segmented to obtain multiple model segments, including: Obtaining model parameters of the initial neural network model; Determine the number of model layers of the initial neural network model according to the model parameters of the initial neural network model; The neural network model is segmented based on the number of model layers of the initial neural network model to obtain a plurality of model fragments and a fragment serial number corresponding to each model fragment; the fragment serial number corresponding to each model fragment represents the order of the model fragment in the initial neural network model.
11. The method according to claim 1, characterized in that: The determining, based on the training end signal, a next terminal device corresponding to the terminal device comprises: Determine a target segment sequence number of the model segment processed by the terminal device; the target segment sequence number represents the order of the target segment in the initial neural network model; Determine the next fragment sequence number corresponding to the target fragment sequence number; The terminal device that processes the model segment corresponding to the next segment sequence number is used as the next terminal device.
12. The method according to claim 1, characterized in that Before the initial neural network model is segmented to obtain a plurality of model segments, the method further includes: Receive the label types and quantities of the local data set reported by each terminal device; Determine the Dirichlet distribution parameters corresponding to the initial neural network model according to the type and quantity of labels; If the Dirichlet distribution parameter is greater than a preset value, determining that the loss function used by each of the terminal devices when training the model fragment is a first loss function; the first loss function is used to determine whether the training of the model fragment converges; If the Dirichlet distribution parameter is not greater than a preset value, the loss function used by each of the terminal devices when training the model fragment is determined to be a second loss function; the second loss function is used to determine whether the training of the model fragment has converged.
13. The method according to claim 12, characterized in that The step of determining the Dirichlet distribution parameters corresponding to the initial neural network model according to the type and quantity of the labels includes: Determine the Dirichlet distribution parameter corresponding to each terminal device according to the type and quantity corresponding to each terminal device; According to the Dirichlet distribution parameters corresponding to each device, the Dirichlet distribution parameters corresponding to the initial neural network model are obtained.
14. A model training method, characterized in that: Applied to a terminal device, the method comprises: Receive model fragments sent by a base station; the model fragments include: an initial fragment, an intermediate fragment and an ending fragment; the initial fragment is a model fragment that is the first in the initial neural network model among multiple model fragments determined by the base station, and the ending fragment is a model fragment that is the last in the initial neural network model among the multiple model fragments determined by the base station; the intermediate fragments are model fragments sent by the base station except the initial fragment and the ending fragment; Training the intermediate segment according to the local data set to obtain trained model parameters; Sending a training end signal to the base station; Receiving device information of a next terminal device sent by the base station; The trained model parameters are sent to the next terminal device according to the device information of the next terminal device.
15. The method according to claim 14, characterized in that The step of training the intermediate segment according to the local data set to obtain trained model parameters includes: Based on the local data set, the intermediate segment is trained in an iterative manner until the loss value corresponding to the intermediate segment is less than a preset loss value; The model parameters of the intermediate segment at the end of the iteration are used as the model parameters of the training completed.
16. The method according to claim 15, characterized in that The intermediate segments are trained according to the local data set, and each round of iteration process is as follows: Inputting the local data set into the intermediate segment based on the initial segment to obtain a parameter value output by the end segment; Determine a loss value corresponding to the intermediate segment based on the parameter value, the local data set, and the loss function; Adjusting the model parameters of the intermediate segment according to the loss value; Determine a gradient value corresponding to the middle segment, and clip the gradient value based on a preset gradient range to obtain a clipped gradient; The clipped gradient is used to update the gradient value of the intermediate segment.
17. The method according to claim 14, characterized in that The method further comprises: The types and quantities of labels of the local data set are sent to the base station so that the base station obtains the loss function of the neural network model according to the types and quantities of labels, and the loss function is used to determine whether the training of the intermediate segments converges.
18. A model training device, characterized in that: Applied to a base station, the device comprises: A segmentation module is used to segment the initial neural network model to obtain multiple model fragments; A distribution module, used for distributing the plurality of model fragments to at least two terminal devices, so that each of the terminal devices trains the received model fragments according to the local data set of the terminal device; A communication module is used for: for each terminal device: receiving a training completion signal uploaded by the terminal device; determining a next terminal device corresponding to the terminal device based on the training completion signal; and sending device information of the next terminal device to the terminal device, so that the terminal device sends the trained model parameters to the next terminal device; The updating module is used to obtain the model parameters of the terminal device that last sends the training completion signal, and use the model parameters of the terminal device that last sends the training completion signal to update the model parameters of the initial neural network model to obtain a trained neural network model.
19. A model training device, characterized in that: Applied to a terminal device, the device comprises: A fragment receiving module, used for receiving model fragments sent by a base station; the model fragments include: an initial fragment, an intermediate fragment and an end fragment; the initial fragment is a model fragment that is the first in the initial neural network model among multiple model fragments determined by the base station, and the end fragment is a model fragment that is the last in the initial neural network model among the multiple model fragments determined by the base station; the intermediate fragments are model fragments sent by the base station except the initial fragment and the end fragment; A training module, used to train the intermediate segment according to the local data set to obtain trained model parameters; A signal sending module, used for sending a training end signal to the base station; A device information receiving module, used to receive device information of a next terminal device sent by the base station; The model parameter sending module is used to send the trained model parameters to the next terminal device according to the device information of the next terminal device.
20. An electronic device, characterized in that: It comprises a memory for storing computer program instructions and a processor for executing the program instructions, wherein when the computer program instructions are executed by the processor, the electronic device is triggered to execute the method according to any one of claims 1-13 and 14-17.
21. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method according to any one of claims 1 to 13 and 14 to 17.