CN116910524A - Federal learning method, apparatus, device and storage medium - Google Patents

Federal learning method, apparatus, device and storage medium Download PDF

Info

Publication number
CN116910524A
CN116910524A CN202310004000.8A CN202310004000A CN116910524A CN 116910524 A CN116910524 A CN 116910524A CN 202310004000 A CN202310004000 A CN 202310004000A CN 116910524 A CN116910524 A CN 116910524A
Authority
CN
China
Prior art keywords
model
local
target client
training task
model parameters
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310004000.8A
Other languages
Chinese (zh)
Inventor
张高山
杜雪涛
常嘉岳
洪东
尹子轩
詹义
巴特尔
朱华
王雪
倪宁宁
刘仲思
方明星
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Mobile Communications Group Co Ltd
China Mobile Group Design Institute Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
China Mobile Group Design Institute Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Mobile Communications Group Co Ltd, China Mobile Group Design Institute Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN202310004000.8A priority Critical patent/CN116910524A/en
Publication of CN116910524A publication Critical patent/CN116910524A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N20/00Machine learning

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Evolutionary Computation (AREA)
  • Medical Informatics (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Artificial Intelligence (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application belongs to the technical field of computers, and discloses a federal learning method, a federal learning device, federal learning equipment and a federal learning storage medium. The method comprises the steps of initializing a federation model and constructing a model training task corresponding to the federation model; distributing the model training task to a target client so that the target client trains the federal model carried in the model training task; receiving local model parameters fed back by a target client, and carrying out safety verification on the local model parameters based on a preset block chain; and when the safety verification is passed, updating the federal model according to the local model parameters. Because the blockchain is introduced in the federation learning process, the local model parameters fed back by each target client can be safely checked through the data stored in the blockchain, and the federation model can be updated after the safety check passes, so that the reliability and the safety of the federation learning method are improved.

Description

联邦学习方法、装置、设备及存储介质Federated learning methods, devices, equipment and storage media

技术领域Technical field

本发明涉及计算机技术领域,尤其涉及一种联邦学习方法、装置、设备及存储介质。The present invention relates to the field of computer technology, and in particular to a federated learning method, device, equipment and storage medium.

背景技术Background technique

随着智能设备和互联网的发展,推动了人工智能等技术在数据处理方面的应用。然而,各企业大都不愿意泄露自身数据,并且因各地的数据隐私保护,导致出现数据孤岛现象。联邦学习规定以分布式协同训练方式完成模型训练,各客户端在本地训练模型,将训练参数传到中心服务器而不泄露自身数据,在很大程度上解决了数据隐私问题。With the development of smart devices and the Internet, the application of technologies such as artificial intelligence in data processing has been promoted. However, most companies are unwilling to disclose their own data, and data privacy protection in various places has led to the phenomenon of data islands. Federated learning stipulates that model training be completed in a distributed collaborative training method. Each client trains the model locally and transmits the training parameters to the central server without leaking its own data, which solves the problem of data privacy to a large extent.

但是,目前联邦学习系统的可信度缺乏保障,导致恶意终端的非法行为无法追溯,无法保证训练过程的公平性和可靠性。However, the current credibility of the federated learning system is not guaranteed, resulting in the illegal behavior of malicious terminals being unable to be traced, and the fairness and reliability of the training process unable to be guaranteed.

上述内容仅用于辅助理解本发明的技术方案,并不代表承认上述内容是现有技术。The above content is only used to assist in understanding the technical solution of the present invention, and does not represent an admission that the above content is prior art.

发明内容Contents of the invention

本发明的主要目的在于提供一种联邦学习方法、装置、设备及存储介质,旨在解决现有技术联邦学习的安全性及可靠性无法保障的技术问题。The main purpose of the present invention is to provide a federated learning method, device, equipment and storage medium, aiming to solve the technical problem that the security and reliability of federated learning in the existing technology cannot be guaranteed.

为实现上述目的,本发明提供了一种联邦学习方法,所述方法包括以下步骤:In order to achieve the above objectives, the present invention provides a federated learning method, which includes the following steps:

初始化联邦模型,并构建所述联邦模型对应的模型训练任务;Initialize the federated model and construct a model training task corresponding to the federated model;

将所述模型训练任务分发至目标客户端,以使所述目标客户端对所述模型训练任务中携带的所述联邦模型进行训练;Distribute the model training task to the target client so that the target client trains the federated model carried in the model training task;

接收所述目标客户端反馈的本地模型参数,并基于预设区块链对所述本地模型参数进行安全校验;Receive the local model parameters fed back by the target client, and perform security verification on the local model parameters based on the preset blockchain;

在安全校验通过时,根据所述本地模型参数对所述联邦模型进行更新。When the security check passes, the federated model is updated according to the local model parameters.

可选的,所述将所述模型训练任务分发至目标客户端,以使所述目标客户端对所述模型训练任务中携带的模型进行训练的步骤,包括:Optionally, the step of distributing the model training task to the target client so that the target client trains the model carried in the model training task includes:

将所述模型训练任务分发至目标客户端,以使所述目标客户端从模型训练任务中提取所述联邦模型,根据本地数据集对所述联邦模型进行训练,并在训练结束后,反馈本地模型参数。Distribute the model training task to the target client, so that the target client extracts the federated model from the model training task, trains the federated model according to the local data set, and after the training is completed, feeds back the local model parameters.

可选的,所述将所述模型训练任务分发至目标客户端,以使所述目标客户端从模型训练任务中提取所述联邦模型,根据本地数据集对所述联邦模型进行训练,并在训练结束后,反馈本地模型参数的步骤,包括:Optionally, the model training task is distributed to the target client, so that the target client extracts the federated model from the model training task, trains the federated model according to the local data set, and After training, the steps for feeding back local model parameters include:

将所述模型训练任务分发至目标客户端,以使所述目标客户端根据本地数据集对所述模型训练任务中所述联邦模型进行训练,并在训练结束后,获取训练后的所述联邦模型的模型参数,将所述模型参数存储至预设区块链,并将所述模型参数作为本地模型参数进行反馈。Distribute the model training task to the target client, so that the target client trains the federated model in the model training task according to the local data set, and after the training is completed, obtains the trained federation The model parameters of the model are stored in the preset blockchain and fed back as local model parameters.

可选的,所述接收所述目标客户端反馈的本地模型参数,并基于预设区块链对所述本地模型参数进行安全校验的步骤,包括:Optionally, the step of receiving local model parameters fed back by the target client and performing security verification on the local model parameters based on a preset blockchain includes:

接收所述目标客户端反馈的本地模型参数,从所述本地模型参数中提取模型标识信息;Receive local model parameters fed back by the target client, and extract model identification information from the local model parameters;

根据所述模型标识信息在预设区块链中查找参数校验数据;Search parameter verification data in the preset blockchain according to the model identification information;

若所述本地模型参数与所述参数校验数据一致,则判定安全校验通过。If the local model parameters are consistent with the parameter verification data, it is determined that the security verification has passed.

可选的,所述若所述本地模型参数与所述参数校验数据一致,则判定安全校验通过的步骤,包括:Optionally, if the local model parameters are consistent with the parameter verification data, the step of determining that the security verification has passed includes:

对所述本地模型参数进行哈希运算,获得参数哈希值;Perform a hash operation on the local model parameters to obtain parameter hash values;

若所述参数哈希值与所述参数校验数据一致,则判定安全校验通过。If the parameter hash value is consistent with the parameter verification data, it is determined that the security verification has passed.

可选的,所述在安全校验通过时,根据所述本地模型参数对所述联邦模型进行更新的步骤之后,包括:Optionally, after the step of updating the federated model according to the local model parameters when the security verification is passed, the step includes:

将更新后的联邦模型作为待检测模型;Use the updated federated model as the model to be tested;

检测所述待检测模型是否满足预设全局收敛条件;Detect whether the model to be detected satisfies preset global convergence conditions;

若不满足,则根据所述待检测模型构建新的模型训练任务,并返回所述将所述模型训练任务分发至目标客户端的步骤。If not, construct a new model training task based on the model to be detected, and return to the step of distributing the model training task to the target client.

可选的,所述检测更新后的联邦模型是否满足预设全局收敛条件的步骤,包括:Optionally, the step of detecting whether the updated federation model meets the preset global convergence conditions includes:

若满足,则将所述待检测模型发送至所述目标客户端,以使所述目标客户端依据预设轮次根据本地数据集对所述待检测模型进行多轮训练,并在训练后的待检测模型满足本地收敛条件时,停止对所述待检测模型的训练。If satisfied, the model to be detected is sent to the target client, so that the target client performs multiple rounds of training on the model to be detected based on the local data set according to the preset rounds, and after training When the model to be detected meets the local convergence condition, training of the model to be detected is stopped.

此外,为实现上述目的,本发明还提出一种联邦学习装置,所述联邦学习装置包括以下模块:In addition, to achieve the above objectives, the present invention also proposes a federated learning device, which includes the following modules:

任务构建模块,用于初始化联邦模型,并构建所述联邦模型对应的模型训练任务;The task construction module is used to initialize the federated model and construct the model training task corresponding to the federated model;

任务分发模块,用于将所述模型训练任务分发至目标客户端,以使所述目标客户端对所述模型训练任务中携带的所述联邦模型进行训练;A task distribution module, configured to distribute the model training task to the target client so that the target client can train the federated model carried in the model training task;

参数校验模块,用于接收所述目标客户端反馈的本地模型参数,并基于预设区块链对所述本地模型参数进行安全校验;A parameter verification module, configured to receive local model parameters fed back by the target client, and perform security verification on the local model parameters based on the preset blockchain;

模型更新模块,用于在安全校验通过时,根据所述本地模型参数对所述联邦模型进行更新。The model update module is used to update the federated model according to the local model parameters when the security verification is passed.

此外,为实现上述目的,本发明还提出一种联邦学习设备,所述联邦学习设备包括:处理器、存储器及存储在所述存储器上并可在所述处理器上运行的联邦学习程序,所述联邦学习程序被处理器执行时实现如上所述的联邦学习方法的步骤。In addition, to achieve the above object, the present invention also proposes a federated learning device. The federated learning device includes: a processor, a memory, and a federated learning program stored on the memory and capable of running on the processor. When the federated learning program is executed by the processor, the steps of implementing the federated learning method as described above are implemented.

此外,为实现上述目的,本发明还提出一种计算机可读存储介质,所述计算机可读存储介质上存储有联邦学习程序,所述联邦学习程序执行时实现如上所述的联邦学习方法的步骤。In addition, in order to achieve the above object, the present invention also proposes a computer-readable storage medium. The computer-readable storage medium stores a federated learning program. When the federated learning program is executed, the steps of the federated learning method as described above are implemented. .

本发明通过初始化联邦模型,并构建联邦模型对应的模型训练任务;将模型训练任务分发至目标客户端,以使目标客户端对模型训练任务中携带的联邦模型进行训练;接收目标客户端反馈的本地模型参数,并基于预设区块链对本地模型参数进行安全校验;在安全校验通过时,根据本地模型参数对联邦模型进行更新。由于是在联邦学习过程中引入区块链,可以通过区块链存储的数据对各目标客户端反馈的本地模型参数进行安全校验,并在安全校验通过之后,才会对联邦模型进行更新,提高了本发明联邦学习方法的可信度及安全性。The present invention initializes the federated model and constructs a model training task corresponding to the federated model; distributes the model training task to the target client so that the target client can train the federated model carried in the model training task; and receives feedback from the target client. Local model parameters, and perform security verification on the local model parameters based on the preset blockchain; when the security verification passes, the federated model is updated based on the local model parameters. Since the blockchain is introduced in the federated learning process, the local model parameters fed back by each target client can be safely verified through the data stored in the blockchain, and the federated model will be updated only after the security verification is passed. , which improves the credibility and security of the federated learning method of the present invention.

附图说明Description of the drawings

图1是本发明实施例方案涉及的硬件运行环境的电子设备的结构示意图;Figure 1 is a schematic structural diagram of an electronic device with a hardware operating environment involved in an embodiment of the present invention;

图2为本发明联邦学习方法第一实施例的流程示意图;Figure 2 is a schematic flow chart of the first embodiment of the federated learning method of the present invention;

图3为本发明联邦学习方法第二实施例的流程示意图;Figure 3 is a schematic flow chart of the second embodiment of the federated learning method of the present invention;

图4为本发明一实施例的层次聚类流程示意图;Figure 4 is a schematic diagram of a hierarchical clustering process according to an embodiment of the present invention;

图5为本发明一实施例的交互流程示意图;Figure 5 is a schematic diagram of an interaction process according to an embodiment of the present invention;

图6为本发明联邦学习装置第一实施例的结构框图。Figure 6 is a structural block diagram of the first embodiment of the federated learning device of the present invention.

本发明目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。The realization of the purpose, functional features and advantages of the present invention will be further described with reference to the embodiments and the accompanying drawings.

具体实施方式Detailed ways

应当理解,此处所描述的具体实施例仅用以解释本发明,并不用于限定本发明。It should be understood that the specific embodiments described here are only used to explain the present invention and are not intended to limit the present invention.

参照图1,图1为本发明实施例方案涉及的硬件运行环境的联邦学习设备结构示意图。Referring to Figure 1, Figure 1 is a schematic structural diagram of the federated learning device of the hardware operating environment involved in the embodiment of the present invention.

如图1所示,该电子设备可以包括:处理器1001,例如中央处理器(CentralProcessing Unit,CPU),通信总线1002、用户接口1003,网络接口1004,存储器1005。其中,通信总线1002用于实现这些组件之间的连接通信。用户接口1003可以包括显示屏(Display)、输入单元比如键盘(Keyboard),可选用户接口1003还可以包括标准的有线接口、无线接口。网络接口1004可选的可以包括标准的有线接口、无线接口(如无线保真(WIreless-FIdelity,WI-FI)接口)。存储器1005可以是高速的随机存取存储器(RandomAccess Memory,RAM),也可以是稳定的非易失性存储器(Non-Volatile Memory,NVM),例如磁盘存储器。存储器1005可选的还可以是独立于前述处理器1001的存储装置。As shown in Figure 1, the electronic device may include: a processor 1001, such as a central processing unit (Central Processing Unit, CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize connection communication between these components. The user interface 1003 may include a display screen (Display) and an input unit such as a keyboard (Keyboard). The optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a wireless fidelity (WIreless-FIdelity, WI-FI) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM) or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk memory. The memory 1005 may optionally be a storage device independent of the aforementioned processor 1001.

本领域技术人员可以理解,图1中示出的结构并不构成对电子设备的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件布置。Those skilled in the art can understand that the structure shown in Figure 1 does not constitute a limitation of the electronic device, and may include more or fewer components than shown, or combine certain components, or arrange different components.

如图1所示,作为一种存储介质的存储器1005中可以包括操作系统、网络通信模块、用户接口模块以及联邦学习程序。As shown in Figure 1, memory 1005, which is a storage medium, may include an operating system, a network communication module, a user interface module, and a federated learning program.

在图1所示的电子设备中,网络接口1004主要用于与网络服务器进行数据通信;用户接口1003主要用于与用户进行数据交互;本发明电子设备中的处理器1001、存储器1005可以设置在联邦学习设备中,所述电子设备通过处理器1001调用存储器1005中存储联邦学习程序,并执行本发明实施例提供的联邦学习方法。In the electronic device shown in Figure 1, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the electronic device of the present invention can be provided in In the federated learning device, the electronic device calls the federated learning program stored in the memory 1005 through the processor 1001, and executes the federated learning method provided by the embodiment of the present invention.

本发明实施例提供了一种联邦学习方法,参照图2,图2为本发明一种联邦学习方法第一实施例的流程示意图。An embodiment of the present invention provides a federated learning method. Refer to Figure 2. Figure 2 is a schematic flow chart of a federated learning method according to the first embodiment of the present invention.

本实施例中,所述联邦学习方法包括以下步骤:In this embodiment, the federated learning method includes the following steps:

步骤S10:初始化联邦模型,并构建所述联邦模型对应的模型训练任务。Step S10: Initialize the federated model and construct a model training task corresponding to the federated model.

需要说明的是,本实施例的执行主体可以是所述联邦学习设备,所述联邦学习设备可以是服务器、云服务器或个人电脑等电子设备,当然,也可以是其他可实现相同或相似功能的设备,本实施例对此不加以限制,在本实施例及下述各实施例中,以联邦学习设备为例对本发明联邦学习方法进行说明。It should be noted that the execution subject of this embodiment may be the federated learning device. The federated learning device may be an electronic device such as a server, a cloud server, or a personal computer. Of course, it may also be other devices that can implement the same or similar functions. Equipment, this embodiment is not limited to this. In this embodiment and the following embodiments, the federated learning method of the present invention is explained by taking the federated learning equipment as an example.

需要说明的是,联邦模型可以是需要通过联邦学习进行训练的全局模型,联邦模型可以由联邦学习设备的管理人员预先进行设置。初始化联邦模型可以是对联邦模型的模型参数和/或超参数进行初始化,构建联邦模型对应的模型训练任务可以是将联邦模型的模型结构、模型参数及训练迭代次数(epoch)等作为任务参数,构建模型训练任务。其中,训练迭代次数可以由联邦学习设备的管理人员预先进行设置,例如:将训练迭代次数设置为5。It should be noted that the federated model can be a global model that needs to be trained through federated learning, and the federated model can be preset by the manager of the federated learning device. Initializing the federated model can be to initialize the model parameters and/or hyperparameters of the federated model. The model training task corresponding to building the federated model can be to use the model structure, model parameters and number of training iterations (epoch) of the federated model as task parameters. Build a model training task. The number of training iterations can be preset by the administrator of the federated learning device, for example, the number of training iterations is set to 5.

步骤S20:将所述模型训练任务分发至目标客户端,以使所述目标客户端对所述模型训练任务中携带的所述联邦模型进行训练。Step S20: Distribute the model training task to the target client, so that the target client trains the federated model carried in the model training task.

需要说明的是,目标客户端可以是被选取用于对联邦模型进行分布式训练的客户端,目标客户端可以由联邦学习设备的管理人员预先进行指定,也可以是从与联邦学习设备的客户端中选取预设数量的客户端作为目标客户端。It should be noted that the target client can be a client selected for distributed training of the federated model. The target client can be specified in advance by the administrator of the federated learning device, or it can be a client of the federated learning device. Select a preset number of clients as target clients.

在具体实现中,联邦学习设备将模型训练任务分发至目标客户端,则目标客户端可以对模型训练任务进行解析,从模型训练任务中提取联邦模型,然后根据目标客户端本地的数据对联邦模型进行训练,则此时本实施例所述步骤S20,可以包括:In the specific implementation, the federated learning device distributes the model training task to the target client, and the target client can parse the model training task, extract the federated model from the model training task, and then compare the federated model based on the local data of the target client. When training is performed, step S20 in this embodiment may include:

将所述模型训练任务分发至目标客户端,以使所述目标客户端从模型训练任务中提取所述联邦模型,根据本地数据集对所述联邦模型进行训练,并在训练结束后,反馈本地模型参数。Distribute the model training task to the target client, so that the target client extracts the federated model from the model training task, trains the federated model according to the local data set, and after the training is completed, feeds back the local model parameters.

需要说明的是,本地数据集可以是目标客户端本地存储的数据集合,不同客户端存储的本地数据集不同,其数据结构也可以不同,即各个客户端中存储的数据为异构数据。It should be noted that the local data set can be a data set stored locally on the target client. The local data sets stored by different clients are different, and their data structures can also be different, that is, the data stored in each client is heterogeneous data.

在实际使用中,目标客户端还可以从模型训练任务中训练迭代次数,然后根据训练迭代次数及本地数据集对联邦模型进行多轮训练。其中,为了保证可以进行问题追溯,目标客户端还可以将训练所使用的本地数据集或本地数据集的哈希值存储至预设区块链中。In actual use, the target client can also train the number of iterations from the model training task, and then perform multiple rounds of training on the federated model based on the number of training iterations and the local data set. Among them, in order to ensure that the problem can be traced, the target client can also store the local data set used for training or the hash value of the local data set in the preset blockchain.

进一步的,为了便于联邦学习设备校验目标客户端反馈的本地模型参数,本实施例所述将所述模型训练任务分发至目标客户端,以使所述目标客户端从模型训练任务中提取所述联邦模型,根据本地数据集对所述联邦模型进行训练,并在训练结束后,反馈本地模型参数的步骤,可以包括:Furthermore, in order to facilitate the federated learning device to verify the local model parameters fed back by the target client, in this embodiment, the model training task is distributed to the target client, so that the target client extracts all the parameters from the model training task. The steps of training the federated model based on the local data set and feeding back the local model parameters after the training is completed may include:

将所述模型训练任务分发至目标客户端,以使所述目标客户端从模型训练任务中提取所述联邦模型,根据本地数据集对所述模型训练任务中所述联邦模型进行训练,并在训练结束后,获取训练后的所述联邦模型的模型参数,将所述模型参数存储至预设区块链,并将所述模型参数作为本地模型参数进行反馈。Distribute the model training task to the target client, so that the target client extracts the federated model from the model training task, trains the federated model in the model training task according to the local data set, and After the training is completed, the model parameters of the trained federated model are obtained, the model parameters are stored in the preset blockchain, and the model parameters are fed back as local model parameters.

需要说明的是,由于联邦学习可能会进行多轮模型训练,同理,目标客户端也会向联邦学习设备反馈多次本地模型参数,而每次反馈的本地模型参数可能均不相同,为了便于联邦学习设备验证目标客户端反馈的本地模型参数是否为恶意攻击者伪造的,在将模型参数存储至预设区块链中时,可以提取当前目标客户端中联邦模型的模型标识信息,然后依据模型标识信息将模型参数存储至预设区块链中。It should be noted that since federated learning may perform multiple rounds of model training, the target client will also feedback local model parameters to the federated learning device multiple times, and the local model parameters fed back each time may be different. For convenience, The federated learning device verifies whether the local model parameters fed back by the target client are forged by malicious attackers. When storing the model parameters in the preset blockchain, the model identification information of the federated model in the current target client can be extracted, and then based on The model identification information stores the model parameters into the preset blockchain.

其中,模型标识信息可以是目标客户端为联邦模型分配的唯一标识,不同客户端中针对同一个联邦模型设置不同的模型标识信息,且同一个客户端中联邦模型不同训练阶段也可以对应不同的模型标识信息,例如:为联邦模型设置模型版本号作为模型标识信息,必要时还可以将目标客户端的客户端的设备标识(设备ID)与模型版本号进行组合,生成模型标识信息。Among them, the model identification information can be the unique identification assigned by the target client to the federated model. Different models are set with different model identification information for the same federated model in different clients, and different training stages of the federated model in the same client can also correspond to different Model identification information, for example: set the model version number for the federated model as the model identification information. If necessary, you can also combine the device identification (device ID) of the target client with the model version number to generate model identification information.

步骤S30:接收所述目标客户端反馈的本地模型参数,并基于预设区块链对所述本地模型参数进行安全校验。Step S30: Receive the local model parameters fed back by the target client, and perform security verification on the local model parameters based on the preset blockchain.

需要说明的是,为了保证数据的安全性,客户端与联邦学习设备均至少安装一个预设区块链的区块链节点,在训练过程中,可以将模型参数、训练数据等数据上链区块链,则此时联邦学习设备可以通过预设区块链中存储的数据校验接收到的数据是否为伪造数据。It should be noted that in order to ensure data security, both the client and the federated learning device must install at least one blockchain node with a preset blockchain. During the training process, model parameters, training data and other data can be uploaded to the chain area. Blockchain, then the federated learning device can verify whether the received data is forged data through the data stored in the preset blockchain.

在具体实现中,目标客户端在依据模型训练任务对联邦模型训练完毕之后,会将训练后的联邦模型中的参数反馈给联邦学习设备。此时,为了保证联邦学习的过程中的安全性,联邦学习设备会通过预设区块链中存储的数据对本地模型参数进行安全校验,以确定该本地模型参数是否为恶意攻击者伪造,则此时本实施例所述基于预设区块链对所述本地模型参数进行安全校验的步骤,可以包括:In specific implementation, after the target client completes training of the federated model based on the model training task, it will feed back the parameters in the trained federated model to the federated learning device. At this time, in order to ensure the security in the federated learning process, the federated learning device will perform a security check on the local model parameters through the data stored in the preset blockchain to determine whether the local model parameters have been forged by a malicious attacker. At this time, the steps of security verification of the local model parameters based on the preset blockchain described in this embodiment may include:

接收所述目标客户端反馈的本地模型参数,从所述本地模型参数中提取模型标识信息;Receive local model parameters fed back by the target client, and extract model identification information from the local model parameters;

根据所述模型标识信息在预设区块链中查找参数校验数据;Search parameter verification data in the preset blockchain according to the model identification information;

若所述本地模型参数与所述参数校验数据一致,则判定安全校验通过。If the local model parameters are consistent with the parameter verification data, it is determined that the security verification has passed.

需要说明的是,目标客户端在反馈本地模型参数时,可以将模型标识信息添加至本地模型参数中一同反馈给联邦学习设备,则联邦学习设备在接收到本地模型参数之后,为了快速在预设区块链中查找到对本地模型参数进行安全验证的参数校验数据,可以从本地模型参数中提取模型标识信息,然后再根据模型标识信息在预设区块链中查找对应的参数校验数据。It should be noted that when the target client feeds back the local model parameters, it can add the model identification information to the local model parameters and feed them back to the federated learning device. After receiving the local model parameters, the federated learning device quickly presets If the parameter verification data for secure verification of local model parameters is found in the blockchain, the model identification information can be extracted from the local model parameters, and then the corresponding parameter verification data can be found in the preset blockchain based on the model identification information. .

可以理解的是,由于目标客户端可以是将本地模型参数作为参数校验数据存储至预设区块链中,则在获取到参数校验数据之后,联邦学习设备可以将接收到的本地模型参数与参数校验数据进行比较,若两者一致,则联邦学习设备可以确定本地模型参数并非恶意攻击者伪造,因此,可以判定安全校验通过。It can be understood that since the target client can store the local model parameters as parameter verification data in the preset blockchain, after obtaining the parameter verification data, the federated learning device can store the received local model parameters. Compare it with the parameter verification data. If the two are consistent, the federated learning device can determine that the local model parameters are not forged by a malicious attacker. Therefore, it can be determined that the security verification has passed.

在具体实现中,由于模型参数的参数项可能较多,若直接将本地模型参数存储至预设区块链上,可能会占用较大空间,甚至会影响到预设区块链的性能,为了避免此种情况,需要缩减存储至预设区块链的数据量,则此时目标客户端可以对本地模型参数进行哈希运算,获取本地模型参数对应的哈希值,然后将哈希值作为参数校验数据存储至预设区块链中,则此时联邦学习设备的验证方式也会相应发生变化,因此,本实施例所述若所述本地模型参数与所述参数校验数据一致,则判定安全校验通过的步骤,可以包括:In specific implementation, since the model parameters may have many parameter items, if the local model parameters are directly stored on the preset blockchain, it may take up a large space and even affect the performance of the preset blockchain. In order to To avoid this situation, it is necessary to reduce the amount of data stored in the preset blockchain. At this time, the target client can hash the local model parameters, obtain the hash value corresponding to the local model parameter, and then use the hash value as When the parameter verification data is stored in the preset blockchain, the verification method of the federated learning device will also change accordingly. Therefore, as described in this embodiment, if the local model parameters are consistent with the parameter verification data, Then the steps to determine whether the security verification is passed may include:

对所述本地模型参数进行哈希运算,获得参数哈希值;Perform a hash operation on the local model parameters to obtain parameter hash values;

若所述参数哈希值与所述参数校验数据一致,则判定安全校验通过。If the parameter hash value is consistent with the parameter verification data, it is determined that the security verification has passed.

可以理解的是,为了缩减存储至预设区块链的数据量,目标客户端会将本地模型参数的哈希值作为参数校验数据存储至预设区块链中,则此时联邦学习设备可以采用相同的方式对本地模型参数进行哈希运算,然后将哈希运算获得的参数哈希值与参数校验数据进行比较,若参数哈希值与参数校验数据一致,则可以确定本地模型参数并非恶意攻击者伪造,因此,可以判定安全校验通过。It is understandable that in order to reduce the amount of data stored in the preset blockchain, the target client will store the hash value of the local model parameters as parameter verification data in the preset blockchain. At this time, the federated learning device The local model parameters can be hashed in the same way, and then the parameter hash value obtained by the hash operation is compared with the parameter verification data. If the parameter hash value is consistent with the parameter verification data, the local model can be determined The parameters were not forged by malicious attackers, so it can be determined that the security check passed.

在具体实现中,仅仅采用哈希值进行验证,则验证方式依旧可能被恶意攻击者破解,为了提高破解难度,目标客户端可以先采用预设顺序对本地模型参数进行重排,然后在对重排后的本地模型参数进行哈希运算,将此时获得的哈希值作为参数校验数据存储至预设区块链中。其中,预设顺序可以由联邦学习设备的管理人员预先设置,并作为任务参数添加至模型训练任务中分发给各个目标客户端。In the specific implementation, if only the hash value is used for verification, the verification method may still be cracked by malicious attackers. In order to improve the difficulty of cracking, the target client can first rearrange the local model parameters in a preset order, and then rearrange the parameters. The ranked local model parameters are hashed, and the hash value obtained at this time is stored in the preset blockchain as parameter verification data. Among them, the preset sequence can be preset by the administrator of the federated learning device, and added as task parameters to the model training task and distributed to each target client.

当然,为了保证安全性,预设区块链在存储数据时,可以存储加密数据,例如:目标客户端将A数据存储至预设区块链时,可以采用目标客户端中的区块连接点存储的加密密钥将A数据加密,加密后再存储至预设区块链上,则联邦学习设备可以根据加密密钥对应的解密密钥对获取到的区块链数据进行解密,从而获得参数校验数据。其中,加密密钥可以是对称性加密算法的加密密钥,也可以是费对称性加密算法的加密密钥,本实施例对此不加以限制。Of course, in order to ensure security, the default blockchain can store encrypted data when storing data. For example, when the target client stores data A to the default blockchain, it can use the block connection point in the target client. The stored encryption key encrypts data A, and then stores it on the preset blockchain after encryption. Then the federated learning device can decrypt the obtained blockchain data based on the decryption key corresponding to the encryption key, thereby obtaining the parameters. Check data. The encryption key may be an encryption key of a symmetric encryption algorithm or an encryption key of a fee-symmetric encryption algorithm, which is not limited in this embodiment.

同理,联邦学习设备在向各目标客户端分发模型训练任务时,也可以将模型训练任务相关的校验数据存储至预设区块链中,则目标客户端可以利用预设区块链中存储的数据对模型训练任务进行安全校验,在安全校验通过时,在根据模型训练任务进行模型训练。In the same way, when the federated learning device distributes model training tasks to each target client, it can also store the verification data related to the model training task in the preset blockchain. Then the target client can use the preset blockchain The stored data performs security verification on the model training task. When the security verification passes, the model training is performed based on the model training task.

步骤S40:在安全校验通过时,根据所述本地模型参数对所述联邦模型进行更新。Step S40: When the security check passes, update the federated model according to the local model parameters.

可以理解的是,若安全校验通过,则表示本地模型参数并非为恶意攻击者伪造的,因此,联邦学习设备可以根据本地模型参数对所述联邦模型进行更新,例如:在接收到各目标客户端反馈的本地模型参数之后,可以计算本地模型参数的平均值,然后根据该平均值更新联邦模型中的模型参数。It can be understood that if the security check is passed, it means that the local model parameters are not forged by malicious attackers. Therefore, the federated learning device can update the federated model based on the local model parameters, for example: after receiving the information from each target customer After receiving the local model parameters fed back by the client, the average value of the local model parameters can be calculated, and then the model parameters in the federated model are updated based on the average value.

本实施例通过初始化联邦模型,并构建联邦模型对应的模型训练任务;将模型训练任务分发至目标客户端,以使目标客户端对模型训练任务中携带的联邦模型进行训练;接收目标客户端反馈的本地模型参数,并基于预设区块链对本地模型参数进行安全校验;在安全校验通过时,根据本地模型参数对联邦模型进行更新。由于是在联邦学习过程中引入区块链,可以通过区块链存储的数据对各目标客户端反馈的本地模型参数进行安全校验,并在安全校验通过之后,才会对联邦模型进行更新,提高了本发明联邦学习方法的可信度及安全性。This embodiment initializes the federated model and constructs a model training task corresponding to the federated model; distributes the model training task to the target client so that the target client can train the federated model carried in the model training task; and receives feedback from the target client. local model parameters, and perform security verification on the local model parameters based on the preset blockchain; when the security verification passes, the federated model is updated based on the local model parameters. Since the blockchain is introduced in the federated learning process, the local model parameters fed back by each target client can be safely verified through the data stored in the blockchain, and the federated model will be updated only after the security verification is passed. , which improves the credibility and security of the federated learning method of the present invention.

参考图3,图3为本发明一种联邦学习方法第二实施例的流程示意图。Refer to Figure 3, which is a schematic flow chart of a second embodiment of a federated learning method of the present invention.

基于上述第一实施例,本实施例联邦学习方法的所述步骤S40之后,还包括:Based on the above first embodiment, after the step S40 of the federated learning method in this embodiment, it also includes:

步骤S50:将更新后的联邦模型作为待检测模型。Step S50: Use the updated federated model as the model to be detected.

需要说明的是,在依据各目标客户端反馈的本地模型参数对联邦模型进行更新之后,还需要对更新后的联邦模型进行进一步验证,确定是否需要继续进行联邦训练,因此,可以将更新后的联邦模型作为待检测模型。It should be noted that after updating the federated model based on the local model parameters fed back by each target client, the updated federated model needs to be further verified to determine whether federated training needs to continue. Therefore, the updated federated model can be The federated model serves as the model to be tested.

步骤S60:检测所述待检测模型是否满足预设全局收敛条件。Step S60: Detect whether the model to be detected satisfies the preset global convergence condition.

需要说明的是,预设全局收敛条件可以由联邦学习设备的管理人员预先进行设置。It should be noted that the preset global convergence conditions can be set in advance by the administrator of the federated learning device.

例如:联邦学习设备的管理人员可以预先设置模型验证集,通过模型验证集对待检测模型进行准确性验证,在待检测模型的模型准确性达到预设准确阈值时,判定待检测模型满足预设全局收敛条件。For example: managers of federated learning equipment can set a model verification set in advance, and use the model verification set to verify the accuracy of the model to be detected. When the model accuracy of the model to be detected reaches the preset accuracy threshold, it is determined that the model to be detected satisfies the preset global convergence conditions.

当然,在验证待检测模型是否满足预设全局收敛条件时,可以不单单结合准确率,还可以结合泛化性、学习率等综合进行判定,本实施例对此不加以限制。Of course, when verifying whether the model to be tested satisfies the preset global convergence conditions, not only the accuracy can be combined, but also the generalization, learning rate, etc. can be combined for comprehensive determination. This embodiment is not limited to this.

可以理解的是,若待检测模型不满足预设全局收敛条件,则表示在联邦学习过程中,训练后的联邦模型还未达到了最初设置的训练目标,则此时根据待测试模型构建新的新的模型训练任务,然后返回所述将所述模型训练任务分发至目标客户端的步骤,对待测试模型进行再次的训练。It can be understood that if the model to be tested does not meet the preset global convergence conditions, it means that during the federated learning process, the trained federated model has not reached the initially set training goal, and a new model will be constructed based on the model to be tested at this time. Create a new model training task, and then return to the step of distributing the model training task to the target client, and train the model to be tested again.

步骤S70:若满足,则将所述待检测模型发送至所述目标客户端,以使所述目标客户端依据预设轮次根据本地数据集对所述待检测模型进行多轮训练,并在训练后的待检测模型满足本地收敛条件时,停止对所述待检测模型的训练。Step S70: If satisfied, send the model to be detected to the target client, so that the target client performs multiple rounds of training on the model to be detected based on the local data set according to preset rounds, and When the trained model to be detected meets the local convergence condition, the training of the model to be detected is stopped.

需要说明的是,若待检测模型满足预设全局收敛条件,则表示在联邦学习过程中,训练后的联邦模型已经达到了最初设置的训练目标,则此时可以结束对联邦模型的联邦学习。It should be noted that if the model to be detected meets the preset global convergence conditions, it means that during the federated learning process, the trained federated model has reached the initially set training goal, and the federated learning of the federated model can be ended at this time.

但是,由于各目标客户端中存储的数据是异构数据,此时联邦模型在目标客户端的应用场景中可能应用效果并不好,为了避免此种情况,在待检测模型满足预设全局收敛条件时,还可以将待检测模型发送至目标客户端,令目标客户端根据预设轮次根据本地数据集对待检测模型再进行多轮训练,并在训练过程中不断检测待检测模型是否满足目标客户端中存储的本地收敛条件,然后在训练后的待检测模型满足本地收敛条件时,停止对待检测模型的训练。However, since the data stored in each target client is heterogeneous data, the federated model may not be effective in the application scenario of the target client. In order to avoid this situation, the model to be detected satisfies the preset global convergence conditions. At the same time, the model to be detected can also be sent to the target client, so that the target client can perform multiple rounds of training on the model to be detected based on the local data set according to the preset rounds, and continuously detect whether the model to be detected satisfies the target customer during the training process. local convergence conditions stored in the terminal, and then stop training the model to be detected when the trained model to be detected meets the local convergence conditions.

其中,预设轮次级本地收敛条件可以由目标客户端的管理人员根据实际需要预先进行设置,本地收敛条件的设置方式与全局收敛条件的设置方式类似,此处不再赘述。Among them, the preset round-level local convergence conditions can be set in advance by the administrator of the target client according to actual needs. The setting method of the local convergence conditions is similar to the setting method of the global convergence conditions, and will not be described again here.

可以理解的是,将满足预设全局收敛条件的待检测模型发送至各个目标客户端进行再次训练,则可以构建符合目标客户端的个性化模型,个性化会使得每个客户端从更多相似性的客户端中获得更多好处。It can be understood that by sending the model to be detected that meets the preset global convergence conditions to each target client for re-training, a personalized model that meets the target client can be built. Personalization will allow each client to learn from more similarities. Get more benefits from your clients.

在了便于理解,现结合图4及图5进行说明,单不对本方案进行限定,图4为本实施例的层次聚类流程示意图,图5本实施例的客户端与服务器(即前文所述联邦学习设备)之间的交互流程示意图。In order to facilitate understanding, the description will now be made in conjunction with Figure 4 and Figure 5. This solution will not be limited. Figure 4 is a schematic diagram of the hierarchical clustering process of this embodiment. Figure 5 shows the client and server of this embodiment (that is, as mentioned above). Schematic diagram of the interaction process between federated learning devices).

第一,可以定义联邦学习问题,假设D表示全局数据分布,s1,...sN=S,S遵循D分布,数据分布在M个客户终端中,每个客户端仅能访问并利用本地数据s1,...sNi=Si,本地数据属于全局数据的子集。Di表示本地数据分布,θg表示全局参数的参数,全局训练任务可以表示为:First, the federated learning problem can be defined, assuming that D represents the global data distribution, s 1 ,...s N =S, S follows the D distribution, the data is distributed among M client terminals, and each client can only access and utilize Local data s 1 ,...s Ni =S i , local data belong to a subset of global data. Di represents the local data distribution, θ g represents the parameters of the global parameters, and the global training task can be expressed as:

每个客户端的Di都是不同的,但是可以根据其相似性执行聚类操作,对于每个聚类结果产生一个特定的模型θc(c∈C,C是聚类集合,θc表示所有聚类结果模型的集合)。以聚类结果定义全局模型的损失函数表示如下:Di is different for each client, but clustering operations can be performed based on their similarities, resulting in a specific model θ c (c∈C, C is the cluster set, θ c represents all clusters) for each clustering result A collection of result-like models). The loss function of the global model defined by the clustering results is expressed as follows:

每个聚类结果的损失函数表示如下The loss function of each clustering result is expressed as follows

将此模型扩展到个性化版本,其中每个客户端都有自己的模型:Extend this model to a personalized version where each client has its own model:

公式(2)和(4)都引入了额外的自由度,允许客户端从各自的分布中更好地学习采样的训练数据点。结果对比如下:Both equations (2) and (4) introduce additional degrees of freedom, allowing clients to better learn sampled training data points from their respective distributions. The results are compared as follows:

第二,可以定义联邦学习训练过程Second, the federated learning training process can be defined

假设拥有M个客户端,Ni=|Di|表示客户端i拥有的样本数量,全局训练损失函数表示如下:Assume that there are M clients, N i =|D i | represents the number of samples owned by client i, and the global training loss function is expressed as follows:

其中/> Among them/>

其中Fi(θ)是每个客户端的局部目标函数,f(θ)是所有客户的平均全局目标,训练过程包括两个阶段,首先,客户端在其本地数据上使用初始分布训练预定的轮数,客户端和服务器通信。然后,服务器基于所有本地更新的模型参数计算加权平均值,结果返回客户端更新其模型参数。where F i (θ) is the local objective function of each client, and f (θ) is the average global objective of all clients. The training process includes two stages. First, the client uses the initial distribution to train a predetermined round on its local data. number, client and server communication. The server then calculates a weighted average based on all locally updated model parameters, and the results are returned to the client to update its model parameters.

第三,设置个性化的联邦学习模型Third, set up a personalized federated learning model

全局模型参数初始化,在联合训练开始前,参数被传送到随机选择的n个客户端中,执行局部训练,在每个客户端中产生更新的局部模型参数,使用基于当前循环数的自适应元学习率更新参数,自适应元学习率在整个训练过程线性下降。在最后一轮联合训练结束后,所有的客户端的本地模型通过对局部训练数据执行固定数量的梯度优化轮数(epochs)来个性化模型,个性化使得每个客户端从更多相似性的客户端中获得更多好处。Global model parameters are initialized. Before joint training starts, the parameters are transmitted to randomly selected n clients, local training is performed, and updated local model parameters are generated in each client, using adaptive elements based on the current cycle number. The learning rate updates parameters, and the adaptive meta-learning rate decreases linearly throughout the training process. After the last round of joint training, the local models of all clients are personalized by performing a fixed number of gradient optimization epochs on the local training data. Personalization enables each client to learn from more similar clients. Get more benefits.

第四,联邦学习过程层次聚类操作Fourth, hierarchical clustering operation of federated learning process

在全局联邦学习的初始阶段之后执行分层聚类。在对指定数量的联邦轮次执行联邦学习后,根据当前轮次中的模型更新,通过分层聚类对客户端进行聚类。然后,每个生成的客户端集群被视为一个孤立的联合学习问题,过程如图4所示。Hierarchical clustering is performed after an initial stage of global federated learning. After performing federated learning for a specified number of federation rounds, clients are clustered by hierarchical clustering based on model updates in the current round. Then, each generated client cluster is treated as an isolated federated learning problem, and the process is shown in Figure 4.

以上步骤只介绍联邦学习相关原理,以下步骤详细介绍区块链和通信相关过程。The above steps only introduce the principles related to federated learning. The following steps introduce the blockchain and communication related processes in detail.

第五,基于区块链场景下的客户端和中央服务器设置Fifth, client and central server settings based on blockchain scenarios

该步骤涉及到联邦学习的作业创建过程和与区块链的交互过程,服务器端处理器和客户端的行为如图2所示,具体流程如下。This step involves the job creation process of federated learning and the interaction process with the blockchain. The behavior of the server-side processor and client is shown in Figure 2. The specific process is as follows.

服务器行为:服务器的作业创建器通过初始化全局模型和超参数创建训练作业,然后将该作业广播给客户端模型训练器。作业创建器将初始全局模型转移到全局模型数据库。服务器等待来自限定客户端的本地模型参数。模型聚合器从客户端接收本地模型参数,执行模型聚合,计算所有模型参数的平均值以更新全局模型参数;Server behavior: The server's job creator creates a training job by initializing the global model and hyperparameters, and then broadcasts the job to the client model trainer. The job creator transfers the initial global model to the global model database. The server waits for local model parameters from qualified clients. The model aggregator receives local model parameters from the client, performs model aggregation, and calculates the average of all model parameters to update global model parameters;

更新的全局模型存储在全局模型数据库中。全局模型版本的哈希值被上传到区块链。模型部署器将更新后的全局模型广播给客户决策器,供下一轮训练使用。模型部署器是选择客户端设备以接收全局模型更新的组件。The updated global model is stored in the global model database. A hash of the global model version is uploaded to the blockchain. The model deployer broadcasts the updated global model to the client decider for use in the next round of training. The model deployer is the component that selects client devices to receive global model updates.

客户端行为:客户端对本地数据预处理后存储在本地数据库中,数据库中的输出传输给模型训练器进行本地训练,每个epoch中使用的训练数据版本的哈希值上传到区块链,训练结束后局部模型被传送到局部模型评估器中进行评估,当前模型版本的哈希值也传输到区块链上;Client behavior: The client preprocesses the local data and stores it in the local database. The output in the database is transmitted to the model trainer for local training. The hash value of the training data version used in each epoch is uploaded to the blockchain. After training, the local model is transferred to the local model evaluator for evaluation, and the hash value of the current model version is also transferred to the blockchain;

本地模型参数存储在本地模型数据库中,发送到服务器的模型聚合器。之后进行多轮通信,如果决策者检查模型的结果满足要求,终止训练过程。Local model parameters are stored in the local model database and sent to the server's model aggregator. After that, multiple rounds of communication are carried out. If the decision-maker checks that the results of the model meet the requirements, the training process is terminated.

第六,数据模型注册智能合约构建Sixth, data model registration smart contract construction

在每个本地训练epoch中,客户端将其本地模型参数和相应的数据版本的哈希值上传到数据模型注册智能合约。在每次全局聚合之后,服务器将全局模型参数的哈希值发送到智能合约。In each local training epoch, the client uploads its local model parameters and corresponding hashes of the data version to the data model registration smart contract. After each global aggregation, the server sends the hash of the global model parameters to the smart contract.

在智能合约中,本地和全局模型参数的哈希值都记录在模型结构体中。一旦上传,信息将无法修改。设置另一个结构体计算每个客户端的上传数量。通过链上哈希映射,这两个结构体通过其链上地址连接到客户端,用于检索上链数据版本和模型参数信息。上传过程中可能会遇到问题,以下列举可能遇到的问题,并给出解决方案。In smart contracts, the hash values of local and global model parameters are recorded in the model structure. Once uploaded, the information cannot be modified. Set up another structure to calculate the number of uploads for each client. Through on-chain hash mapping, these two structures are connected to the client through their on-chain addresses and are used to retrieve on-chain data versions and model parameter information. You may encounter problems during the upload process. The following lists possible problems and gives solutions.

第七,定义系统区块链功能与处理流程Seventh, define the system blockchain functions and processing procedures

在基于区块链的可信联邦学习架构设计中,每个客户端和服务器至少安装一个区块链节点,形成区块链网络。每个节点以区块链的形式保存完整事务数据的本地副本。修改任意块中的任何历史数据状态都需要更新存储在所有参与节点中的所有后续块。此外,区块链主要使用智能合约处理数据模型,其中所有参与者都通过其区块链地址进行识别。为了保持联合学习过程的可行性和效率的同时溯源模型,架构应用了链下数据存储设计模式,采用数据库系统存储实际模型,而区块链只记录模型的哈希版本。区块链系统中链下部分和上链部分具体如下。In the design of a blockchain-based trusted federated learning architecture, each client and server installs at least one blockchain node to form a blockchain network. Each node keeps a local copy of the complete transaction data in the form of a blockchain. Modifying any historical data state in any block requires updating all subsequent blocks stored in all participating nodes. Furthermore, blockchain primarily handles data models using smart contracts, where all participants are identified by their blockchain addresses. In order to maintain the feasibility and efficiency of the joint learning process while tracing the model, the architecture applies an off-chain data storage design pattern, using a database system to store the actual model, while the blockchain only records the hashed version of the model. The details of the off-chain part and the up-chain part in the blockchain system are as follows.

链下部分:所有模型参数(即本地和全局模型)分别存储在本地模型的链下数据库和全局模型的数据库中。Off-chain part: All model parameters (i.e. local and global models) are stored in the off-chain database of the local model and the database of the global model respectively.

上链部分:数据版本由时间戳和数据大小组成,根据本地数据版本生成哈希值并记录在链上数据模型的注册智能合约中,以实现数据和模型的来源和版本控制。On-chain part: The data version consists of timestamp and data size. A hash value is generated based on the local data version and recorded in the registered smart contract of the on-chain data model to achieve source and version control of data and models.

出于数据隐私考虑,本发明跟踪用于使用智能合约训练每个本地模型的数据,而不在区块链上记录实际本地数据。通过比较链外模型的哈希值和相应的链内记录来验证其来源。For data privacy reasons, the present invention tracks the data used to train each local model using smart contracts without recording the actual local data on the blockchain. Verify its origin by comparing the off-chain model’s hash with the corresponding on-chain record.

本实施例通过将更新后的联邦模型作为待检测模型;检测所述待检测模型是否满足预设全局收敛条件;若满足,则将所述待检测模型发送至所述目标客户端,以使所述目标客户端依据预设轮次根据本地数据集对所述待检测模型进行多轮训练,并在训练后的待检测模型满足本地收敛条件时,停止对所述待检测模型的训练。由于会将满足预设全局收敛条件的待检测模型分发至各目标客户端,令各目标客户端依据本地数据集及预设轮次对待检测模型进行多轮训练,直至满足本地收敛条件,保证了可以构建符合目标客户端的个性化模型,保证各目标客户端获得的个性化模型可满足各目标客户端本地使用场景的实际需求。In this embodiment, the updated federated model is used as the model to be detected; it is detected whether the model to be detected satisfies the preset global convergence condition; if it is satisfied, the model to be detected is sent to the target client, so that all The target client performs multiple rounds of training on the model to be detected based on the local data set according to preset rounds, and stops training the model to be detected when the trained model to be detected meets local convergence conditions. Since the model to be detected that meets the preset global convergence conditions will be distributed to each target client, each target client will perform multiple rounds of training on the model to be detected based on the local data set and preset rounds until the local convergence conditions are met, ensuring A personalized model that meets the target client can be constructed to ensure that the personalized model obtained by each target client can meet the actual needs of the local usage scenario of each target client.

此外,本发明实施例还提出一种存储介质,所述存储介质上存储有联邦学习程序,所述联邦学习程序被处理器执行时实现如上文所述的联邦学习方法的步骤。In addition, embodiments of the present invention also provide a storage medium on which a federated learning program is stored. When the federated learning program is executed by a processor, the steps of the federated learning method described above are implemented.

参照图6,图6为本发明联邦学习装置第一实施例的结构框图。Referring to Figure 6, Figure 6 is a structural block diagram of the first embodiment of the federated learning device of the present invention.

如图6所示,本发明实施例提出的联邦学习装置包括:As shown in Figure 6, the federated learning device proposed by this embodiment of the present invention includes:

任务构建模块10,用于初始化联邦模型,并构建所述联邦模型对应的模型训练任务;The task construction module 10 is used to initialize the federated model and construct the model training task corresponding to the federated model;

任务分发模块20,用于将所述模型训练任务分发至目标客户端,以使所述目标客户端对所述模型训练任务中携带的所述联邦模型进行训练;Task distribution module 20 is used to distribute the model training task to the target client, so that the target client trains the federated model carried in the model training task;

参数校验模块30,用于接收所述目标客户端反馈的本地模型参数,并基于预设区块链对所述本地模型参数进行安全校验;The parameter verification module 30 is used to receive the local model parameters fed back by the target client, and perform security verification on the local model parameters based on the preset blockchain;

模型更新模块40,用于在安全校验通过时,根据所述本地模型参数对所述联邦模型进行更新。The model update module 40 is configured to update the federated model according to the local model parameters when the security verification is passed.

本实施例通过初始化联邦模型,并构建联邦模型对应的模型训练任务;将模型训练任务分发至目标客户端,以使目标客户端对模型训练任务中携带的联邦模型进行训练;接收目标客户端反馈的本地模型参数,并基于预设区块链对本地模型参数进行安全校验;在安全校验通过时,根据本地模型参数对联邦模型进行更新。由于是在联邦学习过程中引入区块链,可以通过区块链存储的数据对各目标客户端反馈的本地模型参数进行安全校验,并在安全校验通过之后,才会对联邦模型进行更新,提高了本发明联邦学习方法的可信度及安全性。This embodiment initializes the federated model and constructs a model training task corresponding to the federated model; distributes the model training task to the target client so that the target client can train the federated model carried in the model training task; and receives feedback from the target client. local model parameters, and perform security verification on the local model parameters based on the preset blockchain; when the security verification passes, the federated model is updated based on the local model parameters. Since the blockchain is introduced in the federated learning process, the local model parameters fed back by each target client can be safely verified through the data stored in the blockchain, and the federated model will be updated only after the security verification is passed. , which improves the credibility and security of the federated learning method of the present invention.

进一步的,所述任务分发模块20,还用于将所述模型训练任务分发至目标客户端,以使所述目标客户端从模型训练任务中提取所述联邦模型,根据本地数据集对所述联邦模型进行训练,并在训练结束后,反馈本地模型参数。Further, the task distribution module 20 is also used to distribute the model training task to the target client, so that the target client extracts the federated model from the model training task, and analyzes the federated model according to the local data set. The federated model is trained, and after training, local model parameters are fed back.

进一步的,所述任务分发模块20,还用于将所述模型训练任务分发至目标客户端,以使所述目标客户端从模型训练任务中提取所述联邦模型,根据本地数据集对所述模型训练任务中所述联邦模型进行训练,并在训练结束后,获取训练后的所述联邦模型的模型参数,将所述模型参数存储至预设区块链,并将所述模型参数作为本地模型参数进行反馈。Further, the task distribution module 20 is also used to distribute the model training task to the target client, so that the target client extracts the federated model from the model training task, and analyzes the federated model according to the local data set. The federated model in the model training task is trained, and after the training is completed, the model parameters of the trained federated model are obtained, the model parameters are stored in the preset blockchain, and the model parameters are used as local Model parameters are fed back.

进一步的,所述参数校验模块30,还用于接收所述目标客户端反馈的本地模型参数,从所述本地模型参数中提取模型标识信息;根据所述模型标识信息在预设区块链中查找参数校验数据;若所述本地模型参数与所述参数校验数据一致,则判定安全校验通过。Further, the parameter verification module 30 is also used to receive the local model parameters fed back by the target client, extract model identification information from the local model parameters; and perform the preset blockchain according to the model identification information. Search parameter verification data in; if the local model parameters are consistent with the parameter verification data, it is determined that the security verification has passed.

进一步的,所述参数校验模块30,还用于对所述本地模型参数进行哈希运算,获得参数哈希值;若所述参数哈希值与所述参数校验数据一致,则判定安全校验通过。Further, the parameter verification module 30 is also used to perform a hash operation on the local model parameters to obtain a parameter hash value; if the parameter hash value is consistent with the parameter verification data, it is determined to be safe. Verification passed.

进一步的,所述模型更新模块40,还用于将更新后的联邦模型作为待检测模型;检测所述待检测模型是否满足预设全局收敛条件;若不满足,则根据所述待检测模型构建新的模型训练任务,并返回所述将所述模型训练任务分发至目标客户端的步骤。Further, the model update module 40 is also used to use the updated federated model as a model to be detected; detect whether the model to be detected satisfies the preset global convergence conditions; if not, construct a model based on the model to be detected. Create a new model training task, and return to the step of distributing the model training task to the target client.

进一步的,所述模型更新模块40,还用于若满足,则将所述待检测模型发送至所述目标客户端,以使所述目标客户端依据预设轮次根据本地数据集对所述待检测模型进行多轮训练,并在训练后的待检测模型满足本地收敛条件时,停止对所述待检测模型的训练。Further, the model update module 40 is also configured to, if satisfied, send the model to be detected to the target client, so that the target client can update the model according to the local data set according to the preset round. The model to be detected is trained for multiple rounds, and when the trained model to be detected meets the local convergence condition, training of the model to be detected is stopped.

应当理解的是,以上仅为举例说明,对本发明的技术方案并不构成任何限定,在具体应用中,本领域的技术人员可以根据需要进行设置,本发明对此不做限制。It should be understood that the above are only examples and do not constitute any limitation on the technical solution of the present invention. In specific applications, those skilled in the art can make settings as needed, and the present invention does not impose any limitations on this.

需要说明的是,以上所描述的工作流程仅仅是示意性的,并不对本发明的保护范围构成限定,在实际应用中,本领域的技术人员可以根据实际的需要选择其中的部分或者全部来实现本实施例方案的目的,此处不做限制。It should be noted that the workflow described above is only illustrative and does not limit the scope of the present invention. In practical applications, those skilled in the art can select some or all of them for implementation according to actual needs. The purpose of this embodiment is not limited here.

另外,未在本实施例中详尽描述的技术细节,可参见本发明任意实施例所提供的联邦学习方法,此处不再赘述。In addition, for technical details that are not described in detail in this embodiment, please refer to the federated learning method provided by any embodiment of the present invention, and will not be described again here.

此外,需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、物品或者系统不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、物品或者系统所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、方法、物品或者系统中还存在另外的相同要素。Furthermore, it should be noted that, as used herein, the terms "include", "comprises" or any other variation thereof are intended to cover a non-exclusive inclusion, such that a process, method, article or system that includes a list of elements includes not only those elements, but also other elements not expressly listed or elements inherent to the process, method, article or system. Without further limitation, an element defined by the statement "comprises a..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.

上述本发明实施例序号仅仅为了描述,不代表实施例的优劣。The above serial numbers of the embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments.

通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本发明的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如只读存储器(Read Only Memory,ROM)/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本发明各个实施例所述的方法。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 the necessary general hardware platform. Of course, it can also be implemented by hardware, but in many cases the former is better. implementation. Based on this understanding, the technical solution of the present invention can be embodied in the form of a software product in essence or that contributes to the existing technology. The computer software product is stored in a storage medium (such as a read-only memory). , ROM)/RAM, magnetic disk, optical disk), including several instructions to cause a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the method described in various embodiments of the present invention.

以上仅为本发明的优选实施例,并非因此限制本发明的专利范围,凡是利用本发明说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其他相关的技术领域,均同理包括在本发明的专利保护范围内。The above are only preferred embodiments of the present invention, and do not limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the description and drawings of the present invention may be directly or indirectly used in other related technical fields. , are all similarly included in the scope of patent protection of the present invention.

Claims (10)

1. A federal learning method, comprising the steps of:
Initializing a federation model and constructing a model training task corresponding to the federation model;
distributing the model training task to a target client so that the target client trains the federation model carried in the model training task;
receiving local model parameters fed back by the target client, and carrying out safety verification on the local model parameters based on a preset blockchain;
and updating the federation model according to the local model parameters when the safety verification passes.
2. The federal learning method according to claim 1, wherein the step of distributing the model training task to a target client to cause the target client to train the model carried in the model training task comprises:
and distributing the model training task to a target client so that the target client extracts the federation model from the model training task, trains the federation model according to a local data set, and feeds back local model parameters after training is finished.
3. The federal learning method according to claim 2, wherein the step of distributing the model training task to a target client to cause the target client to extract the federal model from the model training task, train the federal model according to a local data set, and feedback local model parameters after training is completed, comprises:
Distributing the model training task to a target client so that the target client extracts the federation model from the model training task, training the federation model in the model training task according to a local data set, acquiring model parameters of the federation model after training, storing the model parameters into a preset blockchain, and feeding back the model parameters as local model parameters.
4. The federal learning method according to claim 3, wherein the step of receiving the local model parameters fed back by the target client and performing security check on the local model parameters based on a preset blockchain comprises:
receiving local model parameters fed back by the target client, and extracting model identification information from the local model parameters;
searching parameter verification data in a preset blockchain according to the model identification information;
and if the local model parameters are consistent with the parameter verification data, judging that the safety verification is passed.
5. The federal learning method according to claim 4, wherein the step of determining that the security check passes if the local model parameter is consistent with the parameter check data comprises:
Carrying out hash operation on the local model parameters to obtain parameter hash values;
and if the parameter hash value is consistent with the parameter verification data, judging that the safety verification is passed.
6. The federal learning method according to claim 1, wherein the step of updating the federal model based on the local model parameters when the security check passes comprises:
taking the updated federal model as a model to be detected;
detecting whether the model to be detected meets a preset global convergence condition or not;
if not, a new model training task is constructed according to the model to be detected, and the step of distributing the model training task to the target client is returned.
7. The federal learning method according to claim 6, wherein the step of detecting whether the updated federal model satisfies a preset global convergence condition comprises:
if yes, the model to be detected is sent to the target client, so that the target client carries out multi-round training on the model to be detected according to a local data set according to preset rounds, and training on the model to be detected is stopped when the trained model to be detected meets a local convergence condition.
8. A federal learning apparatus, comprising:
the task construction module is used for initializing a federation model and constructing a model training task corresponding to the federation model;
the task distribution module is used for distributing the model training task to a target client so that the target client trains the federal model carried in the model training task;
the parameter verification module is used for receiving local model parameters fed back by the target client and carrying out safety verification on the local model parameters based on a preset block chain;
and the model updating module is used for updating the federal model according to the local model parameters when the safety verification passes.
9. A federal learning apparatus, the federal learning apparatus comprising: a processor, a memory and a federal learning program stored on the memory and executable on the processor, which federal learning program when executed by the processor implements the steps of the federal learning method according to any one of claims 1-7.
10. A computer readable storage medium, wherein a federal learning program is stored on the computer readable storage medium, which when executed implements the steps of the federal learning method according to any one of claims 1-7.
CN202310004000.8A 2023-01-03 2023-01-03 Federal learning method, apparatus, device and storage medium Pending CN116910524A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310004000.8A CN116910524A (en) 2023-01-03 2023-01-03 Federal learning method, apparatus, device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310004000.8A CN116910524A (en) 2023-01-03 2023-01-03 Federal learning method, apparatus, device and storage medium

Publications (1)

Publication Number Publication Date
CN116910524A true CN116910524A (en) 2023-10-20

Family

ID=88365502

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310004000.8A Pending CN116910524A (en) 2023-01-03 2023-01-03 Federal learning method, apparatus, device and storage medium

Country Status (1)

Country Link
CN (1) CN116910524A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118170772A (en) * 2024-02-21 2024-06-11 中电信人工智能科技(北京)有限公司 Model training method, device, storage medium and electronic device
CN118690916A (en) * 2024-07-25 2024-09-24 中维建技术有限公司 Power consumption prediction model optimization method and system
CN119398881A (en) * 2024-12-31 2025-02-07 杭州云娱智慧科技有限公司 A ticket recommendation method and system based on artificial intelligence

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118170772A (en) * 2024-02-21 2024-06-11 中电信人工智能科技(北京)有限公司 Model training method, device, storage medium and electronic device
CN118690916A (en) * 2024-07-25 2024-09-24 中维建技术有限公司 Power consumption prediction model optimization method and system
CN119398881A (en) * 2024-12-31 2025-02-07 杭州云娱智慧科技有限公司 A ticket recommendation method and system based on artificial intelligence

Similar Documents

Publication Publication Date Title
US11985253B2 (en) Non-fungible token authentication
US11836583B2 (en) Method, apparatus and system for secure vertical federated learning
CN110991622B (en) Machine learning model processing method based on block chain network and node
Liu et al. Blockchain and machine learning for communications and networking systems
CN116910524A (en) Federal learning method, apparatus, device and storage medium
US10984410B2 (en) Entity-sovereign data wallets using distributed ledger technology
US11048690B2 (en) Contribution of multiparty data aggregation using distributed ledger technology
CN111816252A (en) Drug screening method and device and electronic equipment
US11367055B2 (en) Decentralized pooled mining for enabling proof-of-work on blockchains
US9542864B2 (en) Methods and apparatus for digital steganography
EP4216077A1 (en) Blockchain network-based method and apparatus for data processing, and computer device
CN110912712A (en) Service operation risk authentication method and system based on block chain
CN112631605A (en) Code compiling method, device, equipment and storage medium of federal learning model
CN111291394B (en) False information management method, false information management device and storage medium
CN112631550A (en) Block chain random number generation method, device, equipment and computer storage medium
CN111460394A (en) Copyright file verification method and device and computer readable storage medium
CN110910110B (en) Data processing method and device and computer storage medium
CN112417480A (en) Data storage system and method based on block chain
Yapp et al. Communication-efficient and Scalable Decentralized Federated Edge Learning.
CN104679870B (en) A kind of method of data acquisition for information system
CN103984728B (en) Range query integrity verification method for outsourcing space database
US20210012001A1 (en) Storage medium, information processing method, and information processing apparatus
CN111092935B (en) Data sharing method and virtual training device for machine learning
CN110572302B (en) Diskless local area network scene identification method and device and terminal
US20240046147A1 (en) Systems and methods for administrating a federated learning network

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination