Operator fusion method and device and electronic equipment

By updating the calculation graph based on operator-related fusion methods in the deep learning framework, the problem of fixed operator fusion methods in the existing technology is solved, more efficient memory operations are achieved, and the running speed of the deep learning framework is improved.

CN118690837APending Publication Date: 2024-09-24BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410805389.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-20
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

When the existing deep learning framework performs operator fusion, the fixed fusion method results in a limited number of fusion operators, which cannot effectively reduce the frequency of memory reading and writing, thus limiting the improvement of running speed.

Method used

When it is determined that the upstream and downstream operators meet the fusion conditions, fusion processing is performed based on the target fusion method related to the operator, the calculation graph is updated, and the processor is called to perform calculations when there are no unfused operators, so as to realize the integration of multiple calculations. Flexible integration of children.

Benefits of technology

It increases the number of fusion operators, reduces the number of intermediate data reads and processing result writes to the memory, improves the processor's running speed and saves execution time.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118690837A
    Figure CN118690837A
Patent Text Reader

Abstract

The invention provides an operator fusion method and device and electronic equipment, and relates to the technical field of computers, in particular to the technical fields of artificial intelligence, model training, big data and the like. According to the specific implementation scheme, under the condition that it is determined that a first operator and a second operator in a current calculation graph meet fusion conditions, fusion processing is carried out on the first operator and the second operator based on a target fusion mode, and a fused first target operator is obtained; based on the fused first target operator, obtaining an updated current calculation graph; and under the condition of determining that the non-fused operators do not exist in the updated current calculation graph, taking the updated current calculation graph as a target calculation graph, and calling a target processor to execute calculation on a plurality of operators included in the target calculation graph through a read-write memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of computer technology, and in particular to technical fields such as artificial intelligence, model training, and big data. Background Art

[0002] As deep learning is increasingly used in various industries, the speed requirements for deep learning frameworks during reasoning are also increasing. The existing technology usually uses operator fusion to optimize the performance of deep learning frameworks. However, when processing operator fusion in related technologies, two upstream and downstream operators are mainly fused in a fixed manner, and the operators that can be fused in a fixed manner are also relatively fixed, which will result in the number of operators that can be fused being unable to be increased, and thus the frequency of reading and / or writing to the memory when the fused operator is executed cannot be reduced, so the running speed cannot be improved. Summary of the invention

[0003] The present disclosure provides an operator fusion method, device, electronic device and storage medium.

[0004] According to one aspect of the present disclosure, there is provided an operator fusion method, comprising:

[0005] When it is determined that the first operator and the second operator in the current calculation graph meet the fusion condition, the first operator and the second operator are fused based on the target fusion mode to obtain a fused first target operator, wherein the first operator is an upstream operator of the second operator, and the target fusion mode is related to the first operator and the second operator;

[0006] Based on the fused first target operator, obtaining an updated current computation graph;

[0007] When it is determined that there are no unfused operators in the updated current computation graph, the updated current computation graph is used as the target computation graph, and a target processor is called to perform calculations on multiple operators included in the target computation graph through a read-write memory, wherein the multiple operators include the fused first target operator.

[0008] According to one aspect of the present disclosure, there is provided an operator fusion device, comprising:

[0009] An operator fusion module, configured to, when determining that a first operator and a second operator in a current computation graph meet a fusion condition, fuse the first operator and the second operator based on the target fusion mode to obtain a fused first target operator, wherein the first operator is an upstream operator of the second operator, and the target fusion mode is related to the first operator and the second operator;

[0010] A computation graph updating module, used to obtain an updated current computation graph based on the fused first target operator;

[0011] An execution module is used to, when it is determined that there are no unfused operators in the updated current calculation graph, use the updated current calculation graph as the target calculation graph, and call the target processor to perform calculations on multiple operators included in the target calculation graph through a read-write memory, wherein the multiple operators include the fused first target operator.

[0012] According to another aspect of the present disclosure, there is provided an electronic device, comprising:

[0013] at least one processor; and

[0014] a memory communicatively connected to the at least one processor; wherein,

[0015] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the method of any embodiment of the present disclosure.

[0016] According to another aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the method according to any embodiment of the present disclosure.

[0017] According to another aspect of the present disclosure, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the method according to any one of the embodiments of the present disclosure is implemented.

[0018] By adopting the above scheme, when it is determined that the first operator and the second operator that are dependent on the upstream and downstream can be fused, the fusion processing can be performed according to the fusion method related to the first operator and the second operator, and the calculation graph is updated based on the fused first target operator. Finally, when there are no unfused operators in the updated calculation graph, the target calculation graph is generated and the target processor is called to execute multiple operators by reading the memory. In this way, based on a more flexible fusion method related to the first operator and the second operator, multiple possible operators are fused, which can increase the number of operators that can be fused. When the target processor performs calculations on the calculation graph containing more fused operators, the number of times the intermediate data of the memory is read and / or the number of times the processing results are written to the memory can be reduced, thereby improving the running speed of the target processor and saving the time consumed by the target processor in the reading and writing process. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present disclosure.

[0020] Figure 1 is a flowchart of an operator fusion method according to an embodiment of the present disclosure;

[0021] Figure 2 is a schematic diagram of a generation scenario of a reduction tree according to an embodiment of the present disclosure;

[0022] Figure 3 is a schematic diagram of another generation scenario of a reduction tree according to an embodiment of the present disclosure;

[0023] Figure 4 is a schematic diagram of the composition structure of an operator fusion device according to another embodiment of the present disclosure;

[0024] Figure 5 is a block diagram of an electronic device for implementing an embodiment of the present disclosure. DETAILED DESCRIPTION

[0025] The following is a description of exemplary embodiments of the present disclosure in conjunction with the accompanying drawings, including various details of the embodiments of the present disclosure to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope of the present disclosure. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0026] In one aspect, an embodiment of the present disclosure provides an operator fusion method, such as Figure 1 As shown, including:

[0027] S101, when it is determined that the first operator and the second operator in the current calculation graph meet the fusion condition, the first operator and the second operator are fused based on the target fusion method to obtain a fused first target operator, wherein the first operator is an upstream operator of the second operator, and the target fusion method is related to the first operator and the second operator.

[0028] S102: Obtain an updated current computation graph based on the fused first target operator.

[0029] S103, when it is determined that there are no unfused operators in the updated current computation graph, use the updated current computation graph as the target computation graph, and call the target processor to perform calculations on multiple operators included in the target computation graph through a read-write memory, wherein the multiple operators include the fused first target operator.

[0030] The operator fusion method provided in this embodiment is executed by a target device, which may be a server or a computer; further, a deep learning framework may be set in or capable of running in the target device.

[0031] The target computation graph is a computation graph for model networking, which can be set or include multiple operators of model networking. The target computation graph can be used to determine or obtain the structure and / or function of the target model. In other words, the target computation graph can construct the structure of a target model. Further, the target computation graph is used to generate a code compilation result, and the code compilation result is used to be executed by the target processor and obtain a processing result when sent to the target processor, wherein the target processor is different from the target device. By running the code compilation result corresponding to the target computation graph, the target model can be trained and / or finally obtained. The target model can be applied to a variety of possible fields, such as speech processing, image processing, data processing, text processing, etc. At least one of the fields in which the target model may be applied is not limited or exhaustive.

[0032] The embodiment of the present application can, when it is determined that the first operator and the second operator that are dependent on the upstream and downstream can be fused, perform fusion processing according to the fusion method related to the first operator and the second operator, update the calculation graph based on the fused first target operator, and finally, when there are no unfused operators in the updated calculation graph, generate a target calculation graph and call the target processor to execute multiple operators by reading the memory. In this way, based on a more flexible fusion method related to the first operator and the second operator, multiple possible operators are fused, which can increase the number of operators that can be fused. When the target processor performs calculations on the calculation graph containing more fused operators, the number of times the intermediate data of the memory is read and / or the number of times the processing results are written to the memory can be reduced, thereby improving the running speed of the target processor and saving the time consumed by the target processor in the reading and writing process.

[0033] In some possible implementations, when it is determined that the first operator and the second operator in the current computation graph meet the fusion condition, the first operator and the second operator are fused based on the target fusion method to obtain the fused first target operator, which may include: the target device extracts the first operator and the second operator from the current computation graph. Here, the second operator may refer to an operator that directly depends on the output tensor of the first operator, or the second operator is an operator that uses a certain output tensor of the first operator as any one of its own input tensors.

[0034] Specifically, the first operator and the second operator extracted from the current computation graph may be one of the following:

[0035] During the k-th fusion traversal process, when the process of extracting operators from the current computation graph is executed for the first time, the most upstream operator in the current computation graph is used as the first operator, and the downstream operator of the first operator is used as the second operator;

[0036] During the kth fusion traversal process, when the process of extracting the operator last time from the current calculation graph is completed, if the first operator and the second operator extracted last time do not meet the fusion condition, the second operator extracted last time is used as the first operator extracted currently, and the downstream operator of the first operator extracted currently is used as the second operator extracted currently; if the first operator and the second operator extracted last time meet the fusion condition and the last target operator after fusion is obtained, the downstream operator of the second operator extracted last time is used as the first operator extracted currently, and the downstream operator of the first operator extracted currently is used as the second operator extracted currently.

[0037] The k-th fusion traversal process mentioned above may refer to performing the k-th fusion traversal process on the current computation graph obtained after the k-1-th fusion traversal process. Any fusion traversal process is to complete an extraction of all operators in the current computation graph, determine whether the fusion conditions are met, and perform operator fusion when the fusion conditions are met. Among them, k is an integer not less than 1. When k is equal to 1, the current computation graph obtained after the k-1-th fusion traversal process refers to the original computation graph, which may include multiple operators, and the multiple operators may be multiple operators that are completely unfused.

[0038] In some possible implementations, when it is determined that the first operator and the second operator in the current calculation graph meet the fusion condition, the first operator and the second operator are fused based on the target fusion method to obtain the fused first target operator, including: when it is determined that the first operator and the second operator meet the fusion condition based on the type of the first operator and the type of the second operator, the first operator and the second operator are fused based on the target fusion method to obtain the fused first target operator.

[0039] Here, the type of the first operator may be determined based on at least one of a calculation expression, input parameters, and output parameters of the first operator. The type of the second operator may be determined based on at least one of a calculation expression, input parameters, and output parameters of the second operator.

[0040] The type of the first operator may be any one of all possible operator types that can be set in the current computation graph, and the type of the second operator may be any one of all possible operator types that can be set in the current computation graph. The type of the first operator and the type of the second operator may be the same or different, both within the protection scope of this embodiment.

[0041] When it is determined that the first operator and the second operator do not satisfy the fusion condition, the target device may perform the following processing: when the second operator currently extracted by the target device is the last operator in the current calculation graph, determine that one traversal and fusion processing of the current calculation graph is completed, and then the next traversal and fusion processing may be performed; when the second operator currently extracted by the target device is not the last operator in the current calculation graph, use the second operator currently extracted as the first operator to be extracted next time, and use the downstream operator of the first operator to be extracted next time as the second operator currently extracted, and perform the next fusion judgment.

[0042] In this way, it is possible to judge in turn whether two operators with upstream and downstream dependencies in the current calculation graph meet the fusion conditions. When the two operators meet the fusion conditions, the fusion will be performed based on the corresponding fusion methods of the two operators, thereby ensuring the accuracy of the fusion results.

[0043] In one embodiment, when it is determined based on the type of the first operator and the type of the second operator that the first operator and the second operator meet the fusion condition, the first operator and the second operator are fused based on the target fusion method to obtain the fused first target operator, including: when the first operator is of the first type and the second operator is of the first type or the second type, determining that the first operator and the second operator meet the fusion condition, wherein the first type is an operator type that does not perform data aggregation and the second type is an operator type that aggregates data; determining the target fusion method based on the type of the first operator and the type of the second operator, wherein the target fusion method is an operator substitution method; substituting the first operator into the second operator based on the target fusion method to obtain the fused first target operator.

[0044] The first type may specifically refer to: operators of multiple input and single output type, which can obtain output without data aggregation or calculation processing. More specifically, the first type of operator may be an operator that satisfies the requirement that there is a unique getindex function (used to obtain the index position of an element in an object or data structure) for each input type, and can map each output parameter to an input parameter for each input. Exemplarily, the first type may also be called a Trivial type, and operators of the Trivial type may include elementwise (tensor operation) operators, broadcast operators, injective operators, etc. All possible operators of the Trivial type are not limited or enumerated here. For example, the calculation expression of the Trivial type operator can be as follows: O[i]=G(I0[f0(i)], I1[f1(i)], I2[f2(i)]), where I0~I2 represent three input types, i represents an input parameter, f0(i)=i, f1(i)=i, f2(i)=i can represent the index of the input parameter, G() can represent the getindex function, and O[i] represents that the output is related to i. The target device can determine whether the calculation expressions of the first operator and the second operator are similar to the calculation expressions of the Trivial type operator by obtaining the calculation expressions of the first operator and the second operator. If the first operator is similar to the calculation expression of the Trivial type operator, it can be determined that the first operator is of the first type, and / or if the second operator is similar to the calculation expression of the Trivial type operator, it can be determined that the second operator is of the first type.

[0045] The second type may specifically refer to: a multi-input operator, which performs data aggregation or calculation processing to obtain an output. More specifically, the second type of operator may be an operator that performs any one or more calculations such as summing, taking the maximum value, taking the minimum value, taking any value, etc. on multiple inputs. Exemplarily, the second type may also be called a Reduce type or a Strict Reduce type. For example, the calculation expression of the operator of the reduction class may include multiple types of parameters in the input, and the output may include one type of parameter; accordingly, the target device may determine whether the calculation expressions of the first operator and the second operator are consistent with the calculation expression of the operator of the reduction class by obtaining the calculation expressions of the first operator and the second operator. If the calculation expression of the first operator is consistent with the calculation expression of the operator of the reduction class, it can be determined that the first operator is of the second type, and / or if the calculation expression of the second operator is consistent with the calculation expression of the operator of the reduction class, it can be determined that the second operator is of the second type.

[0046] In the case where the first operator is of the first type and the second operator is of the first type or the second type, determining whether the first operator and the second operator meet the fusion condition may include: obtaining calculation expressions of the first operator and the second operator, determining whether the calculation expression of the first operator is consistent with the calculation expression of the operator of the reduction class or the calculation expression of the operator of the Trivial type, and determining whether the calculation expression of the second operator is consistent with the calculation expression of the operator of the reduction class or the calculation expression of the operator of the Trivial type; if it is determined that the calculation expression of the first operator is consistent with the calculation expression of the operator of the Trivial type, and it is determined that the calculation expression of the second operator is consistent with the calculation expression of the operator of the Trivial type, or is consistent with the calculation expression of the operator of the reduction class, then it can be determined that the first operator is of the first type and the second operator is of the first type or the second type, and it is determined that the first operator and the second operator meet the fusion condition.

[0047] In addition, the method may further include: when the first operator is neither the first type nor the second type, and the second operator is neither the first type nor the second type, the target device determines that the first operator and the second operator do not satisfy a fusion condition.

[0048] The target fusion method is an operator substitution method, for example, the operator substitution method can be implemented by an inline substitution method, which refers to directly embedding a function or a calculation expression into another function or expression to avoid the overhead of function calls. Correspondingly, substituting the first operator into the second operator to obtain the fused first target operator may include: substituting the calculation expression of the first operator into the calculation expression of the second operator to obtain the fused first target operator.

[0049] For example, the first operator and the second operator may both be of the first type, or the first operator may be of the first type and the second operator may be of the second type. In this case, it can be determined that the first operator and the second operator meet the fusion condition. Assuming that the first operator is represented as operator a and the second operator is represented as operator b, the target fusion method of the first operator and the second operator may be to substitute the calculation expression of operator a into the calculation expression of operator b. Based on such processing, the fused target operator c (for example, represented as c=a*b) may be obtained.

[0050] After obtaining the fused first target operator, obtaining an updated current calculation graph based on the fused first target operator can be: deleting the first operator and the second operator from the current calculation graph, and saving the fused first target operator in the current calculation graph to obtain an updated current calculation graph. If the first operator has an upstream operator, the upstream operator is used as the upstream operator of the fused first target operator, and if the second operator has a downstream operator, the downstream operator is used as the downstream operator of the fused first target operator.

[0051] By adopting the above solution, when the upstream operator is of the first type and the downstream operator is of the first type or the second type, the upstream operator and the downstream operator are directly fused by substitution, which can avoid the overhead of function calls, reduce the time and resources occupied by reading and storing memory, and improve processing efficiency.

[0052] In some embodiments, the method may also include one of the following: when the first operator and the second operator are both of the second type and the first input parameter of the second operator is not a variable that affects the output parameter, determining that the first operator and the second operator satisfy the fusion condition, wherein the second type is an operator type that aggregates data; when the first operator is of the second type, the second operator is of the first type, and the number of output parameters of the second operator is less than the number of input parameters of the first operator, determining that the first operator and the second operator satisfy the fusion condition, wherein the first type is an operator type that does not aggregate data.

[0053] In an embodiment, when the first operator and the second operator are both of the second type and the first input parameter of the second operator is not a variable that affects the output parameter, determining that the first operator and the second operator satisfy the fusion condition may include: when the first operator and the second operator are both of the second type, obtaining the relationship between multiple input parameters and output parameters of the second operator; when the first input parameter among the multiple input parameters of the second operator is not a variable that affects the output parameter, determining that the first operator and the second operator satisfy the fusion condition.

[0054] Optionally, the second operator may be a single operator of the second type. Optionally, the second operator may be a second subtree generated by any previous fusion traversal process.

[0055] Optionally, the number of the first operator may be one. The first operator may be a single second-type operator; or, since any subtree in the current computation graph may be used as a second-type operator, the first operator may be a first subtree obtained after any previous fusion traversal processing.

[0056] Optionally, there may be multiple first operators, which may be multiple upstream operators of the second operator. The multiple first operators may include at least two of the following: one or more single second-type operators, and one or more first subtrees obtained after any previous fusion traversal processing.

[0057] Exemplarily, if the second operator is a single operator of the second type, the method for determining whether the first input parameter among the multiple input parameters of the second operator is a variable that affects the output parameter may be: determining whether the output parameter of the second operator is different when the first input parameter of the multiple input parameters of the second operator changes its value; if different, determining that the first input parameter of the second operator is a variable that affects the output parameter; if the same, determining that the first input parameter of the second operator is not a variable that affects the output parameter.

[0058] For example, assuming that the second operator is a single operator of the second type, the calculation of its input parameter is f b (i, j), where the multiple input parameters are i and j, and the first input parameter j has different values, such as j1 and j2, respectively, and f is obtained. b (i,j1)=f b (i, j2), then the first input parameter "j" of the second operator is not a variable that affects the output parameter.

[0059] Exemplarily, when the second operator is the second subtree, a method for determining whether the first input parameter among multiple input parameters of the second operator is a variable that affects the output parameter may be as follows: determine whether the output parameter of the second subtree is different when the first input parameter of multiple input parameters of one or more leaf nodes in the second subtree changes its value; if different, determine that the first input parameter of the second subtree is a variable that affects the output parameter; if the same, determine that the first input parameter of the second subtree is not a variable that affects the output parameter.

[0060] Furthermore, the solution provided by this embodiment may also include: when multiple input parameters of the second operator are variables that affect output parameters, the target device determines that the first operator and the second operator do not satisfy a fusion condition.

[0061] In one embodiment, when the first operator is of the second type, the second operator is of the first type, and the number of output parameters of the second operator is less than the number of input parameters of the first operator, determining that the first operator and the second operator satisfy the fusion condition includes: when the first operator is of the second type and the second operator is of the first type, obtaining the number of output parameters of the second operator and the number of input parameters of the first operator; when the number of output parameters of the second operator is less than the number of input parameters of the first operator, determining that the first operator and the second operator satisfy the fusion condition.

[0062] Optionally, the number of the first operators may be one; the first operator may be a single operator of the second type, or the first operator may be a first subtree obtained after any previous fusion traversal processing. Optionally, the number of the first operators may be multiple, and the multiple first operators may include at least two of the following: one or more single operators of the second type, and one or more first subtrees obtained after any previous fusion traversal processing.

[0063] In this embodiment, before obtaining the number of output parameters of the second operator and the number of input parameters of the first operator, the second operator may be adjusted to obtain an adjusted second operator, and the adjusted second operator is of the second type.

[0064] For example, if the second operator is of the first type, then the second operator is a Trivial operator. Since the Trivial operator does not aggregate or calculate multiple input parameters, the calculation expression of the second operator can be simply replaced by a reduce operator containing a false or empty input parameter or an adjusted second operator. The adjusted second operator is also a Reduce operator (i.e., an operator of the first type).

[0065] In the case where the number of output parameters of the second operator is less than the number of input parameters of the first operator, determining that the first operator and the second operator meet the fusion condition may include: judging whether the number of output parameters of the adjusted second operator is less than the number of input parameters of the first operator, and in the case where the number of output parameters of the adjusted second operator is less than the number of input parameters of the first operator, determining that the first operator and the adjusted second operator meet the fusion condition. Here, the number of first operators may be one or more, and if the number of first operators is multiple, then the number of input parameters of the first operator refers to the number of all input parameters of all first operators; in addition, if the first operator is a first subtree, then the number of all input parameters of the first operator refers to the number of all input parameters of all leaf nodes of the first subtree, and if the first operator is multiple first subtrees, then the number of all input parameters of multiple first operators refers to the number of all input parameters of all leaf nodes of all first subtrees.

[0066] Furthermore, the solution provided in this embodiment may also include: the target device determines that the first operator and the adjusted second operator do not satisfy a fusion condition when the number of output parameters of the adjusted second operator is not less than the number of input parameters of the first operator.

[0067] In this embodiment, whether the number of output parameters of the adjusted second operator is less than the number of input parameters of the first operator is determined because if the number of output parameters of the second operator is not less than the number of input parameters of the first operator, the first operator may be calculated multiple times, resulting in a problem of excessive computational overhead.

[0068] In this way, when the first operator and the second operator are both operators of the second type, it is possible to further determine whether the first operator and the second operator meet the fusion condition by judging whether the second operator has the first input parameter that does not affect the output parameter, thereby ensuring the accuracy of the fusion of the first operator and the second operator; and, when the first operator is an operator of the second type and the second operator is an operator of the first type, it is possible to further determine whether the first operator and the second operator meet the fusion condition by judging the relationship between the number of input parameters and output parameters of the second operator and the first operator, thereby ensuring the accuracy of the fusion of the first operator and the second operator and avoiding the problem of excessive computational overhead.

[0069] In one embodiment, the first operator and the second operator are fused based on the target fusion method to obtain the fused first target operator, including: the target device combines the first operator and the second operator into a current subtree, wherein the first operator in the current subtree is a leaf node and the second operator is a root node; and the current subtree is used as the fused target operator.

[0070] Optionally, the number of the first operators may be one, for example, the first operator may be a single operator of the second type, or the first operator may be a first subtree generated by any previous fusion traversal process. Optionally, the number of the first operators may be multiple, and the multiple first operators may include at least two of the following: one or more single operators of the second type, and one or more first subtrees obtained after any previous fusion traversal process.

[0071] Optionally, the second operator may be a single operator of the second type (may be an operator of the second type adjusted from a single operator of the first type), or may be a second subtree generated by any previous fusion traversal process.

[0072] Since any subtree can only be composed of operators of the second type (or operators that are initially of the first type but adjusted to operators of the second type (such as the second operator in the aforementioned embodiment)), any subtree can be regarded as an operator of the second type in the current computation graph.

[0073] Exemplarily, there is one first operator; the first operator and the second operator form a current subtree, which may refer to: the first operator is used as a leaf node of the current subtree, and the second operator is used as a root node of the current subtree. That is, the upstream operator or the first subtree of two adjacent second-type operators that meet the fusion condition is used as a leaf node, and the downstream operator is used as a root node to form the current subtree.

[0074] For example, the first operator is Reduce operator A and the second operator is Reduce operator C. Reduce operator A can be used as a leaf node of Reduce operator C to form a current subtree (eg, called Reduce Tree a).

[0075] Exemplarily, there are multiple first operators; forming the current subtree with the first operator and the second operator may refer to: using the multiple first operators as multiple leaf nodes of the current subtree and using the second operator as the root node of the current subtree.

[0076] Combination Figure 2For example, the two first operators are Reduce operator A and Reduce operator B, and the second operator is Reduce operator C. Reduce operator A and Reduce operator B can be used as two leaf nodes, and Reduce operator C can be used as the root node to form a current subtree (for example, called Reduce Tree a). The current subtree is the first target operator obtained by this fusion, and the first target operator is also an operator of the second type.

[0077] Combination Figure 3 For example, the first operator is composed of the first subtree, which is the Reduce Tree a (i.e. Figure 2 The reduction tree a) shown in FIG. 1 is a second operator, and the second subtree is a Reduce Tree b (as shown in FIG. 1 ). Figure 3 The reduction tree b shown in the figure contains two leaf nodes Reduce operator D and Reduce operator A, and a root node Reduce operator E). The first subtree and the second subtree meet the fusion condition, and the first subtree and the second subtree can be fused into the current subtree, and the result is Figure 3 In the reduction tree a*b shown, the first subtree is a leaf node of the second subtree, and the root node of the first subtree is connected to the first leaf node Reduce operator D of the second subtree (because Reduce operator D has a dependency relationship with Reduce operator C). The relationship between the first leaf node and the first operator or the first subtree is the same as that in the previous embodiment and will not be described in detail.

[0078] In this way, when the first operator is of the second type, the second operator is an operator of the first type or the second type, and the first operator and the second operator meet the fusion condition, the current subtree formed by the first operator and the second operator can be used as the fused target operator, thereby ensuring the accuracy of the fusion of the first operator and the second operator and avoiding the problem of excessive computational overhead.

[0079] In one embodiment, obtaining an updated current computation graph based on the fused first target operator includes: generating an updated first target operator based on multiple nodes included in the fused first target operator when there is no fusionable operator in the fused first target operator; and generating the updated current computation graph based on the updated first target operator.

[0080] Optionally, the processing method for determining whether there is a fusible operator for the first target operator after fusion is similar to the aforementioned method for determining whether the first operator is a second similar operator, but the timing for determining whether there is a fusible operator for the first target operator after fusion may be performed when the next fusion traversal process is performed. For example, the first target operator after fusion may be used as the first operator extracted from the current calculation graph at any time during the next fusion traversal process, and when the first operator is of the second type and the first operator and the second operator do not meet the fusion condition, it is determined that there is no fusible operator for the first target operator after fusion.

[0081] Optionally, a method for determining whether there is a fusible operator for the first target operator after fusion may be, when there is no downstream operator after the first target operator after fusion, determining that there is no fusible operator for the first target operator after fusion.

[0082] Generating an updated first target operator based on multiple nodes included in the fused first target operator can include: extracting the current subtree included in the fused first target operator, performing an identity dependency transformation on the operator corresponding to each node in the multiple nodes of the current subtree to obtain the transformed operator corresponding to each node; performing a fusion process in a specified manner based on the transformed operator corresponding to each node to obtain the updated first target operator.

[0083] Among them, performing an identity dependency transformation on the operator corresponding to each of the multiple nodes of the current subtree to obtain the transformed operator corresponding to each node may include: starting from the root node of the current subtree, performing an identity dependency transformation on the operator corresponding to each child node to generate an updated operator corresponding to each updated child node; taking each updated child node as a parent node, continuing to extract each child node corresponding to the parent node from the downstream of the current subtree, performing an identity dependency transformation on the operator corresponding to each child node to generate an updated operator corresponding to each updated child node, and so on, until the processing of all nodes on the first subtree is completed, and the operator corresponding to each node in all nodes on the first subtree is used as the transformed operator. In this way, after the current subtree completes the identity dependency transformation, all operators that meet the identity dependency requirements are obtained.

[0084] The specified method can be configured according to actual conditions. For example, it can be a LEMMA transformation, and the transformed operator corresponding to each node is fused in a specified manner to obtain the updated first target operator. It can be: the calculation expression of the operator corresponding to the leaf node in the current subtree is fused with the calculation expression of the operator corresponding to the parent node corresponding to the leaf node to obtain the calculation expression of the updated operator, and the updated operator is used as the updated leaf node; and so on, until the calculation expressions corresponding to the operators of all updated leaf nodes are fused with the calculation expressions of the operators corresponding to the root node to obtain the updated first target operator.

[0085] The judgment method for determining that there are no unfused operators in the updated current computation graph may be: when completing a fusion traversal, it is determined that this fusion traversal does not perform fusion processing on any operator, and then it is determined that there are no unfused operators in the updated current computation graph.

[0086] There may be one or more target processors, for example, the target processor may include at least one of a CPU (Central Processing Unit) and a GPU (Graphics Processing Unit). Calling the target processor to perform calculations on multiple operators included in the target calculation graph by reading and writing the memory may be to determine the target processor that needs to be called for all operators included in the target calculation graph, and determine the execution order of each operator based on the dependency relationship between the operators; when executing the current operator, calling the target processor corresponding to the current operator, and having the target processor corresponding to the current operator read the input parameters required by the current operator from the memory, perform calculations on the current operator and obtain calculation results, write the calculation results into the memory, and so on, until the processing of all operators is completed. Among them, the target processors corresponding to different operators may be the same or different. The method of determining the target processor corresponding to any operator can be determined based on the calculation type or calculation requirement of each operator. For example, for operators that are computationally intensive and highly parallel, they may be assigned to the GPU, while for operators with more complex logical control, they may be more suitable for execution on the CPU. It should be understood that this is only an exemplary description, and this embodiment does not limit or exhaustively describe how to determine the target processor for each operator.

[0087] By adopting the above scheme, when the first target operator after fusion is the current subtree, it is possible to fuse the multiple nodes it includes to generate an updated target operator. In this way, the fusion of more second-type operators can be achieved through the tree structure, and the number of operators that can be fused can be increased. When the target processor performs calculations on calculation graphs with more fused operators, the number of times the intermediate data of the memory is read and / or the number of times the processing results are written to the memory can be reduced, thereby improving the running speed of the target processor and saving the time consumed by the target processor in the reading and writing process.

[0088] Figure 4 FIG. 1 shows a schematic block diagram of an operator fusion device provided by an embodiment of the present disclosure. Figure 4 As shown, including:

[0089] An operator fusion module 401 is used to fuse the first operator and the second operator in the current calculation graph based on the target fusion mode to obtain a fused first target operator when it is determined that the first operator and the second operator in the current calculation graph meet the fusion condition, wherein the first operator is an upstream operator of the second operator, and the target fusion mode is related to the first operator and the second operator;

[0090] A computation graph updating module 402, configured to obtain an updated current computation graph based on the fused first target operator;

[0091] The execution module 403 is used to, when it is determined that there are no unfused operators in the updated current calculation graph, use the updated current calculation graph as the target calculation graph, and call the target processor to perform calculations on multiple operators included in the target calculation graph through a read-write memory, wherein the multiple operators include the fused first target operator.

[0092] The operator fusion module is used to fuse the first operator and the second operator based on the target fusion mode to obtain the fused first target operator when it is determined that the first operator and the second operator meet the fusion condition based on the type of the first operator and the type of the second operator.

[0093] The operator fusion module is used to determine whether the first operator and the second operator meet the fusion condition when the first operator is of the first type and the second operator is of the first type or the second type, wherein the first type is an operator type that does not perform data aggregation and the second type is an operator type that aggregates data; determine the target fusion mode based on the type of the first operator and the type of the second operator, wherein the target fusion mode is an operator substitution mode; substitute the first operator into the second operator based on the target fusion mode to obtain the fused first target operator.

[0094] The operator fusion module is used to perform one of the following:

[0095] In a case where both the first operator and the second operator are of a second type and a first input parameter of the second operator is not a variable that affects an output parameter, determining that the first operator and the second operator meet the fusion condition, wherein the second type is an operator type for aggregating data;

[0096] When the first operator is the second type, the second operator is the first type, and the number of output parameters of the second operator is less than the number of input parameters of the first operator, it is determined that the first operator and the second operator meet the fusion condition, wherein the first type is an operator type that does not perform data aggregation.

[0097] The operator fusion module is used to combine the first operator and the second operator into a current subtree, wherein the first operator in the current subtree is a leaf node and the second operator is a root node; and the current subtree is used as the first target operator after fusion.

[0098] The computation graph updating module is used to generate an updated first target operator based on multiple nodes included in the fused first target operator when there is no fusible operator in the fused first target operator; and to generate the updated current computation graph based on the updated first target operator.

[0099] For the description of specific functions and examples of each module and submodule of the device in the embodiment of the present disclosure, reference can be made to the relevant description of the corresponding steps in the above method embodiment, which will not be repeated here.

[0100] In the technical solution disclosed herein, the acquisition, storage and application of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0101] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device, a readable storage medium and a computer program product.

[0102] Figure 5 A schematic block diagram of an example electronic device 500 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.

[0103] like Figure 5 As shown, the electronic device 500 includes a computing unit 501, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 502 or a computer program loaded from a storage unit 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device 500 can also be stored. The computing unit 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.

[0104] Multiple components in the electronic device 500 are connected to the I / O interface 505, including: an input unit 506, such as a keyboard, a mouse, etc.; an output unit 507, such as various types of displays, speakers, etc.; a storage unit 508, such as a disk, an optical disk, etc.; and a communication unit 509, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 509 allows the electronic device 500 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.

[0105] The computing unit 501 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 501 performs the various methods and processes described above. For example, in some embodiments, the various methods may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 500 via ROM 502 and / or communication unit 509. When the computer program is loaded into RAM 503 and executed by the computing unit 501, one or more steps of the method described above may be performed. Alternatively, in other embodiments, the computing unit 501 may be configured to execute the method in any other appropriate manner (e.g., by means of firmware).

[0106] According to another aspect of the present disclosure, an autonomous driving vehicle is provided, comprising the above-mentioned electronic device.

[0107] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0108] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.

[0109] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0110] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0111] input, voice input, or tactile input) to receive input from the user.

[0112] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0113] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.

[0114] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.

[0115] The above specific implementations do not constitute a limitation on the protection scope of the present disclosure. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the principles of the present disclosure shall be included in the protection scope of the present disclosure.

Claims

1. An operator fusion method, include: When it is determined that the first operator and the second operator in the current computation graph meet the fusion condition, the first operator and the second operator are fused based on a target fusion mode to obtain a fused first target operator, wherein the first operator is an upstream operator of the second operator, and the target fusion mode is related to the first operator and the second operator; Based on the fused first target operator, obtaining an updated current computation graph; When it is determined that there are no unfused operators in the updated current computation graph, the updated current computation graph is used as the target computation graph, and a target processor is called to perform calculations on multiple operators included in the target computation graph through a read-write memory, wherein the multiple operators include the fused first target operator.

2. The method according to claim 1, in, In the case where it is determined that the first operator and the second operator in the current calculation graph meet the fusion condition, the first operator and the second operator are fused based on the target fusion mode to obtain a fused first target operator, including: When it is determined that the first operator and the second operator satisfy the fusion condition based on the type of the first operator and the type of the second operator, the first operator and the second operator are fused based on the target fusion mode to obtain the fused first target operator.

3. The method according to claim 2, in, The step of, when it is determined based on the type of the first operator and the type of the second operator that the first operator and the second operator meet the fusion condition, fusing the first operator and the second operator based on the target fusion mode to obtain the fused first target operator, includes: When the first operator is of the first type and the second operator is of the first type or the second type, determining that the first operator and the second operator meet a fusion condition, wherein the first type is an operator type that does not perform data aggregation and the second type is an operator type that aggregates data; Determining the target fusion mode based on the type of the first operator and the type of the second operator, wherein the target fusion mode is an operator substitution mode; The first operator is substituted into the second operator based on the target fusion mode to obtain the fused first target operator.

4. The method according to claim 2, further comprising one of the following: In the case where both the first operator and the second operator are of the second type and the first input parameter of the second operator is not a variable that affects the output parameter, determining that the first operator and the second operator satisfy the fusion condition, in, The second type is an operator type for aggregating data; When the first operator is the second type, the second operator is the first type, and the number of output parameters of the second operator is less than the number of input parameters of the first operator, it is determined that the first operator and the second operator meet the fusion condition, wherein the first type is an operator type that does not perform data aggregation.

5. The method according to claim 4, in, The fusing the first operator and the second operator based on the target fusion mode to obtain the fused first target operator includes: The first operator and the second operator form a current subtree, wherein the first operator is a leaf node and the second operator is a root node in the current subtree; The current subtree is used as the first target operator after the fusion.

6. The method according to claim 5, in, The step of obtaining an updated current computation graph based on the fused first target operator includes: If there is no fusionable operator in the fused first target operator, generating an updated first target operator based on a plurality of nodes included in the fused first target operator; Based on the updated first target operator, the updated current computation graph is generated.

7. An operator fusion device, include: An operator fusion module, configured to, when determining that a first operator and a second operator in a current computation graph meet a fusion condition, fuse the first operator and the second operator based on a target fusion mode to obtain a fused first target operator, wherein the first operator is an upstream operator of the second operator, and the target fusion mode is related to the first operator and the second operator; A computation graph updating module, used to obtain an updated current computation graph based on the fused first target operator; An execution module is used to, when it is determined that there are no unfused operators in the updated current calculation graph, use the updated current calculation graph as the target calculation graph, and call the target processor to perform calculations on multiple operators included in the target calculation graph through a read-write memory, wherein the multiple operators include the fused first target operator.

8. The device according to claim 7, in, The operator fusion module is used to fuse the first operator and the second operator based on the target fusion mode to obtain the fused first target operator when it is determined that the first operator and the second operator meet the fusion condition based on the type of the first operator and the type of the second operator.

9. The device according to claim 8, in, The operator fusion module is used to determine whether the first operator and the second operator meet the fusion condition when the first operator is of the first type and the second operator is of the first type or the second type, wherein the first type is an operator type that does not perform data aggregation and the second type is an operator type that aggregates data; determine the target fusion mode based on the type of the first operator and the type of the second operator, wherein the target fusion mode is an operator substitution mode; substitute the first operator into the second operator based on the target fusion mode to obtain the fused first target operator.

10. The device according to claim 8, wherein the operator fusion module is configured to perform one of the following: In the case where both the first operator and the second operator are of the second type and the first input parameter of the second operator is not a variable that affects the output parameter, determining that the first operator and the second operator satisfy the fusion condition, in, The second type is an operator type for aggregating data; When the first operator is the second type, the second operator is the first type, and the number of output parameters of the second operator is less than the number of input parameters of the first operator, it is determined that the first operator and the second operator meet the fusion condition, wherein the first type is an operator type that does not perform data aggregation.

11. The device according to claim 10, in, The operator fusion module is used to combine the first operator and the second operator into a current subtree, wherein the first operator in the current subtree is a leaf node and the second operator is a root node; and the current subtree is used as the first target operator after fusion.

12. The device according to claim 11, in, The computation graph updating module is used to generate an updated first target operator based on a plurality of nodes included in the fused first target operator when there is no fused operator in the fused first target operator; Based on the updated first target operator, the updated current computation graph is generated.

13. An electronic device, include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 6.

14. A non-transitory computer-readable storage medium storing computer instructions, in, The computer instructions are used to cause the computer to execute the method according to any one of claims 1-6.

15. A computer program product, comprising a computer program, which, when executed by a processor, implements the method according to any one of claims 1 to 6.

Citation Information

Cited By

  • Data processing method for neural network model, server, equipment and medium

    CN119167991A

  • Data processing method, server, device and medium for neural network model

    CN119167991B