Compilation methods, devices, electronic devices, and storage media

By generating a computation graph and compiling code based on role nodes and conditional statements, the same set of source code is executed by all participants in federated learning, solving the problem of high code complexity in traditional methods and improving development and maintenance efficiency.

CN114489656BActive Publication Date: 2026-06-30WEBANK (CHINA)

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
WEBANK (CHINA)
Filing Date
2020-11-13
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

Traditional federated machine learning and multi-party secure computation methods require developing different code logic for different participating parties, resulting in high code complexity, difficulty in development and maintenance, and poor user experience.

Method used

By generating a computation graph and compiling code based on role nodes and conditional statements, all participants can execute the same set of source code, identify and execute their own operations, and simplify source code development and maintenance.

Benefits of technology

It reduces the complexity of source code development and the difficulty of later maintenance, and improves the maintainability and execution efficiency of the code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114489656B_ABST
    Figure CN114489656B_ABST
Patent Text Reader

Abstract

This invention discloses a compilation method, apparatus, electronic device, and storage medium. The compilation method can be applied to any participant among multiple participants in a horizontal federated learning process. The method includes: obtaining the source code of the horizontal federated learning process; the source code includes multiple operations to be executed and an executor identifier corresponding to each operation, the executor identifier indicating at least one participant executing the operation; generating a corresponding computation graph based on the source code; the computation graph includes role nodes corresponding to each executor identifier in the source code, each role node corresponding to a branch node, the branch node representing the operation corresponding to the executor identifier; generating corresponding judgment statements based on the role nodes in the computation graph, the judgment statements determining whether the first participant is an executor of the operation; and generating compiled code based on the branch nodes of each role node and the judgment statements corresponding to each role node in the computation graph.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing, and more particularly to a compilation method, apparatus, electronic device, and storage medium. Background Technology

[0002] With the continuous development of technology, artificial intelligence has been widely applied, and the value of data has become increasingly prominent. However, with the growing emphasis on data privacy and the release of corresponding policies and regulations in recent years, the traditional approach of acquiring raw data and performing machine learning modeling is no longer convenient or feasible. People have begun to turn to methods such as federated machine learning or multi-party secure computation for modeling.

[0003] Federated machine learning or multi-party secure computation involves information transmission and scheduling among multiple participants, typically requiring explicit encryption of information transmission during code development. This necessitates different code logic implementations for each participant with a different role, leading to code complexity and making development and maintenance difficult. It also increases the development and learning costs of the corresponding machine learning methods, resulting in a poor user experience. Summary of the Invention

[0004] The main objective of this invention is to provide a compilation method, apparatus, electronic device, and storage medium, which aims to enable each participant to execute their own code from the same set of source code through compilation, thereby simplifying the complexity of source code writing and improving the efficiency of source code development and maintenance.

[0005] To achieve the above objectives, this invention provides a compilation method applied to a first participant among multiple participants in a horizontal federated learning process. The method includes: obtaining the source code of the horizontal federated learning process; the source code includes multiple operations to be executed and an executor identifier corresponding to each operation, the executor identifier indicating at least one participant executing the operation; generating a corresponding computation graph based on the source code; the computation graph includes role nodes corresponding to each executor identifier in the source code, each role node corresponding to a branch node, the branch node representing the operation corresponding to the executor identifier; generating corresponding judgment statements based on the role nodes in the computation graph, the judgment statements determining whether the first participant is an executor of the operation; and generating compiled code based on the branch nodes of each role node in the computation graph and the judgment statements corresponding to each role node.

[0006] Optionally, the method further includes:

[0007] Based on the computation graph, determine the node where the unilateral data provided by each participant is located;

[0008] An encrypted node is added after the node containing the unilateral data provided by each participating party.

[0009] Based on the encryption node, an encryption statement is generated to encrypt the unilateral data;

[0010] The process of generating compiled code based on the branch nodes of each role node in the computation graph and the corresponding judgment statements for each role node includes:

[0011] Based on the branch nodes of each role node in the computation graph, the judgment statement corresponding to each role node, and the encryption statement, the compiled code is generated.

[0012] Optionally, the plurality of operations to be performed include: a data transmission operation; the data transmission operation is used to indicate the transmission direction of the model training data, which is calculated based on unilateral data;

[0013] The step of generating the corresponding computation graph based on the source code includes:

[0014] Based on the data transmission operation, a corresponding data transmission node is generated;

[0015] The method further includes:

[0016] Generate corresponding data transmission statements based on the data transmission nodes;

[0017] The process of generating compiled code based on the branch nodes of each role node in the computation graph and the corresponding judgment statements for each role node includes:

[0018] Based on the branch nodes of each role node in the computation graph, the judgment statements corresponding to each role node, and the data transmission statements, the compiled code is generated.

[0019] Optionally, generating the corresponding computation graph based on the source code further includes:

[0020] Add an encryption node before the data transmission node;

[0021] The method further includes:

[0022] Based on the encryption node, an encryption statement is generated to encrypt the model training data.

[0023] Optionally, generating the encryption statement for encrypting the model training data includes:

[0024] If the data transmission function corresponding to the encrypted node points to the coordinator among the participants, then an encrypted statement for encrypting the model training data is generated based on the coordinator's public key.

[0025] Optionally, generating the corresponding data transmission statement based on the data transmission node includes:

[0026] Based on the role node corresponding to the data transmission node and the data transmission direction corresponding to the data transmission node, a corresponding data transmission statement is generated.

[0027] Optionally, the plurality of operations to be performed include: data decryption operation;

[0028] The step of generating the corresponding computation graph based on the source code includes:

[0029] Based on the data decryption operation, a corresponding data decryption node is generated;

[0030] The method further includes:

[0031] Based on the data decryption node, generate the corresponding data decryption statement;

[0032] The process of generating compiled code based on the branch nodes of each role node in the computation graph and the corresponding judgment statements for each role node includes:

[0033] Based on the branch nodes of each role node in the computation graph, the judgment statements corresponding to each role node, and the data decryption statements, the compiled code is generated.

[0034] The present invention also provides a compilation apparatus, comprising:

[0035] The acquisition module is used to acquire the source code of the horizontal federated learning; the source code includes multiple operations to be executed and an executor identifier corresponding to each operation, the executor identifier being used to indicate at least one participant in executing the operation;

[0036] The computation graph generation module is used to generate a corresponding computation graph based on the source code; the computation graph includes role nodes corresponding to each executor identifier in the source code, each role node has a corresponding branch node, and the branch node is used to represent the operation corresponding to the executor identifier;

[0037] The target code generation module is used to generate corresponding judgment statements based on the role nodes in the computation graph. The judgment statements are used to determine whether the first participant belongs to the executor of the operation. The module also generates compiled code based on the branch nodes of each role node in the computation graph and the judgment statements corresponding to each role node.

[0038] The present invention also provides an electronic device, the electronic device comprising: a memory, a processor, and a compiler stored in the memory and executable on the processor, wherein the compiler, when executed by the processor, implements the steps of the compilation method as described above.

[0039] The present invention also provides a computer-readable storage medium storing a compiler, which, when executed by a processor, implements the steps of the compilation method described above.

[0040] This invention provides a compilation method, apparatus, electronic device, and storage medium. The compilation method can be applied to a first participant among multiple participants in a horizontal federated learning process, where the first participant can be any party. The method includes: obtaining source code for the horizontal federated learning process; the source code includes multiple operations to be executed and an executor identifier corresponding to each operation, the executor identifier indicating at least one participant executing the operation; generating a corresponding computation graph based on the source code; the computation graph includes role nodes corresponding to each executor identifier in the source code, each role node corresponding to a branch node, the branch node representing the operation corresponding to the executor identifier; generating corresponding judgment statements based on the role nodes in the computation graph, the judgment statements determining whether the first participant is an executor of the operation; and generating compiled code based on the branch nodes of each role node and the judgment statements corresponding to each role node in the computation graph. Each participant can use this compilation method to compile the source code. During the compilation process, the executor identifier corresponding to each operation in the source code is identified, and corresponding role nodes are generated based on the executor identifier, thereby generating a computation graph corresponding to the source code, and then the compiled code is generated based on each node in the computation graph. When each participant executes the compiled code, upon reaching the code corresponding to a conditional statement, it can determine whether it belongs to the executor of the corresponding operation and automatically execute its own operation, thus cooperating to complete the vertical federated learning process. In other words, this compilation method is the underlying foundation for supporting source code simplification. Because the compilation method supports generating corresponding conditional statements based on the executor identifier in the source code, it compiles the source code into executable code. Therefore, only the executor of each operation needs to be marked in the source code. This simplifies the original separate source code applicable to multiple participants into a single set of source code applicable to all participants. Furthermore, since each operation's executor is at least one participant, identical operations across parties can be integrated into the same code segment using the "executor identifier," further simplifying the source code. This reduces the complexity of source code development and the difficulty of later maintenance. Attached Figure Description

[0041] Figure 1 A schematic diagram illustrating an application scenario provided by the present invention;

[0042] Figure 2 A flowchart of a compilation method provided in an embodiment of the present invention;

[0043] Figure 3 A schematic diagram of a source code segment provided for an embodiment of the present invention;

[0044] Figure 4 A method provided for an embodiment of the present invention Figure 3 The computation graph generated by parsing the code segment in the code;

[0045] Figure 5 This is a schematic diagram of a horizontal federated learning process provided in an embodiment of the present invention;

[0046] Figure 6 This is a schematic diagram of the structure of a compiler device provided in an embodiment of the present invention;

[0047] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.

[0048] The realization of the objective, functional features and advantages of the present invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0049] Exemplary embodiments of the present disclosure will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.

[0050] In many fields, technologies such as machine learning and model training based on big data are constantly evolving. Mining big data can yield a wealth of valuable information. With technological advancements, the sources of raw data are becoming increasingly diverse, even involving cross-domain collaborations. However, in recent years, there has been a growing emphasis on data privacy, along with the issuance of corresponding policies and regulations. This has rendered the traditional approach of acquiring raw data from multiple sources and performing machine learning modeling inconvenient and impractical. Federated machine learning and multi-party secure computation have emerged as solutions to address this need.

[0051] Federated machine learning, or multi-party secure computation, typically involves encrypted information transmission between multiple participants. Federated learning is an emerging foundational artificial intelligence technology designed to enable efficient machine learning across multiple participants or computing nodes while ensuring information security during big data exchange, protecting endpoint and personal data privacy, and guaranteeing legal compliance. The machine learning algorithms used in federated learning are not limited to neural networks but also include important algorithms such as random forests.

[0052] For different datasets, federated learning is divided into horizontal federated learning, horizontal federated learning and federated transfer learning.

[0053] Horizontal federated learning refers to a model training scenario where two datasets have significant overlap in user features but minimal overlap in users. Therefore, the datasets are split horizontally (i.e., along the user dimension), and the portion with shared user features but not identical users is used for training. For example, consider two banks in different regions whose user groups originate from their respective areas with minimal overlap. However, their businesses are similar, resulting in shared user characteristics. In this case, horizontal federated learning can be used to construct a joint model.

[0054] In horizontal federated learning, multiple data providers may offer sample data for model training. However, each provider's data is independent, and a coordinator is needed to update the model parameters during training. Specifically, each data provider calculates its own model gradient using its sample data and transmits it to the coordinator. The coordinator then aggregates the gradients from all providers to obtain the integrated gradient, updates the model weights, and feeds it back to each data provider. The data providers then use the updated model weights to update their local models. To prevent the inference of sample data from gradients, encryption is required during transmission, primarily involving encrypted gradient exchange between the data providers and the coordinator.

[0055] Because it involves multi-party collaboration, and the execution operations of each party are not entirely the same, implementing the above-mentioned horizontal federated learning process generally requires developing corresponding source code for each role participating in the federated learning. This results in extremely complex and numerous source codes used to complete federated learning, leading to high machine learning costs, a poor user development experience, and significant difficulties in later maintenance and modification of the source code.

[0056] To address the aforementioned problems, this invention proposes a compilation method that identifies executor identifiers within the source code during compilation and generates corresponding conditional statements based on these identifiers. This allows participating parties to execute their own code segments by executing these conditional statements during the compilation process, enabling all parties to collaboratively complete the federated learning process. Based on this compilation method, the code for horizontal federated learning can be written within the same source code during development, eliminating the need to develop separate source codes for different participating parties. This significantly reduces the complexity of source code development.

[0057] Figure 1 This is a schematic diagram illustrating an application scenario provided by the present invention. For example... Figure 1As shown, users write source code for lateral logistic regression on their client-side according to their business needs. This source code is then sent to the various participants in the lateral logistic regression (the diagram shows three participants; the specific number of participants depends on the actual scenario). Each participant compiles the source code, generating executable machine code, and runs it. During execution, each participant performs the operations corresponding to its role. The participants cooperate to achieve the training and / or prediction process of lateral logistic regression, thereby updating the parameters of the longitudinal federated learning model.

[0058] Figure 2 This is a flowchart illustrating a compilation method according to an embodiment of the present invention. The execution entity of the compilation method provided in this embodiment is any one of the multiple participants in a horizontal federated learning process, referred to as the first participant. For example... Figure 2 As shown, the method in this embodiment may include:

[0059] S201. Obtain the source code for horizontal federated learning; the source code includes multiple operations to be executed and the executor identifier corresponding to each operation. The executor identifier is used to indicate at least one participant in executing the operation.

[0060] As mentioned above, horizontal federated learning is completed by multiple participants, each corresponding to one of the two roles in horizontal federated learning: data provider and coordinator.

[0061] In this invention, the operation corresponds to a meaningful code segment, which is a code segment separated by the executor identifier.

[0062] In horizontal federated learning, participants refer to the various parties involved, which can be multiple. Examples include data provider 1, data provider 2, data provider 3, etc., who also calculate the model parameters. Each participant can also participate in training using one or more device nodes. However, the roles of each participant are essentially twofold: providers of feature and target variables, i.e., the data provider (host, abbreviated as H), and coordinator (arbiter, abbreviated as A).

[0063] For example, a role conditional function `role()` can be defined as the executor identifier. The parameter of this function is the role (H, A) of the participants in the horizontal federated learning. In this example, if the executor identifier corresponding to a certain code segment is `role(H)`, then the executor of this code segment is H.

[0064] S202. Generate the corresponding computation graph based on the source code. The computation graph includes role nodes corresponding to each executor identifier in the source code. Each role node has a corresponding branch node, which is used to represent the operation corresponding to the executor identifier.

[0065] The source code is parsed to generate a computation graph. The executor identifiers in the source code correspond to role nodes in the computation graph, and each operation corresponds to a branch node of that role node. Each branch node in the computation graph can be data or a corresponding logical method, and the paths between branches represent logical relationships. The computation graph can be used to represent the data processing logic of individual data.

[0066] Figure 3 This is a schematic diagram of a source code segment provided for an embodiment of the present invention. Figure 4 To Figure 3 The computation graph is generated by parsing the code segment in the source code. Each node is represented as a tensor. The node with role(host) is the role node corresponding to the executor identifier with role(H) in the source code. Other nodes are branch nodes corresponding to the role nodes, implementing the initialization operations for the data of x, y, and w. "Literal" represents a constant. Specifically, "Literal([[]])" represents the constant value of the corresponding parent node. In addition, the computation graph can also contain nodes representing operators and methods. For example, "Op" represents an operator, and "Op.method" represents a method possessed by the operator.

[0067] S203. Based on the role nodes in the computation graph, generate corresponding judgment statements. These judgment statements are used to determine whether the first participant is the executor of the operation.

[0068] The source code only contains role identifiers, and the corresponding computation graph only contains role nodes. The executing device itself cannot automatically identify and determine which part of the code it needs to execute. Therefore, during the compilation process, a corresponding conditional statement needs to be generated for each role node. This statement is then executed by the executing device when executing the compiled code to determine whether to execute the corresponding code segment.

[0069] After parsing and generating the computation graph, corresponding conditional statements are generated based on the nodes where the role functions are located. Specifically, the paths between nodes can be adjusted to generate role-based judgment logic. For example, based on the data processing logic represented by the computation graph, adjustments can be made at the nodes corresponding to the role identifiers of the participants, possibly by adding, deleting, or modifying corresponding nodes, or by adding, deleting, or modifying the paths between corresponding nodes. Correspondingly, this is equivalent to generating corresponding conditional statements at the code level.

[0070] by Figure 4 Taking the computation graph as an example, the code generated after the conditional statement `with role(host)` for the role node should roughly mean: "Is the first participant H? If yes, execute the following branch node; otherwise, proceed to another operation." If the current first participant is H, then the subsequent initialization operation will be executed.

[0071] S204. Generate compiled code based on the branch nodes of each role node in the computation graph and the judgment statements corresponding to each role node.

[0072] Source code can be programs written in interpreted languages, such as Python. While Python, as an interpreted language, is simple and easy to learn, it cannot be directly understood by machines and therefore needs to be compiled into machine language. Similarly, although computational graphs can represent data processing logic, machines cannot directly understand them either, and compiled code still needs to be generated from them.

[0073] The compilation method provided in this embodiment can be applied to the first participant in a horizontal federated learning process, where the first participant can be any party. The method includes: obtaining the source code of the horizontal federated learning process; the source code includes multiple operations to be executed and an executor identifier corresponding to each operation, the executor identifier indicating at least one participant executing the operation; generating a corresponding computation graph based on the source code; the computation graph includes role nodes corresponding to each executor identifier in the source code, each role node corresponding to a branch node, the branch node representing the operation corresponding to the executor identifier; generating corresponding judgment statements based on the role nodes in the computation graph, the judgment statements determining whether the first participant is an executor of the operation; and generating compiled code based on the branch nodes of each role node and the judgment statements corresponding to each role node in the computation graph. Each participant can use this compilation method to compile the source code. During the compilation process, the executor identifier corresponding to each operation in the source code is identified, and corresponding role nodes are generated based on the executor identifier, thereby generating a computation graph corresponding to the source code, and then the compiled code is generated based on each node in the computation graph. When each participant executes the compiled code, upon reaching the code corresponding to a conditional statement, it can determine whether it belongs to the executor of the corresponding operation and automatically execute its own operation, thus cooperating to complete the vertical federated learning process. In other words, this compilation method is the underlying foundation for supporting source code simplification. Because the compilation method supports generating corresponding conditional statements based on the executor identifier in the source code, it compiles the source code into executable code. Therefore, only the executor of each operation needs to be marked in the source code. This simplifies the original separate source code applicable to multiple participants into a single set of source code applicable to all participants. Furthermore, since each operation's executor is at least one participant, identical operations across parties can be integrated into the same code segment using the "executor identifier," further simplifying the source code. This reduces the complexity of source code development and the difficulty of later maintenance.

[0074] Based on the above explanation of horizontal federated learning, it is clear that during model training and use, the data provided by the data provider is only used locally. Therefore, it can be considered that the data provided by a particular party is always solely owned by that party. Hence, in this invention, it is referred to as unilateral data.

[0075] Specifically, based on the computation graph, the nodes containing the unilateral data provided by each participant can be determined; encryption nodes can be added after the nodes containing the unilateral data provided by each participant; and encryption statements for encrypting the unilateral data can be generated based on the encryption nodes. Correspondingly, the compiled code generated based on the branch nodes of each role node and the corresponding judgment statements in the computation graph can specifically include: generating compiled code based on the branch nodes of each role node, the corresponding judgment statements, and the encryption statements in the computation graph.

[0076] In horizontal federated learning, data encryption is required whenever data transmission is involved. (Reference) Figure 5 The diagram illustrating horizontal federated learning shows that the process primarily involves the transmission of one type of data: model training data between data providers and the coordinator. In this invention, model training data refers to parameters that can guide model training or indicate its effectiveness, such as the loss function and its convergence state. To reduce source code complexity, the encryption steps can be omitted during source code writing; instead, encryption statements can be added by finding the corresponding nodes during compilation.

[0077] Specifically, the aforementioned operations to be executed include: data transmission operations. Data transmission operations are used to indicate the transmission direction of model training data, which is calculated based on the unilateral data. The aforementioned generation of the corresponding computation graph based on the source code may include: generating corresponding data transmission nodes based on the data transmission operations; and then generating corresponding data transmission statements based on the data transmission nodes. Correspondingly, the aforementioned generation of compiled code based on the branch nodes of each role node in the computation graph and the corresponding judgment statements of each role node includes: generating compiled code based on the branch nodes of each role node in the computation graph, the corresponding judgment statements of each role node, and the data transmission statements.

[0078] For model training data, based on the principles of lateral federated learning, interaction typically occurs between the data provider H and the coordinator A. The transmission direction may differ depending on the specific parameters. Correspondingly, instead of writing corresponding code for encryption and transmission in the source code, encryption and transmission nodes can be added during compilation by determining the nodes where the corresponding data resides. Alternatively, the transmission direction for different parameters can be represented in the source code using data transmission functions. During parsing, the transmission direction and the addition of encryption nodes are determined by locating the corresponding nodes of the data transmission functions.

[0079] Furthermore, if the data transmission function corresponding to the added encryption node points to the coordinator among the participants, then an encryption statement for encrypting the model training data is generated based on the coordinator's public key. The coordinator's public key can be pre-stored at each participant and retrieved directly from their local machine during the encryption step.

[0080] Specifically, when generating data transmission statements based on data transmission functions, the corresponding data transmission statements can be generated according to the data transmission function, its parameters, and the first participant. Data transmission functions can be divided into two categories based on the data transmission direction: sending functions and receiving functions. Sending and receiving are determined primarily by the participant executing the transmission step. The parameters of the data transmission function are the identifiers of the participants at the other end of the data transmission direction. Thus, combining these three elements determines the specific transmission direction of the data. For example, if the data transmission function is a receiving function, and its parameter in a certain code segment is H, and the identifier of the participant in that code segment is A, then the transmission direction of the data can be determined as from H to A.

[0081] Similar to encryption, the decryption process can also be omitted from the source code and correspondingly incorporated into the encoding process. (Reference) Figure 5 Based on the process of horizontal federated learning, it is known that decryption is only required after the coordinator receives the data. Therefore, it is not necessary to write the corresponding code for the decryption steps in the source code. Instead, the node containing the received data can be determined during compilation, and the decryption node can be added subsequently. Alternatively, the decryption steps can be represented by a decryption function in the source code. During parsing, the decryption statement is generated by locating the corresponding node of this decryption function. Specifically, the key in the decryption statement can be the coordinator's private key.

[0082] In a specific embodiment, a federated learning model training function can be defined, which can be defined as def f(train_data, params). The two input parameters of this function are the training data "train_data" and the model training-related parameters "params". The model training-related parameters can include three parameters: the loss tolerance value tol, the learning rate learning_rate, and the maximum number of training epochs max_iter.

[0083] In actual federated learning, calling this function and inputting the relevant data corresponding to the parameters will initiate the model training process, which involves executing the source code corresponding to this function.

[0084] The source code may include an initialization program, a model training program, and a prediction program for the trained model.

[0085] The initialization process initializes the data provided by H (since the data provided by each data provider has the same structure, they can be considered as the same entity). For H, the data provided by H is defined as x (sample data), y (label), and w (weight).

[0086] During training, data from H is used in calculations to obtain the loss value `fed_loss` and the gradient value `fed_grad`, which are then sent to A. Upon receiving the loss value, A decrypts it and determines whether the loss function has converged based on the loss value and a preset loss tolerance. A then sends the convergence status to H and determines the weight change based on the gradient value and a preset learning rate, which is also sent to H. If the loss function has not converged, H updates the model weights based on the weight change. The entire training process needs to loop until the loss function converges or until the preset maximum number of training epochs is reached.

[0087] The prediction process is performed by H. For H, the intermediate prediction result pred is obtained based on the sample data and weight data, and the pred is transformed by sigmoid to obtain the prediction probability prob.

[0088] After writing the source code, users can send and store it on the electronic devices of all parties involved in the federated learning process, so that each participant can optimize the federated learning model by executing the source code.

[0089] When running this source code, the compilation method of this invention can be used to compile the source code, generate machine code, and then execute the compiled machine code.

[0090] In horizontal federated learning, model training methods can employ logistic regression or linear regression to calculate parameters such as the loss function and its gradient during the training process.

[0091] For example, in logistic regression, let the data feature of H be x, and the weights of the logistic regression function of H be . The corresponding loss function l(w) and the gradient of the loss function are... The calculation formula can be found in the following formula:

[0092]

[0093]

[0094] Based on the above formula, corresponding source code can be written to represent the specific calculation process.

[0095] For example, in linear regression, let the data features of H be x, and the weights of the logistic regression function of H be w. The corresponding loss function l(w) and the gradient of the loss function... The calculation formula can be found in the following formula:

[0096]

[0097]

[0098] Based on the above formula, corresponding source code can be written to represent the specific calculation process.

[0099] Figure 6 A schematic diagram of a compiler apparatus is provided as an example of an embodiment of the present invention, as shown below. Figure 6 As shown, the compilation device includes: an acquisition module 601, a computation graph generation module 602, and an object code generation module 603.

[0100] The acquisition module 601 is used to acquire the source code of the horizontal federated learning; the source code includes multiple operations to be executed and an executor identifier corresponding to each operation, the executor identifier being used to indicate at least one participant in executing the operation;

[0101] The computation graph generation module 602 is used to generate a corresponding computation graph based on the source code; the computation graph includes role nodes corresponding to each executor identifier in the source code, each role node has a corresponding branch node, and the branch node is used to represent the operation corresponding to the executor identifier;

[0102] The target code generation module 603 is used to generate corresponding judgment statements based on the role nodes in the computation graph. The judgment statements are used to determine whether the first participant belongs to the executor of the operation. Based on the branch nodes of each role node in the computation graph and the judgment statements corresponding to each role node, the module generates compiled code.

[0103] Optionally, the device 600 further includes: a node processing module 604, configured to determine the node containing the unilateral data provided by each participant according to the computation graph; and to add an encryption node after the node containing the unilateral data provided by each participant. The target code generation module 603 is further configured to generate encryption statements for encrypting the unilateral data based on the encryption nodes. When generating compiled code based on the branch nodes of each role node in the computation graph and the corresponding judgment statements of each role node, the target code generation module 603 is specifically configured to: generate compiled code based on the branch nodes of each role node in the computation graph, the corresponding judgment statements of each role node, and the encryption statements.

[0104] Optionally, the plurality of operations to be executed include: a data transmission operation, wherein the data transmission operation is used to indicate the transmission direction of model training data, and the model training data is calculated based on the unilateral data. The computation graph generation module 602, when generating a corresponding computation graph based on the source code, is specifically used to: generate corresponding data transmission nodes based on the data transmission operation. The target code generation module 603 is further used to generate corresponding data transmission statements based on the data transmission nodes. When generating compiled code based on the branch nodes of each role node in the computation graph and the judgment statements corresponding to each role node, the target code generation module 603 is specifically used to: generate compiled code based on the branch nodes of each role node in the computation graph, the judgment statements corresponding to each role node, and the data transmission statements.

[0105] Optionally, when generating the corresponding computation graph based on the source code, the computation graph generation module 602 is further configured to add an encryption node before the data transmission node. The target code generation module 603 is further configured to generate an encryption statement for encrypting the model training data based on the encryption node.

[0106] Optionally, when generating the encryption statement to encrypt the model training data, the target code generation module 603 is specifically used to generate the encryption statement to encrypt the model training data based on the coordinator's public key if the transmission direction of the data transmission function corresponding to the encryption node points to the coordinator among the participants.

[0107] Optionally, when the target code generation module 603 generates the corresponding data transmission statement based on the data transmission node, it is specifically used to generate the corresponding data transmission statement based on the role node corresponding to the data transmission node and the data transmission direction corresponding to the data transmission node.

[0108] Optionally, the plurality of operations to be executed include: a data decryption operation. When generating the corresponding computation graph based on the source code, the computation graph generation module 602 is specifically used to generate corresponding data decryption nodes based on the data decryption operation. The target code generation module 603 is also used to generate corresponding data decryption statements based on the data decryption nodes. When generating compiled code based on the branch nodes of each role node in the computation graph and the judgment statements corresponding to each role node, the target code generation module 603 is specifically used to generate compiled code based on the branch nodes of each role node in the computation graph, the judgment statements corresponding to each role node, and the data decryption statements.

[0109] The compilation apparatus provided in the embodiments of the present invention can execute the compilation method provided in any embodiment of the present invention, and has the functional modules corresponding to the above-described compilation method and the same beneficial effects as the above-described compilation method, which will not be elaborated here.

[0110] Figure 7 This is a schematic diagram of the structure of an electronic device provided in one embodiment of the present invention, as shown below. Figure 7 As shown, the electronic device 700 includes: a memory 701, a processor 702, and a computer program.

[0111] The computer program is stored in memory 701 and configured to be executed by processor 702 to implement the compilation method provided in any embodiment of the present invention.

[0112] The memory 701 and the processor 702 are connected via a bus.

[0113] The relevant explanations can be understood by referring to the corresponding descriptions and effects in the above embodiments, and will not be elaborated further here.

[0114] The present invention also provides a computer-readable storage medium having a computer program stored thereon, the computer program being executed by a processor to implement the compilation method provided in any of the embodiments described above.

[0115] The computer-readable storage medium can be ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.

[0116] In the several embodiments provided by this invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for instance, the division of modules is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or modules, and may be electrical, mechanical, or other forms.

[0117] The modules described as separate components may or may not be physically separate. The components shown as modules may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.

[0118] Furthermore, the functional modules in the various embodiments of the present invention can be integrated into one processing unit, or each module can exist physically separately, or two or more modules can be integrated into one unit. The unit composed of the above modules can be implemented in hardware or in the form of hardware plus software functional units.

[0119] The integrated modules described above, implemented as software functional modules, can be stored in a computer-readable storage medium. These software functional modules, stored in a storage medium, include several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute some steps of the methods described in the various embodiments of the present invention.

[0120] It should be understood that the aforementioned processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. A general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly manifested as being executed by a hardware processor, or executed by a combination of hardware and software modules within the processor.

[0121] The memory may include high-speed RAM, and may also include non-volatile storage (NVM), such as at least one disk storage device, and may also be a USB flash drive, external hard drive, read-only memory, disk or optical disc, etc.

[0122] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.

[0123] The aforementioned storage medium can be implemented from any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The storage medium can be any available medium accessible to general-purpose or special-purpose computers.

[0124] An exemplary storage medium is coupled to a processor, enabling the processor to read information from and write information to the storage medium. Alternatively, the storage medium can be an integral part of the processor. Both the processor and the storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and storage medium can exist as discrete components in an electronic device or host device.

[0125] 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. Unless otherwise specified, 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.

[0126] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0127] 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, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0128] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.

Claims

1. A compilation method, characterized in that, The method, applied to the first participant among multiple participants in horizontal federated learning, includes: Obtain the source code for horizontal federated learning; the source code includes multiple operations to be executed and an executor identifier corresponding to each operation, the executor identifier being used to indicate at least one participant executing the operation; Based on the source code, a corresponding computation graph is generated; the computation graph includes role nodes corresponding to each executor identifier in the source code, and each role node has a corresponding branch node, which is used to represent the operation corresponding to the executor identifier. Based on the role nodes in the computation graph, a corresponding judgment statement is generated, which is used to determine whether the first participant belongs to the executor of the operation; Based on the branch nodes of each role node in the computation graph and the judgment statements corresponding to each role node, the compiled code is generated; The method further includes: Based on the computation graph, the node containing the unilateral data provided by each participant is determined; the unilateral data refers to data provided by a certain party that is always owned by that party alone. An encrypted node is added after the node containing the unilateral data provided by each participating party. Based on the encryption node, an encryption statement is generated to encrypt the unilateral data; The process of generating compiled code based on the branch nodes of each role node in the computation graph and the corresponding judgment statements for each role node includes: Based on the branch nodes of each role node in the computation graph, the judgment statement corresponding to each role node, and the encryption statement, the compiled code is generated; The plurality of operations to be executed include: a data transmission operation; the data transmission operation is used to indicate the transmission direction of the model training data, which is calculated based on unilateral data; The step of generating the corresponding computation graph based on the source code includes: Based on the data transmission operation, a corresponding data transmission node is generated; The method further includes: Generate corresponding data transmission statements based on the data transmission nodes; The process of generating compiled code based on the branch nodes of each role node in the computation graph and the corresponding judgment statements for each role node includes: Based on the branch nodes of each role node in the computation graph, the judgment statements corresponding to each role node, and the data transmission statements, the compiled code is generated; The step of generating the corresponding computation graph based on the source code further includes: Add an encryption node before the data transmission node; The method further includes: Based on the encryption node, an encryption statement is generated to encrypt the model training data.

2. The method according to claim 1, characterized in that, The generation of the encryption statement for encrypting the model training data includes: If the data transmission function corresponding to the encrypted node points to the coordinator among the participants, then an encrypted statement for encrypting the model training data is generated based on the coordinator's public key.

3. The method according to claim 1, characterized in that, The step of generating a corresponding data transmission statement based on the data transmission node includes: Based on the role node corresponding to the data transmission node and the data transmission direction corresponding to the data transmission node, a corresponding data transmission statement is generated.

4. The method according to claim 1, characterized in that, The multiple operations to be performed include: data decryption; The step of generating the corresponding computation graph based on the source code includes: Based on the data decryption operation, a corresponding data decryption node is generated; The method further includes: Based on the data decryption node, generate the corresponding data decryption statement; The process of generating compiled code based on the branch nodes of each role node in the computation graph and the corresponding judgment statements for each role node includes: Based on the branch nodes of each role node in the computation graph, the judgment statements corresponding to each role node, and the data decryption statements, the compiled code is generated.

5. A compilation apparatus for performing the compilation method as described in any one of claims 1 to 4, characterized in that, include: The acquisition module is used to acquire the source code of the horizontal federated learning; the source code includes multiple operations to be executed and an executor identifier corresponding to each operation, the executor identifier being used to indicate at least one participant in executing the operation; The computation graph generation module is used to generate a corresponding computation graph based on the source code; the computation graph includes role nodes corresponding to each executor identifier in the source code, each role node has a corresponding branch node, and the branch node is used to represent the operation corresponding to the executor identifier; The target code generation module is used to generate corresponding judgment statements based on the role nodes in the computation graph. The judgment statements are used to determine whether the first participant belongs to the executor of the operation. Based on the branch nodes of each role node in the computation graph and the corresponding judgment statement for each role node, the compiled code is generated.

6. An electronic device, characterized in that, The electronic device includes: a memory, a processor, and a compiler stored in the memory and executable on the processor, wherein the compiler, when executed by the processor, implements the steps of the compilation method as described in any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a compiler, which, when executed by a processor, implements the steps of the compilation method as described in any one of claims 1 to 4.