WO2022142662A1 - Operator mapping method and apparatus for computational graph - Google Patents

Operator mapping method and apparatus for computational graph Download PDF

Info

Publication number
WO2022142662A1
WO2022142662A1 PCT/CN2021/127123 CN2021127123W WO2022142662A1 WO 2022142662 A1 WO2022142662 A1 WO 2022142662A1 CN 2021127123 W CN2021127123 W CN 2021127123W WO 2022142662 A1 WO2022142662 A1 WO 2022142662A1
Authority
WO
WIPO (PCT)
Prior art keywords
operators
operator
matrix
graph
partition
Prior art date
Application number
PCT/CN2021/127123
Other languages
French (fr)
Chinese (zh)
Inventor
吴艺晖
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2022142662A1 publication Critical patent/WO2022142662A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F18/00Pattern recognition
    • G06F18/20Analysing
    • G06F18/22Matching criteria, e.g. proximity measures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/74Image or video pattern matching; Proximity measures in feature spaces
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V10/00Arrangements for image or video recognition or understanding
    • G06V10/70Arrangements for image or video recognition or understanding using pattern recognition or machine learning
    • G06V10/82Arrangements for image or video recognition or understanding using pattern recognition or machine learning using neural networks

Definitions

  • the present application relates to the technical field of artificial intelligence, and in particular, to a method and device for operator mapping of a computational graph.
  • Computational graph as an intermediate representation between the front-end and back-end of a deep learning framework, can bring good interactivity.
  • Computational graph is a way of expressing data functions through graph theory language.
  • nodes are connected by edges, nodes represent things, and the edges connecting two nodes represent the relationship between two things, while nodes in computational graphs represent nerves.
  • the input data or operator in the network, the edge connecting two nodes represents the input-output relationship between the two points, etc.
  • the deep learning framework can convert the script of the model written according to the deep learning framework into a computational graph, and the operators in the model can be converted into a corresponding node in the computational graph.
  • the generated computational graphs are often different.
  • migrating models between different deep learning frameworks for example, when migrating a model from TensorFlow (TF for short) to MindSpore (MS for short)
  • the structure and computation graph of the models corresponding to different deep learning frameworks before and after the migration The operators may be different. Therefore, it may be necessary to compare the structure of the calculation graph corresponding to the model before and after the migration, and whether the operators in the calculation graph are consistent.
  • the structure of the computational graph is complex and there are many operators.
  • the number of operators in the computational graph of ResNet50 (Residual Network) in the deep learning framework TensorFlow is 2000
  • the computational graph in the deep learning framework MindSpore The number of subs is 5000. It is very necessary to design an automatic calculation graph comparison tool to realize the comparison of two calculation graphs and the operator relationship mapping.
  • a method and device for operator mapping of computational graphs are proposed, which can support operator mapping between computational graphs with similar structures, and can be applied to scenarios where a deep learning framework performs model migration.
  • embodiments of the present application provide an operator mapping method for a computation graph, for performing operator mapping on operators in a first computation graph and a second computation graph, the first computation graph and all
  • the second calculation graph is the calculation graph of the same neural network model, and the operator mapping method includes:
  • the operator mapping method of the embodiments provided by the present application constructs footprint matrices of two computation graphs, where the footprint matrix is a matrix representing the topological relationship between operators in the computation graph.
  • the first matrix may be iteratively calculated according to footprint matrices corresponding to the two calculation graphs, and the first matrix may indicate the similarity of the topological relationship of the two calculation graphs. After the iteration is stopped, the preferred one or more mapping relationships can be determined according to the footprint matrix. Therefore, the operator mapping method provided by the present application can support operator mapping between calculation graphs with similar structures, and can be applied to a scenario where a deep learning framework performs model migration.
  • the processor calculates the first matrix according to the first footprint matrix and the second footprint matrix, including: the processor calculates the first matrix according to a plurality of first eigenvectors and a plurality of second eigenvectors, The first matrix is obtained, wherein each of the first eigenvectors corresponds to an operator in the first calculation graph, and the operator corresponding to each of the first eigenvectors and the first eigenvector is in the The corresponding row vectors in the first footprint matrix are related to column vectors, each of the second eigenvectors corresponds to an operator in the second calculation graph, and each of the second eigenvectors is related to the second eigenvectors The row vector corresponding to the corresponding operator in the second footprint matrix is related to the column vector, and the first eigenvector and the second eigenvector are used to calculate the operator corresponding to the first eigenvector and the The similarity of the topological relationship between the operators corresponding
  • the value of the element of the first matrix represents the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located similarity of the topological relationship of the elements, wherein the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located are respectively the operator in the first calculation graph and the operator in the second calculation graph operator.
  • the eigenvectors of the operator are constructed by using the corresponding row and column vectors in the footprint matrix corresponding to the operator in the calculation graph, and the topological relationship characteristics of the operator in the calculation graph are extracted.
  • the similarity of the topological relationship of the operator is calculated according to the eigenvector of the operator, and the similarity of the topological relationship of the operator of the first calculation graph and the operator of the second calculation graph forms a similarity matrix, and the similarity matrix is used to measure the two calculations.
  • the similarity of the topological relationships of the graphs are constructed by using the corresponding row and column vectors in the footprint matrix corresponding to the operator in the calculation graph, and the topological relationship characteristics of the operator in the calculation graph are extracted.
  • the similarity of the topological relationship of the operator is calculated according to the eigenvector of the operator, and the similarity of the topological relationship of the operator of the first calculation graph and the operator of the second calculation graph forms a similarity matrix, and the similarity matrix is used to measure the two calculations.
  • the first footprint matrix, the adjusted first footprint matrix and the third The operator corresponding to the row at the same position and the operator corresponding to the column at the same position of the two footprint matrix are of the same type, and the dimensions of the tensors output by the operators are the same. That is, the first footprint matrix and the second footprint matrix have the same type.
  • the operator corresponding to the row at the same position and the operator corresponding to the column at the same position of the footprint matrix are of the same type, and the dimension of the tensor output by the operator is the same, and the adjusted first footprint matrix and the second footprint matrix are the same.
  • the operator corresponding to the row of the position, the operator corresponding to the column of the same position are of the same type, and the dimension of the tensor output by the operator is the same.
  • the dimensions of the tensors output by the operators are the same, that is, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns in the same position are functionally the same.
  • Combine the similarity matrix to measure the similarity of the topological relationship between operators. According to the operator mapping method provided by the present application, the mapping relationship between two operators can be reflected in terms of functions and topological relationships, thereby ensuring the correctness of the mapping result.
  • the operators in the first computation graph and the second computation graph are divided into Belonging to multiple first partitions, the same first partition has the same operator type, and the dimensions of the tensors output by the operators are the same, and each first partition may include at least part of the first computation graph and/or the second computation graph Operators; some operators in the first calculation graph and the second calculation graph belong to a second partition, and the types of operators in the second partition are different and/or the dimensions of the tensors output by the operators are different; The operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are in the same first partition, and the operators corresponding to the columns in the same position are in the same first partition; and, belong to the same first partition.
  • the operators of the first computation graph are arranged in consecutive rows or columns in the first footprint matrix, and the operators of the second computation graph belonging to the same first partition are arranged in consecutive rows or columns in the second footprint
  • the operators in the first calculation graph and the second calculation graph are homogeneously partitioned, and when adjusting the order of the rows and columns in the first footprint matrix, adjust the The order of the rows and columns corresponding to the operators located in the same homogeneous partition can make the iterative process converge more quickly and speed up the mapping process.
  • the corresponding operator similarity can be obtained by setting mixed partitions for classification and participating in the iterative calculation process.
  • mapping suggestions can be output according to the calculated similarity. Therefore, it can support operator mapping between computational graphs with similar structures, and can also support one-to-many or many-to-many mapping, which can be applied to scenarios where deep learning frameworks perform model migration.
  • the homogeneous depths of the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are the same,
  • the homogeneity depths of the operators corresponding to the columns in the same position are the same, and the corresponding rows or columns of the operators of the first calculation graph belonging to the same first partition in the first footprint matrix are the same as those of the operators.
  • the rows or columns corresponding to the operators of the second computation graph of the same first partition in the second footprint matrix are sorted according to the homogeneous depth of the operators; wherein, the homogeneous depth is: The maximum number of operators before the operator that have the same type as the operator and the same output tensor dimension among all the branches to which the operator belongs in the calculation graph.
  • the operators in the homogeneous partition are sorted according to the homogeneous depth, and the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph are respectively determined according to the homogeneous partition. Since it is more likely that there is a mapping relationship between operators with the same homogeneous depth, the process of calculating the similarity matrix according to the above-mentioned embodiments of the present application can quickly converge, and the mapping relationship between operators can be determined more quickly. the process of mapping. In addition, by distinguishing operators with the same attributes by homogeneous depth, the unreliability of distinguishing operators with the same attributes by the names of the operators can be avoided.
  • the first partition also includes pseudo operators; wherein, the pseudo operators are operators that do not have operator types and operands; if the first calculation graph in the first partition The number of operators is less than the number of operators in the second computation graph in the first partition, and the pseudo operator in the first footprint matrix corresponding to the row or column is located in the first After the row or column corresponding to the operator belonging to the first partition in the graph; if the number of operators in the second computation graph in the first partition is less than the number of operators in the first partition The number of operators in the calculation graph.
  • the row or column corresponding to the pseudo operator in the second footprint matrix is located after the row or column corresponding to the operator belonging to the first partition in the second calculation graph.
  • the second partition also includes the pseudo-operator; if the number of operators in the first computation graph in the second partition is less than that in the second partition The number of operators in the second computation graph in the pseudo-operator, the rows and columns corresponding to the pseudo-operators in the first footprint matrix correspond to the operators belonging to the second partition in the first computation graph Rows and columns are randomly ordered in the same way; if the number of operators in the second computation graph in the second partition is less than the number of operators in the second computation graph in the second partition The number of operators, the rows and columns corresponding to the pseudo operators in the second footprint matrix and the rows and columns corresponding to the operators belonging to the second partition in the second calculation graph are randomly ordered, and the rows and columns Random sorting works the same way.
  • the operator mapping method provided by the present application can be applied to the scenarios of frameworks or migration models between systems using different computational graph representations.
  • the row and column values of the first footprint matrix are adjusted according to the first matrix.
  • the order includes: adjusting the order of the rows and columns corresponding to the operators located in the same first partition in the first footprint matrix according to the first matrix.
  • the first footprint matrix belonging to the same first partition and when the stopping condition is reached There is a mapping relationship between the operators of the first calculation graph and the operators of the second calculation graph that have the same position as the corresponding row or column in the second footprint matrix; the first calculation belonging to the second partition
  • the first calculation belonging to the second partition There is a mapping relationship between the operators of the graph and multiple operators of the second calculation graph belonging to the second partition, wherein the multiple operators of the second calculation graph belonging to the second partition are: reaching the stop condition In the first matrix when , among the values of the elements corresponding to the operators of the first computation graph belonging to the second partition, the operators of the second computation graph corresponding to the largest values.
  • mapping method of the above-mentioned embodiments of the present application it is possible to support operator mapping between computational graphs with similar structures, support one-to-one, one-to-many, and many-to-many mappings, and can be applied to scenarios where deep learning frameworks perform model migration middle.
  • the stopping condition is that the number of times of repeatedly calculating the first matrix is greater than first threshold.
  • embodiments of the present application provide an operator mapping device for a computation graph, which is used to perform operator mapping on operators in a first computation graph and a second computation graph, the first computation graph and all
  • the second calculation graph is the calculation graph of the same neural network model
  • the operator mapping device includes: an iterative module for repeating the following process based on the first footprint matrix and the second footprint matrix until the stopping condition is reached:
  • the first footprint matrix and the second footprint matrix calculate a first matrix, and adjust the order of rows and columns in the first footprint matrix according to the first matrix, and according to the adjusted first footprint matrix and all recompute the first matrix with the second footprint matrix; wherein, the first footprint matrix indicates the topological relationship between the operators of the first computation graph, and the second footprint matrix indicates the second computation graph
  • the topological relationship between the operators of The footprint matrix and the second footprint matrix are used to obtain the operators corresponding to each of the multiple operators in the first calculation graph in the second calculation graph.
  • the operator mapping apparatus of the embodiments provided by the present application constructs footprint matrices of two computation graphs, where the footprint matrix is a matrix representing the topological relationship between operators in the computation graph.
  • the first matrix can be iteratively calculated according to the footprint matrices corresponding to the two computation graphs, and the first matrix indicates the similarity of the topological relationship between the two computation graphs. After the iteration is stopped, one or more preferred mapping relationships can be determined according to the footprint matrix. Therefore, the operator mapping method provided by the present application can support operator mapping between calculation graphs with similar structures, and can be applied to a scenario where a deep learning framework performs model migration.
  • the iteration module includes:
  • the calculation unit is configured to obtain the first matrix according to a plurality of first eigenvectors and a plurality of second eigenvectors, wherein each of the first eigenvectors corresponds to an operator in the first calculation graph, and each Each of the first eigenvectors and the operators corresponding to the first eigenvectors are related to the row vectors and column vectors in the first footprint matrix, and each of the second eigenvectors corresponds to the second calculation graph
  • the operators in , each of the second eigenvectors and the operators corresponding to the second eigenvectors are related to the row vectors and column vectors in the second footprint matrix, and the first eigenvectors and the The second eigenvector is used to calculate the similarity of the topological relationship between the operator corresponding to the first eigenvector and the operator corresponding to the second eigenvector.
  • the value of the element of the first matrix represents the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located similarity of the topological relationship of the elements, wherein the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located are respectively the operator in the first calculation graph and the operator in the second calculation graph operator.
  • the eigenvectors of the operator are constructed by using the corresponding row and column vectors in the footprint matrix corresponding to the operator in the calculation graph, and the topological relationship characteristics of the operator in the calculation graph are extracted.
  • the similarity of the topological relationship of the operator is calculated according to the eigenvector of the operator, and the similarity of the topological relationship of the operator of the first calculation graph and the operator of the second calculation graph forms a similarity matrix, and the similarity matrix is used to measure the two calculations.
  • the similarity of the topological relationships of the graphs are constructed by using the corresponding row and column vectors in the footprint matrix corresponding to the operator in the calculation graph, and the topological relationship characteristics of the operator in the calculation graph are extracted.
  • the similarity of the topological relationship of the operator is calculated according to the eigenvector of the operator, and the similarity of the topological relationship of the operator of the first calculation graph and the operator of the second calculation graph forms a similarity matrix, and the similarity matrix is used to measure the two calculations.
  • the first footprint matrix, the adjusted first footprint matrix and the third The operator corresponding to the row at the same position and the operator corresponding to the column at the same position of the two footprint matrix are of the same type, and the dimensions of the tensors output by the operators are the same. That is, the first footprint matrix and the second footprint matrix have the same type.
  • the operator corresponding to the row at the same position and the operator corresponding to the column at the same position of the footprint matrix are of the same type, and the dimension of the tensor output by the operator is the same, and the adjusted first footprint matrix and the second footprint matrix are the same.
  • the operator corresponding to the row of the position, the operator corresponding to the column of the same position are of the same type, and the dimension of the tensor output by the operator is the same.
  • the dimensions of the tensors output by the operators are the same, that is, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns in the same position are functionally the same.
  • Combine the similarity matrix to measure the similarity of the topological relationship between operators. According to the operator mapping device provided by the present application, the mapping relationship between two operators can be reflected in terms of functions and topological relationships, thereby ensuring the correctness of the mapping result.
  • the operators in the first computation graph and the second computation graph are divided into Belonging to multiple first partitions, the same first partition has the same operator type, and the dimensions of the tensors output by the operators are the same, and each first partition may include at least part of the first computation graph and/or the second computation graph An operator, where some operators in the first calculation graph and the second calculation graph belong to a second partition, and the types of operators in the second partition are different and/or the dimensions of the tensors output by the operators are different; The operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are in the same first partition, and the operators corresponding to the columns in the same position are in the same first partition; and, belong to the same first partition.
  • the operators of the first computation graph are arranged in consecutive rows or columns in the first footprint matrix, and the operators of the second computation graph belonging to the same first partition are arranged in consecutive rows or columns in the second
  • the operators in the first calculation graph and the second calculation graph are homogeneously partitioned, and when adjusting the order of the rows and columns in the first footprint matrix, adjust the The order of the rows and columns corresponding to the operators of the homogeneous partition can make the iterative process converge more quickly and speed up the mapping process.
  • the corresponding operator similarity can be obtained by setting mixed partitions for classification and participating in the iterative calculation process.
  • mapping suggestions can be output according to the calculated similarity. Therefore, it can support operator mapping between computational graphs with similar structures, and can also support one-to-many or many-to-many mapping, which can be applied to scenarios where deep learning frameworks perform model migration.
  • the homogeneous depths of the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are the same,
  • the homogeneity depths of the operators corresponding to the columns in the same position are the same, and the corresponding rows or columns of the operators of the first calculation graph belonging to the same first partition in the first footprint matrix are the same as those of the operators.
  • the rows or columns corresponding to the operators of the second computation graph of the same first partition in the second footprint matrix are sorted according to the homogeneous depth of the operators; wherein, the homogeneous depth is: The maximum number of operators before the operator that have the same type as the operator and the same output tensor dimension among all the branches to which the operator belongs in the calculation graph.
  • the operators in the homogeneous partition are sorted according to the homogeneous depth, and the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph are respectively determined according to the homogeneous partition. Since it is more likely that there is a mapping relationship between operators with the same homogeneous depth, the process of calculating the similarity matrix according to the above-mentioned embodiments of the present application can quickly converge, and the mapping relationship between operators can be determined more quickly. the process of mapping. In addition, by distinguishing operators with the same attributes by homogeneous depth, the unreliability of distinguishing operators with the same attributes by the names of the operators can be avoided.
  • a sixth possible implementation manner if the number of operators of the first computation graph in the first partition and the number of operators of the second computation graph The number of operators is different, and the first partition also includes pseudo operators; wherein, the pseudo operators are operators that do not have operator types and operands; if the first calculation graph in the first partition The number of operators is less than the number of operators in the second computation graph in the first partition, and the pseudo operator in the first footprint matrix corresponding to the row or column is located in the first After the row or column corresponding to the operator belonging to the first partition in the graph; if the number of operators in the second computation graph in the first partition is less than the number of operators in the first partition The number of operators in the calculation graph. The row or column corresponding to the pseudo operator in the second footprint matrix is located after the row or column corresponding to the operator belonging to the first partition in the second calculation graph.
  • the second partition also includes the pseudo-operator; if the number of operators in the first computation graph in the second partition is less than that in the second partition The number of operators in the second computation graph in the pseudo-operator, the rows and columns corresponding to the pseudo-operators in the first footprint matrix correspond to the operators belonging to the second partition in the first computation graph Rows and columns are randomly ordered in the same way; if the number of operators in the second computation graph in the second partition is less than the number of operators in the second computation graph in the second partition The number of operators, the rows and columns corresponding to the pseudo operators in the second footprint matrix and the rows and columns corresponding to the operators belonging to the second partition in the second calculation graph are randomly ordered, and the rows and columns Random sorting works the same way.
  • the operator mapping method provided by the present application can be applied to the scenarios of frameworks or migration models between systems using different computational graph representations.
  • the iteration module further includes: an adjustment unit, configured to adjust according to the first matrix The order of the rows and columns corresponding to the operators located in the same first partition in the first footprint matrix.
  • the first footprint matrix belonging to the same first partition and when the stopping condition is reached There is a mapping relationship between the operators of the first calculation graph and the operators of the second calculation graph that have the same position as the corresponding row or column in the second footprint matrix; the first calculation belonging to the second partition
  • the first calculation belonging to the second partition There is a mapping relationship between the operators of the graph and multiple operators of the second calculation graph belonging to the second partition, wherein the multiple operators of the second calculation graph belonging to the second partition are: reaching the stop condition In the first matrix when , among the values of the elements corresponding to the operators of the first computation graph belonging to the second partition, the operators of the second computation graph corresponding to the largest values.
  • mapping method of the above-mentioned embodiments of the present application it is possible to support operator mapping between computational graphs with similar structures, support one-to-one, one-to-many, and many-to-many mappings, and can be applied to scenarios where deep learning frameworks perform model migration middle.
  • the stopping condition is that the number of times of repeatedly calculating the first matrix is greater than or equal to first threshold.
  • an embodiment of the present application provides an operator mapping apparatus for a computational graph, including:
  • a processor ; a memory for storing processor-executable instructions; wherein the processor is configured to implement the first aspect or one or more of various possible implementations of the first aspect when executing the instructions A kind of operator mapping method.
  • embodiments of the present application provide a non-volatile computer-readable storage medium on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the above-mentioned first aspect or the first aspect is implemented One or more of the multiple possible implementations of the operator mapping method.
  • an embodiment of the present application provides a terminal device, where the terminal device can execute the first aspect or one or more of the operator mapping methods in multiple possible implementations of the first aspect.
  • embodiments of the present application provide a computer program product, comprising computer-readable codes, or a non-volatile computer-readable storage medium carrying computer-readable codes, when the computer-readable codes are stored in an electronic
  • the processor in the electronic device executes the first aspect or one or more of the operator mapping methods in the multiple possible implementation manners of the first aspect.
  • FIG. 1a and 1b respectively show schematic diagrams of application scenarios according to an embodiment of the present application.
  • FIG. 2 shows a block diagram of a device for performing an operator mapping method of a computational graph according to an embodiment of the present application.
  • FIG. 3 shows a flowchart of an operator mapping method for a computation graph according to an embodiment of the present application.
  • FIG. 4 shows a schematic diagram of a calculation graph according to an example of the present application.
  • Fig. 5a shows a flowchart of a process of calculating similarity according to an embodiment of the present application.
  • FIG. 5b shows a flowchart of a method for adjusting the order of rows and columns of a footprint matrix according to an embodiment of the present application.
  • FIG. 6 shows a flowchart of the method of step S300 according to an embodiment of the present application.
  • FIG. 7 shows a schematic diagram of a homogeneous partition according to an embodiment of the present application.
  • FIG. 8 and FIG. 9 respectively show schematic diagrams of determining the homogeneity depth of a homogeneity operator according to an embodiment of the present application.
  • FIG. 10 shows an example of an insertion pseudo-operator according to an embodiment of the present application.
  • FIG. 11 shows a flowchart of an operator mapping method according to an embodiment of the present application.
  • FIG. 12 shows a schematic diagram of determining the shortest distance according to an embodiment of the present application.
  • FIG. 13 shows a schematic diagram of adjusting the footprint matrix according to an embodiment of the present application.
  • FIG. 14 shows a schematic diagram of the effect of iterative calculation according to an embodiment of the present application.
  • FIG. 15 shows a schematic diagram of the effect of iterative calculation according to an embodiment of the present application.
  • FIG. 16 shows a block diagram of an operator mapping apparatus for a computation graph according to an embodiment of the present application.
  • FIG. 17 shows a block diagram of an operator mapping apparatus according to an embodiment of the present application.
  • An operation unit in a calculation graph An operator is used to complete a type of operation logic.
  • a calculation graph can include many different types of operators, and the type of the operator refers to the type of operation logic that the operator can perform.
  • an operator may indicate a type of basic operation logic, and the basic operation logic cannot be split, such as Add (add), Multi (multiply), and so on.
  • An operator can also indicate a kind of complex operation logic, and the complex operation logic can be expressed as a combination of a group of basic operation logic.
  • complex operation logic can be indicated by a variety of operators, and each operator corresponds to a different combination of basic operation logic.
  • These various operators have the same function.
  • a group of operators composed of these various operators can be regarded as an operator that completes the above-mentioned complex operation logic.
  • a group of operators composed of these various operators may be another operator.
  • a tensor is a description of the characteristics of a piece of data stored, and a tensor records information such as the shape and type of the data.
  • a tensor may be understood as tensor data or an operand of an operator, which may include input operands and output operands of an operator in a neural network, and may also include feature tensor data and the like.
  • Taking the artificial intelligence deep learning framework TensorFlow as an example generally use rank (rank), shape (shape) and dimension (dimension number) to describe the dimension of the tensor.
  • Numerical file A file that records the output tensor data (operands) of the deep learning model operator during the operation.
  • Operator mapping In two computation graphs corresponding to the same model, an operator in one computation graph has an equivalent correspondence in function and topology with an operator in the other computation graph. That is to say, A functionally and topologically equivalent correspondence between two operators in two computation graphs.
  • homogeneous operator Two operators with identical properties are called homogeneous operators.
  • the properties of an operator can refer to the type of the operator and the dimension of the output tensor. If the two operators are of the same type and the dimensions of the tensors output by the two operators are the same, then the two operators are homogeneous operators. That is, two homogenous operators are functionally identical.
  • the operator referred to by a homogeneous operator may refer to an operator that completes basic, non-splittable operation logic, or may be a group of operators that complete an operation that can be split. It is divided into complex functions of basic operation logic. This group of operators and another group perform the same function. If the dimensions of the final output tensors of the two groups of operators are also the same, then these two groups of operators are also homogeneous operators.
  • Cosine similarity the cosine value of the angle between two non-zero vectors. The larger the cosine value, the closer and similar the two vectors are.
  • the value in the similarity matrix represents the similarity between the operator corresponding to the row where the value is located and the operator corresponding to the column where the value is located.
  • These two operators can be operators in different calculation graphs.
  • the operator corresponding to the row where the value is located is an operator of a calculation graph
  • the operator corresponding to the column where the operator is located is an operator of another calculation graph.
  • the similarity between two operators can be measured by the above cosine similarity.
  • a value in the matrix can represent the cosine similarity between the operator corresponding to the row where the value is located and the operator corresponding to the column where the value is located.
  • Cosine similarity of operators the cosine value of the angle between the eigenvectors corresponding to two operators.
  • the eigenvector of the operator a vector indicating the topological relationship between the operator and other operators in the computational graph.
  • Element Each number in the matrix is called an element.
  • Calculate the distance from one operator to another in the graph Calculate the length of the path from the node corresponding to one operator to the node corresponding to another operator in the graph.
  • the connection between one node and another node in the computation graph is a reachable path. Since the computation graph is a directed graph, between two directly connected nodes in the computation graph: the path from the parent node to the child node (edge) is reachable, the path length is 1, the child node to the parent node is unreachable, and the length of the path from the child node to the parent node is 0.
  • the length of the path from one node to another in the computation graph is the total length of a reachable path between the two nodes.
  • Calculate the shortest distance from one operator to another in the graph Calculate the shortest length of the path from the node corresponding to one operator to the node corresponding to another operator in the graph.
  • an isomorphic graph algorithm can be used to determine the mapping relationship between nodes of two graphs.
  • the isomorphic graph algorithm is only suitable for the mapping of nodes between completely isomorphic graphs.
  • node mapping cannot be performed, and the isomorphic graph algorithm does not support many-to-many node mapping.
  • the expression of computational graphs is different. Even the same neural network model may correspond to computational graphs of different structures after conversion in different deep learning frameworks. Therefore, the isomorphic graph algorithm cannot be applied to different deep learning frameworks for model transfer scenarios.
  • the present application provides an operator mapping method of a computational graph.
  • the footprint matrix is a matrix representing the topological relationship between the operators of the computational graph.
  • the value of the element is the reciprocal of the shortest distance from the operator corresponding to the row where the element is located to the operator corresponding to the column where the element is located, or the value of the element in the footprint matrix is the operator corresponding to the column where the element is located to the row where the element is located.
  • the reciprocal of the shortest distance of the corresponding operator is the reciprocal of the shortest distance of the corresponding operator.
  • the similarity matrix can be iteratively calculated according to the footprint matrices corresponding to the two calculation graphs, and the similarity matrix indicates the similarity of the topological relationship between the two calculation graphs. After the iteration is stopped, one or more preferred mapping relationships can be determined according to the footprint matrix. Therefore, the operator mapping method provided by the present application can support operator mapping between calculation graphs with similar structures, and can be applied to a scenario where a deep learning framework performs model migration.
  • the operator mapping method of the computational graph in the embodiment of the present application is mainly applied to the computational graph of the neural network, and the neural network may be a neural network model used for image recognition, speech recognition, and the like.
  • the operator mapping method in the embodiment of the present application can be applied to the scenario of performing neural network model migration between different deep learning frameworks, and can also be applied to the scenario of performing neural network model migration between different versions of the same deep learning framework In the scenario of comparing neural networks between different hardware, and in the scenario of comparing the results of training and inference, comparison of design diagrams related to integrated circuits, comparison of calculation diagrams of program codes, and so on.
  • This application does not limit the specific application scenarios, as long as it is a scenario of comparison mapping between two graphs expressed in the form of graphs in graph theory.
  • FIG. 1 a and FIG. 1 b respectively show schematic diagrams of an application scenario according to an embodiment of the present application.
  • FIG. 2 shows a block diagram of a device for performing an operator mapping method of a computational graph according to an embodiment of the present application.
  • Figure 1a shows the application scenario of manual migration.
  • the corresponding calculation diagram 1 and numerical file 1 can be derived from the model script of deep learning framework 1, in which , the numerical file can include data such as the operand Tensor and weight of the operator in the calculation graph.
  • the developer can write the model script of the deep learning framework 2 according to the model script of the deep learning framework 1, and derive the corresponding calculation diagram 2 and the numerical file 2 from the model script of the deep learning framework 2.
  • the device shown in FIG. 2 may be a computer, a server, etc.
  • the device shown in FIG. 2 may include a processor and a memory, wherein the processor may be equipped with an operating system, and the upper layer of the operating system may be installed with calculation graph comparison software.
  • the processor can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), or a central processing unit. It can be a central processor unit (CPU), a network processor (NP), a digital signal processing circuit (DSP), or a microcontroller (MCU) , it can also be a programmable logic device (PLD) or other integrated chips.
  • FPGA field programmable gate array
  • ASIC application specific integrated circuit
  • SoC system on chip
  • CPU central processor unit
  • NP network processor
  • DSP digital signal processing circuit
  • MCU microcontroller
  • PLD programmable logic device
  • the memory can be read-only memory (ROM) or other types of static storage devices that can store static information and instructions, random access memory (RAM) or other types of storage devices that can store information and instructions Dynamic storage device, the memory can also include non-volatile memory (non-volatile memory), such as flash memory (flash memory), hard disk drive (hard disk drive, HDD) or solid-state drive (solid-state drive, SSD); memory Combinations of the above kinds of memories may also be included.
  • non-volatile memory such as flash memory (flash memory), hard disk drive (hard disk drive, HDD) or solid-state drive (solid-state drive, SSD); memory Combinations of the above kinds of memories may also be included.
  • the memory can also be electrically erasable programmable read-only memory (electrically erasable programmable read-only memory, EEPROM), compact disc read-only memory (CD-ROM) or other optical disk storage, optical disk storage (including compressed optical disks) , laser disc, compact disc, digital versatile disc, Blu-ray disc, etc.), magnetic disk storage medium or other magnetic storage device, or any other device capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer Other media, but not limited to this.
  • the memory may exist independently and be connected to the processor through a communication line, such as the hard disk storage device shown in FIG. 2 . Memory can also be integrated with the processor, as shown in Figure 2.
  • the memory provided by the embodiments of the present application may generally be non-volatile.
  • the memory is used to store the computer-executed instructions involved in executing the solution of the present application, and the execution is controlled by the processor.
  • the processor is configured to execute the computer-executed instructions stored in the memory, thereby implementing the method provided by the embodiments of the present application.
  • the calculation graph comparison software can be a set of instructions that integrates the method provided by the present application, and the processing of the input calculation graph by the processor running the instruction can realize the mapping relationship between the operators of the calculation graph to obtain the mapping result, and according to the mapping result , computational graphs, and numerical archives to detect mapping results.
  • the derived calculation diagram 1 and numerical file 1 of the deep learning framework 1, and the calculation diagram 2 and numerical file 2 of the deep learning framework 2 can be input into the processor, and the processor executes the operators of the calculation diagram provided by this application.
  • the mapping method can find out the mapping relationship between the operators in the calculation Figure 1 of the deep learning framework 1 and the calculation Figure 2 of the deep learning framework 2 (the steps shown in the solid line box in Figure 1a are provided by the present application.
  • the operator mapping method of FIG. 1a is realized.
  • the steps shown in the dotted box in Figure 1a are the process of preprocessing to obtain the calculation graph or the process of subsequent adjustment and processing according to the mapping result, which belong to a part of the application scenario of the present application.
  • the dotted box shows steps are not the focus of this application).
  • the processor can compare whether the Tensor corresponding to the operator in the corresponding numerical file 1 and numerical file 2 is consistent according to the mapping relationship, and output the comparison result between the mapping relationship and the numerical file as a comparison report. If the comparison result of the numerical files is inconsistent, or the developer judges that the main structure of the calculation graph is inconsistent according to the mapping relationship, the model script of the deep learning framework 2 can be modified, and then the above process is performed again until the comparison results of the numerical files are consistent and The main structure of the computation graph is consistent.
  • Figure 1b shows the application scenario of automatic migration.
  • the model script of the deep learning framework 1 can be converted into a file in the Open Neural Network Exchange (ONNX, Open Neural Network Exchange) format, which is a file used to represent deep learning models. A standard that enables models to be transferred between different deep learning frameworks.
  • ONNX Open Neural Network Exchange
  • the script conversion tool to convert the file in ONNX format to obtain the model script of the deep learning framework 2.
  • the calculation diagram 1 can be exported, and the calculation diagram 2 can be derived according to the model script of the deep learning framework 2.
  • the calculation diagram 1 and the calculation diagram 2 are input into the device shown in FIG. 2, and the processor executes the application.
  • the operator mapping method can obtain the mapping relationship of the operators in the calculation diagram 1 and the calculation diagram 2, and verify the mapping result according to the mapping relationship.
  • the deep learning framework 1 and the deep learning framework 2 may be any of TensorFlow, PyTorch, MindSpore, and the like. It should be noted that the above FIG. 1a and FIG. 1b are only examples of application scenarios of the present application, and do not limit the present application in any way. The operator mapping methods provided in the embodiments of the present application may also be applied to other application scenarios.
  • FIG. 3 shows a flowchart of an operator mapping method for a computation graph according to an embodiment of the present application.
  • the operator mapping method provided by the present application can be used to perform operator mapping on operators in a first calculation graph and a second calculation graph, wherein the first calculation graph and the second calculation graph are the same neural network
  • the computation graph of the model, the first computation graph and the second computation graph may be computation graphs corresponding to different versions of the same deep learning framework, or may be computation graphs corresponding to different deep learning frameworks, which are not limited in this application.
  • the method steps shown in FIG. 3 may be performed by the processor shown in FIG. 2 .
  • the operator mapping method for a computational graph may include the following steps:
  • Step S300 based on the first footprint matrix and the second footprint matrix, repeat the following process until a stop condition is reached: calculate a first matrix according to the first footprint matrix and the second footprint matrix, and calculate the first matrix according to the first footprint matrix The order of rows and columns in the first footprint matrix is adjusted, and the first matrix is recalculated according to the adjusted first footprint matrix and the second footprint matrix.
  • the first footprint matrix indicates a topological relationship between operators in the first computation graph
  • the second footprint matrix indicates a topological relationship among operators in the second computation graph
  • the first footprint matrix indicates a topological relationship between operators in the second computation graph.
  • the matrix indicates the similarity of the topological relationship of the first computational graph and the second computational graph.
  • Step S301 according to the first footprint matrix and the second footprint matrix when the stopping condition is reached, obtain operators corresponding to each of the multiple operators in the first calculation graph in the second calculation graph.
  • the value of an element of the first footprint matrix may be the reciprocal of the shortest distance from the operator corresponding to the row where the element is located to the operator corresponding to the column where the element is located.
  • the reciprocal of the shortest distance from operator to operator in a computation graph describes the topological relationship between operators in the first computation graph.
  • the value of an element in the second footprint matrix can be the reciprocal of the shortest distance from the operator corresponding to the row where the element is located to the operator corresponding to the column where the element is located.
  • the reciprocal of the shortest distance of the children describes the topological relationship between the operators of the second computational graph.
  • the processor may traverse each operator in the first computation graph and the second computation graph respectively, and determine the shortest distance from each operator to other operators in the computation graph. Specifically, the processor may use the traversed operator as a starting point, perform a depth-first-search (DFS) on the computation graph, and determine the shortest distance from the operator to other operators. Since the first computation graph and the second computation graph are both directed graphs, some operators are unreachable from other operators. In this case, the shortest distance from the operator to the unreachable operator can be determined to be infinite. The reciprocal of the shortest distance from the operator to the unreachable operator is 0, so the corresponding element value of the operator in the footprint matrix is 0.
  • DFS depth-first-search
  • the distance corresponding to the path with the shortest distance is the shortest distance from the operator to the other operator.
  • the reciprocal of the operator's shortest distance to itself is 0.
  • FIG. 4 shows a schematic diagram of a calculation graph according to an example of the present application. Taking FIG. 4 as an example, the process of determining the footprint matrix according to the calculation graph in the embodiment of the present application is described. It is assumed that the calculation graph shown in FIG. 4 is the first calculation graph.
  • the processor performs depth-first traversal with node (operator) A as the starting point, and the shortest distances from operator A to other operators B, C, D, E, and F are obtained as: 1, 2, 3, 2, and 3, respectively.
  • node (operator) A As the starting point, and the shortest distances from operator A to other operators B, C, D, E, and F are obtained as: 1, 2, 3, 2, and 3, respectively.
  • operator E A has two paths to reach operator E, and the distances of the two paths are 2 and 3 respectively. Therefore, the shortest distance from operator A to operator E is 2.
  • the processor performs depth-first traversal with node B as the starting point, and the shortest distances from node B to nodes A, C, D, E, and F can be obtained: ⁇ , ⁇ , ⁇ , 1, and 2, respectively.
  • the processor performs depth-first traversal with node C as the starting point, and the shortest distances from node C to nodes A, B, D, E and F can be obtained: ⁇ , ⁇ , 1, 2, and 3, respectively.
  • the processor performs depth-first traversal with node D as the starting point, and the shortest distances from node D to nodes A, B, C, E, and F can be obtained: ⁇ , ⁇ , ⁇ , 1, and 2, respectively.
  • the processor performs depth-first traversal with node E as the starting point, and the shortest distances from node E to nodes A, B, C, D, and F can be obtained: ⁇ , ⁇ , ⁇ , ⁇ , and 1, respectively.
  • the processor performs depth-first traversal with node F as the starting point, and the shortest distances from node F to nodes A, B, C, D, and E can be obtained as ⁇ , ⁇ , ⁇ , ⁇ , and ⁇ , respectively.
  • the shortest distance from each node to itself is ⁇ .
  • the first footprint matrix of the first calculation graph shown in FIG. 4 may be:
  • the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph can be determined. It should be noted that, what is shown in FIG. 4 is only an example of the present application, and does not limit the present application in any way.
  • the processor when the processor traverses the shortest distance from an operator to other operators, if the shortest distance exceeds the maximum access distance, the processor may set the reciprocal of the shortest distance between the two operators to 0.
  • the maximum access distance may be a distance threshold set to limit the amount of calculation. For example, in the embodiment of the present application, the maximum access distance may be set to 15.
  • the similarity between two non-zero vectors can be measured by cosine similarity.
  • cosine similarity refers to the cosine value of the angle between two non-zero vectors, and the larger the cosine value, the closer the two vectors are pointing.
  • the cosine similarity can be expressed as the following formula (1),
  • the first matrix is used to indicate the similarity of the topological relationship between the first calculation graph and the second calculation graph. Therefore, in the embodiment of the present application, the first matrix may also be called Make a similarity matrix (the similarity matrix of the first calculation graph and the second calculation graph).
  • the value of the element in the first matrix represents the similarity of the topological relationship between the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located.
  • the feature of the operator of the first calculation graph and the feature of the operator of the second calculation graph can be extracted and expressed in the form of a feature vector, according to the feature vector of the operator of the first calculation graph and The eigenvectors of the operators of the second calculation graph are obtained, and the cosine similarity of the operators of the first calculation graph and the operators of the second calculation graph is obtained to describe the difference between the operators of the first calculation graph and the operators of the second calculation graph. similarity of topological relationships.
  • the processor may construct the eigenvectors of the operators in the computation graph according to the footprint matrix, and according to the two operators
  • the cosine similarity of the eigenvectors can measure the similarity of the topological relationship between two operators.
  • calculating the first matrix according to the first footprint matrix and the second footprint matrix in step S300 may include:
  • the first matrix is obtained according to a plurality of first eigenvectors and a plurality of second eigenvectors, wherein each of the first eigenvectors corresponds to an operator in the first calculation graph, and each of the first eigenvectors corresponds to an operator in the first calculation graph.
  • the row vector corresponding to the operator corresponding to the eigenvector and the first eigenvector in the first footprint matrix is related to the column vector, and each of the second eigenvectors corresponds to the operator in the second calculation graph,
  • Each of the second eigenvectors and the operator corresponding to the second eigenvectors are related to row vectors and column vectors in the second footprint matrix, and the first eigenvectors and the second eigenvectors are represented by for calculating the similarity of the topological relationship between the operator corresponding to the first eigenvector and the operator corresponding to the second eigenvector.
  • each operator in the first calculation graph has a first eigenvector corresponding to the operator, and the first eigenvector is related to the row vector and column vector corresponding to the operator in the first footprint matrix.
  • the first calculation The row vector corresponding to the operator of the graph in the first footprint matrix may refer to the row vector of the operator of the first calculation graph in the row corresponding to the first footprint matrix
  • the corresponding column vector may refer to the operator of the first calculation graph
  • Each operator in the second calculation graph has a second eigenvector corresponding to the operator.
  • the second eigenvector is related to the row and column corresponding to the operator in the second footprint matrix.
  • the operator of the second calculation graph is in
  • the corresponding row vector in the second footprint matrix may refer to the row vector of the operator of the second computation graph in the row corresponding to the second footprint matrix
  • the corresponding column vector may refer to the operator of the second computation graph in the second footprint matrix A column vector of corresponding columns.
  • the processor can obtain the first eigenvector of the operator in the first calculation graph according to the row vector and the column vector in the first footprint matrix, and obtain the second calculation graph according to the row vector and column vector in the second footprint matrix
  • the second characteristic of the operators is the same.
  • the first eigenvector and the second eigenvector are used to calculate the similarity of the topological relationship between the operator corresponding to the first eigenvector and the operator corresponding to the second eigenvector
  • the degree may mean that the similarity of the topological relationship between the two operators can be obtained by calculating the cosine similarity of the first eigenvector and the second eigenvector corresponding to the two operators. For example, calculate the cosine similarity of the first eigenvector of operator A in the first calculation graph and the second eigenvector of operator B in the second calculation graph as the similarity of the topological relationship between operator A and operator B Spend.
  • the value of the element of the first matrix represents the similarity of the topological relationship between the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located, wherein the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located are the operators in the first calculation graph and the operators in the second calculation graph, respectively.
  • the operator corresponding to the row of the first matrix may be the operator of the first calculation graph, and the operator corresponding to the column may be the operator of the second calculation graph, or, in another possibility
  • the operator corresponding to the row of the first matrix may be the operator of the second calculation graph, and the operator corresponding to the column may be the operator of the first calculation graph.
  • FIG. 5a shows a flowchart of a process of calculating a first matrix according to an embodiment of the present application.
  • obtaining the first matrix according to multiple first eigenvectors and multiple second eigenvectors may specifically include the following process:
  • Step S3010 determining the first eigenvector of the operator in the first calculation graph according to the first footprint matrix, and determining the second eigenvector of the operator in the second calculation graph according to the second footprint matrix;
  • Step S3011 Calculate the first matrix according to the first eigenvector and the second eigenvector.
  • the processor may concatenate the row vector of the row where the operator is located in the corresponding footprint matrix and the column vector of the column where the operator is located to obtain the feature vector of the operator.
  • the elements in the vector are spliced behind the column vector to obtain the eigenvector of the operator, or the elements in the column vector can be spliced behind the row vector to obtain the eigenvector of the operator.
  • This application does not limit the specific splicing method, but the processor
  • the way of splicing the row vector and the column vector of the operator in the first calculation graph is the same as the way of splicing the row vector and the column vector of the operator in the second calculation graph.
  • the row where operator A is located in the footprint matrix is the first row, and the first row vector is [0,1,1/2,1/3, 1/2,1/3]
  • the column where operator A is located in the footprint matrix is the first column, the first column vector is [0,0,0,0,0,0], and the column vector and row vector are spliced
  • the eigenvectors of operator A can be obtained as [0,0,0,0,0,0,0,0,1,1/2,1/3,1/2,1/3].
  • the cosine similarity between the first eigenvectors of the operators in the first calculation graph and the second eigenvectors of the corresponding operators in the second calculation graph can be calculated according to formula (1). , to get the similarity of the operators.
  • the similarity between the operators in the first calculation graph and the operators in the second calculation graph may form a first matrix.
  • the first computational graph is Q and the second computational graph is R.
  • the first footprint matrix of the first computation graph Q is:
  • the second footprint matrix of the second computation graph R is:
  • the operator corresponding to the row in the footprint matrix can be used as the starting point of the access path, the operator corresponding to the column can be used as the end point of the access path, or the operator corresponding to the column in the footprint matrix can be used as the starting point of the access path.
  • the operator corresponding to the row is used as the end point of the access path, which is not limited in this application.
  • the processor may determine the first eigenvectors of the operators q(1), q(2)...q(n) in the first calculation graph according to the above-mentioned first footprint matrix, and determine the second calculation graph according to the above-mentioned second footprint matrix.
  • the first eigenvectors of operators q(1), q(2)...q(n) can be expressed as:
  • a vector formed by a column of data where the operator is located can represent the first eigenvector of the operator.
  • Above the thick solid line can be the column vector of the column where the operator is located, and below the thick solid line can be the row of the row where the operator is located.
  • the vector is concatenated into a column vector.
  • the second eigenvectors of operators r(1), r(2)...r(n) can be expressed as:
  • the vector formed by a column of data where the operator is located can represent the second eigenvector of the operator.
  • Above the thick solid line can be the column vector of the column where the operator is located, and below the thick solid line can be the row of the row where the operator is located.
  • the vector is concatenated into a column vector.
  • step S300 the processor adjusts the order of rows and columns in the first footprint matrix according to the first matrix, which may refer to adjusting the order between rows and rows and between columns and columns in the first footprint matrix according to the first matrix , while maintaining the order of rows and columns in the second footprint matrix.
  • the processor adjusts the order of rows and columns in the first footprint matrix according to the first matrix, which may refer to adjusting the order between rows and rows and between columns and columns in the first footprint matrix according to the first matrix , while maintaining the order of rows and columns in the second footprint matrix.
  • adjusting the order of rows and columns in the first footprint matrix is only an example of the present application, and it is also possible to adjust the order of rows and columns in the second footprint matrix while maintaining the first footprint matrix. The order of rows and columns remains unchanged.
  • the specific process that the processor adjusts the order of the rows and columns in the first footprint matrix according to the similarity matrix may include: the processor determines the first calculation graph and the second calculation graph according to the similarity matrix A mapping relationship between operators, according to which the order of rows and columns in the first footprint matrix corresponding to the operators of the first calculation graph is adjusted.
  • the processor may determine the degree of similarity between the operator in the first calculation graph and the operator in the second calculation graph according to the value of the elements in the similarity matrix, and determine the first calculation graph and the second calculation graph.
  • the mapping relationship between the operators of the graph for example, you can select the largest element values in the similarity matrix, and determine that the two operators corresponding to the largest element values have a mapping relationship. If the operators correspond to different rows and columns in the first footprint matrix and the second footprint matrix, the relationship between the rows and columns in the first footprint matrix can be adjusted, so that the two operators with a mapping relationship after adjustment are in the The first footprint matrix and the second footprint matrix correspond to the same rows and columns.
  • the order of the rows and columns of the first footprint matrix may not be adjusted first, and continue from the similarity Select the larger element value in the matrix and repeat the above process.
  • the adjusted first footprint matrix When adjusting the row and column order of the first footprint matrix, the rows and columns with the same serial number should be adjusted at the same time.
  • the positions of the first and second rows, and the first and second columns in the footprint matrix, the adjusted first footprint matrix can be expressed as:
  • the similarity matrix can be recalculated according to the adjusted first footprint matrix and the second footprint matrix.
  • the stop condition may be a condition indicating that the process of adjusting the first footprint matrix and calculating the first matrix is stopped.
  • the stopping condition may refer to a condition that is satisfied by the first matrix obtained by multiple calculations, for example, the sum of the element values in the first matrix is greater than the similarity threshold, or it can also be set to be similar to Degree-dependent objective function, when the value of the objective function is maximum, the stopping condition is reached.
  • the objective function of iteration can be set as Among them, M represents a mapping relationship set between operators, and m represents a mapping relationship between two specific operators in this mapping relationship set. If, according to the mapping relationship between the operators corresponding to the adjusted first footprint matrix and the second footprint matrix, the calculated value of the objective function satisfies a certain range, or the calculated value of the objective function is no longer changes, then the processor may determine that the stop condition is reached.
  • the stop condition may also be the number of iterations.
  • the stop condition may be that the number of times the first matrix is repeatedly calculated is greater than the first threshold, that is, the number of times corresponding to the first threshold is performed. After the process of computing the first matrix, the order of the rows and columns of the first footprint matrix is no longer adjusted. This application does not limit this.
  • the first footprint matrix and the second footprint matrix have the same row or column position as the operator of the first computation graph and the operator of the second computation graph. There is a mapping relationship between them.
  • the processor may determine that the operators corresponding to the rows or columns of the same position of the first footprint matrix and the second footprint matrix when the stop condition is reached are mapping operators to each other, and the row of the same position It can refer to the same row number, for example, the first row of the first footprint matrix and the second row of the second footprint matrix are in the same position, the operator corresponding to the first row of the first footprint matrix and the first row of the second footprint matrix.
  • multiple mapping operators can also be determined for one operator according to the calculated similarity matrix. For example, the similarity between one operator and other operators can be sorted according to the calculated similarity matrix value. The multiple operators with the highest similarity with the operator are determined as the mapping operators of the operator.
  • the type of the first footprint matrix, the adjusted first footprint matrix, and the operator corresponding to the row at the same position and the type of the operator corresponding to the column at the same position of the second footprint matrix are the same, that is, the operators corresponding to the rows at the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns at the same position are of the same type , the dimensions of the tensors output by the operators are the same, the operators corresponding to the rows at the same position and the columns at the same positions of the adjusted first footprint matrix and the second footprint matrix are of the same type, and the operators output The dimensions of the tensors are the same.
  • the dimensions of the tensors output by the operators are the same, that is, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns in the same position are functionally the same.
  • Combine the similarity matrix to measure the similarity of the topological relationship between operators. According to the operator mapping method provided by the present application, the mapping relationship between two operators can be reflected in terms of functions and topological relationships, thereby ensuring the correctness of the mapping result.
  • one or more preferred mapping relationships can be obtained through iterative calculation, so it can support operator mapping between computational graphs with similar structures, and can be applied to deep learning frameworks for In the scenario of model migration.
  • the operators in the first calculation graph and the second calculation graph belong to multiple first partitions, the operators in the same first partition are of the same type, and the operator outputs
  • the dimensions of the quantities are the same; some operators in the first calculation graph and the second calculation graph belong to the second partition, the types of operators in the second partition are different and/or the dimensions of the tensors output by the operators are different different.
  • operators with the same type and the same dimension of output tensors can be called homogeneous operators, so the first partition can also be called homogeneous partition.
  • the types of operators in the second partition are different and/or the dimensions of the tensors output by the operators are different. Therefore, the operators in the second partition are not homogeneous operators, and the second partition may also be called a hybrid partition.
  • the processor may classify the operators of the first calculation graph and the operators of the second calculation graph according to the type of the operator and the dimension of the tensor output by the operator, and classify the homogeneous operators Divided into one class, each class of homogeneous operators belongs to a first partition.
  • Each of the first partitions may include at least part of the operators of the first computation graph and/or the second computation graph.
  • the operators in the first calculation graph and the second calculation graph may belong to the second partition (hybrid partition), and the second partition may include the first calculation graph and/or the second partition.
  • Partial operators of computational graphs For the operators in the first calculation graph and the second calculation graph, the operators without homogeneous operators all belong to the mixed partition. For example, some operators in the calculation graph are unmappable operator types, or there are no operators with the same dimension of output operands, and there are no homogeneous operators for such operators. For example, MS's tuple_getitem operator and TF's Identity operator cannot find corresponding operator types with the same functions from each other's framework. Such operators can be divided into mixed partitions, and when a mapping operator is determined, a mapping suggestion can be output according to the first footprint matrix, the second footprint matrix and the calculated similarity matrix when the stopping condition is reached.
  • the operator and the first computation graph belong to the same first partition and have the same row or column position in the first footprint matrix and the second footprint matrix when the stopping condition is reached. There is a mapping relationship between the operators of the two computation graphs.
  • mapping relationship between the operators of the first computation graph belonging to the second partition and multiple operators of the second computation graph belonging to the second partition, wherein the operators belonging to the first computation graph
  • the multiple operators of the second computation graph of the second partition are: in the first matrix when the stopping condition is reached, among the values of the elements corresponding to the operators of the first computation graph belonging to the second partition, The operator of the second computation graph corresponding to the largest multiple values.
  • a mapping suggestion between the operator of the first computation graph and the multiple operators of the second computation graph in the mixed partition can be output, or the first computation graph in the mixed partition can be output.
  • the operator of the second calculation graph and the mapping suggestion of multiple operators in the first calculation graph For example, for the operator of the first calculation graph in the mixed partition, according to the similarity value corresponding to the operator in the similarity matrix, multiple operators (top-k, k is the number of operators suggested when outputting mapping suggestions, and k is a positive integer) output.
  • the processor may arrange the operators of the first computation graph in the rows corresponding to the first footprint matrix and the operators of the second computation graph in the second footprint according to the first partition.
  • the corresponding rows in the matrix, and the columns corresponding to the operators of the first computation graph in the first footprint matrix and the columns corresponding to the operators of the second computation graph in the second footprint matrix are arranged according to the first partition.
  • the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are in the same first partition, and the operators corresponding to the columns in the same position are in the same The first partition; and, the operators of the first computation graph belonging to the same first partition are arranged consecutively in the corresponding rows or columns in the first footprint matrix, and the operators of the second computation graph belonging to the same first partition are in the same first partition.
  • the corresponding rows or columns in the second footprint matrix are arranged consecutively.
  • the row corresponding to the operator of the first computation graph belonging to the same first partition in the first footprint matrix and the row corresponding to the operator of the second computation graph in the second footprint matrix have the same sequence number range, and belong to the same
  • the columns corresponding to the operators of the first computation graph of the first partition in the first footprint matrix and the columns corresponding to the operators of the second computation graph in the second footprint matrix have the same serial number range.
  • the operators q(1), q(2) and q(3) of the first computation graph belonging to the same first partition are in the rows 1-3 and columns 1-3 corresponding to the first footprint matrix.
  • 3 columns, the operators r(1), r(2) and r(3) of the second computation graph belonging to the same first partition as the operators q(1), q(2) and q(3) are in the second
  • the footprint matrix corresponds to rows 1-3 and columns 1-3.
  • FIG. 6 shows a flowchart of constructing a footprint matrix according to an embodiment of the present application.
  • the process of respectively determining the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph may include:
  • Step S3000 according to the type of the operator and the dimension of the tensor output by the operator, partition the operators in the first calculation graph and the second calculation graph to obtain a first partition;
  • the operator is a homogeneous operator, the type of the homogeneous operator is the same, and the dimension of the tensor output by the operator is the same;
  • Step S3002 respectively determining a first footprint matrix of the first computation graph and a second footprint matrix of the second computation graph according to the first partition.
  • adjusting the order of rows and columns in the first footprint matrix according to the first matrix in step S300 may include: adjusting according to the first matrix the order of rows and columns in the first footprint matrix that are located in the same The order of the rows and columns corresponding to the operators in the first partition.
  • the processor may divide the operators of the first computation graph and the second computation graph with the same type and the same dimension of the tensors output by the operators into the same homogeneous partition. That is to say, operators with the same type and the same dimension of the tensors output by the operators in the first calculation graph and the second calculation graph are located in the same homogeneous partition.
  • FIG. 7 shows a schematic diagram of a homogeneous partition according to an embodiment of the present application.
  • operators q(1), q(2), q(3), q(4) and r(1), r(2), r(3), and r(4) are in the same homogeneous partition
  • the type of the operator in the homogeneous partition is convolution operation
  • the dimension of the output operand is 64 ⁇ 55 ⁇ 55.
  • q(5), q(6), q(7) and r(5), r(6), r(7) are in the same homogeneous partition
  • the type of operator in this homogeneous partition is convolution operation
  • the dimension of the output operand is 256 ⁇ 55 ⁇ 55.
  • the operators q(n) and r(n) are in the same homogeneous partition, the type of the operators in the homogeneous partition is the pooling operation, and the dimension of the output operand is m ⁇ n ⁇ k. It should be noted that the types of operators in the homogeneous partition, the dimensions of output operands, the number and number of operators in the homogeneous partition in FIG. 7 are only examples of the present application and do not limit the present application in any way.
  • the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph are determined according to the first partition, mainly for placing operators located in the same homogeneous partition adjacent to each other in the footprint matrix row and column positions.
  • the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are in the same first partition, and the operators corresponding to the columns in the same position are in the same first partition;
  • the operators of the computation graph are arranged consecutively in corresponding rows or columns in the first footprint matrix, and the operators of the second computation graph belonging to the same first partition are arranged consecutively in corresponding rows or columns in the second footprint matrix. That is, when determining the first footprint matrix and the second footprint matrix, for operators located in the same homogeneous partition in the first computation graph and the second computation graph, the operators in the first computation graph are in the first footprint matrix
  • the sequence number range of the row and column in is the same as the sequence number range of the row and column of the operator in the second footprint matrix in the second computation graph.
  • the operators q(1), q(2), q(3), and q(4) of the first calculation graph correspond to the first footprint matrix in the first footprint matrix.
  • Rows 1-4, columns 1-4, then the operators r(1), r(2), r(3), and r(4) of the second calculation graph correspond to rows 1-4 in the second footprint matrix , columns 1-4.
  • the operators in the calculation graph are homogeneously partitioned, and the corresponding footprint matrix is determined according to the homogeneous partition, so that operators with a higher possibility of having a mapping relationship can be quickly determined, and the mapping can be accelerated. the process of.
  • adjusting the order of rows and columns corresponding to operators located in the same first partition in the first footprint matrix according to the first matrix may include:
  • the order of rows and columns in the first footprint matrix corresponding to the operators in the first computation graph is adjusted according to the mapping relationship.
  • the mapping relationship between the operators in the first calculation graph and the operators in the second calculation graph in the same first partition is determined according to the first matrix, which may specifically include two traversals.
  • the following process is for the same first partition. The process of determining the mapping relationship by the operator.
  • the first traversal process start from the operator in the first calculation graph corresponding to the smallest element in a homogeneous partition of the similarity matrix to traverse all the operators in the homogeneous partition, according to the current traversed operator in the similarity
  • the largest element in the row or column of the degree matrix determines the operator most similar to the currently traversed operator in the second calculation graph, if the operator most similar to the currently traversed operator in the second calculation graph has been determined is the most similar operator of the operators that have been traversed, then in the second traversal, the most similar operator is re-determined for the operators that have been traversed, that is, in the process of the first traversal, after the traversal
  • the result of the later traversal overwrites the result of the previous traversal.
  • the operator most similar to the currently traversed operator in the calculation graph has been determined to be the most similar operator of the operator that has been traversed, then according to the order of the current traversed operator in the row or column of the similarity matrix
  • the large element value determines the most similar operator to the currently traversed operator in the second calculation graph until the most similar operator to the currently traversed operator is matched.
  • FIG. 5b shows a flowchart of a method for adjusting the order of rows and columns of a footprint matrix according to an embodiment of the present application.
  • the operator corresponding to the row of the first footprint matrix is the operator of the first calculation graph
  • the operator corresponding to the column is the operator of the second calculation graph
  • the row of the similarity matrix is the same as the first calculation graph.
  • the operators correspond, and the columns correspond to the operators of the second calculation graph.
  • the process of adjusting the footprint matrix in this embodiment of the present application will be described with reference to the similarity matrix in the above example.
  • Fig. 5b shows the process of determining the mapping relationship of the operators for an operator of a homogeneous partition.
  • the processor can first determine whether it is the first traversal or the second traversal, if yes
  • the processor may execute step S510 to first determine whether all operators of the homogeneous partition have been traversed, and if the operators of the homogeneous partition have been traversed, the processor may return Step S500, continue to judge whether it is the first traversal or the second traversal; if the operator of the homogeneous partition has not been traversed, the processor can perform step S511 to determine that the operator that has not been traversed corresponds to the similarity matrix.
  • the smallest element in the row of determines the operator corresponding to the smallest element as the current traversed operator, that is, in the first traversal process: start traversal from the operator corresponding to the smallest element value in the similarity matrix.
  • the processor may execute step S512, and determine the most similar operator to the currently traversed operator in the second calculation graph according to the largest element value in the row where the currently traversed operator is located in the similarity matrix For the operator, for example, the operator in the second calculation graph corresponding to the largest element value of the currently traversed operator in the row where the similarity matrix is located is determined as the most similar operator to the currently traversed operator. In other words, because it has been assumed that the operator corresponding to the row of the first footprint matrix is the operator of the first calculation graph, the operator corresponding to the column is the operator of the second calculation graph, and the row of the similarity matrix is the operator of the first calculation graph.
  • the column corresponds to the operator of the second calculation graph, therefore, in the similarity matrix, the value of a row of elements respectively represents the cosine of an operator in the first calculation graph and each operator in the second calculation graph Similarity, the larger the value in this row of elements, the more similar the operator in the first calculation graph is to the operator in the second calculation graph. Therefore, the processor may determine the operator in the second calculation graph corresponding to the largest element value of the currently traversed operator in the row of the similarity matrix as the operator most similar to the currently traversed operator.
  • the processor may execute step S513 to determine whether the most similar operator has been matched with the previously traversed operator, and if the most similar operator does not match the previously traversed operator If the sub-matches, the processor may perform step S515 to record the mapping relationship between the currently traversed operator and the most similar operator, mark the currently traversed operator as the traversed operator, and return to step S510 to continue to determine whether All operators of the homogeneous partition have been traversed.
  • step S514 the processor may execute step S514 to delete the mapping relationship between the previously traversed operator and the most similar operator, and add the previously traversed operator to the The second traversal of the queue. Then proceed to step S515.
  • steps S514 and S515 the way that the processor records and deletes the mapping relationship is only an example of the present application, and the present application is not limited to this, and other methods can also be used to realize the most similar operator determined by traversal and the most similar operator determined before. When similar operators conflict, the result of the later traversal overwrites the result of the previous traversal.
  • adding the previously traversed operator to the queue for the second traversal is only a way to implement the second traversal.
  • the processor can also implement this process by adding a special identifier to the operator.
  • the implementation method is not limited.
  • the process of the second traversal is started.
  • the processor may execute step S520 to determine whether all operators of the homogeneous partition have been traversed, that is, whether the operators that have not been matched after the first traversal have been traversed. After judging that all operators of the homogeneous partition have been traversed, the processor may end the process of determining the mapping relationship. After judging all the operators of the homogeneous partition that have not traversed the operators, the processor may execute step S521 to determine the largest element in the row corresponding to the similarity matrix of the operator that has not yet been traversed, and calculate the operator corresponding to the largest element. child as the current traversal operator. That is, in the process of the second traversal described above, for the operators that have not yet matched the most similar operator, the traversal starts from the operator corresponding to the largest element in the similarity matrix.
  • the processor may execute step S522 to determine the most similar operator to the currently traversed operator in the second calculation graph according to the maximum element value in the row where the currently traversed operator is located in the similarity matrix the operator. For the specific determination method, reference may be made to the content of step S512, and details are not repeated here.
  • the processor may execute step S523 to determine whether the most similar operator has been matched with the previously traversed operator. For the specific process, please refer to the content of step S513. The difference is that when the processor determines that the most similar operator matches the previously traversed operator, it no longer covers the previously traversed result, but executes step S524, according to the row in the similarity matrix where the currently traversed operator is located.
  • the value of the second largest element in the second calculation graph determines the operator that is most similar to the currently traversed operator, that is to say, continue to find other operators that are most similar to the currently traversed operator until it finds an operator that is not the same as the one traversed before. After the operator matches the operator that is "most similar" to the currently traversed operator, step S525 is executed.
  • the processor can more quickly determine the local (stage) optimal mapping relationship of the operators in the first calculation graph and the second calculation graph, and according to The mapping relationship adjusts the order of the rows and columns in the first footprint matrix corresponding to the operators in the first computation graph. Specifically, according to the arrangement order of operators corresponding to each row (each column) of the second footprint matrix, the mapping operator of the operator in the second calculation graph in the first calculation graph is determined according to the above-mentioned mapping relationship, and the mapping The corresponding row (column) of the operator in the first footprint matrix is adjusted to be the same as the row (column) of the operator in the second footprint matrix in the second calculation graph.
  • the calculation result can be more quickly converged to the stop condition of the iteration, and the mapping relationship between operators can be obtained more quickly, which is beneficial to speed up the mapping process.
  • the above example is only an example of adjusting the order of the rows and columns of the first footprint matrix provided by the present application, and the present application is not limited thereto.
  • the homogeneous depths of the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are the same, and the homogeneous depths of the operators corresponding to the columns of the same position are the same,
  • the corresponding rows or columns of the operators of the first computation graph belonging to the same first partition in the first footprint matrix are sorted according to the homogeneous depth of the operators, and the second computation graph of the same first partition
  • the rows or columns corresponding to the operators in the second footprint matrix are sorted according to the homogeneity depth of the operators; wherein, the homogeneity depth is: in all branches to which the operator belongs in the calculation graph, in The maximum number of operators that have the same type and output tensor dimensions as the operator before the operator.
  • the operator mapping method provided by the present application may further include the following steps:
  • the operators are partitioned to obtain homogeneous partitions, and in each homogeneous partition, the operators of the first computational graph and the second computational graph are sorted and numbered according to the homogeneous depth of the operator; that is, in each In the homogenous partition, the processor may sort and number the operators of the first calculation graph according to the homogeneity depth of the operators of the first calculation graph, and sort and number the operators of the second calculation graph according to the homogeneity depth of the operators of the second calculation graph.
  • the operators are sorted and numbered according to the homogeneous depth, and the method of sorting and numbering is not limited. The depth is sorted from deep to shallow, and the numbers are numbered from small to large.
  • the processor determines the first footprint matrix, it can be determined according to the sequence of the numbers of the operators of the first calculation graph in the first partition; when the processor determines the second footprint matrix, it can be determined according to the second calculation in the first partition.
  • the order of the numbering of the operators of the graph is determined. In this way, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix can have the same homogeneous depth, the operators corresponding to the columns in the same position have the same homogeneous depth, and belong to the first calculation of the same first partition.
  • the corresponding rows or columns of the operators of the graph in the first footprint matrix are sorted according to the homogeneous depth of the operators, and the corresponding rows or columns of the operators of the second calculation graph of the same first partition in the second footprint matrix are sorted according to the operator's homogeneous depth. Homogeneous depth ordering of .
  • Distinguishing operators with the same attributes by the homogeneous depth can avoid the unreliability of distinguishing operators with the same attributes by the names of the operators, and numbering and sorting homogeneous operators according to the homogeneous depth is also conducive to speeding up the mapping process, because it is more likely that there is a mapping relationship between operators that belong to the same first region and have the same homogeneous depth.
  • FIG. 8 and FIG. 9 respectively show schematic diagrams of determining the homogeneity depth of a homogeneity operator according to an embodiment of the present application.
  • the homogeneity depth of the first operator Conv is 1, and the homogeneity depth of the second Conv operator is 2, because from this operator
  • the first homogenous operator (the first Conv operator) starts to the operator (the second Conv operator), and the second Conv operator has a total of two homogenous operators (one is the first Conv operator, one is itself), therefore, the homogeneity depth of the second Conv operator is 2.
  • the homogeneity depths of other operators in the computation graph shown in FIG. 8 can be determined.
  • the fourth Conv operator from top to bottom belongs to two branches.
  • the corresponding homogeneous depth of the operator are different, for example, there is a Conv operator on the left branch before the 4th Conv operator, the homogeneity depth of the 4th Conv operator is 2, and on the right branch before the 4th Conv operator
  • the fourth Conv operator has a homogeneity depth of 3.
  • the maximum number of homogenous operators of the operator is 3, so the homogeneity depth of the fourth Conv operator is 3.
  • the homogeneity operators After determining the homogeneity operators and the homogeneity depths of the homogeneity operators in the first calculation graph and the second calculation graph, the homogeneity operators can be partitioned to obtain homogeneity partitions, and in the homogeneity partitions, according to the operator
  • the homogeneity depth of sorts and numbers the operators of the two computation graphs respectively.
  • the homogeneous depth is used as an example of the representation of the topology structure of the operator in the calculation graph.
  • the present application is not limited to this, and other ways can also be used to represent the topology structure of the operator in the calculation graph. .
  • the method of sorting and numbering by homogeneous depth can be used to distinguish different homogeneous operators well, and the mapping relationship between homogeneous operators can be obtained more quickly, which is conducive to speeding up the mapping process .
  • the first partition further includes Pseudo-operator; wherein, a pseudo-operator is an operator without operator type and operand. If the number of operators of the first computation graph in the second partition is different from the number of operators of the second computation graph, the second partition also includes the pseudo-operator.
  • the The row or column corresponding to the pseudo operator in the first footprint matrix is located after the row or column corresponding to the operator belonging to the first partition in the first calculation graph;
  • the number of operators of the second calculation graph is less than the number of operators of the first calculation graph in the first partition, and the corresponding row or column of the pseudo operator in the second footprint matrix is located in After the row or column corresponding to the operator belonging to the first partition in the second calculation graph.
  • the number of operators of the first computation graph in the second partition is less than the number of operators of the second computation graph in the second partition, the The rows and columns corresponding to the pseudo operators in the first footprint matrix and the rows and columns corresponding to the operators belonging to the second partition in the first calculation graph are randomly sorted, and the rows and columns are randomly sorted in the same manner; If the number of operators of the second computation graph in the second partition is less than the number of operators of the second computation graph in the second partition, the pseudo operator is located in the second footprint The corresponding rows and columns in the matrix and the rows and columns corresponding to the operators belonging to the second partition in the second computation graph are randomly ordered, and the random ordering of the rows and columns is the same.
  • the number of operators in the computation graph corresponding to the model may be different.
  • the length of the feature vector is the same to be calculated. Therefore, when the dimensions of the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph are the same, the eigenvectors of the operators of the first computation graph determined according to the first footprint matrix and the eigenvectors of the operators of the first computation graph determined according to the second footprint matrix The lengths of the eigenvectors of the operators of the second computational graph are the same.
  • it may further include:
  • the pseudo-operators When adding pseudo-operators in homogeneous and mixed partitions, the pseudo-operators can be randomly sorted and numbered. In a possible implementation manner, when a pseudo operator is added to the homogeneous partition, the pseudo operator may be arranged after the operator of the calculation graph. In hybrid partitioning, both pseudo-operators and operators of the computation graph can be randomly ordered and numbered according to the ordering.
  • Pseudo-operators are fictitious fillers that do not have any meaningful operator properties or topology.
  • the purpose of pseudo-operators is to make the total number of operators in the first computational graph and the second computational graph equal, so as to construct the same size. the footprint matrix, so that the subsequent matrix operations can be performed normally.
  • the operator mapping method provided by the present application can be applied to the scenarios of frameworks or migration models between systems using different computational graph representations.
  • the processor may also perform the above process in the following order: the processor may determine the homogeneity depth of the operators in the first and second computation graphs; Partitioning is performed to obtain homogeneous partitions and/or mixed partitions. At the same time, the operators of the first computational graph and the second computational graph can be sorted according to the homogeneous depth of the operators in the homogeneous partition, and the sorting is based on the homogeneity.
  • the depth can be from large to small or from small to large, which is not limited in this application; the processor adds pseudo-operators according to the number of operators in the two calculation graphs in the homogeneous partition, and the processor can
  • the homogeneous depth is set to the maximum (true operator + total number of pseudo-operators).
  • pseudo-operators can be sorted according to the homogeneous depth, and for mixed partitions, pseudo-operators can be randomly sorted; The operators are numbered.
  • FIG. 10 shows an example of an insertion pseudo-operator according to an embodiment of the present application.
  • two pseudo-operators q(3) and q(4) are added to the left computational graph
  • the right A pseudo-operator r(7) is added to the computational graph
  • two pseudo-operators are added to the computational graph on the left.
  • the number of operators in the first computation graph and the second computation graph is the same.
  • the corresponding rows and columns of the two pseudo-operators q(3) and q(4) in the first footprint matrix are calculated.
  • the corresponding row and column of the pseudo-operator r(7) in the second footprint matrix are after the operator r(6).
  • the pseudo operator is unreachable to other operators, that is, the shortest distance from the pseudo operator to other operators is infinite, and the reciprocal of the shortest distance is 0, that is, in the footprint matrix, the pseudo operator corresponds to The elements of are all 0.
  • Application scenario and example description Migrate the ResNet50 model from TensorFlow to MindSpore, and assist in locating the problematic script during the migration process.
  • the number of operators in the calculation graph of the ResNet50 model on the TensorFlow v1.14 platform is 5176, and the number of operators in the calculation graph on the MindSpore v1.0.0 platform is 2513.
  • the operator mapping method of the present application will be described below with reference to the application scenario and the example.
  • FIG. 11 shows a flowchart of an operator mapping method according to an embodiment of the present application. Combined with the example shown in Figure 2, after exporting the computational graph R from the model script of TensorFlow v1.14 and exporting the computational graph Q from the model script of MindSpore v1.0.0, input the computational graph to the processor.
  • the processor may execute the operator mapping method shown in FIG. 11 .
  • the processor may compute the homogenous depth for the operators in the computation graph Q and the computation graph R.
  • the homogeneity depths corresponding to the operators are different. For example, there is a Conv operator on the left branch before the fourth Conv operator, the homogeneity depth of the fourth Conv operator is 2, and on the right branch There are two Conv operators before the fourth Conv operator, and the homogeneity depth of the fourth Conv operator is 3. At this time, from the first homogenous operator of the operator to the operator, the maximum number of homogenous operators of the operator is 3, so the homogeneity depth of the fourth Conv operator is 3.
  • the processor may perform homogeneous partitioning on the operators in the computation graph Q and the computation graph R.
  • An example after the processor performs homogeneous partitioning can refer to FIG. 10 .
  • the processor may divide the operators in the computation graph Q and the computation graph R with the same type and the same dimension size of the output operands of the operators into the same homogeneous partition.
  • a mixed partition can be set, and for the operators without homogeneous operators, they can be divided into mixed partitions.
  • MS's tuple_getitem operator and TF's Identity operator cannot find corresponding operator types with the same functions from each other's framework. For this type of operator, it can be divided into mixed partitions.
  • the two computation graphs After homogeneous partitioning, the two computation graphs have the same number of homogeneous partitions and one mixed partition, each homogeneous partition is different from the other homogeneous partitions in the type of operator and/or the dimension of the output operand, homogeneous In a partition, the order in which the different homogeneous partitions are arranged is not important. If in the same homogeneous partition, the number of operators in the two computation graphs is not the same, the processor can add a pseudo-operator to the computation graph with a relatively small number of operators in the homogeneous partition, so that the two computation graphs in the homogeneous partition have different numbers of operators. The number of operators in each computation graph is the same.
  • Pseudo-operators are fictitious fillers that do not have any meaningful operator attributes or topology.
  • the purpose of pseudo-operators is to make the total number of operators in the computational graph Q and the computational graph R equal, so as to construct footprints of the same size. matrix to enable subsequent matrix operations to be performed.
  • the processor can sort and number the operators according to the predetermined order.
  • the processor can sort and number the operators of the two computation graphs in the order of the homogeneous depth from small to large.
  • the pseudo operators added in the homogeneous partition are arranged after the real operators in the calculation graph, and the pseudo operators in the mixed partition can be arranged after the operators in the calculation graph, or the pseudo operators in the mixed partition and the operators in the calculation graph can be combined.
  • the children are randomly sorted, which is not limited in this application.
  • the processor may construct the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph according to the sequence of the operator numbers in the homogeneous partition. After the homogeneous partition is completed, the total number of operators in both the computational graph Q and the computational graph R is 5176.
  • the processor can construct two footprint matrices of 5176 ⁇ 5176 in the order of operator numbers, and combine all elements of the two footprint matrices. Values are initialized to 0.
  • the footprint matrix of the computation graph Q and the computation graph R stores the reciprocal of the shortest reachable distance from the operator to the operator in the corresponding computation graph. Since the computation graph Q and the computation graph R are both directed graphs, some operators are are not reachable, so the footprint matrix can be asymmetric.
  • the processor can traverse the operators in the computation graph Q and the computation graph R respectively, find out the shortest distance from the operator to other operators, and determine the footprint matrix according to the shortest distance.
  • the processor can use each operator in the computational graph Q as a starting point to perform a depth-first traversal that can repeatedly access the operators.
  • the value (the inverse of the visit distance) is placed in the corresponding element of the column where the origin operator is located and the row where the visited operator is located in the footprint matrix. If the visited operator has already been visited in this traversal and has been granted a larger or equal footprint value, the processor may not update the high corresponding element in the footprint matrix, and will no longer visit the visited operator's Direct downstream operator (already visited).
  • the associated footprint value of all pseudo-operators is 0.
  • FIG. 12 shows a schematic diagram of determining the shortest distance according to an embodiment of the present application.
  • the distance from the start operator to the previous operator is infinite, so the footprint value is 0.
  • the shortest distance from the origin operator to the operator corresponding to the two connected child nodes is 1, and the corresponding footprint value is 1.
  • the last operator in Figure 12 is a pseudo-operator, so the footprint value from the starting point operator to the pseudo-operator is 0.
  • the footprint values from the starting point operator to other operators in Fig. 12 are determined one by one.
  • the footprint matrix corresponding to the calculation graph shown in FIG. 12 can be determined according to the footprint value.
  • the operators of the first calculation graph and the second calculation graph are homogeneously partitioned, the homogeneous depth of the operators is determined, and the operators are sorted and numbered according to the homogeneous depth of the operators in the homogeneous partition.
  • the order of the homogeneity depths of the operators in the partition determines the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph, respectively.
  • the functions of the operators corresponding to the rows and columns in the same position of the first footprint matrix and the second footprint matrix are the same or similar
  • the first footprint matrix indicates the operators of the first calculation graph and other operators in the first calculation graph.
  • the topological relationship between operators, the second footprint matrix indicates the topological relationship between the operators of the second calculation graph and other operators in the second calculation graph.
  • the processor may calculate the similarity matrix according to the footprint matrices corresponding to the computation graph Q and the computation graph R.
  • the cosine similarity of the operators in the computation graph Q and the computation graph R can be calculated according to the footprint matrix q and the footprint matrix r to measure the similarity between two operators in the two computation graphs.
  • the specific process is: determining the first eigenvector of the operator in the calculation graph Q according to the footprint matrix q, determining the second eigenvector of the operator in the calculation graph R according to the footprint matrix r; according to the first eigenvector and the second eigenvector
  • the vector computation computes the similarity matrix between the operators in the computation graph Q and the operators in the computation graph R.
  • col(qk) is the corresponding column vector in the footprint matrix to which the operator qk belongs
  • row(qk) is the corresponding row vector in the footprint matrix to which the operator qk belongs
  • concat is the splicing operator. The row vector of the row in the footprint matrix is spliced with the column vector of the column to obtain the eigenvector of the operator
  • the eigenvector matrix of the computational graph Q and the eigenvector matrix of the computational graph R can be obtained.
  • the eigenvector matrix of the calculation graph Q is shown in the following table.
  • the part above the thick solid line can be the column vector corresponding to the operator in the calculation graph Q, and the part below the thick solid line can be the row vector corresponding to the operator in the calculation graph Q. Obtained below the column vector, the eigenvector matrix of the computational graph Q is 10352 ⁇ 5176:
  • the eigenvector matrix of the calculation graph R is shown in the following table, the part above the thick solid line can be the column vector corresponding to the operator in the calculation graph R, and the part below the thick solid line can be the row vector corresponding to the operator in the calculation graph R After splicing it under the column vector, the eigenvector matrix of the calculation graph R is 10352 ⁇ 5176:
  • the second footprint matrix indicates the operators of the second computation graph and other operators in the second computation graph.
  • the topological relationship between the operators therefore, the eigenvector of the operator obtained by the method of extracting the eigenvector of the operator provided by this application can well reflect the topological relationship between an operator and other operators in the calculation graph, That is, the "feature" of the operator in the calculation graph where it is located.
  • the value of the cosine similarity of any two non-zero eigenvectors is a real number between 0 and 1. The closer to 1, the more similar the two eigenvectors are, and the more similar the two operators corresponding to the eigenvectors are.
  • the similarity between a zero eigenvector and an arbitrary eigenvector is defined as 0, i.e. not at all similar.
  • k and l are both integers between 1 and 5176, represent the eigenvectors of operators qk and rl, respectively.
  • the positions of the rows and columns of the footprint matrix are equivalent to the mapping relationship of the operators. Therefore, when calculating the similarity matrix, the processor calculates all the operators of the calculation graph Q and the calculation R The similarity between the obtained similarity matrix is as follows:
  • the objective function can be calculated according to the similarity matrix value of .
  • the processor can update the footprint matrix according to the process of Figure 5b. Since the corresponding row and column positions of the operators in the footprint matrix are equivalent to the mapping relationship between the operators, the footprint can be updated after finding the mapping relationship of the optimal operator in the stage. matrix, and then continue to calculate the similarity matrix.
  • the adjusted footprint matrix can be either the footprint matrix of the computational graph Q or the footprint matrix of the computational graph R.
  • the footprint matrix of the computation graph with fewer real operators can be selected for adjustment, so as to reduce the number of adjustments.
  • the footprint matrix of the computation graph Q can be selected for adjustment.
  • FIG. 13 shows a schematic diagram of adjusting the footprint matrix according to an embodiment of the present application.
  • the processor can adjust row 7 to the position of row 1, row 9 to the position of row 2, row 2 to the position of the last row...
  • the 7th column Adjust to the position of column 1, adjust the position of column 9 to the position of column 2, and adjust the position of column 2 to the position of the last column.
  • the similarity matrix can be continuously calculated, and the value of the objective function can be calculated.
  • the processor can determine whether a stop condition is reached, and the stop condition may refer to a condition satisfied by the similarity matrix (objective function value) obtained by multiple calculations, or the stop condition may also be the number of iterations, which is not limited in this application .
  • the processor may continue the process of updating the footprint matrix, calculating the similarity according to the updated footprint matrix, and judging whether the stop condition is reached, until the stop condition is reached.
  • the processor may determine the mapping relationship between the operators according to the footprint matrix when the stopping condition is reached.
  • one of the two operators corresponding to the same row (or column) in the two footprint matrices can be directly determined as the mapping operator of the other operator.
  • the footprint matrix of the adjusted computational graph Q is:
  • mapping operator of operator q3 is r1
  • mapping operator of operator q2 is r2
  • mapping operator of operator q1 is r3... . That is to say, the two operators corresponding to the same row (or column) of the two footprint matrices are each other's mapping operators.
  • the processor can output a one-to-one mapping relationship between operators in the homogeneous partition according to the two footprint matrices.
  • the processor may output a mapping suggestion of the operators in the mixed partition according to the similarity matrix calculated by the previous iterations. Specifically, the processor may sort according to the size of the cosine similarity between the mixed region operator and another operator in the similarity matrix. , determine the top-ranked one or more (for example, 5) operators as the mapping suggestion of the mixed area operator, and output the corresponding mapping operator and the value of the cosine similarity as the mapping suggestion.
  • the cosine similarity between the Identity class operator and other operators in the mixed region is calculated. Sort the calculated cosine similarities in descending order, and take the first five operators in the sorting and the corresponding cosine similarity values as the mapping suggestions for the Identity class operators for output.
  • the present application also provides a parameter for measuring whether the mapping result is better: L1 norm.
  • the footprint difference matrix D can be calculated according to the footprint matrix q and the footprint matrix r, and the L1 norm of the footprint difference matrix can be calculated to measure the similarity between the operators in the two calculation graphs.
  • the footprint difference matrix can be calculated according to the following formula:
  • D q-r, where D represents the footprint difference matrix
  • L1 norm ⁇ i ⁇ j
  • the change of the L1 norm in the process of adjusting the footprint matrix it can be judged whether the obtained mapping relationship can reflect the similarity of the two calculation graphs.
  • FIG. 14 shows a schematic diagram of the effect of iterative calculation according to an embodiment of the present application.
  • the value of the objective function and the value of the L1 norm gradually converge, and the value of the objective function gradually becomes larger. After reaching a certain value, the change is no longer obvious. Similarly, The value of the L1 norm gradually becomes smaller, and after reaching a certain value, the change is no longer obvious.
  • the stopping condition can be set by setting the threshold of the objective function or L1 norm, or the number of iterations.
  • the number of iterations can be set to 5 or 6, which is enough to obtain a better mapping relationship.
  • the following table shows some parameters of the mapping effect in the example of migrating the ResNet50 model from TensorFlow to MindSpore.
  • the operator mapping method provided by this application can complete the calculation within 90s, complete the one-to-one mapping of 99% of the backbone operators, and provide many-to-many mapping suggestions, which can give all operators One-to-one mapping of 40% of the operators.
  • the operator mapping apparatus of the embodiments provided by the present application constructs footprint matrices of two computation graphs, where the footprint matrix is a matrix representing the topological relationship between operators in the computation graph.
  • a first matrix indicating the topological relationship between the two computational graphs can be iteratively calculated according to the footprint matrix, and after the iteration is stopped, one or more preferred mapping relationships can be determined according to the footprint matrix.
  • the dimensions of the tensors output by the operators are the same, that is, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns in the same position are functionally the same.
  • Combine the similarity matrix to measure the similarity of the topological relationship between operators. According to the operator mapping device provided by the present application, the mapping relationship between two operators can be reflected in terms of functions and topological relationships, thereby ensuring the correctness of the mapping result.
  • the operator mapping method provided in this application can output mapping suggestions, and supports one-to-one, one-to-many and many-to-many mappings, and the operator mapping method provided in this application can support similar
  • the operator mapping between the computational graphs of the structure can be applied to scenarios where the deep learning framework performs model migration.
  • Migrate the ResNet50 model from MindSpore v0.5.0 to MindSpore v1.0.0 The number of operators in the calculation graph of the ResNet50 model on the MindSpore v0.5.0 platform is 2514, and the number of operators in the calculation graph on the MindSpore v1.0.0 platform is 2513.
  • the calculation graph of MindSpore v0.5.0 is denoted as R
  • the calculation graph of MindSpore v1.0.0 is denoted as Q.
  • the processor can construct two 2514 ⁇ 2514 footprint matrices in the order of operator numbers, and initialize the values of all elements of the two footprint matrices to 0.
  • For the process of determining the footprint matrix reference may also be made to the above example, and details are not repeated here.
  • FIG. 15 shows a schematic diagram of the effect of iterative calculation according to an embodiment of the present application.
  • the value of the objective function gradually converges, and the value of the objective function gradually increases. After reaching a certain value, the change is no longer obvious.
  • the value of the L1 norm also no longer decreases after the 3rd iteration.
  • the following table shows some parameters of the mapping effect in the example of migrating the ResNet50 model from MindSpore v0.5.0 to MindSpore v1.0.0.
  • the operator mapping method provided by the present application can complete the calculation within 25s, complete the one-to-one mapping of 100% of the operators, with fast mapping speed and high accuracy.
  • the operator mapping method of the embodiment provided by the present application can quickly find the operator mapping relationship of two calculation graphs one-to-one, one-to-many and many-to-many without modifying the model script, thereby improving the comparison effect of the calculation graphs , so as to improve the test efficiency of operator developers and the speed of model network development and migration. It can be determined from the mapping statistics table that the one-to-one mapping rate and its correctness of the backbone operators that directly play a role in the problem location of the model are very high whether it is a comparison of the calculation graphs of different versions of the framework or the same framework. Reasonable time. With accurate backbone operator mappings, developers can use it as a reference to quickly compare operator numerical files or analyze model scripts to locate problems.
  • the operator mapping method provided by the embodiments of the present application can quickly realize the mapping of operators in two calculation graphs, and can obtain one or more preferred mapping relationships through iterative calculation, so it can support Operator mapping between computational graphs with similar structures, and can also support one-to-many or many-to-many mapping, which can be applied to scenarios where deep learning frameworks perform model migration.
  • FIG. 16 shows the computation according to an embodiment of the present application.
  • the block diagram of the operator mapping apparatus 90 shown in FIG. 16 the operator mapping apparatus 90 may include:
  • the iteration module 91 is configured to, based on the first footprint matrix and the second footprint matrix, repeat the following process until a stopping condition is reached: calculate the first matrix according to the first footprint matrix and the second footprint matrix, and calculate the first matrix according to the The first matrix adjusts the order of rows and columns in the first footprint matrix, and recalculates the first matrix according to the adjusted first footprint matrix and the second footprint matrix; wherein the first footprint matrix indicates The topological relationship between the operators of the first computational graph, the second footprint matrix indicates the topological relationship between the operators of the second computational graph, the first matrix indicates the first computational graph and the similarity of the topological relationship of the second calculation graph;
  • the corresponding module 92 is configured to obtain the operators corresponding to each of the multiple operators in the first calculation graph in the second calculation graph according to the first footprint matrix and the second footprint matrix when the stopping condition is reached .
  • the first calculation that belongs to the same first partition and has the same row or column position in the first footprint matrix and the second footprint matrix when the stopping condition is reached is the same
  • the operator mapping apparatus of the embodiments provided by the present application constructs footprint matrices of two computation graphs, where the footprint matrix is a matrix representing the topological relationship between operators in the computation graph.
  • a first matrix indicating the similarity of the topological relationship of the two computational graphs can be iteratively calculated according to the footprint matrix, and after the iteration is stopped, one or more preferred mapping relationships can be determined according to the footprint matrix. Therefore, the operator mapping method provided by the present application can support operator mapping between calculation graphs with similar structures, and can be applied to a scenario where a deep learning framework performs model migration.
  • the iteration module 91 includes:
  • the calculation unit is configured to obtain the first matrix according to a plurality of first eigenvectors and a plurality of second eigenvectors, wherein each of the first eigenvectors corresponds to an operator in the first calculation graph, and each Each of the first eigenvectors and the operators corresponding to the first eigenvectors are related to the row vectors and column vectors in the first footprint matrix, and each of the second eigenvectors corresponds to the second calculation graph
  • the operators in , each of the second eigenvectors and the operators corresponding to the second eigenvectors are related to the row vectors and column vectors in the second footprint matrix, and the first eigenvectors and the
  • the second feature vector is used to calculate the similarity between the operator corresponding to the first feature vector and the operator corresponding to the second feature vector.
  • the value of the element of the first matrix represents the similarity between the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located, wherein the row corresponding to the element is located.
  • the operator and the operator corresponding to the column where the element is located are respectively the operator in the first calculation graph and the operator in the second calculation graph.
  • the eigenvectors of the operator are constructed by using the corresponding row and column vectors in the footprint matrix corresponding to the operator in the calculation graph, and the topological relationship characteristics of the operator in the calculation graph are extracted.
  • the similarity of the topological relationship of the operator is calculated according to the eigenvector of the operator, and the similarity of the topological relationship of the operator of the first calculation graph and the operator of the second calculation graph forms a similarity matrix, and the similarity matrix is used to measure the two calculations.
  • the similarity of the topological relationships of the graphs are constructed by using the corresponding row and column vectors in the footprint matrix corresponding to the operator in the calculation graph, and the topological relationship characteristics of the operator in the calculation graph are extracted.
  • the similarity of the topological relationship of the operator is calculated according to the eigenvector of the operator, and the similarity of the topological relationship of the operator of the first calculation graph and the operator of the second calculation graph forms a similarity matrix, and the similarity matrix is used to measure the two calculations.
  • the type of the first footprint matrix, the adjusted first footprint matrix, and the operator corresponding to the row at the same position and the type of the operator corresponding to the column at the same position of the second footprint matrix are the same, that is, the operators corresponding to the rows at the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns at the same position are of the same type , the dimensions of the tensors output by the operators are the same, the operators corresponding to the rows at the same position and the columns at the same positions of the adjusted first footprint matrix and the second footprint matrix are of the same type, and the operators output The dimensions of the tensors are the same.
  • the dimensions of the tensors output by the operators are the same, that is, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns in the same position are functionally the same.
  • Combine the similarity matrix to measure the similarity of the topological relationship between operators. According to the operator mapping method provided by the present application, the mapping relationship between two operators can be reflected in terms of functions and topological relationships, thereby ensuring the correctness of the mapping result.
  • the operators in the first calculation graph and the second calculation graph belong to multiple first partitions, the operators in the same first partition are of the same type, and the operator outputs
  • the dimensions of the quantities are the same; some operators in the first calculation graph and the second calculation graph belong to the second partition, the types of operators in the second partition are different and/or the dimensions of the tensors output by the operators are different different.
  • the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are in the same first partition, and the operators corresponding to the columns in the same position are in the same first partition; and, belong to the same first partition.
  • the operators of the first computation graph are arranged in consecutive rows or columns in the first footprint matrix, and the operators of the second computation graph belonging to the same first partition are arranged in consecutive rows or columns in the second footprint matrix arrangement.
  • the operators in the first calculation graph and the second calculation graph are homogeneously partitioned, and when adjusting the order of the rows and columns in the first footprint matrix, adjust the The order of the rows and columns corresponding to the operators of the homogeneous partition can make the iterative process converge faster and speed up the mapping process.
  • the corresponding operator similarity can be obtained by setting mixed partitions for classification and participating in the iterative calculation process.
  • mapping suggestions can be output according to the calculated similarity. Therefore, it can support operator mapping between computational graphs with similar structures, and can also support one-to-many or many-to-many mapping, which can be applied to scenarios where deep learning frameworks perform model migration.
  • the homogeneous depths of the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are the same, and the homogeneous depths of the operators corresponding to the columns of the same position are the same,
  • the corresponding rows or columns of the operators of the first computation graph belonging to the same first partition in the first footprint matrix are sorted according to the homogeneous depth of the operators, and the second computation graph of the same first partition
  • the rows or columns corresponding to the operators in the second footprint matrix are sorted according to the homogeneity depth of the operators; wherein, the homogeneity depth is: in all branches to which the operator belongs in the calculation graph, in The maximum number of operators that have the same type and output tensor dimensions as the operator before the operator.
  • the operators in the homogeneous partition are sorted according to the homogeneous depth, and the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph are respectively determined according to the homogeneous partition. Since it is more likely that there is a mapping relationship between operators with the same homogeneous depth, the process of calculating the similarity matrix according to the above-mentioned embodiments of the present application can quickly converge, and the mapping relationship between operators can be determined more quickly. the process of mapping. In addition, by distinguishing operators with the same attributes by the homogeneous depth, the unreliability of distinguishing operators with the same attributes by the names of the operators can be avoided.
  • the first partition further includes Pseudo-operator; wherein, the pseudo-operator is an operator without operator type and operand; if the number of operators in the first computation graph in the first partition is less than the number of operators in the first partition.
  • the number of operators in the second calculation graph, the row or column corresponding to the pseudo-operator in the first footprint matrix is located in the row corresponding to the operator belonging to the first partition in the first calculation graph or column; if the number of operators in the second computation graph in the first partition is less than the number of operators in the first computation graph in the first partition, the pseudo operator is The corresponding row or column in the second footprint matrix is located after the row or column corresponding to the operator belonging to the first partition in the second calculation graph.
  • the second partition further includes the pseudo operator; if the number of operators of the first computation graph in the second partition is less than the number of operators of the second computation graph in the second partition, the pseudo operator
  • the rows and columns corresponding to the first footprint matrix and the rows and columns corresponding to the operators belonging to the second partition in the first computation graph are randomly ordered, and the rows and columns are randomly ordered in the same manner; if the The number of operators of the second computation graph in the second partition is less than the number of operators of the second computation graph in the second partition, and the pseudo-operators correspond to the second footprint matrix
  • the rows and columns of , and the rows and columns corresponding to the operators belonging to the second partition in the second calculation graph are randomly ordered, and the random ordering of the rows and columns is the same.
  • the operator mapping method provided by the present application can be applied to the scenarios of frameworks or migration models between systems using different computational graph representations.
  • the iteration module 91 further includes:
  • An adjustment unit configured to adjust the order of the rows and columns corresponding to the operators located in the same first partition in the first footprint matrix according to the first matrix.
  • the first calculation that belongs to the same first partition and has the same row or column position in the first footprint matrix and the second footprint matrix when the stopping condition is reached is the same
  • mapping method of the above-mentioned embodiments of the present application it is possible to support operator mapping between computational graphs with similar structures, support one-to-one, one-to-many, and many-to-many mappings, and can be applied to scenarios where deep learning frameworks perform model migration middle.
  • the stopping condition is that the number of times of repeatedly calculating the first matrix is greater than a first threshold.
  • An embodiment of the present application provides an operator mapping apparatus for a computational graph, including: 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 .
  • FIG. 17 shows a block diagram of an operator mapping apparatus according to an embodiment of the present application.
  • the operator mapping apparatus 1700 may vary greatly due to different configurations or performances, and may include one or more central processing units (CPU) 1701 (eg, one or more processors) ) and a memory 1705 in which one or more applications or data are stored.
  • CPU central processing units
  • memory 1705 in which one or more applications or data are stored.
  • the memory 1705 may be volatile storage or persistent storage.
  • the programs stored in memory 1705 may include one or more modules, each of which may include a series of instructions to operate on a blockchain node.
  • the central processing unit 1701 may be configured to communicate with the memory 1705 to execute a series of instruction operations in the memory 1705 on the operator mapping apparatus 1700.
  • the operator mapping device 1700 may also include one or more power supplies 1702, one or more wired or wireless network interfaces 1703, one or more input and output interfaces 1704, and/or, one or more operating systems, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
  • the process performed by the central processing unit 1701 in the operator mapping apparatus 1700 in this embodiment is similar to the method process described in the embodiment shown in FIG. 3 , FIG. 5 a , FIG. 5 b , FIG. 6 or FIG. Repeat.
  • Embodiments of the present application provide a non-volatile computer-readable storage medium on which computer program instructions are stored, and when the computer program instructions are executed by a processor, implement the above method.
  • Embodiments of the present application provide a computer program product, including computer-readable codes, or a non-volatile computer-readable storage medium carrying computer-readable codes, when the computer-readable codes are stored in a processor of an electronic device When running in the electronic device, the processor in the electronic device executes the above method.
  • a computer-readable storage medium may be a tangible device that can hold and store instructions for use by the instruction execution device.
  • the 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.
  • Computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable programmable read-only memory (Electrically Programmable Read-Only-Memory, EPROM or flash memory), static random access memory (Static Random-Access Memory, SRAM), portable compact disk read-only memory (Compact Disc Read-Only Memory, CD - ROM), Digital Video Disc (DVD), memory sticks, floppy disks, mechanically encoded devices, such as punch cards or raised structures in grooves on which instructions are stored, and any suitable combination of the foregoing .
  • RAM random access memory
  • ROM read only memory
  • EPROM erasable programmable read-only memory
  • EPROM Errically Programmable Read-Only-Memory
  • SRAM static random access memory
  • portable compact disk read-only memory Compact Disc Read-Only Memory
  • CD - ROM Compact Disc Read-Only Memory
  • DVD Digital Video Disc
  • memory sticks floppy disks
  • the computer readable program instructions or code described herein may be downloaded to various computing/processing devices from a computer readable storage medium, or to an external computer or external storage device over a network such as the Internet, a local area network, a wide area network and/or a wireless network.
  • the network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and/or edge servers.
  • a network adapter card or network interface in each computing/processing device receives computer-readable program instructions from a network and forwards the computer-readable program instructions for storage in a computer-readable storage medium in each computing/processing device .
  • the computer program instructions used to perform the operations of the present application may be assembly instructions, Instruction Set Architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or in one or more source or object code written in any combination of programming languages, including object-oriented programming languages such as Smalltalk, C++, etc., and conventional procedural programming languages such as the "C" language or similar programming languages.
  • the computer readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer, or entirely on the remote computer or server implement.
  • the remote computer can be connected to the user's computer through any kind of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or, can be connected to an external computer (e.g. use an internet service provider to connect via the internet).
  • electronic circuits such as programmable logic circuits, Field-Programmable Gate Arrays (FPGA), or Programmable Logic Arrays (Programmable Logic Arrays), are personalized by utilizing state information of computer-readable program instructions.
  • Logic Array, PLA the electronic circuit can execute computer readable program instructions to implement various aspects of the present application.
  • These computer readable program instructions may be provided to a processor of a general purpose computer, special purpose computer or other programmable data processing apparatus to produce a machine that causes the instructions when executed by the processor of the computer or other programmable data processing apparatus , resulting in means for implementing the functions/acts specified in one or more blocks of the flowchart and/or block diagrams.
  • These computer readable program instructions can also be stored in a computer readable storage medium, these instructions cause a computer, programmable data processing apparatus and/or other equipment to operate in a specific manner, so that the computer readable medium storing the instructions includes An article of manufacture comprising instructions for implementing various aspects of the functions/acts specified in one or more blocks of the flowchart and/or block diagrams.
  • Computer readable program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other equipment to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other equipment to produce a computer-implemented process , thereby causing instructions executing on a computer, other programmable data processing apparatus, or other device to implement the functions/acts specified in one or more blocks of the flowcharts and/or block diagrams.
  • each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more functions for implementing the specified logical function(s) executable instructions.
  • the functions noted in the blocks may occur out of the order noted in the figures. For example, two blocks in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved.
  • each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations can be implemented in hardware (eg, circuits or ASICs (Application) that perform the corresponding functions or actions. Specific Integrated Circuit, application-specific integrated circuit)), or can be implemented by a combination of hardware and software, such as firmware.

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • Evolutionary Computation (AREA)
  • Artificial Intelligence (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • General Engineering & Computer Science (AREA)
  • Life Sciences & Earth Sciences (AREA)
  • General Health & Medical Sciences (AREA)
  • Bioinformatics & Computational Biology (AREA)
  • Bioinformatics & Cheminformatics (AREA)
  • Health & Medical Sciences (AREA)
  • Software Systems (AREA)
  • Computing Systems (AREA)
  • Evolutionary Biology (AREA)
  • Computational Linguistics (AREA)
  • Molecular Biology (AREA)
  • Biophysics (AREA)
  • Mathematical Physics (AREA)
  • Biomedical Technology (AREA)
  • Databases & Information Systems (AREA)
  • Medical Informatics (AREA)
  • Multimedia (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present application relates to an operator mapping method and apparatus for a computational graph, the method comprising: on the basis of a first footprint matrix and a second footprint matrix, repeating the following process until stop conditions are reached: calculating a first matrix according to the first footprint matrix and the second footprint matrix, adjusting the order of rows and columns in the first footprint matrix according to the first matrix, and recalculating the first matrix according to the adjusted first footprint matrix and the second footprint matrix; and according to the first footprint matrix and the second footprint matrix when the stop conditions are reached, obtaining operators in a second computational graph that respectively correspond to a plurality of operators in a first computational graph. The operator mapping method and apparatus of the embodiments provided in the present application can support operator mapping between computational graphs of similar structures, and can be applied to a scenario in which a deep learning framework performs model migration.

Description

计算图的算子映射方法以及装置Operator mapping method and device for computational graph
本申请要求于2020年12月29日提交中国专利局、申请号为202011588279.1、发明名称为“计算图的算子映射方法以及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application with the application number 202011588279.1 and the invention titled "Operator Mapping Method and Apparatus for Computational Graphs" filed with the China Patent Office on December 29, 2020, the entire contents of which are incorporated herein by reference Applying.
技术领域technical field
本申请涉及人工智能技术领域,尤其涉及一种计算图的算子映射方法以及装置。The present application relates to the technical field of artificial intelligence, and in particular, to a method and device for operator mapping of a computational graph.
背景技术Background technique
计算图作为深度学习框架的前端和后端之间的中间表示,可以带来良好的交互性。计算图是通过图论语言表示数据函数的一种方式,在图论中节点通过边连接,节点代表事物,连接两节点的边表示两个事物间具有的关系,而计算图中用节点代表神经网络中的输入数据或者算子,连接两节点的边表示两点之间的输入输出关系等。Computational graph, as an intermediate representation between the front-end and back-end of a deep learning framework, can bring good interactivity. Computational graph is a way of expressing data functions through graph theory language. In graph theory, nodes are connected by edges, nodes represent things, and the edges connecting two nodes represent the relationship between two things, while nodes in computational graphs represent nerves. The input data or operator in the network, the edge connecting two nodes represents the input-output relationship between the two points, etc.
深度学习框架可以把根据深度学习框架编写的模型的脚本转换为计算图,模型内的算子都可以被转换为计算图中一个对应的节点。同一个模型的脚本在不同的深度学习框架下处理过程中,生成的计算图往往是不同的。在不同的深度学习框架之间进行模型迁移的时候,比如,将模型从TensorFlow(简称TF)迁移到MindSpore(简称MS),迁移前后不同深度学习框架对应的模型的计算图的结构、计算图中算子可能不同,因此,可能需要比较迁移前后的模型对应的计算图的结构、计算图中的算子是否一致。The deep learning framework can convert the script of the model written according to the deep learning framework into a computational graph, and the operators in the model can be converted into a corresponding node in the computational graph. When the scripts of the same model are processed under different deep learning frameworks, the generated computational graphs are often different. When migrating models between different deep learning frameworks, for example, when migrating a model from TensorFlow (TF for short) to MindSpore (MS for short), the structure and computation graph of the models corresponding to different deep learning frameworks before and after the migration The operators may be different. Therefore, it may be necessary to compare the structure of the calculation graph corresponding to the model before and after the migration, and whether the operators in the calculation graph are consistent.
计算图的结构复杂、算子繁多,举例来说,ResNet50(残差网络,Residual Network)在深度学习框架TensorFlow中的计算图的算子数为2000,在深度学习框架MindSpore中的计算图的算子数为5000。设计自动化的计算图对比工具,实现两个计算图的比较以及算子关系映射非常必要。The structure of the computational graph is complex and there are many operators. For example, the number of operators in the computational graph of ResNet50 (Residual Network) in the deep learning framework TensorFlow is 2000, and the computational graph in the deep learning framework MindSpore The number of subs is 5000. It is very necessary to design an automatic calculation graph comparison tool to realize the comparison of two calculation graphs and the operator relationship mapping.
发明内容SUMMARY OF THE INVENTION
有鉴于此,提出了一种计算图的算子映射方法以及装置,可以支持相似结构的计算图之间的算子映射,能够适用于深度学习框架进行模型迁移的场景中。In view of this, a method and device for operator mapping of computational graphs are proposed, which can support operator mapping between computational graphs with similar structures, and can be applied to scenarios where a deep learning framework performs model migration.
第一方面,本申请的实施例提供了一种计算图的算子映射方法,用于对第一计算图和第二计算图中的算子进行算子映射,所述第一计算图和所述第二计算图为同一个神经网络模型的计算图,所述算子映射方法包括:In a first aspect, embodiments of the present application provide an operator mapping method for a computation graph, for performing operator mapping on operators in a first computation graph and a second computation graph, the first computation graph and all The second calculation graph is the calculation graph of the same neural network model, and the operator mapping method includes:
处理器第一足迹矩阵和第二足迹矩阵,重复下述过程,直到达到停止条件:根据所述第一足迹矩阵和所述第二足迹矩阵计算第一矩阵,并根据所述第一矩阵调整所述第一足迹矩阵中的行和列的顺序,根据调整后的第一足迹矩阵和所述第二足迹矩阵重新计算所述第一矩阵;其中,所述第一足迹矩阵指示所述第一计算图的算子之间的拓扑关系,所述第二足迹矩阵指示所述第二计算图的算子之间的拓扑关系,所述第一矩阵指示所述第一计算图和所述第二计算图的拓扑关系的相似度;处理器根据达到所述停止条件时的第一足迹矩阵、所述第二足迹矩阵,得到所述第一计算图中的多个算子各自在第二计算图中对应的算子。Processes the first footprint matrix and the second footprint matrix, and repeats the following process until a stop condition is reached: calculating a first matrix according to the first footprint matrix and the second footprint matrix, and adjusting all the parameters according to the first matrix. the order of the rows and columns in the first footprint matrix, and recalculate the first matrix according to the adjusted first footprint matrix and the second footprint matrix; wherein the first footprint matrix indicates the first calculation the topological relationship between operators of the graph, the second footprint matrix indicates the topological relationship between the operators of the second computation graph, the first matrix indicates the first computation graph and the second computation graph similarity of the topological relationships of the graphs; the processor obtains, according to the first footprint matrix and the second footprint matrix when the stopping condition is reached, that multiple operators in the first computation graph are respectively in the second computation graph corresponding operator.
本申请提供的实施例的算子映射方法,通过构建两个计算图的足迹矩阵,足迹矩阵为表 示计算图的算子之间的拓扑关系的矩阵。根据两个计算图对应的足迹矩阵可以迭代计算第一矩阵,第一矩阵可以指示两个计算图的拓扑关系的相似度。迭代停止后,可根据足迹矩阵确定优选的一种或多种映射关系。因此,本申请提供的算子映射方法可以支持相似结构的计算图之间的算子映射,能够适用于深度学习框架进行模型迁移的场景中。The operator mapping method of the embodiments provided by the present application constructs footprint matrices of two computation graphs, where the footprint matrix is a matrix representing the topological relationship between operators in the computation graph. The first matrix may be iteratively calculated according to footprint matrices corresponding to the two calculation graphs, and the first matrix may indicate the similarity of the topological relationship of the two calculation graphs. After the iteration is stopped, the preferred one or more mapping relationships can be determined according to the footprint matrix. Therefore, the operator mapping method provided by the present application can support operator mapping between calculation graphs with similar structures, and can be applied to a scenario where a deep learning framework performs model migration.
根据第一方面的第一种可能的实现方式中,处理器根据第一足迹矩阵和第二足迹矩阵计算第一矩阵,包括:处理器根据多个第一特征向量和多个第二特征向量,得到所述第一矩阵,其中,每个所述第一特征向量对应所述第一计算图中的算子,每个所述第一特征向量与所述第一特征向量对应的算子在所述第一足迹矩阵中对应的行向量与列向量有关,每个所述第二特征向量对应所述第二计算图中的算子,每个所述第二特征向量与所述第二特征向量对应的算子在所述第二足迹矩阵中对应的行向量与列向量有关,所述第一特征向量和所述第二特征向量用于计算所述第一特征向量对应的算子和所述第二特征向量对应的算子之间的拓扑关系的相似度。According to a first possible implementation manner of the first aspect, the processor calculates the first matrix according to the first footprint matrix and the second footprint matrix, including: the processor calculates the first matrix according to a plurality of first eigenvectors and a plurality of second eigenvectors, The first matrix is obtained, wherein each of the first eigenvectors corresponds to an operator in the first calculation graph, and the operator corresponding to each of the first eigenvectors and the first eigenvector is in the The corresponding row vectors in the first footprint matrix are related to column vectors, each of the second eigenvectors corresponds to an operator in the second calculation graph, and each of the second eigenvectors is related to the second eigenvectors The row vector corresponding to the corresponding operator in the second footprint matrix is related to the column vector, and the first eigenvector and the second eigenvector are used to calculate the operator corresponding to the first eigenvector and the The similarity of the topological relationship between the operators corresponding to the second eigenvector.
根据第一方面的第一种可能的实现方式,在第二种可能的实现方式中,所述第一矩阵的元素的值表示所述元素所在的行对应的算子和所在的列对应的算子的拓扑关系的相似度,其中,所述元素所在行对应的算子和所述元素所在列对应的算子分别为所述第一计算图中的算子和所述第二计算图中的算子。According to the first possible implementation manner of the first aspect, in the second possible implementation manner, the value of the element of the first matrix represents the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located similarity of the topological relationship of the elements, wherein the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located are respectively the operator in the first calculation graph and the operator in the second calculation graph operator.
采用算子在计算图对应的足迹矩阵中对应的行向量和列向量构建算子的特征向量,提取了算子在计算图中的拓扑关系特征。根据算子的特征向量计算算子的拓扑关系的相似度,第一计算图的算子和第二计算图的算子的拓扑关系的相似度组成相似度矩阵,通过相似度矩阵衡量两个计算图的拓扑关系的相似度。The eigenvectors of the operator are constructed by using the corresponding row and column vectors in the footprint matrix corresponding to the operator in the calculation graph, and the topological relationship characteristics of the operator in the calculation graph are extracted. The similarity of the topological relationship of the operator is calculated according to the eigenvector of the operator, and the similarity of the topological relationship of the operator of the first calculation graph and the operator of the second calculation graph forms a similarity matrix, and the similarity matrix is used to measure the two calculations. The similarity of the topological relationships of the graphs.
根据第一方面、或第一方面的第一种或第二种可能的实现方式,在第三种可能的实现方式中,所述第一足迹矩阵、调整后的第一足迹矩阵与所述第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,也就是说,所述第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,调整后的第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同。According to the first aspect, or the first or second possible implementation manner of the first aspect, in a third possible implementation manner, the first footprint matrix, the adjusted first footprint matrix and the third The operator corresponding to the row at the same position and the operator corresponding to the column at the same position of the two footprint matrix are of the same type, and the dimensions of the tensors output by the operators are the same. That is, the first footprint matrix and the second footprint matrix have the same type. The operator corresponding to the row at the same position and the operator corresponding to the column at the same position of the footprint matrix are of the same type, and the dimension of the tensor output by the operator is the same, and the adjusted first footprint matrix and the second footprint matrix are the same. The operator corresponding to the row of the position, the operator corresponding to the column of the same position are of the same type, and the dimension of the tensor output by the operator is the same.
在构建第一足迹矩阵和第二足迹矩阵、以及调整第一足迹矩阵时,保证第一足迹矩阵和第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,也就是第一足迹矩阵和第二足迹矩阵相同位置的行对应的算子、相同位置的列对应的算子在功能上是相同的。结合相似度矩阵衡量算子之间的拓扑关系的相似度。根据本申请提供的算子映射方法,可以从功能和拓扑关系上体现两个算子之间的映射关系,从而确保映射结果的正确性。When constructing the first footprint matrix and the second footprint matrix, and adjusting the first footprint matrix, ensure the type of the operator corresponding to the row at the same position and the type of the operator corresponding to the column at the same position of the first footprint matrix and the second footprint matrix The same, the dimensions of the tensors output by the operators are the same, that is, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns in the same position are functionally the same. Combine the similarity matrix to measure the similarity of the topological relationship between operators. According to the operator mapping method provided by the present application, the mapping relationship between two operators can be reflected in terms of functions and topological relationships, thereby ensuring the correctness of the mapping result.
根据第一方面、或第一方面的第一种或第二种可能的实现方式,在第四种可能的实现方式中,所述第一计算图和所述第二计算图中的算子分属于多个第一分区,同一第一分区的算子类型相同、且算子输出的张量的维度相同,每个第一分区中可以包括第一计算图和/或第二 计算图的至少部分算子;所述第一计算图和所述第二计算图中的部分算子属于第二分区,所述第二分区中的算子类型不同和/或算子输出的张量的维度不同;所述第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子在同一第一分区、相同位置的列对应的算子在同一第一分区;且,属于同一第一分区的第一计算图的算子在所述第一足迹矩阵中对应的行或者列连续排列,属于同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或者列连续排列。According to the first aspect, or the first or second possible implementation manner of the first aspect, in a fourth possible implementation manner, the operators in the first computation graph and the second computation graph are divided into Belonging to multiple first partitions, the same first partition has the same operator type, and the dimensions of the tensors output by the operators are the same, and each first partition may include at least part of the first computation graph and/or the second computation graph Operators; some operators in the first calculation graph and the second calculation graph belong to a second partition, and the types of operators in the second partition are different and/or the dimensions of the tensors output by the operators are different; The operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are in the same first partition, and the operators corresponding to the columns in the same position are in the same first partition; and, belong to the same first partition. The operators of the first computation graph are arranged in consecutive rows or columns in the first footprint matrix, and the operators of the second computation graph belonging to the same first partition are arranged in consecutive rows or columns in the second footprint matrix arrangement.
因为同质算子之间存在映射关系的可能性更大,并且,在本申请的实施例中,第一足迹矩阵和第二足迹矩阵相同位置的行或列对应的算子之间存在映射关系。因此,根据本申请提供的上述实施例的方法,通过对第一计算图和第二计算图中的算子进行同质分区,并且在调整第一足迹矩阵中的行和列的顺序时,调整位于同一同质分区的算子对应的行和列的顺序,可以更快速使迭代的过程收敛,加快映射的过程。Because it is more likely that there is a mapping relationship between homogeneous operators, and in the embodiment of the present application, there is a mapping relationship between the operators corresponding to the rows or columns in the same position of the first footprint matrix and the second footprint matrix . Therefore, according to the method of the above-mentioned embodiment provided by the present application, the operators in the first calculation graph and the second calculation graph are homogeneously partitioned, and when adjusting the order of the rows and columns in the first footprint matrix, adjust the The order of the rows and columns corresponding to the operators located in the same homogeneous partition can make the iterative process converge more quickly and speed up the mapping process.
对于不存在同质算子的算子,通设置混合分区进行分类并参与迭代计算的过程得到对应的算子相似度,在确定映射算子时,可以根据计算得到的相似度输出映射建议。从而可以支持相似结构的计算图之间的算子映射,并且还可以支持一对多或多对多的映射,能够适用于深度学习框架进行模型迁移的场景中。For operators without homogeneous operators, the corresponding operator similarity can be obtained by setting mixed partitions for classification and participating in the iterative calculation process. When determining the mapping operator, mapping suggestions can be output according to the calculated similarity. Therefore, it can support operator mapping between computational graphs with similar structures, and can also support one-to-many or many-to-many mapping, which can be applied to scenarios where deep learning frameworks perform model migration.
根据第一方面的第三种可能的实现方式,在第五种可能的实现方式中,所述第一足迹矩阵和所述第二足迹矩阵相同位置的行对应的算子的同质深度相同、相同位置的列对应的算子的同质深度相同,且属于同一第一分区的所述第一计算图的算子在所述第一足迹矩阵中对应的行或列按照算子的所述同质深度排序、同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或列按照算子的所述同质深度排序;其中,所述同质深度为:在计算图中所述算子所属的所有分支中,在所述算子之前与所述算子类型相同、输出的张量维度相同的算子的最大数目。According to a third possible implementation manner of the first aspect, in a fifth possible implementation manner, the homogeneous depths of the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are the same, The homogeneity depths of the operators corresponding to the columns in the same position are the same, and the corresponding rows or columns of the operators of the first calculation graph belonging to the same first partition in the first footprint matrix are the same as those of the operators. Homogeneous depth sorting, the rows or columns corresponding to the operators of the second computation graph of the same first partition in the second footprint matrix are sorted according to the homogeneous depth of the operators; wherein, the homogeneous depth is: The maximum number of operators before the operator that have the same type as the operator and the same output tensor dimension among all the branches to which the operator belongs in the calculation graph.
对同质分区中的算子按照同质深度进行排序,按照确定同质分区分别确定第一计算图的第一足迹矩阵和第二计算图的第二足迹矩阵。由于同质深度相同的算子之间存在映射关系的可能性更大,因此,根据本申请上述实施方式计算相似度矩阵的过程可以快速收敛,更快的确定算子之间的映射关系,加速映射的过程。并且,通过同质深度区分具有相同属性的算子,可以避免通过算子的名称区分属性相同的算子的不可靠性。The operators in the homogeneous partition are sorted according to the homogeneous depth, and the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph are respectively determined according to the homogeneous partition. Since it is more likely that there is a mapping relationship between operators with the same homogeneous depth, the process of calculating the similarity matrix according to the above-mentioned embodiments of the present application can quickly converge, and the mapping relationship between operators can be determined more quickly. the process of mapping. In addition, by distinguishing operators with the same attributes by homogeneous depth, the unreliability of distinguishing operators with the same attributes by the names of the operators can be avoided.
根据第一方面的第三种可能的实现方式,在第六种可能的实现方式中,如果所述第一分区中的所述第一计算图的算子的数目和所述第二计算图的算子的数目不同,所述第一分区中还包括伪算子;其中,伪算子为不具备算子类型和操作数的算子;如果所述第一分区中的所述第一计算图的算子的数目少于所述第一分区中的所述第二计算图的算子数目,所述伪算子在所述第一足迹矩阵中对应的行或列,位于所述第一计算图中属于所述第一分区的算子对应的行或列之后;如果所述第一分区中的所述第二计算图的算子的数目少于所述第一分区中的所述第一计算图的算子数目,所述伪算子在所述第二足迹矩阵中对应的行或列,位于所述第二计算图中属于所述第一分区的算子对应的行或列之后。According to a third possible implementation manner of the first aspect, in a sixth possible implementation manner, if the number of operators of the first computation graph in the first partition and the number of operators of the second computation graph The number of operators is different, and the first partition also includes pseudo operators; wherein, the pseudo operators are operators that do not have operator types and operands; if the first calculation graph in the first partition The number of operators is less than the number of operators in the second computation graph in the first partition, and the pseudo operator in the first footprint matrix corresponding to the row or column is located in the first After the row or column corresponding to the operator belonging to the first partition in the graph; if the number of operators in the second computation graph in the first partition is less than the number of operators in the first partition The number of operators in the calculation graph. The row or column corresponding to the pseudo operator in the second footprint matrix is located after the row or column corresponding to the operator belonging to the first partition in the second calculation graph.
根据第一方面的第三种或第五种可能的实现方式,在第七种可能的实现方式中,如果所述第二分区中的所述第一计算图的算子的数目和所述第二计算图的算子的数目不同,所述第二分区中还包括所述伪算子;如果所述第二分区中的所述第一计算图的算子的数目少于所述第二分区中的所述第二计算图的算子数目,所述伪算子在所述第一足迹矩阵中对应的行和列与所述第一计算图中属于所述第二分区的算子对应的行和列随机排序,且行和列随机排序的方式相同;如果所述第二分区中的所述第二计算图的算子的数目少于所述第二分区中的所述第二计算图的算子数目,所述伪算子在所述第二足迹矩阵中对应的行和列与所述第二计算图中属于所述第二分区的算子对应的行和列随机排序,且行和列随机排序的方式相同。According to the third or fifth possible implementation manner of the first aspect, in a seventh possible implementation manner, if the number of operators of the first computation graph in the second partition and the number of the The number of operators in the two computation graphs is different, the second partition also includes the pseudo-operator; if the number of operators in the first computation graph in the second partition is less than that in the second partition The number of operators in the second computation graph in the pseudo-operator, the rows and columns corresponding to the pseudo-operators in the first footprint matrix correspond to the operators belonging to the second partition in the first computation graph Rows and columns are randomly ordered in the same way; if the number of operators in the second computation graph in the second partition is less than the number of operators in the second computation graph in the second partition The number of operators, the rows and columns corresponding to the pseudo operators in the second footprint matrix and the rows and columns corresponding to the operators belonging to the second partition in the second calculation graph are randomly ordered, and the rows and columns Random sorting works the same way.
在第一计算图和第二计算图的算子的数目不同时,通添加伪算子令第一计算图和第二计算图的算子总数相等,从而构造出大小相同的足迹矩阵,以令之后的矩阵运算得以正常进行。这样,本申请提供的算子映射方法可以应用于采用不同的计算图表示方式的框架或者系统之间迁移模型的场景下。When the number of operators in the first computation graph and the second computation graph is different, the total number of operators in the first computation graph and the second computation graph is equal by adding pseudo-operators, thereby constructing footprint matrices of the same size, so that Subsequent matrix operations proceed normally. In this way, the operator mapping method provided by the present application can be applied to the scenarios of frameworks or migration models between systems using different computational graph representations.
根据第一方面的第三种至第六种可能的实现方式中任意一种,在第八种可能的实现方式中,根据所述第一矩阵调整所述第一足迹矩阵中的行和列的顺序,包括:根据所述第一矩阵调整所述第一足迹矩阵中位于同一所述第一分区内的算子对应的行和列的顺序。According to any one of the third to sixth possible implementation manners of the first aspect, in an eighth possible implementation manner, the row and column values of the first footprint matrix are adjusted according to the first matrix. The order includes: adjusting the order of the rows and columns corresponding to the operators located in the same first partition in the first footprint matrix according to the first matrix.
根据第一方面的第三种至第六种可能的实现方式中任意一种,在第九种可能的实现方式中,属于同一第一分区、且在达到所述停止条件时的第一足迹矩阵和所述第二足迹矩阵中对应的行或列的位置相同的所述第一计算图的算子和第二计算图的算子之间存在映射关系;属于所述第二分区的第一计算图的算子与属于第二分区的第二计算图的多个算子之间存在映射关系,其中,所述属于第二分区的第二计算图的多个算子为:达到所述停止条件时的第一矩阵中,与所述属于所述第二分区的第一计算图的算子对应的元素的值中,最大的多个值所对应的第二计算图的算子。According to any one of the third to sixth possible implementation manners of the first aspect, in a ninth possible implementation manner, the first footprint matrix belonging to the same first partition and when the stopping condition is reached There is a mapping relationship between the operators of the first calculation graph and the operators of the second calculation graph that have the same position as the corresponding row or column in the second footprint matrix; the first calculation belonging to the second partition There is a mapping relationship between the operators of the graph and multiple operators of the second calculation graph belonging to the second partition, wherein the multiple operators of the second calculation graph belonging to the second partition are: reaching the stop condition In the first matrix when , among the values of the elements corresponding to the operators of the first computation graph belonging to the second partition, the operators of the second computation graph corresponding to the largest values.
根据本申请上述实施方式的映射方式,可以支持相似结构的计算图之间的算子映射,支持一对一、一对多和多对多的映射,能够适用于深度学习框架进行模型迁移的场景中。According to the mapping method of the above-mentioned embodiments of the present application, it is possible to support operator mapping between computational graphs with similar structures, support one-to-one, one-to-many, and many-to-many mappings, and can be applied to scenarios where deep learning frameworks perform model migration middle.
根据第一方面或第一方面的第一种至第八种可能的实现方式中任意一种,在第十种可能的实现方式中,所述停止条件为所述重复计算第一矩阵的次数大于第一阈值。According to the first aspect or any one of the first to eighth possible implementation manners of the first aspect, in a tenth possible implementation manner, the stopping condition is that the number of times of repeatedly calculating the first matrix is greater than first threshold.
通过对第一计算图和第二计算图中的算子进行同质分区,并且在调整第一足迹矩阵中的行和列的顺序时,调整位于同一同质分区的算子对应的行和列的顺序,可以更快速使迭代的过程收敛,加快映射的过程。这是由于同质算子的相似性更高,同质算子之间存在映射关系的可能性更大,因此,通过进行同质分区的过程可以加速迭代收敛的速度,加快映射的过程。By performing homogeneous partitioning on the operators in the first computational graph and the second computational graph, and when adjusting the order of the rows and columns in the first footprint matrix, adjust the rows and columns corresponding to the operators located in the same homogeneous partition order can make the iterative process converge faster and speed up the mapping process. This is because the similarity of homogenous operators is higher, and there is a greater possibility of a mapping relationship between homogenous operators. Therefore, the process of homogenous partitioning can accelerate the speed of iterative convergence and the process of mapping.
第二方面,本申请的实施例提供了一种计算图的算子映射装置,用于对第一计算图和第二计算图中的算子进行算子映射,所述第一计算图和所述第二计算图为同一个神经网络模型的计算图,所述算子映射装置包括:迭代模块,用于基于第一足迹矩阵和第二足迹矩阵,重复下述过程,直到达到停止条件:根据所述第一足迹矩阵和所述第二足迹矩阵计算第一矩阵,并根据所述第一矩阵调整所述第一足迹矩阵中的行和列的顺序,根据调整后的第一足迹矩阵 和所述第二足迹矩阵重新计算所述第一矩阵;其中,所述第一足迹矩阵指示所述第一计算图的算子之间的拓扑关系,所述第二足迹矩阵指示所述第二计算图的算子之间的拓扑关系,所述第一矩阵指示所述第一计算图和所述第二计算图的拓扑关系的相似度;对应模块,用于根据达到所述停止条件时的第一足迹矩阵、所述第二足迹矩阵,得到所述第一计算图中的多个算子各自在第二计算图中对应的算子。In a second aspect, embodiments of the present application provide an operator mapping device for a computation graph, which is used to perform operator mapping on operators in a first computation graph and a second computation graph, the first computation graph and all The second calculation graph is the calculation graph of the same neural network model, and the operator mapping device includes: an iterative module for repeating the following process based on the first footprint matrix and the second footprint matrix until the stopping condition is reached: The first footprint matrix and the second footprint matrix calculate a first matrix, and adjust the order of rows and columns in the first footprint matrix according to the first matrix, and according to the adjusted first footprint matrix and all recompute the first matrix with the second footprint matrix; wherein, the first footprint matrix indicates the topological relationship between the operators of the first computation graph, and the second footprint matrix indicates the second computation graph The topological relationship between the operators of The footprint matrix and the second footprint matrix are used to obtain the operators corresponding to each of the multiple operators in the first calculation graph in the second calculation graph.
本申请提供的实施例的算子映射装置,通过构建两个计算图的足迹矩阵,足迹矩阵为表示计算图的算子之间的拓扑关系的矩阵。根据两个计算图对应的足迹矩阵可以迭代计算第一矩阵,第一矩阵指示两个计算图的拓扑关系的相似度,迭代停止后,可根据足迹矩阵确定优选的一种或多种映射关系。因此,本申请提供的算子映射方法可以支持相似结构的计算图之间的算子映射,能够适用于深度学习框架进行模型迁移的场景中。The operator mapping apparatus of the embodiments provided by the present application constructs footprint matrices of two computation graphs, where the footprint matrix is a matrix representing the topological relationship between operators in the computation graph. The first matrix can be iteratively calculated according to the footprint matrices corresponding to the two computation graphs, and the first matrix indicates the similarity of the topological relationship between the two computation graphs. After the iteration is stopped, one or more preferred mapping relationships can be determined according to the footprint matrix. Therefore, the operator mapping method provided by the present application can support operator mapping between calculation graphs with similar structures, and can be applied to a scenario where a deep learning framework performs model migration.
根据第二方面的第一种可能的实现方式中,所述迭代模块包括:According to a first possible implementation manner of the second aspect, the iteration module includes:
计算单元,用于根据多个第一特征向量和多个第二特征向量,得到所述第一矩阵,其中,每个所述第一特征向量对应所述第一计算图中的算子,每个所述第一特征向量与所述第一特征向量对应的算子在所述第一足迹矩阵中对应的行向量与列向量有关,每个所述第二特征向量对应所述第二计算图中的算子,每个所述第二特征向量与所述第二特征向量对应的算子在所述第二足迹矩阵中对应的行向量与列向量有关,所述第一特征向量和所述第二特征向量用于计算所述第一特征向量对应的算子和所述第二特征向量对应的算子之间的拓扑关系的相似度。The calculation unit is configured to obtain the first matrix according to a plurality of first eigenvectors and a plurality of second eigenvectors, wherein each of the first eigenvectors corresponds to an operator in the first calculation graph, and each Each of the first eigenvectors and the operators corresponding to the first eigenvectors are related to the row vectors and column vectors in the first footprint matrix, and each of the second eigenvectors corresponds to the second calculation graph The operators in , each of the second eigenvectors and the operators corresponding to the second eigenvectors are related to the row vectors and column vectors in the second footprint matrix, and the first eigenvectors and the The second eigenvector is used to calculate the similarity of the topological relationship between the operator corresponding to the first eigenvector and the operator corresponding to the second eigenvector.
根据第二方面的第一种可能的实现方式,在第二种可能的实现方式中,所述第一矩阵的元素的值表示所述元素所在的行对应的算子和所在的列对应的算子的拓扑关系的相似度,其中,所述元素所在行对应的算子和所述元素所在列对应的算子分别为所述第一计算图中的算子和所述第二计算图中的算子。According to the first possible implementation manner of the second aspect, in the second possible implementation manner, the value of the element of the first matrix represents the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located similarity of the topological relationship of the elements, wherein the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located are respectively the operator in the first calculation graph and the operator in the second calculation graph operator.
采用算子在计算图对应的足迹矩阵中对应的行向量和列向量构建算子的特征向量,提取了算子在计算图中的拓扑关系特征。根据算子的特征向量计算算子的拓扑关系的相似度,第一计算图的算子和第二计算图的算子的拓扑关系的相似度组成相似度矩阵,通过相似度矩阵衡量两个计算图的拓扑关系的相似度。The eigenvectors of the operator are constructed by using the corresponding row and column vectors in the footprint matrix corresponding to the operator in the calculation graph, and the topological relationship characteristics of the operator in the calculation graph are extracted. The similarity of the topological relationship of the operator is calculated according to the eigenvector of the operator, and the similarity of the topological relationship of the operator of the first calculation graph and the operator of the second calculation graph forms a similarity matrix, and the similarity matrix is used to measure the two calculations. The similarity of the topological relationships of the graphs.
根据第二方面、或第二方面的第一种或第二种可能的实现方式,在第三种可能的实现方式中,所述第一足迹矩阵、调整后的第一足迹矩阵与所述第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,也就是说,所述第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,调整后的第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同。According to the second aspect, or the first or second possible implementation manner of the second aspect, in a third possible implementation manner, the first footprint matrix, the adjusted first footprint matrix and the third The operator corresponding to the row at the same position and the operator corresponding to the column at the same position of the two footprint matrix are of the same type, and the dimensions of the tensors output by the operators are the same. That is, the first footprint matrix and the second footprint matrix have the same type. The operator corresponding to the row at the same position and the operator corresponding to the column at the same position of the footprint matrix are of the same type, and the dimension of the tensor output by the operator is the same, and the adjusted first footprint matrix and the second footprint matrix are the same. The operator corresponding to the row of the position, the operator corresponding to the column of the same position are of the same type, and the dimension of the tensor output by the operator is the same.
在构建第一足迹矩阵和第二足迹矩阵、以及调整第一足迹矩阵时,保证第一足迹矩阵和第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,也就是第一足迹矩阵和第二足迹矩阵相同位置的行对应的算子、相同位 置的列对应的算子在功能上是相同的。结合相似度矩阵衡量算子之间的拓扑关系的相似度。根据本申请提供的算子映射装置,可以从功能和拓扑关系上体现两个算子之间的映射关系,从而确保映射结果的正确性。When constructing the first footprint matrix and the second footprint matrix, and adjusting the first footprint matrix, ensure the type of the operator corresponding to the row at the same position and the type of the operator corresponding to the column at the same position of the first footprint matrix and the second footprint matrix The same, the dimensions of the tensors output by the operators are the same, that is, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns in the same position are functionally the same. Combine the similarity matrix to measure the similarity of the topological relationship between operators. According to the operator mapping device provided by the present application, the mapping relationship between two operators can be reflected in terms of functions and topological relationships, thereby ensuring the correctness of the mapping result.
根据第二方面、或第二方面的第一种或第二种可能的实现方式,在第四种可能的实现方式中,所述第一计算图和所述第二计算图中的算子分属于多个第一分区,同一第一分区的算子类型相同、且算子输出的张量的维度相同,每个第一分区中可以包括第一计算图和/或第二计算图的至少部分算子,所述第一计算图和所述第二计算图中的部分算子属于第二分区,所述第二分区中的算子类型不同和/或算子输出的张量的维度不同;所述第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子在同一第一分区、相同位置的列对应的算子在同一第一分区;且,属于同一第一分区的第一计算图的算子在所述第一足迹矩阵中对应的行或者列连续排列,属于同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或者列连续排列。According to the second aspect, or the first or second possible implementation manner of the second aspect, in a fourth possible implementation manner, the operators in the first computation graph and the second computation graph are divided into Belonging to multiple first partitions, the same first partition has the same operator type, and the dimensions of the tensors output by the operators are the same, and each first partition may include at least part of the first computation graph and/or the second computation graph An operator, where some operators in the first calculation graph and the second calculation graph belong to a second partition, and the types of operators in the second partition are different and/or the dimensions of the tensors output by the operators are different; The operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are in the same first partition, and the operators corresponding to the columns in the same position are in the same first partition; and, belong to the same first partition. The operators of the first computation graph are arranged in consecutive rows or columns in the first footprint matrix, and the operators of the second computation graph belonging to the same first partition are arranged in consecutive rows or columns in the second footprint matrix arrangement.
因为同质算子之间存在映射关系的可能性更大,并且,在本申请的实施例中,第一足迹矩阵和第二足迹矩阵相同位置的行或列对应的算子之间存在映射关系。因此,根据本申请提供的上述实施例,通过对第一计算图和第二计算图中的算子进行同质分区,并且在调整第一足迹矩阵中的行和列的顺序时,调整位于同一同质分区的算子对应的行和列的顺序,可以更快速使迭代的过程收敛,加快映射的过程。Because it is more likely that there is a mapping relationship between homogeneous operators, and in the embodiment of the present application, there is a mapping relationship between the operators corresponding to the rows or columns in the same position of the first footprint matrix and the second footprint matrix . Therefore, according to the above-mentioned embodiment provided by the present application, the operators in the first calculation graph and the second calculation graph are homogeneously partitioned, and when adjusting the order of the rows and columns in the first footprint matrix, adjust the The order of the rows and columns corresponding to the operators of the homogeneous partition can make the iterative process converge more quickly and speed up the mapping process.
对于不存在同质算子的算子,通设置混合分区进行分类并参与迭代计算的过程得到对应的算子相似度,在确定映射算子时,可以根据计算得到的相似度输出映射建议。从而可以支持相似结构的计算图之间的算子映射,并且还可以支持一对多或多对多的映射,能够适用于深度学习框架进行模型迁移的场景中。For operators without homogeneous operators, the corresponding operator similarity can be obtained by setting mixed partitions for classification and participating in the iterative calculation process. When determining the mapping operator, mapping suggestions can be output according to the calculated similarity. Therefore, it can support operator mapping between computational graphs with similar structures, and can also support one-to-many or many-to-many mapping, which can be applied to scenarios where deep learning frameworks perform model migration.
根据第二方面的第三种可能的实现方式,在第五种可能的实现方式中,所述第一足迹矩阵和所述第二足迹矩阵相同位置的行对应的算子的同质深度相同、相同位置的列对应的算子的同质深度相同,且属于同一第一分区的所述第一计算图的算子在所述第一足迹矩阵中对应的行或列按照算子的所述同质深度排序、同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或列按照算子的所述同质深度排序;其中,所述同质深度为:在计算图中所述算子所属的所有分支中,在所述算子之前与所述算子类型相同、输出的张量维度相同的算子的最大数目。According to a third possible implementation manner of the second aspect, in a fifth possible implementation manner, the homogeneous depths of the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are the same, The homogeneity depths of the operators corresponding to the columns in the same position are the same, and the corresponding rows or columns of the operators of the first calculation graph belonging to the same first partition in the first footprint matrix are the same as those of the operators. Homogeneous depth sorting, the rows or columns corresponding to the operators of the second computation graph of the same first partition in the second footprint matrix are sorted according to the homogeneous depth of the operators; wherein, the homogeneous depth is: The maximum number of operators before the operator that have the same type as the operator and the same output tensor dimension among all the branches to which the operator belongs in the calculation graph.
对同质分区中的算子按照同质深度进行排序,按照确定同质分区分别确定第一计算图的第一足迹矩阵和第二计算图的第二足迹矩阵。由于同质深度相同的算子之间存在映射关系的可能性更大,因此,根据本申请上述实施方式计算相似度矩阵的过程可以快速收敛,更快的确定算子之间的映射关系,加速映射的过程。并且,通过同质深度区分具有相同属性的算子,可以避免通过算子的名称区分属性相同的算子的不可靠性。The operators in the homogeneous partition are sorted according to the homogeneous depth, and the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph are respectively determined according to the homogeneous partition. Since it is more likely that there is a mapping relationship between operators with the same homogeneous depth, the process of calculating the similarity matrix according to the above-mentioned embodiments of the present application can quickly converge, and the mapping relationship between operators can be determined more quickly. the process of mapping. In addition, by distinguishing operators with the same attributes by homogeneous depth, the unreliability of distinguishing operators with the same attributes by the names of the operators can be avoided.
根据第二方面的第三种可能的实现方式,在第六种可能的实现方式中,如果所述第一分区中的所述第一计算图的算子的数目和所述第二计算图的算子的数目不同,所述第一分区中 还包括伪算子;其中,伪算子为不具备算子类型和操作数的算子;如果所述第一分区中的所述第一计算图的算子的数目少于所述第一分区中的所述第二计算图的算子数目,所述伪算子在所述第一足迹矩阵中对应的行或列,位于所述第一计算图中属于所述第一分区的算子对应的行或列之后;如果所述第一分区中的所述第二计算图的算子的数目少于所述第一分区中的所述第一计算图的算子数目,所述伪算子在所述第二足迹矩阵中对应的行或列,位于所述第二计算图中属于所述第一分区的算子对应的行或列之后。According to a third possible implementation manner of the second aspect, in a sixth possible implementation manner, if the number of operators of the first computation graph in the first partition and the number of operators of the second computation graph The number of operators is different, and the first partition also includes pseudo operators; wherein, the pseudo operators are operators that do not have operator types and operands; if the first calculation graph in the first partition The number of operators is less than the number of operators in the second computation graph in the first partition, and the pseudo operator in the first footprint matrix corresponding to the row or column is located in the first After the row or column corresponding to the operator belonging to the first partition in the graph; if the number of operators in the second computation graph in the first partition is less than the number of operators in the first partition The number of operators in the calculation graph. The row or column corresponding to the pseudo operator in the second footprint matrix is located after the row or column corresponding to the operator belonging to the first partition in the second calculation graph.
根据第二方面的第三种或第五种可能的实现方式,在第七种可能的实现方式中,如果所述第二分区中的所述第一计算图的算子的数目和所述第二计算图的算子的数目不同,所述第二分区中还包括所述伪算子;如果所述第二分区中的所述第一计算图的算子的数目少于所述第二分区中的所述第二计算图的算子数目,所述伪算子在所述第一足迹矩阵中对应的行和列与所述第一计算图中属于所述第二分区的算子对应的行和列随机排序,且行和列随机排序的方式相同;如果所述第二分区中的所述第二计算图的算子的数目少于所述第二分区中的所述第二计算图的算子数目,所述伪算子在所述第二足迹矩阵中对应的行和列与所述第二计算图中属于所述第二分区的算子对应的行和列随机排序,且行和列随机排序的方式相同。According to the third or fifth possible implementation manner of the second aspect, in a seventh possible implementation manner, if the number of operators of the first computation graph in the second partition and the number of the The number of operators in the two computation graphs is different, the second partition also includes the pseudo-operator; if the number of operators in the first computation graph in the second partition is less than that in the second partition The number of operators in the second computation graph in the pseudo-operator, the rows and columns corresponding to the pseudo-operators in the first footprint matrix correspond to the operators belonging to the second partition in the first computation graph Rows and columns are randomly ordered in the same way; if the number of operators in the second computation graph in the second partition is less than the number of operators in the second computation graph in the second partition The number of operators, the rows and columns corresponding to the pseudo operators in the second footprint matrix and the rows and columns corresponding to the operators belonging to the second partition in the second calculation graph are randomly ordered, and the rows and columns Random sorting works the same way.
在第一计算图和第二计算图的算子的数目不同时,通添加伪算子令第一计算图和第二计算图的算子总数相等,从而构造出大小相同的足迹矩阵,以令之后的矩阵运算得以正常进行。这样,本申请提供的算子映射方法可以应用于采用不同的计算图表示方式的框架或者系统之间迁移模型的场景下。When the number of operators in the first computation graph and the second computation graph is different, the total number of operators in the first computation graph and the second computation graph is equal by adding pseudo-operators, thereby constructing footprint matrices of the same size, so that Subsequent matrix operations proceed normally. In this way, the operator mapping method provided by the present application can be applied to the scenarios of frameworks or migration models between systems using different computational graph representations.
根据第二方面的第三种至第六种可能的实现方式中任意一种,在第八种可能的实现方式中,所述迭代模块还包括:调整单元,用于根据所述第一矩阵调整所述第一足迹矩阵中位于同一所述第一分区内的算子对应的行和列的顺序。According to any one of the third to sixth possible implementation manners of the second aspect, in an eighth possible implementation manner, the iteration module further includes: an adjustment unit, configured to adjust according to the first matrix The order of the rows and columns corresponding to the operators located in the same first partition in the first footprint matrix.
根据第二方面的第三种至第六种可能的实现方式中任意一种,在第九种可能的实现方式中,属于同一第一分区、且在达到所述停止条件时的第一足迹矩阵和所述第二足迹矩阵中对应的行或列的位置相同的所述第一计算图的算子和第二计算图的算子之间存在映射关系;属于所述第二分区的第一计算图的算子与属于第二分区的第二计算图的多个算子之间存在映射关系,其中,所述属于第二分区的第二计算图的多个算子为:达到所述停止条件时的第一矩阵中,与所述属于所述第二分区的第一计算图的算子对应的元素的值中,最大的多个值所对应的第二计算图的算子。According to any one of the third to sixth possible implementation manners of the second aspect, in a ninth possible implementation manner, the first footprint matrix belonging to the same first partition and when the stopping condition is reached There is a mapping relationship between the operators of the first calculation graph and the operators of the second calculation graph that have the same position as the corresponding row or column in the second footprint matrix; the first calculation belonging to the second partition There is a mapping relationship between the operators of the graph and multiple operators of the second calculation graph belonging to the second partition, wherein the multiple operators of the second calculation graph belonging to the second partition are: reaching the stop condition In the first matrix when , among the values of the elements corresponding to the operators of the first computation graph belonging to the second partition, the operators of the second computation graph corresponding to the largest values.
根据本申请上述实施方式的映射方式,可以支持相似结构的计算图之间的算子映射,支持一对一、一对多和多对多的映射,能够适用于深度学习框架进行模型迁移的场景中。According to the mapping method of the above-mentioned embodiments of the present application, it is possible to support operator mapping between computational graphs with similar structures, support one-to-one, one-to-many, and many-to-many mappings, and can be applied to scenarios where deep learning frameworks perform model migration middle.
根据第二方面或第二方面的第一种至第八种可能的实现方式中任意一种,在第十种可能的实现方式中,所述停止条件为所述重复计算第一矩阵的次数大于第一阈值。According to the second aspect or any one of the first to eighth possible implementation manners of the second aspect, in a tenth possible implementation manner, the stopping condition is that the number of times of repeatedly calculating the first matrix is greater than or equal to first threshold.
通过对第一计算图和第二计算图中的算子进行同质分区,并且在调整第一足迹矩阵中的行和列的顺序时,调整位于同一同质分区的算子对应的行和列的顺序,可以更快速使迭代的过程收敛,加快映射的过程。这是由于同质算子的相似性更高,同质算子之间存在映射关系 的可能性更大,因此,通过进行同质分区的过程可以加速迭代收敛的速度,加快映射的过程。By performing homogeneous partitioning on the operators in the first computational graph and the second computational graph, and when adjusting the order of the rows and columns in the first footprint matrix, adjust the rows and columns corresponding to the operators located in the same homogeneous partition order can make the iterative process converge faster and speed up the mapping process. This is because the similarity of homogeneous operators is higher, and there is a greater possibility of a mapping relationship between homogeneous operators. Therefore, the process of homogeneous partitioning can accelerate the speed of iterative convergence and the process of mapping.
第三方面,本申请的实施例提供了一种计算图的算子映射装置,包括:In a third aspect, an embodiment of the present application provides an operator mapping apparatus for a computational graph, including:
处理器;用于存储处理器可执行指令的存储器;其中,所述处理器被配置为执行所述指令时实现上述第一方面或者第一方面的多种可能的实现方式中的一种或几种的算子映射方法。A processor; a memory for storing processor-executable instructions; wherein the processor is configured to implement the first aspect or one or more of various possible implementations of the first aspect when executing the instructions A kind of operator mapping method.
第四方面,本申请的实施例提供了一种非易失性计算机可读存储介质,其上存储有计算机程序指令,所述计算机程序指令被处理器执行时实现上述第一方面或者第一方面的多种可能的实现方式中的一种或几种的算子映射方法。In a fourth aspect, embodiments of the present application provide a non-volatile computer-readable storage medium on which computer program instructions are stored, and when the computer program instructions are executed by a processor, the above-mentioned first aspect or the first aspect is implemented One or more of the multiple possible implementations of the operator mapping method.
第五方面,本申请的实施例提供了一种终端设备,该终端设备可以执行上述第一方面或者第一方面的多种可能的实现方式中的一种或几种的算子映射方法。In a fifth aspect, an embodiment of the present application provides a terminal device, where the terminal device can execute the first aspect or one or more of the operator mapping methods in multiple possible implementations of the first aspect.
第六方面,本申请的实施例提供了一种计算机程序产品,包括计算机可读代码,或者承载有计算机可读代码的非易失性计算机可读存储介质,当所述计算机可读代码在电子设备中运行时,所述电子设备中的处理器执行上述第一方面或者第一方面的多种可能的实现方式中的一种或几种的算子映射方法。In a sixth aspect, embodiments of the present application provide a computer program product, comprising computer-readable codes, or a non-volatile computer-readable storage medium carrying computer-readable codes, when the computer-readable codes are stored in an electronic When running in the device, the processor in the electronic device executes the first aspect or one or more of the operator mapping methods in the multiple possible implementation manners of the first aspect.
本申请的这些和其他方面在以下(多个)实施例的描述中会更加简明易懂。These and other aspects of the present application will be more clearly understood in the following description of the embodiment(s).
附图说明Description of drawings
包含在说明书中并且构成说明书的一部分的附图与说明书一起示出了本申请的示例性实施例、特征和方面,并且用于解释本申请的原理。The accompanying drawings, which are incorporated in and constitute a part of the specification, illustrate exemplary embodiments, features and aspects of the application and together with the description, serve to explain the principles of the application.
图1a和图1b分别示出根据本申请一实施例的应用场景的示意图。1a and 1b respectively show schematic diagrams of application scenarios according to an embodiment of the present application.
图2示出根据本申请一实施例的执行计算图的算子映射方法的设备的框图。FIG. 2 shows a block diagram of a device for performing an operator mapping method of a computational graph according to an embodiment of the present application.
图3示出根据本申请一实施例的计算图的算子映射方法的流程图。FIG. 3 shows a flowchart of an operator mapping method for a computation graph according to an embodiment of the present application.
图4示出根据本申请一示例的计算图的示意图。FIG. 4 shows a schematic diagram of a calculation graph according to an example of the present application.
图5a示出根据本申请一实施例的计算相似度的过程的流程图。Fig. 5a shows a flowchart of a process of calculating similarity according to an embodiment of the present application.
图5b示出根据本申请一实施例的调整足迹矩阵的行和列的顺序的方法的流程图。FIG. 5b shows a flowchart of a method for adjusting the order of rows and columns of a footprint matrix according to an embodiment of the present application.
图6示出根据本申请一实施例的步骤S300的方法的流程图。FIG. 6 shows a flowchart of the method of step S300 according to an embodiment of the present application.
图7示出根据本申请一实施例的同质分区的示意图。FIG. 7 shows a schematic diagram of a homogeneous partition according to an embodiment of the present application.
图8和图9分别示出根据本申请一实施例的确定同质算子的同质深度的示意图。FIG. 8 and FIG. 9 respectively show schematic diagrams of determining the homogeneity depth of a homogeneity operator according to an embodiment of the present application.
图10示出根据本申请一实施例的插入伪算子的示例。FIG. 10 shows an example of an insertion pseudo-operator according to an embodiment of the present application.
图11示出根据本申请一实施例的算子映射方法的流程图。FIG. 11 shows a flowchart of an operator mapping method according to an embodiment of the present application.
图12示出根据本申请一实施例的确定最短距离的示意图。FIG. 12 shows a schematic diagram of determining the shortest distance according to an embodiment of the present application.
图13示出根据本申请一实施例的调整足迹矩阵的示意图。FIG. 13 shows a schematic diagram of adjusting the footprint matrix according to an embodiment of the present application.
图14示出根据本申请一实施例的迭代计算的效果的示意图。FIG. 14 shows a schematic diagram of the effect of iterative calculation according to an embodiment of the present application.
图15示出根据本申请一实施例的迭代计算的效果的示意图。FIG. 15 shows a schematic diagram of the effect of iterative calculation according to an embodiment of the present application.
图16示出根据本申请一实施例的计算图的算子映射装置的框图。FIG. 16 shows a block diagram of an operator mapping apparatus for a computation graph according to an embodiment of the present application.
图17示出根据本申请一实施例的算子映射装置的框图。FIG. 17 shows a block diagram of an operator mapping apparatus according to an embodiment of the present application.
具体实施方式Detailed ways
以下将参考附图详细说明本申请的各种示例性实施例、特征和方面。附图中相同的附图标记表示功能相同或相似的元件。尽管在附图中示出了实施例的各种方面,但是除非特别指出,不必按比例绘制附图。Various exemplary embodiments, features and aspects of the present application will be described in detail below with reference to the accompanying drawings. The same reference numbers in the figures denote elements that have the same or similar functions. While various aspects of the embodiments are shown in the drawings, the drawings are not necessarily drawn to scale unless otherwise indicated.
在这里专用的词“示例性”意为“用作例子、实施例或说明性”。这里作为“示例性”所说明的任何实施例不必解释为优于或好于其它实施例。The word "exemplary" is used exclusively herein to mean "serving as an example, embodiment, or illustration." Any embodiment described herein as "exemplary" is not necessarily to be construed as preferred or advantageous over other embodiments.
另外,为了更好的说明本申请,在下文的具体实施方式中给出了众多的具体细节。本领域技术人员应当理解,没有某些具体细节,本申请同样可以实施。在一些实例中,对于本领域技术人员熟知的方法、手段、元件和电路未作详细描述,以便于凸显本申请的主旨。In addition, in order to better illustrate the present application, numerous specific details are given in the following detailed description. It should be understood by those skilled in the art that the present application may be practiced without certain specific details. In some instances, methods, means, components and circuits well known to those skilled in the art have not been described in detail so as not to obscure the subject matter of the present application.
名词解释:Glossary:
算子:计算图中的运算单元,一个算子用于完成一类运算逻辑,本申请中的算子可以理解为一个函数空间到另一个函数空间上的映射:y=f(x),也就是广义上认为的算子。计算图中可以包括多种不同类型的算子,算子的类型是指算子可以进行的运算逻辑的类型。本申请中,算子可以指示一类基本的运算逻辑,基本的运算逻辑无法再拆分,例如Add(加)、Multi(乘)等等。算子也可以指示一类复杂的运算逻辑,复杂的运算逻辑可以表达为一组基本的运算逻辑的组合。这样,复杂的运算逻辑就可以通过多种算子来指示,每种算子对应不同的基本的运算逻辑的组合方式。而这多种算子就具有相同的功能,这多种算子组成的一组算子可以视为完成上述复杂的运算逻辑的一个算子,这多种算子组成的一组算子可能另一组算子具有相同功能的算子的同质算子。例如:Conv(卷积)算子、sigmoid算子等,其中,conv算子可以由加法算子和乘法算子组成。Operator: An operation unit in a calculation graph. An operator is used to complete a type of operation logic. An operator in this application can be understood as a mapping from one function space to another function space: y=f(x), also It is an operator in a broad sense. A calculation graph can include many different types of operators, and the type of the operator refers to the type of operation logic that the operator can perform. In this application, an operator may indicate a type of basic operation logic, and the basic operation logic cannot be split, such as Add (add), Multi (multiply), and so on. An operator can also indicate a kind of complex operation logic, and the complex operation logic can be expressed as a combination of a group of basic operation logic. In this way, complex operation logic can be indicated by a variety of operators, and each operator corresponds to a different combination of basic operation logic. These various operators have the same function. A group of operators composed of these various operators can be regarded as an operator that completes the above-mentioned complex operation logic. A group of operators composed of these various operators may be another operator. A homogeneous operator of a set of operators with the same function. For example: Conv (convolution) operator, sigmoid operator, etc., wherein, the conv operator can be composed of an addition operator and a multiplication operator.
张量:在本申请中,张量是对存储的一块数据的特征的描述,张量记录了数据的形状、类型等信息。本申请实施例中,张量可以理解为张量数据或者算子的操作数,可以包括神经网络中算子的输入操作数、输出操作数,也可以包括特征张量数据等。以人工智能深度学习框架TensorFlow为例,一般使用阶(rank)、形状(shape)和维数(dimension number)来描述张量的维度。Tensor: In this application, a tensor is a description of the characteristics of a piece of data stored, and a tensor records information such as the shape and type of the data. In this embodiment of the present application, a tensor may be understood as tensor data or an operand of an operator, which may include input operands and output operands of an operator in a neural network, and may also include feature tensor data and the like. Taking the artificial intelligence deep learning framework TensorFlow as an example, generally use rank (rank), shape (shape) and dimension (dimension number) to describe the dimension of the tensor.
数值档案:记录深度学习模型算子在运算过程中的输出张量数据(操作数)的档案。Numerical file: A file that records the output tensor data (operands) of the deep learning model operator during the operation.
算子映射:对应于同一个模型的两个计算图中,一个计算图的一个算子跟另一个计算图的一个算子在功能上及拓扑关系上有等价对应关系,这也就是说,两个计算图中的两个算子之间在功能上以及拓扑关系上等价的对应关系。Operator mapping: In two computation graphs corresponding to the same model, an operator in one computation graph has an equivalent correspondence in function and topology with an operator in the other computation graph. That is to say, A functionally and topologically equivalent correspondence between two operators in two computation graphs.
同质算子:两个具有完全相同属性的算子称为同质算子,在深度学习模型中算子的属性可以是指算子的类型及输出张量的维度。如果两个算子的类型相同、且两个算子输出的张量的维度也相同,那么,这两个算子为同质算子。也就是说,两个同质算子在功能上是相同的。在本申请中,同质算子所指的算子可以是指完成基本的、不可再拆分的运算逻辑的算子,也可以是一组算子,这组算子完成一种能够被拆分为基本的运算逻辑的复杂功能,这组算子和另外一组完成同样的功能,如果两组算子最终输出的张量的维度也相同,那么这两组算子也是同质算子。Homogeneous operator: Two operators with identical properties are called homogeneous operators. In a deep learning model, the properties of an operator can refer to the type of the operator and the dimension of the output tensor. If the two operators are of the same type and the dimensions of the tensors output by the two operators are the same, then the two operators are homogeneous operators. That is, two homogenous operators are functionally identical. In this application, the operator referred to by a homogeneous operator may refer to an operator that completes basic, non-splittable operation logic, or may be a group of operators that complete an operation that can be split. It is divided into complex functions of basic operation logic. This group of operators and another group perform the same function. If the dimensions of the final output tensors of the two groups of operators are also the same, then these two groups of operators are also homogeneous operators.
余弦相似性:两个非零向量之间夹角的余弦值,余弦值越大代表两个向量的指向越是接近,越相似。Cosine similarity: the cosine value of the angle between two non-zero vectors. The larger the cosine value, the closer and similar the two vectors are.
相似度矩阵:相似度矩阵中的数值表示该数值所在的行对应的算子与该数值所在的列对 应的算子的相似性,这两个算子可以为不同的计算图中的算子,比如说,该数值所在的行对应的算子为一个计算图的算子,该算子所在的列对应的算子为另一个计算图的算子。两个算子之间的相似性可以采用上述的余弦相似性衡量,,比如矩阵中的数值可以表示该数值所在的行对应的算子与该数值所在的列对应的算子的余弦相似性。Similarity matrix: The value in the similarity matrix represents the similarity between the operator corresponding to the row where the value is located and the operator corresponding to the column where the value is located. These two operators can be operators in different calculation graphs. For example, the operator corresponding to the row where the value is located is an operator of a calculation graph, and the operator corresponding to the column where the operator is located is an operator of another calculation graph. The similarity between two operators can be measured by the above cosine similarity. For example, a value in the matrix can represent the cosine similarity between the operator corresponding to the row where the value is located and the operator corresponding to the column where the value is located.
算子的余弦相似性:两个算子对应的特征向量之间夹角的余弦值。Cosine similarity of operators: the cosine value of the angle between the eigenvectors corresponding to two operators.
算子的特征向量:指示算子在计算图中与其他算子之间的拓扑关系的向量。The eigenvector of the operator: a vector indicating the topological relationship between the operator and other operators in the computational graph.
元素:矩阵中的每一个数均称为元素。Element: Each number in the matrix is called an element.
计算图中一个算子到另一个算子的距离:计算图中一个算子对应的节点到达另一个算子对应的节点的路径的长度。计算图中一个节点到达另一个节点之间的边的连线为可达路径,由于计算图为有向图,因此,计算图中两个直接相连的节点之间:父节点到子节点的路径(边)可达、路径长度为1,子节点到父节点不可达,子节点到父节点的路径的长度为0。计算图中一个节点到达另一个节点的路径的长度为这两个节点之间的一条可达路径的总长度。Calculate the distance from one operator to another in the graph: Calculate the length of the path from the node corresponding to one operator to the node corresponding to another operator in the graph. The connection between one node and another node in the computation graph is a reachable path. Since the computation graph is a directed graph, between two directly connected nodes in the computation graph: the path from the parent node to the child node (edge) is reachable, the path length is 1, the child node to the parent node is unreachable, and the length of the path from the child node to the parent node is 0. The length of the path from one node to another in the computation graph is the total length of a reachable path between the two nodes.
计算图中一个算子到另一个算子的最短距离:计算图中一个算子对应的节点到另一个算子对应的节点的路径的最短长度。Calculate the shortest distance from one operator to another in the graph: Calculate the shortest length of the path from the node corresponding to one operator to the node corresponding to another operator in the graph.
相关技术中,可以采用同构图算法确定两个图的节点的映射关系。但同构图算法只适用于完全同构的图之间节点的映射,对于相似结构的图,无法进行节点的映射,而且同构图算法也不支持多对多节点映射。而不同的深度学习框架中,计算图的表达方式不同,即使是相同的神经网络模型,在不同的深度学习框架中转换后也可能对应不同结构的计算图。因此,同构图算法无法适用于不同的深度学习框架进行模型迁移的场景。In the related art, an isomorphic graph algorithm can be used to determine the mapping relationship between nodes of two graphs. However, the isomorphic graph algorithm is only suitable for the mapping of nodes between completely isomorphic graphs. For graphs with similar structures, node mapping cannot be performed, and the isomorphic graph algorithm does not support many-to-many node mapping. In different deep learning frameworks, the expression of computational graphs is different. Even the same neural network model may correspond to computational graphs of different structures after conversion in different deep learning frameworks. Therefore, the isomorphic graph algorithm cannot be applied to different deep learning frameworks for model transfer scenarios.
为了解决上述技术问题,本申请提供了一种计算图的算子映射方法,通过构建两个计算图的足迹矩阵,足迹矩阵为表示计算图的算子之间的拓扑关系的矩阵,足迹矩阵中的元素的值为元素所在的行对应的算子到元素所在的列对应的算子的最短距离的倒数,或者足迹矩阵中的元素的值为元素所在的列对应的算子到元素所在的行对应的算子的最短距离的倒数。根据两个计算图对应的足迹矩阵可以迭代计算相似度矩阵,相似度矩阵指示两个计算图的拓扑关系的相似度,迭代停止后,可根据足迹矩阵确定优选的一种或多种映射关系。因此,本申请提供的算子映射方法可以支持相似结构的计算图之间的算子映射,能够适用于深度学习框架进行模型迁移的场景中。In order to solve the above-mentioned technical problems, the present application provides an operator mapping method of a computational graph. By constructing footprint matrices of two computational graphs, the footprint matrix is a matrix representing the topological relationship between the operators of the computational graph. The value of the element is the reciprocal of the shortest distance from the operator corresponding to the row where the element is located to the operator corresponding to the column where the element is located, or the value of the element in the footprint matrix is the operator corresponding to the column where the element is located to the row where the element is located. The reciprocal of the shortest distance of the corresponding operator. The similarity matrix can be iteratively calculated according to the footprint matrices corresponding to the two calculation graphs, and the similarity matrix indicates the similarity of the topological relationship between the two calculation graphs. After the iteration is stopped, one or more preferred mapping relationships can be determined according to the footprint matrix. Therefore, the operator mapping method provided by the present application can support operator mapping between calculation graphs with similar structures, and can be applied to a scenario where a deep learning framework performs model migration.
本申请实施例的计算图的算子映射方法主要是应用于神经网络的计算图,神经网络可以是用于图像识别、语音识别等的神经网络模型。本申请实施例的算子映射方法可以应用于在不同的深度学习框架之间进行神经网络模型迁移的场景中,也可以应用在相同的深度学习框架的不同版本之间进行神经网络模型迁移的场景中,或者不同硬件之间的神经网络的对比的场景中,以及比较训练和推理的结果的场景中,集成电路相关的设计图的比较、程序代码的计算图的比较,等等。本申请对具体的应用场景不作限定,只要是对以图论中图的形式表示的两个图之间的比较映射的场景即可。The operator mapping method of the computational graph in the embodiment of the present application is mainly applied to the computational graph of the neural network, and the neural network may be a neural network model used for image recognition, speech recognition, and the like. The operator mapping method in the embodiment of the present application can be applied to the scenario of performing neural network model migration between different deep learning frameworks, and can also be applied to the scenario of performing neural network model migration between different versions of the same deep learning framework In the scenario of comparing neural networks between different hardware, and in the scenario of comparing the results of training and inference, comparison of design diagrams related to integrated circuits, comparison of calculation diagrams of program codes, and so on. This application does not limit the specific application scenarios, as long as it is a scenario of comparison mapping between two graphs expressed in the form of graphs in graph theory.
以在不同的深度学习框架之间进行模型迁移的场景为例,图1a和图1b分别示出根据本申请一实施例的应用场景的示意图。图2示出根据本申请一实施例的执行计算图的算子映射方法的设备的框图。Taking a scenario of model migration between different deep learning frameworks as an example, FIG. 1 a and FIG. 1 b respectively show schematic diagrams of an application scenario according to an embodiment of the present application. FIG. 2 shows a block diagram of a device for performing an operator mapping method of a computational graph according to an embodiment of the present application.
如图1a所示为人工迁移的应用场景,在将模型从深度学习框架1迁移到深度学习框架2时,可以从深度学习框架1的模型脚本中导出对应的计算图1和数值档案1,其中,数值档案可以包括计算图中算子的操作数Tensor、权值等数据。开发人员可以根据深度学习框架1的模型脚本编写深度学习框架2的模型脚本,从深度学习框架2的模型脚本中导出对应的计算图2和数值档案2。Figure 1a shows the application scenario of manual migration. When the model is migrated from deep learning framework 1 to deep learning framework 2, the corresponding calculation diagram 1 and numerical file 1 can be derived from the model script of deep learning framework 1, in which , the numerical file can include data such as the operand Tensor and weight of the operator in the calculation graph. The developer can write the model script of the deep learning framework 2 according to the model script of the deep learning framework 1, and derive the corresponding calculation diagram 2 and the numerical file 2 from the model script of the deep learning framework 2.
如图2所示的设备可以为计算机、服务器等设备,图2所示的设备可以包括处理器和存储器,其中,处理器上可以搭载有操作系统,操作系统上层可以安装有计算图对比软件。处理器可以是现场可编程门阵列(field programmable gate array,FPGA),可以是专用集成芯片(application specific integrated circuit,ASIC),还可以是系统芯片(system on chip,SoC),还可以是中央处理器(central processor unit,CPU),还可以是网络处理器(network processor,NP),还可以是数字信号处理电路(digital signal processor,DSP),还可以是微控制器(micro controller unit,MCU),还可以是可编程控制器(programmable logic device,PLD)或其他集成芯片。The device shown in FIG. 2 may be a computer, a server, etc. The device shown in FIG. 2 may include a processor and a memory, wherein the processor may be equipped with an operating system, and the upper layer of the operating system may be installed with calculation graph comparison software. The processor can be a field programmable gate array (FPGA), an application specific integrated circuit (ASIC), a system on chip (SoC), or a central processing unit. It can be a central processor unit (CPU), a network processor (NP), a digital signal processing circuit (DSP), or a microcontroller (MCU) , it can also be a programmable logic device (PLD) or other integrated chips.
存储器可以是只读存储器(read-only memory,ROM)或可存储静态信息和指令的其他类型的静态存储设备,随机存取存储器(random access memory,RAM)或者可存储信息和指令的其他类型的动态存储设备,存储器也可以包括非易失性存储器(non-volatile memory),例如快闪存储器(flash memory),硬盘(hard disk drive,HDD)或固态硬盘(solid-state drive,SSD);存储器还可以包括上述种类的存储器的组合。存储器还可以是电可擦可编程只读存储器(electrically erasable programmable read-only memory,EEPROM)、只读光盘(compact disc read-only memory,CD-ROM)或其他光盘存储、光碟存储(包括压缩光碟、激光碟、光碟、数字通用光碟、蓝光光碟等)、磁盘存储介质或者其他磁存储设备、或者能够用于携带或存储具有指令或数据结构形式的期望的程序代码并能够由计算机存取的任何其他介质,但不限于此。存储器可以是独立存在,通过通信线路与处理器相连接,如图2所示的硬盘存储装置。存储器也可以和处理器集成在一起,如图2所示的内存。本申请实施例提供的存储器通常可以具有非易失性。其中,存储器用于存储执行本申请方案所涉及的计算机执行指令,并由处理器来控制执行。处理器用于执行存储器中存储的计算机执行指令,从而实现本申请实施例提供的方法。The memory can be read-only memory (ROM) or other types of static storage devices that can store static information and instructions, random access memory (RAM) or other types of storage devices that can store information and instructions Dynamic storage device, the memory can also include non-volatile memory (non-volatile memory), such as flash memory (flash memory), hard disk drive (hard disk drive, HDD) or solid-state drive (solid-state drive, SSD); memory Combinations of the above kinds of memories may also be included. The memory can also be electrically erasable programmable read-only memory (electrically erasable programmable read-only memory, EEPROM), compact disc read-only memory (CD-ROM) or other optical disk storage, optical disk storage (including compressed optical disks) , laser disc, compact disc, digital versatile disc, Blu-ray disc, etc.), magnetic disk storage medium or other magnetic storage device, or any other device capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer Other media, but not limited to this. The memory may exist independently and be connected to the processor through a communication line, such as the hard disk storage device shown in FIG. 2 . Memory can also be integrated with the processor, as shown in Figure 2. The memory provided by the embodiments of the present application may generally be non-volatile. The memory is used to store the computer-executed instructions involved in executing the solution of the present application, and the execution is controlled by the processor. The processor is configured to execute the computer-executed instructions stored in the memory, thereby implementing the method provided by the embodiments of the present application.
计算图对比软件可以是集成了本申请提供的方法的指令的集合,由处理器运行指令对输入的计算图进行处理可以实现计算图的算子之间的映射关系得到映射结果,并根据映射结果、计算图和数值档案可以对映射结果进行检测。The calculation graph comparison software can be a set of instructions that integrates the method provided by the present application, and the processing of the input calculation graph by the processor running the instruction can realize the mapping relationship between the operators of the calculation graph to obtain the mapping result, and according to the mapping result , computational graphs, and numerical archives to detect mapping results.
具体地,可以将导出的深度学习框架1的计算图1和数值档案1、深度学习框架2的计算图2和数值档案2输入到处理器中,处理器执行本申请提供的计算图的算子映射方法,可以找出深度学习框架1的计算图1和深度学习框架2的计算图2中的算子之间的映射关系(如图1a中的实线框所示的步骤为通过本申请提供的算子映射方法实现,图1a中虚线框所示的步骤为预处理得到计算图的过程或者根据映射结果进行后续的调整和处理的过程,属于本申请的应用场景的一部分,虚线框所示的步骤不是本申请的重点)。然后处理器可以根据映射关系比较对应的数值档案1和数值档案2中与算子对应的Tensor是否一致,将映射关系和数值 档案的比较结果作为对比报告输出。如果数值档案的比较结果为不一致,或者,开发人员根据映射关系判断计算图的主结构不一致,可以修改深度学习框架2的模型脚本,然后再次进行上述的过程,直到数值档案的比较结果为一致且计算图的主结构一致。Specifically, the derived calculation diagram 1 and numerical file 1 of the deep learning framework 1, and the calculation diagram 2 and numerical file 2 of the deep learning framework 2 can be input into the processor, and the processor executes the operators of the calculation diagram provided by this application. The mapping method can find out the mapping relationship between the operators in the calculation Figure 1 of the deep learning framework 1 and the calculation Figure 2 of the deep learning framework 2 (the steps shown in the solid line box in Figure 1a are provided by the present application. The operator mapping method of FIG. 1a is realized. The steps shown in the dotted box in Figure 1a are the process of preprocessing to obtain the calculation graph or the process of subsequent adjustment and processing according to the mapping result, which belong to a part of the application scenario of the present application. The dotted box shows steps are not the focus of this application). Then the processor can compare whether the Tensor corresponding to the operator in the corresponding numerical file 1 and numerical file 2 is consistent according to the mapping relationship, and output the comparison result between the mapping relationship and the numerical file as a comparison report. If the comparison result of the numerical files is inconsistent, or the developer judges that the main structure of the calculation graph is inconsistent according to the mapping relationship, the model script of the deep learning framework 2 can be modified, and then the above process is performed again until the comparison results of the numerical files are consistent and The main structure of the computation graph is consistent.
如图1b所示为自动迁移的应用场景,可以将深度学习框架1的模型脚本转换为Open Neural Network Exchange(ONNX,开放神经网络交换)格式的文件,ONNX格式是一个用于表示深度学习模型的标准,可以使模型在不同深度学习框架之间进行迁移。再利用脚本转换工具根据ONNX格式的文件进行转换,得到深度学习框架2的模型脚本。根据ONNX格式的文件可以导出计算图1,根据深度学习框架2的模型脚本可以导出计算图2,将计算图1和计算图2输入到图2所示的设备中,由处理器执行本申请提供的算子映射方法可以得到计算图1和计算图2中的算子的映射关系,并根据映射关系验证映射结果。Figure 1b shows the application scenario of automatic migration. The model script of the deep learning framework 1 can be converted into a file in the Open Neural Network Exchange (ONNX, Open Neural Network Exchange) format, which is a file used to represent deep learning models. A standard that enables models to be transferred between different deep learning frameworks. Then use the script conversion tool to convert the file in ONNX format to obtain the model script of the deep learning framework 2. According to the file in ONNX format, the calculation diagram 1 can be exported, and the calculation diagram 2 can be derived according to the model script of the deep learning framework 2. The calculation diagram 1 and the calculation diagram 2 are input into the device shown in FIG. 2, and the processor executes the application. The operator mapping method can obtain the mapping relationship of the operators in the calculation diagram 1 and the calculation diagram 2, and verify the mapping result according to the mapping relationship.
图1a和图1b所示的应用场景中,深度学习框架1和深度学习框架2可以是TensorFlow、PyTorch、MindSpore等中的任意一种。需要说明的是,以上图1a和图1b仅仅是本申请的应用场景的示例,不以任何方式限制本申请,本申请提供的实施例的算子映射方法还可以应用在其他应用场景中。In the application scenarios shown in Figure 1a and Figure 1b, the deep learning framework 1 and the deep learning framework 2 may be any of TensorFlow, PyTorch, MindSpore, and the like. It should be noted that the above FIG. 1a and FIG. 1b are only examples of application scenarios of the present application, and do not limit the present application in any way. The operator mapping methods provided in the embodiments of the present application may also be applied to other application scenarios.
图3示出根据本申请一实施例的计算图的算子映射方法的流程图。本申请提供的算子映射方法可以用于对第一计算图和第二计算图中的算子进行算子映射,其中,所述第一计算图和所述第二计算图为同一个神经网络模型的计算图,第一计算图和第二计算图可以是同一深度学习框架的不同版本对应的计算图,也可以是不同的深度学习框架对应的计算图,本申请对此不作限定。图3所示的方法步骤可以由图2中所示的处理器执行。FIG. 3 shows a flowchart of an operator mapping method for a computation graph according to an embodiment of the present application. The operator mapping method provided by the present application can be used to perform operator mapping on operators in a first calculation graph and a second calculation graph, wherein the first calculation graph and the second calculation graph are the same neural network The computation graph of the model, the first computation graph and the second computation graph may be computation graphs corresponding to different versions of the same deep learning framework, or may be computation graphs corresponding to different deep learning frameworks, which are not limited in this application. The method steps shown in FIG. 3 may be performed by the processor shown in FIG. 2 .
如图3所示,本申请提供的一实施例的计算图的算子映射方法可以包括以下步骤:As shown in FIG. 3 , the operator mapping method for a computational graph according to an embodiment of the present application may include the following steps:
步骤S300,基于第一足迹矩阵和第二足迹矩阵,重复下述过程,直到达到停止条件:根据所述第一足迹矩阵和所述第二足迹矩阵计算第一矩阵,并根据所述第一矩阵调整所述第一足迹矩阵中的行和列的顺序,根据调整后的第一足迹矩阵和所述第二足迹矩阵重新计算所述第一矩阵。Step S300, based on the first footprint matrix and the second footprint matrix, repeat the following process until a stop condition is reached: calculate a first matrix according to the first footprint matrix and the second footprint matrix, and calculate the first matrix according to the first footprint matrix The order of rows and columns in the first footprint matrix is adjusted, and the first matrix is recalculated according to the adjusted first footprint matrix and the second footprint matrix.
其中,所述第一足迹矩阵指示所述第一计算图的算子之间的拓扑关系,所述第二足迹矩阵指示所述第二计算图的算子之间的拓扑关系,所述第一矩阵指示所述第一计算图和所述第二计算图的拓扑关系的相似度。Wherein, the first footprint matrix indicates a topological relationship between operators in the first computation graph, the second footprint matrix indicates a topological relationship among operators in the second computation graph, and the first footprint matrix indicates a topological relationship between operators in the second computation graph. The matrix indicates the similarity of the topological relationship of the first computational graph and the second computational graph.
步骤S301,根据达到所述停止条件时的第一足迹矩阵、所述第二足迹矩阵,得到所述第一计算图中的多个算子各自在第二计算图中对应的算子。Step S301 , according to the first footprint matrix and the second footprint matrix when the stopping condition is reached, obtain operators corresponding to each of the multiple operators in the first calculation graph in the second calculation graph.
在一种可能的实现方式中,第一足迹矩阵的元素的值可以为该元素所在的行对应的算子到该元素所在的列对应的算子的最短距离的倒数,第一足迹矩阵通过第一计算图中算子到算子的最短距离的倒数描述第一计算图的算子之间的拓扑关系。第二足迹矩阵中的元素的值可以为该元素所在的行对应的算子到该元素所在的列对应的算子的最短距离的倒数,第二足迹矩阵通过第二计算图中算子到算子的最短距离的倒数描述第二计算图的算子之间的拓扑关系。In a possible implementation manner, the value of an element of the first footprint matrix may be the reciprocal of the shortest distance from the operator corresponding to the row where the element is located to the operator corresponding to the column where the element is located. The reciprocal of the shortest distance from operator to operator in a computation graph describes the topological relationship between operators in the first computation graph. The value of an element in the second footprint matrix can be the reciprocal of the shortest distance from the operator corresponding to the row where the element is located to the operator corresponding to the column where the element is located. The reciprocal of the shortest distance of the children describes the topological relationship between the operators of the second computational graph.
在一种可能的实现方式中,处理器可以分别遍历第一计算图和第二计算图中的每个算子,确定每个算子到所在的计算图中其他算子的最短距离。具体地,处理器可以将遍历的算子作为起点,对计算图进行深度优先遍历(Depth-First-Search,DFS),确定该算子到其他算子的最短距离。由于第一计算图和第二计算图都是有向图,因此,有些算子到其他算子是不可达的,这种情况下,算子到不可达算子的最短距离可以确定为无穷大,算子到不可达算子的最短距离的倒数为0,因此,算子在足迹矩阵中对应的元素值为0。另外,如果一个算子到另外一个算子存在不止一条路径,而且这些路径的距离不相同,可以确定其中距离最短的路径对应的距离为该算子到另一个算子的最短距离。算子到自身的最短距离的倒数为0。In a possible implementation manner, the processor may traverse each operator in the first computation graph and the second computation graph respectively, and determine the shortest distance from each operator to other operators in the computation graph. Specifically, the processor may use the traversed operator as a starting point, perform a depth-first-search (DFS) on the computation graph, and determine the shortest distance from the operator to other operators. Since the first computation graph and the second computation graph are both directed graphs, some operators are unreachable from other operators. In this case, the shortest distance from the operator to the unreachable operator can be determined to be infinite. The reciprocal of the shortest distance from the operator to the unreachable operator is 0, so the corresponding element value of the operator in the footprint matrix is 0. In addition, if there is more than one path from an operator to another operator, and the distances of these paths are different, it can be determined that the distance corresponding to the path with the shortest distance is the shortest distance from the operator to the other operator. The reciprocal of the operator's shortest distance to itself is 0.
图4示出根据本申请一示例的计算图的示意图。以图4为例说明本申请实施例根据计算图确定足迹矩阵的过程,假设图4所示的计算图为第一计算图。FIG. 4 shows a schematic diagram of a calculation graph according to an example of the present application. Taking FIG. 4 as an example, the process of determining the footprint matrix according to the calculation graph in the embodiment of the present application is described. It is assumed that the calculation graph shown in FIG. 4 is the first calculation graph.
处理器以节点(算子)A为起点进行深度优先遍历,可以得到算子A到其他算子B、C、D、E和F的最短距离分别为:1、2、3、2、3。对于其中的算子E,A有两条路径可以到达算子E,两条路径的距离分别为2和3,因此,算子A到算子E的最短距离为2。The processor performs depth-first traversal with node (operator) A as the starting point, and the shortest distances from operator A to other operators B, C, D, E, and F are obtained as: 1, 2, 3, 2, and 3, respectively. For operator E, A has two paths to reach operator E, and the distances of the two paths are 2 and 3 respectively. Therefore, the shortest distance from operator A to operator E is 2.
处理器以节点B为起点进行深度优先遍历,可以得到节点B到节点A、C、D、E和F的最短距离分别为:∞、∞、∞、1、2。The processor performs depth-first traversal with node B as the starting point, and the shortest distances from node B to nodes A, C, D, E, and F can be obtained: ∞, ∞, ∞, 1, and 2, respectively.
处理器以节点C为起点进行深度优先遍历,可以得到节点C到节点A、B、D、E和F的最短距离分别为:∞、∞、1、2、3。The processor performs depth-first traversal with node C as the starting point, and the shortest distances from node C to nodes A, B, D, E and F can be obtained: ∞, ∞, 1, 2, and 3, respectively.
处理器以节点D为起点进行深度优先遍历,可以得到节点D到节点A、B、C、E和F的最短距离分别为:∞、∞、∞、1、2。The processor performs depth-first traversal with node D as the starting point, and the shortest distances from node D to nodes A, B, C, E, and F can be obtained: ∞, ∞, ∞, 1, and 2, respectively.
处理器以节点E为起点进行深度优先遍历,可以得到节点E到节点A、B、C、D和F的最短距离分别为:∞、∞、∞、∞、1。The processor performs depth-first traversal with node E as the starting point, and the shortest distances from node E to nodes A, B, C, D, and F can be obtained: ∞, ∞, ∞, ∞, and 1, respectively.
处理器以节点F为起点进行深度优先遍历,可以得到节点F到节点A、B、C、D和E的最短距离分别为:∞、∞、∞、∞、∞。每个节点到自己的最短距离都是∞。The processor performs depth-first traversal with node F as the starting point, and the shortest distances from node F to nodes A, B, C, D, and E can be obtained as ∞, ∞, ∞, ∞, and ∞, respectively. The shortest distance from each node to itself is ∞.
根据以上过程可知,图4所示的第一计算图的第一足迹矩阵可以为:According to the above process, the first footprint matrix of the first calculation graph shown in FIG. 4 may be:
   AA BB CC DD E E FF
AA 00 11 1/21/2 1/31/3 1/21/2 1/31/3
B B 00 00 00 00 11 1/21/2
C C 00 00 00 11 1/21/2 1/31/3
D D 00 00 00 00 11 1/21/2
E E 00 00 00 00 00 11
F F 00 00 00 00 00 00
根据以上过程可以确定第一计算图的第一足迹矩阵、第二计算图的第二足迹矩阵,需要说明的是,图4所示仅仅是本申请的一个示例,不以任何方式限制本申请。According to the above process, the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph can be determined. It should be noted that, what is shown in FIG. 4 is only an example of the present application, and does not limit the present application in any way.
在一种可能的实现方式中,处理器在遍历算子到其他算子的最短距离时,若最短距离超过最大访问距离,可以将两个算子之间的最短距离的倒数设置为0。其中,最大访问距离可以是为了限制计算量而设置的距离阈值,比如说在本申请的实施例中,可以设置最大访问距离为15。当其他算子到起点的算子的最短距离超过最大访问距离时,该其他算子对作为起点的算子的拓扑结构的影响比较小,因此,可以忽略不计。这样,可以增加足迹矩阵的稀疏性,减少计算量。In a possible implementation manner, when the processor traverses the shortest distance from an operator to other operators, if the shortest distance exceeds the maximum access distance, the processor may set the reciprocal of the shortest distance between the two operators to 0. The maximum access distance may be a distance threshold set to limit the amount of calculation. For example, in the embodiment of the present application, the maximum access distance may be set to 15. When the shortest distance from other operators to the operator at the starting point exceeds the maximum access distance, the influence of the other operators on the topology of the operator as the starting point is relatively small, so it can be ignored. In this way, the sparsity of the footprint matrix can be increased and the amount of computation can be reduced.
在一种可能的实现方式中,可以通过余弦相似性衡量两个非零向量之间的相似度。其中,余弦相似性是指两个非零向量之间夹角的余弦值,余弦值越大代表两个向量的指向越是接近。举例来说,假设两个非零向量
Figure PCTCN2021127123-appb-000001
Figure PCTCN2021127123-appb-000002
余弦相似性可以表示为以下公式(1),
In one possible implementation, the similarity between two non-zero vectors can be measured by cosine similarity. Among them, cosine similarity refers to the cosine value of the angle between two non-zero vectors, and the larger the cosine value, the closer the two vectors are pointing. For example, suppose two non-zero vectors
Figure PCTCN2021127123-appb-000001
and
Figure PCTCN2021127123-appb-000002
The cosine similarity can be expressed as the following formula (1),
Figure PCTCN2021127123-appb-000003
Figure PCTCN2021127123-appb-000003
本申请的实施例中,第一矩阵用于指示所述第一计算图和所述第二计算图的拓扑关系的相似度,因此,在本申请的实施例中,第一矩阵也可以被称作相似度矩阵(第一计算图和第二计算图的相似度矩阵)。在一种可能的实现方式中,第一矩阵中的元素的值表示所述元素所在的行对应的算子和所在的列对应的算子的拓扑关系的相似度。在本申请的实施例中,可以提取第一计算图的算子的特征和第二计算图的算子的特征、并以特征向量的形式表达,根据第一计算图的算子的特征向量和第二计算图的算子的特征向量,得到第一计算图的算子和第二计算图的算子的余弦相似性,来描述第一计算图的算子和第二计算图的算子的拓扑关系的相似度。In the embodiment of the present application, the first matrix is used to indicate the similarity of the topological relationship between the first calculation graph and the second calculation graph. Therefore, in the embodiment of the present application, the first matrix may also be called Make a similarity matrix (the similarity matrix of the first calculation graph and the second calculation graph). In a possible implementation manner, the value of the element in the first matrix represents the similarity of the topological relationship between the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located. In the embodiment of the present application, the feature of the operator of the first calculation graph and the feature of the operator of the second calculation graph can be extracted and expressed in the form of a feature vector, according to the feature vector of the operator of the first calculation graph and The eigenvectors of the operators of the second calculation graph are obtained, and the cosine similarity of the operators of the first calculation graph and the operators of the second calculation graph is obtained to describe the difference between the operators of the first calculation graph and the operators of the second calculation graph. similarity of topological relationships.
由于足迹矩阵是表示计算图的算子之间的拓扑关系的矩阵,因此,在一种可能的实现方式中,处理器可以根据足迹矩阵构建计算图中算子的特征向量,根据两个算子的特征向量的余弦相似性可以衡量两个算子之间的拓扑关系的相似性。Since the footprint matrix is a matrix representing the topological relationship between the operators of the computation graph, in a possible implementation manner, the processor may construct the eigenvectors of the operators in the computation graph according to the footprint matrix, and according to the two operators The cosine similarity of the eigenvectors can measure the similarity of the topological relationship between two operators.
在一种可能的实现方式中,步骤S300中的根据所述第一足迹矩阵和所述第二足迹矩阵计算所述第一矩阵,可以包括:In a possible implementation manner, calculating the first matrix according to the first footprint matrix and the second footprint matrix in step S300 may include:
根据多个第一特征向量和多个第二特征向量,得到所述第一矩阵,其中,每个所述第一特征向量对应所述第一计算图中的算子,每个所述第一特征向量与所述第一特征向量对应的算子在所述第一足迹矩阵中对应的行向量与列向量有关,每个所述第二特征向量对应所述第二计算图中的算子,每个所述第二特征向量与所述第二特征向量对应的算子在所述第二足迹矩阵中对应的行向量与列向量有关,所述第一特征向量和所述第二特征向量用于计算所述第一特征向量对应的算子和所述第二特征向量对应的算子之间的拓扑关系的相似度。The first matrix is obtained according to a plurality of first eigenvectors and a plurality of second eigenvectors, wherein each of the first eigenvectors corresponds to an operator in the first calculation graph, and each of the first eigenvectors corresponds to an operator in the first calculation graph. The row vector corresponding to the operator corresponding to the eigenvector and the first eigenvector in the first footprint matrix is related to the column vector, and each of the second eigenvectors corresponds to the operator in the second calculation graph, Each of the second eigenvectors and the operator corresponding to the second eigenvectors are related to row vectors and column vectors in the second footprint matrix, and the first eigenvectors and the second eigenvectors are represented by for calculating the similarity of the topological relationship between the operator corresponding to the first eigenvector and the operator corresponding to the second eigenvector.
也就是说,第一计算图中的每个算子有该算子对应的第一特征向量,第一特征向量与算子在第一足迹矩阵中对应的行向量和列向量有关,第一计算图的算子在第一足迹矩阵中对应的行向量可以是指第一计算图的算子在第一足迹矩阵对应的行的行向量、对应的列向量可以是指第一计算图的算子在第一足迹矩阵对应的列的列向量。第二计算图中的每个算子都有该算子对应的第二特征向量,第二特征向量与算子在第二足迹矩阵中对应的行和列有关,第二 计算图的算子在第二足迹矩阵中对应的行向量可以是指第二计算图的算子在第二足迹矩阵对应的行的行向量、对应的列向量可以是指第二计算图的算子在第二足迹矩阵对应的列的列向量。That is to say, each operator in the first calculation graph has a first eigenvector corresponding to the operator, and the first eigenvector is related to the row vector and column vector corresponding to the operator in the first footprint matrix. The first calculation The row vector corresponding to the operator of the graph in the first footprint matrix may refer to the row vector of the operator of the first calculation graph in the row corresponding to the first footprint matrix, and the corresponding column vector may refer to the operator of the first calculation graph Column vector of the corresponding column in the first footprint matrix. Each operator in the second calculation graph has a second eigenvector corresponding to the operator. The second eigenvector is related to the row and column corresponding to the operator in the second footprint matrix. The operator of the second calculation graph is in The corresponding row vector in the second footprint matrix may refer to the row vector of the operator of the second computation graph in the row corresponding to the second footprint matrix, and the corresponding column vector may refer to the operator of the second computation graph in the second footprint matrix A column vector of corresponding columns.
换言之,处理器根据第一足迹矩阵中的行向量和列向量可以得到第一计算图中算子的第一特征向量,根据第二足迹矩阵中的行向量和列向量可以得到第二计算图中算子的第二特征相同。In other words, the processor can obtain the first eigenvector of the operator in the first calculation graph according to the row vector and the column vector in the first footprint matrix, and obtain the second calculation graph according to the row vector and column vector in the second footprint matrix The second characteristic of the operators is the same.
在一种可能的实现方式中,第一特征向量和所述第二特征向量用于计算所述第一特征向量对应的算子和所述第二特征向量对应的算子之间拓扑关系的相似度,可以是指,通过计算两个算子对应的第一特征向量和第二特征向量的余弦相似性,可以得到两个算子之间拓扑关系的相似度。比如说,计算第一计算图中的算子A的第一特征向量和第二计算图中的算子B的第二特征向量的余弦相似性作为算子A和算子B的拓扑关系的相似度。这样,第一矩阵的元素的值表示元素所在的行对应的算子和所在的列对应的算子的拓扑关系的相似度,其中,元素所在行对应的算子和元素所在列对应的算子分别为第一计算图中的算子和第二计算图中的算子。In a possible implementation manner, the first eigenvector and the second eigenvector are used to calculate the similarity of the topological relationship between the operator corresponding to the first eigenvector and the operator corresponding to the second eigenvector The degree may mean that the similarity of the topological relationship between the two operators can be obtained by calculating the cosine similarity of the first eigenvector and the second eigenvector corresponding to the two operators. For example, calculate the cosine similarity of the first eigenvector of operator A in the first calculation graph and the second eigenvector of operator B in the second calculation graph as the similarity of the topological relationship between operator A and operator B Spend. In this way, the value of the element of the first matrix represents the similarity of the topological relationship between the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located, wherein the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located are the operators in the first calculation graph and the operators in the second calculation graph, respectively.
在一种可能的实现方式中,第一矩阵的行对应的算子可以是第一计算图的算子、列对应的算子可以是第二计算图的算子,或者,在另一种可能的实现方式中,第一矩阵的行对应的算子可以是第二计算图的算子、列对应的算子可以是第一计算图的算子。In a possible implementation manner, the operator corresponding to the row of the first matrix may be the operator of the first calculation graph, and the operator corresponding to the column may be the operator of the second calculation graph, or, in another possibility In the implementation manner of , the operator corresponding to the row of the first matrix may be the operator of the second calculation graph, and the operator corresponding to the column may be the operator of the first calculation graph.
图5a示出根据本申请一实施例的计算第一矩阵的过程的流程图。FIG. 5a shows a flowchart of a process of calculating a first matrix according to an embodiment of the present application.
如图5a所示,在一种可能的实现方式中,根据多个第一特征向量和多个第二特征向量,得到所述第一矩阵,具体可以包括以下过程:As shown in FIG. 5a, in a possible implementation manner, obtaining the first matrix according to multiple first eigenvectors and multiple second eigenvectors may specifically include the following process:
步骤S3010,根据第一足迹矩阵确定第一计算图中的算子的第一特征向量,根据第二足迹矩阵确定第二计算图中的算子的第二特征向量;Step S3010, determining the first eigenvector of the operator in the first calculation graph according to the first footprint matrix, and determining the second eigenvector of the operator in the second calculation graph according to the second footprint matrix;
步骤S3011,根据第一特征向量和第二特征向量计算所述第一矩阵。Step S3011: Calculate the first matrix according to the first eigenvector and the second eigenvector.
在一种可能的实现方式中,处理器可以将算子在对应的足迹矩阵中所在行的行向量和所在列的列向量进行拼接,得到算子的特征向量,比如说,处理器可以将行向量中的元素拼接到列向量后面得到算子的特征向量,或者也可以将列向量中的元素拼接到行向量后面得到算子的特征向量,本申请对具体的拼接方式不作限定,但处理器对第一计算图中的算子的行向量和列向量的拼接方式与对第二计算图中的算子的行向量和列向量的拼接方式相同。In a possible implementation manner, the processor may concatenate the row vector of the row where the operator is located in the corresponding footprint matrix and the column vector of the column where the operator is located to obtain the feature vector of the operator. The elements in the vector are spliced behind the column vector to obtain the eigenvector of the operator, or the elements in the column vector can be spliced behind the row vector to obtain the eigenvector of the operator. This application does not limit the specific splicing method, but the processor The way of splicing the row vector and the column vector of the operator in the first calculation graph is the same as the way of splicing the row vector and the column vector of the operator in the second calculation graph.
举例来说,以图4所示的示例中的算子A为例,算子A在足迹矩阵中所在行为第一行,第一行向量为[0,1,1/2,1/3,1/2,1/3],算子A在足迹矩阵中所在列为第一列,第一列向量为[0,0,0,0,0,0],将列向量和行向量进行拼接可以得到算子A的特征向量为[0,0,0,0,0,0,0,1,1/2,1/3,1/2,1/3]。For example, taking operator A in the example shown in FIG. 4 as an example, the row where operator A is located in the footprint matrix is the first row, and the first row vector is [0,1,1/2,1/3, 1/2,1/3], the column where operator A is located in the footprint matrix is the first column, the first column vector is [0,0,0,0,0,0], and the column vector and row vector are spliced The eigenvectors of operator A can be obtained as [0,0,0,0,0,0,0,1,1/2,1/3,1/2,1/3].
在确定算子的特征向量后,根据公式(1)可以计算第一计算图中的算子的第一特征向量 和第二计算图中对应的算子的第二特征向量之间的余弦相似性,得到算子的相似度。第一计算图中的算子和第二计算图中的算子的相似度可以组成第一矩阵。After the eigenvectors of the operators are determined, the cosine similarity between the first eigenvectors of the operators in the first calculation graph and the second eigenvectors of the corresponding operators in the second calculation graph can be calculated according to formula (1). , to get the similarity of the operators. The similarity between the operators in the first calculation graph and the operators in the second calculation graph may form a first matrix.
举例来说,假设第一计算图为Q,第二计算图为R。For example, it is assumed that the first computational graph is Q and the second computational graph is R.
第一计算图Q的第一足迹矩阵为:The first footprint matrix of the first computation graph Q is:
   q(1)q(1) q(2)q(2) q(3)q(3) q(n-1)q(n-1) q(n)q(n)
q(1)q(1) 00
q(2)q(2) 00
q(3)q(3) 00
00
q(n-1)q(n-1) 00
q(n)q(n) 00
第二计算图R的第二足迹矩阵为:The second footprint matrix of the second computation graph R is:
   r(1)r(1) r(2)r(2) r(3)r(3) r(n-1)r(n-1) r(n)r(n)
r(1)r(1) 00
r(2)r(2) 00
r(3)r(3) 00
00
r(n-1)r(n-1) 00
r(n)r(n) 00
需要说明的是,可以将足迹矩阵中的行对应的算子作为访问路径的起点、列对应的算子作为访问路径的终点,也可以将足迹矩阵中的列对应的算子作为访问路径的起点、行对应的算子作为访问路径的终点,本申请对此不作限定。It should be noted that the operator corresponding to the row in the footprint matrix can be used as the starting point of the access path, the operator corresponding to the column can be used as the end point of the access path, or the operator corresponding to the column in the footprint matrix can be used as the starting point of the access path. The operator corresponding to the row is used as the end point of the access path, which is not limited in this application.
处理器可以根据上述第一足迹矩阵确定第一计算图中的算子q(1)、q(2)…q(n)的第一特征向量,根据上述第二足迹矩阵确定第二计算图中的算子r(1)、r(2)…r(n)的第二特征向量。The processor may determine the first eigenvectors of the operators q(1), q(2)...q(n) in the first calculation graph according to the above-mentioned first footprint matrix, and determine the second calculation graph according to the above-mentioned second footprint matrix. The second eigenvectors of the operators r(1), r(2)...r(n).
算子q(1)、q(2)…q(n)的第一特征向量可以表示为:The first eigenvectors of operators q(1), q(2)...q(n) can be expressed as:
Figure PCTCN2021127123-appb-000004
Figure PCTCN2021127123-appb-000004
Figure PCTCN2021127123-appb-000005
Figure PCTCN2021127123-appb-000005
以上表格中,算子所在的一列数据组成的向量可以表示算子的第一特征向量,粗实线以上可以为算子所在列的列向量,粗实线以下可以为算子所在的行的行向量拼接到列向量中得到的。In the above table, a vector formed by a column of data where the operator is located can represent the first eigenvector of the operator. Above the thick solid line can be the column vector of the column where the operator is located, and below the thick solid line can be the row of the row where the operator is located. The vector is concatenated into a column vector.
算子r(1)、r(2)…r(n)的第二特征向量可以表示为:The second eigenvectors of operators r(1), r(2)...r(n) can be expressed as:
Figure PCTCN2021127123-appb-000006
Figure PCTCN2021127123-appb-000006
以上表格中,算子所在的一列数据组成的向量可以表示算子的第二特征向量,粗实线以上可以为算子所在列的列向量,粗实线以下可以为算子所在的行的行向量拼接到列向量中得到的。In the above table, the vector formed by a column of data where the operator is located can represent the second eigenvector of the operator. Above the thick solid line can be the column vector of the column where the operator is located, and below the thick solid line can be the row of the row where the operator is located. The vector is concatenated into a column vector.
举例来说,算子q(1)和r(1)的相似性可以通过以下公式(2)计算得到:For example, the similarity of operators q(1) and r(1) can be calculated by the following formula (2):
Figure PCTCN2021127123-appb-000007
Figure PCTCN2021127123-appb-000007
其中,
Figure PCTCN2021127123-appb-000008
表示算子q(1)的第一特征向量,
Figure PCTCN2021127123-appb-000009
表示算子r(1)的第二特征向量,根据以上公式(2)可以计算得到算子q(1)和r(1)的相似度,第一计算图的算子和第二计算图的算子的相似度可以组成第一计算图和第二计算图的相似度矩阵,如下表所示:
in,
Figure PCTCN2021127123-appb-000008
represents the first eigenvector of the operator q(1),
Figure PCTCN2021127123-appb-000009
Represents the second eigenvector of operator r(1). According to the above formula (2), the similarity between operators q(1) and r(1) can be calculated. The operator of the first calculation graph and the second calculation graph of The similarity of operators can form the similarity matrix of the first calculation graph and the second calculation graph, as shown in the following table:
Figure PCTCN2021127123-appb-000010
Figure PCTCN2021127123-appb-000010
Figure PCTCN2021127123-appb-000011
Figure PCTCN2021127123-appb-000011
在步骤S300中,处理器根据第一矩阵调整第一足迹矩阵中的行和列的顺序,可以是指根据第一矩阵调整第一足迹矩阵中行与行之间的顺序、以及列与列之间的顺序,同时,保持第二足迹矩阵中行和列的顺序不变。需要说明的是,在本申请的实施方式中,调整第一足迹矩阵中行和列的顺序仅仅是本申请的一个示例,也可以调整第二足迹矩阵中行和列的顺序,同时保持第一足迹矩阵中行和列的顺序不变。In step S300, the processor adjusts the order of rows and columns in the first footprint matrix according to the first matrix, which may refer to adjusting the order between rows and rows and between columns and columns in the first footprint matrix according to the first matrix , while maintaining the order of rows and columns in the second footprint matrix. It should be noted that, in the embodiments of the present application, adjusting the order of rows and columns in the first footprint matrix is only an example of the present application, and it is also possible to adjust the order of rows and columns in the second footprint matrix while maintaining the first footprint matrix. The order of rows and columns remains unchanged.
在一种可能的实现方式中,处理器根据相似度矩阵调整第一足迹矩阵中的行和列的顺序的具体过程可以包括:处理器根据相似度矩阵确定第一计算图和第二计算图中算子之间的映射关系,根据所述映射关系调整第一足迹矩阵中与第一计算图的算子对应的行和列的顺序。In a possible implementation manner, the specific process that the processor adjusts the order of the rows and columns in the first footprint matrix according to the similarity matrix may include: the processor determines the first calculation graph and the second calculation graph according to the similarity matrix A mapping relationship between operators, according to which the order of rows and columns in the first footprint matrix corresponding to the operators of the first calculation graph is adjusted.
示例性的,处理器可以根据相似度矩阵中元素的值的大小确定第一计算图中的算子和第二计算图中的算子之间的相似程度,并确定第一计算图和第二计算图的算子之间的映射关系,比如说,可以选择相似度矩阵中最大的几个元素值,确定最大的几个元素值对应的两个算子存在映射关系,如果存在映射关系的两个算子在第一足迹矩阵和第二足迹矩阵中对应的是不同的行和列,则可以调整第一足迹矩阵中的行和列的关系,使得调整后存在映射关系的两个算子在第一足迹矩阵和第二足迹矩阵中对应相同的行和列。如果确定存在映射关系的两个算子在第一足迹矩阵和第二足迹矩阵中对应的是相同的行和列,则可以先不调整第一足迹矩阵的行和列的顺序,继续从相似度矩阵中选择比较大的元素值,并重复以上过程。Exemplarily, the processor may determine the degree of similarity between the operator in the first calculation graph and the operator in the second calculation graph according to the value of the elements in the similarity matrix, and determine the first calculation graph and the second calculation graph. To calculate the mapping relationship between the operators of the graph, for example, you can select the largest element values in the similarity matrix, and determine that the two operators corresponding to the largest element values have a mapping relationship. If the operators correspond to different rows and columns in the first footprint matrix and the second footprint matrix, the relationship between the rows and columns in the first footprint matrix can be adjusted, so that the two operators with a mapping relationship after adjustment are in the The first footprint matrix and the second footprint matrix correspond to the same rows and columns. If it is determined that the two operators with a mapping relationship correspond to the same rows and columns in the first footprint matrix and the second footprint matrix, then the order of the rows and columns of the first footprint matrix may not be adjusted first, and continue from the similarity Select the larger element value in the matrix and repeat the above process.
需要说明的是,以上仅仅是根据相似度矩阵调整第一足迹矩阵的行和列的顺序的一个示例,不以任何方式限制本申请。It should be noted that the above is just an example of adjusting the order of the rows and columns of the first footprint matrix according to the similarity matrix, and does not limit the present application in any way.
在调整第一足迹矩阵的行和列顺序时,要对相同序号的行和列同时进行调整,举例来说,以调整第一足迹矩阵中的行和列的顺序为例,假设调整了第一足迹矩阵中第一行和第二行、以及第一列和第二列的位置,调整后的第一足迹矩阵可以表示为:When adjusting the row and column order of the first footprint matrix, the rows and columns with the same serial number should be adjusted at the same time. The positions of the first and second rows, and the first and second columns in the footprint matrix, the adjusted first footprint matrix can be expressed as:
   q(2)q(2) q(1)q(1) q(3)q(3) q(n-1)q(n-1) q(n)q(n)
q(2)q(2) 00
q(1)q(1) 00
q(3)q(3) 00
00
q(n-1)q(n-1) 00
q(n)q(n) 00
调整第一足迹矩阵中的行和列的顺序后,第一计算图中的算子和第二计算图中的算子的映射关系发生了变化,并且算子的特征向量也跟调整之前不同,因此,可以根据调整后的第一足迹矩阵和第二足迹矩阵重新计算相似度矩阵。After adjusting the order of rows and columns in the first footprint matrix, the mapping relationship between the operators in the first calculation graph and the operators in the second calculation graph has changed, and the eigenvectors of the operators are also different from those before the adjustment. Therefore, the similarity matrix can be recalculated according to the adjusted first footprint matrix and the second footprint matrix.
重复以上过程直到达到停止条件,其中,停止条件可以是指示停止调整第一足迹矩阵和计算第一矩阵的过程的条件。在一种可能的实现方式中,停止条件可以是指多次计算得到的第一矩阵满足的条件,比如说,第一矩阵中的元素值的和大于相似度阈值,或者,也可以设置与相似度相关的目标函数,当目标函数的值最大时,达到停止条件。The above process is repeated until a stop condition is reached, where the stop condition may be a condition indicating that the process of adjusting the first footprint matrix and calculating the first matrix is stopped. In a possible implementation manner, the stopping condition may refer to a condition that is satisfied by the first matrix obtained by multiple calculations, for example, the sum of the element values in the first matrix is greater than the similarity threshold, or it can also be set to be similar to Degree-dependent objective function, when the value of the objective function is maximum, the stopping condition is reached.
举例来说,迭代的目标函数可以设置为
Figure PCTCN2021127123-appb-000012
其中,M表示算子之间的映射关系集合,m表示在这种映射关系集合中两个具体的算子之间的映射关系。如果根据调整后的第一足迹矩阵和第二足迹矩阵对应的算子之间的映射关系,计算得到的目标函数的值满足一定的范围,或者,相对于已经计算得到的目标函数的值不再变化,那么处理器可确定达到停止条件。
For example, the objective function of iteration can be set as
Figure PCTCN2021127123-appb-000012
Among them, M represents a mapping relationship set between operators, and m represents a mapping relationship between two specific operators in this mapping relationship set. If, according to the mapping relationship between the operators corresponding to the adjusted first footprint matrix and the second footprint matrix, the calculated value of the objective function satisfies a certain range, or the calculated value of the objective function is no longer changes, then the processor may determine that the stop condition is reached.
在另一种可能的实现方式中,停止条件也可以是迭代的次数,比如说,停止条件可以为重复计算第一矩阵的次数大于第一阈值,也就是说在进行与第一阈值对应的次数计算第一矩阵的过程后,不再调整第一足迹矩阵的行和列的顺序。本申请对此不作限定。In another possible implementation manner, the stop condition may also be the number of iterations. For example, the stop condition may be that the number of times the first matrix is repeatedly calculated is greater than the first threshold, that is, the number of times corresponding to the first threshold is performed. After the process of computing the first matrix, the order of the rows and columns of the first footprint matrix is no longer adjusted. This application does not limit this.
在一种可能的实现方式中,在达到停止条件时的第一足迹矩阵和第二足迹矩阵中对应的行或列的位置相同的第一计算图的算子和第二计算图的算子之间存在映射关系。In a possible implementation manner, when the stopping condition is reached, the first footprint matrix and the second footprint matrix have the same row or column position as the operator of the first computation graph and the operator of the second computation graph. There is a mapping relationship between them.
在达到停止条件后,对于步骤S301,处理器可以确定达到所述停止条件时的第一足迹矩阵和第二足迹矩阵相同位置的行或列对应的算子互为映射算子,相同位置的行可以是指行号相同,比如说第一足迹矩阵的第一行和第二足迹矩阵的第二行为相同位置的行,第一足迹矩阵的第一行对应的算子和第二足迹矩阵的第二行对应的算子之间存在映射关系。或者,也可以根据计算出来的相似度矩阵为一个算子确定多个映射算子,比如说,可以根据计算出来的相似度矩阵的值,为一个算子与其他算子的相似度进行排序,将与该算子的相似度最高的多个算子确定为该算子的映射算子。After the stop condition is reached, for step S301, the processor may determine that the operators corresponding to the rows or columns of the same position of the first footprint matrix and the second footprint matrix when the stop condition is reached are mapping operators to each other, and the row of the same position It can refer to the same row number, for example, the first row of the first footprint matrix and the second row of the second footprint matrix are in the same position, the operator corresponding to the first row of the first footprint matrix and the first row of the second footprint matrix. There is a mapping relationship between the operators corresponding to the two rows. Alternatively, multiple mapping operators can also be determined for one operator according to the calculated similarity matrix. For example, the similarity between one operator and other operators can be sorted according to the calculated similarity matrix value. The multiple operators with the highest similarity with the operator are determined as the mapping operators of the operator.
在一种可能的实现方式中,所述第一足迹矩阵、调整后的第一足迹矩阵与所述第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,也就是说,所述第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,调整后的第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同。In a possible implementation manner, the type of the first footprint matrix, the adjusted first footprint matrix, and the operator corresponding to the row at the same position and the type of the operator corresponding to the column at the same position of the second footprint matrix The same, the dimensions of the tensors output by the operators are the same, that is, the operators corresponding to the rows at the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns at the same position are of the same type , the dimensions of the tensors output by the operators are the same, the operators corresponding to the rows at the same position and the columns at the same positions of the adjusted first footprint matrix and the second footprint matrix are of the same type, and the operators output The dimensions of the tensors are the same.
在构建第一足迹矩阵和第二足迹矩阵、以及调整第一足迹矩阵时,保证第一足迹矩阵和第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,也就是第一足迹矩阵和第二足迹矩阵相同位置的行对应的算子、相同位置的列对应的算子在功能上是相同的。结合相似度矩阵衡量算子之间的拓扑关系的相似度。根据本申请提供的算子映射方法,可以从功能和拓扑关系上体现两个算子之间的映射关系,从而确保映射结果的正确性。When constructing the first footprint matrix and the second footprint matrix, and adjusting the first footprint matrix, ensure the type of the operator corresponding to the row at the same position and the type of the operator corresponding to the column at the same position of the first footprint matrix and the second footprint matrix The same, the dimensions of the tensors output by the operators are the same, that is, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns in the same position are functionally the same. Combine the similarity matrix to measure the similarity of the topological relationship between operators. According to the operator mapping method provided by the present application, the mapping relationship between two operators can be reflected in terms of functions and topological relationships, thereby ensuring the correctness of the mapping result.
根据本申请提供的计算图的算子映射方法,通过迭代计算可以得到优选的一种或多种映 射关系,因此可以支持相似结构的计算图之间的算子映射,能够适用于深度学习框架进行模型迁移的场景中。According to the operator mapping method for computational graphs provided by the present application, one or more preferred mapping relationships can be obtained through iterative calculation, so it can support operator mapping between computational graphs with similar structures, and can be applied to deep learning frameworks for In the scenario of model migration.
在一种可能的实现方式中,所述第一计算图和所述第二计算图中的算子分属于多个第一分区,同一第一分区的算子类型相同、且算子输出的张量的维度相同;所述第一计算图和所述第二计算图中的部分算子属于第二分区,所述第二分区中的算子类型不同和/或算子输出的张量的维度不同。In a possible implementation manner, the operators in the first calculation graph and the second calculation graph belong to multiple first partitions, the operators in the same first partition are of the same type, and the operator outputs The dimensions of the quantities are the same; some operators in the first calculation graph and the second calculation graph belong to the second partition, the types of operators in the second partition are different and/or the dimensions of the tensors output by the operators are different different.
其中,类型相同、且输出的张量的维度相同的算子可以称为同质算子,因此,第一分区也可以称为同质分区。第二分区中算子的类型不同和/或算子输出的张量的维度不同,因此,第二分区中的算子不是同质算子,第二分区也可以称作混合分区。Among them, operators with the same type and the same dimension of output tensors can be called homogeneous operators, so the first partition can also be called homogeneous partition. The types of operators in the second partition are different and/or the dimensions of the tensors output by the operators are different. Therefore, the operators in the second partition are not homogeneous operators, and the second partition may also be called a hybrid partition.
在一种可能的实现方式中,处理器可以按照算子的类型和算子输出的张量的维度对第一计算图的算子和第二计算图的算子进行分类,将同质算子分为一类,每一类同质算子属于一个第一分区。每个第一分区中可以包括第一计算图和/或第二计算图的至少部分算子。In a possible implementation manner, the processor may classify the operators of the first calculation graph and the operators of the second calculation graph according to the type of the operator and the dimension of the tensor output by the operator, and classify the homogeneous operators Divided into one class, each class of homogeneous operators belongs to a first partition. Each of the first partitions may include at least part of the operators of the first computation graph and/or the second computation graph.
第一计算图和第二计算图中的部分算子可能不存在同质算子,这类算子可以属于第二分区(混合分区),第二分区中可以包括第一计算图和/或第二计算图的部分算子。对于第一计算图和第二计算图中的算子,不存在同质算子的算子全部属于混合分区。比如说,计算图中有些算子为不可映射的算子类型,或者不存在输出操作数维度相同的算子,这类算子不存在同质算子。举例来说,MS的tuple_getitem类算子和TF的Identity类算子,都是无法从对方的框架中找到功能相同的对应算子类型。对于这类算子,可以分入混合分区,在确定映射算子时,可以根据达到停止条件时的第一足迹矩阵、所述第二足迹矩阵以及计算得到的相似度矩阵输出映射建议。There may be no homogeneous operators in some operators in the first calculation graph and the second calculation graph. Such operators may belong to the second partition (hybrid partition), and the second partition may include the first calculation graph and/or the second partition. 2. Partial operators of computational graphs. For the operators in the first calculation graph and the second calculation graph, the operators without homogeneous operators all belong to the mixed partition. For example, some operators in the calculation graph are unmappable operator types, or there are no operators with the same dimension of output operands, and there are no homogeneous operators for such operators. For example, MS's tuple_getitem operator and TF's Identity operator cannot find corresponding operator types with the same functions from each other's framework. Such operators can be divided into mixed partitions, and when a mapping operator is determined, a mapping suggestion can be output according to the first footprint matrix, the second footprint matrix and the calculated similarity matrix when the stopping condition is reached.
在一种可能的实现方式中,属于同一第一分区、且在达到停止条件时的第一足迹矩阵和第二足迹矩阵中对应的行或列的位置相同的第一计算图的算子和第二计算图的算子之间存在映射关系。In a possible implementation manner, the operator and the first computation graph belong to the same first partition and have the same row or column position in the first footprint matrix and the second footprint matrix when the stopping condition is reached. There is a mapping relationship between the operators of the two computation graphs.
在一种可能的实现方式中,属于所述第二分区的第一计算图的算子与属于第二分区的第二计算图的多个算子之间存在映射关系,其中,所述属于第二分区的第二计算图的多个算子为:达到所述停止条件时的第一矩阵中,与所述属于所述第二分区的第一计算图的算子对应的元素的值中,最大的多个值所对应的第二计算图的算子。根据达到停止条件时的第一足迹、第二矩阵以及第一矩阵可以输出混合分区中第一计算图的算子与第二计算图的多个算子的映射建议,或者,输出混合分区中第二计算图的算子和第一计算图中多个算子的映射建议。比如说,对于混合分区中的第一计算图的算子,根据相似度矩阵中该算子对应的相似度的值选确定最相似的第二计算图中的多个算子(top-k,k为输出映射建议时建议的算子个数,k为正整数)输出。In a possible implementation manner, there is a mapping relationship between the operators of the first computation graph belonging to the second partition and multiple operators of the second computation graph belonging to the second partition, wherein the operators belonging to the first computation graph The multiple operators of the second computation graph of the second partition are: in the first matrix when the stopping condition is reached, among the values of the elements corresponding to the operators of the first computation graph belonging to the second partition, The operator of the second computation graph corresponding to the largest multiple values. According to the first footprint, the second matrix, and the first matrix when the stopping condition is reached, a mapping suggestion between the operator of the first computation graph and the multiple operators of the second computation graph in the mixed partition can be output, or the first computation graph in the mixed partition can be output. The operator of the second calculation graph and the mapping suggestion of multiple operators in the first calculation graph. For example, for the operator of the first calculation graph in the mixed partition, according to the similarity value corresponding to the operator in the similarity matrix, multiple operators (top-k, k is the number of operators suggested when outputting mapping suggestions, and k is a positive integer) output.
因为同质算子之间存在映射关系的可能性更大,并且,在本申请的实施例中,第一足迹矩阵和第二足迹矩阵相同位置的行或列对应的算子之间存在映射关系。因此,在确定第一足迹矩阵和第二足迹矩阵时,处理器可以按照第一分区排列第一计算图的算子在第一足迹矩阵 对应的行和第二计算图的算子在第二足迹矩阵中对应的行,以及按照第一分区排列第一计算图的算子在第一足迹矩阵对应的列和第二计算图的算子在第二足迹矩阵中对应的列。Because it is more likely that there is a mapping relationship between homogeneous operators, and in the embodiment of the present application, there is a mapping relationship between the operators corresponding to the rows or columns in the same position of the first footprint matrix and the second footprint matrix . Therefore, when determining the first footprint matrix and the second footprint matrix, the processor may arrange the operators of the first computation graph in the rows corresponding to the first footprint matrix and the operators of the second computation graph in the second footprint according to the first partition. The corresponding rows in the matrix, and the columns corresponding to the operators of the first computation graph in the first footprint matrix and the columns corresponding to the operators of the second computation graph in the second footprint matrix are arranged according to the first partition.
具体地,在一种可能的实现方式中,所述第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子在同一第一分区、相同位置的列对应的算子在同一第一分区;且,属于同一第一分区的第一计算图的算子在所述第一足迹矩阵中对应的行或者列连续排列,属于同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或者列连续排列。也就是说,属于同一第一分区的第一计算图的算子在第一足迹矩阵中对应的行和第二计算图的算子在第二足迹矩阵中对应的行的序号范围相同,属于同一第一分区的第一计算图的算子在第一足迹矩阵中对应的列和第二计算图的算子在第二足迹矩阵中对应的列的序号范围相同。举例来说,属于同一第一分区的第一计算图的算子q(1)、q(2)和q(3)在第一足迹矩阵对应的行为第1-3行、列为第1-3列,与算子q(1)、q(2)和q(3)属于同一第一分区的第二计算图的算子r(1)、r(2)和r(3)在第二足迹矩阵对应的行为1-3行、列为第1-3列。Specifically, in a possible implementation manner, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are in the same first partition, and the operators corresponding to the columns in the same position are in the same The first partition; and, the operators of the first computation graph belonging to the same first partition are arranged consecutively in the corresponding rows or columns in the first footprint matrix, and the operators of the second computation graph belonging to the same first partition are in the same first partition. The corresponding rows or columns in the second footprint matrix are arranged consecutively. That is to say, the row corresponding to the operator of the first computation graph belonging to the same first partition in the first footprint matrix and the row corresponding to the operator of the second computation graph in the second footprint matrix have the same sequence number range, and belong to the same The columns corresponding to the operators of the first computation graph of the first partition in the first footprint matrix and the columns corresponding to the operators of the second computation graph in the second footprint matrix have the same serial number range. For example, the operators q(1), q(2) and q(3) of the first computation graph belonging to the same first partition are in the rows 1-3 and columns 1-3 corresponding to the first footprint matrix. 3 columns, the operators r(1), r(2) and r(3) of the second computation graph belonging to the same first partition as the operators q(1), q(2) and q(3) are in the second The footprint matrix corresponds to rows 1-3 and columns 1-3.
图6示出根据本申请一实施例的构建足迹矩阵的流程图。如图6所示,在一种可能的实现方式中,分别确定第一计算图的第一足迹矩阵和第二计算图的第二足迹矩阵的过程可以包括:FIG. 6 shows a flowchart of constructing a footprint matrix according to an embodiment of the present application. As shown in FIG. 6, in a possible implementation manner, the process of respectively determining the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph may include:
步骤S3000,根据算子的类型和算子输出的张量的维度,对第一计算图和第二计算图中的算子进行分区,得到第一分区;其中,位于同一第一分区中的算子为同质算子,同质算子的类型相同、且算子输出的张量的维度相同;Step S3000, according to the type of the operator and the dimension of the tensor output by the operator, partition the operators in the first calculation graph and the second calculation graph to obtain a first partition; The operator is a homogeneous operator, the type of the homogeneous operator is the same, and the dimension of the tensor output by the operator is the same;
步骤S3002,按照第一分区分别确定第一计算图的第一足迹矩阵和第二计算图的第二足迹矩阵。Step S3002, respectively determining a first footprint matrix of the first computation graph and a second footprint matrix of the second computation graph according to the first partition.
在本实施方式中,步骤S300中的根据所述第一矩阵调整所述第一足迹矩阵中的行和列的顺序,可以包括:根据所述第一矩阵调整所述第一足迹矩阵中位于同一所述第一分区内的算子对应的行和列的顺序。In this implementation manner, adjusting the order of rows and columns in the first footprint matrix according to the first matrix in step S300 may include: adjusting according to the first matrix the order of rows and columns in the first footprint matrix that are located in the same The order of the rows and columns corresponding to the operators in the first partition.
通过对第一计算图和第二计算图中的算子进行同质分区,并且在调整第一足迹矩阵中的行和列的顺序时,调整位于同一同质分区的算子对应的行和列的顺序,可以更快速使迭代的过程收敛,加快映射的过程。这是由于同质算子的相似性更高,同质算子之间存在映射关系的可能性更大,因此,通过进行同质分区的过程可以加速步骤S300收敛的速度,加快映射的过程。By performing homogeneous partitioning on the operators in the first computational graph and the second computational graph, and when adjusting the order of the rows and columns in the first footprint matrix, adjust the rows and columns corresponding to the operators located in the same homogeneous partition order can make the iterative process converge faster and speed up the mapping process. This is because the similarity of homogeneous operators is higher, and there is a greater possibility of a mapping relationship between homogeneous operators. Therefore, the process of performing homogeneous partitioning can speed up the speed of convergence in step S300 and speed up the mapping process.
对于步骤S3000,处理器可以将第一计算图和第二计算图的算子中,类型相同、算子输出的张量的维度相同的算子分入同一个同质分区中。也就是说,第一计算图和第二计算图中类型相同、且算子输出的张量的维度相同的算子位于同一个同质分区中。For step S3000, the processor may divide the operators of the first computation graph and the second computation graph with the same type and the same dimension of the tensors output by the operators into the same homogeneous partition. That is to say, operators with the same type and the same dimension of the tensors output by the operators in the first calculation graph and the second calculation graph are located in the same homogeneous partition.
图7示出根据本申请一实施例的同质分区的示意图,如图7所示,算子q(1)、q(2)、q(3)、q(4)和r(1)、r(2)、r(3)、r(4)在同一个同质分区中,该同质分区中算子的类型为卷积运算,输出操作数的维度为64×55×55。q(5)、q(6)、q(7)和r(5)、r(6)、r(7)在同一个同质分区 中,该同质分区中算子的类型为卷积运算,输出操作数的维度为256×55×55。算子q(n)和r(n)在同一个同质分区中,该同质分区中算子的类型为池化运算,输出的操作数的维度为m×n×k。需要说明的是,图7中同质分区的算子的类型以及输出操作数的维度、同质分区中算子的数目、编号仅仅是本申请的示例,不以任何方式限制本申请。FIG. 7 shows a schematic diagram of a homogeneous partition according to an embodiment of the present application. As shown in FIG. 7 , operators q(1), q(2), q(3), q(4) and r(1), r(2), r(3), and r(4) are in the same homogeneous partition, the type of the operator in the homogeneous partition is convolution operation, and the dimension of the output operand is 64×55×55. q(5), q(6), q(7) and r(5), r(6), r(7) are in the same homogeneous partition, and the type of operator in this homogeneous partition is convolution operation , the dimension of the output operand is 256×55×55. The operators q(n) and r(n) are in the same homogeneous partition, the type of the operators in the homogeneous partition is the pooling operation, and the dimension of the output operand is m×n×k. It should be noted that the types of operators in the homogeneous partition, the dimensions of output operands, the number and number of operators in the homogeneous partition in FIG. 7 are only examples of the present application and do not limit the present application in any way.
对于步骤S3002,按照第一分区确定第一计算图的第一足迹矩阵和第二计算图的第二足迹矩阵,主要是为了将位于同一同质分区的算子在足迹矩阵中放在相邻的行和列的位置。For step S3002, the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph are determined according to the first partition, mainly for placing operators located in the same homogeneous partition adjacent to each other in the footprint matrix row and column positions.
第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子在同一第一分区、相同位置的列对应的算子在同一第一分区;且,属于同一第一分区的第一计算图的算子在所述第一足迹矩阵中对应的行或者列连续排列,属于同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或者列连续排列。也就是说,在确定第一足迹矩阵和第二足迹矩阵时,对于第一计算图和第二计算图中位于同一同质分区的算子,第一计算图中的算子在第一足迹矩阵中的行和列的序号范围与第二计算图中的算子在第二足迹矩阵中的行和列的序号范围相同。举例来说,仍然以图7所示的示例为例,假设第一计算图的算子q(1)、q(2)、q(3)、q(4)在第一足迹矩阵中对应第1-4行、第1-4列,那么第二计算图的算子r(1)、r(2)、r(3)、r(4)在第二足迹矩阵中对应第1-4行、第1-4列。这样,第一足迹矩阵和第二足迹矩阵相同的行和列对应的算子之间存在映射关系的可能性更大,在调整第一足迹矩阵中的行和列的顺序时,通过调整第一足迹矩阵中位于同一同质分区内的算子对应的行和列的顺序,可以快速的将存在映射关系的算子调整到相同的行和列上。The operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are in the same first partition, and the operators corresponding to the columns in the same position are in the same first partition; The operators of the computation graph are arranged consecutively in corresponding rows or columns in the first footprint matrix, and the operators of the second computation graph belonging to the same first partition are arranged consecutively in corresponding rows or columns in the second footprint matrix. That is, when determining the first footprint matrix and the second footprint matrix, for operators located in the same homogeneous partition in the first computation graph and the second computation graph, the operators in the first computation graph are in the first footprint matrix The sequence number range of the row and column in is the same as the sequence number range of the row and column of the operator in the second footprint matrix in the second computation graph. For example, still taking the example shown in FIG. 7 as an example, it is assumed that the operators q(1), q(2), q(3), and q(4) of the first calculation graph correspond to the first footprint matrix in the first footprint matrix. Rows 1-4, columns 1-4, then the operators r(1), r(2), r(3), and r(4) of the second calculation graph correspond to rows 1-4 in the second footprint matrix , columns 1-4. In this way, it is more likely that there is a mapping relationship between operators corresponding to the same rows and columns of the first footprint matrix and the second footprint matrix. When adjusting the order of rows and columns in the first footprint matrix, by adjusting the first footprint The order of the rows and columns corresponding to the operators located in the same homogeneous partition in the footprint matrix can quickly adjust the operators with mapping relationships to the same rows and columns.
通过本申请上述实施方式中,对计算图中的算子进行同质分区,并按照同质分区确定对应的足迹矩阵的方式,可以快速确定存在映射关系的可能性更大的算子,加速映射的过程。In the above-mentioned embodiments of the present application, the operators in the calculation graph are homogeneously partitioned, and the corresponding footprint matrix is determined according to the homogeneous partition, so that operators with a higher possibility of having a mapping relationship can be quickly determined, and the mapping can be accelerated. the process of.
在一种可能的实现方式中,根据第一矩阵调整第一足迹矩阵中位于同一第一分区内的算子对应的行和列的顺序,可以包括:In a possible implementation manner, adjusting the order of rows and columns corresponding to operators located in the same first partition in the first footprint matrix according to the first matrix may include:
根据第一矩阵确定位于同一第一分区内第一计算图中的算子与第二计算图中的算子的映射关系;Determine the mapping relationship between the operator in the first calculation graph and the operator in the second calculation graph in the same first partition according to the first matrix;
根据所述映射关系调整所述第一足迹矩阵中与第一计算图中的算子对应的行和列的顺序。The order of rows and columns in the first footprint matrix corresponding to the operators in the first computation graph is adjusted according to the mapping relationship.
其中,根据第一矩阵确定位于同一第一分区内第一计算图中的算子与第二计算图中的算子的映射关系,具体可以包括两次遍历,以下过程是对同一第一分区内的算子确定映射关系的过程。The mapping relationship between the operators in the first calculation graph and the operators in the second calculation graph in the same first partition is determined according to the first matrix, which may specifically include two traversals. The following process is for the same first partition. The process of determining the mapping relationship by the operator.
在第一次遍历过程中:从相似度矩阵的一个同质分区中最小元素对应的第一计算图中的算子开始遍历该同质分区中的所有算子,根据当前遍历的算子在相似度矩阵中所在的行或者列中的最大元素确定第二计算图中与当前遍历的算子最相似的算子,如果第二计算图中与当前遍历的算子最相似的算子已经被确定为已经遍历的算子的最相似的算子,则在第二次遍历时为所述已经遍历的算子重新确定最相似的算子,也就是,在第一次遍历的过程中,后遍历确定的最相似的算子与之前确定的最相似的算子存在冲突时,后遍历的结果覆盖之前遍历的 结果。In the first traversal process: start from the operator in the first calculation graph corresponding to the smallest element in a homogeneous partition of the similarity matrix to traverse all the operators in the homogeneous partition, according to the current traversed operator in the similarity The largest element in the row or column of the degree matrix determines the operator most similar to the currently traversed operator in the second calculation graph, if the operator most similar to the currently traversed operator in the second calculation graph has been determined is the most similar operator of the operators that have been traversed, then in the second traversal, the most similar operator is re-determined for the operators that have been traversed, that is, in the process of the first traversal, after the traversal When the determined most similar operator conflicts with the previously determined most similar operator, the result of the later traversal overwrites the result of the previous traversal.
在第二次遍历的过程中:对于该同质分区中还未匹配到最相似的算子的算子,从相似度矩阵的该同质分区中最大元素对应的算子开始遍历还未匹配到最相似的算子的算子,根据当前遍历的算子在相似度矩阵中所在的行或者列中的最大元素确定第二计算图中与当前遍历的算子最相似的算子,如果第二计算图中与当前遍历的算子最相似的算子已经被确定为已经遍历的算子的最相似的算子,则根据当前遍历的算子在相似度矩阵中所在的行或者列中的次大元素值确定第二计算图中与当前遍历的算子最相似的算子,直到匹配到当前遍历的算子的最相似的算子。In the process of the second traversal: for the operator that has not yet matched the most similar operator in the homogeneous partition, start the traversal from the operator corresponding to the largest element in the homogeneous partition of the similarity matrix and have not yet matched. The operator of the most similar operator, according to the largest element in the row or column where the currently traversed operator is located in the similarity matrix, to determine the operator that is most similar to the currently traversed operator in the second calculation graph. If the operator most similar to the currently traversed operator in the calculation graph has been determined to be the most similar operator of the operator that has been traversed, then according to the order of the current traversed operator in the row or column of the similarity matrix The large element value determines the most similar operator to the currently traversed operator in the second calculation graph until the most similar operator to the currently traversed operator is matched.
图5b示出根据本申请一实施例的调整足迹矩阵的行和列的顺序的方法的流程图。假设在本示例中,第一足迹矩阵的行对应的算子为第一计算图的算子,列对应的算子为第二计算图的算子,相似度矩阵的行与第一计算图的算子对应、列与第二计算图的算子对应,结合上文示例中的相似度矩阵对本申请实施例的调整足迹矩阵的过程进行说明。FIG. 5b shows a flowchart of a method for adjusting the order of rows and columns of a footprint matrix according to an embodiment of the present application. Assume that in this example, the operator corresponding to the row of the first footprint matrix is the operator of the first calculation graph, the operator corresponding to the column is the operator of the second calculation graph, and the row of the similarity matrix is the same as the first calculation graph. The operators correspond, and the columns correspond to the operators of the second calculation graph. The process of adjusting the footprint matrix in this embodiment of the present application will be described with reference to the similarity matrix in the above example.
Figure PCTCN2021127123-appb-000013
Figure PCTCN2021127123-appb-000013
图5b所示为对一个同质分区的算子确定算子的映射关系的过程,如图5b所示,在步骤S500,处理器可以先确定是第一次遍历还是第二次遍历,如果是第一次遍历第一计算图中的算子,则处理器可以执行步骤S510先判断是否已经遍历完该同质分区的所有算子,如果已经遍历完该同质分区的算子,则可以返回步骤S500,继续判断是第一次遍历还是第二次遍历;如果还未遍历完该同质分区的算子,则处理器可以执行步骤S511,确定还未遍历的算子在相似度矩阵中对应的行中的最小元素,将最小元素对应的算子确定为当前遍历的算子,也就是说,在第一次遍历过程中:从相似度矩阵中最小的元素值对应的算子开始遍历。Fig. 5b shows the process of determining the mapping relationship of the operators for an operator of a homogeneous partition. As shown in Fig. 5b, in step S500, the processor can first determine whether it is the first traversal or the second traversal, if yes For the first time to traverse the operators in the first calculation graph, the processor may execute step S510 to first determine whether all operators of the homogeneous partition have been traversed, and if the operators of the homogeneous partition have been traversed, the processor may return Step S500, continue to judge whether it is the first traversal or the second traversal; if the operator of the homogeneous partition has not been traversed, the processor can perform step S511 to determine that the operator that has not been traversed corresponds to the similarity matrix. The smallest element in the row of , determines the operator corresponding to the smallest element as the current traversed operator, that is, in the first traversal process: start traversal from the operator corresponding to the smallest element value in the similarity matrix.
在确定当前遍历的算子后,处理器可以执行步骤S512,根据当前遍历的算子在相似度矩阵中所在的行中的最大元素值确定第二计算图中与当前遍历的算子最相似的算子,比如说,将当前遍历的算子在相似度矩阵所在的行中的最大元素值对应的第二计算图中的算子确定为与当前遍历的算子最相似的算子。换言之,因为已经假设第一足迹矩阵的行对应的算子为第一计算图的算子,列对应的算子为第二计算图的算子,相似度矩阵的行与第一计算图的算子 对应、列与第二计算图的算子对应,因此,在相似度矩阵中,一行元素的值分别代表第一计算图中的一个算子与第二计算图中的每一个算子的余弦相似性,这一行元素中的值越大代表第一计算图中的算子与第二计算图中的算子越相似。因此,处理器可以将当前遍历的算子在相似度矩阵所在的行中的最大元素值对应的第二计算图中的算子确定为与当前遍历的算子最相似的算子。After determining the currently traversed operator, the processor may execute step S512, and determine the most similar operator to the currently traversed operator in the second calculation graph according to the largest element value in the row where the currently traversed operator is located in the similarity matrix For the operator, for example, the operator in the second calculation graph corresponding to the largest element value of the currently traversed operator in the row where the similarity matrix is located is determined as the most similar operator to the currently traversed operator. In other words, because it has been assumed that the operator corresponding to the row of the first footprint matrix is the operator of the first calculation graph, the operator corresponding to the column is the operator of the second calculation graph, and the row of the similarity matrix is the operator of the first calculation graph. The sub-correspondence, the column corresponds to the operator of the second calculation graph, therefore, in the similarity matrix, the value of a row of elements respectively represents the cosine of an operator in the first calculation graph and each operator in the second calculation graph Similarity, the larger the value in this row of elements, the more similar the operator in the first calculation graph is to the operator in the second calculation graph. Therefore, the processor may determine the operator in the second calculation graph corresponding to the largest element value of the currently traversed operator in the row of the similarity matrix as the operator most similar to the currently traversed operator.
在确定当前遍历的算子的最相似的算子后,处理器可以执行步骤S513,判断最相似的算子是否已经与之前遍历的算子匹配,如果最相似的算子未与之前遍历的算子匹配,处理器可以执行步骤S515,记录当前遍历的算子和最相似的算子之间的映射关系,将当前遍历的算子标记为已遍历的算子,并返回步骤S510,继续判断是否已经遍历完该同质分区的所有算子。After determining the most similar operator of the currently traversed operator, the processor may execute step S513 to determine whether the most similar operator has been matched with the previously traversed operator, and if the most similar operator does not match the previously traversed operator If the sub-matches, the processor may perform step S515 to record the mapping relationship between the currently traversed operator and the most similar operator, mark the currently traversed operator as the traversed operator, and return to step S510 to continue to determine whether All operators of the homogeneous partition have been traversed.
如果处理器判断最相似的算子与之前遍历的算子匹配,则处理器可以执行步骤S514,删除之前遍历的算子与最相似的算子之间的映射关系,将之前遍历的算子加入第二次遍历的队列。然后继续执行步骤S515。对于步骤S514、S515,处理器通过记录、删除映射关系的方式仅仅是本申请的一个示例,本申请不限于此,也可以采用其他方式实现后遍历确定的最相似的算子与之前确定的最相似的算子存在冲突时,后遍历的结果覆盖之前遍历的结果。同样的,将之前遍历的算子加入第二次遍历的队列也仅仅是一种实现二次遍历的方式,处理器还可以通过为算子添加特殊标识的方式实现这一过程,本申请对具体的实现方式不作限定。If the processor determines that the most similar operator matches the previously traversed operator, the processor may execute step S514 to delete the mapping relationship between the previously traversed operator and the most similar operator, and add the previously traversed operator to the The second traversal of the queue. Then proceed to step S515. For steps S514 and S515, the way that the processor records and deletes the mapping relationship is only an example of the present application, and the present application is not limited to this, and other methods can also be used to realize the most similar operator determined by traversal and the most similar operator determined before. When similar operators conflict, the result of the later traversal overwrites the result of the previous traversal. Similarly, adding the previously traversed operator to the queue for the second traversal is only a way to implement the second traversal. The processor can also implement this process by adding a special identifier to the operator. The implementation method is not limited.
在根据以上过程第一次遍历完该同质分区的算子后,开始第二次遍历的过程。处理器可以执行步骤S520,判断是否遍历完该同质分区的所有算子,也就是是否遍历完第一次遍历完后还未进行匹配的算子。处理器在判断遍历完该同质分区的所有算子后,可以结束确定映射关系的过程。处理器在判断未遍历完算子的该同质分区的所有算子后,可以执行步骤S521,确定还未遍历的算子在相似性矩阵对应的行中的最大元素,将最大元素对应的算子作为当前遍历的算子。也就是上文所述的在第二次遍历的过程中,对于还未匹配到最相似的算子的算子,从相似度矩阵中最大元素对应的算子开始遍历。After the operators of the homogeneous partition are traversed for the first time according to the above process, the process of the second traversal is started. The processor may execute step S520 to determine whether all operators of the homogeneous partition have been traversed, that is, whether the operators that have not been matched after the first traversal have been traversed. After judging that all operators of the homogeneous partition have been traversed, the processor may end the process of determining the mapping relationship. After judging all the operators of the homogeneous partition that have not traversed the operators, the processor may execute step S521 to determine the largest element in the row corresponding to the similarity matrix of the operator that has not yet been traversed, and calculate the operator corresponding to the largest element. child as the current traversal operator. That is, in the process of the second traversal described above, for the operators that have not yet matched the most similar operator, the traversal starts from the operator corresponding to the largest element in the similarity matrix.
在确定了当前遍历的算子后,处理器可以执行步骤S522,根据当前遍历的算子在相似度矩阵中所在的行中的最大元素值确定第二计算图中与当前遍历的算子最相似的算子。具体确定的方式,可以参见步骤S512部分的内容,不再赘述。处理器可以执行步骤S523,判断判断最相似的算子是否已经与之前遍历的算子匹配,具体的过程可以参见步骤S513部分的内容。不同之处在于,当处理器判断最相似的算子与之前遍历的算子匹配,不再覆盖之前遍历的结果,而是执行步骤S524,根据当前遍历的算子在相似度矩阵中所在的行中的次大元素值确定第二计算图中与当前遍历的算子最相似的算子,也就是说,继续查找其他与当前遍历的算子最相似的算子,直到找到未与之前遍历的算子匹配、且与当前遍历的算子“最相似”的算子之后,执行步骤S525。After the currently traversed operator is determined, the processor may execute step S522 to determine the most similar operator to the currently traversed operator in the second calculation graph according to the maximum element value in the row where the currently traversed operator is located in the similarity matrix the operator. For the specific determination method, reference may be made to the content of step S512, and details are not repeated here. The processor may execute step S523 to determine whether the most similar operator has been matched with the previously traversed operator. For the specific process, please refer to the content of step S513. The difference is that when the processor determines that the most similar operator matches the previously traversed operator, it no longer covers the previously traversed result, but executes step S524, according to the row in the similarity matrix where the currently traversed operator is located. The value of the second largest element in the second calculation graph determines the operator that is most similar to the currently traversed operator, that is to say, continue to find other operators that are most similar to the currently traversed operator until it finds an operator that is not the same as the one traversed before. After the operator matches the operator that is "most similar" to the currently traversed operator, step S525 is executed.
对所有的同质分区内的算子进行以上两次遍历的过程,处理器可以更快的确定第一计算图和第二计算图中的算子的局部(阶段)最佳映射关系,并根据映射关系调整所述第一足迹矩阵中与第一计算图中的算子对应的行和列的顺序。具体来说,按照第二足迹矩阵的每一行(每一列)对应的算子的排列顺序,根据上述映射关系确定第二计算图中的算子在第一计算 图中的映射算子,将映射算子在第一足迹矩阵中对应的行(列)调整为和第二计算图中的算子在第二足迹矩阵的行(列)相同。In the process of performing the above two traversals on all the operators in the homogeneous partition, the processor can more quickly determine the local (stage) optimal mapping relationship of the operators in the first calculation graph and the second calculation graph, and according to The mapping relationship adjusts the order of the rows and columns in the first footprint matrix corresponding to the operators in the first computation graph. Specifically, according to the arrangement order of operators corresponding to each row (each column) of the second footprint matrix, the mapping operator of the operator in the second calculation graph in the first calculation graph is determined according to the above-mentioned mapping relationship, and the mapping The corresponding row (column) of the operator in the first footprint matrix is adjusted to be the same as the row (column) of the operator in the second footprint matrix in the second calculation graph.
根据本申请上述实施方式提供的调整第一足迹矩阵的方法,可以更快速的使计算结果收敛到迭代的停止条件,更快速的获得算子之间的映射关系,有利于加速映射的过程。需要说明的是,以上示例仅仅是本申请提供的调整第一足迹矩阵的行和列的顺序的一个示例,本申请不限于此。According to the method for adjusting the first footprint matrix provided by the above embodiments of the present application, the calculation result can be more quickly converged to the stop condition of the iteration, and the mapping relationship between operators can be obtained more quickly, which is beneficial to speed up the mapping process. It should be noted that the above example is only an example of adjusting the order of the rows and columns of the first footprint matrix provided by the present application, and the present application is not limited thereto.
在一种可能的实现方式中,所述第一足迹矩阵和所述第二足迹矩阵相同位置的行对应的算子的同质深度相同、相同位置的列对应的算子的同质深度相同,且属于同一第一分区的所述第一计算图的算子在所述第一足迹矩阵中对应的行或列按照算子的所述同质深度排序、同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或列按照算子的所述同质深度排序;其中,所述同质深度为:在计算图中所述算子所属的所有分支中,在所述算子之前与所述算子类型相同、输出的张量维度相同的算子的最大数目。In a possible implementation manner, the homogeneous depths of the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are the same, and the homogeneous depths of the operators corresponding to the columns of the same position are the same, And the corresponding rows or columns of the operators of the first computation graph belonging to the same first partition in the first footprint matrix are sorted according to the homogeneous depth of the operators, and the second computation graph of the same first partition The rows or columns corresponding to the operators in the second footprint matrix are sorted according to the homogeneity depth of the operators; wherein, the homogeneity depth is: in all branches to which the operator belongs in the calculation graph, in The maximum number of operators that have the same type and output tensor dimensions as the operator before the operator.
在一种可能的实现方式中,本申请提供的算子映射方法还可以包括以下步骤:In a possible implementation manner, the operator mapping method provided by the present application may further include the following steps:
根据算子的类型、算子输出的张量的维度、以及算子在第一计算图或第二计算图中的拓扑结构的顺序,确定算子的同质深度;Determine the homogeneity depth of the operator according to the type of the operator, the dimension of the tensor output by the operator, and the order of the topological structure of the operator in the first computation graph or the second computation graph;
对算子进行分区得到同质分区,在每个同质分区中根据算子的同质深度对第一计算图和第二计算图的算子分别进行排序并编号;也就是说,在每个同质分区中,处理器可以根据第一计算图的算子的同质深度对第一计算图的算子进行排序和编号,根据第二计算图的算子的同质深度对第二计算图的算子进行排序和编号,具体根据同质深度进行排序和编号的方式不作限定,比如说,可以按照同质深度由浅到深排序、按照编号由小到大编号,或者,也可以按照同质深度由深到浅排序、按照编号由小到大编号。The operators are partitioned to obtain homogeneous partitions, and in each homogeneous partition, the operators of the first computational graph and the second computational graph are sorted and numbered according to the homogeneous depth of the operator; that is, in each In the homogenous partition, the processor may sort and number the operators of the first calculation graph according to the homogeneity depth of the operators of the first calculation graph, and sort and number the operators of the second calculation graph according to the homogeneity depth of the operators of the second calculation graph. The operators are sorted and numbered according to the homogeneous depth, and the method of sorting and numbering is not limited. The depth is sorted from deep to shallow, and the numbers are numbered from small to large.
这样,处理器在确定第一足迹矩阵时,可以按照第一分区中第一计算图的算子的编号的顺序确定;处理器在确定第二足迹矩阵时,可以按照第一分区中第二计算图的算子的编号的顺序确定。这样可以实现第一足迹矩阵和第二足迹矩阵相同位置的行对应的算子的同质深度相同、相同位置的列对应的算子的同质深度相同,且属于同一第一分区的第一计算图的算子在第一足迹矩阵中对应的行或列按照算子的同质深度排序、同一第一分区的第二计算图的算子在第二足迹矩阵中对应的行或列按照算子的同质深度排序。In this way, when the processor determines the first footprint matrix, it can be determined according to the sequence of the numbers of the operators of the first calculation graph in the first partition; when the processor determines the second footprint matrix, it can be determined according to the second calculation in the first partition. The order of the numbering of the operators of the graph is determined. In this way, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix can have the same homogeneous depth, the operators corresponding to the columns in the same position have the same homogeneous depth, and belong to the first calculation of the same first partition. The corresponding rows or columns of the operators of the graph in the first footprint matrix are sorted according to the homogeneous depth of the operators, and the corresponding rows or columns of the operators of the second calculation graph of the same first partition in the second footprint matrix are sorted according to the operator's homogeneous depth. Homogeneous depth ordering of .
通过同质深度区分具有相同属性的算子,可以避免通过算子的名称区分属性相同的算子的不可靠性,并且根据同质深度对同质算子进行编号和排序,也有利于加速映射的过程,因为属于同一第一区域且同质深度相同的算子之间存在映射关系的可能性更大。Distinguishing operators with the same attributes by the homogeneous depth can avoid the unreliability of distinguishing operators with the same attributes by the names of the operators, and numbering and sorting homogeneous operators according to the homogeneous depth is also conducive to speeding up the mapping process, because it is more likely that there is a mapping relationship between operators that belong to the same first region and have the same homogeneous depth.
由于用户对算子命名存在主观性或者缺失的情况,如果根据用户命名的算子的名称区分具有相同属性的算子,存在的一个问题是可能无法很好的区分(存在重命名或者缺失命名的情况)、不可靠,另一个问题是无法反应同质算子之间的映射关系的可能性。采用本申请提供的实施方式中,以同质深度区分具有相同属性的同质算子可以很好的解决上述两个问题。Due to the subjectivity or lack of user naming of operators, if the operators with the same attributes are distinguished according to the names of the operators named by the user, there is a problem that it may not be well differentiated (renamed or missing names) case), unreliable, and another problem is the possibility of not reflecting the mapping relationship between homogeneous operators. In the embodiments provided in this application, the above two problems can be well solved by distinguishing homogeneous operators with the same properties by homogeneous depth.
图8和图9分别示出根据本申请一实施例的确定同质算子的同质深度的示意图。如图8所示的计算图中,存在四个同质算子Conv,第一个算子Conv的同质深度为1,第二个Conv算子的同质深度为2,因为从该算子的第一个同质算子(第一个Conv算子)开始到该算子(第二个Conv算子),第二个Conv算子的同质算子一共两个(一个是第一个Conv算子,一个是其自身),因此,第二个Conv算子的同质深度为2。同理可以确定图8所示的计算图中其他算子的同质深度。FIG. 8 and FIG. 9 respectively show schematic diagrams of determining the homogeneity depth of a homogeneity operator according to an embodiment of the present application. In the calculation diagram shown in Figure 8, there are four homogenous operators Conv, the homogeneity depth of the first operator Conv is 1, and the homogeneity depth of the second Conv operator is 2, because from this operator The first homogenous operator (the first Conv operator) starts to the operator (the second Conv operator), and the second Conv operator has a total of two homogenous operators (one is the first Conv operator, one is itself), therefore, the homogeneity depth of the second Conv operator is 2. Similarly, the homogeneity depths of other operators in the computation graph shown in FIG. 8 can be determined.
如图9所示,从上往下数第4个Conv算子(图9中填充了图案的算子),属于两个分支,在两个不同的分支中,该算子对应的同质深度是不同的,比如说,左侧分支上在第4个Conv算子之前有一个Conv算子,第4个Conv算子的同质深度为2,右侧分支上在第4个Conv算子之前有两个Conv算子,第4个Conv算子的同质深度为3。此时,从该算子的第一个同质算子开始到该算子,该算子的同质算子的最大数目为3,因此,第4个Conv算子的同质深度为3。As shown in Figure 9, the fourth Conv operator from top to bottom (the operator filled with patterns in Figure 9) belongs to two branches. In two different branches, the corresponding homogeneous depth of the operator are different, for example, there is a Conv operator on the left branch before the 4th Conv operator, the homogeneity depth of the 4th Conv operator is 2, and on the right branch before the 4th Conv operator There are two Conv operators, and the fourth Conv operator has a homogeneity depth of 3. At this time, from the first homogenous operator of the operator to the operator, the maximum number of homogenous operators of the operator is 3, so the homogeneity depth of the fourth Conv operator is 3.
在确定第一计算图和第二计算图中的同质算子以及同质算子的同质深度后,可以对同质算子进行分区得到同质分区,并且在同质分区中根据算子的同质深度对两个计算图的算子分别进行排序和编号。After determining the homogeneity operators and the homogeneity depths of the homogeneity operators in the first calculation graph and the second calculation graph, the homogeneity operators can be partitioned to obtain homogeneity partitions, and in the homogeneity partitions, according to the operator The homogeneity depth of , sorts and numbers the operators of the two computation graphs respectively.
本申请上述的实施方式中,采用同质深度作为算子在计算图中的拓扑结构的表示方式的一个示例,本申请不限于此,还可以采用其他方式表示算子在计算图中的拓扑结构。In the above-mentioned embodiments of the present application, the homogeneous depth is used as an example of the representation of the topology structure of the operator in the calculation graph. The present application is not limited to this, and other ways can also be used to represent the topology structure of the operator in the calculation graph. .
根据本申请上述实施方式采用同质深度进行排序和编号的方法,可以很好的区分不同的同质算子,并且更快速的获得同质算子之间的映射关系,有利于加速映射的过程。According to the above-mentioned embodiments of the present application, the method of sorting and numbering by homogeneous depth can be used to distinguish different homogeneous operators well, and the mapping relationship between homogeneous operators can be obtained more quickly, which is conducive to speeding up the mapping process .
在一种可能的实现方式中,如果所述第一分区中的所述第一计算图的算子的数目和所述第二计算图的算子的数目不同,所述第一分区中还包括伪算子;其中,伪算子为不具备算子类型和操作数的算子。如果所述第二分区中的所述第一计算图的算子的数目和所述第二计算图的算子的数目不同,所述第二分区中还包括所述伪算子。In a possible implementation manner, if the number of operators of the first computation graph in the first partition is different from the number of operators of the second computation graph, the first partition further includes Pseudo-operator; wherein, a pseudo-operator is an operator without operator type and operand. If the number of operators of the first computation graph in the second partition is different from the number of operators of the second computation graph, the second partition also includes the pseudo-operator.
在一种可能的实现方式中,如果所述第一分区中的所述第一计算图的算子的数目少于所述第一分区中的所述第二计算图的算子数目,所述伪算子在所述第一足迹矩阵中对应的行或列,位于所述第一计算图中属于所述第一分区的算子对应的行或列之后;如果所述第一分区中的所述第二计算图的算子的数目少于所述第一分区中的所述第一计算图的算子数目,所述伪算子在所述第二足迹矩阵中对应的行或列,位于所述第二计算图中属于所述第一分区的算子对应的行或列之后。In a possible implementation manner, if the number of operators of the first computation graph in the first partition is less than the number of operators of the second computation graph in the first partition, the The row or column corresponding to the pseudo operator in the first footprint matrix is located after the row or column corresponding to the operator belonging to the first partition in the first calculation graph; The number of operators of the second calculation graph is less than the number of operators of the first calculation graph in the first partition, and the corresponding row or column of the pseudo operator in the second footprint matrix is located in After the row or column corresponding to the operator belonging to the first partition in the second calculation graph.
在一种可能的实现方式中,如果所述第二分区中的所述第一计算图的算子的数目少于所述第二分区中的所述第二计算图的算子数目,所述伪算子在所述第一足迹矩阵中对应的行和列与所述第一计算图中属于所述第二分区的算子对应的行和列随机排序,且行和列随机排序的方式相同;如果所述第二分区中的所述第二计算图的算子的数目少于所述第二分区中的所述第二计算图的算子数目,所述伪算子在所述第二足迹矩阵中对应的行和列与所述第二计算图中属于所述第二分区的算子对应的行和列随机排序,且行和列随机排序的方式相同。In a possible implementation manner, if the number of operators of the first computation graph in the second partition is less than the number of operators of the second computation graph in the second partition, the The rows and columns corresponding to the pseudo operators in the first footprint matrix and the rows and columns corresponding to the operators belonging to the second partition in the first calculation graph are randomly sorted, and the rows and columns are randomly sorted in the same manner; If the number of operators of the second computation graph in the second partition is less than the number of operators of the second computation graph in the second partition, the pseudo operator is located in the second footprint The corresponding rows and columns in the matrix and the rows and columns corresponding to the operators belonging to the second partition in the second computation graph are randomly ordered, and the random ordering of the rows and columns is the same.
由于在不同的深度学习框架之间迁移模型时,模型对应的计算图中的算子的数目可能是不同的。而在进行相似度计算时,特征向量的长度是相同的才能进行计算。因此,第一计算图的第一足迹矩阵和第二计算图的第二足迹矩阵的维度相同时,根据第一足迹矩阵确定的第一计算图的算子的特征向量和根据第二足迹矩阵确定的第二计算图的算子的特征向量的长度是相同的。为了确保第一计算图的第一足迹矩阵和第二计算图的第二足迹矩阵的足迹相同,在本申请提供的算子映射方法的实施例中,还可以包括:Since the model is transferred between different deep learning frameworks, the number of operators in the computation graph corresponding to the model may be different. When the similarity calculation is performed, the length of the feature vector is the same to be calculated. Therefore, when the dimensions of the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph are the same, the eigenvectors of the operators of the first computation graph determined according to the first footprint matrix and the eigenvectors of the operators of the first computation graph determined according to the second footprint matrix The lengths of the eigenvectors of the operators of the second computational graph are the same. In order to ensure that the footprints of the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph are the same, in the embodiment of the operator mapping method provided by the present application, it may further include:
若同质分区中第一计算图的算子的数目和第二计算图的算子的数目不同,则在同质分区中为算子的数目少的计算图添加伪算子,使得所述同质分区中第一计算图和第二计算图的算子的数目相同;If the number of operators in the first computation graph is different from the number of operators in the second computation graph in the homogeneous partition, a pseudo operator is added to the computation graph with a small number of operators in the homogeneous partition, so that the same The number of operators in the first computational graph and the second computational graph in the prime partition is the same;
若混合分区中第一计算图的算子的数目和第二计算图的算子的数目不同,则在混合分区中为算子的数目少的计算图添加伪算子,使得所述混合分区中第一计算图和第二计算图的算子的数目相同。If the number of operators in the first computation graph is different from the number of operators in the second computation graph in the mixed partition, a pseudo-operator is added to the computation graph with a small number of operators in the mixed partition, so that the mixed partition The number of operators of the first computational graph and the second computational graph is the same.
在同质分区和混合分区中添加伪算子时,可以随机对伪算子进行排序和编号。在一种可能的实现方式中,在同质分区中添加伪算子时,可以将伪算子排在计算图的算子之后。在混合分区中,伪算子和计算图的算子都可以随机排序,并按照排序编号。When adding pseudo-operators in homogeneous and mixed partitions, the pseudo-operators can be randomly sorted and numbered. In a possible implementation manner, when a pseudo operator is added to the homogeneous partition, the pseudo operator may be arranged after the operator of the calculation graph. In hybrid partitioning, both pseudo-operators and operators of the computation graph can be randomly ordered and numbered according to the ordering.
伪算子是虚构的填充物,不具备任何有意义的算子属性或拓扑结构,伪算子存在目的是为了令第一计算图和第二计算图的算子总数相等,从而构造出大小相同的足迹矩阵,以令之后的矩阵运算得以正常进行。这样,本申请提供的算子映射方法可以应用于采用不同的计算图表示方式的框架或者系统之间迁移模型的场景下。Pseudo-operators are fictitious fillers that do not have any meaningful operator properties or topology. The purpose of pseudo-operators is to make the total number of operators in the first computational graph and the second computational graph equal, so as to construct the same size. the footprint matrix, so that the subsequent matrix operations can be performed normally. In this way, the operator mapping method provided by the present application can be applied to the scenarios of frameworks or migration models between systems using different computational graph representations.
需要说明的是,以上关于确定同质深度、分区、添加伪算子、排序和编号的先后顺序仅仅是本申请的一个示例,本申请不限于上述顺序。比如说,处理器还可以按照以下顺序执行上述过程:处理器可以确定第一计算图和第二计算图中的算子的同质深度;将第一计算图和第二计算图中的算子进行分区,得到同质分区和/或混合分区,同时,可以在同质分区中按照算子的同质深度对第一计算图和第二计算图的算子分别进行排序,排序是按照同质深度由大到小或者由小到大都可以,本申请对此不作限定;处理器根据同质分区中两个计算图的算子的数量,添加伪算子,处理器可以将所有伪算子的同质深度设置为最大(真算子+伪算子总数),对于同质分区可以按照同质深度对伪算子进行排序,混合分区可以对伪算子随机排序;之后,处理器可以为所有的算子进行编号。It should be noted that the above sequence of determining the homogeneous depth, partitioning, adding pseudo-operators, sorting and numbering is only an example of the present application, and the present application is not limited to the above sequence. For example, the processor may also perform the above process in the following order: the processor may determine the homogeneity depth of the operators in the first and second computation graphs; Partitioning is performed to obtain homogeneous partitions and/or mixed partitions. At the same time, the operators of the first computational graph and the second computational graph can be sorted according to the homogeneous depth of the operators in the homogeneous partition, and the sorting is based on the homogeneity. The depth can be from large to small or from small to large, which is not limited in this application; the processor adds pseudo-operators according to the number of operators in the two calculation graphs in the homogeneous partition, and the processor can The homogeneous depth is set to the maximum (true operator + total number of pseudo-operators). For homogeneous partitions, pseudo-operators can be sorted according to the homogeneous depth, and for mixed partitions, pseudo-operators can be randomly sorted; The operators are numbered.
图10示出根据本申请一实施例的插入伪算子的示例。如图10所示,在第一个同质分区中,为左侧的计算图添加了两个伪算子q(3)、q(4),第二个同质分区中,为右侧的计算图添加了一个伪算子r(7),在混合分区中,为左侧的计算图添加了两个伪算子。添加了伪算子之后,第一计算图和第二计算图的算子的数目是相同的。FIG. 10 shows an example of an insertion pseudo-operator according to an embodiment of the present application. As shown in Figure 10, in the first homogeneous partition, two pseudo-operators q(3) and q(4) are added to the left computational graph, and in the second homogeneous partition, the right A pseudo-operator r(7) is added to the computational graph, and in the mixed partition, two pseudo-operators are added to the computational graph on the left. After the pseudo-operator is added, the number of operators in the first computation graph and the second computation graph is the same.
在确定第一计算图的第一足迹矩阵和第二计算图的第二足迹矩阵时,两个伪算子q(3)、q(4)在第一足迹矩阵中对应的行和列在算子q(1)、q(2)之后,伪算子r(7)在第二足迹矩阵中对应的行和列在算子r(6)之后。另外,伪算子到其他算子都是不可达的,也就是伪算子到其 他算子的最短距离都是无穷大,最短距离的倒数都是0,也就是在足迹矩阵中,伪算子对应的元素值都为0。When determining the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph, the corresponding rows and columns of the two pseudo-operators q(3) and q(4) in the first footprint matrix are calculated. After the sub-q(1), q(2), the corresponding row and column of the pseudo-operator r(7) in the second footprint matrix are after the operator r(6). In addition, the pseudo operator is unreachable to other operators, that is, the shortest distance from the pseudo operator to other operators is infinite, and the reciprocal of the shortest distance is 0, that is, in the footprint matrix, the pseudo operator corresponds to The elements of are all 0.
应用示例Application example
下面结合具体的应用场景和示例,对本申请提供的计算图的算子映射方法进行说明。The operator mapping method of the computation graph provided by the present application will be described below with reference to specific application scenarios and examples.
应用场景和示例说明:将ResNet50模型从TensorFlow迁移到MindSpore,迁移过程中协助定位有问题的脚本位置。ResNet50模型在TensorFlow v1.14平台上的计算图的算子数为5176,在MindSpore v1.0.0平台上的计算图的算子数为2513。在本示例中,将TensorFlow的计算图表示为R,将MindSpore的计算图表示为Q。下面结合该应用场景和示例对本申请的算子映射方法进行说明。Application scenario and example description: Migrate the ResNet50 model from TensorFlow to MindSpore, and assist in locating the problematic script during the migration process. The number of operators in the calculation graph of the ResNet50 model on the TensorFlow v1.14 platform is 5176, and the number of operators in the calculation graph on the MindSpore v1.0.0 platform is 2513. In this example, denote the computation graph of TensorFlow as R and the computation graph of MindSpore as Q. The operator mapping method of the present application will be described below with reference to the application scenario and the example.
图11示出根据本申请一实施例的算子映射方法的流程图。结合图2所示的示例,在从TensorFlow v1.14的模型脚本中导出计算图R,从MindSpore v1.0.0的模型脚本中导出计算图Q后,将计算图输入到处理器。处理器可以执行图11所示的算子映射方法。FIG. 11 shows a flowchart of an operator mapping method according to an embodiment of the present application. Combined with the example shown in Figure 2, after exporting the computational graph R from the model script of TensorFlow v1.14 and exporting the computational graph Q from the model script of MindSpore v1.0.0, input the computational graph to the processor. The processor may execute the operator mapping method shown in FIG. 11 .
处理器可以对计算图Q和计算图R中的算子计算同质深度。The processor may compute the homogenous depth for the operators in the computation graph Q and the computation graph R.
仍然以图8和图9所示的示例为例,如图8所示,假设图8中所有算子输出的张量的维度一致,以每个算子作为起点,往入边(inedge)的方向向上遍历,查找有多少个与起点的算子同质(属性相同)的算子,把同质算子的数目加一便是起点的算子的同质深度,如图8所示的最后一个Conv算子之前有三个Conv算子,最后一个Conv算子的同质深度为4。在图9所示的示例中,存在多个分支,从上往下数第4个Conv算子(图9中填充了图案的算子),属于两个分支,在两个不同的分支中,该算子对应的同质深度是不同的,比如说,左侧分支上在第4个Conv算子之前有一个Conv算子,第4个Conv算子的同质深度为2,右侧分支上在第4个Conv算子之前有两个Conv算子,第4个Conv算子的同质深度为3。此时,从该算子的第一个同质算子开始到该算子,该算子的同质算子的最大数目为3,因此,第4个Conv算子的同质深度为3。Still taking the examples shown in Figure 8 and Figure 9 as an example, as shown in Figure 8, assuming that the dimensions of the tensors output by all operators in Figure 8 are the same, using each operator as a starting point, go to the edge Traverse upwards in the direction to find how many operators are homogeneous (with the same attributes) as the operator at the starting point, and add one to the number of homogeneous operators to obtain the homogeneity depth of the operator at the starting point, as shown in Figure 8 at the end A Conv operator is preceded by three Conv operators, and the last Conv operator has a homogeneity depth of 4. In the example shown in Figure 9, there are multiple branches. The fourth Conv operator (the operator filled with patterns in Figure 9) from top to bottom belongs to two branches. In two different branches, The homogeneity depths corresponding to the operators are different. For example, there is a Conv operator on the left branch before the fourth Conv operator, the homogeneity depth of the fourth Conv operator is 2, and on the right branch There are two Conv operators before the fourth Conv operator, and the homogeneity depth of the fourth Conv operator is 3. At this time, from the first homogenous operator of the operator to the operator, the maximum number of homogenous operators of the operator is 3, so the homogeneity depth of the fourth Conv operator is 3.
在计算完计算图中的算子的同质深度后,处理器可以对计算图Q和计算图R的算子进行同质分区。处理器进行同质分区后的示例可以参考图10。After calculating the homogeneous depth of the operators in the computation graph, the processor may perform homogeneous partitioning on the operators in the computation graph Q and the computation graph R. An example after the processor performs homogeneous partitioning can refer to FIG. 10 .
处理器可以将计算图Q和计算图R的算子中,类型相同、算子的输出操作数的维度大小相同的算子分入同一个同质分区中。对于计算图Q和计算图R中不存在同质算子的算子,可以设置一个混合分区,对于不存在同质算子的算子,可以分区混合分区中。举例来说,MS的tuple_getitem类算子和TF的Identity类算子,都是无法从对方的框架中找到功能相同的对应算子类型。对于这类算子,可以分入混合分区。The processor may divide the operators in the computation graph Q and the computation graph R with the same type and the same dimension size of the output operands of the operators into the same homogeneous partition. For the operators that do not have homogeneous operators in the computational graph Q and the computational graph R, a mixed partition can be set, and for the operators without homogeneous operators, they can be divided into mixed partitions. For example, MS's tuple_getitem operator and TF's Identity operator cannot find corresponding operator types with the same functions from each other's framework. For this type of operator, it can be divided into mixed partitions.
在进行同质分区后,两个计算图具有相同数量的同质分区和一个混合分区,每个同质分区与其他同质分区的算子的类型和/或输出操作数的维度不同,同质分区中,不同的同质分区排布的顺序不重要。如果在同一个同质分区中,两个计算图的算子数目不相同,处理器可以 在同质分区中为算子数目比较少的计算图添加伪算子,从而令该同质分区中两个计算图的算子数目相同。伪算子是虚构的填充物,不具备任何有意义的算子属性或拓扑结构,伪算子存在目的是为了令计算图Q和计算图R的算子总数相等,从而构造出大小相同的足迹矩阵以令之后的矩阵运算得以实行。After homogeneous partitioning, the two computation graphs have the same number of homogeneous partitions and one mixed partition, each homogeneous partition is different from the other homogeneous partitions in the type of operator and/or the dimension of the output operand, homogeneous In a partition, the order in which the different homogeneous partitions are arranged is not important. If in the same homogeneous partition, the number of operators in the two computation graphs is not the same, the processor can add a pseudo-operator to the computation graph with a relatively small number of operators in the homogeneous partition, so that the two computation graphs in the homogeneous partition have different numbers of operators. The number of operators in each computation graph is the same. Pseudo-operators are fictitious fillers that do not have any meaningful operator attributes or topology. The purpose of pseudo-operators is to make the total number of operators in the computational graph Q and the computational graph R equal, so as to construct footprints of the same size. matrix to enable subsequent matrix operations to be performed.
完成同质分区后,处理器可以按定好的排序为算子编号,在一个同质分区中,处理器可以按照同质深度从小到大的顺序对两个计算图的算子分别进行排序和编号。同质分区中添加的伪算子排在计算图的真实算子之后,混合分区中伪算子可以排在计算图的算子之后,也可以将混合分区中的伪算子和计算图的算子进行随机排序,本申请对此不作限定。After the homogeneous partition is completed, the processor can sort and number the operators according to the predetermined order. In a homogeneous partition, the processor can sort and number the operators of the two computation graphs in the order of the homogeneous depth from small to large. . The pseudo operators added in the homogeneous partition are arranged after the real operators in the calculation graph, and the pseudo operators in the mixed partition can be arranged after the operators in the calculation graph, or the pseudo operators in the mixed partition and the operators in the calculation graph can be combined. The children are randomly sorted, which is not limited in this application.
处理器在完成同质分区后,可以按照同质分区中算子的编号的顺序分别构造第一计算图的第一足迹矩阵和第二计算图的第二足迹矩阵。完成同质分区后,计算图Q和计算图R的算子总数都为5176,处理器可以按照算子编号的顺序构造两个5176×5176的足迹矩阵,并把两个足迹矩阵的所有元素的值都初始化为0。After completing the homogeneous partition, the processor may construct the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph according to the sequence of the operator numbers in the homogeneous partition. After the homogeneous partition is completed, the total number of operators in both the computational graph Q and the computational graph R is 5176. The processor can construct two footprint matrices of 5176 × 5176 in the order of operator numbers, and combine all elements of the two footprint matrices. Values are initialized to 0.
计算图Q的足迹矩阵q,全部初始化为0:Compute the footprint matrix q of the graph Q, all initialized to 0:
   q1q1 q2q2 q3q3 q5176 q5176
q1q1 00 00
q2q2
q3q3
q5176q5176 00 00
计算图Q的足迹矩阵r,全部初始化为0:Calculate the footprint matrix r of the graph Q, all initialized to 0:
   r1r1 r2r2 r3r3 r5176r5176
r1 r1 00 00
r2r2
r3r3
r5176r5176 00 00
计算图Q和计算图R的足迹矩阵中存储对应的计算图中算子到算子之间可达的最短距离的倒数,由于计算图Q和计算图R都是有向图,有些算子之间是不可达的,所以足迹矩阵可以是不对称的。The footprint matrix of the computation graph Q and the computation graph R stores the reciprocal of the shortest reachable distance from the operator to the operator in the corresponding computation graph. Since the computation graph Q and the computation graph R are both directed graphs, some operators are are not reachable, so the footprint matrix can be asymmetric.
处理器可以分别遍历计算图Q和计算图R中的算子,找出算子到其他算子的最短距离,并根据最短距离确定足迹矩阵。以计算图Q为例,处理器可以将计算图Q中的每一个算子作为起点,进行可以重复访问算子的深度优先遍历,每当访问一个算子,便把一个按访问距离衰减的足迹值(访问距离的倒数)放到足迹矩阵中起点算子所在的列、受访算子所在的行的对 应元素中。如果该受访算子在本次遍历中已被访问过并且已被授予较大或相等的足迹值,处理器可以不更新足迹矩阵中高对应的元素,并且不会再访问该受访算子的直接下游算子(已经访问过了)。所有伪算子的相关足迹值均为0。The processor can traverse the operators in the computation graph Q and the computation graph R respectively, find out the shortest distance from the operator to other operators, and determine the footprint matrix according to the shortest distance. Taking the computational graph Q as an example, the processor can use each operator in the computational graph Q as a starting point to perform a depth-first traversal that can repeatedly access the operators. The value (the inverse of the visit distance) is placed in the corresponding element of the column where the origin operator is located and the row where the visited operator is located in the footprint matrix. If the visited operator has already been visited in this traversal and has been granted a larger or equal footprint value, the processor may not update the high corresponding element in the footprint matrix, and will no longer visit the visited operator's Direct downstream operator (already visited). The associated footprint value of all pseudo-operators is 0.
图12示出根据本申请一实施例的确定最短距离的示意图。如图12所示,从起点算子开始遍历其他算子,确定起点算子到其他算子的最短距离以及对应的足迹值。起点算子到上一个算子的距离为无穷大,因此,足迹值为0。起点算子到连接的两个子节点对应的算子的最短距离都为1,对应的足迹值都是1。图12中最后一个算子为伪算子,因此,起点算子到伪算子的足迹值为0。根据以上过程,逐个确定图12中起点算子到其他算子的足迹值。根据足迹值可以确定图12所示的计算图对应的足迹矩阵。FIG. 12 shows a schematic diagram of determining the shortest distance according to an embodiment of the present application. As shown in Figure 12, traverse other operators from the starting point operator to determine the shortest distance from the starting point operator to other operators and the corresponding footprint value. The distance from the start operator to the previous operator is infinite, so the footprint value is 0. The shortest distance from the origin operator to the operator corresponding to the two connected child nodes is 1, and the corresponding footprint value is 1. The last operator in Figure 12 is a pseudo-operator, so the footprint value from the starting point operator to the pseudo-operator is 0. According to the above process, the footprint values from the starting point operator to other operators in Fig. 12 are determined one by one. The footprint matrix corresponding to the calculation graph shown in FIG. 12 can be determined according to the footprint value.
通过对第一计算图和第二计算图的算子进行同质分区、确定算子的同质深度,在同质分区中按照算子的同质深度对算子进行排序和编号,按照同质分区中算子的同质深度的顺序分别确定第一计算图的第一足迹矩阵和第二计算图的第二足迹矩阵。这样,第一足迹矩阵和第二足迹矩阵相同位置的行和列对应的算子的功能是相同或者相似的,并且第一足迹矩阵指示了第一计算图的算子和第一计算图中其他算子之间的拓扑关系,第二足迹矩阵指示了第二计算图的算子和第二计算图中其他算子之间的拓扑关系。The operators of the first calculation graph and the second calculation graph are homogeneously partitioned, the homogeneous depth of the operators is determined, and the operators are sorted and numbered according to the homogeneous depth of the operators in the homogeneous partition. The order of the homogeneity depths of the operators in the partition determines the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph, respectively. In this way, the functions of the operators corresponding to the rows and columns in the same position of the first footprint matrix and the second footprint matrix are the same or similar, and the first footprint matrix indicates the operators of the first calculation graph and other operators in the first calculation graph. The topological relationship between operators, the second footprint matrix indicates the topological relationship between the operators of the second calculation graph and other operators in the second calculation graph.
在确定计算图Q和计算图R对应的足迹矩阵后,处理器可以根据计算图Q和计算图R对应的足迹矩阵计算相似度矩阵。After determining the footprint matrices corresponding to the computation graph Q and the computation graph R, the processor may calculate the similarity matrix according to the footprint matrices corresponding to the computation graph Q and the computation graph R.
在一个示例中,可以根据足迹矩阵q和足迹矩阵r计算计算图Q和计算图R中算子的余弦相似性,来衡量两个计算图中的两个算子之间的相似性。具体的过程为:根据足迹矩阵q确定计算图Q中的算子的第一特征向量,根据足迹矩阵r确定计算图R中的算子的第二特征向量;根据第一特征向量和第二特征向量计算计算图Q中的算子和计算图R中的算子的相似度矩阵。In one example, the cosine similarity of the operators in the computation graph Q and the computation graph R can be calculated according to the footprint matrix q and the footprint matrix r to measure the similarity between two operators in the two computation graphs. The specific process is: determining the first eigenvector of the operator in the calculation graph Q according to the footprint matrix q, determining the second eigenvector of the operator in the calculation graph R according to the footprint matrix r; according to the first eigenvector and the second eigenvector The vector computation computes the similarity matrix between the operators in the computation graph Q and the operators in the computation graph R.
以计算图Q中的一个算子qk为例,其中,k为1~5176之间的整数,算子qk的特征向量可以表示为:Taking an operator qk in the calculation graph Q as an example, where k is an integer between 1 and 5176, the eigenvector of the operator qk can be expressed as:
Figure PCTCN2021127123-appb-000014
其中,col(qk)为算子qk所属的足迹矩阵中对应的列向量,row(qk)为算子qk所属的足迹矩阵中对应的行向量,concat为拼接算子,将算子在对应的足迹矩阵中所在行的行向量和所在列的列向量进行拼接,得到算子的特征向量
Figure PCTCN2021127123-appb-000015
Figure PCTCN2021127123-appb-000014
Among them, col(qk) is the corresponding column vector in the footprint matrix to which the operator qk belongs, row(qk) is the corresponding row vector in the footprint matrix to which the operator qk belongs, and concat is the splicing operator. The row vector of the row in the footprint matrix is spliced with the column vector of the column to obtain the eigenvector of the operator
Figure PCTCN2021127123-appb-000015
根据确定的足迹矩阵q和足迹矩阵r可以得到计算图Q的特征向量矩阵和计算图R的特征向量矩阵。According to the determined footprint matrix q and footprint matrix r, the eigenvector matrix of the computational graph Q and the eigenvector matrix of the computational graph R can be obtained.
计算图Q的特征向量矩阵如下表所示,粗实线以上部分可以为计算图Q中的算子对应的列向量,粗实线以下部分可以为计算图Q中算子对应的行向量拼接到了列向量下方得到的,计算图Q的特征向量矩阵为10352×5176:The eigenvector matrix of the calculation graph Q is shown in the following table. The part above the thick solid line can be the column vector corresponding to the operator in the calculation graph Q, and the part below the thick solid line can be the row vector corresponding to the operator in the calculation graph Q. Obtained below the column vector, the eigenvector matrix of the computational graph Q is 10352×5176:
q1q1 q2q2 q3q3 q5176q5176
同样,计算图R的特征向量矩阵如下表所示,粗实线以上部分可以为计算图R中的算子对应的列向量,粗实线以下部分可以为计算图R中算子对应的行向量拼接到了列向量下方得到的,计算图R的特征向量矩阵为10352×5176:Similarly, the eigenvector matrix of the calculation graph R is shown in the following table, the part above the thick solid line can be the column vector corresponding to the operator in the calculation graph R, and the part below the thick solid line can be the row vector corresponding to the operator in the calculation graph R After splicing it under the column vector, the eigenvector matrix of the calculation graph R is 10352×5176:
r1r1 r2r2 r3r3 r5176r5176
由于第一足迹矩阵指示了第一计算图的算子和第一计算图中其他算子之间的拓扑关系,第二足迹矩阵指示了第二计算图的算子和第二计算图中其他算子之间的拓扑关系,因此,本申请提供的提取算子的特征向量的方式得到的算子的特征向量可以很好的反应出一个算子和计算图中其他算子之间的拓扑关系,也就是该算子在所在的计算图中的“特征”。Since the first footprint matrix indicates the topological relationship between the operators of the first computation graph and other operators in the first computation graph, the second footprint matrix indicates the operators of the second computation graph and other operators in the second computation graph The topological relationship between the operators, therefore, the eigenvector of the operator obtained by the method of extracting the eigenvector of the operator provided by this application can well reflect the topological relationship between an operator and other operators in the calculation graph, That is, the "feature" of the operator in the calculation graph where it is located.
任意两个非零特征向量的余弦相似性的值为0到1之间的实数,越是接近1代表两个特征向量越是相似,表示特征向量对应的两个算子越相似。零特征向量和任意特征向量的相似性被定义为0,即完全不相似。The value of the cosine similarity of any two non-zero eigenvectors is a real number between 0 and 1. The closer to 1, the more similar the two eigenvectors are, and the more similar the two operators corresponding to the eigenvectors are. The similarity between a zero eigenvector and an arbitrary eigenvector is defined as 0, i.e. not at all similar.
根据以上确定的算子的特征向量,任意两个算子的相似性可以表示为:According to the eigenvectors of the operators determined above, the similarity of any two operators can be expressed as:
Figure PCTCN2021127123-appb-000016
其中,k和l都为1~5176之间的整数,
Figure PCTCN2021127123-appb-000017
分别表示算子qk和rl的特征向量。
Figure PCTCN2021127123-appb-000016
Among them, k and l are both integers between 1 and 5176,
Figure PCTCN2021127123-appb-000017
represent the eigenvectors of operators qk and rl, respectively.
在本申请的实施例中,足迹矩阵的行和列的位置是等价于算子的映射关系的,因此,在计算相似性矩阵时,处理器计算计算图Q和计算R的所有的算子之间的相似度,得到相似度 矩阵如下:In the embodiment of the present application, the positions of the rows and columns of the footprint matrix are equivalent to the mapping relationship of the operators. Therefore, when calculating the similarity matrix, the processor calculates all the operators of the calculation graph Q and the calculation R The similarity between the obtained similarity matrix is as follows:
Figure PCTCN2021127123-appb-000018
Figure PCTCN2021127123-appb-000018
根据相似度矩阵可以计算目标函数
Figure PCTCN2021127123-appb-000019
的值。
The objective function can be calculated according to the similarity matrix
Figure PCTCN2021127123-appb-000019
value of .
之后,处理器可以根据图5b的过程更新足迹矩阵,由于算子在足迹矩阵中对应的的行列位置等价于算子之间映射关系,所以找到阶段最优算子的映射关系后可以更新足迹矩阵,然后继续计算相似度矩阵。在更新足迹矩阵时,可以固定两个足迹矩阵中的一个的行和列的位置不变,调整另一个足迹矩阵中的行和列的位置。调整的足迹矩阵可以是计算图Q的足迹矩阵,也可以是计算图R的足迹矩阵。在一种可能的实现方式中,可以选择真实算子较少的计算图的足迹矩阵进行调整,减少调整的次数,比如说,在本示例中,可以选择计算图Q的足迹矩阵进行调整。After that, the processor can update the footprint matrix according to the process of Figure 5b. Since the corresponding row and column positions of the operators in the footprint matrix are equivalent to the mapping relationship between the operators, the footprint can be updated after finding the mapping relationship of the optimal operator in the stage. matrix, and then continue to calculate the similarity matrix. When updating the footprint matrix, you can fix the row and column position of one of the two footprint matrices unchanged, and adjust the row and column position of the other footprint matrix. The adjusted footprint matrix can be either the footprint matrix of the computational graph Q or the footprint matrix of the computational graph R. In a possible implementation manner, the footprint matrix of the computation graph with fewer real operators can be selected for adjustment, so as to reduce the number of adjustments. For example, in this example, the footprint matrix of the computation graph Q can be selected for adjustment.
图13示出根据本申请一实施例的调整足迹矩阵的示意图。如图13所示,处理器可以将第7行调整到第1行的位置,将第9行调整到第2行的位置,将第2行调整到最后一行的位置…同时,将第7列调整到第1列的位置,将第9列调整到第2列的位置,将第2列调整到最后一列的位置。FIG. 13 shows a schematic diagram of adjusting the footprint matrix according to an embodiment of the present application. As shown in Figure 13, the processor can adjust row 7 to the position of row 1, row 9 to the position of row 2, row 2 to the position of the last row... At the same time, the 7th column Adjust to the position of column 1, adjust the position of column 9 to the position of column 2, and adjust the position of column 2 to the position of the last column.
根据调整后的计算图Q的足迹矩阵以及计算图R的足迹矩阵可以继续计算相似度矩阵,并计算目标函数的值。According to the footprint matrix of the adjusted calculation graph Q and the footprint matrix of the calculation graph R, the similarity matrix can be continuously calculated, and the value of the objective function can be calculated.
然后,处理器可以判断是否达到停止条件,止条件可以是指多次计算得到的相似度矩阵(目标函数值)满足的条件,或者,停止条件也可以是迭代的次数,本申请对此不作限定。Then, the processor can determine whether a stop condition is reached, and the stop condition may refer to a condition satisfied by the similarity matrix (objective function value) obtained by multiple calculations, or the stop condition may also be the number of iterations, which is not limited in this application .
在未达到停止条件时,处理器可以继续更新足迹矩阵、根据更新后的足迹矩阵计算相似度并判断是否达到停止条件的过程,直到达到停止条件。处理器可以根据达到停止条件时的足迹矩阵确定算子之间的映射关系。When the stop condition is not reached, the processor may continue the process of updating the footprint matrix, calculating the similarity according to the updated footprint matrix, and judging whether the stop condition is reached, until the stop condition is reached. The processor may determine the mapping relationship between the operators according to the footprint matrix when the stopping condition is reached.
对于同质分区,可以直接将两个足迹矩阵中相同的行(或列)对应的两个算子中,一个算子确定为另一个算子的映射算子。比如说,达到停止条件时,调整得到的计算图Q的足迹矩阵为:For a homogeneous partition, one of the two operators corresponding to the same row (or column) in the two footprint matrices can be directly determined as the mapping operator of the other operator. For example, when the stopping condition is reached, the footprint matrix of the adjusted computational graph Q is:
   q3q3 q2q2 q1q1 q5176 q5176
q3q3 00 00
q2q2
q1q1
q5176q5176 00 00
算子q3的映射算子为r1,算子q2的映射算子为r2,算子q1的映射算子为r3……。也就是说,两个足迹矩阵相同的行(或列)对应的两个算子互为对方的映射算子。The mapping operator of operator q3 is r1, the mapping operator of operator q2 is r2, the mapping operator of operator q1 is r3... . That is to say, the two operators corresponding to the same row (or column) of the two footprint matrices are each other's mapping operators.
处理器可以根据两个足迹矩阵输出同质分区中算子之间的一对一的映射关系。The processor can output a one-to-one mapping relationship between operators in the homogeneous partition according to the two footprint matrices.
而对于混合分区的算子,是没有映射算子的。处理器可以根据历次迭代计算得到的相似度矩阵输出混合分区中算子的映射建议,具体可以为,处理器根据相似度矩阵中混合区算子与另一算子的余弦相似性的大小进行排序,确定排序靠前的一个或多个(例如,5个)算子作为混合区算子的映射建议,可以输出对应的映射算子以及余弦相似性的值作为映射建议。For the mixed partition operator, there is no mapping operator. The processor may output a mapping suggestion of the operators in the mixed partition according to the similarity matrix calculated by the previous iterations. Specifically, the processor may sort according to the size of the cosine similarity between the mixed region operator and another operator in the similarity matrix. , determine the top-ranked one or more (for example, 5) operators as the mapping suggestion of the mixed area operator, and output the corresponding mapping operator and the value of the cosine similarity as the mapping suggestion.
以TF的Identity类算子为例,在对计算图Q的足迹矩阵进行调整和计算相似度矩阵的过程中,计算了Identity类算子与混合区中其他算子之间的余弦相似性。对计算得到的多个余弦相似性按照由大到小的顺序排序,可以取排序中前五个算子以及对应的余弦相似性的值作为Identity类算子的映射建议进行输出。Taking the Identity class operator of TF as an example, in the process of adjusting the footprint matrix of the computational graph Q and calculating the similarity matrix, the cosine similarity between the Identity class operator and other operators in the mixed region is calculated. Sort the calculated cosine similarities in descending order, and take the first five operators in the sorting and the corresponding cosine similarity values as the mapping suggestions for the Identity class operators for output.
在一种可能的实现方式中,本申请还提供了一种衡量映射结果是否比较好的参数:L1范数。可以根据足迹矩阵q和足迹矩阵r计算足迹差值矩阵D,并计算足迹差值矩阵的L1范数,来衡量两个计算图中的算子之间的相似性。In a possible implementation manner, the present application also provides a parameter for measuring whether the mapping result is better: L1 norm. The footprint difference matrix D can be calculated according to the footprint matrix q and the footprint matrix r, and the L1 norm of the footprint difference matrix can be calculated to measure the similarity between the operators in the two calculation graphs.
足迹差值矩阵可以根据以下公式计算得到:The footprint difference matrix can be calculated according to the following formula:
D=q-r,其中D表示足迹差值矩阵;D=q-r, where D represents the footprint difference matrix;
L1范数=∑ ij|d ij|,L1范数越小,可以表示两个足迹矩阵越接近,代表两个计算图在拓扑上越相似。 L1 norm=∑ ij |d ij |, the smaller the L1 norm, the closer the two footprint matrices are, and the more similar the two computation graphs are in topology.
根据前述示例中调整第一足迹矩阵中的行和列的顺序对第一足迹矩阵进行调整,并根据调整后的第一足迹矩阵和第二足迹矩阵继续计算L1范数。通过计算调整足迹矩阵的过程中L1范数的变化,可以判断得到的映射关系是否能反应两个计算图的相似性。Adjust the first footprint matrix according to the order in which the rows and columns in the first footprint matrix are adjusted in the foregoing example, and continue to calculate the L1 norm according to the adjusted first footprint matrix and the second footprint matrix. By calculating the change of the L1 norm in the process of adjusting the footprint matrix, it can be judged whether the obtained mapping relationship can reflect the similarity of the two calculation graphs.
图14示出根据本申请一实施例的迭代计算的效果的示意图。如图14所示,随着迭代次数的增加,目标函数的值和L1范数的值都逐渐收敛,目标函数的值逐渐变大,在达到一定的值之后,变化不再明显,同样的,L1范数的值逐渐变小,在达到一定的值之后,变化不再明显。FIG. 14 shows a schematic diagram of the effect of iterative calculation according to an embodiment of the present application. As shown in Figure 14, as the number of iterations increases, the value of the objective function and the value of the L1 norm gradually converge, and the value of the objective function gradually becomes larger. After reaching a certain value, the change is no longer obvious. Similarly, The value of the L1 norm gradually becomes smaller, and after reaching a certain value, the change is no longer obvious.
因此,可以通过设置目标函数或者L1范数的阈值,或者迭代次数的方式来这只停止条件。在本申请的上述应用示例中,可以将迭代次数设置为5或者6,已经足够得到比较好的映射关系。Therefore, the stopping condition can be set by setting the threshold of the objective function or L1 norm, or the number of iterations. In the above application example of the present application, the number of iterations can be set to 5 or 6, which is enough to obtain a better mapping relationship.
下表示出将ResNet50模型从TensorFlow迁移到MindSpore的示例中的映射效果的一些参数。在本示例中,本申请提供的算子映射方法可以在90s内算完,完成99%的骨干算子的一对一映射,并给出多对多的映射建议,可以给出全部算子中40%的算子的一对一映射。The following table shows some parameters of the mapping effect in the example of migrating the ResNet50 model from TensorFlow to MindSpore. In this example, the operator mapping method provided by this application can complete the calculation within 90s, complete the one-to-one mapping of 99% of the backbone operators, and provide many-to-many mapping suggestions, which can give all operators One-to-one mapping of 40% of the operators.
MS v1.0.0算子总数The total number of MS v1.0.0 operators 25132513
1对1映射数1 to 1 mapping number 994(40%)994 (40%)
多对多映射数Many-to-many mapping number 所有MS算子都有Top-K映射建议All MS operators have Top-K mapping suggestions
*骨干算子数* number of backbone operators 895895
*骨干算子1对1映射数* Backbone operator 1-to-1 mapping number 888(99%)888 (99%)
映射运算时间Map operation time ~90s~90s
本申请提供的实施例的算子映射装置,通过构建两个计算图的足迹矩阵,足迹矩阵为表示计算图的算子之间的拓扑关系的矩阵。根据足迹矩阵可以迭代计算指示两个计算图的拓扑关系的第一矩阵,迭代停止后,可根据足迹矩阵确定优选的一种或多种映射关系。在构建第一足迹矩阵和第二足迹矩阵、以及调整第一足迹矩阵时,保证第一足迹矩阵和第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,也就是第一足迹矩阵和第二足迹矩阵相同位置的行对应的算子、相同位置的列对应的算子在功能上是相同的。结合相似度矩阵衡量算子之间的拓扑关系的相似度。根据本申请提供的算子映射装置,可以从功能和拓扑关系上体现两个算子之间的映射关系,从而确保映射结果的正确性。The operator mapping apparatus of the embodiments provided by the present application constructs footprint matrices of two computation graphs, where the footprint matrix is a matrix representing the topological relationship between operators in the computation graph. A first matrix indicating the topological relationship between the two computational graphs can be iteratively calculated according to the footprint matrix, and after the iteration is stopped, one or more preferred mapping relationships can be determined according to the footprint matrix. When constructing the first footprint matrix and the second footprint matrix, and adjusting the first footprint matrix, ensure the type of the operator corresponding to the row at the same position and the type of the operator corresponding to the column at the same position of the first footprint matrix and the second footprint matrix The same, the dimensions of the tensors output by the operators are the same, that is, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns in the same position are functionally the same. Combine the similarity matrix to measure the similarity of the topological relationship between operators. According to the operator mapping device provided by the present application, the mapping relationship between two operators can be reflected in terms of functions and topological relationships, thereby ensuring the correctness of the mapping result.
对于不存在同质算子的算子,本申请提供的算子映射方法可以输出映射建议,支持一对一、一对多和多对多的映射,本申请提供的算子映射方法可以支持相似结构的计算图之间的算子映射,能够适用于深度学习框架进行模型迁移的场景中。For operators without homogeneous operators, the operator mapping method provided in this application can output mapping suggestions, and supports one-to-one, one-to-many and many-to-many mappings, and the operator mapping method provided in this application can support similar The operator mapping between the computational graphs of the structure can be applied to scenarios where the deep learning framework performs model migration.
应用场景和示例说明:将ResNet50模型从MindSpore v0.5.0迁移到MindSpore v1.0.0。ResNet50模型在从MindSpore v0.5.0平台上的计算图的算子数为2514,在MindSpore v1.0.0平台上的计算图的算子数为2513。在本示例中,将MindSpore v0.5.0的计算图表示为R,将MindSpore v1.0.0的计算图表示为Q。Application scenario and example description: Migrate the ResNet50 model from MindSpore v0.5.0 to MindSpore v1.0.0. The number of operators in the calculation graph of the ResNet50 model on the MindSpore v0.5.0 platform is 2514, and the number of operators in the calculation graph on the MindSpore v1.0.0 platform is 2513. In this example, the calculation graph of MindSpore v0.5.0 is denoted as R, and the calculation graph of MindSpore v1.0.0 is denoted as Q.
计算同质深度的过程参见上述示例,不再赘述。For the process of calculating the homogeneous depth, refer to the above example and will not be repeated here.
进行同质分区,在本示例中,由于是在同一个深度学习框架的不同版本之间迁移模型,所有算子均具有同质算子,进行分区后所没有混合分区。完成同质分区后,计算图Q和计算图R的算子总数都为2514。Perform homogeneous partitioning. In this example, since the model is transferred between different versions of the same deep learning framework, all operators have homogeneous operators, and there is no mixed partition after partitioning. After the homogeneous partition is completed, the total number of operators in both the computational graph Q and the computational graph R is 2514.
处理器可以按照算子编号的顺序构造两个2514×2514的足迹矩阵,并把两个足迹矩阵的所有元素的值都初始化为0。确定足迹矩阵的过程也可以参见上述示例,不再赘述。The processor can construct two 2514×2514 footprint matrices in the order of operator numbers, and initialize the values of all elements of the two footprint matrices to 0. For the process of determining the footprint matrix, reference may also be made to the above example, and details are not repeated here.
计算相似性以及输出映射关系的过程也和上文的示例相同,不再赘述。The process of calculating the similarity and outputting the mapping relationship is also the same as the above example, and will not be repeated.
图15示出根据本申请一实施例的迭代计算的效果的示意图。如图15所示,随着迭代次数的增加,目标函数的值都逐渐收敛,目标函数的值逐渐变大,在达到一定的值之后,变化不再明显。L1范数的值也于第3次迭代后不再下降。FIG. 15 shows a schematic diagram of the effect of iterative calculation according to an embodiment of the present application. As shown in Figure 15, with the increase of the number of iterations, the value of the objective function gradually converges, and the value of the objective function gradually increases. After reaching a certain value, the change is no longer obvious. The value of the L1 norm also no longer decreases after the 3rd iteration.
下表示出将ResNet50模型从MindSpore v0.5.0迁移到MindSpore v1.0.0的示例中的映射效果的一些参数。在本示例中,本申请提供的算子映射方法可以在25s内算完,完成100%的算子的一对一映射,映射速度快,准确性高。The following table shows some parameters of the mapping effect in the example of migrating the ResNet50 model from MindSpore v0.5.0 to MindSpore v1.0.0. In this example, the operator mapping method provided by the present application can complete the calculation within 25s, complete the one-to-one mapping of 100% of the operators, with fast mapping speed and high accuracy.
MS v1.0.0算子总数The total number of MS v1.0.0 operators 25132513
1对1映射数1 to 1 mapping number 2513(100%)2513 (100%)
1对1映射正确率1 to 1 mapping accuracy 83%83%
*骨干算子数* number of backbone operators 895895
*骨干算子1对1映射数* Backbone operator 1-to-1 mapping number 895(100%)895 (100%)
*骨干算子1对1映射正确率* 1-to-1 mapping accuracy rate of backbone operators 100%100%
映射运算时间Map operation time ~25s~25s
本申请提供的实施例的算子映射方法,在无须修改模型脚本的情况下,可以快速找到两个计算图一对一、一对多及多对多的算子映射关系,提升计算图对比效果,从而提高算子开发人员的测试效率及模型网络开发、迁移速度。从映射统计表中可以确定,无论是跨框架或同框架不同版本的计算图的对比,对模型问题定位直接发挥作用的骨干算子的一对一映射率及其正确性均十分高,并且运算耗时合理。有了准确的骨干算子映射关系,开发人员就可以作为参考,快速对比算子数值档案或分析模型脚本以定位问题所在。The operator mapping method of the embodiment provided by the present application can quickly find the operator mapping relationship of two calculation graphs one-to-one, one-to-many and many-to-many without modifying the model script, thereby improving the comparison effect of the calculation graphs , so as to improve the test efficiency of operator developers and the speed of model network development and migration. It can be determined from the mapping statistics table that the one-to-one mapping rate and its correctness of the backbone operators that directly play a role in the problem location of the model are very high whether it is a comparison of the calculation graphs of different versions of the framework or the same framework. Reasonable time. With accurate backbone operator mappings, developers can use it as a reference to quickly compare operator numerical files or analyze model scripts to locate problems.
根据上述示例可知,本申请的实施例提供的算子映射方法,可以快速的实现两个计算图中算子的映射,并且通过迭代计算可以得到优选的一种或多种映射关系,因此可以支持相似结构的计算图之间的算子映射,并且还可以支持一对多或多对多的映射,能够适用于深度学习框架进行模型迁移的场景中。According to the above example, the operator mapping method provided by the embodiments of the present application can quickly realize the mapping of operators in two calculation graphs, and can obtain one or more preferred mapping relationships through iterative calculation, so it can support Operator mapping between computational graphs with similar structures, and can also support one-to-many or many-to-many mapping, which can be applied to scenarios where deep learning frameworks perform model migration.
本申请的实施例提供了一种计算图的算子映射装置,用于对第一计算图和第二计算图中的算子进行算子映射,图16示出根据本申请一实施例的计算图的算子映射装置90的框图,如图16所示,算子映射装置90可以包括:An embodiment of the present application provides an operator mapping apparatus for a computation graph, which is used to perform operator mapping on operators in a first computation graph and a second computation graph. FIG. 16 shows the computation according to an embodiment of the present application. The block diagram of the operator mapping apparatus 90 shown in FIG. 16 , the operator mapping apparatus 90 may include:
迭代模块91,用于基于第一足迹矩阵和第二足迹矩阵,重复下述过程,直到达到停止条件:根据所述第一足迹矩阵和所述第二足迹矩阵计算第一矩阵,并根据所述第一矩阵调整所述第一足迹矩阵中的行和列的顺序,根据调整后的第一足迹矩阵和所述第二足迹矩阵重新计算所述第一矩阵;其中,所述第一足迹矩阵指示所述第一计算图的算子之间的拓扑关系,所述第二足迹矩阵指示所述第二计算图的算子之间的拓扑关系,所述第一矩阵指示所述第一计算图和所述第二计算图的拓扑关系的相似度;The iteration module 91 is configured to, based on the first footprint matrix and the second footprint matrix, repeat the following process until a stopping condition is reached: calculate the first matrix according to the first footprint matrix and the second footprint matrix, and calculate the first matrix according to the The first matrix adjusts the order of rows and columns in the first footprint matrix, and recalculates the first matrix according to the adjusted first footprint matrix and the second footprint matrix; wherein the first footprint matrix indicates The topological relationship between the operators of the first computational graph, the second footprint matrix indicates the topological relationship between the operators of the second computational graph, the first matrix indicates the first computational graph and the similarity of the topological relationship of the second calculation graph;
对应模块92,用于根据达到所述停止条件时的第一足迹矩阵、所述第二足迹矩阵,得到 所述第一计算图中的多个算子各自在第二计算图中对应的算子。The corresponding module 92 is configured to obtain the operators corresponding to each of the multiple operators in the first calculation graph in the second calculation graph according to the first footprint matrix and the second footprint matrix when the stopping condition is reached .
在一种可能的实现方式中,属于同一第一分区、且在达到所述停止条件时的第一足迹矩阵和所述第二足迹矩阵中对应的行或列的位置相同的所述第一计算图的算子和第二计算图的算子之间存在映射关系。In a possible implementation manner, the first calculation that belongs to the same first partition and has the same row or column position in the first footprint matrix and the second footprint matrix when the stopping condition is reached is the same There is a mapping relationship between the operators of the graph and the operators of the second computation graph.
本申请提供的实施例的算子映射装置,通过构建两个计算图的足迹矩阵,足迹矩阵为表示计算图的算子之间的拓扑关系的矩阵。根据足迹矩阵可以迭代计算指示两个计算图的拓扑关系的相似度的第一矩阵,迭代停止后,可根据足迹矩阵确定优选的一种或多种映射关系。因此,本申请提供的算子映射方法可以支持相似结构的计算图之间的算子映射,能够适用于深度学习框架进行模型迁移的场景中。The operator mapping apparatus of the embodiments provided by the present application constructs footprint matrices of two computation graphs, where the footprint matrix is a matrix representing the topological relationship between operators in the computation graph. A first matrix indicating the similarity of the topological relationship of the two computational graphs can be iteratively calculated according to the footprint matrix, and after the iteration is stopped, one or more preferred mapping relationships can be determined according to the footprint matrix. Therefore, the operator mapping method provided by the present application can support operator mapping between calculation graphs with similar structures, and can be applied to a scenario where a deep learning framework performs model migration.
在一种可能的实现方式中,所述迭代模块91包括:In a possible implementation, the iteration module 91 includes:
计算单元,用于根据多个第一特征向量和多个第二特征向量,得到所述第一矩阵,其中,每个所述第一特征向量对应所述第一计算图中的算子,每个所述第一特征向量与所述第一特征向量对应的算子在所述第一足迹矩阵中对应的行向量与列向量有关,每个所述第二特征向量对应所述第二计算图中的算子,每个所述第二特征向量与所述第二特征向量对应的算子在所述第二足迹矩阵中对应的行向量与列向量有关,所述第一特征向量和所述第二特征向量用于计算所述第一特征向量对应的算子和所述第二特征向量对应的算子之间的相似度。The calculation unit is configured to obtain the first matrix according to a plurality of first eigenvectors and a plurality of second eigenvectors, wherein each of the first eigenvectors corresponds to an operator in the first calculation graph, and each Each of the first eigenvectors and the operators corresponding to the first eigenvectors are related to the row vectors and column vectors in the first footprint matrix, and each of the second eigenvectors corresponds to the second calculation graph The operators in , each of the second eigenvectors and the operators corresponding to the second eigenvectors are related to the row vectors and column vectors in the second footprint matrix, and the first eigenvectors and the The second feature vector is used to calculate the similarity between the operator corresponding to the first feature vector and the operator corresponding to the second feature vector.
在一种可能的实现方式中,所述第一矩阵的元素的值表示所述元素所在的行对应的算子和所在的列对应的算子的相似度,其中,所述元素所在行对应的算子和所述元素所在列对应的算子分别为所述第一计算图中的算子和所述第二计算图中的算子。In a possible implementation manner, the value of the element of the first matrix represents the similarity between the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located, wherein the row corresponding to the element is located. The operator and the operator corresponding to the column where the element is located are respectively the operator in the first calculation graph and the operator in the second calculation graph.
采用算子在计算图对应的足迹矩阵中对应的行向量和列向量构建算子的特征向量,提取了算子在计算图中的拓扑关系特征。根据算子的特征向量计算算子的拓扑关系的相似度,第一计算图的算子和第二计算图的算子的拓扑关系的相似度组成相似度矩阵,通过相似度矩阵衡量两个计算图的拓扑关系的相似度。The eigenvectors of the operator are constructed by using the corresponding row and column vectors in the footprint matrix corresponding to the operator in the calculation graph, and the topological relationship characteristics of the operator in the calculation graph are extracted. The similarity of the topological relationship of the operator is calculated according to the eigenvector of the operator, and the similarity of the topological relationship of the operator of the first calculation graph and the operator of the second calculation graph forms a similarity matrix, and the similarity matrix is used to measure the two calculations. The similarity of the topological relationships of the graphs.
在一种可能的实现方式中,所述第一足迹矩阵、调整后的第一足迹矩阵与所述第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,也就是说,所述第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,调整后的第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同。In a possible implementation manner, the type of the first footprint matrix, the adjusted first footprint matrix, and the operator corresponding to the row at the same position and the type of the operator corresponding to the column at the same position of the second footprint matrix The same, the dimensions of the tensors output by the operators are the same, that is, the operators corresponding to the rows at the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns at the same position are of the same type , the dimensions of the tensors output by the operators are the same, the operators corresponding to the rows at the same position and the columns at the same positions of the adjusted first footprint matrix and the second footprint matrix are of the same type, and the operators output The dimensions of the tensors are the same.
在构建第一足迹矩阵和第二足迹矩阵、以及调整第一足迹矩阵时,保证第一足迹矩阵和第二足迹矩阵的相同位置的行对应的算子、相同位置的列对应的算子的类型相同、算子输出的张量的维度相同,也就是第一足迹矩阵和第二足迹矩阵相同位置的行对应的算子、相同位置的列对应的算子在功能上是相同的。结合相似度矩阵衡量算子之间的拓扑关系的相似度。根据本申请提供的算子映射方法,可以从功能和拓扑关系上体现两个算子之间的映射关系, 从而确保映射结果的正确性。When constructing the first footprint matrix and the second footprint matrix, and adjusting the first footprint matrix, ensure the type of the operator corresponding to the row at the same position and the type of the operator corresponding to the column at the same position of the first footprint matrix and the second footprint matrix The same, the dimensions of the tensors output by the operators are the same, that is, the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix and the operators corresponding to the columns in the same position are functionally the same. Combine the similarity matrix to measure the similarity of the topological relationship between operators. According to the operator mapping method provided by the present application, the mapping relationship between two operators can be reflected in terms of functions and topological relationships, thereby ensuring the correctness of the mapping result.
在一种可能的实现方式中,所述第一计算图和所述第二计算图中的算子分属于多个第一分区,同一第一分区的算子类型相同、且算子输出的张量的维度相同;所述第一计算图和所述第二计算图中的部分算子属于第二分区,所述第二分区中的算子类型不同和/或算子输出的张量的维度不同。所述第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子在同一第一分区、相同位置的列对应的算子在同一第一分区;且,属于同一第一分区的第一计算图的算子在所述第一足迹矩阵中对应的行或者列连续排列,属于同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或者列连续排列。In a possible implementation manner, the operators in the first calculation graph and the second calculation graph belong to multiple first partitions, the operators in the same first partition are of the same type, and the operator outputs The dimensions of the quantities are the same; some operators in the first calculation graph and the second calculation graph belong to the second partition, the types of operators in the second partition are different and/or the dimensions of the tensors output by the operators are different different. The operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are in the same first partition, and the operators corresponding to the columns in the same position are in the same first partition; and, belong to the same first partition. The operators of the first computation graph are arranged in consecutive rows or columns in the first footprint matrix, and the operators of the second computation graph belonging to the same first partition are arranged in consecutive rows or columns in the second footprint matrix arrangement.
因为同质算子之间存在映射关系的可能性更大,并且,在本申请的实施例中,第一足迹矩阵和第二足迹矩阵相同位置的行或列对应的算子之间存在映射关系。因此,根据本申请提供的上述实施例,通过对第一计算图和第二计算图中的算子进行同质分区,并且在调整第一足迹矩阵中的行和列的顺序时,调整位于同一同质分区的算子对应的行和列的顺序,可以更快速使迭代的过程收敛,加快映射的过程。Because it is more likely that there is a mapping relationship between homogeneous operators, and in the embodiment of the present application, there is a mapping relationship between the operators corresponding to the rows or columns in the same position of the first footprint matrix and the second footprint matrix . Therefore, according to the above-mentioned embodiment provided by the present application, the operators in the first calculation graph and the second calculation graph are homogeneously partitioned, and when adjusting the order of the rows and columns in the first footprint matrix, adjust the The order of the rows and columns corresponding to the operators of the homogeneous partition can make the iterative process converge faster and speed up the mapping process.
对于不存在同质算子的算子,通设置混合分区进行分类并参与迭代计算的过程得到对应的算子相似度,在确定映射算子时,可以根据计算得到的相似度输出映射建议。从而可以支持相似结构的计算图之间的算子映射,并且还可以支持一对多或多对多的映射,能够适用于深度学习框架进行模型迁移的场景中。For operators without homogeneous operators, the corresponding operator similarity can be obtained by setting mixed partitions for classification and participating in the iterative calculation process. When determining the mapping operator, mapping suggestions can be output according to the calculated similarity. Therefore, it can support operator mapping between computational graphs with similar structures, and can also support one-to-many or many-to-many mapping, which can be applied to scenarios where deep learning frameworks perform model migration.
在一种可能的实现方式中,所述第一足迹矩阵和所述第二足迹矩阵相同位置的行对应的算子的同质深度相同、相同位置的列对应的算子的同质深度相同,且属于同一第一分区的所述第一计算图的算子在所述第一足迹矩阵中对应的行或列按照算子的所述同质深度排序、同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或列按照算子的所述同质深度排序;其中,所述同质深度为:在计算图中所述算子所属的所有分支中,在所述算子之前与所述算子类型相同、输出的张量维度相同的算子的最大数目。In a possible implementation manner, the homogeneous depths of the operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are the same, and the homogeneous depths of the operators corresponding to the columns of the same position are the same, And the corresponding rows or columns of the operators of the first computation graph belonging to the same first partition in the first footprint matrix are sorted according to the homogeneous depth of the operators, and the second computation graph of the same first partition The rows or columns corresponding to the operators in the second footprint matrix are sorted according to the homogeneity depth of the operators; wherein, the homogeneity depth is: in all branches to which the operator belongs in the calculation graph, in The maximum number of operators that have the same type and output tensor dimensions as the operator before the operator.
对同质分区中的算子按照同质深度进行排序,按照确定同质分区分别确定第一计算图的第一足迹矩阵和第二计算图的第二足迹矩阵。由于同质深度相同的算子之间存在映射关系的可能性更大,因此,根据本申请上述实施方式计算相似度矩阵的过程可以快速收敛,更快的确定算子之间的映射关系,加速映射的过程。并且,通过同质深度区分具有相同属性的算子,可以避免通过算子的名称区分属性相同的算子的不可靠性。The operators in the homogeneous partition are sorted according to the homogeneous depth, and the first footprint matrix of the first computation graph and the second footprint matrix of the second computation graph are respectively determined according to the homogeneous partition. Since it is more likely that there is a mapping relationship between operators with the same homogeneous depth, the process of calculating the similarity matrix according to the above-mentioned embodiments of the present application can quickly converge, and the mapping relationship between operators can be determined more quickly. the process of mapping. In addition, by distinguishing operators with the same attributes by the homogeneous depth, the unreliability of distinguishing operators with the same attributes by the names of the operators can be avoided.
在一种可能的实现方式中,如果所述第一分区中的所述第一计算图的算子的数目和所述第二计算图的算子的数目不同,所述第一分区中还包括伪算子;其中,伪算子为不具备算子类型和操作数的算子;如果所述第一分区中的所述第一计算图的算子的数目少于所述第一分区中的所述第二计算图的算子数目,所述伪算子在所述第一足迹矩阵中对应的行或列,位于所述第一计算图中属于所述第一分区的算子对应的行或列之后;如果所述第一分区中的所述第二计算图的算子的数目少于所述第一分区中的所述第一计算图的算子数目,所述伪算子在所述第二足迹矩阵中对应的行或列,位于所述第二计算图中属于所述第一分区的算子对应的 行或列之后。In a possible implementation manner, if the number of operators of the first computation graph in the first partition is different from the number of operators of the second computation graph, the first partition further includes Pseudo-operator; wherein, the pseudo-operator is an operator without operator type and operand; if the number of operators in the first computation graph in the first partition is less than the number of operators in the first partition The number of operators in the second calculation graph, the row or column corresponding to the pseudo-operator in the first footprint matrix is located in the row corresponding to the operator belonging to the first partition in the first calculation graph or column; if the number of operators in the second computation graph in the first partition is less than the number of operators in the first computation graph in the first partition, the pseudo operator is The corresponding row or column in the second footprint matrix is located after the row or column corresponding to the operator belonging to the first partition in the second calculation graph.
在一种可能的实现方式中,如果所述第二分区中的所述第一计算图的算子的数目和所述第二计算图的算子的数目不同,所述第二分区中还包括所述伪算子;如果所述第二分区中的所述第一计算图的算子的数目少于所述第二分区中的所述第二计算图的算子数目,所述伪算子在所述第一足迹矩阵中对应的行和列与所述第一计算图中属于所述第二分区的算子对应的行和列随机排序,且行和列随机排序的方式相同;如果所述第二分区中的所述第二计算图的算子的数目少于所述第二分区中的所述第二计算图的算子数目,所述伪算子在所述第二足迹矩阵中对应的行和列与所述第二计算图中属于所述第二分区的算子对应的行和列随机排序,且行和列随机排序的方式相同。In a possible implementation manner, if the number of operators of the first computation graph in the second partition is different from the number of operators of the second computation graph, the second partition further includes the pseudo operator; if the number of operators of the first computation graph in the second partition is less than the number of operators of the second computation graph in the second partition, the pseudo operator The rows and columns corresponding to the first footprint matrix and the rows and columns corresponding to the operators belonging to the second partition in the first computation graph are randomly ordered, and the rows and columns are randomly ordered in the same manner; if the The number of operators of the second computation graph in the second partition is less than the number of operators of the second computation graph in the second partition, and the pseudo-operators correspond to the second footprint matrix The rows and columns of , and the rows and columns corresponding to the operators belonging to the second partition in the second calculation graph are randomly ordered, and the random ordering of the rows and columns is the same.
在第一计算图和第二计算图的算子的数目不同时,通添加伪算子令第一计算图和第二计算图的算子总数相等,从而构造出大小相同的足迹矩阵,以令之后的矩阵运算得以正常进行。这样,本申请提供的算子映射方法可以应用于采用不同的计算图表示方式的框架或者系统之间迁移模型的场景下。When the number of operators in the first computation graph and the second computation graph is different, the total number of operators in the first computation graph and the second computation graph is equal by adding pseudo-operators, thereby constructing footprint matrices of the same size, so that Subsequent matrix operations proceed normally. In this way, the operator mapping method provided by the present application can be applied to the scenarios of frameworks or migration models between systems using different computational graph representations.
在一种可能的实现方式中,所述迭代模块91还包括:In a possible implementation manner, the iteration module 91 further includes:
调整单元,用于根据所述第一矩阵调整所述第一足迹矩阵中位于同一所述第一分区内的算子对应的行和列的顺序。An adjustment unit, configured to adjust the order of the rows and columns corresponding to the operators located in the same first partition in the first footprint matrix according to the first matrix.
在一种可能的实现方式中,属于同一第一分区、且在达到所述停止条件时的第一足迹矩阵和所述第二足迹矩阵中对应的行或列的位置相同的所述第一计算图的算子和第二计算图的算子之间存在映射关系;属于所述第二分区的第一计算图的算子与属于第二分区的第二计算图的多个算子之间存在映射关系,其中,所述属于第二分区的第二计算图的多个算子为:达到所述停止条件时的第一矩阵中,与所述属于所述第二分区的第一计算图的算子对应的元素的值中,最大的多个值所对应的第二计算图的算子。In a possible implementation manner, the first calculation that belongs to the same first partition and has the same row or column position in the first footprint matrix and the second footprint matrix when the stopping condition is reached is the same There is a mapping relationship between the operators of the graph and the operators of the second computation graph; there is a mapping relationship between the operators of the first computation graph belonging to the second partition and multiple operators of the second computation graph belonging to the second partition A mapping relationship, wherein the multiple operators of the second computation graph belonging to the second partition are: in the first matrix when the stopping condition is reached, the number of operators in the first computation graph belonging to the second partition is Among the values of the elements corresponding to the operator, the operator of the second calculation graph corresponding to the largest multiple values.
根据本申请上述实施方式的映射方式,可以支持相似结构的计算图之间的算子映射,支持一对一、一对多和多对多的映射,能够适用于深度学习框架进行模型迁移的场景中。According to the mapping method of the above-mentioned embodiments of the present application, it is possible to support operator mapping between computational graphs with similar structures, support one-to-one, one-to-many, and many-to-many mappings, and can be applied to scenarios where deep learning frameworks perform model migration middle.
在一种可能的实现方式中,所述停止条件为所述重复计算第一矩阵的次数大于第一阈值。In a possible implementation manner, the stopping condition is that the number of times of repeatedly calculating the first matrix is greater than a first threshold.
通过对第一计算图和第二计算图中的算子进行同质分区,并且在调整第一足迹矩阵中的行和列的顺序时,调整位于同一同质分区的算子对应的行和列的顺序,可以更快速使迭代的过程收敛,加快映射的过程。这是由于同质算子的相似性更高,同质算子之间存在映射关系的可能性更大,因此,通过进行同质分区的过程可以加速迭代收敛的速度,加快映射的过程。By performing homogeneous partitioning on the operators in the first computational graph and the second computational graph, and when adjusting the order of the rows and columns in the first footprint matrix, adjust the rows and columns corresponding to the operators located in the same homogeneous partition order can make the iterative process converge faster and speed up the mapping process. This is because the similarity of homogenous operators is higher, and there is a greater possibility of a mapping relationship between homogenous operators. Therefore, the process of homogenous partitioning can accelerate the speed of iterative convergence and the process of mapping.
本申请的实施例提供了一种计算图的算子映射装置,包括:处理器以及用于存储处理器可执行指令的存储器;其中,所述处理器被配置为执行所述指令时实现上述方法。An embodiment of the present application provides an operator mapping apparatus for a computational graph, including: 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 .
图17示出根据本申请一实施例的算子映射装置的框图。如图17所示,算子映射装置1700可因配置或性能不同而产生比较大的差异,可以包括一个或一个以上中央处理器(central  processing units,CPU)1701(例如,一个或一个以上处理器)和存储器1705,该存储器1705中存储有一个或一个以上的应用程序或数据。FIG. 17 shows a block diagram of an operator mapping apparatus according to an embodiment of the present application. As shown in FIG. 17 , the operator mapping apparatus 1700 may vary greatly due to different configurations or performances, and may include one or more central processing units (CPU) 1701 (eg, one or more processors) ) and a memory 1705 in which one or more applications or data are stored.
其中,存储器1705可以是易失性存储或持久存储。存储在存储器1705的程序可以包括一个或一个以上模块,每个模块可以包括对区块链节点中的一系列指令操作。更进一步地,中央处理器1701可以设置为与存储器1705通信,在算子映射装置1700上执行存储器1705中的一系列指令操作。Among them, the memory 1705 may be volatile storage or persistent storage. The programs stored in memory 1705 may include one or more modules, each of which may include a series of instructions to operate on a blockchain node. Further, the central processing unit 1701 may be configured to communicate with the memory 1705 to execute a series of instruction operations in the memory 1705 on the operator mapping apparatus 1700.
算子映射装置1700还可以包括一个或一个以上电源1702,一个或一个以上有线或无线网络接口1703,一个或一个以上输入输出接口1704,和/或,一个或一个以上操作系统,例如Windows ServerTM,Mac OS XTM,UnixTM,LinuxTM,FreeBSDTM等等。The operator mapping device 1700 may also include one or more power supplies 1702, one or more wired or wireless network interfaces 1703, one or more input and output interfaces 1704, and/or, one or more operating systems, such as Windows Server™, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
本实施例中算子映射装置1700中的中央处理器1701所执行的流程与前述图3、图5a、图5b、图6或图11所示的实施例中描述的方法流程类似,此处不再赘述。The process performed by the central processing unit 1701 in the operator mapping apparatus 1700 in this embodiment is similar to the method process described in the embodiment shown in FIG. 3 , FIG. 5 a , FIG. 5 b , FIG. 6 or FIG. Repeat.
本申请的实施例提供了一种非易失性计算机可读存储介质,其上存储有计算机程序指令,所述计算机程序指令被处理器执行时实现上述方法。Embodiments of the present application provide a non-volatile computer-readable storage medium on which computer program instructions are stored, and when the computer program instructions are executed by a processor, implement the above method.
本申请的实施例提供了一种计算机程序产品,包括计算机可读代码,或者承载有计算机可读代码的非易失性计算机可读存储介质,当所述计算机可读代码在电子设备的处理器中运行时,所述电子设备中的处理器执行上述方法。Embodiments of the present application provide a computer program product, including computer-readable codes, or a non-volatile computer-readable storage medium carrying computer-readable codes, when the computer-readable codes are stored in a processor of an electronic device When running in the electronic device, the processor in the electronic device executes the above method.
计算机可读存储介质可以是可以保持和存储由指令执行设备使用的指令的有形设备。计算机可读存储介质例如可以是――但不限于――电存储设备、磁存储设备、光存储设备、电磁存储设备、半导体存储设备或者上述的任意合适的组合。计算机可读存储介质的更具体的例子(非穷举的列表)包括:便携式计算机盘、硬盘、随机存取存储器(Random Access Memory,RAM)、只读存储器(Read Only Memory,ROM)、可擦式可编程只读存储器(Electrically Programmable Read-Only-Memory,EPROM或闪存)、静态随机存取存储器(Static Random-Access Memory,SRAM)、便携式压缩盘只读存储器(Compact Disc Read-Only Memory,CD-ROM)、数字多功能盘(Digital Video Disc,DVD)、记忆棒、软盘、机械编码设备、例如其上存储有指令的打孔卡或凹槽内凸起结构、以及上述的任意合适的组合。A computer-readable storage medium may be a tangible device that can hold and store instructions for use by the instruction execution device. The 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 (a non-exhaustive list) of computer-readable storage media include: portable computer disks, hard disks, random access memory (RAM), read only memory (ROM), erasable programmable read-only memory (Electrically Programmable Read-Only-Memory, EPROM or flash memory), static random access memory (Static Random-Access Memory, SRAM), portable compact disk read-only memory (Compact Disc Read-Only Memory, CD - ROM), Digital Video Disc (DVD), memory sticks, floppy disks, mechanically encoded devices, such as punch cards or raised structures in grooves on which instructions are stored, and any suitable combination of the foregoing .
这里所描述的计算机可读程序指令或代码可以从计算机可读存储介质下载到各个计算/处理设备,或者通过网络、例如因特网、局域网、广域网和/或无线网下载到外部计算机或外部存储设备。网络可以包括铜传输电缆、光纤传输、无线传输、路由器、防火墙、交换机、网关计算机和/或边缘服务器。每个计算/处理设备中的网络适配卡或者网络接口从网络接收计算机可读程序指令,并转发该计算机可读程序指令,以供存储在各个计算/处理设备中的计算机可读存储介质中。The computer readable program instructions or code described herein may be downloaded to various computing/processing devices from a computer readable storage medium, or to an external computer or external storage device over a network such as the Internet, a local area network, a wide area network and/or a wireless network. The network may include copper transmission cables, fiber optic transmission, wireless transmission, routers, firewalls, switches, gateway computers, and/or edge servers. A network adapter card or network interface in each computing/processing device receives computer-readable program instructions from a network and forwards the computer-readable program instructions for storage in a computer-readable storage medium in each computing/processing device .
用于执行本申请操作的计算机程序指令可以是汇编指令、指令集架构(Instruction Set Architecture,ISA)指令、机器指令、机器相关指令、微代码、固件指令、状态设置数据、或者以一种或多种编程语言的任意组合编写的源代码或目标代码,所述编程语言包括面向对 象的编程语言—诸如Smalltalk、C++等,以及常规的过程式编程语言—诸如“C”语言或类似的编程语言。计算机可读程序指令可以完全地在用户计算机上执行、部分地在用户计算机上执行、作为一个独立的软件包执行、部分在用户计算机上部分在远程计算机上执行、或者完全在远程计算机或服务器上执行。在涉及远程计算机的情形中,远程计算机可以通过任意种类的网络—包括局域网(Local Area Network,LAN)或广域网(Wide Area Network,WAN)—连接到用户计算机,或者,可以连接到外部计算机(例如利用因特网服务提供商来通过因特网连接)。在一些实施例中,通过利用计算机可读程序指令的状态信息来个性化定制电子电路,例如可编程逻辑电路、现场可编程门阵列(Field-Programmable Gate Array,FPGA)或可编程逻辑阵列(Programmable Logic Array,PLA),该电子电路可以执行计算机可读程序指令,从而实现本申请的各个方面。The computer program instructions used to perform the operations of the present application may be assembly instructions, Instruction Set Architecture (ISA) instructions, machine instructions, machine-related instructions, microcode, firmware instructions, state setting data, or in one or more source or object code written in any combination of programming languages, including object-oriented programming languages such as Smalltalk, C++, etc., and conventional procedural programming languages such as the "C" language or similar programming languages. The computer readable program instructions may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer, or entirely on the remote computer or server implement. In the case of a remote computer, the remote computer can be connected to the user's computer through any kind of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or, can be connected to an external computer (e.g. use an internet service provider to connect via the internet). In some embodiments, electronic circuits, such as programmable logic circuits, Field-Programmable Gate Arrays (FPGA), or Programmable Logic Arrays (Programmable Logic Arrays), are personalized by utilizing state information of computer-readable program instructions. Logic Array, PLA), the electronic circuit can execute computer readable program instructions to implement various aspects of the present application.
这里参照根据本申请实施例的方法、装置(系统)和计算机程序产品的流程图和/或框图描述了本申请的各个方面。应当理解,流程图和/或框图的每个方框以及流程图和/或框图中各方框的组合,都可以由计算机可读程序指令实现。Aspects of the present application are described herein with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the present application. It will be understood that each block of the flowchart illustrations and/or block diagrams, and combinations of blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer readable program instructions.
这些计算机可读程序指令可以提供给通用计算机、专用计算机或其它可编程数据处理装置的处理器,从而生产出一种机器,使得这些指令在通过计算机或其它可编程数据处理装置的处理器执行时,产生了实现流程图和/或框图中的一个或多个方框中规定的功能/动作的装置。也可以把这些计算机可读程序指令存储在计算机可读存储介质中,这些指令使得计算机、可编程数据处理装置和/或其他设备以特定方式工作,从而,存储有指令的计算机可读介质则包括一个制造品,其包括实现流程图和/或框图中的一个或多个方框中规定的功能/动作的各个方面的指令。These computer readable program instructions may be provided to a processor of a general purpose computer, special purpose computer or other programmable data processing apparatus to produce a machine that causes the instructions when executed by the processor of the computer or other programmable data processing apparatus , resulting in means for implementing the functions/acts specified in one or more blocks of the flowchart and/or block diagrams. These computer readable program instructions can also be stored in a computer readable storage medium, these instructions cause a computer, programmable data processing apparatus and/or other equipment to operate in a specific manner, so that the computer readable medium storing the instructions includes An article of manufacture comprising instructions for implementing various aspects of the functions/acts specified in one or more blocks of the flowchart and/or block diagrams.
也可以把计算机可读程序指令加载到计算机、其它可编程数据处理装置、或其它设备上,使得在计算机、其它可编程数据处理装置或其它设备上执行一系列操作步骤,以产生计算机实现的过程,从而使得在计算机、其它可编程数据处理装置、或其它设备上执行的指令实现流程图和/或框图中的一个或多个方框中规定的功能/动作。Computer readable program instructions can also be loaded onto a computer, other programmable data processing apparatus, or other equipment to cause a series of operational steps to be performed on the computer, other programmable data processing apparatus, or other equipment to produce a computer-implemented process , thereby causing instructions executing on a computer, other programmable data processing apparatus, or other device to implement the functions/acts specified in one or more blocks of the flowcharts and/or block diagrams.
附图中的流程图和框图显示了根据本申请的多个实施例的装置、系统、方法和计算机程序产品的可能实现的体系架构、功能和操作。在这点上,流程图或框图中的每个方框可以代表一个模块、程序段或指令的一部分,所述模块、程序段或指令的一部分包含一个或多个用于实现规定的逻辑功能的可执行指令。在有些作为替换的实现中,方框中所标注的功能也可以以不同于附图中所标注的顺序发生。例如,两个连续的方框实际上可以基本并行地执行,它们有时也可以按相反的顺序执行,这依所涉及的功能而定。The flowchart and block diagrams in the Figures illustrate the architecture, functionality, and operation of possible implementations of apparatuses, systems, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of instructions, which comprises one or more functions for implementing the specified logical function(s) executable instructions. In some alternative implementations, the functions noted in the blocks may occur out of the order noted in the figures. For example, two blocks in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved.
也要注意的是,框图和/或流程图中的每个方框、以及框图和/或流程图中的方框的组合,可以用执行相应的功能或动作的硬件(例如电路或ASIC(Application Specific Integrated Circuit,专用集成电路))来实现,或者可以用硬件和软件的组合,如固件等来实现。It is also noted that each block of the block diagrams and/or flowchart illustrations, and combinations of blocks in the block diagrams and/or flowchart illustrations, can be implemented in hardware (eg, circuits or ASICs (Application) that perform the corresponding functions or actions. Specific Integrated Circuit, application-specific integrated circuit)), or can be implemented by a combination of hardware and software, such as firmware.
尽管在此结合各实施例对本发明进行了描述,然而,在实施所要求保护的本发明过程中,本领域技术人员通过查看所述附图、公开内容、以及所附权利要求书,可理解并实现所述公 开实施例的其它变化。在权利要求中,“包括”(comprising)一词不排除其他组成部分或步骤,“一”或“一个”不排除多个的情况。单个处理器或其它单元可以实现权利要求中列举的若干项功能。相互不同的从属权利要求中记载了某些措施,但这并不表示这些措施不能组合起来产生良好的效果。While the invention has been described herein in connection with various embodiments, those skilled in the art will understand and understand from a review of the drawings, the disclosure, and the appended claims in practicing the claimed invention. Other variations of the disclosed embodiments are implemented. In the claims, the word "comprising" does not exclude other components or steps, and "a" or "an" does not exclude a plurality. A single processor or other unit may fulfill the functions of several items recited in the claims. The mere fact that certain measures are recited in mutually different dependent claims does not indicate that these measures cannot be combined to advantage.
以上已经描述了本申请的各实施例,上述说明是示例性的,并非穷尽性的,并且也不限于所披露的各实施例。在不偏离所说明的各实施例的范围和精神的情况下,对于本技术领域的普通技术人员来说许多修改和变更都是显而易见的。本文中所用术语的选择,旨在最好地解释各实施例的原理、实际应用或对市场中的技术的改进,或者使本技术领域的其它普通技术人员能理解本文披露的各实施例。Various embodiments of the present application have been described above, and the foregoing descriptions are exemplary, not exhaustive, and not limiting of the disclosed embodiments. Numerous modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein was chosen to best explain the principles of the embodiments, the practical application or improvement over the technology in the marketplace, or to enable others of ordinary skill in the art to understand the embodiments disclosed herein.

Claims (25)

  1. 一种计算图的算子映射方法,其特征在于,用于对第一计算图和第二计算图算子映射,所述第一计算图和所述第二计算图为同一个神经网络模型的计算图,所述算子映射方法包括:An operator mapping method for a computational graph, characterized in that it is used for operator mapping of a first computational graph and a second computational graph, wherein the first computational graph and the second computational graph are of the same neural network model. Computational graph, the operator mapping method includes:
    基于第一足迹矩阵和第二足迹矩阵,重复下述过程,直到达到停止条件:根据所述第一足迹矩阵和所述第二足迹矩阵计算第一矩阵,并根据所述第一矩阵调整所述第一足迹矩阵中的行和列的顺序,根据调整后的第一足迹矩阵和所述第二足迹矩阵重新计算所述第一矩阵;其中,所述第一足迹矩阵指示所述第一计算图的算子之间的拓扑关系,所述第二足迹矩阵指示所述第二计算图的算子之间的拓扑关系,所述第一矩阵指示所述第一计算图和所述第二计算图的拓扑关系的相似度;Based on the first footprint matrix and the second footprint matrix, the following process is repeated until a stop condition is reached: calculating a first matrix from the first footprint matrix and the second footprint matrix, and adjusting the the order of rows and columns in the first footprint matrix, the first matrix is recalculated according to the adjusted first footprint matrix and the second footprint matrix; wherein the first footprint matrix indicates the first calculation graph The topological relationship between the operators of the second footprint matrix indicates the topological relationship between the operators of the second computational graph, and the first matrix indicates the first computational graph and the second computational graph The similarity of the topological relationship;
    根据达到所述停止条件时的第一足迹矩阵、所述第二足迹矩阵,得到所述第一计算图中的多个算子各自在第二计算图中对应的算子。According to the first footprint matrix and the second footprint matrix when the stopping condition is reached, the operators corresponding to each of the multiple operators in the first calculation graph in the second calculation graph are obtained.
  2. 根据权利要求1所述的方法,其特征在于,根据所述第一足迹矩阵和所述第二足迹矩阵计算所述第一矩阵,包括:The method according to claim 1, wherein calculating the first matrix according to the first footprint matrix and the second footprint matrix comprises:
    根据多个第一特征向量和多个第二特征向量,得到所述第一矩阵,其中,每个所述第一特征向量对应所述第一计算图中的算子,每个所述第一特征向量与所述第一特征向量对应的算子在所述第一足迹矩阵中对应的行向量与列向量有关,每个所述第二特征向量对应所述第二计算图中的算子,每个所述第二特征向量与所述第二特征向量对应的算子在所述第二足迹矩阵中对应的行向量与列向量有关,所述第一特征向量和所述第二特征向量用于计算所述第一特征向量对应的算子和所述第二特征向量对应的算子之间的拓扑关系的相似度。The first matrix is obtained according to a plurality of first eigenvectors and a plurality of second eigenvectors, wherein each of the first eigenvectors corresponds to an operator in the first calculation graph, and each of the first eigenvectors corresponds to an operator in the first calculation graph. The row vector corresponding to the operator corresponding to the eigenvector and the first eigenvector in the first footprint matrix is related to the column vector, and each of the second eigenvectors corresponds to the operator in the second calculation graph, Each of the second eigenvectors and the operator corresponding to the second eigenvectors are related to row vectors and column vectors in the second footprint matrix, and the first eigenvectors and the second eigenvectors are represented by for calculating the similarity of the topological relationship between the operator corresponding to the first eigenvector and the operator corresponding to the second eigenvector.
  3. 根据权利要求2所述的方法,其特征在于,所述第一矩阵的元素的值表示所述元素所在的行对应的算子和所在的列对应的算子的拓扑关系的相似度,其中,所述元素所在行对应的算子和所述元素所在列对应的算子分别为所述第一计算图中的算子和所述第二计算图中的算子。The method according to claim 2, wherein the value of the element of the first matrix represents the similarity of the topological relationship between the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located, wherein, The operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located are the operator in the first calculation graph and the operator in the second calculation graph, respectively.
  4. 根据权利要求1-3任意一项所述的方法,其特征在于,所述第一计算图和所述第二计算图中的算子分属于多个第一分区,同一第一分区的算子类型相同、且算子输出的张量的维度相同;The method according to any one of claims 1-3, wherein the operators in the first calculation graph and the second calculation graph belong to multiple first partitions, and the operators in the same first partition The types are the same, and the dimensions of the tensors output by the operators are the same;
    所述第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子在同一第一分区、相同位置的列对应的算子在同一第一分区;The operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are in the same first partition, and the operators corresponding to the columns in the same position are in the same first partition;
    且,属于同一第一分区的第一计算图的算子在所述第一足迹矩阵中对应的行或者列连续排列,属于同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或者列连续排列。In addition, the operators of the first computation graph belonging to the same first partition are arranged consecutively in the corresponding rows or columns of the first footprint matrix, and the operators of the second computation graph belonging to the same first partition are arranged in the second footprint matrix. Corresponding rows or columns in the matrix are arranged consecutively.
  5. 根据权利要求4所述的方法,其特征在于,所述第一计算图和所述第二计算图中的部 分算子属于第二分区,所述第二分区中的算子类型不同和/或算子输出的张量的维度不同。The method according to claim 4, wherein some operators in the first computation graph and the second computation graph belong to a second partition, and the types of operators in the second partition are different and/or The dimensions of the tensors output by the operators are different.
  6. 根据权利要求4所述的方法,其特征在于,所述第一足迹矩阵和所述第二足迹矩阵相同位置的行对应的算子的同质深度相同、相同位置的列对应的算子的同质深度相同,且属于同一第一分区的所述第一计算图的算子在所述第一足迹矩阵中对应的行或列按照算子的所述同质深度排序、同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或列按照算子的所述同质深度排序;The method according to claim 4, wherein the operators corresponding to the rows at the same position of the first footprint matrix and the second footprint matrix have the same homogeneous depth, and the operators corresponding to the columns at the same position have the same homogeneous depth. The rows or columns corresponding to the operators of the first computation graph belonging to the same first partition in the first footprint matrix are sorted according to the homogenous depth of the operators, and the first partition of the same first partition The corresponding rows or columns of the operators in the second footprint matrix are sorted according to the homogeneous depth of the operators;
    其中,所述同质深度为:在计算图中所述算子所属的所有分支中,在所述算子之前与所述算子类型相同、输出的张量维度相同的算子的最大数目。Wherein, the homogeneity depth is: in all the branches to which the operator belongs in the calculation graph, the maximum number of operators before the operator that have the same type as the operator and the same output tensor dimension.
  7. 根据权利要求5所述的方法,其特征在于,The method of claim 5, wherein:
    如果所述第一分区中的所述第一计算图的算子的数目和所述第二计算图的算子的数目不同,所述第一分区中还包括伪算子;其中,伪算子为不具备算子类型和操作数的算子;If the number of operators of the first computation graph in the first partition is different from the number of operators of the second computation graph, the first partition also includes pseudo-operators; wherein the pseudo-operators are It is an operator without operator type and operand;
    如果所述第一分区中的所述第一计算图的算子的数目少于所述第一分区中的所述第二计算图的算子数目,所述伪算子在所述第一足迹矩阵中对应的行或列,位于所述第一计算图中属于所述第一分区的算子对应的行或列之后,If the number of operators of the first computation graph in the first partition is less than the number of operators of the second computation graph in the first partition, the pseudo-operator is in the first footprint The corresponding row or column in the matrix is located after the row or column corresponding to the operator belonging to the first partition in the first calculation graph,
    如果所述第一分区中的所述第二计算图的算子的数目少于所述第一分区中的所述第一计算图的算子数目,所述伪算子在所述第二足迹矩阵中对应的行或列,位于所述第二计算图中属于所述第一分区的算子对应的行或列之后。If the number of operators of the second computation graph in the first partition is less than the number of operators of the first computation graph in the first partition, the pseudo-operator is in the second footprint The corresponding row or column in the matrix is located after the row or column corresponding to the operator belonging to the first partition in the second calculation graph.
  8. 根据权利要求5或7所述的方法,其特征在于,如果所述第二分区中的所述第一计算图的算子的数目和所述第二计算图的算子的数目不同,所述第二分区中还包括所述伪算子;The method according to claim 5 or 7, wherein if the number of operators of the first computation graph in the second partition is different from the number of operators of the second computation graph, the The second partition also includes the pseudo operator;
    如果所述第二分区中的所述第一计算图的算子的数目少于所述第二分区中的所述第二计算图的算子数目,所述伪算子在所述第一足迹矩阵中对应的行和列与所述第一计算图中属于所述第二分区的算子对应的行和列随机排序,且行和列随机排序的方式相同;If the number of operators of the first computation graph in the second partition is less than the number of operators of the second computation graph in the second partition, the pseudo-operator is in the first footprint Corresponding rows and columns in the matrix are randomly sorted with the rows and columns corresponding to the operators belonging to the second partition in the first calculation graph, and the rows and columns are randomly sorted in the same manner;
    如果所述第二分区中的所述第二计算图的算子的数目少于所述第二分区中的所述第二计算图的算子数目,所述伪算子在所述第二足迹矩阵中对应的行和列与所述第二计算图中属于所述第二分区的算子对应的行和列随机排序,且行和列随机排序的方式相同。If the number of operators of the second computation graph in the second partition is less than the number of operators of the second computation graph in the second partition, the pseudo operator is located in the second footprint The corresponding rows and columns in the matrix and the rows and columns corresponding to the operators belonging to the second partition in the second computation graph are randomly ordered, and the random ordering of the rows and columns is the same.
  9. 根据权利要求5-8任意一项所述的方法,其特征在于,根据所述第一矩阵调整所述第一足迹矩阵中的行和列的顺序,包括:The method according to any one of claims 5-8, wherein adjusting the order of rows and columns in the first footprint matrix according to the first matrix comprises:
    根据所述第一矩阵调整所述第一足迹矩阵中位于同一所述第一分区内的算子对应的行和列的顺序。The order of the rows and columns corresponding to the operators located in the same first partition in the first footprint matrix is adjusted according to the first matrix.
  10. 根据权利要求5-8任意一项所述的方法,其特征在于,The method according to any one of claims 5-8, wherein,
    属于同一第一分区、且在达到所述停止条件时的第一足迹矩阵和所述第二足迹矩阵中对 应的行或列的位置相同的所述第一计算图的算子和第二计算图的算子之间存在映射关系;an operator and a second computation graph of the first computation graph belonging to the same first partition and having the same row or column position in the first footprint matrix and the second footprint matrix when the stopping condition is reached There is a mapping relationship between the operators of ;
    属于所述第二分区的第一计算图的算子与属于第二分区的第二计算图的多个算子之间存在映射关系,There is a mapping relationship between the operators of the first computation graph belonging to the second partition and multiple operators of the second computation graph belonging to the second partition,
    其中,所述属于第二分区的第二计算图的多个算子为:达到所述停止条件时的第一矩阵中,与所述属于所述第二分区的第一计算图的算子对应的元素的值中,最大的多个值所对应的第二计算图的算子。Wherein, the multiple operators of the second computation graph belonging to the second partition are: in the first matrix when the stopping condition is reached, the operators corresponding to the operators of the first computation graph belonging to the second partition Among the values of the elements of , the operator of the second calculation graph corresponding to the largest multiple values.
  11. 根据权利要求1-10任意一项所述的方法,其特征在于,所述停止条件为所述重复计算第一矩阵的次数大于第一阈值。The method according to any one of claims 1-10, wherein the stopping condition is that the number of times of repeatedly calculating the first matrix is greater than a first threshold.
  12. 一种计算图的算子映射装置,其特征在于,用于对第一计算图和第二计算图算子映射,所述第一计算图和所述第二计算图为同一个神经网络模型的计算图,所述算子映射装置包括:A computational graph operator mapping device, characterized in that it is used for operator mapping to a first computational graph and a second computational graph, wherein the first computational graph and the second computational graph are of the same neural network model. Computational graph, the operator mapping device includes:
    迭代模块,用于基于第一足迹矩阵和第二足迹矩阵,重复下述过程,直到达到停止条件:根据所述第一足迹矩阵和所述第二足迹矩阵计算第一矩阵,并根据所述第一矩阵调整所述第一足迹矩阵中的行和列的顺序,根据调整后的第一足迹矩阵和所述第二足迹矩阵重新计算所述第一矩阵;其中,所述第一足迹矩阵指示所述第一计算图的算子之间的拓扑关系,所述第二足迹矩阵指示所述第二计算图的算子之间的拓扑关系,所述第一矩阵指示所述第一计算图和所述第二计算图的拓扑关系的相似度;an iterative module for repeating the following process based on the first footprint matrix and the second footprint matrix until a stopping condition is reached: calculating a first matrix according to the first footprint matrix and the second footprint matrix, and calculating a first matrix according to the first footprint matrix and the second footprint matrix A matrix adjusts the order of rows and columns in the first footprint matrix, and the first matrix is recalculated according to the adjusted first footprint matrix and the second footprint matrix; wherein the first footprint matrix indicates the the topological relationship between the operators of the first computational graph, the second footprint matrix indicates the topological relationship between the operators of the second computational graph, the first matrix indicates the first computational graph and all the similarity of the topological relationship of the second calculation graph;
    对应模块,用于根据达到所述停止条件时的第一足迹矩阵、所述第二足迹矩阵,得到所述第一计算图中的多个算子各自在第二计算图中对应的算子。A corresponding module, configured to obtain operators corresponding to each of the multiple operators in the first calculation graph in the second calculation graph according to the first footprint matrix and the second footprint matrix when the stopping condition is reached.
  13. 根据权利要求12所述的装置,其特征在于,所述迭代模块包括:The apparatus according to claim 12, wherein the iterative module comprises:
    计算单元,用于根据多个第一特征向量和多个第二特征向量,得到所述第一矩阵,其中,每个所述第一特征向量对应所述第一计算图中的算子,每个所述第一特征向量与所述第一特征向量对应的算子在所述第一足迹矩阵中对应的行向量与列向量有关,每个所述第二特征向量对应所述第二计算图中的算子,每个所述第二特征向量与所述第二特征向量对应的算子在所述第二足迹矩阵中对应的行向量与列向量有关,所述第一特征向量和所述第二特征向量用于计算所述第一特征向量对应的算子和所述第二特征向量对应的算子之间的拓扑关系的相似度。The calculation unit is configured to obtain the first matrix according to a plurality of first eigenvectors and a plurality of second eigenvectors, wherein each of the first eigenvectors corresponds to an operator in the first calculation graph, and each Each of the first eigenvectors and the operators corresponding to the first eigenvectors are related to the row vectors and column vectors in the first footprint matrix, and each of the second eigenvectors corresponds to the second calculation graph The operators in , each of the second eigenvectors and the operators corresponding to the second eigenvectors are related to the row vectors and column vectors in the second footprint matrix, and the first eigenvectors and the The second eigenvector is used to calculate the similarity of the topological relationship between the operator corresponding to the first eigenvector and the operator corresponding to the second eigenvector.
  14. 根据权利要求13所述的装置,其特征在于,所述第一矩阵的元素的值表示所述元素所在的行对应的算子和所在的列对应的算子的拓扑关系的相似度,其中,所述元素所在行对应的算子和所述元素所在列对应的算子分别为所述第一计算图中的算子和所述第二计算图中的算子。The device according to claim 13, wherein the value of the element of the first matrix represents the similarity of the topological relationship between the operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located, wherein, The operator corresponding to the row where the element is located and the operator corresponding to the column where the element is located are the operator in the first calculation graph and the operator in the second calculation graph, respectively.
  15. 根据权利要求12-14任意一项所述的装置,其特征在于,所述第一计算图和所述第二计算图中的算子分属于多个第一分区,同一第一分区的算子类型相同、且算子输出的张量 的维度相同;The device according to any one of claims 12-14, wherein the operators in the first calculation graph and the second calculation graph belong to multiple first partitions, and operators in the same first partition The types are the same, and the dimensions of the tensors output by the operators are the same;
    所述第一足迹矩阵和所述第二足迹矩阵的相同位置的行对应的算子在同一第一分区、相同位置的列对应的算子在同一第一分区;The operators corresponding to the rows in the same position of the first footprint matrix and the second footprint matrix are in the same first partition, and the operators corresponding to the columns in the same position are in the same first partition;
    且,属于同一第一分区的第一计算图的算子在所述第一足迹矩阵中对应的行或者列连续排列,属于同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或者列连续排列。In addition, the operators of the first computation graph belonging to the same first partition are arranged consecutively in the corresponding rows or columns of the first footprint matrix, and the operators of the second computation graph belonging to the same first partition are arranged in the second footprint matrix. Corresponding rows or columns in the matrix are arranged consecutively.
  16. 根据权利要求15所述的装置,其特征在于,所述第一计算图和所述第二计算图中的部分算子属于第二分区,所述第二分区中的算子类型不同和/或算子输出的张量的维度不同。The apparatus according to claim 15, wherein some operators in the first computation graph and the second computation graph belong to a second partition, and the types of operators in the second partition are different and/or The dimensions of the tensors output by the operators are different.
  17. 根据权利要求15所述的装置,其特征在于,所述第一足迹矩阵和所述第二足迹矩阵相同位置的行对应的算子的同质深度相同、相同位置的列对应的算子的同质深度相同,且属于同一第一分区的所述第一计算图的算子在所述第一足迹矩阵中对应的行或列按照算子的所述同质深度排序、同一第一分区的第二计算图的算子在所述第二足迹矩阵中对应的行或列按照算子的所述同质深度排序;The device according to claim 15, wherein the operators corresponding to the rows at the same position of the first footprint matrix and the second footprint matrix have the same homogeneous depth, and the operators corresponding to the columns at the same position have the same homogeneous depth. The rows or columns corresponding to the operators of the first computation graph belonging to the same first partition in the first footprint matrix are sorted according to the homogenous depth of the operators, and the first partition of the same first partition The corresponding rows or columns of the operators in the second footprint matrix are sorted according to the homogeneous depth of the operators;
    其中,所述同质深度为:在计算图中所述算子所属的所有分支中,在所述算子之前与所述算子类型相同、输出的张量维度相同的算子的最大数目。Wherein, the homogeneity depth is: in all the branches to which the operator belongs in the calculation graph, the maximum number of operators before the operator that have the same type as the operator and the same output tensor dimension.
  18. 根据权利要求16所述的装置,其特征在于,The apparatus of claim 16, wherein:
    如果所述第一分区中的所述第一计算图的算子的数目和所述第二计算图的算子的数目不同,所述第一分区中还包括伪算子;其中,伪算子为不具备算子类型和操作数的算子;If the number of operators of the first computation graph in the first partition is different from the number of operators of the second computation graph, the first partition also includes pseudo-operators; wherein the pseudo-operators are It is an operator without operator type and operand;
    如果所述第一分区中的所述第一计算图的算子的数目少于所述第一分区中的所述第二计算图的算子数目,所述伪算子在所述第一足迹矩阵中对应的行或列,位于所述第一计算图中属于所述第一分区的算子对应的行或列之后,If the number of operators of the first computation graph in the first partition is less than the number of operators of the second computation graph in the first partition, the pseudo-operator is in the first footprint The corresponding row or column in the matrix is located after the row or column corresponding to the operator belonging to the first partition in the first calculation graph,
    如果所述第一分区中的所述第二计算图的算子的数目少于所述第一分区中的所述第一计算图的算子数目,所述伪算子在所述第二足迹矩阵中对应的行或列,位于所述第二计算图中属于所述第一分区的算子对应的行或列之后。If the number of operators of the second computation graph in the first partition is less than the number of operators of the first computation graph in the first partition, the pseudo-operator is in the second footprint The corresponding row or column in the matrix is located after the row or column corresponding to the operator belonging to the first partition in the second calculation graph.
  19. 根据权利要求16或18所述的装置,其特征在于,如果所述第二分区中的所述第一计算图的算子的数目和所述第二计算图的算子的数目不同,所述第二分区中还包括所述伪算子;The device according to claim 16 or 18, wherein if the number of operators of the first computation graph in the second partition is different from the number of operators of the second computation graph, the The second partition also includes the pseudo operator;
    如果所述第二分区中的所述第一计算图的算子的数目少于所述第二分区中的所述第二计算图的算子数目,所述伪算子在所述第一足迹矩阵中对应的行和列与所述第一计算图中属于所述第二分区的算子对应的行和列随机排序,且行和列随机排序的方式相同;If the number of operators of the first computation graph in the second partition is less than the number of operators of the second computation graph in the second partition, the pseudo-operator is in the first footprint Corresponding rows and columns in the matrix are randomly sorted with the rows and columns corresponding to the operators belonging to the second partition in the first calculation graph, and the rows and columns are randomly sorted in the same manner;
    如果所述第二分区中的所述第二计算图的算子的数目少于所述第二分区中的所述第二计 算图的算子数目,所述伪算子在所述第二足迹矩阵中对应的行和列与所述第二计算图中属于所述第二分区的算子对应的行和列随机排序,且行和列随机排序的方式相同。If the number of operators of the second computation graph in the second partition is less than the number of operators of the second computation graph in the second partition, the pseudo operator is located in the second footprint The corresponding rows and columns in the matrix and the rows and columns corresponding to the operators belonging to the second partition in the second computation graph are randomly ordered, and the random ordering of the rows and columns is the same.
  20. 根据权利要求16-19任意一项所述的装置,其特征在于,所述迭代模块还包括:The device according to any one of claims 16-19, wherein the iterative module further comprises:
    调整单元,用于根据所述第一矩阵调整所述第一足迹矩阵中位于同一所述第一分区内的算子对应的行和列的顺序。An adjustment unit, configured to adjust the order of the rows and columns corresponding to the operators located in the same first partition in the first footprint matrix according to the first matrix.
  21. 根据权利要求16-19任意一项所述的装置,其特征在于,The device according to any one of claims 16-19, characterized in that,
    属于同一第一分区、且在达到所述停止条件时的第一足迹矩阵和所述第二足迹矩阵中对应的行或列的位置相同的所述第一计算图的算子和第二计算图的算子之间存在映射关系;an operator and a second computation graph of the first computation graph belonging to the same first partition and having the same row or column position in the first footprint matrix and the second footprint matrix when the stopping condition is reached There is a mapping relationship between the operators of ;
    属于所述第二分区的第一计算图的算子与属于第二分区的第二计算图的多个算子之间存在映射关系,There is a mapping relationship between the operators of the first computation graph belonging to the second partition and multiple operators of the second computation graph belonging to the second partition,
    其中,所述属于第二分区的第二计算图的多个算子为:达到所述停止条件时的第一矩阵中,与所述属于所述第二分区的第一计算图的算子对应的元素的值中,最大的多个值所对应的第二计算图的算子。Wherein, the multiple operators of the second computation graph belonging to the second partition are: in the first matrix when the stopping condition is reached, the operators corresponding to the operators of the first computation graph belonging to the second partition Among the values of the elements of , the operator of the second calculation graph corresponding to the largest multiple values.
  22. 根据权利要求12-21任意一项所述的装置,其特征在于,所述停止条件为所述重复计算第一矩阵的次数大于第一阈值。The apparatus according to any one of claims 12-21, wherein the stopping condition is that the number of times of repeatedly calculating the first matrix is greater than a first threshold.
  23. 一种计算图的算子映射装置,其特征在于,包括:An operator mapping device for computing a graph, comprising:
    处理器;processor;
    用于存储处理器可执行指令的存储器;memory for storing processor-executable instructions;
    其中,所述处理器被配置为执行所述指令时实现权利要求1-11任意一项所述的方法。Wherein, the processor is configured to implement the method of any one of claims 1-11 when executing the instructions.
  24. 一种非易失性计算机可读存储介质,其上存储有计算机程序指令,其特征在于,所述计算机程序指令被处理器执行时实现权利要求1-11中任意一项所述的方法。A non-volatile computer-readable storage medium on which computer program instructions are stored, characterized in that, when the computer program instructions are executed by a processor, the method described in any one of claims 1-11 is implemented.
  25. 一种计算机程序产品,包括计算机可读代码,当所述计算机可读代码在电子设备中运行时实现权利要求1-11中任意一项所述的方法。A computer program product comprising computer readable code which, when run in an electronic device, implements the method of any one of claims 1-11.
PCT/CN2021/127123 2020-12-29 2021-10-28 Operator mapping method and apparatus for computational graph WO2022142662A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202011588279.1A CN114692711A (en) 2020-12-29 2020-12-29 Operator mapping method and device for computation graph
CN202011588279.1 2020-12-29

Publications (1)

Publication Number Publication Date
WO2022142662A1 true WO2022142662A1 (en) 2022-07-07

Family

ID=82130046

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/127123 WO2022142662A1 (en) 2020-12-29 2021-10-28 Operator mapping method and apparatus for computational graph

Country Status (2)

Country Link
CN (1) CN114692711A (en)
WO (1) WO2022142662A1 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106650922A (en) * 2016-09-29 2017-05-10 清华大学 Hardware neural network conversion method, computing device, compiling method and neural network software and hardware collaboration system
EP3255586A1 (en) * 2016-06-06 2017-12-13 Fujitsu Limited Method, program, and apparatus for comparing data graphs
EP3333770A1 (en) * 2016-12-09 2018-06-13 Fujitsu Limited Matching graph entities in graph data
US20190130264A1 (en) * 2017-11-02 2019-05-02 Palo Alto Research Center Incorporated Deep graph representation learning
CN111338635A (en) * 2020-02-20 2020-06-26 腾讯科技(深圳)有限公司 Graph compiling method, device and equipment for calculation graph and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
EP3255586A1 (en) * 2016-06-06 2017-12-13 Fujitsu Limited Method, program, and apparatus for comparing data graphs
CN106650922A (en) * 2016-09-29 2017-05-10 清华大学 Hardware neural network conversion method, computing device, compiling method and neural network software and hardware collaboration system
EP3333770A1 (en) * 2016-12-09 2018-06-13 Fujitsu Limited Matching graph entities in graph data
US20190130264A1 (en) * 2017-11-02 2019-05-02 Palo Alto Research Center Incorporated Deep graph representation learning
CN111338635A (en) * 2020-02-20 2020-06-26 腾讯科技(深圳)有限公司 Graph compiling method, device and equipment for calculation graph and storage medium

Also Published As

Publication number Publication date
CN114692711A (en) 2022-07-01

Similar Documents

Publication Publication Date Title
CN110366734B (en) Optimizing neural network architecture
Mkaouer et al. High dimensional search-based software engineering: finding tradeoffs among 15 objectives for automating software refactoring using NSGA-III
CN111414987B (en) Training method and training device of neural network and electronic equipment
JP4790816B2 (en) Parallel multirate circuit simulation
CN111737535B (en) Network characterization learning method based on element structure and graph neural network
KR20180041200A (en) Information processing method and apparatus
CN111275172B (en) Feedforward neural network structure searching method based on search space optimization
JP2016149127A (en) Device and method for determining entity attribute value
US11687540B2 (en) Fast, approximate conditional distribution sampling
US20140142903A1 (en) Table model circuit simulation acceleration using model caching
CN108399268B (en) Incremental heterogeneous graph clustering method based on game theory
Feng Grass: Graph spectral sparsification leveraging scalable spectral perturbation analysis
WO2022111125A1 (en) Random-forest-based automatic optimization method for graphic data processing framework
CN108710662B (en) Language conversion method and device, storage medium, data query system and method
KR20230095796A (en) Joint personalized search and recommendation with hypergraph convolutional networks
CN111626489A (en) Shortest path planning method and device based on time sequence difference learning algorithm
WO2022142662A1 (en) Operator mapping method and apparatus for computational graph
WO2022036515A1 (en) Production process modeling and simulating method and apparatus
CN111898039B (en) Attribute community searching method integrating hidden relations
CN116302088B (en) Code clone detection method, storage medium and equipment
KR102098255B1 (en) System and method for consolidating knowledge based on knowledge embedding
Shor et al. Lagrangian bounds in multiextremal polynomial and discrete optimization problems
CN113486347A (en) Deep learning hardware Trojan horse detection method based on semantic understanding
US11900018B2 (en) Method for generating designs based on automatically built design space grammars
CN117253209B (en) Automatic driving point cloud detection method, device, communication equipment and storage medium

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21913407

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21913407

Country of ref document: EP

Kind code of ref document: A1