# Multi-Level Split Federated Learning for Large-Scale AIoT System Based on Smart Cities
## 3 Proposed Framework
### Multi-Level Federated Learning Workflow  
The cloud server publishes topics through the MQTT protocol to match the edge server to the nearest IoT device group. Then, the edge server publishes topics to receive the tasks performed by the IoT device, information about the local model, and information about the respective resources of the IoT device, including computing resources and storage resources. Based on the IoT device information, the edge server will determine whether the IoT device meets the requirements of collaborative training (whether it is idle and has enough computing resources) and send the training task to the cloud server. Depending on the training task, the cloud server randomly initializes the global model parameters and sends them to the IoT device. Each group of IoT devices receives the cutting layer gradient from the master server and backpropagates the local model to update the parameters of the neural network. The next major step is parameter aggregation in the edge server and cloud server, where we use the FedAvg aggregation algorithm. After the IoT devices in each group update the weights of the local model through the model gradient sent by the master server, they send the model parameters (weights) to the associated edge server. Each edge node is responsible for collecting updated parameters from local IoT devices in its region and using the FedAvg algorithm for weighted averaging to update the weights of the local partial model (initial aggregation). Suppose there are \(E\) edge servers; then, the FedAvg algorithm [35] can be expressed as  
\[W^{e}=\sum_{m=1}^{D}\frac{s_{m}}{s}W_{d}^{e},\ \ e\in E. \tag{6}\]  
There are two situations when model parameters are sent to an edge server. If the edge device is in the middle layer of the hierarchy, the aggregation of model parameters can be expressed as  
\[W^{e_{N-1}}{}_{t+1}=\frac{\sum_{d_{i}\in s_{N-1}}S_{d}W_{t}^{d}}{S_{D}^{e_{N-1 }}},\ \ e\in E, \tag{7}\]  
where \(S_{d}eS_{D}\), \(S_{D}\) denotes the size of the total samples in the IoT device from one group under the \(e_{N-1}\), which is the edge server located in layer \(N-1\). The edge node in the middle layer will forward the aggregated average weight to the upper connected edge node to aggregate again. Similarly, the edge server in level \(N-2\) executes the aggregation algorithm and can be represented as  
\[W^{e_{N-2}t+1}=\frac{\sum_{d_{i}\in e_{N-2}}S_{e_{N-1}}W_{e_{N-1},t}^{d}}{S_{D}^{e _{N-2}}},\ \ e\in E. \tag{8}\]  
If the edge node is at the top of the hierarchy, that is, the cloud server, the weights from the edge nodes of the previous layer are aggregated and weighted and then sent back to the lower level. The cloud server aggregates all the model parameters for each group of IoT devices. The aggregation operation in the server can be expressed as  
\[W^{C}_{t+1}=\frac{\sum_{S_{d}\in S_{e}}S_{e}^{d}W_{e_{2},t}^{d}}{S_{D}^{e_{N-2} }},\ \ e\in E. \tag{9}\]  
The final average weight is sent from the cloud server back to the edge server and client in the same path as the model parameters were previously uploaded, as shown in Figure 2. After receiving the global parameters, each set of IoT devices updates its local model and forwards the cutting layer activation to the master server for forward propagation and loss calculation. The entire multi-level federation learning begins a new iteration until the model converges. Algorithm 2 illustrates the precise algorithm flow of the multi-level SFL framework and shows the algorithm of the multi-level FL part in detail. Figure 2: Multi–level federated learning workflow. ```
1:\(\mathbf{s}\) is the size of total samples; \(t\) is time period; \(E\) is the number of edge servers in each level.