Model training method and device based on federated learning and hierarchical distillation, electronic device and medium
Patent Information
- Application Number
- CN202611409098.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-11
- Publication Date
- 2026-10-20
AI Technical Summary
[0004]本发明实施例的目的是提供一种基于联邦学习与分层蒸馏的模型训练方法、装置、电子设备及介质,能够解决设备数据在聚合过程中相互干扰,聚合得到的全局模型在特定场景下的控制决策精度不足问题
[0009]在本发明实施例中,通过接收各边缘设备上传的模型参数以及表征设备所处场景的环境特征信息,并根据环境特征信息确定各边缘设备模型参数的聚合权重,使场景相近的边缘设备对全局模型的贡献更大,从而避免跨场景数据在聚合过程中相互干扰,提升聚合得到的全局模型在特定场景下的控制决策精度;通过将全局模型作为教师模型进行知识蒸馏得到目标轻量化模型,并在知识蒸馏的损失函数中引入基于智能家居设备被控物理量变化规律的物理一致性约束项,使目标轻量化模型能够适配边缘设备的算力约束,同时保障其输出的控制动作符合物理规律,提升设备控制的安全性与可靠性。
Smart Images

Figure FT_1 
Figure FT_2 
Figure FT_3
Abstract
Description
Technical Field
[0001] This invention belongs to the field of smart home, specifically relating to a model training method, device, electronic device, and medium based on federated learning and hierarchical distillation. Background Technology
[0002] With the development of IoT and AI technologies, an increasing number of edge devices are equipped with intelligent control models to achieve autonomous intelligent control. To improve the decision-making accuracy of individual edge device intelligent control models, existing technologies employ a federated learning framework, uploading model parameters from multiple edge devices to a server for aggregation, resulting in a global model that integrates knowledge from multiple devices.
[0003] However, in multi-device collaborative training scenarios, the application scenarios of different edge devices vary significantly, and the data collected by each edge device exhibits non-independent and identically distributed characteristics. Existing federated learning frameworks typically aggregate the model parameters of each edge device using a simple averaging method, without considering the differences in the scenarios in which each edge device operates. This leads to mutual interference between device data during the aggregation process, resulting in insufficient control decision accuracy of the aggregated global model in specific scenarios. Summary of the Invention
[0004] The purpose of this invention is to provide a model training method, apparatus, electronic device, and medium based on federated learning and hierarchical distillation, which can solve the problem of mutual interference between device data during the aggregation process and insufficient control decision accuracy of the global model obtained by aggregation in specific scenarios.
[0005] To solve the above-mentioned technical problems, the present invention is implemented as follows: In a first aspect, embodiments of the present invention provide a model training method based on federated learning and hierarchical distillation, applied to a collaborative training system including at least one edge device and a federated coordination node, wherein a corresponding local model is deployed on the at least one edge device, and the method includes: The system receives model parameters and environmental feature information of the local model corresponding to each of the at least one edge device, wherein the environmental feature information is used to characterize the scene in which the edge device is located. The aggregation weights of the model parameters of the local model corresponding to each edge device are determined based on the environmental feature information. The model parameters of the local model corresponding to the at least one edge device are weighted and aggregated according to the aggregation weight to obtain the global model; The global model is used as a teacher model for knowledge distillation to obtain the target lightweight model. The loss function used in the knowledge distillation includes a physical consistency constraint term, which is constructed based on the variation law of the controlled physical quantity of the smart home device and is used to constrain the control actions output by the target lightweight model to not violate the variation law.
[0006] Secondly, embodiments of the present invention provide a model training apparatus based on federated learning and hierarchical distillation, applied to a collaborative training system including at least one edge device and a federated coordination node, wherein the at least one edge device is equipped with a corresponding local model, including: The parameter receiving module is used to receive model parameters and environmental feature information of the local model corresponding to each of the at least one edge device, wherein the environmental feature information is used to characterize the scene in which the edge device is located. The aggregation weight determination module is used to determine the aggregation weight of the model parameters of the local model corresponding to each edge device based on the environmental feature information. A global model determination module is used to perform weighted aggregation of the model parameters of the local models corresponding to the at least one edge device according to the aggregation weight to obtain a global model; The parameter receiving module is used to perform knowledge distillation on the global model as a teacher model to obtain the target lightweight model. The loss function used in the knowledge distillation includes a physical consistency constraint term. The physical consistency constraint term is constructed based on the change law of the controlled physical quantity of the smart home device and is used to constrain the control action output by the target lightweight model to not violate the change law.
[0007] Thirdly, embodiments of the present invention provide an electronic device including a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the method described in the first aspect.
[0008] Fourthly, embodiments of the present invention provide a readable storage medium on which a program or instructions are stored, which, when executed by a processor, implement the steps of the method described in the first aspect.
[0009] In this embodiment of the invention, by receiving model parameters uploaded by each edge device and environmental feature information representing the scene in which the device is located, and determining the aggregation weight of the model parameters of each edge device based on the environmental feature information, the edge devices with similar scenes contribute more to the global model, thereby avoiding mutual interference between cross-scene data during the aggregation process and improving the control decision accuracy of the global model obtained by aggregation in specific scenarios. By using the global model as a teacher model for knowledge distillation to obtain a target lightweight model, and introducing a physical consistency constraint term based on the change law of the controlled physical quantity of smart home devices into the loss function of knowledge distillation, the target lightweight model can adapt to the computing power constraints of edge devices, while ensuring that its output control actions conform to physical laws, thereby improving the safety and reliability of device control.
[0010] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0011] Figure 1 This is a flowchart illustrating the steps of an embodiment of a model training method based on federated learning and hierarchical distillation according to the present invention. Figure 2 This is a flowchart illustrating the steps of another embodiment of the model training method based on federated learning and hierarchical distillation of the present invention. Figure 3 This is a structural block diagram of an embodiment of a model training device based on federated learning and hierarchical distillation according to the present invention. Detailed Implementation
[0012] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0013] The terms "first," "second," etc., used in the specification and claims of this invention are used to distinguish similar objects and are not used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of the invention can be implemented in orders other than those illustrated or described herein. Furthermore, in the specification and claims, "and / or" indicates at least one of the connected objects, and the character " / " generally indicates that the preceding and following objects are in an "or" relationship.
[0014] The following description, in conjunction with the accompanying drawings, details the model training method, apparatus, equipment, and medium based on federated learning and hierarchical distillation provided by the embodiments of the present invention through specific examples and application scenarios.
[0015] Reference Figure 1 The diagram illustrates a step flowchart of an embodiment of a model training method based on federated learning and hierarchical distillation according to the present invention, which may specifically include the following steps: The implementation entity of this solution is the server-side of the collaborative training system. This server-side can take various forms, including but not limited to federated coordination nodes, cloud servers, edge computing gateways, and local central control hosts. The disclosure document uses a federated coordination node as one specific implementation method for the server-side. The application scenarios for this solution are multi-device collaborative model training scenarios, including but not limited to collaborative control of smart home devices, cluster management and control of industrial IoT devices, and energy management of commercial building equipment. The disclosure document uses a smart home scenario as one specific application scenario.
[0016] This invention operates within a collaborative training system comprising at least one edge device and a server. The edge device is a terminal device deployed at the application site, possessing data acquisition and local computing capabilities. In a smart home scenario, the edge device refers to smart home devices, including but not limited to smart air conditioners, smart refrigerators, fresh air systems, and smart lighting. The server is a computing node responsible for coordinating the collaborative training of multiple edge devices. The server connects to each edge device via an encrypted network, receiving only model parameters and environmental feature information, and not any raw user data. The local model is a neural network model deployed on each edge device, used to output device control decisions. The local models on different edge devices have different model parameters due to differences in their environment and user habits.
[0017] Step 101: Receive model parameters and environmental feature information of the local model corresponding to each of the at least one edge device, wherein the environmental feature information is used to characterize the scene in which the edge device is located.
[0018] The server receives two types of data uploaded by each edge device via an encrypted communication link: model parameters of the local model and environmental feature information. The model parameters are the network weight parameters updated after local training of the local model on each edge device. These model parameters are encrypted by the edge device before uploading, and the uploaded content only includes the updated model weights, excluding the original user data collected by the edge device (such as voice recordings and video footage), thus ensuring user privacy and security at the data transmission level. The environmental feature information is lightweight feature data used to characterize the scene in which the edge device is located. This environmental feature information reflects the objective attributes of the environment in which each edge device is located. In a smart home scenario, this includes, but is not limited to, the climate zone of the geographical location, the type of residential building, the baseline of historical energy consumption of the household, and the labels of the main family members. The data dimension of the environmental feature information is lower than that of the model parameters and is only used to determine the subsequent aggregation weights, without involving user privacy. After receiving the above two types of data, the server associates and stores the model parameters of each edge device with the corresponding environmental feature information, preparing for subsequent weighted aggregation processing. In one implementation, the server is a federated coordination node, and the encrypted communication link is an encrypted connection based on a transport layer security protocol.
[0019] Step 102: Determine the aggregate weight of the model parameters of the local model corresponding to each edge device based on the environmental feature information.
[0020] The server assigns aggregation weights to the model parameters of each edge device based on the environmental feature information uploaded by each edge device. Since the data distribution of different edge devices varies significantly in multi-device collaborative training scenarios—for example, the operating logic of air conditioners differs between humid southern regions and dry northern regions in smart home scenarios, and the work and rest patterns differ between elderly households and households with young children—simple average aggregation of the model parameters of all edge devices would lead to cross-scenario data interference and a decrease in the performance of the aggregated global model. Therefore, this step measures the differences in the scenarios in which each edge device is located using environmental feature information, assigning higher aggregation weights to edge devices with similar scenario characteristics and lower aggregation weights to edge devices with significantly different scenario characteristics. This enables the aggregation process to have scenario awareness and avoids cross-scenario data interference. The aggregation weight is the proportion of each edge device's model parameters in the subsequent weighted aggregation process. The aggregation weight is a non-negative value, and the sum of the aggregation weights of all edge devices is normalized to 1. Each edge device corresponds to one aggregation weight value.
[0021] Step 103: Perform weighted aggregation of the model parameters of the local model corresponding to the at least one edge device according to the aggregation weight to obtain the global model.
[0022] The server, according to the aggregation weights determined in step 102, performs a weighted summation of the model parameters uploaded by each edge device to obtain a global model. Weighted aggregation is a process of multiplying the model parameters of each edge device by their corresponding aggregation weights and then summing the results. This weighted aggregation is implemented based on a federated learning parameter aggregation mechanism. By weighted fusion of multi-device model parameters on the server side, common control knowledge scattered across various edge devices is aggregated into a unified global model. The global model is a neural network model obtained by the server through weighted aggregation, incorporating common control decision knowledge from multiple edge devices. This global model possesses cross-scenario general device control capabilities, but its model parameters are large and computationally complex, making it unsuitable for direct deployment on edge devices with limited computing power. Subsequent knowledge distillation is required for model compression. In one implementation, the weighted aggregation is based on a federated averaging algorithm.
[0023] Step 104: Use the global model as the teacher model to perform knowledge distillation to obtain the target lightweight model; the loss function used in the knowledge distillation includes a physical consistency constraint term, which is constructed based on the change law of the controlled physical quantity of the smart home device, and is used to constrain the control action output by the target lightweight model to not violate the change law.
[0024] The server uses the global model obtained in step 103 as the teacher model. Through knowledge distillation, the control and decision-making capabilities of the teacher model are transferred to a smaller student model, resulting in the target lightweight model. Knowledge distillation is a model compression technique. Its core idea is to allow the student model to learn the probability distribution (soft labels) output by the teacher model, rather than just learning discrete real labels (hard labels), thereby transferring the implicit knowledge contained in the teacher model to the student model. The teacher model is the large model that provides knowledge during the knowledge distillation process, which is the global model in this step. The student model is a small model that learns the knowledge of the teacher model during the knowledge distillation process. The number of network layers, parameters, and computational cost of the student model are much smaller than those of the teacher model, which can adapt to the computing power constraints of embedded AI chips on edge devices. The target lightweight model is the student model obtained through knowledge distillation, which has control and decision-making capabilities similar to the global model and whose model size is adapted to the computing power of edge devices.
[0025] During the knowledge distillation training process, the loss function used includes a physical consistency constraint term. This physical consistency constraint term is a regularization constraint term constructed based on the changing patterns of the controlled physical quantities of smart home devices. These controlled physical quantities are those targeted by the smart home device control, including but not limited to indoor temperature, indoor humidity, and indoor air quality. The changing patterns refer to the physical change patterns followed by the controlled physical quantities under the constraints of the device's actuator output capability and environmental conditions. For example, the rate of change of indoor temperature is constrained by the air conditioner compressor's output power and environmental heat exchange conditions. The physical consistency constraint term is used to constrain the control actions output by the target lightweight model during distillation training, ensuring that the control actions do not violate the changing patterns of the controlled physical quantities. This prevents the target lightweight model from outputting control commands that violate common sense, such as instantaneous large-scale cooling commands exceeding the air conditioner compressor's power limit, thus ensuring the physical feasibility of the model's output. The target lightweight model trained through knowledge distillation can then be deployed to various edge devices to replace the original local model in executing device control decisions.
[0026] By receiving model parameters uploaded from each edge device and environmental feature information representing the scene in which the device is located, and determining the aggregation weight of the model parameters of each edge device based on the environmental feature information, edge devices with similar scenes contribute more to the global model, thereby avoiding mutual interference between cross-scene data during the aggregation process and improving the control decision accuracy of the global model obtained by aggregation in specific scenarios. By using the global model as a teacher model for knowledge distillation to obtain a target lightweight model, and introducing a physical consistency constraint term based on the change law of the controlled physical quantity of smart home devices into the loss function of knowledge distillation, the target lightweight model can adapt to the computing power constraints of edge devices, while ensuring that its output control actions conform to physical laws, thereby improving the safety and reliability of device control.
[0027] Reference Figure 2 The flowchart illustrates another embodiment of the model training method based on federated learning and hierarchical distillation of the present invention, which may specifically include the following steps: Step 201: Receive model parameters and environmental feature information of the local model corresponding to each of the at least one edge device, wherein the environmental feature information is used to characterize the scene in which the edge device is located.
[0028] This step corresponds to step 101 above. The server receives the local model parameters and environmental feature information uploaded by each edge device through an encrypted communication link and completes the association and storage of the two. This will not be explained in detail here.
[0029] Step 202: Match the environmental feature information of each edge device with at least one preset scene type to obtain the matching degree between each edge device and the at least one scene type.
[0030] In this step, the server compares the environmental feature information uploaded by each edge device with the pre-maintained scene types and outputs the matching degree of each edge device relative to each scene type. The scenario type is a set of scenario labels pre-defined by the server to classify the environment in which edge devices are located. Scenario types are divided from multiple dimensions based on objective environmental attributes, including climate zone (e.g., subtropical humid climate, temperate dry climate), building structure (e.g., high-rise apartments, detached villas, bungalows), family composition (e.g., elderly families, families with children, young adults living alone), and energy consumption level (e.g., high-energy-consuming families, low-energy-consuming families). Each scenario type corresponds to a set of feature representation vectors to characterize the typical environmental features of that scenario type. Matching is the process of comparing the environmental feature information of the edge device with the feature representation of the scenario type. Matching is achieved by calculating the similarity between the two in the feature space. The matching degree is a quantitative result of the similarity between the environment in which the edge device is located and a certain scenario type. The matching degree value is between 0 and 1; the closer to 1, the more closely the environmental features of the edge device match the scenario type; the closer to 0, the greater the difference. Each edge device corresponds to a set of matching degree values, reflecting its similarity to each scenario type.
[0031] Step 203: Determine the aggregate weight of the model parameters of the local model corresponding to each edge device based on the matching degree.
[0032] After scene matching is completed, the server assigns aggregate weights to the model parameters of each edge device based on the matching degree output in step 202. This assignment follows a positive correlation rule: the higher the matching degree between the edge device and the current target scene type, the greater the aggregate weight assigned to its model parameters; the lower the matching degree, the smaller the aggregate weight. Here, the target scene type refers to the scene type corresponding to the global model currently being optimized by the server. In an optional implementation, the server can simultaneously maintain global models corresponding to multiple scene types, and the aggregate weight of each global model is determined based on the matching degree between each edge device and that scene type. Through this allocation method, edge devices highly similar to the target scene contribute more significantly to the global model of that scene, while the contributions of edge devices with significantly different scenes are correspondingly reduced, thereby suppressing cross-scene data interference and improving the control decision accuracy of the global model in specific scenes.
[0033] Step 204: Perform weighted aggregation of the model parameters of the local model corresponding to the at least one edge device according to the aggregation weight to obtain the global model.
[0034] After the aggregation weights are determined, the server performs a weighted summation of the model parameters for each edge device to obtain a global model that integrates common control knowledge from multiple devices. This step is consistent with the processing method in step 103 above, and will not be repeated here.
[0035] Step 205: Use the global model as the teacher model to perform knowledge distillation to obtain the target lightweight model; the loss function used in the knowledge distillation includes a physical consistency constraint term, which is constructed based on the change law of the controlled physical quantity of the smart home device, and is used to constrain the control actions output by the target lightweight model to not violate the change law.
[0036] This step is consistent with the previous step 104. The server uses the global model as the teacher model to perform knowledge distillation to obtain the target lightweight model, and introduces a physical consistency constraint term based on the change law of the controlled physical quantity of smart home devices into the distillation loss function. This will not be elaborated here.
[0037] In one embodiment, step 202 may include the following sub-steps: Sub-step S11: Determine the similarity between the environmental feature information of each edge device and the feature representation of at least one scene type; Among them, the feature representation is the feature vector corresponding to the scene type. The feature vector is composed of typical environmental feature statistics under the scene type, including climate zone coding, building type coding, average energy consumption baseline, typical user group labels and other dimensions. Each scene type corresponds to a feature representation vector with a fixed dimension. Similarity is a quantitative measure of the degree of similarity between environmental feature information and feature representation in the feature space. The similarity value is between 0 and 1. The larger the value, the more similar the two are.
[0038] The similarity calculation can employ either cosine similarity or a Gaussian kernel function. Cosine similarity calculates the similarity by taking the cosine of the angle between the environmental feature information vector and the feature representation vector. Cosine similarity is insensitive to the absolute magnitude of the vectors and is suitable for measuring the directional consistency of environmental features. The Gaussian kernel function calculates the similarity by substituting the Euclidean distance between the environmental feature information vector and the feature representation vector into a Gaussian kernel function. The Gaussian kernel function is more sensitive to the numerical closeness of the vectors and is suitable for matching continuous numerical features such as energy consumption baselines. In practical applications, the appropriate similarity calculation method can be selected based on the data type of the environmental feature information, or multiple methods can be combined.
[0039] Step 203 may include the following sub-steps: Sub-step S21 determines the aggregation weight based on the exponential function of the similarity.
[0040] The exponential function is a function with a base of the natural constant and an exponent of the product of similarity and a preset coefficient. The preset coefficient is a positive hyperparameter used to control the influence of similarity on the aggregation weight. The larger the preset coefficient, the more significant the weight difference caused by the similarity difference. The aggregation weight has a positive exponential relationship with similarity, that is, the higher the similarity of the edge device, the greater its aggregation weight, thus making the edge device that is highly similar to the current scene type contribute more to the global model.
[0041] After obtaining the initial weight values of each edge device, the server normalizes all the initial weight values of all edge devices so that the sum of the normalized aggregate weights is 1, for subsequent weighted aggregation calculations. This normalization process is achieved by dividing the initial weight value of each edge device by the sum of the initial weight values of all edge devices.
[0042] In one exemplary embodiment, the server can pre-maintain three scenario types: "apartment type in humid southern regions", "villa type in dry northern regions" and "high-energy-consuming commercial building type". Each scenario type corresponds to a four-dimensional feature representation vector, with the dimensions being climate zone code, building type code, historical energy consumption baseline, and typical user group label, respectively.
[0043] An edge device uploads an environmental feature vector as [subtropical humid climate, high-rise apartment, medium energy consumption, young couple]. The server calculates the cosine similarity between this environmental feature vector and the feature representation vectors of three scene types: 0.92 with "apartment type in humid southern region", 0.35 with "villa type in dry northern region", and 0.18 with "commercial building type with high energy consumption".
[0044] The server is currently optimizing the global model for the "apartment type in humid southern regions" scenario. Therefore, the initial weight is calculated by substituting the similarity of this scenario type (0.92) into the exponential function, with a preset coefficient of 2.0. The initial weight is then exp(2.0×0.92)≈6.19. Similarly, the other edge devices participating in this aggregation round calculate their own initial weights. Assuming there are five edge devices, their initial weights are 6.19, 5.51, 1.92, 1.41, and 1.10, respectively. After summing and normalizing, the aggregation weights of each edge device are approximately 0.382, 0.340, 0.118, 0.087, and 0.068, respectively.
[0045] Therefore, the edge device with the highest similarity to the "apartment type in humid southern region" scenario received the largest aggregation weight of 0.382, making the most significant contribution to the global model of this scenario; while the edge devices with larger scenario differences had correspondingly lower weights, and the influence of their model parameters on the global model of this scenario was suppressed, thereby avoiding cross-scenario data interference and improving the control decision accuracy of the global model in the apartment scenario in humid southern region.
[0046] In one embodiment, step 204 may include the following sub-steps: Sub-step S31: Determine the gradient norm of the model parameters uploaded by each edge device.
[0047] The gradient norm is calculated for the model parameters uploaded by each edge device. The gradient of the model parameters refers to the update amount of the network weights after the local model is trained locally on the edge device; the gradient reflects the direction and magnitude of parameter changes in the local model during this training round. The gradient norm is a measure of the overall size of the gradient vector, obtained by calculating the L2 norm of the gradient vector (i.e., the square root of the sum of the squares of the elements of the gradient vector). The gradient norm is a non-negative scalar; a larger value indicates a larger parameter update magnitude for the local model on that edge device. The server calculates the gradient norm for all edge devices participating in this aggregation round, forming a gradient norm set.
[0048] Sub-step S32: Determine the median threshold, which is the product of the median of the gradient norm of the model parameters uploaded by each edge device and a preset multiple.
[0049] The median threshold is calculated based on the gradient norm set obtained in sub-step S31. The median is the value in the middle after sorting the gradient norm set by numerical value. The median is robust to extreme values and reflects the normal level of parameter update amplitude for each edge device in this round. A preset multiple is a positive real number greater than 1, used to set the leniency of anomaly detection. A larger preset multiple indicates a more lenient anomaly detection standard and fewer devices are identified as anomalous; a smaller preset multiple indicates a more stringent standard and more devices are identified as anomalous. The median threshold is obtained by multiplying the median by the preset multiple, and this median threshold serves as the baseline for determining whether an edge device is anomalous.
[0050] In sub-step S33, if the gradient norm is greater than the median threshold, the edge device corresponding to the gradient norm is determined to be an abnormal device, and the abnormal device is removed.
[0051] The gradient norm of each edge device is compared one by one with the median threshold determined in sub-step S32. If the gradient norm of an edge device is greater than the median threshold, it indicates that the parameter update magnitude of the device significantly exceeds the normal level of this round. The server determines that the edge device is an abnormal device and removes it from the subsequent weighted aggregation. The causes of abnormal devices include, but are not limited to, malicious poisoning attacks (attackers destroy the global model by uploading abnormal gradients), device hardware failure (sensor or computing unit malfunctions leading to distorted training results), and abnormal local data acquisition (data noise or labeling errors leading to abnormal gradients). Through the above-mentioned anomaly detection and removal mechanism, the pollution of the global model by abnormal gradients can be effectively prevented, ensuring the stability and reliability of the weighted aggregation results.
[0052] Sub-step S34: Based on the aggregation weight, perform weighted aggregation on the model parameters of the remaining edge devices after removing abnormal devices to obtain the global model.
[0053] First, the server renormalizes the aggregate weights of the remaining edge devices, ensuring that the sum of the aggregate weights of the remaining devices is 1. Then, the model parameters of each remaining edge device are multiplied by the renormalized aggregate weights and summed to obtain a global model that integrates common control knowledge from multiple devices. This renormalization process compensates for the missing weight sum caused by the removal of abnormal devices, ensuring the mathematical validity of the weighted aggregation.
[0054] For example, the model parameters uploaded by five edge devices are processed by the server to calculate the gradient norm, resulting in a gradient norm set of {0.8, 1.2, 0.9, 1.1, 8.5}, where the unit is the L2 norm of the parameter update. The server then sorts this set in ascending order as {0.8, 0.9, 1.1, 1.2, 8.5} and takes the median as 1.1. With a preset multiplier of 3, the median threshold is 1.1 × 3 = 3.3.
[0055] The server compared the gradient norm of each edge device with the median threshold of 3.3. The gradient norms of the first four devices were 0.8, 1.2, 0.9, and 1.1, respectively, all less than 3.3, and were therefore considered normal devices. The gradient norm of the fifth device was 8.5, greater than 3.3, and was therefore identified as an abnormal device and removed. The gradient norm of this abnormal device was significantly higher than that of the other devices, which may be due to abnormal local data collection or malicious poisoning attacks.
[0056] After removing the abnormal device, the original aggregate weights of the remaining four devices are 0.30, 0.25, 0.20, and 0.25, respectively, summing to 1.0. Since the original weight of the removed abnormal device was 0 (this device had not been assigned an effective weight before anomaly detection, or its weight had been reset to zero after anomaly determination), the weights of the remaining four devices remain normalized. The server multiplies the model parameters of the four devices by their corresponding aggregate weights and then sums them to obtain the global model. This global model is not contaminated by the gradient of the fifth abnormal device, and the parameter update magnitude is within the normal range.
[0057] In one embodiment, step 205 may include the following sub-steps: Sub-step S41: The global model is used as the teacher model for first-level knowledge distillation to obtain an intermediate model; In this sub-step, the server uses the global model obtained in step 204 as the teacher model to perform the first-level knowledge distillation, outputting an intermediate model. The first-level knowledge distillation is the process of transferring the general control knowledge of the global model to a smaller intermediate model. The intermediate model has fewer parameters than the global model but more than the final target lightweight model. The main function of the first-level distillation is to remove redundant knowledge from the global model that is irrelevant to device control decisions, retaining the general control knowledge adapted to the target application scenario. During the distillation process, the intermediate model acts as a student model, learning the probability distribution (soft labels) output by the global model. Knowledge transfer is achieved by minimizing the difference between the student model's and the teacher model's output distributions. The distillation temperature parameter controls the smoothness of the soft labels; a higher distillation temperature results in a smoother distribution of soft labels and richer hidden knowledge information.
[0058] In sub-step S42, the intermediate model is used as the teacher model for second-level knowledge distillation to obtain the target lightweight model; the loss function used in the knowledge distillation also includes an attention constraint term, which is used to preferentially retain knowledge related to device control decisions.
[0059] In this sub-step, the server uses the intermediate model obtained in sub-step S41 as the teacher model, performs second-level knowledge distillation, and outputs the target lightweight model. The second-level knowledge distillation is the process of further transferring the control knowledge of the intermediate model to the smaller target lightweight model. The number of parameters and computational cost of the target lightweight model are adapted to the computing power constraints of the embedded AI chip in the edge device. The second-level distillation can combine compression techniques such as model quantization, weight pruning, and sparsification to compress the intermediate model into a lightweight model adapted to the computing power level of the target edge device. Model quantization converts model parameters from high-precision floating-point representation to low-precision integer representation (e.g., 8-bit integers) to reduce storage usage and computational overhead; weight pruning removes redundant weights with small absolute values from the model to reduce the number of model parameters; sparsification makes a large number of elements in the model weight matrix zero to accelerate inference using sparse computation.
[0060] The loss function used in the second-level knowledge distillation includes not only the conventional supervised learning loss term and knowledge distillation loss term, but also an attention constraint term. This attention constraint term is a regularization term that penalizes the difference between the attention feature maps of the teacher and student models. These attention feature maps reflect the degree of attention the model pays to different regions of the input features during inference. By minimizing the difference between the attention feature maps of the student and teacher models, the attention constraint term ensures that the student model's attention distribution aligns with the teacher model's in key control decision regions, thus prioritizing the retention of knowledge related to device control decisions. In smart home scenarios, this knowledge related to device control decisions includes core control knowledge such as temperature control strategies, fan speed adjustment logic, and device timing linkage rules. The attention constraint term ensures that this core knowledge is not lost during model compression, guaranteeing the actual control effect of the target lightweight model.
[0061] For example, the global model is a large neural network model that integrates common control knowledge from multiple smart home edge devices. It has approximately 500 million parameters and contains 24 Transformer coding layers. It can process multimodal inputs and output complex device control decisions, but it cannot be directly deployed on the embedded chips of edge devices.
[0062] The first-level knowledge distillation is performed on the server side, using the global model as the teacher model and an intermediate model with approximately 100 million parameters as the student model. The distillation temperature is set to 5.0 to ensure a relatively flat distribution of soft labels output by the teacher model, carrying rich dark knowledge information. The intermediate model learns the output probability distribution of the global model, eliminating redundant knowledge unrelated to smart home device control (such as general natural language understanding, image classification, and other non-control knowledge), while retaining general control knowledge adapted to smart home scenarios (such as environmental perception, user intent recognition, and device linkage logic). After the first-level distillation, the intermediate model is obtained with approximately 100 million parameters and contains 12 coding layers.
[0063] The second-level knowledge distillation involves using an intermediate model as the teacher model on the server side and a target lightweight model with approximately 5 million parameters as the student model. During the distillation process, 8-bit integer quantization and weight pruning are combined to convert the floating-point parameters of the intermediate model into 8-bit integer representations and prune redundant weights with small absolute values. The final result is a target lightweight model adapted to the computing power of embedded AI chips in edge devices, with approximately 5 million parameters, containing four coding layers, and inference latency meeting the real-time control requirements of the device.
[0064] The loss function of the second-stage distillation includes a cross-entropy loss term, a knowledge distillation loss term, and an attention constraint term. The attention constraint term calculates the difference in attention feature maps between the intermediate model and the target lightweight model in key control decision areas such as temperature regulation, wind speed adjustment, and time-series linkage, and incorporates this difference into the loss function to penalize it, ensuring that the attention distribution of the target lightweight model is consistent with that of the intermediate model in the core control areas. After training, the target lightweight model maintains a difference of less than 5% compared to the intermediate model in core control indicators such as temperature regulation accuracy, wind speed adjustment response speed, and equipment linkage accuracy, while its model parameters are only 5% of those of the intermediate model, enabling efficient deployment on edge devices for real-time intelligent control.
[0065] In one embodiment, the loss function used in the knowledge distillation includes a cross-entropy loss term, a knowledge distillation loss term, and the physical consistency constraint term; the physical consistency constraint term is constructed based on the squared deviation between the predicted rate of change of the controlled physical quantity under the control action and the physical limit rate of change of the controlled physical quantity, the physical limit rate of change being determined by the actuator parameters of the device and environmental parameters, the actuator parameters including the output power of the device actuator, and the environmental parameters including the environmental thermal resistance and the environmental temperature.
[0066] The loss function is a weighted sum of three terms: cross-entropy loss, knowledge distillation loss, and physical consistency constraint. These three terms constrain the training process of the student model from different dimensions. Specifically, the cross-entropy loss is the cross-entropy between the student model's predicted output and the true control label, used to constrain the student model to learn the correct control decision mapping. This cross-entropy loss measures the difference between the student model's output probability distribution and the true label distribution. The knowledge distillation loss is the KL divergence between the student model's output and the teacher model's output, used to constrain the student model to learn the teacher model's soft label knowledge. This KL divergence measures the asymmetric difference between the two probability distributions, enabling the student model to inherit the implicit knowledge contained in the teacher model. The physical consistency constraint is a regularization term constructed based on the changing laws of the controlled physical quantity, used to constrain the student model's output control actions to not violate physical laws. The three terms are multiplied by their respective weight coefficients and then summed to obtain the final value of the loss function. During training, the student model is optimized by minimizing this loss function.
[0067] The physical consistency constraint is constructed based on the squared deviation between the predicted rate of change of the controlled physical quantity under control actions and the physical limit rate of change of the controlled physical quantity. The controlled physical quantity is the physical quantity targeted by the device control, and in smart home scenarios, it includes, but is not limited to, indoor temperature, indoor humidity, and indoor air quality. The predicted rate of change is the predicted value of the rate of change of the controlled physical quantity caused by the control actions output by the student model, which is inferred by the student model based on the current environmental state and the output control actions. The physical limit rate of change is the maximum rate of change that the controlled physical quantity can achieve under the constraints of the device's actuator output capability and environmental conditions. The physical limit rate of change reflects the physical upper limit of the change of the controlled physical quantity; no control action can cause the rate of change of the controlled physical quantity to exceed this upper limit.
[0068] The physical limit rate of change is determined by both the actuator parameters and environmental parameters of the equipment. Actuator parameters are the performance parameters of the mechanism that performs the control actions. These parameters include the output power of the actuator, which determines its ability to regulate the controlled physical quantity; a higher output power results in a larger absolute value of the physical limit rate of change. Environmental parameters are the external environmental conditions that affect the change of the controlled physical quantity. These parameters include environmental thermal resistance and environmental temperature. Environmental thermal resistance reflects the resistance to heat exchange between the controlled space and the external environment; a higher thermal resistance results in a smaller influence of the external environment on the controlled physical quantity. Environmental temperature includes the internal temperature of the controlled space and the external environmental temperature; the temperature difference between the two determines the direction and rate of heat exchange. The physical limit rate of change is calculated by substituting the actuator parameters and environmental parameters into the fundamental law formula of the physical domain to which the controlled physical quantity belongs.
[0069] The squared deviation is obtained by taking the square of the difference between the predicted rate of change and the physical limit rate of change. The squared deviation is a non-negative value. When the predicted rate of change is within the range of the physical limit rate of change, the squared deviation is small. When the predicted rate of change exceeds the range of the physical limit rate of change, the squared deviation increases significantly, thereby penalizing control actions that violate physical laws in the loss function.
[0070] For example, the following explanation uses knowledge distillation of an air conditioner temperature control model in a smart home scenario.
[0071] The controlled physical quantity is indoor temperature, the student model is a target lightweight model, and the teacher model is a global model. The loss function consists of three terms.
[0072] The first term is the cross-entropy loss term: the cross-entropy between the probability distribution of temperature adjustment actions output by the student model and the true label. Assuming the probability of the cooling action output by the student model is 0.85, and the true label is cooling, then the cross-entropy loss term is -log(0.85)≈0.163.
[0073] The second term is the knowledge distillation loss term: the KL divergence between the student model output and the teacher model output. The distillation temperature is set to 5.0. The soft label distribution of the teacher model output is [cooling 0.72, heating 0.10, dehumidification 0.12, ventilation 0.06], and the soft label distribution of the student model output is [cooling 0.68, heating 0.12, dehumidification 0.14, ventilation 0.06]. The calculated KL divergence is approximately 0.003. Multiplying this by the weighting coefficient λ1 = 0.5, the knowledge distillation loss term is approximately 0.0015.
[0074] The third term is the physical consistency constraint: it is constructed based on the squared deviation between the predicted rate of change of indoor temperature and the physical limit rate of change.
[0075] The current environmental conditions are: indoor temperature T_in=30°C, outdoor temperature T_out=35°C, environmental thermal resistance R=0.5°C / W, house heat capacity C_house=20000J / ℃, and air conditioner compressor output power P_action=2000W.
[0076] Based on the thermodynamic thermal equilibrium relationship, the physical limit rate of change of indoor temperature is calculated as follows: dT_phys / dt=(P_action-(T_out-T_in) / R) / C_house=(2000-(35-30) / 0.5) / 20000=(2000-10) / 20000≈0.0995°C / s That is, under the current environmental conditions, the fastest rate at which the indoor temperature drops is approximately 0.0995°C / s.
[0077] Suppose the student model outputs an extreme cooling control action, predicting an indoor temperature change rate of dT_pred / dt = 0.5°C / s, which significantly exceeds the physical limit of 0.0995°C / s. Then the squared deviation of the physical consistency constraint term is: L_phy=(dT_pred / dt-dT_phys / dt)²=(0.5-0.0995)²≈0.1604 After multiplying by the weighting coefficient λ2=1.0, the physical consistency constraint term is 0.1604.
[0078] The total loss function is: L_total=L_CE+λ1 L_KD+λ2 L_phy=0.163+0.5×0.003+1.0×0.1604≈0.3249 During training, the total loss function is minimized through backpropagation. The gradient of the physical consistency constraint term forces the student model to adjust its output, bringing the predicted rate of temperature change closer to the physical limit rate of change, thereby avoiding the output of control commands that violate physical principles. After multiple rounds of training, the temperature change rate output by the student model is consistently constrained within the range of the physical limit rate of change.
[0079] In one embodiment, the local model is continuously learned and updated in the following manner: New multimodal data is collected through the edge device, including user interaction data, environmental perception data, and device operating status data; historical multimodal data is obtained from the edge device; the offset value between the new multimodal data and the historical multimodal data is determined; a regularization strength value for incremental model training is determined based on the offset value; and incremental training of the local model is performed based on the new multimodal data and the regularization strength value.
[0080] First, the multimodal data includes three categories: user interaction data, environmental perception data, and device operating status data. User interaction data includes user voice control commands, manual adjustment operations, and voice correction commands, reflecting user preferences and operating habits. Environmental perception data includes indoor temperature, humidity, air quality, and human presence status, reflecting the environmental conditions in which the device operates. Device operating status data includes device operating power, operating mode, start / stop status, and set parameters, reflecting the actual operating status of the device. These three types of data characterize the user-device interaction process and environmental status from different dimensions, providing a data foundation for incremental training of the local model.
[0081] Next, the historical multimodal data is a collection of data collected and stored by the edge device during its past operation. This historical multimodal data reflects the user's long-term usage habits and the device's historical operating patterns. The historical multimodal data is stored in the edge device's local non-volatile storage medium and is not transmitted externally, thereby ensuring user privacy and security.
[0082] Furthermore, the offset value is used to quantify the degree of change in user habits or environmental conditions relative to historical states. The offset value is obtained by comparing the difference between the distribution of new data and the distribution of historical data. The difference in distribution is calculated using a probability distribution distance metric. A larger offset value indicates a more significant change in user habits or environmental conditions, while a smaller offset value indicates that the data distribution tends to be stable.
[0083] Next, the regularization strength value is determined. This value is a parameter used during incremental training to protect existing knowledge. A higher regularization strength value indicates that the model is more likely to retain existing knowledge and less likely to forget historical decision logic during incremental training. Conversely, a lower regularization strength value indicates that the model is more adaptable to new data and can quickly learn new usage habits. There is a negative correlation between the offset value and the regularization strength value: when the offset value exceeds a preset threshold, it indicates a significant change in user habits or the environment, and the regularization strength value is reduced to allow the model to quickly adapt to the new data distribution; when the offset value is below the preset threshold, the regularization strength value is increased to protect existing knowledge and prevent the model from forgetting historical decision logic.
[0084] For example, the following explanation uses the local model of a smart air conditioner in a smart home scenario as an example of continuous learning.
[0085] This smart air conditioner is equipped with an embedded artificial intelligence chip, which collects three types of multimodal data in real time during daily operation. User interaction data includes: the user sets sleep mode at 22:00 every day, the temperature is set to 26℃, and the fan speed is low; environmental perception data includes: indoor temperature 28℃, humidity 65%, and the presence of a person in the bedroom; device operating status data includes: compressor power 1200W, operating mode is cooling, and the air outlet temperature is 16℃. The above data constitutes the newly added multimodal data, with temperature and humidity collected periodically at a sampling rate of 1Hz, and control logs collected according to event triggering.
[0086] Retrieve historical multimodal data from the local storage area for the past 30 days. Historical data shows that the user's long-term habits are: setting sleep mode at 23:00 daily, temperature at 27℃, and wind speed at moderate. The distribution of historical data reflects the user's past sleep patterns and temperature preferences.
[0087] Calculate the offset between the distribution of newly added data and the distribution of historical data. By comparing the distribution differences between the recent 7 days of data and the historical 30 days of data, the offset value is calculated using a distribution distance metric, resulting in a value of 0.62 (range 0 to 1, threshold set at 0.5). An offset value of 0.62 exceeds the threshold of 0.5, indicating a significant change in user habits (earlier sleep time, lower set temperature, reduced fan speed).
[0088] Because the offset value of 0.62 exceeds the threshold of 0.5, the regularization strength for incremental training is reduced. Historically, under normal conditions, the regularization strength μ is 0.8 (strongly protecting existing knowledge). This time, due to the offset exceeding the threshold, μ is reduced to 0.3, allowing the model to quickly adapt to new user habits. If the offset value subsequently falls below 0.5, the μ value will be increased accordingly to protect newly formed stable habits.
[0089] Incremental training execution: The air conditioner uses newly added multimodal data as training samples, and controls the degree of existing knowledge protection with a regularization strength value of μ=0.3 to incrementally train the local model. The training parameters are set as follows: batch size 32, initial learning rate 0.001, and a cosine annealing learning rate decay strategy. Gradient updates are performed once every 1000 valid interaction samples are collected or every hour. The regularization term penalizes the degree to which the model parameters deviate from historical parameter values. The penalty strength is controlled by μ=0.3. While adapting to new user habits (22:00 sleep, 26°C, low fan speed), it also appropriately retains the still effective parts of the historical decision-making logic (such as the temperature adjustment range in cooling mode).
[0090] After incremental training, the local model can automatically predict and set a 26°C low-wind sleep mode when the user enters the bedroom at 10:00 PM, aligning with the user's new usage habits. Simultaneously, the model did not exhibit catastrophic forgetting, correctly executing general control logic learned from historical data (such as adjusting compressor power based on indoor and outdoor temperature differences). As user habits stabilize, the bias value gradually decreases, the regularization strength value increases accordingly, and the model enters a stable protection state.
[0091] By receiving model parameters uploaded from each edge device and environmental feature information representing the scene in which the device is located, and determining the aggregation weight of the model parameters of each edge device based on the environmental feature information, edge devices with similar scenes contribute more to the global model, thereby avoiding mutual interference between cross-scene data during the aggregation process and improving the control decision accuracy of the global model obtained by aggregation in specific scenarios. By using the global model as a teacher model for knowledge distillation to obtain a target lightweight model, and introducing a physical consistency constraint term based on the change law of the controlled physical quantity of smart home devices into the loss function of knowledge distillation, the target lightweight model can adapt to the computing power constraints of edge devices, while ensuring that its output control actions conform to physical laws, thereby improving the safety and reliability of device control.
[0092] It should be noted that, for the sake of simplicity, the method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments of the present invention are not limited to the described order of actions, because according to the embodiments of the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions involved are not necessarily essential to the embodiments of the present invention.
[0093] Reference Figure 3 The diagram shows a structural block diagram of an embodiment of a model training device based on federated learning and hierarchical distillation according to the present invention. The specific details are as follows: The parameter receiving module 301 is used to receive model parameters and environmental feature information of the local model corresponding to each of the at least one edge device, wherein the environmental feature information is used to characterize the scene in which the edge device is located. The aggregation weight determination module 302 is used to determine the aggregation weight of the model parameters of the local model corresponding to each edge device based on the environmental feature information. The global model determination module 303 is used to perform weighted aggregation of the model parameters of the local model corresponding to the at least one edge device according to the aggregation weight to obtain a global model; The parameter receiving module 304 is used to perform knowledge distillation on the global model as the teacher model to obtain the target lightweight model. The loss function used in the knowledge distillation includes a physical consistency constraint term. The physical consistency constraint term is constructed based on the change law of the controlled physical quantity of the smart home device and is used to constrain the control action output by the target lightweight model to not violate the change law.
[0094] In one embodiment, the aggregation weight determination module includes: The matching degree determination submodule is used to match the environmental feature information of each edge device with at least one preset scene type to obtain the matching degree between each edge device and the at least one scene type; The aggregate weight matching determination submodule is used to determine the aggregate weight of the model parameters of the local model corresponding to each edge device based on the matching degree.
[0095] In one embodiment, the matching degree determination submodule includes: A similarity determination unit is used to determine the similarity between the environmental feature information of each edge device and the feature representation of at least one scene type; The aggregation weight matching determination submodule includes: A similarity weight determination unit is used to determine the aggregation weight based on an exponential function of the similarity.
[0096] In one embodiment, the global model determination module includes: The gradient norm determination submodule is used to determine the gradient norm of the model parameters uploaded by each edge device respectively; The median threshold determination submodule is used to determine the median threshold, which is the product of the median of the gradient norm of the model parameters uploaded by each edge device and a preset multiple. An abnormal device determination submodule is used to determine that the edge device corresponding to the gradient norm is an abnormal device and remove the abnormal device when the gradient norm is greater than the median threshold. The global model final determination submodule is used to perform weighted aggregation of the model parameters of the remaining edge devices after removing abnormal devices, based on the aggregation weight, to obtain the global model.
[0097] In one embodiment, the parameter receiving module includes: The intermediate module determines the sub-module, which is used to perform first-level knowledge distillation on the global model as the teacher model to obtain the intermediate model; The target lightweight model determination submodule is used to perform a second-level knowledge distillation on the intermediate model as a teacher model to obtain the target lightweight model; the loss function used in the knowledge distillation also includes an attention constraint term, which is used to prioritize the retention of knowledge related to equipment control decisions.
[0098] In one embodiment, the local model is continuously learned and updated through the following modules: The multimodal data acquisition submodule is used to collect new multimodal data through the edge device. The multimodal data includes user interaction data, environmental perception data, and device operating status data. A historical multimodal data acquisition submodule is used to acquire historical multimodal data on the edge device; The offset value determination submodule is used to determine the offset value between the newly added multimodal data and the historical multimodal data; The regularization intensity value determination submodule is used to determine the regularization intensity value for incremental model training based on the offset value; The incremental training submodule is used to perform incremental training on the local model based on the newly added multimodal data and the regularization intensity value.
[0099] By receiving model parameters uploaded from each edge device and environmental feature information representing the scene in which the device is located, and determining the aggregation weight of the model parameters of each edge device based on the environmental feature information, edge devices with similar scenes contribute more to the global model, thereby avoiding mutual interference between cross-scene data during the aggregation process and improving the control decision accuracy of the global model obtained by aggregation in specific scenarios. By using the global model as a teacher model for knowledge distillation to obtain a target lightweight model, and introducing a physical consistency constraint term based on the change law of the controlled physical quantity of smart home devices into the loss function of knowledge distillation, the target lightweight model can adapt to the computing power constraints of edge devices, while ensuring that its output control actions conform to physical laws, thereby improving the safety and reliability of device control.
[0100] As the apparatus embodiment is basically similar to the method embodiment, it is described in a relatively simple manner. For relevant details, please refer to the description of the method embodiment.
[0101] This invention also provides an electronic device, including: a processor, a memory, and a computer program stored in the memory and capable of running on the processor. When the computer program is executed by the processor, it implements the various processes of the above-described embodiments of the model training method based on federated learning and hierarchical distillation, and can achieve the same technical effect. To avoid repetition, it will not be described again here.
[0102] This invention also provides a readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the above-described model training method embodiments based on federated learning and hierarchical distillation, and achieve the same technical effect. To avoid repetition, they will not be described again here.
[0103] The processor is the processor in the electronic device described in the above embodiments. The readable storage medium includes computer-readable storage media, such as computer read-only memory (ROM), random access memory (RAM), magnetic disk, or optical disk.
[0104] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of the present invention is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.
[0105] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, electronic device, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0106] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of the present invention.
Claims
1. A model training method based on federated learning and hierarchical distillation, characterized in that, A collaborative training system applied to a network of at least one edge device and a federated coordination node, wherein a corresponding local model is deployed on the at least one edge device, including: The system receives model parameters and environmental feature information of the local model corresponding to each of the at least one edge device, wherein the environmental feature information is used to characterize the scene in which the edge device is located. The aggregation weights of the model parameters of the local model corresponding to each edge device are determined based on the environmental feature information. The model parameters of the local model corresponding to the at least one edge device are weighted and aggregated according to the aggregation weight to obtain the global model; The global model is used as a teacher model for knowledge distillation to obtain the target lightweight model. The loss function used in the knowledge distillation includes a physical consistency constraint term, which is constructed based on the variation law of the controlled physical quantity of the smart home device and is used to constrain the control actions output by the target lightweight model to not violate the variation law.
2. The model training method based on federated learning and hierarchical distillation according to claim 1, characterized in that, The step of determining the aggregation weights of the model parameters of the local model corresponding to each edge device based on the environmental feature information includes: The environmental feature information of each edge device is matched with at least one preset scene type to obtain the matching degree between each edge device and the at least one scene type; The aggregation weight of the model parameters of the local model corresponding to each edge device is determined based on the degree of matching.
3. The model training method based on federated learning and hierarchical distillation according to claim 2, characterized in that, The step of matching the environmental feature information of each edge device with at least one preset scene type to obtain the matching degree between each edge device and the at least one scene type includes: Determine the similarity between the environmental feature information of each edge device and the feature representation of at least one scene type; The step of determining the aggregation weight of the model parameters of the local model corresponding to each edge device based on the matching degree includes: The aggregation weight is determined based on an exponential function of the similarity.
4. The model training method based on federated learning and hierarchical distillation according to claim 1, characterized in that, The step of weighted aggregation of model parameters of the local model corresponding to the at least one edge device according to the aggregation weight to obtain a global model includes: Determine the gradient norm of the model parameters uploaded by each edge device; A median threshold is determined, which is the product of the median of the gradient norm of the model parameters uploaded by each edge device and a preset multiple; If the gradient norm is greater than the median threshold, the edge device corresponding to the gradient norm is determined to be an abnormal device, and the abnormal device is removed. Based on the aggregation weights, the model parameters of the remaining edge devices after removing abnormal devices are weighted and aggregated to obtain the global model.
5. The model training method based on federated learning and hierarchical distillation according to claim 1, characterized in that, The step of using the global model as a teacher model for knowledge distillation to obtain the target lightweight model includes: The global model is used as the teacher model for first-level knowledge distillation to obtain the intermediate model; The intermediate model is used as the teacher model for a second-level knowledge distillation to obtain the target lightweight model. The loss function used in the knowledge distillation also includes an attention constraint term, which is used to prioritize the retention of knowledge related to equipment control decisions.
6. The model training method based on federated learning and hierarchical distillation according to claim 1, characterized in that, The loss function used in the knowledge distillation includes a cross-entropy loss term, a knowledge distillation loss term, and the physical consistency constraint term. The physical consistency constraint term is constructed based on the squared deviation between the predicted rate of change of the controlled physical quantity under the control action and the physical limit rate of change of the controlled physical quantity. The physical limit rate of change is determined by the actuator parameters and environmental parameters of the device. The actuator parameters include the output power of the device actuator, and the environmental parameters include the environmental thermal resistance and the environmental temperature.
7. The model training method based on federated learning and hierarchical distillation according to claim 1, characterized in that, The local model is continuously learned and updated in the following ways: New multimodal data is collected through the edge device, including user interaction data, environmental perception data, and device operating status data. Acquire historical multimodal data from the edge device; Determine the offset between the newly added multimodal data and the historical multimodal data; The regularization strength value used for incremental model training is determined based on the offset value; The local model is incrementally trained based on the newly added multimodal data and the regularization intensity value.
8. A model training device based on federated learning and hierarchical distillation, characterized in that, include: The parameter receiving module is used to receive model parameters and environmental feature information of the local model corresponding to each of the at least one edge device, wherein the environmental feature information is used to characterize the scene in which the edge device is located. The aggregation weight determination module is used to determine the aggregation weight of the model parameters of the local model corresponding to each edge device based on the environmental feature information. A global model determination module is used to perform weighted aggregation of the model parameters of the local models corresponding to the at least one edge device according to the aggregation weight to obtain a global model; The parameter receiving module is used to perform knowledge distillation on the global model as a teacher model to obtain the target lightweight model. The loss function used in the knowledge distillation includes a physical consistency constraint term. The physical consistency constraint term is constructed based on the change law of the controlled physical quantity of the smart home device and is used to constrain the control action output by the target lightweight model to not violate the change law.
9. An electronic device, characterized in that, It includes a processor, a memory, and a program or instructions stored in the memory and executable on the processor, wherein the program or instructions, when executed by the processor, implement the steps of the model training method based on federated learning and hierarchical distillation as described in any one of claims 1-7.
10. A readable storage medium, characterized in that, The readable storage medium stores a program or instructions that, when executed by a processor, implement the steps of the model training method based on federated learning and hierarchical distillation as described in any one of claims 1-7.