Similarity calculation optimization method and device for tensor program

By identifying shared inputs and dividing calculation graphs, redundant calculations in artificial intelligence applications are optimized, which solves the problem of unused redundant calculations in the existing technology and improves calculation efficiency.

CN118605931AActive Publication Date: 2024-09-06TSINGHUA UNIVERSITY

Patent Information

Application Number
CN202410533655.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-04-29
Publication Date
2024-09-06
Estimated Expiration
2044-04-29

AI Technical Summary

Technical Problem

Existing automatic optimization technology ignores the characteristics and properties of input and output tensors in artificial intelligence applications, making it difficult to automatically discover and utilize redundant computing optimization opportunities in complex applications.

Method used

By obtaining the shared input in the user request, the task processing calculation graph is divided into subgraphs, and the task execution plan is determined based on the specialized calculation graph of the subgraph, and similarity optimization is performed, including redundant propagation calculation and format conversion, and optimization of operators. Input and output tensors.

Benefits of technology

It realizes automatic identification of redundant data, formulates efficient task execution plans, reduces redundant calculations, and improves the optimization efficiency of calculation graphs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118605931A
    Figure CN118605931A
Patent Text Reader

Abstract

The invention relates to a similarity calculation optimization method and device for a tensor program, and the method comprises the steps: obtaining a plurality of user requests comprising at least one piece of initial data, and determining the initial data included in at least two user requests as shared input; at least one task execution scheme is determined according to the shared input, a plurality of sub-graphs obtained by segmenting the task processing calculation graph and a plurality of specialized calculation graphs corresponding to each sub-graph, and each task execution scheme is used for executing at least one user request and comprises a target specialized calculation graph corresponding to each sub-graph. And performing similarity optimization on the task processing calculation graph according to each task execution scheme to obtain an optimization processing calculation graph for executing a corresponding user request. According to the method and the device, after the user request is received, the shared input in the data information is automatically identified to obtain redundancy, then the specialized calculation graphs corresponding to the sub-graphs in the task calculation graph are selected through the redundancy, and the adaptive efficient task execution scheme is formulated to automatically optimize the task calculation graph.
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 a similarity calculation optimization method and device for a tensor program. Background Art

[0002] In order to generate efficient executable code on general-purpose processors or domain-specific AI chips, typical AI programming frameworks represent AI applications as tensor programs, and their computational processes are represented as computational graphs consisting of tensors and operators. In the compilation and optimization stage, AI applications represented by computational graphs are optimized in multiple layers, and more efficient computational graphs are found through equivalent transformations of computational graphs. In terms of graph optimization, existing work is mainly divided into two categories: manual optimization and automatic optimization. Manual optimization, that is, domain experts manually discover optimization rules and apply them to the compilation and optimization process, is widely used in AI programming frameworks including TensorFlow, TensorRT, TVM, MetaFlow, etc. However, this type of optimization requires system development engineers to have high domain knowledge and spend a lot of time looking for optimization opportunities. Therefore, automatic optimization has become a new research direction in academia and industry in recent years. However, existing automatic optimization technologies all focus on the computation itself and its equivalence, ignoring the characteristics and properties of the input and output tensors involved in the computation. Therefore, there are a large number of optimization opportunities such as redundant computations in increasingly complex AI applications that are difficult to be automatically discovered and utilized. Summary of the invention

[0003] In view of this, the present disclosure proposes a similarity calculation optimization method and device for tensor programs, aiming to automatically formulate efficient execution plans using redundant calculations and perform similarity optimization of calculation graphs.

[0004] According to a first aspect of the present disclosure, a similarity calculation optimization method for a tensor program is provided, the method comprising:

[0005] A similarity calculation optimization method for a tensor program, characterized in that the method comprises:

[0006] Acquire multiple user requests, each user request includes at least one initial data, and each initial data has a corresponding position in the user request;

[0007] determining initial data located at the same position in at least two of the user requests as shared input;

[0008] Determine multiple subgraphs obtained by splitting the task processing computation graph, and multiple specialized computation graphs corresponding to each of the subgraphs;

[0009] Determine at least one task execution scheme according to at least one of the shared inputs and a plurality of specialized computation graphs corresponding to each of the subgraphs, wherein each of the task execution schemes is used to execute at least one user request, and includes a target specialized computation graph corresponding to each of the subgraphs;

[0010] The task processing calculation graph is similarly optimized according to each task execution scheme to obtain an optimized processing calculation graph for executing the corresponding user request.

[0011] In a possible implementation, the task processing computation graph includes a plurality of operators, and an input tensor and an output tensor of each of the operators, the input tensor includes at least one input data to be processed by the operator, the output tensor includes output data after each input data in the input tensor is calculated by the operator, the determination of splitting the task processing computation graph to obtain a plurality of subgraphs, and a plurality of specialized computation graphs corresponding to each of the subgraphs, includes:

[0012] By performing consistency analysis on the task computation graph, at least one operator with the same optimization enabling condition is clustered to obtain a corresponding subgraph;

[0013] Specializing the subgraph according to the input tensor of each subgraph to obtain at least one corresponding candidate computation graph, each of the candidate computation graphs having a corresponding attribute signature, and the attribute signature is used to characterize whether there is redundancy in each of the input tensors corresponding to the candidate computation graph;

[0014] The input tensors and output tensors of the operators in each candidate computation graph are format converted according to the corresponding attribute signatures to obtain the corresponding specialized computation graph.

[0015] In a possible implementation, performing subgraph specialization according to the input tensor of each subgraph to obtain at least one corresponding candidate computation graph includes:

[0016] Determining a plurality of attribute signatures according to the number of each of the subgraph input tensors;

[0017] Specializing each of the subgraphs to obtain a computational graph to be screened corresponding to each of the attribute signatures;

[0018] The computation graph to be screened corresponding to each of the subgraphs is screened according to a preset computation graph screening rule to obtain at least one corresponding candidate computation graph.

[0019] In a possible implementation, the computation graph screening rule includes at least one of the following:

[0020] Deleting the computation graph to be screened that conflicts with the attribute signature;

[0021] In response to the existence of an inclusion relationship between the two to-be-screened computation graphs, deleting the included to-be-screened computation graph;

[0022] Delete all computational graphs to be filtered that have redundant input tensors.

[0023] In a possible implementation, the format conversion of the input tensor and the output tensor of each operator in the candidate computation graph is performed according to the corresponding attribute signature to obtain the corresponding specialized computation graph, including:

[0024] For each of the candidate computation graphs, performing redundant propagation calculations on each operator included therein according to the corresponding attribute signature, to obtain redundant attributes of each operator input tensor and output tensor;

[0025] According to the redundant attributes of the input tensor and output tensor of each operator, the input tensor and output tensor of the operator are format converted to obtain a corresponding specialized calculation graph.

[0026] In a possible implementation, for each candidate computation graph, redundant propagation calculation is performed on each operator included therein according to the corresponding attribute signature to obtain redundant attributes of each operator input tensor and output tensor, including:

[0027] Determine a redundancy propagation function for each operator, wherein the redundancy propagation function is used to determine the redundant attributes of the output tensor after the calculation based on the redundant attributes of the input tensor before the calculation;

[0028] For each of the candidate computation graphs, determining redundant attributes of the input tensor of the first operator therein according to the corresponding attribute signature;

[0029] Starting from the first operator in the candidate computation graph, the redundant attributes of the input tensor and the output tensor of each of the operators are calculated in turn according to the redundant attributes of the input tensor and the redundant propagation function.

[0030] In a possible implementation manner, the format conversion includes:

[0031] In response to the redundant attributes of the input tensor and the output tensor of the operator being redundant, dimension reduction processing is performed on the input tensor and the output tensor.

[0032] In a possible implementation, the task processing computation graph includes a plurality of operators and an input tensor of each of the operators, and the determination of splitting the task processing computation graph to obtain a plurality of subgraphs and a plurality of specialized computation graphs corresponding to each of the subgraphs further includes:

[0033] For each of the specialized computation graphs, when the number of input tensors of the operator is greater than 1 and there are at least two input tensors with different shapes, determining that the operator is an irregular operator;

[0034] The irregular operators are batch optimized to obtain an optimized specialized computation graph.

[0035] In a possible implementation, batch optimization is performed on the irregular operator to obtain an optimized specialized computation graph, including:

[0036] Determining the type of each of the irregular operators;

[0037] Corresponding batch optimization is performed according to the type of the irregular operator to obtain an optimized specialized computation graph.

[0038] In a possible implementation, performing corresponding batch optimization according to the type of the irregular operator includes:

[0039] In response to the type of the irregular operator being a data sharing operator, corresponding shape conversion operators are added before and after the irregular operator according to the shape of the input tensor, respectively, for converting the input tensor of the irregular operator into a regular input tensor, and performing reverse conversion on the output tensor of the irregular operator;

[0040] In response to the type of the irregular operator being a data-independent operator, splitting the input tensor so as to process each input data in the input tensor in parallel through the data-independent operator.

[0041] In a possible implementation, determining at least one task execution scheme according to at least one of the shared inputs and a plurality of specialized computation graphs corresponding to each of the subgraphs includes:

[0042] Grouping the plurality of user requests according to at least one of the shared inputs to obtain at least one task partitioning scheme, each of the task partitioning schemes including at least one user request group, including user requests in a user request group where the number of user requests is greater than 1 having a shared input;

[0043] For each of the task partitioning schemes, determining a scheme input tensor whose redundant attribute is redundant according to the shared input in each of the user request groups, and determining a scheme input tensor whose redundant attribute is non-redundant according to other initial data;

[0044] According to the attribute signature of the specialized computation graph corresponding to each of the subgraphs and the redundant attributes of the input tensor of the scheme, the target specialized computation graph corresponding to each of the subgraphs is selected in turn in the execution order to generate the corresponding candidate execution scheme;

[0045] According to the multiple candidate execution schemes corresponding to each of the task partitioning schemes, a plurality of candidate execution schemes corresponding to an optimal task partitioning scheme is selected as the task execution scheme.

[0046] In a possible implementation, the similarity optimization of the task processing calculation graph according to each of the task execution schemes to obtain an optimized processing calculation graph for executing the corresponding user request includes:

[0047] For each of the task execution schemes, the subgraph in the task processing computation graph is replaced according to the target specialized computation graph corresponding to each of the subgraphs, so as to obtain an optimized processing computation graph for executing the corresponding user request.

[0048] According to a second aspect of the present disclosure, a similarity calculation optimization device for a tensor program is provided, the device comprising:

[0049] A request acquisition module, used for acquiring a plurality of user requests including at least one initial data having a corresponding position;

[0050] A shared input determination module, used to determine that the initial data located at the same position in at least two of the user requests is a shared input;

[0051] A subgraph specialization module, used to determine multiple subgraphs obtained by splitting the task processing calculation graph, and multiple specialized calculation graphs corresponding to each of the subgraphs;

[0052] A solution generation module, used to determine at least one task execution solution according to at least one of the shared inputs and a plurality of specialized computation graphs corresponding to each of the subgraphs, each of the task execution solutions being used to execute at least one user request, including a target specialized computation graph corresponding to each of the subgraphs;

[0053] The calculation graph optimization module is used to perform similarity optimization on the task processing calculation graph according to each task execution scheme to obtain an optimized processing calculation graph for executing the corresponding user request.

[0054] In a possible implementation, the task processing computation graph includes a plurality of operators, and an input tensor and an output tensor of each of the operators, the input tensor includes at least one input data to be processed by the operator, the output tensor includes output data after each input data in the input tensor is calculated by the operator, and the subgraph specialization module is further used to:

[0055] By performing consistency analysis on the task computation graph, at least one operator with the same optimization enabling condition is clustered to obtain a corresponding subgraph;

[0056] Specializing the subgraph according to the input tensor of each subgraph to obtain at least one corresponding candidate computation graph, each of the candidate computation graphs having a corresponding attribute signature, and the attribute signature is used to characterize whether there is redundancy in each of the input tensors corresponding to the candidate computation graph;

[0057] The input tensors and output tensors of the operators in each candidate computation graph are format converted according to the corresponding attribute signatures to obtain the corresponding specialized computation graph.

[0058] In a possible implementation, the subgraph specialization module is further used to:

[0059] Determining a plurality of attribute signatures according to the number of each of the subgraph input tensors;

[0060] Specializing each of the subgraphs to obtain a computational graph to be screened corresponding to each of the attribute signatures;

[0061] The computation graph to be screened corresponding to each of the subgraphs is screened according to a preset computation graph screening rule to obtain at least one corresponding candidate computation graph.

[0062] In a possible implementation, the computation graph screening rule includes at least one of the following:

[0063] Deleting the computation graph to be screened that conflicts with the attribute signature;

[0064] In response to the existence of an inclusion relationship between the two to-be-screened computation graphs, deleting the included to-be-screened computation graph;

[0065] Delete all computational graphs to be filtered that have redundant input tensors.

[0066] In a possible implementation, the subgraph specialization module is further used to:

[0067] For each of the candidate computation graphs, performing redundant propagation calculations on each operator included therein according to the corresponding attribute signature, to obtain redundant attributes of each operator input tensor and output tensor;

[0068] According to the redundant attributes of the input tensor and output tensor of each operator, the input tensor and output tensor of the operator are format converted to obtain a corresponding specialized calculation graph.

[0069] In a possible implementation, the subgraph specialization module is further used to:

[0070] Determine a redundancy propagation function for each operator, wherein the redundancy propagation function is used to determine the redundant attributes of the output tensor after the calculation based on the redundant attributes of the input tensor before the calculation;

[0071] For each of the candidate computation graphs, determining redundant attributes of the input tensor of the first operator therein according to the corresponding attribute signature;

[0072] Starting from the first operator in the candidate computation graph, the redundant attributes of the input tensor and the output tensor of each of the operators are calculated in turn according to the redundant attributes of the input tensor and the redundant propagation function.

[0073] In a possible implementation manner, the format conversion includes:

[0074] In response to the redundant attributes of the input tensor and the output tensor of the operator being redundant, dimension reduction processing is performed on the input tensor and the output tensor.

[0075] In a possible implementation, the task processing computation graph includes a plurality of operators and an input tensor of each of the operators, and the subgraph specialization module is further used to:

[0076] For each of the specialized computation graphs, when the number of input tensors of the operator is greater than 1 and there are at least two input tensors with different shapes, determining that the operator is an irregular operator;

[0077] The irregular operators are batch optimized to obtain an optimized specialized computation graph.

[0078] In a possible implementation, the subgraph specialization module is further used to:

[0079] Determining the type of each of the irregular operators;

[0080] Corresponding batch optimization is performed according to the type of the irregular operator to obtain an optimized specialized computation graph.

[0081] In a possible implementation, the subgraph specialization module is further used to:

[0082] In response to the type of the irregular operator being a data sharing operator, corresponding shape conversion operators are added before and after the irregular operator according to the shape of the input tensor, respectively, for converting the input tensor of the irregular operator into a regular input tensor, and performing reverse conversion on the output tensor of the irregular operator;

[0083] In response to the type of the irregular operator being a data-independent operator, splitting the input tensor so as to process each input data in the input tensor in parallel through the data-independent operator.

[0084] In a possible implementation, the solution generation module is further used to:

[0085] Grouping the plurality of user requests according to at least one of the shared inputs to obtain at least one task partitioning scheme, each of the task partitioning schemes including at least one user request group, including user requests in a user request group where the number of user requests is greater than 1 having a shared input;

[0086] For each of the task partitioning schemes, determining a scheme input tensor whose redundant attribute is redundant according to the shared input in each of the user request groups, and determining a scheme input tensor whose redundant attribute is non-redundant according to other initial data;

[0087] According to the attribute signature of the specialized computation graph corresponding to each of the subgraphs and the redundant attributes of the input tensor of the scheme, the target specialized computation graph corresponding to each of the subgraphs is selected in turn in the execution order to generate the corresponding candidate execution scheme;

[0088] According to the multiple candidate execution schemes corresponding to each of the task partitioning schemes, a plurality of candidate execution schemes corresponding to an optimal task partitioning scheme is selected as the task execution scheme.

[0089] In a possible implementation, the computation graph optimization module is further used to:

[0090] For each of the task execution schemes, the subgraph in the task processing computation graph is replaced according to the target specialized computation graph corresponding to each of the subgraphs, so as to obtain an optimized processing computation graph for executing the corresponding user request.

[0091] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to implement the above method when executing the instructions stored in the memory.

[0092] According to a fourth aspect of the present disclosure, a non-volatile computer-readable storage medium is provided, on which computer program instructions are stored, wherein the computer program instructions implement the above method when executed by a processor.

[0093] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above method.

[0094] In an embodiment of the present disclosure, multiple user requests including at least one initial data are obtained, and the initial data included in at least two user requests is determined to be a shared input. At least one task execution plan is determined based on the shared input, multiple subgraphs obtained by splitting the task processing calculation graph, and multiple specialized calculation graphs corresponding to each subgraph, each task execution plan is used to execute at least one user request, including a target specialized calculation graph corresponding to each subgraph. Then, the task processing calculation graph is similarity optimized according to each task execution plan to obtain an optimized processing calculation graph for executing the corresponding user request. After receiving the user request, the present disclosure automatically identifies the shared input in the data information to obtain redundancy, and then selects the specialized calculation graphs corresponding to the multiple subgraphs in the task calculation graph through redundancy, and formulates an adaptive and efficient task execution plan to automatically optimize the task calculation graph.

[0095] Further features and aspects of the present disclosure will become apparent from the following detailed description of exemplary embodiments with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0096] The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate exemplary embodiments, features, and aspects of the disclosure and, together with the description, serve to explain the principles of the disclosure.

[0097] Figure 1 A flowchart showing a similarity calculation optimization method of a tensor program according to an embodiment of the present disclosure;

[0098] Figure 2 A schematic diagram showing a process of determining a specialized computation graph according to an embodiment of the present disclosure;

[0099] Figure 3 A schematic diagram showing a redundancy propagation calculation process according to an embodiment of the present disclosure;

[0100] Figure 4 A schematic diagram showing a batch optimization process according to an embodiment of the present disclosure;

[0101] Figure 5 A schematic diagram showing an optimization processing calculation graph according to an embodiment of the present disclosure;

[0102] Figure 6 A schematic diagram showing a similarity calculation optimization device for a tensor program according to an embodiment of the present disclosure;

[0103] Figure 7 A schematic diagram of an electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION

[0104] Various exemplary embodiments, features and aspects of the present disclosure will be described in detail below with reference to the accompanying drawings. The same reference numerals in the accompanying drawings represent elements with the same or similar functions. Although various aspects of the embodiments are shown in the accompanying drawings, the drawings are not necessarily drawn to scale unless otherwise specified.

[0105] The word “exemplary” is used exclusively herein to mean “serving as an example, example, or illustration.” Any embodiment described herein as “exemplary” is not necessarily to be construed as preferred or advantageous over other embodiments.

[0106] In addition, in order to better illustrate the present disclosure, numerous specific details are given in the following specific embodiments. It should be understood by those skilled in the art that the present disclosure can also be implemented without certain specific details. In some examples, methods, means, components and circuits well known to those skilled in the art are not described in detail in order to highlight the subject matter of the present disclosure.

[0107] The similarity calculation optimization method of the tensor program of the embodiment of the present disclosure can be executed by an electronic device such as a terminal device or a server. Among them, the terminal device can be any fixed or mobile terminal such as a user equipment (User Equipment, UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (Personal Digital Assistant, PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. The server can be a single server or a server cluster composed of multiple servers. Any electronic device can implement the similarity calculation optimization method of the tensor program of the embodiment of the present disclosure by a processor calling a computer-readable instruction stored in a memory.

[0108] Figure 1 A flowchart of a similarity calculation optimization method for a tensor program according to an embodiment of the present disclosure is shown. Figure 1 As shown, the similarity calculation optimization method of the tensor program of the embodiment of the present disclosure may include the following steps S10-S50.

[0109] Step S10: Obtain multiple user requests.

[0110] In a possible implementation, multiple user requests are obtained by an electronic device in a receiving manner, and each user request includes at least one initial data. The multiple initial data included in each user request may have corresponding positions in the user request, and the electronic device may execute each user request by calculating the initial data included therein, and the electronic device performs different calculations on the initial data at different positions. The number of initial data included in each user request and the execution method corresponding to the same position are the same, that is, when executing each user request, the same calculation needs to be performed on the initial data at the same position. Exemplarily, when the electronic device receives three user requests, namely r1(a,x), r2(a,y) and r3(b,x), the initial data included in user request r1 are a and x, the initial data included in user request r2 are a and y, and the initial data included in user request r3 are b and x. When executing user request r1, the electronic device needs to perform calculations based on initial data a and x; when executing user request r2, the electronic device needs to perform calculations based on initial data a and y; when executing user request r3, the electronic device needs to perform calculations based on initial data b and x, wherein the positions of a in r1, a in r2, and b in r3 are the same, and the positions of x in r1, y in r2, and x in r3 are the same.

[0111] Step S20: Determine that the initial data located at the same position in at least two of the user requests is a shared input.

[0112] In a possible implementation, after obtaining multiple user requests, the electronic device compares the initial data included in each user request. When there is an initial data that exists in at least two user requests at the same time and the corresponding positions are the same, the initial data is determined to be the shared input of the multiple user requests including it. Exemplarily, when the electronic device receives three user requests r1(a,x), r2(a,y) and r3(b,x), the electronic device can determine that the initial data a is the shared input of the user request r1 and the user request r2, and the initial data x is the shared input of the user request r1 and the user request r3. When the electronic device receives three user requests r1(a,x), r2(a,y) and r3(b,a), the electronic device can determine that the initial data a is the shared input of the user request r1 and the user request r2. Although the user request r3 also includes the initial data a, the position of the initial data a in the user request r3 is different from that in the user request r1 and the user request r2, so a is not the shared input of the user request r3.

[0113] Optionally, since the electronic device performs the same form of calculation processing on each user request, the electronic device performs the same calculation on the shared input when processing different user requests, which will cause calculation redundancy. For example, when the electronic device receives three user requests, namely r1(a,x), r2(a,y) and r3(b,x), the electronic device needs to perform calculations based on the initial data a and x when executing user request r1, needs to perform calculations based on the initial data a and y when executing user request r2, and needs to perform calculations based on the initial data b and x when executing user request r3. Among them, for the shared input a of user request r1 and user request r2, the same calculation is performed once when executing user request r1 and r2 respectively, and for the shared input x of user request r1 and user request r3, the same calculation is performed once when executing user request r1 and r3 respectively, which will cause redundancy in the calculation process.

[0114] Step S30: determine multiple subgraphs obtained by splitting the task processing computation graph, and multiple specialized computation graphs corresponding to each of the subgraphs.

[0115] In a possible implementation, the electronic device determines a task processing calculation graph for processing each user request, and a plurality of subgraphs obtained by dividing the task processing calculation graph, and a plurality of specialized calculation graphs corresponding to each subgraph. Among them, the task processing calculation graph can be in the form of a data flow graph, including a plurality of operators, and the input tensor and output tensor of each operator. The task processing calculation graph can be divided into a plurality of subgraphs, each of which includes at least one operator executed in sequence by the data processing flow. Each subgraph has a plurality of corresponding specialized calculation graphs, and a specialized calculation graph (Specialized Computational Graph) generally refers to a calculation graph optimized for a specific application or field. The specialized calculation graph in this embodiment is used to optimize the similarity of the task processing calculation graph by replacing the corresponding subgraph, and each specialized calculation graph has a corresponding attribute signature, which is used to characterize whether there is redundancy in each input tensor corresponding to the specialized calculation graph, that is, whether each input tensor in the input specialized calculation graph includes the same input data. Exemplarily, the redundant attribute of each input tensor in the attribute signature can be represented by 0 or 1, 0 represents non-redundancy, and 1 represents redundancy.

[0116] Optionally, the multiple subgraphs of the task processing computation graph in the embodiment of the present disclosure, and the multiple specialized computation graphs corresponding to each subgraph can be predetermined, or determined during the execution of the present solution. At the same time, the multiple subgraphs corresponding to the task processing computation graph and the specialized computation graphs of the subgraphs can be determined by the electronic device executing the embodiment of the present disclosure, or determined by other devices and sent to the current electronic device.

[0117] Furthermore, the process of splitting the task processing computation graph to obtain multiple subgraphs, and further obtaining multiple specialized computation graphs corresponding to the multiple subgraphs in the disclosed embodiment may include clustering at least one operator with the same optimization enabling condition to obtain corresponding subgraphs by performing consistency analysis on the task computation graph. Then, the subgraph is specialized according to the input tensor of each subgraph to obtain at least one corresponding candidate computation graph, each candidate computation graph having a corresponding attribute signature, and the attribute signature is used to characterize whether there is redundancy in each input tensor corresponding to the candidate computation graph. Then, the input tensor of the operator in each candidate computation graph is formatted according to the corresponding attribute signature to obtain the corresponding specialized computation graph.

[0118] Alternatively, directly generating an optimized task processing graph without subgraph splitting may result in an exponential increase in optimization solutions as the number of inputs increases. For example, if each input tensor has only one possible redundant attribute, a task processing graph of n operators will be specialized into 2 n The optimization of task processing computation graphs with dozens of operators is introduced by the execution engine, which introduces unacceptable optimization overhead for the optimization of task processing computation graphs that may have dozens of operators. To solve this problem, we observed that intermediate tensors have interdependencies in their redundant properties. For example, the input tensors of adjacent operators in some execution orders are the same, and the redundant properties of their input tensors and output tensors must be the same. Therefore, many operators in the task processing computation graph share the same optimization enabling condition. Electronic devices can perform consistency analysis on the task computation graph and cluster at least one operator with the same optimization enabling condition to obtain the corresponding subgraph.

[0119] Figure 2 A schematic diagram of a process for determining a specialized computation graph according to an embodiment of the present disclosure is shown. Figure 2 As shown, in order to cluster (split) the operators in the task processing computation graph into subgraphs, it is necessary to infer when each tensor in the task computation graph (including the input tensor and output tensor of each operator) is redundant, and the operators with the same redundant or not input tensor are considered to have the "same optimization enabling conditions" and clustered into a subgraph. Optionally, this problem can be solved by a preset redundancy propagation function. For the input tensors of the initial input task processing computation graph (for example, a tensor composed of the initial data at the same position in at least two user requests), the relationship between the redundant attributes of the current input tensor and the redundant attributes of the input tensors of each operator in the task computation graph can be expressed by maintaining a conditional expression. Figure 2(a) shows a simplified case where the redundant attributes are only for a single dimension. The orange operators a and b are only affected by input A, and if input A is redundant, they generate redundant outputs. The yellow operators c, e, and d are only affected by input B, and if input B is redundant, they generate redundant outputs. Therefore, the optimization enabling condition m(A) is propagated through the a and b operators, and the optimization enabling condition m(B) is propagated through the c, d, and e operators. Among them, m(A) represents the redundant attributes of the input tensor A, and m(B) represents the redundant attributes of the input tensor B. It can be determined that the orange operators a and b are operators with the same optimization enabling conditions, and can be clustered to obtain corresponding subgraphs. The yellow operators c, e, and d are operators with the same optimization enabling conditions, and can be clustered to obtain corresponding subgraphs. For the green operator f, the redundant attributes can only be propagated if both of its input tensors are redundant, so its conditional expression is m(A)∧m(B) (∧ represents logical "and"). For subsequent operators involving the output tensor C, we only need to consider whether m(A) and m(B) are satisfied at the same time, rather than considering the two redundant attributes m(A) and m(B) separately. Therefore, we can also determine that operators g and f have the same optimization enabling conditions, and we can cluster them to obtain the corresponding subgraphs.

[0120] After propagating the conditional expression, such as Figure 2 As shown in (b), operators can be clustered into the same subgraph with commonality if they can be optimized simultaneously. When the input of an operator has different conditional expressions, for example, operator f can be specialized if it satisfies m(a) or m(b), which is different from its subsequent operator. In the process of determining a subgraph, the electronic device does not create an independent subgraph for it separately, which may cause performance degradation due to the overhead of scheduling during service, but merges these operators into their subsequent subgraphs, that is, merges the f operator and the g operator into the same subgraph.

[0121] Furthermore, subgraph specialization is performed according to the input tensor of each subgraph to obtain at least one corresponding candidate computation graph, and each candidate computation graph has a corresponding attribute signature, and the attribute signature is used to characterize whether there is redundancy in each input tensor corresponding to the specialized computation graph. Among them, the disclosed embodiment can first determine multiple attribute signatures according to the number of input tensors of each subgraph. Then, subgraph specialization is performed on each subgraph to obtain a computation graph to be screened corresponding to each attribute signature. The computation graph to be screened corresponding to each subgraph is screened according to the preset computation graph screening rules to obtain at least one corresponding candidate computation graph.

[0122] Optionally, when the number of subgraph input tensors is n, we can determine 2 nattribute signatures. For example, when the input tensor is 1, the two attribute signatures can be determined to be redundant and non-redundant. When the number of subgraph input tensors is 2, the four attribute signatures can be determined to be (redundant, redundant), (redundant, non-redundant), (non-redundant, redundant), and (non-redundant, non-redundant).

[0123] After determining the multiple attribute signatures corresponding to each subgraph, the corresponding subgraph can be specialized based on each attribute signature to obtain a computational graph to be screened that matches each attribute signature of the subgraph. For example, if there is one input to a subgraph, and there are two attribute signatures, redundant and non-redundant, then there are two computational graphs to be screened, one is the "redundant" attribute signature plus the subgraph, and the other is the "non-redundant" attribute signature plus the subgraph. In other words, the computational graph to be screened is a subgraph with attribute labels added, and the subgraphs and their different labels constitute different computational graphs to be screened. However, due to limited performance benefits or the inability to meet the assumed attribute signatures, some computational graphs to be screened obtained by specialization may be unnecessary or impossible. Therefore, unnecessary computational graphs to be screened can be further deleted by screening, and the screening process can be implemented by preset computational graph screening rules. The computational graph screening rules can include three types of screening conditions, namely, deleting computational graphs to be screened that conflict with the attribute signatures, for example Figure 2 In , the attribute signatures of the two inputs of operator e should be either redundant or non-redundant, because they have the same source and are both affected by input B. If one is redundant and the other is not, it is a conflict. When there are two computational graphs to be filtered that have an inclusion relationship, delete the included computational graph to be filtered. For example, Figure 1 The attribute signature is (i1∧i2), to be screened and calculated Figure 2 The attribute signature of is (i1∧i2∧i2), then the calculation to be screened is Figure 2 Calculated to be screened Figure 1 Contains, can delete the calculation to be filtered Figure 2 . And delete all the computational graphs to be filtered that have redundant input tensors.

[0124] Exemplarily, the calculation graph screening rule can delete the corresponding specialized calculation graph to be screened (conflicting condition) through e1∧e2→False, if e1→e2 or e2→e1 (arrows indicate inclusion relationship), then delete e1, e2 and e1∧e2 corresponding specialized calculation graphs to be screened (duplicate condition), and delete e1∧e2→i1∧i2∧···∧in corresponding specialized calculation graph to be screened (completely redundant). Among them, e1 and e2 are the redundant attributes corresponding to the input tensors of the two input calculation graphs to be screened, and i1 and i2 represent the redundant attributes of the input of the entire application.

[0125] In a possible implementation, after the electronic device obtains the candidate computation graph corresponding to each subgraph through the computation graph screening rule, it converts each candidate computation graph into a specialized computation graph by format conversion of the operators and output tensors in the candidate computation graph. For each candidate computation graph, redundant propagation calculation can be performed on each operator included therein according to the corresponding attribute signature to obtain the redundant attributes of each operator input tensor and output tensor. Then, according to the redundant attributes of each operator input tensor and output tensor, the input tensor and output tensor of the operator are format converted to obtain the corresponding specialized computation graph.

[0126] Optionally, operators of tensors can propagate redundancy in a variety of ways. For example, whether the length and width dimensions in the result of matrix multiplication are redundant depends on the redundant properties of a single input tensor, while the batch dimension of the output is redundant only when the batch dimensions of both input tensors are redundant. Therefore, a set of redundant propagation functions for operators of operators can be used to perform redundant propagation calculations on each operator to obtain the redundant properties of each operator's input tensor and output tensor. The process can be to first determine the redundant propagation function of each operator, which is used to determine the redundant properties of the output tensor after calculation based on the redundant properties of the input tensor before calculation. Then, for each candidate computation graph, the redundant properties of the input tensor of the first operator are determined according to the corresponding attribute signature. Starting from the first operator in the candidate computation graph, the redundant properties of the input tensor and output tensor of each operator are calculated in turn according to the redundant properties of the input tensor and the redundant propagation function.

[0127] Figure 3 A schematic diagram of a redundant propagation calculation process according to an embodiment of the present disclosure is shown. Figure 3 As shown in the table above, the redundant propagation function determined for operators corresponding to different operators is shown below, and the redundant attributes of each operator input tensor and output tensor are calculated according to the redundant propagation function. Among them, the redundant attributes can be obtained by the formula OUT b =Φ(IN b )IN b =∪ p∈pred(b) (OUT p ) is calculated. Where Φ is the redundant propagation function, IN b and OUT b are the redundant attributes of the input tensors and output tensors of a basic block b consisting of at least one operator (which can be determined based on the attribute signature corresponding to the candidate computation graph), and pred(b) is the set of predecessor blocks of basic block b (e.g., Figure 3The predecessor block of block2 is block1), and p is a block in the set. For a basic block in the candidate computation graph, the redundant attributes of its input tensors are propagated to each operator in the basic block. The operator of each operator uses the corresponding redundancy propagation function to infer the redundancy of the output. The output tensor of the basic block is then forwarded to other basic blocks. In the case where the input tensor has multiple sources, the redundant attributes of each dimension are combined separately.

[0128] Optionally, when there are operators of circular calculations in the current candidate calculation graph, the embodiment of the present disclosure also performs redundant propagation calculations in a circular iterative manner. The previous calculation results can be updated through the subsequent calculation results. When the redundant attributes of the output tensor obtained after two consecutive rounds of calculations are the same, it can be determined that there is no further update in a single iteration, and the redundant attributes of the current output tensor are determined to be the corresponding redundant attributes.

[0129] Further, after obtaining the redundant attributes of the input tensor and output tensor of each operator in the candidate calculation graph, the input tensor and output tensor of the operator can be format converted according to the redundant attributes of the input tensor and output tensor of each operator to obtain the corresponding specialized calculation graph. Due to the complexity of the tensor operator, eliminating the redundancy therein is different from the classic scalar operator, wherein the optional redundancy elimination rule can be to reduce the dimension of the input tensor and the output tensor when the redundant attributes of the input tensor and the output tensor of the operator are redundant. With the help of the redundant elimination rule, the embodiment of the present disclosure can eliminate two types of redundancy caused by data. The first type is redundant calculation, which generates repeated outputs with redundant dimensions. The embodiment of the present disclosure can convert the original input tensor calculation into a non-redundant form by dimensionality reduction, and compress the redundant dimensions of the input tensor and the output tensor into one dimension. For complex situations, such as redundant input channels in convolution, additional calculations can also be performed by other preset application elimination rules (such as summing along the weight channel) to achieve equivalent results. At the same time, by recording redundant attributes, the embodiments of the present disclosure can restore the original shapes of these format-converted tensors by broadcasting data, eliminating as much redundancy as possible until necessary, while maintaining the equivalence of the results. The second type of redundancy eliminated by the embodiments of the present disclosure is redundant memory access, which can be merged through redundant tensor data to avoid the overhead caused by multiple memory accesses of the same data.

[0130] In one possible implementation, since different input tensors of a specialized computation graph may have different shapes, in order to further improve service efficiency, the disclosed embodiment may also divide each operator in the task processing computation graph into regular operators and irregular operators according to whether the shapes of the input tensors are the same, so as to regularize the irregular operators. Among them, for each specialized computation graph, when the number of input tensors of the operator is greater than 1 and there are at least two input tensors of different shapes, it can be determined that the operator is an irregular operator. The irregular operators are further batch optimized to obtain an optimized specialized computation graph.

[0131] Optionally, the process of batch optimization may include determining the type of each irregular operator, and then performing corresponding batch optimization according to the type of the irregular operator to obtain an optimized specialized computational graph. Among them, the types of irregular operators may include data-sharing operators and data-independent operators. Data-sharing operators are operators whose input tensors are shared between requests in a batch, and data-independent operators are operators whose input tensors are not shared between requests in a batch. For example, layers involving weights, such as convolutional layers and linear layers, belong to the category of data-sharing operators. This is because the weight tensors of these layers are shared between different requests within a batch. On the other hand, data-independent operators include operators that do not involve weights, such as transposition and reduction operators.

[0132] Optionally, a technique called irregular operator regularization is introduced in the disclosed embodiment to achieve the reuse of existing highly optimized computing kernels in irregular computing. This technique opportunistically converts irregular operators into standard operators and irregular data-independent operators. Since batch data-independent operators can be decomposed into computing task blocks that can be processed in parallel, the kernels of these operators are relatively easy to implement. Therefore, it is possible to benefit from the high efficiency of the kernel library with only a small amount of effort.

[0133] Specifically, for irregular operators of data sharing operator type, corresponding shape conversion operators can be added before and after the irregular operator according to the shape of the input tensor, which are used to convert the input tensor of the irregular operator into a regular input tensor, that is, to make the input tensor shape the same, and to reversely convert the output tensor of the irregular operator. That is, the irregular dimension can be converted into a regular dimension by fusing it with the batch dimension.

[0134] Figure 4 FIG. 1 is a schematic diagram showing a batch optimization process according to an embodiment of the present disclosure. Figure 4 As shown, for example, in the linear layer in 4(a), we can transpose and reshape the irregular input tensor to separate its batch dimension b and irregular dimension into a regular (non-irregular) dimension. This process is similar to Figure 4 (b) is the height of the two matrices connected. Therefore, existing well-optimized matrix multiplication operators can be used to perform irregular calculations. Optionally, the disclosed embodiment may adopt a set of preset equivalent graph transformation rules to regularize irregular data sharing operators. The rule set stores rules involving dimension fusion and arrangement, making it possible to convert irregular dimensions into regular dimensions. Based on the rule set, each available conversion rule can be applied to the irregular data sharing operator, and then evaluate whether the irregular dimension is successfully converted to a regular dimension. For multiple candidate conversions, they can be analyzed using typical input tensors and the best result can be selected.

[0135] Since the regularization process changes the data layout of the input tensor to match the existing well-optimized kernel, the layout transformation kernel may introduce large overhead. The disclosed embodiment merges two adjacent layout transformations together to minimize this overhead. This method can effectively reduce the need for separate transformations and eliminate layout transformations after reverse transformation. This approach mitigates potential performance impacts and achieves more efficient computing.

[0136] Furthermore, in batch processing, requests in data-independent operators do not share data, they can be decomposed into separate requests, and can be efficiently executed in an awkwardly parallel manner. Therefore, for irregular operators of type data-independent operators, the disclosed embodiment can split the input tensor to process each input data in the input tensor in parallel through data-independent operators. In addition, since each separate request is a regular operator, the existing optimization strategy and the computing microkernel of the corresponding operator can be directly reused.

[0137] Step S40: determine at least one task execution plan based on at least one of the shared inputs and a plurality of specialized computation graphs corresponding to each of the subgraphs.

[0138] In a possible implementation, after determining the shared inputs in the multiple user requests and the specialized computation graphs of the multiple subgraphs in the task processing computation graph, the electronic device can determine at least one task execution scheme according to at least one shared input and the multiple specialized computation graphs corresponding to each subgraph. Each task execution scheme is used to execute at least one user request, including the target specialized computation graph corresponding to each subgraph.

[0139] Specifically, the process of determining the task execution plan may include grouping multiple user requests according to at least one shared input to obtain at least one task partitioning plan. Each task partitioning plan includes at least one user request group, including user requests in a user request group in which the number of user requests is greater than 1 and has shared inputs. For each task partitioning plan, a redundant scheme input tensor with a redundant attribute is determined based on the shared input in each user request group, and other initial data determines a non-redundant scheme input tensor with a redundant attribute. According to the attribute signature of the specialized computational graph corresponding to each subgraph and the redundant attributes of the scheme input tensor, the target specialized computational graph corresponding to each subgraph is selected in turn in the execution order to generate the corresponding candidate execution plan. Then, according to the multiple candidate execution plans corresponding to each task partitioning plan, a plurality of candidate execution plans corresponding to an optimal task partitioning plan are selected as the task execution plan.

[0140] Exemplarily, when the electronic device receives three user requests, namely r1(a,x), r2(a,y) and r3(b,x), the electronic device can determine that the initial data a is the shared input of user request r1 and user request r2, and the initial data x is the shared input of user request r1 and user request r3. Based on the shared input a and the shared input x, the electronic device can determine that the task partitioning scheme 1 is {user request group 1: user request r1 and user request r2, user request group 2: user request r3}. The task partitioning scheme 2 is {user request group 1: user request r1 and user request r3, user request group 2: user request r2}, and the task partitioning scheme 3 is {user request group 1: user request r1, user request r2 and user request r3}. For user request group 1 in the task partitioning scheme 1, the corresponding scheme input tensors can be (a, a) and (x, y), where the input data in the scheme input tensor (a, a) is the same, so the redundancy attribute is redundant. The input data in the scheme input tensor (x, y) is different, so the redundant attribute is not redundant.

[0141] Further, after the electronic device determines the scheme input tensor corresponding to each user request group, the target specialized computation graph corresponding to each subgraph can be selected in turn according to the attribute signature of the specialized computation graph corresponding to each subgraph and the redundant attribute of the scheme input tensor in the execution order to generate the corresponding candidate execution scheme. For example, for the user request group 1 in the task partitioning scheme 1 in the above example, the input tensor is one redundant and one non-redundant, then the specialized computation graph with the attribute signature of (redundant, non-redundant) is selected as the target specialized computation graph. According to the execution order of the subgraph, the above selection is performed for each subgraph in turn, and each target specialized computation graph is obtained to constitute a candidate execution scheme. Each user request group corresponds to a candidate execution scheme. If there are multiple user request groups in a task partitioning scheme, multiple candidate execution schemes are corresponding. Among them, it can also be selected whether to perform batch optimization on the target specialized computation graph according to the shape of the input tensors of different schemes. After obtaining multiple candidate execution schemes corresponding to each task partitioning scheme, the embodiment of the present disclosure can use dynamic programming based on user requests and corresponding data fingerprints to search for multiple candidate execution schemes corresponding to an optimal task partitioning scheme as a task execution scheme. Each user request group can correspond to a task execution scheme. The "optimal" standard can be selected as needed, and this application does not impose any restrictions on this.

[0142] Step S50: perform similarity optimization on the task processing calculation graph according to each of the task execution schemes to obtain an optimized processing calculation graph for executing the corresponding user request.

[0143] In a possible implementation, after obtaining multiple task execution schemes for processing at least one user request, the electronic device can replace the subgraph in the task processing calculation graph according to the target specialized calculation graph corresponding to each subgraph for each task execution scheme, and obtain an optimized processing calculation graph for executing the corresponding user request. At the same time, it is also possible to determine whether the operator in each task processing calculation graph needs to be batch optimized according to the shape of the tensor input in different schemes, and batch optimize the target specialized calculation graph according to the operator type if batch optimization is required.

[0144] Figure 5 FIG. 1 is a schematic diagram showing an optimization processing calculation graph according to an embodiment of the present disclosure. Figure 5 As shown, the bold data is the shared data between different user requests. The electronic device can optimize the task processing calculation graph based on the shared data in the manner of the embodiment of the present disclosure to obtain an optimized processing calculation graph that can process user requests in batches.

[0145] Based on the above technical features, the disclosed embodiment fully combines the calculation process in the task processing calculation graph with the information of the data in the user request that needs to be calculated, automatically locates the redundancy that may exist when processing user requests in parallel, and generates a series of optimized processing calculation graphs after eliminating redundancy optimization to optimize the entire task processing process. At the same time, by performing detailed attribute analysis on the tensors involved in the calculation, an adaptive and efficient execution plan is formulated to schedule user requests with different similarities and generated shapes to achieve better service efficiency.

[0146] Figure 6 A schematic diagram of a similarity calculation optimization device for a tensor program according to an embodiment of the present disclosure is shown. Figure 6 As shown, the similarity calculation optimization device of the tensor program of the embodiment of the present disclosure may include:

[0147] A request acquisition module 60, configured to acquire a plurality of user requests including at least one initial data having a corresponding position;

[0148] A shared input determination module 61, configured to determine that initial data located at the same position in at least two of the user requests is a shared input;

[0149] A subgraph specialization module 62, used to determine a plurality of subgraphs obtained by splitting the task processing computation graph, and a plurality of specialized computation graphs corresponding to each of the subgraphs;

[0150] A solution generation module 63 is used to determine at least one task execution solution according to at least one of the shared inputs and a plurality of specialized computation graphs corresponding to each of the subgraphs, each of the task execution solutions being used to execute at least one user request, including a target specialized computation graph corresponding to each of the subgraphs;

[0151] The calculation graph optimization module 64 is used to perform similarity optimization on the task processing calculation graph according to each of the task execution schemes to obtain an optimized processing calculation graph for executing the corresponding user request.

[0152] In a possible implementation, the task processing computation graph includes a plurality of operators, and an input tensor and an output tensor of each of the operators, the input tensor includes at least one input data to be processed by the operator, and the output tensor includes output data after each input data in the input tensor is calculated by the operator, and the subgraph specialization module 62 is further used to:

[0153] By performing consistency analysis on the task computation graph, at least one operator with the same optimization enabling condition is clustered to obtain a corresponding subgraph;

[0154] Specializing the subgraph according to the input tensor of each subgraph to obtain at least one corresponding candidate computation graph, each of the candidate computation graphs having a corresponding attribute signature, and the attribute signature is used to characterize whether there is redundancy in each of the input tensors corresponding to the candidate computation graph;

[0155] The input tensors and output tensors of the operators in each candidate computation graph are format converted according to the corresponding attribute signatures to obtain the corresponding specialized computation graph.

[0156] In a possible implementation, the subgraph specialization module 62 is further configured to:

[0157] Determining a plurality of attribute signatures according to the number of each of the subgraph input tensors;

[0158] Specializing each of the subgraphs to obtain a computational graph to be screened corresponding to each of the attribute signatures;

[0159] The computation graph to be screened corresponding to each of the subgraphs is screened according to a preset computation graph screening rule to obtain at least one corresponding candidate computation graph.

[0160] In a possible implementation, the computation graph screening rule includes at least one of the following:

[0161] Deleting the computation graph to be screened that conflicts with the attribute signature;

[0162] In response to the existence of an inclusion relationship between the two to-be-screened computation graphs, deleting the included to-be-screened computation graph;

[0163] Delete all computational graphs to be filtered that have redundant input tensors.

[0164] In a possible implementation, the subgraph specialization module 62 is further configured to:

[0165] For each of the candidate computation graphs, performing redundant propagation calculations on each operator included therein according to the corresponding attribute signature, to obtain redundant attributes of each operator input tensor and output tensor;

[0166] According to the redundant attributes of the input tensor and output tensor of each operator, the input tensor and output tensor of the operator are format converted to obtain a corresponding specialized calculation graph.

[0167] In a possible implementation, the subgraph specialization module 62 is further configured to:

[0168] Determine a redundancy propagation function for each operator, wherein the redundancy propagation function is used to determine the redundant attributes of the output tensor after the calculation based on the redundant attributes of the input tensor before the calculation;

[0169] For each of the candidate computation graphs, determining redundant attributes of the input tensor of the first operator therein according to the corresponding attribute signature;

[0170] Starting from the first operator in the candidate computation graph, the redundant attributes of the input tensor and the output tensor of each of the operators are calculated in turn according to the redundant attributes of the input tensor and the redundant propagation function.

[0171] In a possible implementation manner, the format conversion includes:

[0172] In response to the redundant attributes of the input tensor and the output tensor of the operator being redundant, dimension reduction processing is performed on the input tensor and the output tensor.

[0173] In a possible implementation, the task processing computation graph includes a plurality of operators and an input tensor of each of the operators, and the subgraph specialization module 62 is further used to:

[0174] For each of the specialized computation graphs, when the number of input tensors of the operator is greater than 1 and there are at least two input tensors with different shapes, determining that the operator is an irregular operator;

[0175] The irregular operators are batch optimized to obtain an optimized specialized computation graph.

[0176] In a possible implementation, the subgraph specialization module 62 is further configured to:

[0177] Determining the type of each of the irregular operators;

[0178] Corresponding batch optimization is performed according to the type of the irregular operator to obtain an optimized specialized computation graph.

[0179] In a possible implementation, the subgraph specialization module 62 is further configured to:

[0180] In response to the type of the irregular operator being a data sharing operator, corresponding shape conversion operators are added before and after the irregular operator according to the shape of the input tensor, respectively, for converting the input tensor of the irregular operator into a regular input tensor, and performing reverse conversion on the output tensor of the irregular operator;

[0181] In response to the type of the irregular operator being a data-independent operator, splitting the input tensor so as to process each input data in the input tensor in parallel through the data-independent operator.

[0182] In a possible implementation, the solution generating module 63 is further configured to:

[0183] Grouping the plurality of user requests according to at least one of the shared inputs to obtain at least one task partitioning scheme, each of the task partitioning schemes including at least one user request group, including user requests in a user request group where the number of user requests is greater than 1 having a shared input;

[0184] For each of the task partitioning schemes, determining a scheme input tensor whose redundant attribute is redundant according to the shared input in each of the user request groups, and determining a scheme input tensor whose redundant attribute is non-redundant according to other initial data;

[0185] According to the attribute signature of the specialized computation graph corresponding to each of the subgraphs and the redundant attributes of the input tensor of the scheme, the target specialized computation graph corresponding to each of the subgraphs is selected in turn in the execution order to generate the corresponding candidate execution scheme;

[0186] According to the multiple candidate execution schemes corresponding to each of the task partitioning schemes, a plurality of candidate execution schemes corresponding to an optimal task partitioning scheme is selected as the task execution scheme.

[0187] In a possible implementation, the computation graph optimization module 64 is further configured to:

[0188] For each of the task execution schemes, the subgraph in the task processing computation graph is replaced according to the target specialized computation graph corresponding to each of the subgraphs, so as to obtain an optimized processing computation graph for executing the corresponding user request.

[0189] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.

[0190] The embodiment of the present disclosure also provides a computer-readable storage medium on which computer program instructions are stored, and the computer program instructions implement the above method when executed by a processor. The computer-readable storage medium can be a volatile or non-volatile computer-readable storage medium.

[0191] An embodiment of the present disclosure further proposes an electronic device, comprising: a processor; and a memory for storing instructions executable by the processor; wherein the processor is configured to implement the above method when executing the instructions stored in the memory.

[0192] The embodiments of the present disclosure also provide a computer program product, including a computer-readable code, or a non-volatile computer-readable storage medium carrying the computer-readable code. When the computer-readable code runs in a processor of an electronic device, the processor in the electronic device executes the above method.

[0193] Figure 7 1 is a schematic diagram showing an electronic device 1900 according to an embodiment of the present disclosure. For example, the electronic device 1900 may be provided as a server or a terminal device. Figure 7 , the electronic device 1900 includes a processing component 1922, which further includes one or more processors, and a memory resource represented by a memory 1932 for storing instructions executable by the processing component 1922, such as an application. The application stored in the memory 1932 may include one or more modules, each corresponding to a set of instructions. In addition, the processing component 1922 is configured to execute instructions to perform the above method.

[0194] The electronic device 1900 may also include a power supply component 1926 configured to perform power management of the electronic device 1900, a wired or wireless network interface 1950 configured to connect the electronic device 1900 to a network, and an input / output interface 1958 (I / O interface). The electronic device 1900 may operate based on an operating system stored in the memory 1932, such as Windows Server 2003. TM , Mac OS X TM , Unix TM ,Linux TM , FreeBSD TM or similar.

[0195] In an exemplary embodiment, a non-volatile computer-readable storage medium is also provided, such as a memory 1932 including computer program instructions, which can be executed by the processing component 1922 of the electronic device 1900 to perform the above method.

[0196] The present disclosure may be a system, a method and / or a computer program product. The computer program product may include a computer-readable storage medium carrying computer-readable program instructions for causing a processor to implement various aspects of the present disclosure.

[0197] A computer-readable storage medium may be a tangible device that can hold and store instructions used by an instruction execution device. A computer-readable storage medium may be, for example, but not limited to, an electrical storage device, a magnetic storage device, an optical storage device, an electromagnetic storage device, a semiconductor storage device, or any suitable combination of the foregoing. More specific examples of computer-readable storage media (a non-exhaustive list) include: 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), a static random access memory (SRAM), a portable compact disk read-only memory (CD-ROM), a digital versatile disk (DVD), a memory stick, a floppy disk, a mechanical encoding device, such as a punch card or a raised structure in a groove on which instructions are stored, and any suitable combination of the foregoing. As used herein, a computer-readable storage medium is not to be interpreted as a transient signal per se, such as a radio wave or other freely propagating electromagnetic wave, an electromagnetic wave propagating through a waveguide or other transmission medium (e.g., a light pulse through a fiber optic cable), or an electrical signal transmitted through a wire.

[0198] The computer-readable program instructions described herein can be downloaded from a computer-readable storage medium to each computing / processing device, or downloaded to an external computer or external storage device via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network. The network can include copper transmission cables, optical fiber transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. The network adapter card or network interface in each computing / processing device receives the computer-readable program instructions from the network and forwards the computer-readable program instructions for storage in the computer-readable storage medium in each computing / processing device.

[0199] The computer program instructions for performing the operation of the present disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages, such as Smalltalk, C++, etc., and conventional procedural programming languages, such as "C" language or similar programming languages. Computer-readable program instructions may be executed completely on a user's computer, partially on a user's computer, as an independent software package, partially on a user's computer, partially on a remote computer, or completely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer via any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., using an Internet service provider to connect via the Internet). In some embodiments, an electronic circuit, such as a programmable logic circuit, a field programmable gate array (FPGA), or a programmable logic array (PLA), may be customized by utilizing the state information of the computer-readable program instructions, and the electronic circuit may execute the computer-readable program instructions, thereby realizing various aspects of the present disclosure.

[0200] Various aspects of the present disclosure are described herein with reference to the flowcharts and / or block diagrams of the methods, devices (systems) and computer program products according to the embodiments of the present disclosure. It should be understood that each box in the flowchart and / or block diagram and the combination of each box in the flowchart and / or block diagram can be implemented by computer-readable program instructions.

[0201] These computer-readable program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, thereby producing a machine, so that when these instructions are executed by the processor of the computer or other programmable data processing device, a device that implements the functions / actions specified in one or more boxes in the flowchart and / or block diagram is generated. These computer-readable program instructions can also be stored in a computer-readable storage medium, and these instructions cause the computer, programmable data processing device, and / or other equipment to work in a specific manner, so that the computer-readable medium storing the instructions includes a manufactured product, which includes instructions for implementing various aspects of the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0202] Computer-readable program instructions may also be loaded onto a computer, other programmable data processing apparatus, or other device so that a series of operating steps are performed on the computer, other programmable data processing apparatus, or other device to produce a computer-implemented process, thereby causing the instructions executed on the computer, other programmable data processing apparatus, or other device to implement the functions / actions specified in one or more boxes in the flowchart and / or block diagram.

[0203] The flow chart and block diagram in the accompanying drawings show the possible architecture, function and operation of the system, method and computer program product according to multiple embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a part of a module, program segment or instruction, and a part of the module, program segment or instruction includes one or more executable instructions for realizing the specified logical function. In some alternative implementations, the function marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two continuous square boxes can actually be executed substantially in parallel, and they can sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs the specified function or action, or can be implemented with a combination of special hardware and computer instructions.

[0204] The embodiments of the present disclosure have been described above, and the above description is exemplary, not exhaustive, and is not limited to the disclosed embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the described embodiments. The selection of terms used herein is intended to best explain the principles of the embodiments, practical applications, or technical improvements in the market, or to enable other persons of ordinary skill in the art to understand the embodiments disclosed herein.

Claims

1. A similarity calculation optimization method for tensor programs, characterized in that: The method comprises: Acquire multiple user requests, each user request includes at least one initial data, and each initial data has a corresponding position in the user request; Determining initial data located at the same position in at least two of the user requests as shared input; Determine multiple subgraphs obtained by splitting the task processing computation graph, and multiple specialized computation graphs corresponding to each of the subgraphs; Determine at least one task execution scheme according to at least one of the shared inputs and a plurality of specialized computation graphs corresponding to each of the subgraphs, wherein each of the task execution schemes is used to execute at least one user request, and includes a target specialized computation graph corresponding to each of the subgraphs; The task processing calculation graph is similarly optimized according to each task execution scheme to obtain an optimized processing calculation graph for executing the corresponding user request.

2. The method according to claim 1, characterized in that The task processing calculation graph includes multiple operators, and input tensors and output tensors of each operator, the input tensor includes at least one input data that needs to be processed by the operator, and the output tensor includes output data after each input data in the input tensor is calculated by the operator, the multiple subgraphs obtained by determining the split task processing calculation graph, and the multiple specialized calculation graphs corresponding to each subgraph include: By performing consistency analysis on the task computation graph, at least one operator with the same optimization enabling condition is clustered to obtain a corresponding subgraph; Specializing the subgraph according to the input tensor of each subgraph to obtain at least one corresponding candidate computation graph, each of the candidate computation graphs having a corresponding attribute signature, and the attribute signature is used to characterize whether there is redundancy in each of the input tensors corresponding to the candidate computation graph; The input tensors and output tensors of the operators in each candidate computation graph are format converted according to the corresponding attribute signatures to obtain the corresponding specialized computation graph.

3. The method according to claim 2, characterized in that The subgraph specialization is performed according to the input tensor of each subgraph to obtain at least one corresponding candidate computation graph, including: Determining a plurality of attribute signatures according to the number of each of the subgraph input tensors; Specializing each of the subgraphs to obtain a computational graph to be screened corresponding to each of the attribute signatures; The computation graph to be screened corresponding to each of the subgraphs is screened according to a preset computation graph screening rule to obtain at least one corresponding candidate computation graph.

4. The method according to claim 3, characterized in that The calculation graph screening rule includes at least one of the following: Deleting the computation graph to be screened that conflicts with the attribute signature; In response to the existence of an inclusion relationship between the two to-be-screened computation graphs, deleting the included to-be-screened computation graph; Delete all computational graphs to be filtered that have redundant input tensors.

5. The method according to any one of claims 2 to 4, characterized in that: The format conversion of the input tensor and the output tensor of each operator in the candidate computation graph is performed according to the corresponding attribute signature to obtain the corresponding specialized computation graph, including: For each of the candidate computation graphs, performing redundant propagation calculations on each operator included therein according to the corresponding attribute signature, to obtain redundant attributes of each operator input tensor and output tensor; According to the redundant attributes of the input tensor and output tensor of each operator, the input tensor and output tensor of the operator are format converted to obtain a corresponding specialized calculation graph.

6. The method according to claim 5, characterized in that For each candidate computation graph, redundant propagation calculation is performed on each operator included therein according to the corresponding attribute signature to obtain redundant attributes of each operator input tensor and output tensor, including: Determine a redundancy propagation function for each operator, wherein the redundancy propagation function is used to determine the redundant attributes of the output tensor after the calculation based on the redundant attributes of the input tensor before the calculation; For each of the candidate computation graphs, determining redundant attributes of the input tensor of the first operator therein according to the corresponding attribute signature; Starting from the first operator in the candidate computation graph, the redundant attributes of the input tensor and the output tensor of each of the operators are calculated in turn according to the redundant attributes of the input tensor and the redundant propagation function.

7. The method according to claim 5 or 6, characterized in that: The format conversion includes: In response to the redundant attributes of the input tensor and the output tensor of the operator being redundant, dimension reduction processing is performed on the input tensor and the output tensor.

8. The method according to any one of claims 2 to 7, characterized in that: The task processing computation graph includes a plurality of operators and an input tensor of each operator, the determination of splitting the task processing computation graph to obtain a plurality of subgraphs, and a plurality of specialized computation graphs corresponding to each of the subgraphs, and further includes: For each of the specialized computation graphs, when the number of input tensors of the operator is greater than 1 and there are at least two input tensors with different shapes, determining that the operator is an irregular operator; The irregular operators are batch optimized to obtain an optimized specialized computation graph.

9. The method according to claim 8, characterized in that The batch optimization of the irregular operators to obtain an optimized specialized computation graph includes: Determining the type of each of the irregular operators; Corresponding batch optimization is performed according to the type of the irregular operator to obtain an optimized specialized computation graph.

10. The method according to claim 9, characterized in that The performing corresponding batch processing optimization according to the type of the irregular operator includes: In response to the type of the irregular operator being a data sharing operator, corresponding shape conversion operators are added before and after the irregular operator according to the shape of the input tensor, respectively, for converting the input tensor of the irregular operator into a regular input tensor, and performing reverse conversion on the output tensor of the irregular operator; In response to the type of the irregular operator being a data-independent operator, splitting the input tensor to process each input data in the input tensor in parallel through the data-independent operator.

11. The method according to any one of claims 1 to 10, characterized in that: Determining at least one task execution scheme according to at least one of the shared inputs and a plurality of specialized computation graphs corresponding to each of the subgraphs includes: Grouping the plurality of user requests according to at least one of the shared inputs to obtain at least one task partitioning scheme, each of the task partitioning schemes including at least one user request group, including user requests in a user request group where the number of user requests is greater than 1 having a shared input; For each of the task partitioning schemes, determining a scheme input tensor whose redundant attribute is redundant according to the shared input in each of the user request groups, and determining a scheme input tensor whose redundant attribute is non-redundant according to other initial data; According to the attribute signature of the specialized computation graph corresponding to each of the subgraphs and the redundant attributes of the input tensor of the scheme, the target specialized computation graph corresponding to each of the subgraphs is selected in turn in the execution order to generate the corresponding candidate execution scheme; According to the multiple candidate execution schemes corresponding to each of the task partitioning schemes, a plurality of candidate execution schemes corresponding to an optimal task partitioning scheme is selected as the task execution scheme.

12. The method according to any one of claims 1 to 11, characterized in that: The similarity optimization of the task processing calculation graph according to each of the task execution schemes to obtain an optimized processing calculation graph for executing the corresponding user request includes: For each of the task execution schemes, the subgraph in the task processing computation graph is replaced according to the target specialized computation graph corresponding to each of the subgraphs, so as to obtain an optimized processing computation graph for executing the corresponding user request.

13. A similarity calculation optimization device for a tensor program, characterized in that: The device comprises: A request acquisition module, used for acquiring a plurality of user requests including at least one initial data having a corresponding position; A shared input determination module, used to determine that the initial data located at the same position in at least two of the user requests is a shared input; A subgraph specialization module, used to determine multiple subgraphs obtained by splitting the task processing calculation graph, and multiple specialized calculation graphs corresponding to each of the subgraphs; A solution generation module, used to determine at least one task execution solution according to at least one of the shared inputs and a plurality of specialized computation graphs corresponding to each of the subgraphs, each of the task execution solutions being used to execute at least one user request, including a target specialized computation graph corresponding to each of the subgraphs; The calculation graph optimization module is used to perform similarity optimization on the task processing calculation graph according to each task execution scheme to obtain an optimized processing calculation graph for executing the corresponding user request.

14. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; Wherein, the processor is configured to implement the method described in any one of claims 1 to 12 when executing the instructions stored in the memory.

15. A non-volatile computer-readable storage medium having computer program instructions stored thereon, characterized in that: When the computer program instructions are executed by a processor, the method according to any one of claims 1 to 12 is implemented.

Citation Information

Patent Citations

  • GPU graph neural network optimization method and device

    CN112767230A

  • Deep learning framework module design and construction method for large-format remote sensing image

    CN113869172A

  • Optimization method for executing deep learning tasks in distributed mode and distributed system

    CN115543639A

Cited By

  • Construction method of cross-platform high-performance tensor program generation model and related device

    CN121278388A