Computational graph optimization method and device, storage medium and electronic equipment

By converting the neural network model into a calculation graph and optimizing based on historical record collections, the problem of inefficiency in the deep neural network optimization process is solved, achieving faster processing speed and more efficient optimization effects.

CN118657172APending Publication Date: 2024-09-17WUHAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410760073.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-13
Publication Date
2024-09-17

AI Technical Summary

Technical Problem

When optimizing complex deep neural networks, the existing technology has a low search process efficiency, resulting in a huge amount of calculation that affects the processing speed.

Method used

By converting the neural network model into a calculation graph, traversing the rule set to match and replace the calculation graph to form a candidate set, select the calculation graph with the lowest cost as the next round of matching graphs, and repeat matching based on the historical record set until all matches are completed. to optimize the computational graph.

Benefits of technology

It significantly shortens the time for graph-level optimization, avoids falling into local optima, and improves the processing speed and efficiency of large-scale neural networks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118657172A
    Figure CN118657172A
Patent Text Reader

Abstract

The invention discloses a calculation graph optimization method and device, a storage medium and electronic equipment. The method comprises the following steps: converting a neural network model into a computational graph; traversing a rule set to match the computational graph, and replacing the successfully matched computational graph to obtain a replaced computational graph; determining a candidate set according to the replaced computational graph; if the candidate set is not empty, taking the calculation graph with the lowest cost in the candidate set as a calculation graph to be matched in the next round, and adding the calculation graphs except the calculation graph to be matched in the next round in the candidate set into a historical record set, repeatedly executing the step of obtaining the replaced calculation graph set and the step of determining the candidate set until all the source graphs in the rule set are matched; and performing matching based on the historical record set to obtain an optimized calculation graph. According to the method, the time of graph hierarchy optimization is obviously shortened.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of neural network layer optimization, and in particular to a computational graph optimization method, device, storage medium and electronic device. Background Art

[0002] In recent years, with the development of artificial intelligence, neural networks have achieved remarkable results in fields such as images, text, voice and recommendation systems, and have been widely used in all walks of life.

[0003] As the problems being solved become increasingly complex, the scale of neural networks is increasing accordingly. Correspondingly, the amount of computation required by neural networks is becoming increasingly large, which is bound to affect the processing speed of neural networks.

[0004] Current techniques consider rules that may reduce efficiency and use cost-based backtracking search algorithms, but they lack guarantees on the time and space complexity of the search. These methods may explore the entire search space, especially when optimizing complex deep neural networks, which can lead to a less efficient search process. Summary of the invention

[0005] The embodiments of the present application provide a computational graph optimization method, device, storage medium, and electronic device, which can solve the technical problem of low search process efficiency when optimizing complex deep neural networks.

[0006] The present application provides a method for optimizing a computational graph, including:

[0007] Convert the neural network model into a computational graph;

[0008] Traversing the rule set to match the computation graph, and replacing the successfully matched computation graph to obtain a replaced computation graph;

[0009] Determine a candidate set based on the replaced computational graph;

[0010] If the candidate set is not empty, the computation graph with the lowest cost in the candidate set is used as the computation graph to be matched in the next round, and the computation graphs in the candidate set except the computation graph to be matched in the next round are added to the historical record set, and the step of obtaining the replaced computation graph set and the step of determining the candidate set are repeated until all the source graphs in the rule set are matched;

[0011] Matching is performed based on the historical record set to obtain an optimized calculation graph.

[0012] Furthermore, in the above-mentioned computational graph optimization method, the computational graph includes multiple subgraphs, the rule set includes multiple rules, and each of the rules includes a source graph and a target graph.

[0013] Furthermore, in the above-mentioned calculation graph optimization method, the traversal rule set matches the calculation graph, and the successfully matched calculation graph is replaced to obtain a replaced calculation graph, including:

[0014] Traversing the rule set, matching the source graphs in the rule set with the subgraphs in the computation graph respectively;

[0015] When a subgraph matching the source graph is found, the subgraph is replaced by the target graph in the rule to which the source graph belongs, to obtain a replaced computational graph.

[0016] Furthermore, in the above-mentioned computation graph optimization method, the step of determining the candidate set according to the replaced computation graph includes:

[0017] Calculate the cost of the replaced computation graph;

[0018] If the cost of the replaced computation graph is lower than the lowest cost value of the computation graph before replacement, the replaced computation graph is added to the candidate set.

[0019] Furthermore, in the above-mentioned calculation graph optimization method, the cost of the calculation graph after the calculation is replaced includes:

[0020] Calculate the cost of the replaced computational graph through the cost function;

[0021] The cost function includes:

[0022]

[0023] Where |V| represents the number of operators in the computation graph G, and t_i represents the execution time of the i-th operator.

[0024] Furthermore, in the above-mentioned calculation graph optimization method, the matching based on the historical record set to obtain an optimized calculation graph includes:

[0025] Find the computation graph with the lowest cost in the set of history records;

[0026] The computation graph with the lowest cost is used as the computation graph to be matched in the next round, and the steps of obtaining the replaced computation graph set, determining the candidate set, and adding the computation graphs in the candidate set except the computation graph to be matched in the next round to the historical record set are repeatedly performed until all the computation graphs in the historical record set are replaced;

[0027] The replaced computational graph is the optimized computational graph.

[0028] The present application also provides a computational graph optimization device, including:

[0029] The conversion module is used to convert the neural network model into a computational graph;

[0030] A matching module, used for traversing the rule set to match the calculation graph, and replacing the successfully matched calculation graph to obtain a replaced calculation graph;

[0031] and, for determining a candidate set according to the replaced computational graph;

[0032] And, if the candidate set is not empty, the computation graph with the lowest cost in the candidate set is used as the computation graph to be matched in the next round, and the computation graphs in the candidate set except the computation graph to be matched in the next round are added to the historical record set, and the step of obtaining the replaced computation graph set and the step of determining the candidate set are repeatedly performed until all the source graphs in the rule set are matched;

[0033] And, matching is performed based on the historical record set to obtain an optimized calculation graph.

[0034] An embodiment of the present application also provides a computer-readable storage medium, in which a plurality of instructions are stored, and the instructions are suitable for being loaded by a processor to execute any of the above-mentioned computational graph optimization methods.

[0035] An embodiment of the present application also provides an electronic device, including a processor and a memory, wherein the processor is electrically connected to the memory, the memory is used to store instructions and data, and the processor is used to perform the steps in any of the above-mentioned computational graph optimization methods.

[0036] The computational graph optimization method, device, storage medium and electronic device provided by the present application combine the greedy strategy with the historical record-based search. Not only does it construct a candidate set and select the computational graph from the candidate set for re-matching, but it also selects the computational graph from the historical search set for further matching based on the historical search set. This matching method effectively improves the problem that large-scale neural networks need to spend too much time on graph-level optimization. On the premise of ensuring the correctness and speed of reasoning, it significantly shortens the time for graph-level optimization. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The technical solution and other beneficial effects of the present application will be made apparent by describing in detail the specific implementation methods of the present application in conjunction with the accompanying drawings.

[0038] Figure 1 A flowchart of a computational graph optimization method provided in an embodiment of the present application.

[0039] Figure 2 Another flowchart of the computational graph optimization method provided in an embodiment of the present application.

[0040] Figure 3 A schematic diagram comparing the initial calculation graph and the optimized calculation graph provided in the embodiment of the present application.

[0041] Figure 4 A schematic diagram of the structure of a computational graph optimization device provided in an embodiment of the present application.

[0042] Figure 5 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0043] Figure 6 Another schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0044] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.

[0045] Currently, the processing speed of neural networks is generally improved by using more efficient search rules, but this method is prone to falling into local optimality.

[0046] Current techniques consider rules that may reduce efficiency and use cost-based backtracking search algorithms, but they lack guarantees on the time and space complexity of the search. In the worst case, these methods may explore the entire search space, especially when optimizing complex deep neural networks, which can lead to a less efficient search process.

[0047] To solve the above problems, the embodiments of the present application provide a method, device, storage medium and electronic device for optimizing a computational graph. The computational graph optimization device provided in the embodiments of the present application can be integrated in an electronic device, which can be a terminal, a server or other device, wherein the terminal can include a tablet computer, a laptop computer, a personal computer (PC), a microprocessor box, or other devices.

[0048] See also Figure 1 and Figure 2 , Figure 1 A flowchart of a computational graph optimization method provided in an embodiment of the present application is provided. Figure 2 Another flowchart of a computation graph optimization method provided in an embodiment of the present application is provided, which is applied in an electronic device. The computation graph optimization method includes the following steps:

[0049] In the greedy search phase:

[0050] S1, convert the neural network model into a computational graph.

[0051] The operations and data flows in the neural network model are represented in the form of a graph. In the computational graph, nodes represent mathematical operations, and edges represent the dependencies between the computational results, forming a directed acyclic graph. The computational graph can complete the entire computational process through a series of computations and data transfers between nodes.

[0052] S2, traverse the rule set matching calculation graph, replace the successfully matched calculation graph to obtain the replaced calculation graph.

[0053] Specifically, the computation graph includes multiple subgraphs, the rule set includes multiple rules (i.e., rules for replacing subgraphs), and each rule includes a source graph and a target graph. The source graph is used to match the computation graph, and the target graph is used to replace the subgraph of the computation graph.

[0054] In one embodiment, step S2 comprises the following steps:

[0055] S21, traverse the rule set and match the source graph in the rule set with the subgraph in the computation graph respectively;

[0056] S22, when a subgraph matching the source graph is found, the subgraph is replaced by the target graph in the rule to which the source graph belongs, to obtain a replaced computational graph.

[0057] The data layout is considered at each rule match. Specifically, at each match, possible layouts are enumerated for tensors in the target graph based on the data layout of tensors in the source graph and the layouts supported by operators. Applying a rule to a matching computational graph may produce multiple graphs that have the same graph structure but different data layouts.

[0058] S3, determine the candidate set according to the replaced computational graph.

[0059] Specifically, step S3 includes:

[0060] S31, calculate the cost of the replaced computational graph.

[0061] Specifically, the cost of the replaced computational graph is calculated by a cost function, and the cost function includes:

[0062]

[0063] Where |V| represents the number of operators in the computation graph G, and t_i represents the execution time of the i-th operator.

[0064] S32: If the cost of the replaced computation graph is lower than the lowest cost value of the computation graph before the replacement, the replaced computation graph is added to the candidate set.

[0065] Specifically, each time a computation graph is replaced, the replaced computation graph is compared with the lowest cost value of the previous computation graph. If the cost of the replaced computation graph is lower than the lowest cost value of the computation graph before replacement, the replaced computation graph is added to the candidate set.

[0066] Specifically, after step S32, determine whether the candidate set is empty. If the candidate set is not empty, execute step S4. If the candidate set is empty, it means that the calculation graph has not been matched successfully. If the rule set has not been matched at this time, re-execute steps S2-S3 and continue to match the remaining rules in the rule set. If the rule set has been matched, execute step S5.

[0067] S4, if the candidate set is not empty, the computational graph with the lowest cost in the candidate set is used as the computational graph to be matched in the next round, and the computational graphs in the candidate set except the computational graph to be matched in the next round are added to the historical record set, and the steps of obtaining the replaced computational graph set and determining the candidate set are repeated until all the source graphs in the rule set are matched.

[0068] Specifically, the computation graph with the lowest cost in the candidate set is used as the computation graph to be matched in the next round, and the computation graphs in the candidate set except the computation graph to be matched in the next round are added to the historical record set, and the computation graphs are sorted according to the cost, and then steps S2-S3 are repeated.

[0069] In the history-based search phase:

[0070] S5, matching is performed based on the historical record set to obtain an optimized computational graph.

[0071] Specifically, step S5 includes:

[0072] S51, find the computational graph with the lowest cost in the historical record set;

[0073] S52, taking the computational graph with the lowest cost as the computational graph to be matched in the next round, repeating the steps of obtaining the replaced computational graph set, determining the candidate set, and adding the computational graphs in the candidate set except the computational graph to be matched in the next round to the historical record set, until all the computational graphs in the historical record set are replaced.

[0074] Specifically, the computational graph with the lowest cost is found from the historical record set to start the next round of search and matching. Steps S2-S4 are repeated until both the candidate set and the historical record set are empty. The repetition is stopped. At this time, all computational graphs are replaced, and the optimized computational graph can be obtained. Figure 3 , Figure 3 A schematic diagram comparing the initial calculation graph and the optimized calculation graph provided in the embodiment of the present application.

[0075] In the greedy search stage, the embodiment of the present application first generates a calculation graph of the neural network model, then traverses the rule set matching calculation graph and considers the data layout, obtains the replaced calculation graph each time the rule is matched, and then calculates the cost of the replaced calculation graph, and adds the calculation graph with a cost lower than the current minimum cost to the candidate set. If the candidate set is not empty, find the calculation graph with the lowest cost from the candidate set as the calculation graph for the next match, and add the remaining ones to the historical record set; otherwise, determine whether the rules in the rule set have been completely matched, and if not, continue to match the remaining rules. In the historical record search stage, the calculation graph with the lowest cost is found from the historical record set to start the next round of search until both the candidate set and the historical record set are empty, and finally an optimized calculation graph is obtained. The present application organically combines the greedy strategy with the historical record search, which effectively improves the problem that large-scale neural networks need to spend too much time on layer-level optimization. On the premise of ensuring the correctness and speed of reasoning, the layer-level optimization time is significantly shortened, and it can effectively avoid falling into the local optimum.

[0076] According to the method described in the above embodiment, this embodiment will be further described from the perspective of a computational graph optimization device, which can be implemented as an independent entity or integrated in an electronic device, which can be a terminal, server or other device, wherein the terminal can include a tablet computer, a laptop computer, a personal computer (PC), a micro processing box, or other devices.

[0077] See also Figure 4 , Figure 4 The computation graph optimization device provided in the embodiment of the present application is specifically described, and is applied to an electronic device. The computation graph optimization device may include:

[0078] The conversion module is used to convert the neural network model into a computational graph;

[0079] A matching module is used to traverse the rule set matching calculation graph and replace the successfully matched calculation graph to obtain a replaced calculation graph;

[0080] and, for determining a candidate set according to the replaced computational graph;

[0081] And, if the candidate set is not empty, the computation graph with the lowest cost in the candidate set is used as the computation graph to be matched in the next round, and the computation graphs in the candidate set except the computation graph to be matched in the next round are added to the historical record set, and the steps of obtaining the replaced computation graph set and determining the candidate set are repeated until all source graphs in the rule set are matched;

[0082] And, matching is performed based on the historical record set to obtain an optimized computational graph.

[0083] During specific implementation, the above modules and / or units can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above modules and / or units can refer to the previous method embodiments. The specific beneficial effects that can be achieved can also refer to the beneficial effects in the previous method embodiments, which will not be repeated here.

[0084] In addition, an embodiment of the present application also provides an electronic device, which may be a computer, a tablet computer, or other device. Figure 5 As shown, the electronic device 400 includes a processor 401 and a memory 402. The processor 401 is electrically connected to the memory 402.

[0085] The processor 401 is the control center of the electronic device 400. It uses various interfaces and lines to connect various parts of the entire electronic device. It executes various functions of the electronic device and processes data by running or loading applications stored in the memory 402 and calling data stored in the memory 402, thereby monitoring the electronic device as a whole.

[0086] In this embodiment, the processor 401 in the electronic device 400 loads instructions corresponding to the processes of one or more application programs into the memory 402 according to the following steps, and the processor 401 runs the application programs stored in the memory 402 to implement various functions:

[0087] Convert the neural network model into a computational graph;

[0088] Traversing the rule set to match the computation graph, and replacing the successfully matched computation graph to obtain a replaced computation graph;

[0089] Determine a candidate set based on the replaced computational graph;

[0090] If the candidate set is not empty, the computation graph with the lowest cost in the candidate set is used as the computation graph to be matched in the next round, and the computation graphs in the candidate set except the computation graph to be matched in the next round are added to the historical record set, and the step of obtaining the replaced computation graph set and the step of determining the candidate set are repeated until all the source graphs in the rule set are matched;

[0091] Matching is performed based on the historical record set to obtain an optimized calculation graph.

[0092] The electronic device can implement the steps in any embodiment of the computational graph optimization method provided in the embodiments of the present application. Therefore, it can achieve the beneficial effects that can be achieved by any computational graph optimization method provided in the embodiments of the present invention. Please refer to the previous embodiments for details and will not be repeated here.

[0093] Figure 6 The specific structural block diagram of the electronic device provided in the embodiment of the present invention is shown, and the electronic device can be used to implement the calculation graph optimization method provided in the above embodiment. The electronic device 500 can be a terminal, a server and other devices, wherein the terminal can include a tablet computer, a laptop computer, a personal computer (PC, Personal Computer), a micro processing box, or other devices.

[0094] The RF circuit 510 is used to receive and send electromagnetic waves, realize the mutual conversion between electromagnetic waves and electrical signals, and thus communicate with a communication network or other devices. The RF circuit 510 may include various existing circuit elements for performing these functions, such as antennas, radio frequency transceivers, digital signal processors, encryption / decryption chips, user identity module (SIM) cards, memories, etc. The RF circuit 510 can communicate with various networks such as the Internet, corporate intranets, wireless networks, or communicate with other devices through wireless networks. The above-mentioned wireless networks may include cellular telephone networks, wireless local area networks, or metropolitan area networks. The above-mentioned wireless networks can use various communication standards, protocols and technologies, including but not limited to Global System for Mobile Communication (GSM), Enhanced Data GSM Environment (EDGE), Wideband Code Division Multiple Access (WCDMA), Code Division Multiple Access (CDMA), Time Division Multiple Access (TDMA), Wireless Fidelity (Wi-Fi) (such as Institute of Electrical and Electronics Engineers standards IEEE 802.11a, IEEE 802.11b, IEEE802.11g and / or IEEE802.11n), Voice over Internet Protocol (VoIP), Worldwide Interoperability for Microwave Access (Wi-Max), other protocols for email, instant messaging and short messages, and any other suitable communication protocols, even those that have not yet been developed.

[0095] The memory 520 can be used to store software programs and modules, such as the corresponding program instructions / modules in the above embodiments. The processor 580 executes various functional applications and data processing by running the software programs and modules stored in the memory 520, that is, realizing the functions of taking pictures with the front camera, processing the captured images, and switching the display color of the display content on the display screen. The memory 520 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 520 may further include a memory remotely arranged relative to the processor 580, and these remote memories may be connected to the electronic device 500 via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof.

[0096] The input unit 530 may be used to receive input digital or character information, and generate a keyboard and a mouse related to user settings and function control.

[0097] The display unit 540 may be used to display information input by the user or information provided to the user and various graphical user interfaces, which may be composed of graphics, text, icons, videos, and any combination thereof. The display unit 540 may include a display panel 541, which may be configured in the form of an LCD (Liquid Crystal Display), an OLED (Organic Light-Emitting Diode), or the like.

[0098] The audio circuit 560, the speaker 561, and the microphone 562 can provide an audio interface between the user and the electronic device 500. The audio circuit 560 can transmit the electrical signal converted from the received audio data to the speaker 561, which is converted into a sound signal for output; on the other hand, the microphone 562 converts the collected sound signal into an electrical signal, which is received by the audio circuit 560 and converted into audio data, and then the audio data is output to the processor 580 for processing, and then sent to another terminal through the RF circuit 510, or the audio data is output to the memory 520 for further processing. The audio circuit 560 may also include an earplug jack to provide communication between an external headset and the electronic device 500.

[0099] The electronic device 500 can help the user receive requests, send information, etc. through the transmission module 570 (such as a Wi-Fi module), which provides the user with wireless broadband Internet access. Although the transmission module 570 is shown in the figure, it is understandable that it is not a necessary component of the electronic device 500 and can be omitted as needed without changing the essence of the invention.

[0100] The processor 580 is the control center of the electronic device 500. It uses various interfaces and lines to connect various parts of the entire mobile phone. By running or executing software programs and / or modules stored in the memory 520, and calling data stored in the memory 520, it executes various functions of the electronic device 500 and processes data, thereby monitoring the electronic device as a whole. Optionally, the processor 580 may include one or more processing cores; in some embodiments, the processor 580 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, etc., and the modem processor mainly processes wireless communications. It can be understood that the above-mentioned modem processor may not be integrated into the processor 580.

[0101] The electronic device 500 also includes a power supply 590 (such as a battery) for supplying power to various components. In some embodiments, the power supply can be logically connected to the processor 580 through a power management system, so that the power management system can manage charging, discharging, and power consumption management. The power supply 590 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.

[0102] Although not shown, the electronic device 500 also includes a camera (such as a front camera, a rear camera), a Bluetooth module, etc., which will not be described in detail here. Specifically in this embodiment, the display unit of the electronic device is a touch screen display, and the mobile terminal also includes a memory, and one or more programs, wherein one or more programs are stored in the memory, and are configured to be executed by one or more processors. One or more programs include instructions for performing the following operations:

[0103] Convert the neural network model into a computational graph;

[0104] Traversing the rule set to match the computation graph, and replacing the successfully matched computation graph to obtain a replaced computation graph;

[0105] Determine a candidate set based on the replaced computational graph;

[0106] If the candidate set is not empty, the computation graph with the lowest cost in the candidate set is used as the computation graph to be matched in the next round, and the computation graphs in the candidate set except the computation graph to be matched in the next round are added to the historical record set, and the step of obtaining the replaced computation graph set and the step of determining the candidate set are repeated until all the source graphs in the rule set are matched;

[0107] Matching is performed based on the historical record set to obtain an optimized calculation graph.

[0108] In specific implementation, the above modules can be implemented as independent entities, or can be arbitrarily combined and implemented as the same or several entities. The specific implementation of the above modules can be found in the previous method embodiments, which will not be repeated here.

[0109] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments can be completed by instructions, or by controlling related hardware through instructions, and the instructions can be stored in a computer-readable storage medium and loaded and executed by a processor. To this end, an embodiment of the present invention provides a storage medium in which a plurality of instructions are stored, and the instructions can be loaded by a processor to execute the steps of any embodiment of the computational graph optimization method provided in the embodiment of the present invention.

[0110] The computer-readable storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.

[0111] Since the instructions stored in the storage medium can execute the steps in any embodiment of the computational graph optimization method provided in the embodiments of the present invention, the beneficial effects that can be achieved by any computational graph optimization method provided in the embodiments of the present invention can be achieved. Please refer to the previous embodiments for details and will not be repeated here.

[0112] The above is a detailed introduction to a computational graph optimization method, device, storage medium and electronic device provided in the embodiments of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the ideas of the present application, there will be changes in the specific implementation methods and application scopes. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A computational graph optimization method, characterized in that: The method comprises: Convert the neural network model into a computational graph; Traversing the rule set to match the computation graph, and replacing the successfully matched computation graph to obtain a replaced computation graph; Determine a candidate set based on the replaced computational graph; If the candidate set is not empty, the computation graph with the lowest cost in the candidate set is used as the computation graph to be matched in the next round, and the computation graphs in the candidate set except the computation graph to be matched in the next round are added to the historical record set, and the step of obtaining the replaced computation graph set and the step of determining the candidate set are repeated until all the source graphs in the rule set are matched; Matching is performed based on the historical record set to obtain an optimized calculation graph.

2. The computational graph optimization method according to claim 1, characterized in that: The computation graph includes multiple subgraphs, the rule set includes multiple rules, and each rule includes a source graph and a target graph.

3. The computational graph optimization method according to claim 2, characterized in that: The traversal rule set matches the computation graph, and the successfully matched computation graph is replaced to obtain a replaced computation graph, including: Traversing the rule set, matching the source graphs in the rule set with the subgraphs in the computation graph respectively; When a subgraph matching the source graph is found, the subgraph is replaced by the target graph in the rule to which the source graph belongs, to obtain a replaced computational graph.

4. The computational graph optimization method according to claim 1, characterized in that: The determining of the candidate set according to the replaced computation graph includes: Calculate the cost of the replaced computation graph; If the cost of the replaced computation graph is lower than the lowest cost value of the computation graph before replacement, the replaced computation graph is added to the candidate set.

5. The computational graph optimization method according to claim 4, characterized in that: The cost of the computational graph after the computational replacement is calculated, including: Calculate the cost of the replaced computational graph through the cost function; The cost function includes: Where |V| represents the number of operators in the computation graph G, and t_i represents the execution time of the i-th operator.

6. The computational graph optimization method according to claim 1, characterized in that: The matching based on the historical record set to obtain an optimized calculation graph includes: Find the computation graph with the lowest cost in the set of history records; The computation graph with the lowest cost is used as the computation graph to be matched in the next round, and the steps of obtaining the replaced computation graph set, determining the candidate set, and adding the computation graphs in the candidate set except the computation graph to be matched in the next round to the historical record set are repeatedly performed until all the computation graphs in the historical record set are replaced; The replaced computational graph is the optimized computational graph.

7. A computational graph optimization device, characterized in that: include: The conversion module is used to convert the neural network model into a computational graph; A matching module, used for traversing the rule set to match the calculation graph, and replacing the successfully matched calculation graph to obtain a replaced calculation graph; and, for determining a candidate set according to the replaced computational graph; And, if the candidate set is not empty, the computation graph with the lowest cost in the candidate set is used as the computation graph to be matched in the next round, and the computation graphs in the candidate set except the computation graph to be matched in the next round are added to the historical record set, and the step of obtaining the replaced computation graph set and the step of determining the candidate set are repeatedly performed until all the source graphs in the rule set are matched; And, matching is performed based on the historical record set to obtain an optimized calculation graph.

8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a plurality of instructions, which are suitable for being loaded by a processor to execute the computational graph optimization method according to any one of claims 1 to 6.

9. An electronic device, characterized in that: It includes a processor and a memory, the processor is electrically connected to the memory, the memory is used to store instructions and data, and the processor is used to execute the steps in the computational graph optimization method described in any one of claims 1 to 6.