Neural network computational graph optimization method

By using genetic algorithms in the optimization of neural network computing graphs, the problems of local optimal solutions and high computing overhead in the prior art are solved, and a more efficient optimization process and faster optimization time are achieved.

CN119494382APending Publication Date: 2025-02-21BEIJING TSINGMICRO INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411289648.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-14
Publication Date
2025-02-21

AI Technical Summary

Technical Problem

When optimizing neural network computing graphs, the prior art is prone to fall into local optimal solutions, and the optimization of large-scale computing graphs requires high computing overhead and time.

Method used

Genetic algorithms are used to optimize the encoding combination of computational graphs. By searching the entire solution space and continuously iterating the optimization, local optimal solutions are avoided, and parallel computing is used to reduce optimization time.

Benefits of technology

The time required for the optimization process is significantly reduced, the trap of local optimal solutions is avoided, and optimization efficiency is improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119494382A_ABST
    Figure CN119494382A_ABST
Patent Text Reader

Abstract

The invention belongs to the technical field of neural network compilation, and particularly discloses an optimization method of a neural network computational graph. According to the method, the genetic algorithm is provided for optimizing the calculation graph coding combination aiming at the defects of searching the optimal calculation graph coding combination by adopting a loop traversal method in the prior art, and the method provided by the invention not only can avoid falling into a local optimal solution, but also can improve the calculation graph coding combination optimization efficiency when the optimization of a large-scale neural network calculation graph is executed. And the time required by the optimization process is obviously reduced. Besides, according to the method provided by the invention, the search direction and intensity can be adjusted according to the search states of different stages, so that the optimization efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of neural network compilation, and in particular relates to a method for optimizing a neural network calculation graph. Background Art

[0002] For different computing architectures, the reasoning process of executing neural networks varies greatly. Therefore, the neural network needs to be compiled into a computational graph to convert the neural network model into instructions on the corresponding computing architecture, thereby realizing the reasoning of the neural network model on the computing architecture. Since the reasoning speed of the neural network model is closely related to the data access bandwidth and the order of instructions, by optimizing the computational graph, the efficiency of model training and reasoning can be significantly improved and the cost can be reduced. Therefore, optimizing the computational graph of the neural network is crucial to improving the performance of the deep learning system.

[0003] However, the current method for optimizing the computational graph of a neural network is to find the optimal computational graph encoding combination after encoding through a loop. Since the computational graph encoding combination needs to be traversed multiple times, not only does the optimization process take a lot of time, but the optimization of large-scale computational graphs also requires a high computational overhead. In addition, the loop traversal is usually based on local data, which means that the loop traversal optimization may only be able to find a local optimal solution, but not a global optimal solution. Summary of the invention

[0004] In order to solve the problems mentioned in the above background technology, the present invention proposes a method for optimizing a neural network calculation graph.

[0005] A method for optimizing a neural network computation graph comprises the following steps:

[0006] Step S1, obtain the computation graph of the neural network to be compiled, and mark the neural network layer in the computation graph that can perform the permutation operation according to the marking rule.

[0007] Specifically, the marking rules are:

[0008] If it is an intra-dimensional permutation, the data coordinates input when calculating a single output by the calculation functions of the layer before and after the permutation operation should be equal in the permuted dimension.

[0009] If it is a permutation between dimensions, the data coordinates input when the calculation functions of the layer before the permutation operation and the layer after the permutation operation calculate a single output should be equal in all permuted dimensions.

[0010] Step S2: Encode the marked computation graph according to the encoding rules to obtain a computation graph encoding combination.

[0011] Specifically, the encoding rule is: encode the data conversion layer in the calculation graph as 0, and encode the data calculation layer in the calculation graph as 1.

[0012] Step S3, optimizing the obtained computational graph coding combination, and obtaining the optimized computational graph coding combination.

[0013] Specifically, the genetic algorithm is used to optimize the computational graph encoding combination, and the optimization process is as follows:

[0014] First, a certain number of computational graph encoding combinations are randomly generated as the initial population.

[0015] Then, the performance of each encoding combination in the population is evaluated using the objective function.

[0016] Next, a portion of the coding combinations are selected as parents according to their performance.

[0017] Finally, the selected parent encoding combinations are crossed to generate new child encoding combinations as the optimized computational graph encoding combinations.

[0018] In view of the shortcomings of the existing method of using loop traversal to find the optimal calculation graph coding combination, the present invention proposes to use genetic algorithms to optimize the calculation graph coding combination. Since genetic algorithms can search the entire solution space and continuously iterate and optimize, they can avoid falling into local optimal solutions. In addition, genetic algorithms are easy to implement parallel computing, which enables genetic algorithms to significantly reduce the time required for the optimization process when performing large-scale neural network calculation graph optimization. In addition, genetic algorithms can adaptively adjust the search strategy based on the information obtained during the search process, so that the genetic algorithm can adjust the search direction and intensity according to the search status at different stages, thereby improving the efficiency of optimization.

[0019] After obtaining the optimized computational graph encoding combination, it is necessary to determine whether the optimized computational graph encoding combination meets the optimization conditions. If the optimization conditions are met, the computational graph encoding combination is output; otherwise, the computational graph encoding combination needs to be optimized again.

[0020] Among them, the first optimization condition is: whether the optimized calculation graph encoding combination satisfies the permutation rule, and the permutation rule includes the intra-dimensional permutation rule and the inter-dimensional permutation rule. Specifically,

[0021] The calculation formula for the intra-dimensional permutation rule is:

[0022] C0→C1→f→C2…→C n =C0→C1→C2→f…→C n

[0023] Among them, C irepresents the network layer in the neural network, f represents the permutation operation within the dimension, and → represents the data flow direction in the neural network;

[0024] The specific calculation formula for inter-dimensional substitution rules is:

[0025] C0→C1→g→C2…→C n =C0→C1→C2→g…→C n

[0026] Among them, C i Represents the network layer in the neural network, g represents the permutation operation between dimensions, and → represents the data flow in the neural network.

[0027] The second optimization condition is:

[0028] N after ≥N before

[0029] Wherein, is the number of data conversion layers in the optimized computational graph encoding combination, and is the number of data conversion layers in the computational graph encoding combination before optimization.

[0030] Step S4: decode the optimized computation graph encoding combination according to the decoding rules to obtain the optimized computation graph.

[0031] Specifically, the decoding rule is: decode 0 in the computation graph encoding combination into the data conversion layer of the computation graph; decode 1 in the computation graph encoding combination into the data computation layer of the computation graph.

[0032] Step S5, simulating and verifying the optimized calculation graph;

[0033] Step S6, repeating steps S3 to S5 until the optimization termination rule is met.

[0034] The present invention proposes a method for optimizing a neural network computation graph, which has the following advantages compared with the existing technology:

[0035] Beneficial effects:

[0036] The method proposed in the present invention can not only avoid falling into a local optimal solution, but also significantly reduce the time required for the optimization process when performing optimization of large-scale neural network calculation graphs.

[0037] The method proposed in the present invention can adjust the search direction and intensity according to the search status at different stages, thereby improving the optimization efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] Figure 1 It is a schematic diagram of the process of the present invention;

[0039] Figure 2It is a schematic diagram of encoding a computation graph in an embodiment of the present invention. DETAILED DESCRIPTION

[0040] In order to make the purpose and features of the present invention more obvious and easy to understand, the present technical solution is described in detail below through embodiments and in conjunction with the accompanying drawings.

[0041] like Figure 1 As shown in FIG. 1 , a method for optimizing a neural network computation graph is implemented as follows:

[0042] Step S1, obtain the computation graph of the neural network to be compiled, and mark the neural network layer in the computation graph that can perform the permutation operation according to the marking rule.

[0043] Specifically, the marking rules are:

[0044] If it is an intra-dimensional permutation, the data coordinates input when calculating a single output by the calculation functions of the layer before and after the permutation operation should be equal in the permuted dimension.

[0045] If it is a permutation between dimensions, the data coordinates input when the calculation functions of the layer before the permutation operation and the layer after the permutation operation calculate a single output should be equal in all permuted dimensions.

[0046] Step S2: Encode the marked computation graph according to the encoding rules to obtain a computation graph encoding combination.

[0047] like Figure 2 As shown, specifically, the encoding rule is: encode the data conversion layer in the calculation graph as 0, and encode the data calculation layer in the calculation graph as 1.

[0048] Step S3, optimizing the obtained computational graph coding combination, and obtaining the optimized computational graph coding combination.

[0049] Specifically, the genetic algorithm is used to optimize the computational graph encoding combination, and the optimization process is as follows:

[0050] First, a certain number of computational graph encoding combinations are randomly generated as the initial population.

[0051] Then, the performance of each encoding combination in the population is evaluated using the objective function.

[0052] Next, a portion of the coding combinations are selected as parents according to their performance.

[0053] Finally, the selected parent encoding combinations are crossed to generate new child encoding combinations as the optimized computational graph encoding combinations.

[0054] After obtaining the optimized computational graph encoding combination, it is necessary to determine whether the optimized computational graph encoding combination meets the optimization conditions. If the optimization conditions are met, the computational graph encoding combination is output; otherwise, the computational graph encoding combination needs to be optimized again.

[0055] Among them, one of the optimization conditions is: whether the optimized calculation graph encoding combination satisfies the permutation rule, and the permutation rule includes the intra-dimensional permutation rule and the inter-dimensional permutation rule. Specifically,

[0056] The calculation formula for the intra-dimensional permutation rule is:

[0057] C0→C1→f→C2…→C n =C0→C1→C2→f…→C n

[0058] Among them, C i represents the network layer in the neural network, f represents the permutation operation within the dimension, and → represents the data flow direction in the neural network;

[0059] The specific calculation formula for inter-dimensional substitution rules is:

[0060] C0→C1→g→C2…→C n =C0→C1→C2→g…→C n

[0061] Among them, C i Represents the network layer in the neural network, g represents the permutation operation between dimensions, and → represents the data flow in the neural network.

[0062] The second optimization condition is:

[0063] N after ≥N before

[0064] Wherein, is the number of data conversion layers in the optimized computational graph encoding combination, and is the number of data conversion layers in the computational graph encoding combination before optimization.

[0065] In the specific implementation process, compared with the calculation graph encoding combination before optimization, the number of data conversion layers after the optimization can only be reduced or remain unchanged, and cannot be increased.

[0066] Step S4: decode the optimized computation graph encoding combination according to the decoding rules to obtain the optimized computation graph.

[0067] Specifically, the decoding rule is: decode 0 in the computation graph encoding combination into the data conversion layer of the computation graph; decode 1 in the computation graph encoding combination into the data computation layer of the computation graph.

[0068] Step S5, simulating and verifying the optimized calculation graph;

[0069] In the specific implementation process, the computational graph needs to be compiled first, and then simulation verification is performed.

[0070] Step S6, repeating steps S3 to S5 until the optimization termination rule is met.

[0071] Preferably, one of the termination rules is: the calculation speed of the optimized calculation graph is less than a set threshold.

[0072] So far, according to the method disclosed in the present invention, the working process of the present invention has been implemented once.

[0073] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.

[0074] It should be noted that the serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages and disadvantages of the embodiments. And the terms "including", "comprising" or any other variants thereof in this article are intended to cover non-exclusive inclusion, so that a process, device, article or method including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, device, article or method. In the absence of further restrictions, an element defined by the sentence "including a ..." does not exclude the presence of other identical elements in the process, device, article or method including the element.

Claims

1. A method for optimizing a neural network computation graph, characterized in that: Includes steps: Step S1, obtaining a computational graph of a neural network to be compiled, and marking the neural network layer in the computational graph that can perform a permutation operation according to a marking rule; Step S2, encoding the marked computational graph according to the encoding rule to obtain a computational graph encoding combination; Step S3, optimizing the obtained computational graph coding combination, and obtaining the optimized computational graph coding combination; Step S4, decoding the optimized computation graph coding combination according to the decoding rule to obtain the optimized computation graph; Step S5, simulating and verifying the optimized calculation graph; Step S6, repeating steps S3 to S5 until the optimization termination rule is met.

2. A method for optimizing a neural network calculation graph according to claim 1, characterized in that: The neural network layer that can perform the permutation operation in the computation graph is marked according to the marking rule described in step S1. Specifically, the marking rule is: If it is an intra-dimensional permutation, the data coordinates input when calculating a single output by the calculation functions of the layer before and after the permutation operation should be equal in the permuted dimension. If it is a permutation between dimensions, the data coordinates input when the calculation functions of the layer before the permutation operation and the layer after the permutation operation calculate a single output should be equal in all permuted dimensions.

3. The method for optimizing a neural network calculation graph according to claim 1, characterized in that: The encoding rule described in step S2 is specifically: encoding the data conversion layer in the calculation graph as 0, and encoding the data calculation layer in the calculation graph as 1.

4. The method for optimizing a neural network calculation graph according to claim 1, characterized in that: Step S3 includes the steps of: Step S301, optimizing the computational graph encoding combination using a genetic algorithm; Step S302: after obtaining the optimized computation graph coding combination, determine whether the optimized computation graph coding combination meets the optimization condition; Step S303: if the optimization condition is met, the computation graph coding combination is output; otherwise, the computation graph coding combination needs to be optimized again.

5. A method for optimizing a neural network calculation graph according to claim 4, characterized in that: Step S301 includes the steps of: Step A1, randomly generate a certain number of computational graph encoding combinations as the initial population; Step A2, using the objective function to evaluate the performance of each encoding combination in the population; Step A3, selecting a portion of the coding combinations as parents according to the performance of the coding combinations; Step A4, cross the selected parent coding combination to generate a new child coding combination as the optimized computation graph coding combination.

6. A method for optimizing a neural network calculation graph according to claim 4, characterized in that: The step S302 determines whether the optimized calculation graph encoding combination meets the optimization conditions, specifically including optimization condition 1 and optimization condition 2, wherein: The first optimization condition is whether the optimized computational graph encoding combination satisfies the permutation rule. The permutation rule includes the intra-dimensional permutation rule and the inter-dimensional permutation rule. Specifically, The calculation formula for the intra-dimensional substitution rule is: C0→C1→f→C2…→C n =C0→C1→C2→f…→C n Among them, C i represents the network layer in the neural network, f represents the permutation operation within the dimension, and → represents the data flow direction in the neural network; The specific calculation formula for inter-dimensional substitution rules is: C0→C1→g→C2…→C n =C0→C1→C2→g…→C n Among them, C i Represents the network layer in the neural network, g represents the permutation operation between dimensions, and → represents the data flow in the neural network. The second optimization condition is: N after ≥N before Wherein, is the number of data conversion layers in the optimized computational graph encoding combination, and is the number of data conversion layers in the computational graph encoding combination before optimization.

7. A method for optimizing a neural network calculation graph according to claim 1, characterized in that: The optimized computation graph coding combination described in step S4 is decoded. Specifically, the decoding rule is: decode 0 in the computation graph coding combination into the data conversion layer of the computation graph; and decode 1 in the computation graph coding combination into the data computation layer of the computation graph.