A computing graph splitting method and device, electronic equipment and storage medium
By performing point reduction and segmentation on the unidirectional acyclic graph of the neural network model, the problem of time-consuming training and inference of large-scale neural network models is solved, achieving more efficient computation graph optimization and processing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-22
- Publication Date
- 2026-03-17
AI Technical Summary
As the size of neural network models increases, hardware resource limitations lead to excessively long training and inference processes, and existing technologies struggle to effectively optimize the computation graph to improve processing efficiency.
By obtaining the unidirectional acyclic graph of the network model, nodes that do not participate in operator fusion are marked as first-class nodes, and point contraction is performed based on the termination and start nodes to obtain a contracted graph, thereby dividing the computation graph, reducing the dependencies between sub-computation graphs and reducing the number of sub-computation graphs.
This improves the processing efficiency of the network model, increases the probability of parallel processing of sub-computation graphs, and reduces the number of sub-computation graphs, facilitating later operator fusion and improving model optimization efficiency.
Smart Images

Figure CN116861952B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of information processing technology, and in particular to a computational graph segmentation method, apparatus, electronic device, and storage medium. Background Technology
[0002] As the size of neural network models continues to increase, the training and inference processes become increasingly time-consuming due to limitations in hardware computing power. To reduce the training and inference time of neural network models, optimization is necessary. Summary of the Invention
[0003] The purpose of this application is to provide a computation graph segmentation method, apparatus, electronic device, and storage medium to segment the computation graph of the part to be optimized in a network model, resulting in lower dependencies between the segmented sub-computation graphs and a smaller number of sub-computation graphs, thereby improving the processing efficiency of the network model. The specific technical solution is as follows:
[0004] This application provides a computational graph segmentation method, the method comprising:
[0005] Obtain the one-way acyclic graph corresponding to the part to be optimized in the network model. The one-way acyclic graph includes multiple nodes and relational edges between the nodes. The multiple nodes correspond one-to-one with the operators in the part to be optimized.
[0006] Nodes that are classified as not participating in operator fusion and are determined to be the first type of nodes among the plurality of nodes;
[0007] For each first type of node, the second type of node in the parent node of the first type of node is marked as the shrinking termination node, and the second type of node in the child node of the first type of node is marked as the shrinking start node, wherein the second type of node is any other node in the plurality of nodes other than the first type of node;
[0008] The weight of each relation edge is determined based on the node types of the two nodes connected by each relation edge in the unidirectional acyclic graph.
[0009] Based on the node where the shrinking ends, the node where the shrinking begins, and the weight of each relation edge, the nodes in the unidirectional acyclic graph are shrunk to obtain a shrunk graph.
[0010] The unidirectional acyclic graph is segmented based on the condensed graph to obtain multiple first sub-computation graphs.
[0011] Optionally, the step of performing node shrinking processing on the nodes in the unidirectional acyclic graph based on the shrinking termination node, the shrinking start node, and the weight of each relation edge to obtain a condensed graph includes:
[0012] Based on the weight of each relation edge in the unidirectional acyclic graph, calculate the longest path length between every two second-type nodes in the unidirectional acyclic graph;
[0013] According to the topology of the unidirectional acyclic graph, the first second-type node in the unidirectional acyclic graph that has not undergone node shrinking is determined as the first node, and it is determined whether the first node and the second node satisfy the preset node shrinking rule. The second node is a child node of the first node.
[0014] When the first node and the second node satisfy the preset shrinking rule, the first node and the second node are determined as nodes to be processed;
[0015] If the second node is a second type of node, then the second node is used as the first node, and the step of determining whether the first node and the second node meet the preset shrinking rule is returned until the first node and / or the second node do not meet the preset shrinking rule, and the first node is determined as the node to be processed.
[0016] The nodes to be processed are shrunk to obtain a shrunk one-way acyclic graph. Then, the process returns to the step of determining the first unshrunk second-type node in the shrunk one-way acyclic graph as the first node according to the topology of the shrunk one-way acyclic graph, until the shrunk one-way acyclic graph does not contain any unshrunk second-type nodes, thus obtaining a shrunk one-way graph.
[0017] The preset node shrinking rules include: when the first node is a first type of target node, the first node is not the node shrinking termination node, the second node is not the node shrinking start node, the longest path length between the first second type node that has not undergone node shrinking and the second node is a preset path length, and the node shrinking process after processing the first node and the second node results in a unidirectional acyclic graph; when the first node is a second type of target node, the second node is a second type of node, the longest path length between the first second type node that has not undergone node shrinking and the second node is a preset path length, and the node shrinking process after processing the first node and the second node results in a unidirectional acyclic graph.
[0018] The first type of target node is a second type of node whose parent node is a second type of node; the second type of target node is a second type of node other than the first type of target node.
[0019] Optionally, the step of calculating the longest path length between every two second-type nodes in the unidirectional acyclic graph based on the weight of each relation edge in the unidirectional acyclic graph includes:
[0020] For every two second-type nodes in the unidirectional acyclic graph, determine each path between the two second-type nodes;
[0021] For each path, calculate the path length between the two second-type nodes based on the weight of each relation edge on that path;
[0022] The maximum value among the calculated path lengths is determined as the longest path length between the two second-type nodes.
[0023] Optionally, the step of determining the weight of each relation edge based on the node types of the two nodes connected by each relation edge in the unidirectional acyclic graph includes:
[0024] For each relation edge in the unidirectional acyclic graph, if both nodes connected by the relation edge are nodes of the second type, then the weight of the relation edge is determined to be the first preset weight.
[0025] If the two nodes connected by the relation edge include the first type of node, then the weight of the relation edge is determined to be the second preset weight.
[0026] Optionally, the method further includes:
[0027] For each second sub-computation graph, based on the operator category of the operator corresponding to each node in the second sub-computation graph, the operators corresponding to the second type of nodes in the second sub-computation graph are fused to obtain a third sub-computation graph including the fused operators; the second sub-computation graph is a first sub-computation graph including multiple second type nodes.
[0028] Optionally, the method further includes:
[0029] According to the topology of the unidirectional acyclic graph, the first sub-computation graphs other than the second sub-computation graph and the third sub-computation graph in the plurality of first sub-computation graphs are combined to obtain the optimized part to be optimized;
[0030] Call the optimized part to be optimized.
[0031] This application embodiment also provides a computational graph segmentation device, the device comprising:
[0032] The acquisition module is used to acquire the one-way acyclic graph corresponding to the part to be optimized in the network model. The one-way acyclic graph includes multiple nodes and the relationship edges between each node. The multiple nodes correspond one-to-one with the operators in the part to be optimized.
[0033] The first determining module is used to determine the nodes in the plurality of nodes whose preset optimization category for the corresponding operator is not participating in operator fusion, as the first type of node;
[0034] The marking module is used to mark the second type of nodes in the parent nodes of each first type of node as shrinkage termination nodes and mark the second type of nodes in the child nodes of the first type of node as shrinkage start nodes, wherein the second type of nodes are other nodes besides the first type of nodes among the plurality of nodes.
[0035] The second determining module is used to determine the weight of each relation edge based on the node types of the two nodes connected by each relation edge in the unidirectional acyclic graph.
[0036] The processing module is used to perform node shrinking processing on the nodes in the unidirectional acyclic graph based on the node shrinking termination node, the node shrinking start node, and the weight of each relation edge, to obtain a condensed graph.
[0037] The segmentation module is used to segment the unidirectional acyclic graph based on the condensed graph to obtain multiple first sub-computation graphs.
[0038] Optionally, the processing module includes:
[0039] The calculation submodule is used to calculate the longest path length between every two second-type nodes in the unidirectional acyclic graph based on the weight of each relation edge in the unidirectional acyclic graph.
[0040] The judgment submodule is used to determine the first second type node in the unidirectional acyclic graph that has not been shrunk as the first node according to the topology of the unidirectional acyclic graph, and to determine whether the first node and the second node satisfy the preset shrunk rule, wherein the second node is a child node of the first node.
[0041] The determination submodule is used to determine the first node and the second node as nodes to be processed when the first node and the second node satisfy the preset shrinking rule;
[0042] The calling submodule is used to treat the second node as the first node if the second node is the second type of node, and call the judgment submodule to return to execute the step of judging whether the first node and the second node meet the preset shrinking rule, until the first node and / or the second node do not meet the preset shrinking rule, and determine the first node as the node to be processed;
[0043] The processing submodule is used to perform node shrinking processing on the node to be processed to obtain a unidirectional acyclic graph after node shrinking processing, and call the judgment submodule to return to execute the step of determining the first second type node in the unidirectional acyclic graph that has not been shrunk as the first node according to the topology of the unidirectional acyclic graph, until the unidirectional acyclic graph does not include any second type nodes that have not been shrunk, and obtain a shrunk graph.
[0044] The preset node shrinking rules include: when the first node is a first type of target node, the first node is not the node shrinking termination node, the second node is not the node shrinking start node, the longest path length between the first second type node that has not undergone node shrinking and the second node is a preset path length, and the node shrinking process after processing the first node and the second node results in a unidirectional acyclic graph; when the first node is a second type of target node, the second node is a second type of node, the longest path length between the first second type node that has not undergone node shrinking and the second node is a preset path length, and the node shrinking process after processing the first node and the second node results in a unidirectional acyclic graph.
[0045] The first type of target node is a second type of node whose parent node is a second type of node; the second type of target node is a second type of node other than the first type of target node.
[0046] Optionally, the calculation submodule is specifically used to determine each path between every two second-type nodes in the unidirectional acyclic graph.
[0047] For each path, calculate the path length between the two second-type nodes based on the weight of each relation edge on that path;
[0048] The maximum value among the calculated path lengths is determined as the longest path length between the two second-type nodes.
[0049] Optionally, the second determining module is specifically used to determine the weight of each relation edge in the unidirectional acyclic graph as a first preset weight if both nodes connected by the relation edge are nodes of the second type.
[0050] If the two nodes connected by the relation edge include the first type of node, then the weight of the relation edge is determined to be the second preset weight.
[0051] Optionally, the device further includes:
[0052] The fusion module is used to perform operator fusion on the operators corresponding to the second type of nodes in each second sub-computation graph according to the operator category of each node in the second sub-computation graph, so as to obtain a third sub-computation graph including the fused operators; the second sub-computation graph is a first sub-computation graph including multiple second type nodes.
[0053] Optionally, the device further includes:
[0054] The combination module is used to combine the first sub-computation graphs (excluding the second sub-computation graph) and the third sub-computation graph in the plurality of first sub-computation graphs according to the topology of the unidirectional acyclic graph, to obtain the optimized part to be optimized.
[0055] The calling module is used to call the optimized part to be optimized.
[0056] This application also provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus;
[0057] Memory, used to store computer programs;
[0058] When a processor executes a program stored in memory, it implements any of the computational graph partitioning method steps described above.
[0059] This application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of any of the computational graph segmentation methods described above.
[0060] This application also provides a computer program product containing instructions that, when run on a computer, cause the computer to execute any of the computational graph segmentation methods described above.
[0061] Beneficial effects of the embodiments in this application:
[0062] The technical solution provided in this application, during the process of segmenting the one-way acyclic graph corresponding to the part of the network model to be optimized, for each first-type node in the one-way acyclic graph, that is, for each node in the one-way acyclic graph whose corresponding operator does not participate in the subsequent operator fusion process, the second-type nodes among the parent and child nodes of the node are marked as the shrinking termination node and the shrinking start node, respectively. Based on the shrinking start node, shrinking termination node and the weight of each relation edge in the one-way acyclic graph, the nodes in the one-way acyclic graph are shrunk to obtain a shrunk graph. Based on the shrunk graph, the one-way acyclic graph is segmented to realize the segmentation of the computation graph of the part to be optimized in the network model.
[0063] In this embodiment, based on the topology of the unidirectional undirected graph and the node type of each node, the node shrinking method in graph theory is used to mark the shrinking termination node and the shrinking start node in the unidirectional acyclic graph. This allows the partitioning problem of the unidirectional acyclic graph to be transformed into an equivalent graph theory node shrinking problem based on the marked shrinking start and termination nodes and the weight of each relation edge. Since the dependency relationship between nodes in the unidirectional acyclic graph does not need to be considered during the node shrinking process, the probability of breaking the dependency relationship between nodes is greatly increased when the unidirectional acyclic graph is partitioned based on the shrunk graph obtained from the node shrinking process. This results in lower dependency relationships between the partitioned sub-computation graphs while partitioning the computation graph of the part to be optimized in the network model. This greatly increases the probability of parallel processing of the partitioned sub-computation graphs, thereby improving the processing efficiency of the network model.
[0064] Furthermore, the aforementioned termination and start nodes for shrinking are marked for second-type nodes within the parent and child nodes of each first-type node. This means that intermediate nodes in a continuous connection of multiple second-type nodes in a unidirectional acyclic graph are not marked as termination or start nodes. This effectively increases the probability of second-type nodes of the same type being shrunk into a single node, while reducing the probability of different node types being shrunk into a single node. This significantly increases the probability of multiple consecutive second-type nodes being segmented into the same sub-computation graph, thereby reducing the number of sub-computation graphs obtained. In other words, while segmenting the unidirectional acyclic graph of the part to be optimized in the network model, the number of sub-computation graphs obtained is minimized. By controlling the number of sub-computation graphs obtained, each sub-computation graph can include as many nodes as possible, facilitating the subsequent operator fusion process and allowing as many operators as possible to be merged into one operator, thus improving the processing efficiency of the network model.
[0065] Furthermore, the first type of nodes mentioned above are nodes whose preset optimization category for the corresponding operator is not to participate in operator fusion, while the second type of nodes are other nodes in the unidirectional acyclic graph besides the first type of nodes. In other words, the second type of nodes are nodes whose preset optimization category for the corresponding operator is to participate in operator fusion. This will lay the foundation for the later operator fusion process, facilitate the later operator fusion process, and improve the efficiency of model optimization.
[0066] Of course, implementing any product or method of this application does not necessarily require achieving all of the advantages described above at the same time. Attached Figure Description
[0067] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other embodiments can be obtained based on these drawings.
[0068] Figure 1 This is a schematic diagram of the first flowchart of the computational graph segmentation method provided in the embodiments of this application;
[0069] Figure 2-a A schematic diagram of the computation graph provided in an embodiment of this application;
[0070] Figure 2-b for Figure 2-a A schematic diagram illustrating the weights of the edges in a one-way acyclic graph.
[0071] Figure 2-c for Figure 2-a The diagram showing the acyclic graph corresponding to the unidirectional acyclic graph;
[0072] Figure 2-d for Figure 2-a The sub-computation graph obtained by dividing the unidirectional acyclic graph shown;
[0073] Figure 3 This is a schematic diagram of a second flowchart of the computational graph segmentation method provided in the embodiments of this application;
[0074] Figure 4-a A schematic diagram of the computation graph corresponding to a certain network model;
[0075] Figure 4-b This is a schematic diagram of the sub-computation graphs obtained by segmenting a computation graph using relevant techniques.
[0076] Figure 4-c This is a schematic diagram of the sub-computation graphs obtained by segmenting the computation graph using the embodiments of this application;
[0077] Figure 5-a A schematic diagram of the computation graph corresponding to a certain network model;
[0078] Figure 5-b This is a schematic diagram of the sub-computation graphs obtained by segmenting a computation graph using relevant techniques.
[0079] Figure 5-c This is a schematic diagram of the sub-computation graphs obtained by segmenting the computation graph using the embodiments of this application;
[0080] Figure 6 This is a schematic diagram of the third process of the computational graph segmentation method provided in the embodiments of this application;
[0081] Figure 7-a A schematic diagram of the logic fusion process provided in the embodiments of this application;
[0082] Figure 7-b A schematic diagram of the memory fusion process provided in an embodiment of this application;
[0083] Figure 8 This is a schematic diagram of the fourth process of the computational graph segmentation method provided in the embodiments of this application;
[0084] Figure 9 for Figure 2-d The computation graph obtained by combining the various sub-computation graphs after operator fusion;
[0085] Figure 10 A schematic diagram of a computational graph segmentation device provided in an embodiment of this application;
[0086] Figure 11 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation
[0087] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art based on this application are within the scope of protection of this application.
[0088] The terms used in the embodiments of this application are explained below.
[0089] Neural Network Models: Currently, a wide variety of neural network models have been proposed in academia, such as fully connected neural networks, convolutional neural networks, recurrent neural networks, generative adversarial networks, and graph neural networks. The differences between these different neural network models mainly lie in the activation rules of neurons, the topological structure of the neural network model, and the parameter learning algorithms. Different neural networks are composed of different computational logics, and the corresponding computational graphs also vary.
[0090] Computational graph: A computational graph is a way of representing mathematical functions using graph theory. A computational graph is defined as a directed graph where nodes correspond to mathematical operations. Nodes are connected by edges; everything in the graph is either a node or an edge. In a computational graph, a node is either an input value or a function used to combine values.
[0091] In related technologies, when performing neural network model training and inference on software and hardware systems, in order to improve the utilization of system resources such as computing power and bandwidth, and reduce redundant computations in the neural network model processing, graph-computation fusion optimization can be performed on the neural network model to optimize it. Specifically, graph-computation fusion optimization includes the computation graph tiling process and the sub-computation graph intra-operator fusion process.
[0092] In the above computation graph segmentation process, in order to make the space for operator fusion within the segmented sub-computation graphs large enough, the segmentation result of the computation graph needs to have two characteristics: first, the dependency relationship between the segmented sub-computation graphs is the lowest; second, the number of operators contained in each segmented sub-computation graph is as large as possible, that is, the number of segmented sub-computation graphs is relatively small.
[0093] To ensure that the computational graph segmentation result satisfies the two characteristics mentioned above, this application provides a computational graph segmentation method. This method can be applied to any electronic device, including but not limited to mobile terminals, servers, etc. No specific limitation is made to this electronic device.
[0094] like Figure 1 As shown, Figure 1 This is a schematic diagram of a first flowchart of a computational graph segmentation method provided in an embodiment of this application. The method includes the following steps.
[0095] Step S101: Obtain the one-way acyclic graph corresponding to the part to be optimized in the network model. The one-way acyclic graph includes multiple nodes and the relationship edges between each node. The multiple nodes correspond one-to-one with the operators in the part to be optimized.
[0096] Step S102: Determine the nodes that do not participate in operator fusion among the multiple nodes and identify them as the first type of nodes.
[0097] Step S103: For each first type of node, mark the second type of node in the parent node of the first type of node as the shrinking termination node, and mark the second type of node in the child node of the first type of node as the shrinking start node. The second type of node is any node other than the first type of node among the multiple nodes.
[0098] Step S104: Determine the weight of each relation edge based on the node types of the two nodes connected by each relation edge in the unidirectional acyclic graph.
[0099] Step S105: Based on the node of the shrinking termination point, the node of the shrinking start point, and the weight of each relation edge, perform node shrinking processing on the nodes in the unidirectional acyclic graph to obtain the shrunken graph.
[0100] Step S106: The unidirectional acyclic graph is segmented based on the condensed graph to obtain multiple first sub-computation graphs.
[0101] pass Figure 1 The method shown describes a process for segmenting the unidirectional acyclic graph (AAG) corresponding to the part of the network model to be optimized. For each first-type node in the AAG, that is, for each node whose corresponding operator does not participate in the subsequent operator fusion process, the second-type nodes among the parent and child nodes of the node are marked as the shrinking termination node and the shrinking start node, respectively. Based on the shrinking start node, shrinking termination node, and the weight of each relation edge in the AAG, the nodes in the AAG are shrunk to obtain a shrunk graph. The AAG is then segmented based on this shrunk graph, thus achieving the segmentation of the computation graph of the part to be optimized in the network model.
[0102] In this embodiment, based on the topology of the unidirectional undirected graph and the node type of each node, the node shrinking method in graph theory is used to mark the shrinking termination node and the shrinking start node in the unidirectional acyclic graph. This allows the partitioning problem of the unidirectional acyclic graph to be transformed into an equivalent graph theory node shrinking problem based on the marked shrinking start and termination nodes and the weight of each relation edge. Since the dependency relationship between nodes in the unidirectional acyclic graph does not need to be considered during the node shrinking process, the probability of breaking the dependency relationship between nodes is greatly increased when the unidirectional acyclic graph is partitioned based on the shrunk graph obtained from the node shrinking process. This results in lower dependency relationships between the partitioned sub-computation graphs while partitioning the computation graph of the part to be optimized in the network model. This greatly increases the probability of parallel processing of the partitioned sub-computation graphs, thereby improving the processing efficiency of the network model.
[0103] Furthermore, the aforementioned termination and start nodes for shrinking are marked for second-type nodes within the parent and child nodes of each first-type node. This means that intermediate nodes in a continuous connection of multiple second-type nodes in a unidirectional acyclic graph are not marked as termination or start nodes. This effectively increases the probability of second-type nodes of the same type being shrunk into a single node, while reducing the probability of different node types being shrunk into a single node. This significantly increases the probability of multiple consecutive second-type nodes being segmented into the same sub-computation graph, thereby reducing the number of sub-computation graphs obtained. In other words, while segmenting the unidirectional acyclic graph of the part to be optimized in the network model, the number of sub-computation graphs obtained is minimized. By controlling the number of sub-computation graphs obtained, each sub-computation graph can include as many nodes as possible, facilitating the subsequent operator fusion process and allowing as many operators as possible to be merged into one operator, thus improving the processing efficiency of the network model.
[0104] Furthermore, the first type of nodes mentioned above are nodes whose preset optimization category for the corresponding operator is not to participate in operator fusion, while the second type of nodes are other nodes in the unidirectional acyclic graph besides the first type of nodes. In other words, the second type of nodes are nodes whose preset optimization category for the corresponding operator is to participate in operator fusion. This will lay the foundation for the later operator fusion process, facilitate the later operator fusion process, and improve the efficiency of model optimization.
[0105] The embodiments of this application will be described below through specific examples. For ease of understanding, the following description uses an electronic device as the execution subject and does not constitute any limitation.
[0106] For step S101 above, that is, to obtain the unidirectional acyclic graph corresponding to the part to be optimized in the network model, the unidirectional acyclic graph includes multiple nodes and the relationship edges between each node, and the multiple nodes correspond one-to-one with the operators in the part to be optimized.
[0107] In this step, when optimizing the network model, the electronic device needs to obtain the computation graph corresponding to the part of the network model to be optimized. To ensure the smooth execution of subsequent steps, this computation graph is a one-way acyclic graph. This one-way acyclic graph includes multiple nodes and the relationship edges between the nodes. The specific details of obtaining the above-mentioned one-way acyclic graph are not explained here.
[0108] The network model described above can be a neural network model, a deep learning model, or a machine learning model. No specific limitations are imposed on the network model described here.
[0109] The part to be optimized can be the entire network model or a part of the structure within the network model.
[0110] In this embodiment, each node in the unidirectional acyclic graph corresponds one-to-one with an operator in the part to be optimized, and the edge connecting two nodes is the aforementioned relational edge, which indicates the dependency relationship between the two connected nodes. The unidirectional acyclic graph does not include a cycle structure.
[0111] Regarding step S102 above, that is, determining the nodes in the multiple nodes whose preset optimization category for the corresponding operator is not participating in operator fusion, as the first type of node.
[0112] In this step, for the aforementioned unidirectional acyclic graph, the electronic device can determine the node type of each node in the unidirectional acyclic graph based on the preset optimization type of the operator corresponding to each node. That is, the nodes in the unidirectional acyclic graph are divided into a first type of node and a second type of node. The preset optimization type of the operator corresponding to the first type of node is nodes that do not participate in operator fusion. The second type of node is all nodes in the unidirectional acyclic graph other than the first type of node, that is, nodes whose preset optimization type corresponds to nodes that participate in operator fusion.
[0113] In this embodiment of the application, when dividing the nodes into first and second categories, only the first category nodes in the unidirectional acyclic graph are determined. In this case, all other nodes in the unidirectional acyclic graph other than the first category nodes are defaulted to being second category nodes. Similarly, the electronic device can also determine only the second category nodes in the unidirectional acyclic graph, thereby defining all other nodes as first category nodes.
[0114] In the embodiments of this application, each node in the above-mentioned unidirectional acyclic graph has a corresponding operator category.
[0115] In an optional embodiment, the operator category described above can be represented by the operator's purpose. For example, if the operator corresponding to a node is the input to the node's child nodes, then the operator category of that operator can be an input operator. As another example, if the operator corresponding to a node is used to perform a convolution (Conv) operation on the input data, then the operator category of that operator can be a convolution operator.
[0116] When the above operator categories are represented by operator uses, the electronic device can determine the nodes in the unidirectional acyclic graph whose operator category is the preset optimization category according to the preset optimization type that does not participate in operator fusion as the first type of node.
[0117] For ease of understanding, let's take the pre-defined optimization category that does not participate in operator fusion as an example, where convolution operators are used. The electronic device can identify the nodes corresponding to all operators in the aforementioned unidirectional acyclic graph that are classified as convolution operators as first-class nodes.
[0118] In another optional embodiment, the operator categories mentioned above can be represented by preset optimization categories. That is, the operator category corresponding to each operator is either a preset optimization category that does not participate in operator fusion (denoted as the first category), or a preset optimization category that participates in operator fusion (denoted as the second category).
[0119] When the above operator categories are represented by the first category or the second category, the electronic device can determine the nodes corresponding to all operators of the first category in the above unidirectional acyclic graph as the nodes of the first category.
[0120] The above-mentioned preset optimization categories can be set according to the application scenario of the network model and user needs. Here, no specific limitation is made on the above-mentioned preset optimization categories.
[0121] In this embodiment, depending on the representation of the operator categories and the different preset optimization categories, the first and second types of nodes determined in the unidirectional acyclic graph will also differ. Here, no specific limitations are made on the determined first and second types of nodes.
[0122] For step S103 above, that is, for each first type of node, the second type of node in the parent node of the first type of node is marked as the shrinking termination node, and the second type of node in the child node of the first type of node is marked as the shrinking start node. Here, the second type of node is any other node among the multiple nodes except the first type of node.
[0123] In the aforementioned one-way acyclic graph, each node may have no parent node, or it may have one or more parent nodes. Furthermore, each node may have no child nodes, or it may have one or more child nodes. Here, no specific limit is placed on the number of parent and child nodes corresponding to each node in the aforementioned one-way acyclic graph.
[0124] For each first-type node in the aforementioned unidirectional acyclic graph, when the first-type node has a parent node, the electronic device can mark each second-type node among the parent nodes of the first-type node as a shrinkage termination node. When the first-type node has child nodes, the electronic device can mark each second-type node among the child nodes of the first-type node as a shrinkage start node.
[0125] For ease of understanding, combined with Figure 2-a Let's take an example to illustrate. Figure 2-a This is a schematic diagram of a computational graph provided in an embodiment of this application.
[0126] exist Figure 2-a In the above, the first type of node includes node B1, and the second type of node includes nodes A1 to A8.
[0127] For node B, its parent node is node A3, and its child node is node A7. Since both node A3 and node A7 belong to the second type of node, when performing the above step S103, the electronic device can mark node A3 as the shrinking termination node and node A7 as the shrinking start node.
[0128] For step S104 above, that is, determining the weight of the relation edge based on the node types of the two nodes connected by each relation edge in the unidirectional acyclic graph.
[0129] In the embodiments of this application, for each relation edge in the above-mentioned unidirectional acyclic graph, the node types of the two nodes connected by the relation edge include at least three cases.
[0130] Case 1: The two nodes connected by the relation edge are both of the first type of node mentioned above;
[0131] Scenario 2: The two nodes connected by this relation edge are both of the second type of nodes mentioned above;
[0132] Scenario 3: Of the two nodes connected by the relation edge, one node is of the first type mentioned above, and the other node is of the second type mentioned above.
[0133] In an optional embodiment, step S104 above, which determines the weight of the relation edge based on the node types of the two nodes connected by each relation edge in the unidirectional acyclic graph, can specifically represent the following steps, namely step one to step two.
[0134] Step 1: For each relation edge in a unidirectional acyclic graph, if both nodes connected by the relation edge are of type 2, then the weight of the relation edge is determined to be the first preset weight.
[0135] In an optional embodiment, the first preset weight can be 0. For each relation edge in the unidirectional acyclic graph, when the two nodes connected by the relation edge satisfy condition two above, the electronic device can determine that the weight of the relation edge is 0.
[0136] Step 2: If the two nodes connected by the relation edge include nodes of the first type, then the weight of the relation edge is determined to be the second preset weight.
[0137] In one optional embodiment, the second preset weight can be any value other than the first preset weight, such as 1, 2, 3, etc. For ease of understanding, the following explanation uses a second preset weight of 1 as an example and does not serve as a limitation.
[0138] For each relation edge in the aforementioned unidirectional acyclic graph, the electronic device can determine the weight of the relation edge to be 1 when the two nodes connected by the relation edge satisfy either condition one or condition three.
[0139] For ease of understanding, the above will still be used. Figure 2-a For example, combined with Figure 2-b The determination of the weights of the aforementioned relational edges is explained. Figure 2-b for Figure 2-a This is a schematic diagram of the weights of the edges in a one-way acyclic graph.
[0140] In response to the above Figure 2-b For each relation edge, such as the relation edge between node A1 and node A3, since both node A1 and node A3 are second-type nodes, the electronic device can determine that the weight of the relation edge between node A1 and node A3 is the aforementioned first preset weight, i.e., 0. Similarly, for the relation edge between node A3 and node B, since node B is also a first-type node, the electronic device can determine that the weight of the relation edge between node A3 and node B is the aforementioned second preset weight, i.e., 1. And so on, the electronic device can determine... Figure 2-a The weight of each relation edge is obtained. Figure 2-bThe weight of each relation edge shown.
[0141] In this embodiment of the application, by applying the first preset weight and the second preset weight, the electronic device can accurately determine the weight of each relation edge in the unidirectional acyclic graph according to the node types of the two nodes connected by each relation, thereby facilitating the subsequent node shrinking processing of the unidirectional acyclic graph.
[0142] In the above embodiments, step S104 is executed after step S103. Alternatively, step S104 may be executed before step S103 or simultaneously with step S103. The execution order of steps S103 and S104 is not specifically limited here.
[0143] For step S105 above, which is to perform node shrinking on the nodes in the unidirectional acyclic graph based on the node of the shrinking termination, the node of the shrinking start, and the weight of each relation edge, a condensed graph is obtained.
[0144] In this step, after marking the termination and start nodes of the shrinking process in the one-way acyclic graph (AAG) through step S103, the electronic device transforms the problem of partitioning the AAG into the problem of shrinking the nodes in the AAG. That is, based on the start and end nodes of the shrinking process in the AAG, and the weight of each relation edge in the AAG, the nodes in the AAG are shrunk according to preset shrinking rules, resulting in a shrunk graph.
[0145] The process of point shrinkage in step S105 above can be found in the following description, and will not be explained in detail here.
[0146] For step S106 above, that is, the unidirectional acyclic graph is divided based on the condensed graph to obtain multiple first sub-computation graphs.
[0147] In this step, after obtaining the condensed graph corresponding to the unidirectional acyclic graph through step S105, the condensed graph includes multiple nodes and relational edges between the nodes. Based on the condensed graph, the electronic device disconnects the relational edges corresponding to each relational edge in the unidirectional acyclic graph, thereby segmenting the unidirectional acyclic graph and obtaining multiple first sub-computation graphs.
[0148] The partitioning of the aforementioned one-way acyclic graph can be found in the description below, and will not be explained in detail here.
[0149] In an optional embodiment, according to the above... Figure 1 The method shown in this application embodiment also provides a computational graph segmentation method. For example... Figure 3 As shown, Figure 3 This is a schematic diagram of a second flowchart of the computational graph segmentation method provided in an embodiment of this application. Figure 3 In this context, step S105 is further broken down into the following steps: steps S1051 to S1055.
[0150] Step S1051: Based on the weight of each relation edge in the unidirectional acyclic graph, calculate the longest path length between every two second-type nodes in the unidirectional acyclic graph.
[0151] In this step, the electronic device can calculate the longest path length between every two second-type nodes in the unidirectional acyclic graph based on the weight of each relation edge determined in step S104 above and the topology of the unidirectional acyclic graph.
[0152] In an optional embodiment, step S1051 above, based on the weight of each relation edge in the unidirectional acyclic graph, calculates the longest path length between every two second-type nodes in the unidirectional acyclic graph. Specifically, this can be refined into the following steps, namely steps one to three.
[0153] Step 1: For every two second-type nodes in a one-way acyclic graph, determine every path between those two second-type nodes.
[0154] In this embodiment of the application, depending on the different topological structures of the unidirectional acyclic graph, the number of paths between any two second-type nodes can be empty, as described above. Figure 2-a The path from node A6 to node A7 is empty; it can also be 1, as mentioned above. Figure 2-a The path from node A1 to node A2 is 1; there can be multiple paths, such as... Figure 2-a The path from node A1 to node A8 is 3, specifically represented as: Path 1, A1-A2-A4-A6-A8, Path 2, A1-A3-B-A7-A8, and Path 3, A1-A3-A5-A7-A8.
[0155] The electronic device can determine all paths between any two second-type nodes based on the topology of the unidirectional acyclic graph and the node type of each node in the unidirectional acyclic graph.
[0156] In the embodiments of this application, the number of paths between any two second-type nodes varies depending on the topology of the unidirectional acyclic graph. Here, the number of all paths between any two second-type nodes is not specifically limited.
[0157] Step 2: For each path, calculate the path length between the two second-type nodes based on the weight of each relation edge on that path.
[0158] In an optional embodiment, when calculating the path length, the electronic device may calculate the sum of the weights of each relation edge on the path as the path length of that relation edge.
[0159] In another optional embodiment, when calculating the path length, the electronic device may calculate the weight of each relation edge on the path and the preset value of the relation edge as the path length of the relation edge.
[0160] The aforementioned preset value can be any non-zero positive integer. No specific limitations are imposed on the aforementioned preset value.
[0161] In the embodiments of this application, the method for calculating the path length of each of the above paths is not specifically limited.
[0162] Step 3: Determine the maximum value among the calculated path lengths as the longest path length between the two second-type nodes.
[0163] For ease of understanding, let's continue with the example where the path length is represented as the sum of the weights on the path. Figure 2-a The following explanation is provided. Through steps one through three above, the electronic device can calculate the longest path length relationship as shown in Table 1.
[0164] Table 1
[0165] node A1 A2 A3 A4 A5 A6 A7 A8 A1 - 0 0 0 0 0 2 2 A2 - - Unreachable 0 Unreachable 0 Unreachable 0 A3 - - - Unreachable 0 Unreachable 2 2 A4 - - - - Unreachable 0 Unreachable 0 A5 - - - - - Unreachable 0 0 A6 - - - - - - Unreachable 0 A7 - - - - - - - 0 A8 - - - - - - - -
[0166] In Table 1, all nodes are of the second type mentioned above. Because... Figure 2-a As this is a unidirectional acyclic graph, there are no paths between nodes of the second type and themselves, and no paths between child nodes and parent nodes, specifically represented by the "-" in Table 1 above. The 0 and 2 in Table 1 represent the longest path length between two nodes of the second type. For example, the 2 in row 2, column 9 of Table 1 indicates that the longest path length from node A1 to node A8 is 2. "Unreachable" in Table 1 indicates that there is no path between two nodes of the second type, i.e., the path count is empty. For example, the "unreachable" in row 3, column 4 of Table 1 indicates that the path count from node A2 to node A3 is empty.
[0167] In this embodiment, when the electronic device performs steps one to three above, it can calculate the longest path length between every two second-type nodes using a preset path algorithm. This preset path algorithm includes, but is not limited to, Floyd's longest path algorithm, depth-first search algorithm, breadth-first search algorithm, Dijkstra's algorithm, and Tarjan's algorithm. Here, the specific method for calculating the path length between nodes in the second sub-calculation graph is not limited.
[0168] Step S1052: According to the topology of the unidirectional acyclic graph, the first second-type node in the unidirectional acyclic graph that has not undergone node shrinking is determined as the first node, and it is determined whether the first node and the second node satisfy the preset node shrinking rules. The second node is a child node of the first node.
[0169] In this embodiment, the electronic device determines the first second-type node in the unidirectional acyclic graph that has not undergone node shrinking as the first node, according to the topology of the unidirectional acyclic graph. At this time, the electronic device can determine whether the first node and its child node (i.e., the second node) satisfy the preset node shrinking rule based on the topology of the unidirectional acyclic graph, the node types corresponding to the first node and the second node, and the weight of the relationship edge between the first node and the second node.
[0170] In this embodiment of the application, when the first node is a first type of target node, the above-mentioned preset shrinking rule can be expressed as follows: the first node is not a shrinking termination node, the second node is not a shrinking start node, the longest path length between the first second type of node that has not undergone shrinking processing and the second node is a preset path length, and the shrinking graph obtained after shrinking the first node and the second node is a unidirectional acyclic graph.
[0171] When the first node is a second type of target node, the above-mentioned preset node shrinking rule can be expressed as follows: when the first node is a second type of target node, the second node is a second type of node, the longest path length between the first second type of node that has not undergone node shrinking and the second node is the preset path length, and the node shrinking graph obtained after performing node shrinking on the first node and the second node is a unidirectional acyclic graph.
[0172] The first type of target node is a second type of node that does not have a parent node that is a second type of node; the second type of target node is a second type of node other than the first type of target node.
[0173] In this embodiment of the application, the first type of target node can be represented as: a second type of node in a unidirectional acyclic graph that does not have a parent node, or a second type of node that has a parent node, but the parent node includes the first type of node.
[0174] For example, the above Figure 2-a Nodes A1 and A7 in the diagram, correspondingly, Figure 2-a All second-type nodes except for nodes A1 and A7 are the aforementioned second-type target nodes.
[0175] Step S1053: When the first node and the second node satisfy the preset shrinkage rule, the first node and the second node are determined as nodes to be processed.
[0176] In this step, when the first node and the second node satisfy the preset shrinking rule, the electronic device determines that the first node and the second node can be shrunk into one node. At this time, the electronic device can identify the first node and the second node as the node to be processed.
[0177] In an optional embodiment, when the first node and the second node do not meet the preset node shrinking rules, the electronic device determines that the first node and the second node cannot be shrunk into a single node. In this case, the electronic device can identify the first node as the node to be processed and leave the second node unprocessed.
[0178] Step S1054: If the second node is a second type of node, then the second node is treated as the first node, and the process returns to the step of judging whether the first node and the second node meet the preset shrinking rule, until the first node and / or the second node do not meet the preset shrinking rule, and the first node is determined as the node to be processed.
[0179] In this embodiment of the application, the node type of the second node can be either the first type of node or the second type of node.
[0180] When the second node is the second type of node, the electronic device can identify the second node as the first node and return to the step of determining whether the first node and the second node meet the preset shrinking rule in step S1051, until the first node and / or the second node do not meet the preset shrinking rule, and then identify the first node as the node to be processed.
[0181] In this embodiment of the application, after the second node of the electronic device is determined to be the first node, the first node will be changed to the second node, and correspondingly, the second node will be changed to a child node of the updated first node.
[0182] In an optional embodiment, when the second node is the first type of node, the electronic device may not process the second node.
[0183] Through step S1053 above, the electronic device determines at least one node to be processed. Specifically, the number of nodes to be processed determined by the electronic device varies depending on the topology of the unidirectional acyclic graph. Here, no specific limit is made on the number of nodes to be processed.
[0184] Step S1055: Perform node shrinking on the nodes to be processed to obtain a unidirectional acyclic graph after node shrinking. Then, return to execute the step of determining the first un-shrunken second-type node in the unidirectional acyclic graph as the first node according to the topology of the unidirectional acyclic graph, until the unidirectional acyclic graph does not contain any un-shrunken second-type nodes, and obtain the shrunken graph.
[0185] In this embodiment of the application, the electronic device can determine at least one node to be processed through the above step S1053. At this time, the electronic device can perform point shrinking processing on all the determined nodes to be processed to obtain a one-way acyclic graph after point shrinking.
[0186] In one optional embodiment, when the number of nodes to be processed is one, the node to be processed is the node in the unidirectional acyclic graph after the node shrinking process.
[0187] In another optional embodiment, when the number of identified nodes to be processed is multiple, the electronic device can shrink the multiple nodes to be processed into one node. That is, in the unidirectional acyclic graph after shrinking, multiple nodes to be processed are represented as one node.
[0188] After shrinking the nodes to be processed, the electronic device can return to step S1051 and perform the same shrinking process on the nodes in the unidirectional acyclic graph again, until the unidirectional acyclic graph no longer contains any un-shrunken nodes of the second type. At this point, the electronic device can determine the unidirectional acyclic graph after the current shrinking process as the shrunken graph.
[0189] For ease of understanding, the above will still be used. Figure 2-a For example, combined with Figure 2-c The above-mentioned shortening process will be explained. Figure 2-c for Figure 2-a The diagram shown is a condensed version of the unidirectional acyclic graph.
[0190] When the electronic device performs step S1052 above, according to Figure 2-a Given the topology of the unidirectional acyclic graph shown, the electronic device can identify node A1 as the first node. Since the child nodes of node A1 include nodes A2 and A3, that is, the second node mentioned above is nodes A2 and A3, the electronic device needs to determine whether nodes A1 and A2 satisfy the preset shrinking rule, and also determine whether nodes A1 and A2 satisfy the preset shrinking rule.
[0191] When determining whether nodes A1 and A2 meet the preset shrinking rules, since the first node (node A1) is the aforementioned first type of target node, the preset shrinking rules can be expressed as follows: the first node is not a shrinking termination node, the second node is not a shrinking start node, the longest path length between the first second type node that has not undergone shrinking processing and the second node is the preset path length, and the shrunk graph obtained after shrinking the first node and the second node is a unidirectional acyclic graph. According to these preset shrinking rules, the electronic device can determine that the first node and the second node meet these rules, and at this time, nodes A1 and A2 will be identified as nodes to be processed.
[0192] Since node A2 is a second type of node as described above, the electronic device will execute step S1054, which means setting node A2 as the first node and node A4 as the second node. After re-determining the first and second nodes, the electronic device returns to the step S1052 above, which involves determining whether the first and second nodes meet the preset shrinking rules.
[0193] When determining whether nodes A2 and A4 satisfy the preset shrinking rule, since node A2 is a second-type target node, the preset shrinking rule can be expressed as follows: when the first node is a second-type target node, the second node is a second-type node; the longest path length between the first un-shrunken second-type node and the second node is the preset path length; and the shrunken graph obtained after shrinking the first and second nodes is a unidirectional acyclic graph. At this point, the electronic device can determine that nodes A2 and A4 satisfy the preset shrinking rule, and can identify nodes A2 and A4 as nodes to be processed. Similarly, when... Figure 2-a When node A6 is determined as the first node and node A8 as the second node, since the longest path length between the first and second nodes is not equal to the preset path length, the electronic device can determine that the first and second nodes do not meet the aforementioned preset node shrinking rule. In this case, the electronic device can only determine node A6 as the node to be processed.
[0194] When determining whether nodes A1 and A3 satisfy the preset shrinking rules, since the first node (node A1) is the first type of target node, the preset shrinking rules can be expressed as follows: the first node is not a shrinking termination node, the second node is not a shrinking start node, the longest path length between the first un-shrunken second type node and the second node is the preset path length, and the shrunken graph obtained after shrinking the first node and the second node is a unidirectional acyclic graph. Based on these preset shrinking rules, the electronic device can determine that the first node and the second node satisfy these rules. At this point, nodes A1 and A3 will be identified as nodes to be processed.
[0195] Since node A3 is a second type of node as described above, the electronic device will execute step S1054, which means setting node A3 as the first node. At this time, nodes B and A5 will be set as the second nodes. After re-determining the first and second nodes, the electronic device returns to the step S1052 above, which involves determining whether the first and second nodes meet the preset shrinking rules.
[0196] When determining whether nodes A3 and A5, and nodes A3 and B satisfy the preset shrinking rules, since the first node (node A1) is the first type of target node, the preset shrinking rules can be expressed as follows: the first node is not a shrinking termination node, the second node is not a shrinking start node, the weight of the edge between the first and second nodes is a preset weight threshold, and the shrunk graph obtained after shrinking the first and second nodes is a unidirectional acyclic graph. Since node A3 is the aforementioned shrinking termination node, nodes A3 and A5, and nodes A3 and B do not satisfy the preset shrinking rules. In this case, the electronic device can only identify node A3 as the node to be processed.
[0197] At this point, the nodes to be processed identified by the electronic device include: node A1, node A2, node A3, node A4, and node A6. The electronic device can perform node shrinking on the identified nodes to obtain a unidirectional acyclic graph after node shrinking.
[0198] Since the unidirectional acyclic graph after point shrinking still contains nodes of the second type that have not undergone point shrinking, namely nodes A5, A7, and A8, the electronic device can determine node A5 as the aforementioned first node based on the topology of the unidirectional acyclic graph. The electronic device can then return to step S1052 and so on, until the unidirectional acyclic graph after point shrinking still does not contain any nodes of the second type that have not undergone point shrinking. At this point, the electronic device can determine the current unidirectional acyclic graph after point shrinking as the unidirectional acyclic graph of the aforementioned unidirectional acyclic graph, i.e. Figure 2-c The diagram shown is a thumbnail.
[0199] Through the above steps S1051-S1055, the electronic device can perform node shrinking processing on the second type of nodes in the unidirectional acyclic graph, realizing the transformation from the partitioning problem of the unidirectional acyclic graph to the equivalent graph theory node shrinking problem. This reduces the impact of considering the dependencies between nodes in the unidirectional acyclic graph on the node shrinking process. This greatly increases the probability of breaking the dependencies between nodes when partitioning the unidirectional acyclic graph based on the shrunken graph obtained from the node shrinking processing. Thus, while partitioning the computation graph of the part to be optimized in the network model, the dependencies between the partitioned sub-computation graphs are low.
[0200] Regarding step S106 above, after obtaining the condensed graph through steps S1051-S1055, the electronic device can segment the unidirectional acyclic graph based on the condensed graph to obtain multiple first sub-computation graphs. Specifically, the electronic device can segment the sub-computation graph corresponding to each node in the unidirectional acyclic graph from the condensed graph, using it as the first computation graph.
[0201] For ease of understanding, the above will still be used. Figure 2-c For example, combined with Figure 2-d To explain, Figure 2-d for Figure 2-a The sub-computation graph obtained by dividing the unidirectional acyclic graph shown is an example.
[0202] according to Figure 2-a The thumbnail diagram shown indicates that the electronic device can display the above... Figure 2-a The nodes A1, A2, A3, A4, and A6 in the graph are divided into a first sub-computation graph, i.e. Figure 2-d Sub-computation in Figure 1 ; Divide node B into a first sub-computation graph, i.e. Figure 2-d In sub-computation graph 2, node A3 is divided into a first sub-computation graph, namely... Figure 2-d Sub-computation in Figure 3 And divide node A7 and node A8 into a first sub-computation graph, that is Figure 2-d Sub-computation graph 4.
[0203] In this embodiment, the aforementioned termination and start nodes are marked for second-type nodes among the parent and child nodes of each first-type node. That is, intermediate nodes in a unidirectional acyclic graph connecting multiple consecutive second-type nodes are not marked as termination or start nodes. This significantly increases the probability that multiple consecutive second-type nodes in a unidirectional acyclic graph will be partitioned into the same computational graph, thereby reducing the number of sub-computational graphs obtained. In other words, while partitioning the computational graph of the part to be optimized in the network model, the number of sub-computational graphs obtained is minimized.
[0204] For ease of understanding, combined with Figure 4-a , Figure 4-b and Figure 4-c Let's take an example to illustrate. Figure 4-a A schematic diagram of the computation graph corresponding to a certain network model; Figure 4-b This is a schematic diagram of the sub-computation graphs obtained by segmenting a computation graph using relevant techniques. Figure 4-c This is a schematic diagram of the sub-computation graphs obtained by segmenting the computation graph using the embodiments of this application.
[0205] exist Figure 4-a In the above, the first type of node is node B, and the second type of node is nodes A1-A7. Figure 4-b middle, Figure 4-a The computation graph shown is divided into 5 sub-computation graphs, namely sub-computation graphs. Figure 1 - Sub-computation graph 5. In Figure 4-c middle, Figure 4-a The computation graph shown is divided into four sub-computation graphs, namely sub-computation graphs. Figure 1- Sub-computation graph 4. The number of sub-computation subgraphs obtained by segmentation using the embodiments of this application is reduced, while the number of nodes included in sub-computation graph 2 is increased.
[0206] exist Figure 4-b In the graph, nodes A2, A3, and A5 are partitioned into the same sub-computation graph, i.e. Figure 4-b In the sub-computation graph 2 shown, node A7 is partitioned into another sub-computation graph, namely... Figure 4-b The sub-computation diagram shown is 5. And... Figure 4-c In the graph, nodes A2, A3, A5, and A7 are assigned to the same sub-computation graph, i.e. Figure 4-c The sub-computation diagram 2 is shown. Therefore, Figure 4-c The number of sub-computation graphs obtained by mid-segmentation is less than Figure 4-b The number of sub-computation graphs obtained by mid-segmentation, which makes Figure 4-c Neutron computation graph 2 includes a large number of nodes. Later, when electronic devices perform operator fusion for the operators corresponding to each node in each sub-computation graph, Figure 4-c In the neutron computation graph 2, all the operators corresponding to the nodes can be merged into one operator, which allows as many operators as possible to be merged into one operator, thereby improving the processing efficiency of the network model.
[0207] In this embodiment of the application, based on the node shrinking algorithm in graph theory, for each first type node in a one-way acyclic graph, the second type nodes among the parent and child nodes corresponding to the first node are marked as the node shrinking termination node and the node shrinking start node, thereby transforming the computation graph partitioning problem into an equivalent graph theory node shrinking problem. This allows the partitioning of the one-way acyclic graph based on the node shrinking termination node and the node shrinking start node to disregard the dependencies between nodes, greatly increasing the probability of the dependencies between nodes being broken. Thus, while partitioning the computation graph of the part to be optimized in the network model, the dependencies between the partitioned sub-computation graphs are kept low.
[0208] For ease of understanding, combined with Figure 5-a , Figure 5-b and Figure 5-c Let's take an example to illustrate. Figure 5-a A schematic diagram of the computation graph corresponding to a certain network model; Figure 5-b This is a schematic diagram of the sub-computation graphs obtained by segmenting a computation graph using relevant techniques. Figure 5-c This is a schematic diagram of the sub-computation graphs obtained by segmenting the computation graph using the embodiments of this application.
[0209] exist Figure 5-a In the above, the first type of node is node B, and the second type of node is nodes A1-A5. Figure 5-b middle, Figure 5-a The computation graph shown is divided into three sub-computation graphs, namely sub-computation graphs. Figure 1 - Sub-computation Figure 3 .exist Figure 5-c middle, Figure 5-a The computation graph shown is divided into four sub-computation graphs, namely sub-computation graphs. Figure 1 - Sub-computation graph 4. Although Figure 5-c The number of sub-computation graphs obtained by partitioning is greater than Figure 5-b The number of sub-computation graphs obtained from the partitioning, however, in Figure 5-b In the subcomputation graph 2, the input depends on the subcomputation. Figure 1 The output of node A2 in the middle. This makes sub-computation graph 2 must be in the sub-computation. Figure 1 Execution after execution, that is, execution after the operator corresponding to node A3 is executed, increases the number of sub-computations. Figure 1 The dependency relationship between node A3 and node B.
[0210] However, in Figure 5-c In the process, because node A3 and node B are partitioned into different sub-computation graphs, i.e. Figure 5-c The sub-computation diagram 2 and sub-computation shown Figure 3 This effectively reduces the interaction between node A3 in subcomputation graph 2 and subcomputation. Figure 3 Dependencies between nodes B in the middle.
[0211] In addition, Figure 5-b In the middle, sub-computation graph 2 must be in the sub-computation Figure 1 After execution is complete, the processing procedure corresponding to node B is executed based on the output of node A2. Furthermore, the execution of node A4 can only be performed based on the outputs of nodes A3 and B, which is called sub-computation. Figure 3 This must be executed after subcomputation graph 2 has finished. However, in Figure 5-c In the middle, sub-computation graph 2 and sub-computation Figure 3 The execution of all depends on sub-computations. Figure 1 The output of node A2 in the subcomputation graph 2 and the subcomputation graph 2 are due to the subcomputation graph 2. Figure 3 It belongs to two sub-computation graphs, therefore, in the sub-computation Figure 1 After execution, sub-computation graph 2 and sub-computation Figure 3 It can be executed in parallel, which effectively improves the processing efficiency of network model training and inference.
[0212] In an optional embodiment, according to Figure 1 The method shown in this application embodiment also provides a computational graph segmentation method. For example... Figure 6 As shown, Figure 6 This is a schematic diagram of a third computational graph segmentation method provided in an embodiment of this application. The method includes the following steps.
[0213] Step S601: Obtain the unidirectional acyclic graph corresponding to the part to be optimized in the network model. The unidirectional acyclic graph includes multiple nodes and the relationship edges between each node. The multiple nodes correspond one-to-one with the operators in the part to be optimized.
[0214] Step S602: Determine the nodes in the multiple nodes whose preset optimization category for the corresponding operator is not participating in operator fusion, and designate them as the first type of nodes.
[0215] Step S603: For each first type of node, mark the second type of node in the parent node of the first type of node as the shrinking termination node, and mark the second type of node in the child node of the first type of node as the shrinking start node. The second type of node is any node other than the first type of node among the multiple nodes.
[0216] Step S604: Determine the weight of each relation edge based on the node types of the two nodes connected by each relation edge in the unidirectional acyclic graph.
[0217] Step S605: Based on the node of the shrinking termination point, the node of the shrinking start point, and the weight of each relation edge, perform node shrinking processing on the nodes in the unidirectional acyclic graph to obtain a condensed graph.
[0218] Step S606: The unidirectional acyclic graph is divided based on the condensed graph to obtain multiple first sub-computation graphs.
[0219] The steps S601-S606 described above are the same as the steps S101-S106 described above.
[0220] Step S607: For each second sub-computation graph, according to the operator category of the operator corresponding to each node in the second sub-computation graph, the operators corresponding to the second type of nodes in the second sub-computation graph are fused to obtain a third sub-computation graph including the fused operators; the second sub-computation graph is a first sub-computation graph including multiple second type nodes.
[0221] In this step, after the electronic device divides the above-mentioned unidirectional acyclic graph into multiple first sub-computation graphs, it can perform operator fusion on each second sub-computation graph of the multiple first sub-computation graphs according to the operator category of the operator corresponding to each second type node in the second sub-computation graph, and obtain a third sub-computation graph including the fused operator.
[0222] The above-mentioned preset operator categories can be set according to user needs, specific application scenarios, etc. Here, no specific limitation is made on the above-mentioned preset operator categories.
[0223] In the embodiments of this application, the above-mentioned operator fusion process refers to merging multiple computing units in the network model into a single computing kernel to obtain a kernel function, namely the above-mentioned fusion operator.
[0224] For ease of understanding, combined with Figure 7-a and Figure 7-b Let's take an example to illustrate. Figure 7-a A schematic diagram of the logic fusion process provided in the embodiments of this application; Figure 7-b This is a schematic diagram of a memory fusion process provided in an embodiment of this application.
[0225] exist Figure 7-a In the network model structure shown on the left, the following are listed sequentially: input operator, Conv operator, output operator, input operator, batch normalization (BN) operator, and output operator. When the nodes corresponding to the Conv and BN operators are two second-type nodes connected by a certain relation edge in the same sub-computation graph, and the preset operator categories include Conv and BN operators, the electronic device can perform operator fusion on the Conv and BN operators to obtain the network model structure shown on the left, which includes input operator, ConvBN operator, and output operator.
[0226] exist Figure 7-a In this process, by logically fusing the Conv operator and the BN operator, the computational logic of the fused ConvBN operator can be made equivalent to the computational logic when the Conv operator and the BN operator work together, thereby reducing the frequency of logical computation.
[0227] exist Figure 7-b In the network model structure shown on the left, the following are listed sequentially: input operator, multiplication (Mul) operator, output operator, input operator, addition operator, and output operator. When the nodes corresponding to the Mul and Add operators are two second-type nodes connected by a certain relation edge in the same sub-computation graph, and the preset operator categories include the Mul and Add operators, the electronic device can fuse the Mul and Add operators to obtain the network model structure shown on the left, which includes the input operator, the Mul+Add operator, and the output operator.
[0228] exist Figure 7-b In this context, the memory fusion of the Mul and Add operators allows the fused Mul+Add operator to achieve the same computational effect as the combined Mul and Add operators.
[0229] In this embodiment of the application, by fusing the operators corresponding to the second type of nodes in the second sub-computation graph as described above, the data transfer process of intermediate data can be effectively avoided, saving the time and resources required for logic execution or data computation.
[0230] In an optional embodiment, according to Figure 6The method shown in this application embodiment also provides a computational graph segmentation method. For example... Figure 8 As shown, Figure 8 This is a schematic diagram of the fourth flowchart of the computational graph segmentation method provided in the embodiments of this application. The method adds the following steps, namely steps S608-S609.
[0231] Step S608: According to the topology of the unidirectional acyclic graph, the first sub-computation graphs (excluding the second sub-computation graph) and the third sub-computation graph are combined to obtain the optimized part to be optimized.
[0232] The first sub-computation graphs mentioned above, in addition to the second sub-computation graphs, may also include: first sub-computation graphs containing only one second-type node, and / or first sub-computation graphs containing only first-type nodes.
[0233] After the electronic device performs operator fusion on the second sub-computation graphs of the multiple first sub-computation graphs to obtain the third sub-computation graph, it can combine the first sub-computation graphs (excluding the second sub-computation graph) and the third sub-computation graph according to the dependency relationship between the nodes in the unidirectional acyclic graph, that is, according to the connection relationship between the nodes in the unidirectional acyclic graph, to obtain the optimized part to be optimized.
[0234] For ease of understanding, the above will still be used. Figure 2-d For example, combined with Figure 9 Let's take an example to illustrate. Figure 9 for Figure 2-d The computation graph is obtained by combining the various sub-computation graphs after operator fusion.
[0235] Through the above steps S607-S608, Figure 2-d The operators corresponding to nodes A1, A2, A3, A4, and A6 are merged into a single fusion operator, i.e. Figure 9 The node corresponding to fusion operator 1 in the diagram; Figure 2-d The operators corresponding to nodes A7 and A8 are merged into a single fusion operator, i.e. Figure 9 The node corresponding to fusion operator 2 in the process. At this time, the electronic device according to... Figure 2-a The dependencies between nodes in the computation graph can be obtained by combining the sub-computation graphs after operator fusion, as shown below. Figure 9 The computational graph shown is the network model structure obtained after optimizing the part to be optimized mentioned above.
[0236] Step S609: Call the optimized part to be optimized.
[0237] In this step, the electronic device can call upon the optimized part to be optimized to complete the training and inference of the network model.
[0238] For ease of understanding, let's take the above network model as an example of a face recognition model. Assume that the part of the face recognition model to be optimized includes five consecutive convolutional pooling layers. The operator structure of each convolutional pooling layer is: input operator - convolution operator - output operator - input operator - pooling operator - output operator. Through steps S601-S607, all operators in the five consecutive convolutional pooling layers of the face recognition model are fused into one operator, namely the convolutional pooling operator. When training and inference of this face recognition model, the electronic device can directly use the fused convolutional pooling operator to process the face image during feature extraction (i.e., convolution and pooling operations), completing the feature extraction process and continuing with subsequent processing.
[0239] Through steps S608-S609 above, the electronic device can optimize the network model by calling the optimized part to be optimized, thereby effectively reducing the data transfer process during network model training and inference, improving the efficiency of network model training and inference, and saving system computing resources.
[0240] The above embodiments only use a face recognition model as an example to illustrate the calling of the part to be optimized. In addition, the above network model can also be a speech recognition model, behavior recognition model, etc. The above network model will also be different depending on the application scenario. Here, no specific limitation is made on the above network model.
[0241] Based on the same inventive concept, and according to the computational graph segmentation method provided in the above embodiments of this application, this application also provides a computational graph segmentation device. For example... Figure 10 As shown, Figure 10 This is a schematic diagram of a computational graph segmentation device provided in an embodiment of this application. The device may include the following modules.
[0242] The acquisition module 1001 is used to acquire the unidirectional acyclic graph corresponding to the part to be optimized in the network model. The unidirectional acyclic graph includes multiple nodes and the relationship edges between each node. The multiple nodes correspond one-to-one with the operators in the part to be optimized.
[0243] The first determining module 1002 is used to determine the nodes in the multiple nodes whose preset optimization category for the corresponding operator is not to participate in operator fusion, as the first type of nodes;
[0244] The marking module 1003 is used to mark the second type node in the parent node of each first type node as the shrinking end node and mark the second type node in the child node of the first type node as the shrinking start node. The second type node is other nodes besides the first type node among multiple nodes.
[0245] The second determining module 1004 is used to determine the weight of each relation edge in a unidirectional acyclic graph based on the node types of the two nodes connected by each relation edge.
[0246] The processing module 1005 is used to perform node shrinking processing on nodes in a unidirectional acyclic graph based on the node shrinking termination node, the node shrinking start node, and the weight of each relation edge, to obtain a condensed graph.
[0247] The segmentation module 1006 is used to segment a unidirectional acyclic graph based on a condensed graph to obtain multiple first sub-computation graphs.
[0248] Optionally, the above processing module 1005 includes:
[0249] The calculation submodule is used to calculate the longest path length between every two second-type nodes in a one-way acyclic graph based on the weight of each relation edge in the graph.
[0250] The judgment submodule is used to determine the first second-type node in the unidirectional acyclic graph that has not been shrunk as the first node according to the topology of the unidirectional acyclic graph, and to determine whether the first node and the second node meet the preset shrunk rule. The second node is a child node of the first node.
[0251] The determination submodule is used to determine the first node and the second node as nodes to be processed when the first node and the second node meet the preset shrinking rules.
[0252] The calling submodule is used to treat the second node as the first node if the second node is a second type of node. The calling submodule returns to execute the step of judging whether the first node and the second node meet the preset shrinking rules, until the first node and / or the second node do not meet the preset shrinking rules, and the first node is determined as the node to be processed.
[0253] The processing submodule is used to shrink the nodes to be processed, obtain the shrunken one-way acyclic graph, and call the judgment submodule to return and execute the step of determining the first unshrunken second type node in the one-way acyclic graph as the first node according to the topology of the one-way acyclic graph, until the one-way acyclic graph does not contain any unshrunken second type nodes, thus obtaining the shrunken graph.
[0254] The preset node shrinking rules include: when the first node is a first-type target node, the first node is not the node to terminate node shrinking, the second node is not the node to start node shrinking, the longest path length between the first second-type node that has not undergone node shrinking and the second node is the preset path length, and the shrunk graph obtained after shrinking the first node and the second node is a one-way acyclic graph; when the first node is a second-type target node, the second node is a second-type node, the longest path length between the first second-type node that has not undergone node shrinking and the second node is the preset path length, and the shrunk graph obtained after shrinking the first node and the second node is a one-way acyclic graph.
[0255] Among them, the first type of target node is a second type node whose parent node is a second type node; the second type of target node is a second type node other than the first type of target node.
[0256] Optionally, the above calculation submodule can be used to determine each path between two second-type nodes in a unidirectional acyclic graph.
[0257] For each path, calculate the path length between the two second-type nodes based on the weight of each relation edge on that path;
[0258] The maximum value among the calculated path lengths is determined as the longest path length between the two second-type nodes.
[0259] Optionally, the second determining module 1004 can be used to determine the weight of each relation edge in a unidirectional acyclic graph as a first preset weight if both nodes connected by the relation edge are second-type nodes.
[0260] If the two nodes connected by the relation edge include nodes of the first type, then the weight of the relation edge is determined to be the second preset weight.
[0261] Optionally, the above-mentioned computational graph segmentation device may further include:
[0262] The fusion module is used to perform operator fusion on the operators corresponding to the second type of nodes in each second sub-computation graph according to the operator category of each node in the second sub-computation graph, so as to obtain a third sub-computation graph including the fused operators; the second sub-computation graph is a first sub-computation graph including multiple second type nodes.
[0263] Optionally, the above-mentioned computational graph segmentation device may further include:
[0264] The combination module is used to combine the first sub-computation graphs (excluding the second sub-computation graph) and the third sub-computation graph according to the topology of the unidirectional acyclic graph, to obtain the optimized part to be optimized.
[0265] The calling module is used to invoke the optimized part that needs to be optimized.
[0266] The apparatus provided in this application, during the process of segmenting the unidirectional acyclic graph corresponding to the part of the network model to be optimized, for each first-type node in the unidirectional acyclic graph, that is, for each node in the unidirectional acyclic graph whose corresponding operator does not participate in the subsequent operator fusion process, the second-type nodes among the parent and child nodes of the node are marked as the shrinking termination node and the shrinking start node, respectively. Based on the shrinking start node, shrinking termination node and the weight of each relation edge in the unidirectional acyclic graph, the nodes in the unidirectional acyclic graph are shrunk to obtain a shrunk graph. Based on the shrunk graph, the unidirectional acyclic graph is segmented to realize the segmentation of the computation graph of the part to be optimized in the network model.
[0267] In this embodiment, based on the topology of the unidirectional undirected graph and the node type of each node, the node shrinking method in graph theory is used to mark the shrinking termination node and the shrinking start node in the unidirectional acyclic graph. This allows the partitioning problem of the unidirectional acyclic graph to be transformed into an equivalent graph theory node shrinking problem based on the marked shrinking start and termination nodes and the weight of each relation edge. Since the dependency relationship between nodes in the unidirectional acyclic graph does not need to be considered during the node shrinking process, the probability of breaking the dependency relationship between nodes is greatly increased when the unidirectional acyclic graph is partitioned based on the shrunk graph obtained from the node shrinking process. This results in lower dependency relationships between the partitioned sub-computation graphs while partitioning the computation graph of the part to be optimized in the network model. This greatly increases the probability of parallel processing of the partitioned sub-computation graphs, thereby improving the processing efficiency of the network model.
[0268] Furthermore, the aforementioned termination and start nodes for shrinking are marked for second-type nodes within the parent and child nodes of each first-type node. This means that intermediate nodes in a continuous connection of multiple second-type nodes in a unidirectional acyclic graph are not marked as termination or start nodes. This effectively increases the probability of second-type nodes of the same type being shrunk into a single node, while reducing the probability of different node types being shrunk into a single node. This significantly increases the probability of multiple consecutive second-type nodes being segmented into the same sub-computation graph, thereby reducing the number of sub-computation graphs obtained. In other words, while segmenting the unidirectional acyclic graph of the part to be optimized in the network model, the number of sub-computation graphs obtained is minimized. By controlling the number of sub-computation graphs obtained, each sub-computation graph can include as many nodes as possible, facilitating the subsequent operator fusion process and allowing as many operators as possible to be merged into one operator, thus improving the processing efficiency of the network model.
[0269] Furthermore, the first type of nodes mentioned above are nodes whose preset optimization category for the corresponding operator is not to participate in operator fusion, while the second type of nodes are other nodes in the unidirectional acyclic graph besides the first type of nodes. In other words, the second type of nodes are nodes whose preset optimization category for the corresponding operator is to participate in operator fusion. This will lay the foundation for the later operator fusion process, facilitate the later operator fusion process, and improve the efficiency of model optimization.
[0270] Based on the same inventive concept, and according to the computational graph segmentation method provided in the above embodiments of this application, this application also provides an electronic device, such as... Figure 11 As shown, it includes a processor 1101, a communication interface 1102, a memory 1103, and a communication bus 1104. The processor 1101, communication interface 1102, and memory 1103 communicate with each other via the communication bus 1104.
[0271] Memory 1103 is used to store computer programs;
[0272] When processor 1101 executes the program stored in memory 1103, it performs the following steps:
[0273] Obtain the one-way acyclic graph corresponding to the part to be optimized in the network model. The one-way acyclic graph includes multiple nodes and the relationship edges between the nodes. The multiple nodes correspond one-to-one with the operators in the part to be optimized.
[0274] Nodes that do not participate in operator fusion are identified as the first type of nodes in the preset optimization category corresponding to the operators among multiple nodes;
[0275] For each first-type node, mark the second-type node in the parent node of the first-type node as the shrinking termination node, and mark the second-type node in the child node of the first-type node as the shrinking start node. Here, the second-type node is any node other than the first-type node among multiple nodes.
[0276] The weight of each relation edge is determined based on the node types of the two nodes connected by each relation edge in a one-way acyclic graph.
[0277] Based on the node where the shrinking ends, the node where the shrinking begins, and the weight of each relation edge, the nodes in the unidirectional acyclic graph are shrunk to obtain a shrunk graph.
[0278] The unidirectional acyclic graph is divided based on the condensed graph to obtain multiple first sub-computation graphs.
[0279] In the process of segmenting the unidirectional acyclic graph corresponding to the part of the network model to be optimized using the electronic device provided in this application embodiment, for each first type node in the unidirectional acyclic graph, that is, for each node in the unidirectional acyclic graph whose corresponding operator does not participate in the subsequent operator fusion process, the second type nodes in the parent and child nodes of the node are marked as the shrinking termination node and the shrinking start node, respectively. Based on the shrinking start node, shrinking termination node and the weight of each relation edge in the unidirectional acyclic graph, the nodes in the unidirectional acyclic graph are shrunk to obtain a shrunk graph. Based on the shrunk graph, the unidirectional acyclic graph is segmented to realize the segmentation of the computation graph of the part to be optimized in the network model.
[0280] In this embodiment, based on the topology of the unidirectional undirected graph and the node type of each node, the node shrinking method in graph theory is used to mark the shrinking termination node and the shrinking start node in the unidirectional acyclic graph. This allows the partitioning problem of the unidirectional acyclic graph to be transformed into an equivalent graph theory node shrinking problem based on the marked shrinking start and termination nodes and the weight of each relation edge. Since the dependency relationship between nodes in the unidirectional acyclic graph does not need to be considered during the node shrinking process, the probability of breaking the dependency relationship between nodes is greatly increased when the unidirectional acyclic graph is partitioned based on the shrunk graph obtained from the node shrinking process. This results in lower dependency relationships between the partitioned sub-computation graphs while partitioning the computation graph of the part to be optimized in the network model. This greatly increases the probability of parallel processing of the partitioned sub-computation graphs, thereby improving the processing efficiency of the network model.
[0281] Furthermore, the aforementioned termination and start nodes for shrinking are marked for second-type nodes within the parent and child nodes of each first-type node. This means that intermediate nodes in a continuous connection of multiple second-type nodes in a unidirectional acyclic graph are not marked as termination or start nodes. This effectively increases the probability of second-type nodes of the same type being shrunk into a single node, while reducing the probability of different node types being shrunk into a single node. This significantly increases the probability of multiple consecutive second-type nodes being segmented into the same sub-computation graph, thereby reducing the number of sub-computation graphs obtained. In other words, while segmenting the unidirectional acyclic graph of the part to be optimized in the network model, the number of sub-computation graphs obtained is minimized. By controlling the number of sub-computation graphs obtained, each sub-computation graph can include as many nodes as possible, facilitating the subsequent operator fusion process and allowing as many operators as possible to be merged into one operator, thus improving the processing efficiency of the network model.
[0282] Furthermore, the first type of nodes mentioned above are nodes whose preset optimization category for the corresponding operator is not to participate in operator fusion, while the second type of nodes are other nodes in the unidirectional acyclic graph besides the first type of nodes. In other words, the second type of nodes are nodes whose preset optimization category for the corresponding operator is to participate in operator fusion. This will lay the foundation for the later operator fusion process, facilitate the later operator fusion process, and improve the efficiency of model optimization.
[0283] The communication bus mentioned in the above electronic devices can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used to represent it in the diagram, but this does not mean that there is only one bus or one type of bus.
[0284] The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0285] The memory may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0286] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0287] Based on the same inventive concept, and according to the computational graph segmentation method provided in the above embodiments of this application, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of any of the above computational graph segmentation methods.
[0288] Based on the same inventive concept, and according to the computational graph segmentation method provided in the above embodiments of this application, this application also provides a computer program product containing instructions, which, when run on a computer, causes the computer to execute any of the computational graph segmentation methods in the above embodiments.
[0289] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0290] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0291] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, embodiments such as apparatuses, electronic devices, computer-readable storage media, and computer program products are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0292] The above description is merely a preferred embodiment of this application and is not intended to limit the scope of protection of this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application are included within the scope of protection of this application.
Claims
1. A method of computing graph cut, characterized in that, The method comprises: acquiring a single-direction acyclic graph corresponding to a to-be-optimized part in a face recognition model, the single-direction acyclic graph comprising a plurality of nodes and relationship edges between the nodes, the plurality of nodes and operators in the to-be-optimized part corresponding one by one; determining a preset optimization category of an operator corresponding to a node in the plurality of nodes as a node not participating in operator fusion, as a first category node; for each first category node, marking a second category node in a parent node of the first category node as a sink node termination node, and marking a second category node in a child node of the first category node as a sink node start node, wherein the second category node is a node other than the first category node in the plurality of nodes; determining a weight of each relationship edge in the single-direction acyclic graph according to node types of two nodes connected by the relationship edge; based on the sink node termination node, the sink node start node, and the weight of each relationship edge, performing sink node processing on the nodes in the single-direction acyclic graph to obtain a sink graph; based on the sink graph, performing partitioning on the single-direction acyclic graph to obtain a plurality of first sub-computation graphs; for each second sub-computation graph, performing operator fusion on an operator corresponding to a second category node in the second sub-computation graph according to an operator category of the operator corresponding to each node in the second sub-computation graph to obtain a third sub-computation graph comprising a fused operator; the second sub-computation graph is a first sub-computation graph comprising a plurality of second category nodes; the operator fusion comprises logical fusion and memory fusion; combining, according to a topological structure of the single-direction acyclic graph, the first sub-computation graphs other than the second sub-computation graph and the third sub-computation graph in the plurality of first sub-computation graphs to obtain an optimized to-be-optimized part; when training and reasoning the face recognition model, calling the optimized to-be-optimized part to perform feature extraction on a face image to complete a feature extraction process.
2. The method of claim 1, wherein, The step of performing sink node processing on the nodes in the single-direction acyclic graph based on the sink node termination node, the sink node start node, and the weight of each relationship edge to obtain a sink graph comprises: calculating a longest path length between each two second category nodes in the single-direction acyclic graph based on the weight of each relationship edge in the single-direction acyclic graph; determining, according to a topological structure of the single-direction acyclic graph, a first node as a first node in the single-direction acyclic graph that has not been subjected to sink node processing, and determining whether the first node and a second node satisfy a preset sink node rule, the second node being a child node of the first node; when the first node and the second node satisfy the preset sink node rule, determining the first node and the second node as to-be-processed nodes; if the second node is the second category node, taking the second node as the first node, and returning to the step of determining whether the first node and the second node satisfy the preset sink node rule, until the first node and / or the second node does not satisfy the preset sink node rule, and determining the first node as the to-be-processed node; The node to be processed is point reduction processed to obtain a point reduction processed directed acyclic graph, and the step of determining the first node as a first node according to the topology of the directed acyclic graph is returned until there is no second type node that is not point reduction processed in the directed acyclic graph, and a point reduction graph is obtained; The preset point reduction rule includes: when the first node is a first type target node, the first node is not the point reduction stop node, the second node is not the point reduction start node, the longest path length between the first node and the second node is a preset path length, and the point reduction graph obtained after the point reduction processing of the first node and the second node is a directed acyclic graph; when the first node is a second type target node, the second node is the second type node, the longest path length between the first node and the second node is a preset path length, and the point reduction graph obtained after the point reduction processing of the first node and the second node is a directed acyclic graph; The first type target node is a second type node that does not have a parent node that is the second type node; and the second type target node is a second type node other than the first type target node.
3. The method of claim 2, wherein, The step of calculating the longest path length between each two second type nodes in the directed acyclic graph based on the weight of each relationship edge in the directed acyclic graph includes: For each two second type nodes in the directed acyclic graph, determine each path between the two second type nodes; For each path, calculate the path length between the two second type nodes according to the weight of each relationship edge on the path; Determine the maximum value of the calculated path lengths as the longest path length between the two second type nodes.
4. The method of claim 1, wherein, The step of determining the weight of each relationship edge in the directed acyclic graph based on the node type of the two nodes connected by the relationship edge includes: For each relationship edge in the directed acyclic graph, if the two nodes connected by the relationship edge are both the second type nodes, determine the weight of the relationship edge as a first preset weight; If the two nodes connected by the relationship edge include the first type node, determine the weight of the relationship edge as a second preset weight.
5. A computing graph cut device, comprising: The device includes: An acquisition module configured to acquire a directed acyclic graph corresponding to a to-be-optimized part in a face recognition model, the directed acyclic graph including a plurality of nodes and relationship edges between the nodes, the plurality of nodes and operators in the to-be-optimized part corresponding one-to-one; A first determination module configured to determine a preset optimization category of an operator corresponding node in the plurality of nodes as a node that does not participate in operator fusion, as a first type node; A marking module configured to, for each first type node, mark a second type node in a parent node of the first type node as a point reduction stop node, and mark a second type node in a child node of the first type node as a point reduction start node, wherein the second type node is a node other than the first type node in the plurality of nodes; The second determining module is configured to determine the weight of each relationship edge in the single-direction acyclic graph according to the node types of two nodes connected by the relationship edge; The processing module is configured to perform a sink node processing on the nodes in the single-direction acyclic graph based on the sink node, the sink start node, and the weight of each relationship edge, to obtain a sink graph; The splitting module is configured to split the single-direction acyclic graph based on the sink graph, to obtain a plurality of first sub-computation graphs; The fusion module is configured to, for each second sub-computation graph, perform operator fusion on the operators corresponding to the second-type nodes in the second sub-computation graph according to the operator categories of the operators corresponding to each node in the second sub-computation graph, to obtain a third sub-computation graph including fused operators; the second sub-computation graph is a first sub-computation graph including a plurality of second-type nodes; the operator fusion includes logical fusion and memory fusion; The combination module is configured to combine the first sub-computation graphs other than the second sub-computation graphs and the third sub-computation graphs in the plurality of first sub-computation graphs according to the topological structure of the single-direction acyclic graph, to obtain an optimized to-be-optimized part. The calling module is configured to, when training and reasoning the face recognition model, call the optimized to-be-optimized part to perform feature extraction on a face image, to complete a feature extraction process.
6. The apparatus of claim 5, wherein, The processing module includes: The computing submodule is configured to calculate the longest path length between each two second-type nodes in the single-direction acyclic graph based on the weight of each relationship edge in the single-direction acyclic graph; The judging submodule is configured to determine a first node as a first node in the single-direction acyclic graph according to the topological structure of the single-direction acyclic graph, and judge whether the first node and a second node satisfy a preset sink node rule, the second node being a child node of the first node; The determining submodule is configured to determine the first node and the second node as to-be-processed nodes when the first node and the second node satisfy the preset sink node rule; The calling submodule is configured to, if the second node is the second-type node, take the second node as the first node, call the judging submodule to return to execute the step of judging whether the first node and the second node satisfy the preset sink node rule, until the first node and / or the second node does not satisfy the preset sink node rule, and determine the first node as the to-be-processed node; The processing submodule is configured to perform sink node processing on the to-be-processed nodes, to obtain a sink-processed single-direction acyclic graph, and call the judging submodule to return to execute the step of determining a first node as a first node in the single-direction acyclic graph according to the topological structure of the single-direction acyclic graph, until the single-direction acyclic graph does not include a second-type node that has not been processed, to obtain a sink graph. The preset condensing point rule comprises: when the first node is a first type target node, the first node is not the condensing point termination node, the second node is not the condensing point starting node, the longest path length between the first uncondensed second type node and the second node is a preset path length, and the condensed graph obtained after the condensing point processing of the first node and the second node is a unidirectional acyclic graph; when the first node is a second type target node, the second node is the second type node, the longest path length between the first uncondensed second type node and the second node is a preset path length, and the condensed graph obtained after the condensing point processing of the first node and the second node is a unidirectional acyclic graph. The first type target node is a second type node without a parent node being the second type node; and the second type target node is a second type node other than the first type target node.
7. An electronic device, comprising: The device comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus. The memory is used for storing a computer program. The processor is used for executing the program stored in the memory, and realizes the method steps in any one of claims 1-4.
8. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to realize the method steps in any one of claims 1-4.
Citation Information
Patent Citations
Deep learning computational graph optimization method based on longest path fusion algorithm
CN113326869A
A calculation graph node division method and device and a computer readable storage medium
CN113553287A