Algorithm model subgraph division method, device and equipment and readable storage medium
By converting the AI algorithm model into a sequence of processing nodes and dividing paths according to the division cost, the problem of long compilation time and low operating efficiency of the AI algorithm model is solved, and a balance between compilation speed and operating efficiency is achieved.
Patent Information
- Application Number
- CN202410844471.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-27
- Publication Date
- 2024-09-17
AI Technical Summary
In the existing technology, the compilation of AI algorithm models takes a long time or the running efficiency of the compiled model is not high, and it is impossible to take into account both.
By converting the AI algorithm model into a sequence of processing nodes, and dividing the processing nodes according to the minimum cost path and additional random paths, the divided subgraph sequence is obtained to ensure a balance between compilation speed and operating efficiency.
It is possible to improve the running efficiency of the compiled model while maintaining compilation speed, avoid local minimum value traps, and ensure comprehensive optimization of hardware efficiency.
Smart Images

Figure CN118656080A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of compiler technology, and in particular to a method, device, equipment and readable storage medium for partitioning an algorithm model into subgraphs. Background Art
[0002] The development of AI (artificial intelligence) technology has promoted the development of AI compilers. AI compilers can compile AI algorithm models into machine codes that can be efficiently processed by AI processors. However, since AI algorithm models are programs with large computational complexity and large memory usage, and limited by cost factors, it is usually difficult for AI algorithm model graphs converted from AI algorithm models to be loaded into AI chips in their entirety.
[0003] Therefore, the common practice at this stage is to divide the AI algorithm model graph into segments of sub-graphs, which are then loaded and processed by the AI chip segment by segment. At present, the common AI algorithm model graph division methods in academia and industry are:
[0004] First, based on manual division, or based on template matching. When compiling an AI algorithm model, the compiler matches the template structure in the template library one by one in a certain way, thereby dividing the large AI algorithm model graph into sub-graphs to meet the back-end hardware requirements.
[0005] This method has the advantage of fast compile time, but its disadvantage is that template division relies on artificial priors. At the same time, due to the continuous development of AI algorithm models, it is difficult for the template library to cover new structures. In the face of new model structures, the compiled model has poor running efficiency.
[0006] Second, based on exhaustive search, also known as brute force search, the basic idea is to exhaustively search for possible AI algorithm model graph partitioning methods one by one, and select a set of graph partitionings with the highest runtime efficiency.
[0007] This method is simple and crude. Due to its global optimal characteristics, it has the advantage of high running efficiency of the compiled model. However, its disadvantages are also very obvious. Due to the deep characteristics of the AI model, the compilation time of the method based on exhaustive search is particularly long.
[0008] Third, based on extreme partitioning. The so-called extreme partitioning means that each node in the AI model graph is divided into a subgraph. After the division, the number of subgraphs is equal to the number of nodes in the original AI model. This division method shortens the compilation time, but is limited by the fact that the AI model graph is divided too fragmented, resulting in a sharp increase in the amount of off-chip on-chip memory access, low hardware utilization, and low efficiency of the compiled model.
[0009] Therefore, the current technical solutions have the problem that it takes a long time to compile the AI algorithm model or the compiled model has low running efficiency. Summary of the invention
[0010] In view of this, the purpose of the present invention is to provide an algorithm model subgraph partitioning method, device, equipment and readable storage medium, which solves the problem in the prior art that the time consumption of the algorithm model and the operating efficiency of the compiled model cannot be taken into account at the same time.
[0011] In order to solve the above technical problems, the present invention provides an algorithm model subgraph partitioning method, comprising:
[0012] Converting the AI algorithm model into a processing node sequence, wherein the processing node sequence includes a plurality of processing nodes;
[0013] According to a first number of partition paths and an additional second number of partition paths with the smallest partition costs respectively corresponding to the plurality of processing nodes, the processing node sequence is partitioned to obtain a subgraph sequence after partitioning;
[0014] The first number is a positive integer, the second number is a non-negative integer, the partitioning cost reflects the total hardware efficiency when partitioning is performed according to the corresponding partitioning path, and the partitioning path is a path formed by combining the corresponding processing node in the processing node sequence and other nodes before the corresponding processing node under the partitioning rule corresponding to the partitioning cost.
[0015] Optionally, the step of dividing the processing node sequence according to a first number of division paths and an additional second number of division paths with the smallest division costs respectively corresponding to the plurality of processing nodes to obtain a divided subgraph sequence includes:
[0016] sequentially selecting a first processing node from among the plurality of processing nodes;
[0017] Whenever the first processing node is selected, a first number of partition paths and an additional second number of partition paths corresponding to a second processing node with the smallest partition cost are obtained, wherein the second processing node is a processing node preceding the first processing node in the processing node sequence;
[0018] generating a plurality of partition paths corresponding to the first processing node based on a first number of partition paths with the smallest partition costs corresponding to the second processing node and an additional second number of partition paths;
[0019] Selecting a first number of division paths with the minimum division cost corresponding to the first processing node from the multiple division paths corresponding to the first processing node, and additionally selecting a second number of division paths corresponding to the first processing node from the remaining division paths except the selected division path, and returning to continue selecting the first processing node until the first number of division paths with the minimum division cost corresponding to the last first processing node and the additional second number of division paths are selected;
[0020] A target partitioning path is selected from a first number of partitioning paths with the smallest partitioning cost corresponding to the last first processing node and an additional second number of partitioning paths, and the processing node sequence is partitioned according to the target partitioning path to obtain a divided subgraph sequence.
[0021] Optionally, the multiple division paths corresponding to the first processing node include a first path and a second path;
[0022] The first path is a path including any one of the partition paths corresponding to the second processing node and a node block, and the node block includes the first processing node and the second processing node;
[0023] The second path is a path including any one of the divided paths corresponding to the second processing node and a node block composed solely of the first processing node;
[0024] The partition cost is equal to A+B, where A is the cost of the node block, and B is the sum of the costs of the remaining node blocks except the node block in the partition path corresponding to the partition cost.
[0025] Optionally, the selecting, from the plurality of partition paths corresponding to the first processing node, a first number of partition paths with minimum partition costs corresponding to the first processing node includes:
[0026] Screening out the partitioning paths that do not meet the hardware restriction condition from among the multiple partitioning paths corresponding to the first processing node;
[0027] A first number of partition paths with minimum partition costs are selected from the screened partition paths as the first number of partition paths with minimum partition costs corresponding to the first processing node.
[0028] Optionally, the additionally selecting a second number of division paths corresponding to the first processing node from the remaining division paths except the selected division path includes:
[0029] A second number of partition paths are randomly selected from the remaining partition paths as additional second number of partition paths corresponding to the first processing node.
[0030] Optionally, after obtaining the divided subgraph sequence, the method further includes:
[0031] Compile the target instruction sequence corresponding to the divided subgraph sequence;
[0032] The target instruction sequence is executed on a processor.
[0033] Optionally, converting the AI algorithm model into a processing node sequence includes:
[0034] Convert the AI algorithm model into an intermediate representation graph of a compiler;
[0035] Optimizing the intermediate representation graph to obtain an operator node graph;
[0036] Combining adjacent operator nodes in the operator node graph that can flow in parallel into a combined operator node;
[0037] Generate a processing node topology map according to the operator nodes and the combination operator nodes; the processing node is the operator node or the combination operator node;
[0038] A topological sort is performed according to the processing node topology graph to obtain the processing node sequence.
[0039] The present application also provides an algorithm model subgraph partitioning device, comprising:
[0040] An AI algorithm model conversion module, used to convert the AI algorithm model into a processing node sequence, wherein the processing node sequence includes a plurality of processing nodes;
[0041] A target model partition subgraph determination module, configured to partition the processing node sequence according to a first number of partition paths with the smallest partition costs respectively corresponding to a number of the processing nodes and an additional second number of partition paths, to obtain a subgraph sequence after partitioning;
[0042] The first number is a positive integer, the second number is a non-negative integer, the partitioning cost reflects the total hardware efficiency when partitioning is performed according to the corresponding partitioning path, and the partitioning path is a path formed by combining the corresponding processing node in the processing node sequence and other nodes before the corresponding processing node under the partitioning rule corresponding to the partitioning cost.
[0043] The present application also provides an electronic device, characterized in that it includes:
[0044] Memory for storing computer programs;
[0045] A processor is used to implement the steps of the algorithm model subgraph partitioning method as described above when executing the computer program.
[0046] The present application also provides a readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the algorithm model subgraph partitioning method as described above are implemented.
[0047] It can be seen that the present invention converts the AI algorithm model into a processing node sequence, and the processing node sequence includes a plurality of processing nodes; the processing node sequence is divided according to a first number of division paths with the smallest division costs corresponding to the plurality of processing nodes and an additional second number of division paths to obtain a subgraph sequence after division; the first number is a positive integer, the second number is a non-negative integer, the division cost reflects the total hardware efficiency when dividing according to the corresponding division path, and the division path is a path formed by combining the corresponding processing node in the processing node sequence with other nodes before the corresponding processing node under the division rule corresponding to the division cost.
[0048] The present invention abstracts the subgraph partitioning problem into the problem of path partitioning in a processing node sequence according to the partitioning cost. For several processing nodes in the processing node sequence, only a first number of paths with the smallest partitioning cost and an additional second number of paths need to be memorized, so that the partitioning of the processing node sequence is performed in a local neighborhood, with low time complexity and still having excellent compilation speed when processing deep subgraph partitioning.
[0049] At the same time, memorizing the first number of partition paths with the lowest partition cost for several processing nodes can effectively avoid falling into local minima, and additionally (randomly) memorizing the second number of partition paths can increase disturbances, thereby increasing the probability of jumping out of local minima and ensuring high efficiency of the compiled model. Therefore, the present application can flexibly and effectively balance the compilation speed and the running efficiency of the compiled model, solving the problem in the prior art that the time consumption of the algorithm model and the running efficiency of the compiled model cannot be taken into account at the same time. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.
[0051] Figure 1 A flowchart of a subgraph partitioning method for an algorithm model provided by an embodiment of the present invention;
[0052] Figure 2 A schematic diagram of a processing node sequence provided by an embodiment of the present invention;
[0053] Figure 3A schematic diagram of a node block composed of a first processing node and a second processing node provided in an embodiment of the present invention;
[0054] Figure 4 A schematic diagram of a third processing node division method provided by an embodiment of the present invention;
[0055] Figure 5 A schematic diagram of a fourth processing node division method provided by an embodiment of the present invention;
[0056] Figure 6 A schematic diagram of the structure of an algorithm model subgraph partitioning device provided by an embodiment of the present invention;
[0057] Figure 7 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0058] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0059] On the one hand, in order to meet the requirements of operating efficiency, different operators of the AI algorithm model may run on different hardware backends. Different hardware backends may include, for example, CPU, GPU, NPU, and DSP, which creates requirements for the division of the AI algorithm model.
[0060] On the other hand, due to hardware resource limitations, large graphs must be divided into small subgraphs so that the AI algorithm model can be loaded and executed smoothly. In addition, in edge AI chips, subgraphs are also required to be divided into smaller computing blocks to meet hardware resource limitations.
[0061] It is understandable that different subgraph partitioning methods directly affect important AI chip indicators such as AI chip computing array efficiency, off-chip memory access, and on-chip memory usage (i.e., post-compilation running efficiency). In addition, since AI algorithm models are usually very deep (with many layers), if the graph partitioning method is not selected properly, the AI compiler will be very time-consuming in the graph partitioning stage.
[0062] In summary, in the field of AI compilers, the division of AI algorithm model graphs is one of the important processes and factors that affect the running efficiency and compilation time of the compiled model.
[0063] In addition to the three AI algorithm model subgraph partitioning methods and corresponding problems mentioned in the background technology, the related technology also includes the following partitioning methods:
[0064] 1. Division method based on machine learning. The basic idea is to use machine learning methods to train a model that can predict the division of AI algorithm model graphs, and then use the model to predict the division of the AI algorithm model graph to be compiled, thereby realizing the division of the AI algorithm model graph in the compilation stage. Since the division of the AI algorithm model graph in the compilation stage is based on model prediction, it is fast. However, its shortcomings are also obvious and direct. As AI technology is constantly developing, various new model structures are constantly evolving, and the performance is poor in front of new AI algorithm models. At the same time, since it is a predictive model graph division, there is a natural deviation between the predicted value and the optimal value.
[0065] 2. Greedy-based subgraph partitioning method. This method generally first defines the cost function, such as the number of cycles in the AI chip simulator and the amount of on-chip and off-chip memory access. Then, based on the cost function, determine whether to include the next node in the current subgraph (if the cost function reflects a positive return, the node is included in the current subgraph; if the cost function reflects a negative return, the next subgraph partition is started). This method compiles quickly, but its disadvantage is that it is easy to fall into a local optimum, which makes the compiled model run inefficiently.
[0066] 3. Partitioning method based on dynamic programming. The method based on dynamic programming can generally achieve a better solution in global graph partitioning, but due to the deep characteristics and complex topological relationships of the AI algorithm model, the compilation takes a long time.
[0067] In summary, the subgraph partitioning schemes in the related art can basically be summarized as the problem that it takes a long time to compile the AI algorithm model or the compiled model has low running efficiency. The two have their own strengths and weaknesses, and you cannot have both. It is impossible to flexibly balance the compilation speed and the running efficiency of the compiled model as needed.
[0068] In particular, in some scenarios that require a dynamic and flexible balance between the time consumption of model compilation and the running efficiency of the compiled model, existing technical solutions are difficult to meet.
[0069] For example, when evaluating the feasibility of model deployment, we hope to obtain the evaluation results of a large number of models relatively quickly; in actual deployment, we hope that a selected target model will run efficiently after compilation. At this time, we need to dynamically and flexibly balance the compilation speed of the model and the running efficiency of the compiled model according to actual needs, but it is obvious that the above solution is difficult to meet the needs.
[0070] In order to solve at least one of the above technical problems, the present application fully considers the computational sequentiality and locality of the AI algorithm model graph structure, and provides an AI algorithm model graph partitioning scheme that uses the memory TopK minimum partitioning cost, and specifically provides an algorithm model subgraph partitioning method, device, equipment, readable storage medium and computer program product, which can improve the above-mentioned problem of the time consumption of compiling the AI algorithm model and the running efficiency of the compiled model, and balance the time consumption of compiling the AI algorithm model and the running efficiency of the compiled model. The algorithm model subgraph partitioning method is first introduced below.
[0071] Please refer to Figure 1 , Figure 1 A flowchart of a subgraph partitioning method for an algorithm model provided by an embodiment of the present invention. The method may include:
[0072] S101, converting the AI algorithm model into a processing node sequence, where the processing node sequence includes a number of processing nodes.
[0073] The execution subject of this embodiment may be any electronic device, which may include a compiler and can divide the algorithm model (graph), or the electronic device is a compiler.
[0074] The above AI algorithm model is an AI model involved in the field of AI compilers. The processing node sequence in this embodiment generally refers to a sequence consisting of a series of nodes arranged in a specific order in a certain data structure.
[0075] For example, the processing node sequence in this embodiment may be a processing node list; or the processing node sequence in this embodiment may be a processing node linear relationship; or the processing node sequence in this embodiment may also be a processing node graph.
[0076] For example, this embodiment can convert the AI algorithm model into a PU (Process Unit) graph, and then use the PU graph as or convert it into a processing node sequence; or this embodiment can convert the AI algorithm model into a PU graph, and then according to some special PU nodes, the PU graph can be divided into a first-level sub-graph set to obtain a processing node sequence.
[0077] It should be noted that the PU graph can be divided into at least one first-level sub-graph, and the first-level sub-graphs in the first-level sub-graph set can be processed in parallel to speed up the division of the entire PU graph, that is, to improve the speed of the entire sub-graph division.
[0078] The so-called special PU nodes refer to PU nodes where two nodes cannot be processed together or the hardware efficiency is extremely low when they are processed together due to the hardware resource limitation of the AI processor. Therefore, some sub-graphs that can be processed together can be processed in parallel to speed up the division of the overall PU graph.
[0079] The topological relationship between the nodes of the above processing node sequence can be guaranteed by a shadow topological graph, and the shadow topological graph can be generated for the PU graph after the PU graph is obtained. The shadow topological graph can represent the topological relationship of the PU nodes.
[0080] It should be further explained that the above-mentioned conversion of the AI algorithm model into a processing node sequence may include:
[0081] S1011, converting the AI algorithm model into an intermediate representation graph in the compiler;
[0082] S1012, optimizing the intermediate representation graph to obtain an operator node graph;
[0083] S1013, combining adjacent operator nodes in the operator node graph that can flow in parallel into a combined operator node;
[0084] S1014, generating a processing node topology map according to the operator nodes and the combined operator nodes;
[0085] Wherein, the processing node is the above-mentioned operator node or combined operator node;
[0086] S1015, performing topological sorting according to the processing node topology graph to obtain a processing node sequence.
[0087] In this embodiment, the AI algorithm models of various front-end AI frameworks can be converted into a unified IR (Intermediate Representation) graph of the compiler, and then the IR graph is subjected to various optimization processes, such as various Passes (compiler terminology, optimization processes), and finally converted into an OP (Operator) node graph that can be supported by the AI processor.
[0088] In order to make full use of the parallel relationship of multiple computing engines of AI processors, adjacent OP nodes that can be pipelined in parallel can be further combined into a new node, represented by a COP node (Combined OP, combined operator node), and replace the original node to better realize the parallel pipeline after calculation block, and improve the running efficiency of the compiled model.
[0089] For the convenience of representation, the remaining OP nodes and COP nodes can also be uniformly recorded as PU (Process Unit) nodes. A PU node contains at least one OP node. At this point, the AI algorithm model is converted into a PU topology graph represented by PU nodes.
[0090] Subsequently, the topological relationship of the PU nodes can be sorted according to the sequential processing characteristics of the PU nodes to obtain a processing node sequence.
[0091] For another example, the PU graph can be divided into a set of first-level sub-graphs according to some special PU nodes, and then the topological relationship of the PU nodes can be sorted according to the PU node sequence processing characteristics, and the first-level sub-graph can be regarded as a PU node table (i.e., a processing node sequence). The content of the PU node table is the topologically sorted PU nodes.
[0092] Since this embodiment combines adjacent operator nodes that can be pipelined in parallel into a new combined operator node, the operator nodes that can be pipelined in parallel are merged, thereby reducing the number of processing nodes that can be processed subsequently and improving the subgraph partitioning efficiency.
[0093] S102, dividing the processing node sequence according to a first number of division paths with the smallest division costs corresponding to a number of processing nodes and an additional second number of division paths to obtain a divided subgraph sequence;
[0094] In this embodiment, the sum of the first number and the second number is less than or equal to the number of all node division paths. The first number K is a positive integer, and the second number E is a non-negative integer.
[0095] When performing the above-mentioned partition path selection, the number of partition paths with the smallest partition cost selected successively, that is, each first number, can be consistent; the number of additional partition paths selected successively, that is, each second number, can be consistent.
[0096] Alternatively, each first number and each second number may be inconsistent or not completely consistent. For example, when selecting the division path corresponding to the last processing node, only one or two division paths with the smallest division cost may be selected without performing additional division path selection, and when selecting the division paths corresponding to other processing nodes except the last processing node, the same first number and the same second number may be set.
[0097] The above-mentioned additional division paths refer to other division paths other than the first number of division paths with the lowest division cost selected, and the second number of division paths can be selected from the other division paths. Therefore, in some examples, the division paths in the second number of division paths are different from the division paths in the first number of division paths.
[0098] It should be noted that since AI algorithm models usually contain convolution operations, when the spatial dimensions (feature map length and width) of PU nodes containing convolution operations and convolution kernels > 1 are divided into blocks, conical division will occur.
[0099] In some embodiments, K+E>1, and K+E is less than . It can be known that: when K=1, E=0, the partitioning method may degenerate into a simple greedy algorithm, which has a very fast partitioning speed but is prone to fall into a local minimum. When K+E is large enough, assuming that the graph to be partitioned has N PU nodes, when When , the partitioning method degenerates into an exhaustive search method, which can obtain the global optimal solution for graph partitioning, but it is very time-consuming. When the values of K and E are within this range, the compilation speed and the running efficiency of the compiled model can be well balanced on demand.
[0100] The above partitioning cost reflects the total hardware efficiency when partitioning according to the corresponding partitioning path. The above partitioning cost can reflect the comprehensive efficiency of the back-end model runtime after the front-end path partitioning and subgraph partitioning. The partitioning path is the path formed by combining the corresponding processing node in the processing node sequence and other nodes before the corresponding processing node under the partitioning rule corresponding to the partitioning cost.
[0101] The partition cost can be obtained through the cost function, which can be defined as the number of cycles, on-chip and off-chip memory access, on-chip memory usage and their combination given by the simulator, computing model, etc. in the subgraph partition state; it can also be the theoretical number of cycles, on-chip and off-chip memory access, on-chip memory usage and their combination; it can also be the actual running time, on-chip and off-chip memory access, on-chip memory usage and their combination. In short, the partition cost given by the cost function can reflect the hardware efficiency of the subgraph partition path.
[0102] Based on the cost function, the partition cost of the current processing node and all nodes before the processing node when they are partitioned according to the corresponding partition path can be determined, so that the memory of TopK minimum cost subgraphs combined with RamdomE partitioning can be implemented for several processing nodes in each first-level subgraph / processing node sequence, that is, the K partition paths with the minimum partition cost and additional memory, such as additional random memory of E partition paths, are memorized for each processing node, and finally partitioning is performed based on this to obtain a subgraph sequence after division.
[0103] It should be noted that for each processing node, there are a first number of partition paths and an additional second number of partition paths, that is, multiple partition paths are formed. When the values of K and E are appropriate, this solution only needs to remember K (first number) + E (second number) partition paths, and the time complexity is O(n). When processing deep graph partitions, it still has excellent compilation speed. At the same time, memorizing K minimum cost partition paths can effectively avoid falling into local minima, and the additional random memorization of E partition paths can effectively increase the probability of jumping out of local minima, so the compiled model runs efficiently.
[0104] In summary, the present application abstracts the subgraph partitioning problem into the problem of path partitioning according to the partitioning cost in the processing node sequence. For several processing nodes in the processing node sequence, only a first number of paths with the smallest partitioning cost and an additional second number of paths need to be remembered, so that the partitioning of the processing node sequence is performed in a local neighborhood, with low time complexity, and still has excellent compilation speed when processing deep subgraph partitioning.
[0105] At the same time, memorizing the first number of partition paths with the lowest partition cost for several processing nodes, that is, memorizing the TopK minimum cost partition paths, can effectively avoid falling into local minima, and memorizing an additional second number of partition paths can increase disturbances, thereby increasing the probability of jumping out of local minima and ensuring high efficiency of the compiled model. Therefore, the present application can flexibly and effectively balance the compilation speed and the running efficiency of the compiled model, solving the problem in the prior art that the time-consuming algorithm model and the running efficiency of the compiled model cannot be taken into account at the same time.
[0106] It should be further explained that the above-mentioned subgraph sequence obtained by dividing the processing node sequence according to the first number of division paths with the smallest division costs corresponding to the plurality of processing nodes and the additional second number of division paths may include:
[0107] S1021, selecting a first processing node from a plurality of processing nodes in sequence;
[0108] S1022, each time a first processing node is selected, obtaining a first number of partition paths and an additional second number of partition paths corresponding to a second processing node with the smallest partition cost;
[0109] The second processing node is a previous processing node of the first processing node in the processing node sequence;
[0110] S1023, generating a plurality of partition paths corresponding to the first processing node based on the first number of partition paths with the smallest partition costs corresponding to the second processing node and the additional second number of partition paths;
[0111] S1024, selecting a first number of division paths with the minimum division cost corresponding to the first processing node from the multiple division paths corresponding to the first processing node, and additionally selecting a second number of division paths corresponding to the first processing node from the remaining division paths except the selected division path, and returning to continue selecting the first processing node until the first number of division paths with the minimum division cost corresponding to the last first processing node and the additional second number of division paths are selected;
[0112] S1025, selecting a target partitioning path from the first number of partitioning paths with the smallest partitioning cost corresponding to the last first processing node and the additional second number of partitioning paths, and partitioning the processing node sequence according to the target partitioning path to obtain a subgraph sequence after partitioning.
[0113] It should be noted that, in this embodiment, each processing node has three options when being divided:
[0114] w1: It is grouped together with the previous processing node block to form a new node block;
[0115] w2: The processing node becomes a node block alone;
[0116] w3: forms a new node block with the next processing node.
[0117] Since the first processing node has no preceding processing node and the last processing node has no succeeding processing node, it can be understood that the first processing node and the last processing node have the above two types of selections when being divided into node blocks, namely, w2 selection and w1 / w3 selection.
[0118] Furthermore, for other processing nodes, since the w3 selection and the w1 selection when the next processing node is the target node have the same result, in order to simplify the calculation, the other processing nodes can remove the repeated w3 selection.
[0119] Therefore, there are two non-repetitive selection methods (partitioning rules) for all target processing nodes: either as a single node block, or as a node block with the previous (or next) processing node.
[0120] For ease of understanding, the following combination Figures 2 to 6 To illustrate with an example, the solid circle in the figure represents the processing node, that is, the PU node, and the dotted ellipse in the figure represents the node block after division.
[0121] like Figure 2 As shown, a first-level subgraph contains N processing nodes, which are sorted according to the topological relationship to form the PU node table (ie, processing node sequence) shown.
[0122] Please also see Figure 2 and Figure 3 As shown, after the first quantity K and the second quantity E are set, the cost function can be used to determine Figure 2 The partitioning paths corresponding to the first processing node and the second processing node in .
[0123] Since the first processing node does not have the previous processing node, it can temporarily form a single node block, that is, form a partition path. On this basis, multiple partition paths corresponding to the second processing node can be generated, namely c1 and c2. c1 is based on the partition path of the first processing node, and the first processing node and the second processing node together form a node block; c2 is based on the partition path of the first node, and the first processing node alone forms a node block, and the first processing node and the second processing node belong to different node blocks.
[0124] Assuming that the first number K=3 and the second number E=0, then it is necessary to remember the Top3 partitioning paths with the smallest partitioning costs corresponding to the second processing node. However, the second processing node has two corresponding partitioning paths in total, so both partitioning paths can be retained and remembered.
[0125] Based on the above example, it can be seen that in this embodiment, each time the first processing node is selected, the multiple division paths corresponding to the first processing node include two types, that is, the multiple division paths corresponding to the first processing node include a first path and a second path.
[0126] The first path is a path including any partition path corresponding to the second processing node and a node block, the node block including the first processing node and the second processing node, for example, the node block is composed of the first processing node and the second processing node, similar to Figure 2 The path c1, w1 selection method in .
[0127] The second path is a path including any one of the partition paths corresponding to the second processing node and a node block composed of the first processing node alone, similar to Figure 2 The path c2, w2 selection method in .
[0128] It can be understood that node blocks are the basis for subgraph partitioning, and different combinations of node blocks form different total partitioning costs.
[0129] Continue to explain with the diagram. Figure 3 On this basis, multiple partitioning paths corresponding to the third processing node can be simulated and generated based on the two partitioning paths corresponding to the second processing node.
[0130] Please see Figure 4 , Figure 4 is Figure 3 Based on this, a third processing node division method and division path diagram is provided. Figure 3 The second processing node is divided into c1 and c2 paths, and the third processing node can be correspondingly divided into four divided paths, namely c1 to c4.
[0131] Since it is necessary to select the first number of division paths with the smallest division costs from the multiple division paths c1 to c4 corresponding to the third processing node when the first processing node becomes the third processing node, that is, it is necessary to remember the Top3 division paths, the division cost of each division path can be calculated based on the cost function.
[0132] It should be noted that the partition cost is equal to A+B, where A is the partition cost of the node block, and B is the sum of the partition costs of the remaining node blocks except the node block in the partition path corresponding to the partition cost.
[0133] It can be known that the total partition cost of the current partition path is equal to the sum of the current node block partition cost A and the partition costs B of the remaining node blocks in this path. Using this rule, the path partition cost calculation can be simplified so that the subgraph partition calculation is always performed in the local adjacent domain.
[0134] Corresponding to Figure 4 , that is, when the two partitioning paths of the second processing node are generated, the partitioning costs corresponding to c1 and c2 can be obtained. Based on the cost function and the two partitioning paths of the second processing node, the partitioning costs of multiple partitioning paths corresponding to the third processing node can be obtained.
[0135] For example Figure 4 The partition cost of the partition path c4 corresponding to the third processing node in is equal to the partition cost when the third processing node is used alone as a node block plus the partition cost when the second processing node and the first processing node form a node block.
[0136] The partition cost of the partition path c2 corresponding to the third processing node is equal to the sum of the node costs when the first processing node, the second processing node and the third processing node are all individually regarded as node blocks.
[0137] After calculation, the four partition paths c1 to c4 corresponding to the third processing node have the following partition costs: C1 to C4 have the following size relationship: cost C1 <C3<C4<C2。
[0138] If the TOP3 minimum cost partitioning costs are remembered and the additional 0 partitioning paths are remembered, then C2 is forgotten, and the partitioning cost paths selected by the third processing node are c1, c3, and c4.
[0139] If the TOP2 minimum cost partitioning costs are remembered and the additional 0 partitioning paths are remembered, then C2 and C4 are forgotten, and the partitioning cost paths selected by the third processing node are c1 and c3.
[0140] Similarly, see Figure 4 and Figure 5, based on the partitioning cost paths c1, c3, and c4 corresponding to the selection of the third processing node, multiple partitioning paths corresponding to the fourth processing node can be simulated and generated, that is Figure 5 c1 to c6 in Figure 5 . Then, calculate the partitioning costs of each partitioning path according to the cost function, and finally select the three partitioning paths with the smallest memorized partitioning costs, which are respectively
[0141] c1 to c3 in
[0142] Figure 5 Specifically, for the multiple partitioning paths c1 to c6 corresponding to the fourth processing node, their corresponding partitioning costs are C1 to C6, and the sorting relationship is C1 < C3 < C2 < C4 < C6 < C5. When memorizing the partitioning paths of the fourth processing node, based on memorizing the partitioning paths c1, c3, and c4 corresponding to the third processing node, w1 and w2 selections can be made for the fourth processing node.
[0143] In
[0144] , c1 and c2 shown in the upper part of the figure represent w1 and w2 selections for the c1 path memorized by the third processing node, respectively obtaining two partitioning paths with partitioning costs of C1 and C2. c3 and c4 shown in the middle part of the figure represent w1 and w2 selections for the c4 path memorized by the third processing node, respectively obtaining two partitioning paths with partitioning costs of C3 and C4. c5 and c6 shown in the lower part of the figure represent w1 and w2 selections for the c3 path memorized by the third processing node, respectively obtaining two partitioning paths with partitioning costs of C5 and C6.
[0143] Since the cost sorting result of the 6 partitioning paths is C1 < C3 < C2 < C4 < C6 < C5, according to memorizing the Top3 paths with the smallest costs and additionally memorizing 0 partitioning paths, the partitioning paths corresponding to C1, C3, and C2 are memorized, and the paths corresponding to C4, C6, and C5 are forgotten.
[0144] It should be noted that the above shows the process of memorizing the Top3 partitioning paths, and the paths of other first quantities and additional second quantities of partitioning costs can also be referred to and executed.
[0145] For example, referring to Figure 5 , when the second quantity is equal to 1, one more path can be additionally selected from the paths corresponding to the forgotten C4, C6, and C5, which can increase the perturbation, thereby increasing the probability of jumping out of the local minimum and ensuring high operating efficiency of the compiled model.
[0146] For example, when the first quantity is equal to 2 and the second quantity is equal to 0, c1 and c3 can be selected as the partitioning paths obtained by the selection of this node.
[0147] In some embodiments, the method of selecting the additional second number of division paths from the remaining division paths corresponding to the processing node may be to randomly select the second number of division paths from the remaining division paths as the additional second number of division paths corresponding to the first processing node. This embodiment randomly selects from the remaining division paths, which can improve the randomness of the disturbance.
[0148] Of course, in other implementation schemes, the selection may also be performed according to other rules, such as selecting a second number of partition paths with the smallest or largest partition costs from the remaining partition paths.
[0149] It should be further explained that, considering the hardware condition limitation, the above-mentioned selecting the first number of partition paths corresponding to the first processing node with the minimum partition cost from the multiple partition paths corresponding to the first processing node may include:
[0150] The partition paths that do not meet the hardware restriction condition are screened out from the multiple partition paths corresponding to the first processing node; and the first number of partition paths with the smallest partition cost are selected from the screened out partition paths as the first number of partition paths with the smallest partition cost corresponding to the first processing node.
[0151] Subsequently, a second number of division paths corresponding to the first processing node can be additionally selected from the remaining division paths, and the first processing node can be returned to continue to be selected until the first number of division paths with the smallest division cost corresponding to the last first processing node and the additional second number of division paths are selected. The processing node sequence can be divided according to the first number of division paths with the smallest division cost corresponding to the last first processing node and the additional randomly selected second number of division paths to obtain a divided subgraph sequence.
[0152] For example, a target partitioning path can be selected from a first number of partitioning paths with the smallest partitioning cost corresponding to the last first processing node and an additional randomly selected second number of partitioning paths, and the processing node sequence can be partitioned according to the target partitioning path to obtain a divided subgraph sequence.
[0153] This embodiment can eliminate the division paths that do not meet the hardware restrictions, such as the division paths that do not reach the preset hardware efficiency value, and select the division paths that meet the hardware condition restrictions to perform division path memory based on the division cost, thereby preventing the division and operation of subsequent sub-graphs from being affected by hardware condition restrictions and improving the overall operation efficiency.
[0154] It should also be noted that when the first number of division paths with the smallest division cost and the additional second number of division paths corresponding to the last processing node are completed and memorized, the division path with the smallest division cost can be randomly or selected as the target division path. In other examples, the division path with the second smallest division cost can also be selected as the target division path.
[0155] Subsequently, each processing node in the processing node sequence may be divided according to this method or the target division path to obtain a divided subgraph sequence.
[0156] Subsequently, the target instruction sequence corresponding to the divided subgraph sequence can be obtained by compiling through a compiler; and the target instruction sequence can be run on a processor.
[0157] It should be noted that, as stated above, the PU graph can be divided into at least one first-level subgraph, and the first-level subgraphs in the first-level subgraph set can be processed in parallel. Correspondingly, after compiling the divided subgraph sequence, a subgraph instruction sequence can be obtained, and all subgraph instruction sequences can be combined according to the shadow topology graph to obtain a first-level group graph instruction stream, also known as a first-level group graph instruction sequence, and finally all first-level subgraph instruction streams are combined to obtain the target instruction sequence of the AI model.
[0158] Since the target instruction sequence is compiled based on the target model partition subgraph, and the target model partition subgraph is obtained by dividing each node block with reference to the TopK minimum partition cost and the additional second quantity partition cost, it can effectively balance the compilation speed and the running efficiency of the compiled model.
[0159] A method for dividing an algorithm model into subgraphs provided in this embodiment may include: S101, converting an AI algorithm model into a processing node sequence, where the processing node sequence includes a number of processing nodes; S102, dividing the processing node sequence according to a first number of division paths with the smallest division costs corresponding to the several processing nodes and an additional second number of division paths, to obtain a divided subgraph sequence; the first number is a positive integer, the second number is a non-negative integer, the division cost reflects the total hardware efficiency when dividing according to the corresponding division path, and the division path is a path formed by combining the corresponding processing node in the processing node sequence with other nodes before the corresponding processing node under a division rule corresponding to the division cost.
[0160] When dividing each processing node, this embodiment only needs to remember the first number of minimum cost partition paths and additionally randomly remember the second number of partition paths. Since all partition paths do not need to be processed, the time complexity is extremely low. At the same time, the method of additionally randomly remembering the second number of partition paths is used to increase disturbances, thereby increasing the probability of jumping out of the local minimum and ensuring high efficiency of the compiled model. By adjusting the number of partition cost minimum paths and the number of memorized paths, the present application can effectively balance the compilation speed and the efficiency of the compiled model.
[0161] Moreover, this embodiment will combine adjacent and parallel nodes into a new processing node, so that nodes with parallel pipeline relationships can be merged, thereby reducing the number of processing nodes to be divided subsequently and improving the efficiency of model subgraph division; and, the total cost of the current division path of this embodiment is equal to the sum of the current node block cost and the remaining node block costs in this path, which simplifies the calculation of the path division cost and improves the efficiency of the calculation of the division path cost; and, this embodiment provides a specific method for dividing the path, so that accurate division can be performed when dividing; and, this embodiment can eliminate division paths that do not meet hardware limitations, such as division paths that do not reach a preset hardware efficiency value, thereby preventing the overall efficiency from being affected and improving the effect of division; and, after obtaining the subgraph sequence after division, this embodiment will compile the target instruction sequence. Since the time complexity of dividing the target model subgraph is extremely low, the efficiency of subsequent running of the target instruction sequence can be improved.
[0162] An algorithm model subgraph partitioning device provided in an embodiment of the present invention is introduced below. The algorithm model subgraph partitioning device described below and the algorithm model subgraph partitioning method described above can refer to each other.
[0163] Please refer to Figure 6 , Figure 6 A schematic diagram of a structure of an algorithm model subgraph partitioning device provided by an embodiment of the present invention may include:
[0164] The AI algorithm model conversion module 100 is used to convert the AI algorithm model into a processing node sequence, wherein the processing node sequence includes a plurality of processing nodes;
[0165] A target model partition subgraph determination module 200, configured to partition the processing node sequence according to a first number of partition paths with the smallest partition costs corresponding to a plurality of the processing nodes and an additional second number of partition paths, to obtain a partitioned subgraph sequence;
[0166] The first number is a positive integer, the second number is a non-negative integer, the partitioning cost reflects the total hardware efficiency when partitioning is performed according to the corresponding partitioning path, and the partitioning path is a path formed by combining the corresponding processing node in the processing node sequence and other nodes before the corresponding processing node under the partitioning rule corresponding to the partitioning cost.
[0167] Further, based on the above embodiment, the above target model division subgraph determination module 200 may include:
[0168] A first processing node selection unit, configured to sequentially select a first processing node from the plurality of processing nodes;
[0169] a partition path determination unit, configured to obtain a first number of partition paths and an additional second number of partition paths with the minimum partition cost corresponding to a second processing node each time the first processing node is selected, wherein the second processing node is a processing node preceding the first processing node in the processing node sequence;
[0170] A division path determination unit corresponding to the first processing node, configured to generate a plurality of division paths corresponding to the first processing node based on a first number of division paths with the smallest division costs corresponding to the second processing node and an additional second number of division paths;
[0171] a quantity determination unit, configured to select a first number of division paths with the smallest division cost corresponding to the first processing node from the multiple division paths corresponding to the first processing node, and additionally select a second number of division paths corresponding to the first processing node from the remaining division paths except the selected division path, and return to continue selecting the first processing node until the first number of division paths with the smallest division cost corresponding to the last first processing node and the additional second number of division paths are selected;
[0172] The target model partition subgraph determination unit is used to select a target partition path from a first number of partition paths with the smallest partition cost corresponding to the last first processing node and an additional second number of partition paths, and to partition the processing node sequence according to the target partition path to obtain a divided subgraph sequence.
[0173] Further, based on the above embodiment, the multiple division paths corresponding to the above-mentioned first processing node include a first path and a second path; the first path is a path including any division path corresponding to the second processing node and a node block, and the node block includes the first processing node and the second processing node; the second path is a path including any division path corresponding to the second processing node and a node block composed of the first processing node alone; the division cost is equal to A+B, A is the cost of the node block, and B is the sum of the costs of the remaining node blocks except the node block in the division path corresponding to the division cost.
[0174] Further, based on the above embodiment, the quantity determination unit may include:
[0175] A screening subunit, used to screen out the partitioning paths that do not meet the hardware restriction condition from the multiple partitioning paths corresponding to the first processing node;
[0176] The first quantity determining subunit is used to select a first number of division paths with the smallest division costs from the eliminated division paths as the first number of division paths with the smallest division costs corresponding to the first processing node.
[0177] Further, based on the above embodiment, the quantity determination unit may include:
[0178] The second quantity determining subunit is used to randomly select a second number of division paths from the remaining division paths as additional second number of division paths corresponding to the first processing node.
[0179] Further, based on any of the above embodiments, the algorithm model subgraph partitioning device may further include:
[0180] A compiling module, used for compiling a target instruction sequence corresponding to the divided subgraph sequence;
[0181] The running module is used to run the target instruction sequence on a processor.
[0182] Further, based on any of the above embodiments, the AI algorithm model conversion module 100 may include:
[0183] An intermediate representation graph determination unit, used to convert the AI algorithm model into an intermediate representation graph of a compiler;
[0184] A node graph determination unit, used for optimizing the intermediate representation graph to obtain an operator node graph;
[0185] A combined operator node determination unit, used for combining adjacent operator nodes in the operator node graph that can flow in parallel into a combined operator node;
[0186] A topology map determining unit, configured to generate the processing node topology map according to the operator nodes and the combined operator nodes; the processing nodes are operator nodes or combined operator nodes;
[0187] The processing node sequence determining unit is used to perform topological sorting according to the processing node topology graph to obtain the processing node sequence.
[0188] An algorithm model subgraph partitioning device provided in this embodiment may include: an AI algorithm model conversion module 100, used to convert the AI algorithm model into a processing node sequence, wherein the processing node sequence includes a plurality of processing nodes; a target model partition subgraph determination module 200, used to partition the processing node sequence according to a first number of partition paths with the smallest partition costs corresponding to the plurality of processing nodes and an additional second number of partition paths, to obtain a divided subgraph sequence; the first number is a positive integer, the second number is a non-negative integer, the partition cost reflects the total hardware efficiency when partitioning according to the corresponding partition path, and the partition path is a path formed by combining the corresponding processing node in the processing node sequence with other nodes before the corresponding processing node under a partition rule corresponding to the partition cost.
[0189] When dividing each processing node, this embodiment only needs to remember the first number of minimum cost partition paths and additionally randomly remember the second number of partition paths. Since all partition paths do not need to be processed, the time complexity is extremely low. At the same time, the method of additionally randomly remembering the second number of partition paths is used to increase disturbances, thereby increasing the probability of jumping out of the local minimum and ensuring high efficiency of the compiled model. By adjusting the number of partition cost minimum paths and the number of memorized paths, the present application can effectively balance the compilation speed and the efficiency of the compiled model.
[0190] Moreover, this embodiment will combine adjacent and parallel nodes into a new processing node, so that nodes with parallel pipeline relationships can be merged, thereby reducing the number of processing nodes to be divided subsequently and improving the efficiency of model subgraph division; and, the total cost of the current division path of this embodiment is equal to the sum of the current node block cost and the remaining node block costs in this path, which simplifies the calculation of the path division cost and improves the efficiency of the calculation of the division path cost; and, this embodiment provides a specific method for dividing the path, so that accurate division can be performed when dividing; and, this embodiment can eliminate division paths that do not meet hardware limitations, such as division paths that do not reach a preset hardware efficiency value, thereby preventing the overall efficiency from being affected and improving the effect of division; and, after obtaining the subgraph sequence after division, this embodiment will compile the target instruction sequence. Since the time complexity of dividing the target model subgraph is extremely low, the efficiency of subsequent running of the target instruction sequence can be improved.
[0191] An electronic device provided by an embodiment of the present invention is introduced below. The electronic device described below and the algorithm model subgraph partitioning method described above can refer to each other.
[0192] Please refer to Figure 7 , Figure 7 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention may include:
[0193] A memory 10, used for storing computer programs;
[0194] The processor 20 is used to execute a computer program to implement the steps of the above-mentioned algorithm model subgraph partitioning method.
[0195] The memory 10 , the processor 20 , and the communication interface 30 all communicate with each other via a communication bus 40 .
[0196] In the embodiment of the present invention, the memory 10 is used to store one or more programs, and the program may include a program code, and the program code includes a computer operation instruction. In the embodiment of the present invention, the memory 10 may store a program corresponding to the algorithm model subgraph partitioning method, for example, a program that performs the following functions:
[0197] Converting the AI algorithm model into a processing node sequence, where the processing node sequence includes a number of processing nodes;
[0198] According to a first number of partition paths with the smallest partition costs corresponding to a plurality of processing nodes and an additional second number of partition paths, the processing node sequence is partitioned to obtain a subgraph sequence after partitioning;
[0199] The first number is a positive integer, the second number is a non-negative integer, the partitioning cost reflects the total hardware efficiency when partitioning according to the corresponding partitioning path, and the partitioning path is a path formed by combining the corresponding processing node in the processing node sequence and other nodes before the corresponding processing node under the partitioning rules corresponding to the partitioning cost.
[0200] In a possible implementation, the memory 10 may include a program storage area and a data storage area, wherein the program storage area may store an operating system and an application required for at least one function, etc.; the data storage area may store data created during use.
[0201] In addition, the memory 10 may include a read-only memory and a random access memory, and provide instructions and data to the processor. A portion of the memory may also include an NVRAM. The memory stores an operating system and operating instructions, executable modules or data structures, or a subset thereof, or an extended set thereof, wherein the operating instructions may include various operating instructions for implementing various operations. The operating system may include various system programs for implementing various basic tasks and processing hardware-based tasks.
[0202] The processor 20 may be a central processing unit (CPU), an application specific integrated circuit, a digital signal processor, a field programmable gate array or other programmable logic device, a microprocessor or any conventional processor, etc. The processor 20 may call a program stored in the memory 10 .
[0203] The communication interface 30 may be an interface of a communication module, and is used to connect to other devices or systems.
[0204] Of course, it should be noted that Figure 7 The structure shown does not constitute a limitation on the electronic device in the embodiment of the present invention. In actual applications, the electronic device may include Figure 7 More or fewer components than shown, or combinations of certain components.
[0205] The following is an introduction to the readable storage medium and computer program product provided in the embodiments of the present invention. The readable storage medium and computer program product described below can be referenced to each other with the algorithm model subgraph partitioning method described above.
[0206] The present invention also provides a readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the above-mentioned algorithm model subgraph partitioning method are implemented.
[0207] The present invention also provides a computer program product, which implements the steps of the above-mentioned algorithm model subgraph partitioning method when executed by a processor.
[0208] The readable storage medium may include: a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and other media that can store program codes.
[0209] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0210] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0211] Finally, it should be noted that, in this article, relationships such as first and second, etc. are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprises" or any other variations are intended to cover non-exclusive inclusion, so that a process, method, article or device that includes a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0212] The above is a detailed introduction to the algorithm model subgraph partitioning method, device, equipment and readable storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A subgraph partitioning method for an algorithm model, characterized in that: include: Converting the AI algorithm model into a processing node sequence, wherein the processing node sequence includes a plurality of processing nodes; According to a first number of partition paths and an additional second number of partition paths with the smallest partition costs respectively corresponding to the plurality of processing nodes, the processing node sequence is partitioned to obtain a subgraph sequence after partitioning; The first number is a positive integer, the second number is a non-negative integer, the partitioning cost reflects the total hardware efficiency when partitioning is performed according to the corresponding partitioning path, and the partitioning path is a path formed by combining the corresponding processing node in the processing node sequence and other nodes before the corresponding processing node under the partitioning rule corresponding to the partitioning cost.
2. The algorithm model subgraph partitioning method according to claim 1, characterized in that: The step of dividing the processing node sequence according to the first number of division paths and the additional second number of division paths with the smallest division costs respectively corresponding to the plurality of processing nodes to obtain a divided subgraph sequence comprises: sequentially selecting a first processing node from among the plurality of processing nodes; Whenever the first processing node is selected, a first number of partition paths and an additional second number of partition paths corresponding to a second processing node with the smallest partition cost are obtained, wherein the second processing node is a processing node preceding the first processing node in the processing node sequence; generating a plurality of partition paths corresponding to the first processing node based on a first number of partition paths with the smallest partition costs corresponding to the second processing node and an additional second number of partition paths; Selecting a first number of division paths with the minimum division cost corresponding to the first processing node from the multiple division paths corresponding to the first processing node, and additionally selecting a second number of division paths corresponding to the first processing node from the remaining division paths except the selected division path, and returning to continue selecting the first processing node until the first number of division paths with the minimum division cost corresponding to the last first processing node and the additional second number of division paths are selected; A target partitioning path is selected from a first number of partitioning paths with the smallest partitioning cost corresponding to the last first processing node and an additional second number of partitioning paths, and the processing node sequence is partitioned according to the target partitioning path to obtain a divided subgraph sequence.
3. The algorithm model subgraph partitioning method according to claim 2, characterized in that: The multiple division paths corresponding to the first processing node include a first path and a second path; The first path is a path including any one of the partition paths corresponding to the second processing node and a node block, and the node block includes the first processing node and the second processing node; The second path is a path including any one of the divided paths corresponding to the second processing node and a node block composed solely of the first processing node; The partition cost is equal to A+B, where A is the cost of the node block, and B is the sum of the costs of the remaining node blocks except the node block in the partition path corresponding to the partition cost.
4. The algorithm model subgraph partitioning method according to claim 2, characterized in that: The selecting, from the plurality of partition paths corresponding to the first processing node, a first number of partition paths corresponding to the first processing node and having the smallest partition costs, comprises: Screening out the partitioning paths that do not meet the hardware restriction condition from among the multiple partitioning paths corresponding to the first processing node; A first number of partition paths with minimum partition costs are selected from the screened partition paths as the first number of partition paths with minimum partition costs corresponding to the first processing node.
5. The algorithm model subgraph partitioning method according to claim 2, characterized in that: The additionally selecting a second number of division paths corresponding to the first processing node from the remaining division paths except the selected division path includes: A second number of partition paths are randomly selected from the remaining partition paths as additional second number of partition paths corresponding to the first processing node.
6. The algorithm model subgraph partitioning method according to any one of claims 1 to 5, characterized in that: After obtaining the divided sub-graph sequence, the method further includes: Compile the target instruction sequence corresponding to the divided subgraph sequence; The target instruction sequence is executed on a processor.
7. The algorithm model subgraph partitioning method according to any one of claims 1 to 5, characterized in that: The step of converting the AI algorithm model into a processing node sequence includes: Converting the AI algorithm model into an intermediate representation graph of a compiler; Optimizing the intermediate representation graph to obtain an operator node graph; Combining adjacent operator nodes in the operator node graph that can flow in parallel into a combined operator node; Generate a processing node topology map according to the operator nodes and the combined operator nodes; the processing node is the operator node or the combined operator node; A topological sort is performed according to the processing node topology graph to obtain the processing node sequence.
8. An algorithm model subgraph partitioning device, characterized in that: include: An AI algorithm model conversion module, used to convert the AI algorithm model into a processing node sequence, wherein the processing node sequence includes a plurality of processing nodes; A target model partition subgraph determination module, configured to partition the processing node sequence according to a first number of partition paths with the smallest partition costs respectively corresponding to a number of the processing nodes and an additional second number of partition paths, to obtain a subgraph sequence after partitioning; The first number is a positive integer, the second number is a non-negative integer, the partitioning cost reflects the total hardware efficiency when partitioning is performed according to the corresponding partitioning path, and the partitioning path is a path formed by combining the corresponding processing node in the processing node sequence and other nodes before the corresponding processing node under the partitioning rule corresponding to the partitioning cost.
9. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, used to implement the steps of the algorithm model subgraph partitioning method as described in any one of claims 1 to 7 when executing the computer program.
10. A readable storage medium, characterized in that: The readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the algorithm model subgraph partitioning method according to any one of claims 1 to 7 are implemented.
