Data model adjustment method and device, model construction method and device

The method optimizes the operation order of tensor reshape and transpose operators in data models, enhancing computational efficiency by adjusting their precedence and expression, thus addressing the inefficiencies caused by interleaved operations.

JP7814513B2Active Publication Date: 2026-02-16VERISILICON MICROELECTRONICS (CHENGDU) CO LTD +4
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
JP2024529210
Authority / Receiving Office
JP · JP
Patent Type
Patents
Current Assignee / Owner
Filing Date
2023-07-28
Publication Date
2026-02-16
Estimated Expiration
2043-07-28

AI Technical Summary

Technical Problem

Existing data models suffer from reduced computational efficiency due to the interleaving of target tensor transpose and reshape operators, leading to inefficient operation processes.

Method used

A method to adjust the operation precedence and expression of tensor reshape and transpose operators in data models, ensuring that the operation result remains unchanged while improving computational efficiency by exchanging the precedence of these operators when they satisfy specific conditions.

Benefits of technology

Enhances the computational efficiency of data models by optimizing the operation order of tensor reshape and transpose operators, reducing the impact on the data model and improving overall performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure 0007814513000001
    Figure 0007814513000001
  • Figure 0007814513000002
    Figure 0007814513000002
  • Figure 0007814513000003
    Figure 0007814513000003
Patent Text Reader

Abstract

A data model adjustment method and device, a model construction method and device, an electronic device, and a computer-readable storage medium are provided. The data model adjustment method includes the steps of obtaining a target tensor reshape operator and a target tensor transpose operator in a target data model, determining whether the target tensor reshape operator and the target tensor transpose operator satisfy an exchange condition, and if the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition, exchanging the operation precedence of the target tensor reshape operator and the target tensor transpose operator in the target data model, and adjusting the operator expression of the tensor transpose operator.
Need to check novelty before this filing date? Find Prior Art

Description

[Technical Field]

[0001] The present application relates to the field of data processing, and specifically to a data model adjustment method and apparatus, a model construction method and apparatus, an electronic device, and a computer-readable storage medium. [Background technology]

[0002] With the development of artificial intelligence, various data models are increasingly used in situations such as speech recognition, image recognition, and face recognition. In various data models, target tensor transpose operators and target tensor reshape operators are commonly used operators. However, in various data models in the prior art, a large number of target tensor transpose operators and target tensor reshape operators are interleaved, which has a significant impact on the calculation efficiency of the data model. Summary of the Invention [Problem to be solved by the invention]

[0003] The present application aims to provide a data model adjustment method and device, a model construction method and device, an electronic device, and a computer-readable storage medium that can adjust a data model, have little impact on the data model, and improve the computational efficiency of the data model. [Means for solving the problem]

[0004] In a first aspect, a data model adjustment method according to the present application includes obtaining a target tensor reshape operator and a target tensor transpose operator in a target data model, wherein the target tensor reshape operator is a tensor reshape operator between two tensor transpose operators in an operation order, and the target tensor transpose operator is either one of the two tensor transpose operators, or the target tensor transpose operator is a tensor transpose operator between two tensor reshape operators in an operation order, and the target tensor reshape operator is either one of the two tensor reshape operators. a step of determining whether the target tensor reshape operator and the target tensor transpose operator satisfy an exchange condition; a step of exchanging the operation precedence of the target tensor reshape operator and the target tensor transpose operator in the target data model if the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition; and a step of adjusting the operator expression of the tensor transpose operator so that the operation result before and after the exchange of the operation precedence of the target tensor reshape operator and the target tensor transpose operator remains unchanged.

[0005] Compared with the prior art, the data model adjustment method according to the embodiments of the present application, when a tensor reshape operator is between two tensor transpose operators in the target data model, or when a tensor transpose operator is between two tensor reshape operators, obtains the target tensor reshape operator and the target tensor transpose operator, determines whether the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition, and if the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition, exchanges the operation precedence of the target tensor reshape operator and the target tensor transpose operator in the target data model, thereby approximating the operation precedence of the two tensor reshape operators or approximating the operation precedence of the two tensor transpose operators, which contributes more to the operations of the tensor reshape operator and the tensor transpose operator, and improves the operation efficiency of the entire data model. In addition, after exchanging the operation precedence of the target tensor reshape operator and the target tensor transpose operator, the operator expression of the tensor transpose operator is adjusted to ensure that the operation result remains unchanged, thereby reducing the impact of exchanging the operation precedence of the target tensor reshape operator and the target tensor transpose operator on the data model.

[0006] In an alternative embodiment, determining whether the target tensor reshape operator and the target tensor transpose operator satisfy an exchange condition comprises obtaining an input tensor and an output tensor of the target tensor reshape operator; determining a plurality of data dimension map groups corresponding to the target tensor reshape operator based on the input tensor and the output tensor; and determining whether the target tensor reshape operator and the target tensor transpose operator satisfy an exchange condition based on the plurality of data dimension map groups and the target tensor transpose operator, wherein the input tensor comprises a plurality of input tensor dimension values, the output tensor comprises a plurality of output tensor dimension values, and each of the data dimension map groups comprises a correspondence between a plurality of the input tensor dimension values ​​and a plurality of the output tensor dimension values.

[0007] In an alternative embodiment, the step of determining whether the target tensor reshape operator and the target tensor transpose operator satisfy an exchange condition based on the plurality of data dimension map groups and the target tensor transpose operator includes the steps of: determining whether a tensor transpose operation corresponding to the target tensor transpose operator is a transpose operation between groups of the plurality of data dimension map groups; determining that the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition if the tensor transpose operation corresponding to the target tensor transpose operator is a transpose operation between groups of the plurality of data dimension map groups; and determining that the target tensor reshape operator and the target tensor transpose operator do not satisfy the exchange condition if the tensor transpose operation corresponding to the target tensor transpose operator is not a transpose operation between groups of the plurality of data dimension map groups.

[0008] In an alternative embodiment, adjusting an operator expression of the target tensor transpose operator includes adjusting an operator expression of the target tensor transpose operator based on the plurality of data dimension map groups.

[0009] In an alternative embodiment, adjusting the operator expression of the target tensor transpose operator based on the plurality of data dimension map groups comprises: an operator expression of the target tensor transpose operator including a plurality of transpose dimension values; when the target tensor reshape operator is placed before the target tensor transpose operator in the operation precedence, the plurality of transpose dimension values ​​correspond one-to-one to the output tensor dimension values; and converting the plurality of transpose dimension values ​​to input tensor dimension values ​​corresponding to the plurality of transpose dimension values ​​based on the data dimension map group.

[0010] In an alternative embodiment, adjusting the operator expression of the target tensor transpose operator based on the plurality of data dimension map groups is such that when the target tensor reshape operator is after the target tensor transpose operator in operation precedence, the plurality of transpose dimension values ​​correspond one-to-one to the input tensor dimension values, and the plurality of transpose dimension values ​​are converted to output tensor dimension values ​​corresponding to the plurality of transpose dimension values ​​based on the data dimension map group.

[0011] In an alternative embodiment, determining a plurality of data dimension map groups corresponding to the target tensor reshape operator based on the input tensor and the output tensor includes performing a Euclidean algorithm on the plurality of input tensor dimension values ​​and the plurality of output tensor dimension values ​​to obtain the plurality of data dimension map groups.

[0012] In alternative embodiments, the target data model includes a neural network model, a machine learning model, or a decision tree model.

[0013] In a second aspect, a data model construction method according to the present application includes the steps of: constructing a target data model including a plurality of tensor transpose operators and a plurality of tensor reshape operators based on a default model framework; and performing an order adjustment on the plurality of tensor transpose operators and tensor reshape operators using a data model adjustment method according to any one of the above embodiments.

[0014] As a third aspect, a data model adjustment device according to the present application includes an operator acquisition module configured to acquire a target tensor reshape operator and a target tensor transpose operator in a target data model, wherein the target tensor reshape operator is a tensor reshape operator between two tensor transpose operators in an operation order, and the target tensor transpose operator is either one of the two tensor transpose operators, or the target tensor transpose operator is a tensor transpose operator between two tensor reshape operators in an operation order, and the target tensor reshape operator is either one of the two tensor reshape operators; the data model adjustment module is configured to, if the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition, exchange the operation precedence of the target tensor reshape operator and the target tensor transpose operator in the target data model, and adjust the operator expression of the tensor transpose operator so that the operation result does not change after exchanging the operation precedence of the target tensor reshape operator and the target tensor transpose operator.

[0015] In a fourth aspect, a data model construction device according to the present application includes a model construction module that constructs a target data model including a plurality of tensor transpose operators and a plurality of tensor reshape operators based on a predetermined model framework, and a model adjustment module that performs order adjustment on the plurality of tensor transpose operators and tensor reshape operators using a data model adjustment method according to any one of the above embodiments.

[0016] In a fifth aspect, an electronic device according to the present application comprises at least one processor and a storage device communicatively connected to the at least one processor, wherein commands executable by the at least one processor are stored in the storage device, and when the commands are executed by the at least one processor, the at least one processor executes a data model adjustment method according to any one of the above embodiments or a data model construction method according to the above embodiments.

[0017] In a sixth aspect, a computer program is stored in a computer-readable storage medium according to the present application, and when the computer program is executed by a processor, a data model adjustment method according to any one of the above embodiments or a data model construction method according to the above embodiments is realized. [Brief explanation of the drawings]

[0018] In order to more clearly explain the technical solutions of the embodiments of the present application, the drawings used in the embodiments will be briefly described below. The drawings described are only for illustrating some embodiments of the present application and are not intended to limit the scope. Those skilled in the art can obtain other drawings based on these drawings without using inventive ability. [Figure 1] 1 is a schematic flowchart of a data model adjustment method according to a first embodiment of the present application; [Figure 2]10 is a schematic flowchart of a process for determining whether a target tensor reshape operator and a target tensor transpose operator satisfy an exchange condition in a data model adjustment method according to Example 1 of the present application. [Figure 3] FIG. 2 is a schematic diagram of several tensors in a data model adjustment method according to Example 1 of the present application; [Figure 4] 1 is a schematic flowchart of a data model construction method according to a second embodiment of the present application; [Figure 5] FIG. 10 is a schematic configuration diagram of a data model adjustment device according to a third embodiment of the present application. [Figure 6] FIG. 10 is a schematic configuration diagram of a data model construction device according to a fourth embodiment of the present application. [Figure 7] FIG. 10 is a schematic configuration diagram of an electronic device according to a fifth embodiment of the present application. DETAILED DESCRIPTION OF THE INVENTION

[0019] In order to make the objectives, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions of the embodiments of the present application will be described below clearly and completely with reference to the drawings in the embodiments of the present application. Of course, the described embodiments are only some of the embodiments of the present application, and do not represent all of the embodiments. In general, the elements in the embodiments of the present application shown in the drawings and described herein can be arranged and designed in various combinations.

[0020] Therefore, the detailed description of the embodiments of the present application shown in the drawings does not limit the scope of the present application to be protected, but merely illustrates selected embodiments of the present application. All other embodiments that a person skilled in the art can obtain based on the embodiments in the present application without using his or her inventive abilities also fall within the scope of protection of the present application.

[0021] Since like reference numerals refer to like elements in the drawings, if an element is defined in one drawing, it need not be defined and interpreted repeatedly in other drawings.

[0022] In the description of this application, the directions or positional relationships expressed by terms such as "upper," "lower," "inner," and "outer" are based on the drawings or are the directions or positional relationships of the general arrangement of the inventive product during normal use, and are merely intended to facilitate and simplify the description of this application. They do not expressly or imply that the relevant devices or elements necessarily have a specific orientation or are configured and operated in a specific orientation, and therefore do not limit this application.

[0023] Additionally, terms such as "first," "second," etc. are for descriptive purposes only and do not express or imply any relative importance.

[0024] Unless there is a contradiction, the features in the embodiments of the present application may be combined with each other.

[0025] Tensors are multidimensional arrays that can be used for data access. The tensor transpose operator is used to perform a dimensional transposition operation on tensor data, changing the order in which the data is sorted in storage. The tensor reshape operator changes the shape of tensor data without changing the order in which the data is sorted in storage. In actual use, data is stored in a storage device, and the stored data can be adjusted according to different usage requirements. For example, adjustments to tensors can be made to the data distribution of the stored data, and the adjustments to tensors can be realized by a data model constructed by the tensor transpose operator and the tensor reshape operator. However, in order to perform complex data distribution adjustment, conventional data models have multiple tensor transpose operators and multiple tensor reshape operators, and the operation order between the multiple tensor transpose operators and the multiple tensor reshape operators is interleaved, so the operation process for one tensor includes repeated tensor transpose and tensor reshape operations. For example, for one tensor, first perform a tensor transpose operator operation, then perform a tensor reshape operator operation, then perform another tensor transpose operator operation, and then further include multiple interleaved tensor transpose and tensor reshape operations, which reduces the operation efficiency of the data model.

[0026] To solve the above problem of reduced computational efficiency caused by interleaving operations between multiple tensor transpose operators and multiple tensor reshape operators, Example 1 of the present application provides a data model adjustment method for adjusting operators in a data model, which has a relatively small impact on the computation results of the data model and improves the computational efficiency of the data model. The specific data model adjustment method, as shown in Figure 1, includes the following steps:

[0027] Step S101: Obtain a target tensor reshape operator and a target tensor transpose operator in the target data model.

[0028] In this step, the target data model is a data model that needs to be adjusted. In some embodiments of the present application, the target data model may be a model that is initially constructed and has not been trained on data, or may be a model that has been trained on data.

[0029] Additionally, in some embodiments of the present application, the target data model is any one of a variety of different data models, such as, for example, a neural network model, a machine learning model, a decision tree model, and the like.

[0030] The target data model includes a plurality of tensor transpose operators and a plurality of tensor reshape operators, and the plurality of tensor transpose operators and the plurality of tensor reshape operators are arranged in an interleaved manner.

[0031] In this step, the target tensor reshape operator and the target tensor transpose operator are respectively a tensor reshape operator and a tensor transpose operator in the target data model. In some embodiments of the present application, the target tensor reshape operator is a tensor reshape operator between two tensor transpose operators in operation order, and the target tensor transpose operator is one of the two tensor transpose operators. If the tensor transpose operator is A and the tensor reshape operator is B, and the operation order of the tensor transpose operator A and the tensor reshape operator B is ABA, the target tensor reshape operator is a tensor reshape operator B between the two tensor transpose operators A, and the target tensor transpose operator is one of the two tensor transpose operators A. When the target tensor transpose operator and the target tensor reshape operator are exchanged, the original operation order ABA of the tensor transpose operator and the tensor reshape operator becomes AAB or BAA, where the two tensor transpose operators A are adjacent in operation order and can be merged into one new tensor transpose operator or can cancel each other out. Alternatively, in some other embodiments of the present application, the target tensor transpose operator is a tensor transpose operator between two tensor reshape operators in operation order, and the target tensor reshape operator is one of the two tensor reshape operators. Similarly, if the tensor transpose operator is A and the tensor reshape operator is B, then when the operation order of the tensor transpose operator A and the tensor reshape operator B is BAB, the target tensor transpose operator is a tensor transpose operator A between the two tensor reshape operators B, and the target tensor reshape operator is one of the two tensor reshape operators B.Therefore, when the target tensor transpose operator and the target tensor reshape operator are exchanged, the original operation order of the tensor transpose operator and the tensor reshape operator, BAB, becomes ABB or BBA, and in this case, the two tensor reshape operators B have adjacent operation orders and can be merged into one new tensor reshape operator or can cancel each other out.

[0032] In some embodiments of the present application, the above tensor transpose operators and tensor reshape operators may be existing tensor transpose operators and tensor reshape operators in the data model, or may be tensor transpose operators and tensor reshape operators obtained by adjustment using the data model adjustment method according to the embodiments of the present application. For example, if the original multiple tensor transpose operators and multiple tensor reshape operators are ABABA, among them, "ABA" may be reordered to BAA using the data model adjustment method according to the embodiments of the present application, and adjacent tensor transpose operators AA may be merged into one tensor transpose operator A, i.e., the original ABABA may become BAABA, and after merging, become BABA, and further reordering and operator merging or cancellation may be performed on "BAB" among them.

[0033] Also, in some embodiments of the present application, the target tensor reshape operator and the target tensor transpose operator are two immediately adjacent operators.

[0034] Step S102: Determine whether the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition. If YES, execute step S103; if NO, execute step S101.

[0035] As shown in FIG. 2, this step may include several sub-steps shown in FIG. 2, specifically including the following steps:

[0036] Step S201: Obtain the input tensor and output tensor of the target tensor reshape operator.

[0037] In this step, the input tensor is a tensor to be reshaped by the target tensor reshape operator, and includes a plurality of input tensor dimension values. The output tensor is a tensor obtained by the target tensor reshape operator performing a reshape operation on the input tensor, and includes a plurality of output tensor dimension values. As shown in Figure 3, after performing a tensor transpose operator on tensor A (2,6), tensor B (6,2) is obtained, and after performing a tensor reshape operator on tensor B (6,2), tensor C (2,3,2) is obtained. Taking Figure 3 as an example, the input tensor is, for example, tensor B (6,2) in Figure 3, in which the input tensor dimension is 6,2, and the output tensor is, for example, tensor C (2,3,2) in Figure 3, in which the output tensor dimension is 2,3,2.

[0038] Step S202: Determine a plurality of data dimension map groups corresponding to the target tensor reshape operator according to the input tensor and the output tensor.

[0039] In this step, the data reshape operator means to rearrange and combine the data dimensions of the input tensor, thereby changing the spatial information of the data access and obtaining the output tensor. The data dimension map group defines the dimension conversion relationship between the input tensor and the output tensor. The multiple input tensor dimension values ​​of the input tensor and the multiple output tensor dimension values ​​of the output tensor have the following mapping relationship:

[0040] Direct mapping: This does not involve tensor reshaping and maintains the dimensional information. For example, for an input tensor (2,2,100,128) and an output tensor (4,10,10,128), the direct mapping relationship is satisfied by the input tensor dimension value of 128 and the output tensor dimension value of 128.

[0041] Merger Mapping: Merges multiple dimensions into a single output dimension. For example, for an input tensor (2,2,100,128) and an output tensor (4,10,10,128), the merge mapping relationship is that the input tensor dimension value is 2, 2 and the output tensor dimension value is 4.

[0042] Split mapping: Splits one dimension into multiple output dimensions. For example, for an input tensor (2,2,100,128) and an output tensor (4,10,10,128), the split mapping relationship is satisfied by the input tensor dimension value of 100 and the output tensor dimension values ​​of 10,10.

[0043] Mapping including merging and splitting: There are multiple types of mapping relationships between multiple dimensions. For example, for an input tensor (3,5,7,11) and an output tensor (21,5,11), the input tensor dimension values ​​3, 5, 7 and the output tensor dimension values ​​21, 5 satisfy the split mapping relationship.

[0044] In this step, each data dimension map group contains a mapping relationship between some input tensor dimension values ​​and some output tensor dimension values. That is, a mapping relationship between input tensor dimension values ​​and output tensor dimension values ​​that satisfies the above mapping relationship is constructed to form a data dimension map group. For example, an input tensor (2,2,100,128) and an output tensor (4,10,10,128) include a data dimension map group G0 = (in:{0,1}, out:{0}), a data dimension map group G1 = (in:{2}, out:{1,2}), and a data dimension map group G2 = (in:{3}, out:{3}). Among them, the data dimension map group G0 = (in:{0,1}, out:{0}) is a mapping relationship between the first input tensor dimension value (symbol is 0) and the second input tensor dimension value (symbol is 1) in the input tensor and the first output tensor dimension value (symbol is 0) in the output tensor. The data dimension map group G1 = (in:{2},out:{1,2}) is a mapping relationship between the third input tensor dimension value (symbol is 2) in the input tensor and the second output tensor dimension value (symbol is 1) and the third output tensor dimension value (symbol is 2) in the output tensor. The data dimension map group G2 = (in:{3},out:{3}) is a mapping relationship between the fourth input tensor dimension value (symbol is 3) in the input tensor and the fourth output tensor dimension value (symbol is 3) in the output tensor.

[0045] In some embodiments of the present application, a Euclidean algorithm is performed on a plurality of input tensor dimension values ​​and a plurality of output tensor dimension values ​​to obtain a plurality of data dimension map groups. For input tensors (K1, K2, K3, K4, K5) and output tensors (R1, R2, R3), the Euclidean algorithm includes the following steps:

[0046] Step s1: Obtain the first input tensor dimension value K1 in the input tensor and the first output tensor dimension value R1 in the output tensor. Take the larger of K1 and R1 as the numerator and the smaller as the denominator, and calculate the quotient Q1 and remainder W1 of K1 divided by R1. For example, when K1 < R1, R1 ÷ K1 = Q1 … W1.

[0047] Step s2: If the remainder W1 is 0 and the quotient Q1 is not 1, obtain the second tensor dimension value in the tensor to which the denominator's tensor dimension value belongs. If the numerator is R1 and the denominator is K1, obtain the second input tensor dimension value K2 in the input tensor; if the numerator is K1 and the denominator is R1, obtain the second output tensor dimension value R2 in the output tensor. Taking obtaining the second input tensor dimension value K2 in the input tensor as an example, in this step, further take the larger of K2 and Q1 as the numerator and the smaller as the denominator, and calculate the quotient Q2 and remainder W2 of K2 divided by Q1.

[0048] Step s3: If the remainder W1 is not 0 and the quotient Q1 is 1, obtain the second input tensor dimension value K2 and the second output tensor dimension value R2, and calculate the quotient Q2 and remainder W2 of K1 * K2 divided by R1 * R2.

[0049] Step s4: If the remainder W1 is not 0 and the quotient Q1 is 1, calculate the product K1 * R1 of the numerator K1 and the denominator R1, obtain the second tensor dimension value in the tensor to which the denominator belongs. For example, when K1 < R1, obtain the second output tensor dimension value R2, and calculate the quotient Q2 and remainder W2 of K1 * R1 divided by R2.

[0050] Step s5: Repeat steps s2 to s4 until the quotient becomes 1 and the remainder becomes 0, and output one data dimension mapping group G0 = (in:{0,1…}, out:{0,1…}), where 0, 1… are the rank numbers of the obtained input tensor dimension values and output tensor dimension values.

[0051] s6: Further, new input tensor dimension values ​​and output tensor dimension values ​​are sequentially obtained, and s2 to s5 are executed until calculations for all input tensor dimension values ​​and output tensor dimension values ​​are completed.

[0052] For example, if a Euclidean algorithm is performed on an input tensor (2,2,10,10,128) and an output tensor (4,100,128), first s1 is executed, and the quotient of the input tensor dimension value 2 and the output tensor dimension value 4, 2, and the remainder 0 are calculated. Then s2 is executed, and the quotient of this quotient 2 and the second input tensor dimension value 2, 1, and the remainder 0 are calculated. In this case, s5 is executed, and a data dimension map group G0 = (in:{0,1},out:{0}) is output. Then, a new input tensor dimension value of 10 and an output tensor dimension value of 100 are sequentially obtained, and a data dimension map group G1 = (in:{2,3},,out:{1}) and a data dimension map group G2 = (in:{4},out:{2}) are output.

[0053] For example, if you want to perform a Euclidean algorithm on an input tensor (3,5,7,11) and an output tensor (21,5,11), first execute s1, and calculate the quotient of the input tensor dimension value 2 and the output tensor dimension value 21, which is 7, and the remainder is 0. Then execute s2, and calculate the quotient of this quotient 7 and the second input tensor dimension value 5, which is 1, and the remainder is 2. In this case, execute s4, and calculate the product of the quotient 7 and the second input tensor dimension value 5, which is 35, and the second output tensor dimension value The product 35 is obtained, and the quotient of 7 and the second output tensor dimension value 5 is calculated to be 7, and the remainder 0 is obtained. Then s2 is executed, and the quotient of 7 and the third input tensor dimension value 7 is calculated to be 1, and the remainder 0 is obtained. Then s5 is executed, and the data dimension map group G0 = (in: {0,1,2}, out: {0,1}) is output, and then a new input tensor dimension value of 11 and an output tensor dimension value of 11 are sequentially obtained... and the data dimension map group G1 = (in: {3}, out: {2}) is output.

[0054] Step S203: Determine whether the target tensor reshape operator and the target tensor transpose operator satisfy a trade-off condition based on the plurality of data dimension map groups and the target tensor transpose operator.

[0055] In this step, the target tensor transpose operator can be used to determine whether the tensor transpose operation corresponding to the target tensor transpose operator is a transpose operation between groups of a plurality of data dimension map groups. If the tensor transpose operation corresponding to the target tensor transpose operator is a transpose operation between groups of a plurality of data dimension map groups, it is determined that the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition. If the tensor transpose operation corresponding to the target tensor transpose operator is not a transpose operation between groups of a plurality of data dimension map groups, it is determined that the target tensor reshape operator and the target tensor transpose operator do not satisfy the exchange condition.

[0056] Here, the inter-group transposition operation of multiple data dimension map groups is a unified transposition operation between the input tensor dimension values ​​corresponding to each data dimension map group. Taking the target tensor transposition operator {2,3,0,1,4} as an example, the target tensor transposition operator {2,3,0,1,4} converts the tensor dimension value order {0,1,2,3,4} in the tensor to {2,3,0,1,4} in the target tensor transposition operator. That is, the first tensor dimension value is moved to the third, the second tensor dimension value to the fourth, the third tensor dimension value to the first, the fourth tensor dimension value to the second, and the position of the fifth tensor dimension value remains the same. That is, the first tensor dimension value and the second tensor dimension value are unified, and the third tensor dimension value and the fourth tensor dimension value are unified.

[0057] If the corresponding data dimension map groups are G0=(in:{0,1},out:{0}), G1=(in:{2,3},out:{1}), G2=(in:{4},out:{2}), the input tensor dimension values ​​corresponding to the data dimension map group G0 are the first tensor dimension value and the second tensor dimension value, and the input tensor dimension values ​​corresponding to the data dimension map group G1 are the third tensor dimension value and the fourth tensor dimension value. In this case, the tensor transpose operation corresponding to {2,3,0,1,4} of the target tensor transpose operator is a transpose operation between the data dimension map groups G0 and G1, and it is determined that the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition.

[0058] If the corresponding data dimension map groups are G0=(in:{0,1},out:{0}), G1=(in:{2},out:{1,2}), G2=(in:{4},out:{3}), the input tensor dimension values ​​corresponding to the data dimension map group G0 are the first tensor dimension value and the second tensor dimension value, and the input tensor dimension value corresponding to the data dimension map group G1 is the third tensor dimension value. In this case, it is determined that the tensor transpose operation corresponding to {2,3,0,1,4} of the target tensor transpose operator is not a transpose operation between the data dimension map groups G0, G1, and G2, and the target tensor reshape operator and the target tensor transpose operator do not satisfy the exchange condition.

[0059] Step S103: Exchange the operation precedence of the target tensor reshape operator and the target tensor transpose operator in the target data model.

[0060] Step S104: Adjust the operator expression of the tensor transpose operator.

[0061] In this step, the purpose of adjusting the operator expression of the tensor transpose operator is to ensure that the operation result remains unchanged after the operation precedence of the target tensor reshape operator and the target tensor transpose operator is exchanged. Specifically, the operator expression of the target tensor transpose operator can be adjusted based on multiple data dimension map groups.

[0062] Furthermore, in some embodiments of the present application, the operator expression of the target tensor transpose operator includes multiple transpose dimension values, for example, 2, 3, 0, 1, 4 in {2, 3, 0, 1, 4} of the above target tensor transpose operator are transpose dimension values.

[0063] If the target tensor reshape operator is prior to the target tensor transpose operator in the operation order, the target tensor reshape operator is operated first, and then the target tensor transpose operator is operated. At this time, the multiple transpose dimension values ​​correspond one-to-one to the output tensor dimension values, and the multiple transpose dimension values ​​are converted into the input tensor dimension values ​​corresponding to the multiple transpose dimension values ​​based on the data dimension map group. For example, for a tensor (10,10,2,2,128), first a target tensor reshape operator is operated on it to obtain a tensor (100,4,128), and then a target tensor transpose operator is operated on the tensor (100,4,128) to obtain a tensor (4,100,128), where the multiple data dimension map groups corresponding to the target tensor reshape operator are G0=(in:{0,1},out:{0}), G1=(in:{2,3},out:{1}), G2=(in:{4},out:{2}), respectively, the output tensor dimension values ​​corresponding to the target tensor reshape operator are 100, 4, 128, the target tensor transpose operator is {1,0,2}, and the transpose dimension values ​​are 1, 0, 2. Based on the data dimension map group, the multiple transpose dimension values ​​are transformed into input tensor dimension values ​​corresponding to the multiple transpose dimension values, i.e., the transpose dimension value 1 is transformed into the corresponding input tensor dimension values ​​2, 3 in the data dimension map group G1=(in:{2,3},out:{1}), the transpose dimension value 0 is transformed into the corresponding input tensor dimension values ​​0, 1 in the data dimension map group G0=(in:{0,1},out:{0}), and the transpose dimension value 2 is transformed into the corresponding input tensor dimension value 4 in the data dimension map group G2=(in:{4},out:{2}), so that the rewritten operator expression of {1,0,2} of the target tensor transpose operator becomes {2,3,0,1,4}.

[0064] If the operation priority of the target tensor reshape operator is after the target tensor transpose operator, the operation of the target tensor transpose operator is performed first, and then the operation of the target tensor reshape operator is performed, and at this time, the multiple transpose dimension values ​​and the input tensor dimension values ​​correspond one-to-one, and the multiple transpose dimension values ​​are converted into output tensor dimension values ​​corresponding to the multiple transpose dimension values ​​based on the data dimension map group. For example, for a tensor (10,10,2,2,128), first a target tensor transpose operator is operated on it to obtain a tensor (2,2,10,10,128), and then a target tensor reshape operator is operated on the tensor (2,2,10,10,128) to obtain a tensor (4,100,128), where the multiple data dimension map groups corresponding to the target tensor transpose operator are G0=(in:{0,1},out:{0}), G1=(in:{2,3},out:{1}), G2=(in:{4},out:{2}), respectively, the input tensor dimension values ​​corresponding to the target tensor reshape operator are 2, 2, 10, 10, 128, the target tensor transpose operator is {2,3,0,1,4}, and the transpose dimension values ​​are 2, 3, 0, 1, 4. Based on the data dimension map group, the multiple transpose dimension values ​​are transformed into output tensor dimension values ​​corresponding to the multiple transpose dimension values, i.e., the transpose dimension values ​​2 and 3 are transformed into the corresponding output tensor dimension value 1 in the data dimension map group G1=(in:{2,3},out:{1}), the transpose dimension values ​​0 and 1 are transformed into the corresponding output tensor dimension value 0 in the data dimension map group G0=(in:{0,1},out:{0}), and the transpose dimension value 2 is transformed into the corresponding output tensor dimension value 4 in the data dimension map group G2=(in:{4},out:{2}), so that the rewritten operator expression of the target tensor transpose operator {2,3,0,1,4} becomes {1,0,2}.

[0065] Compared with the prior art, the data model adjustment method according to the embodiments of the present application, when a tensor reshape operator is between two tensor transpose operators in the target data model, or when a tensor transpose operator is between two tensor reshape operators, obtains the target tensor reshape operator and the target tensor transpose operator, determines whether the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition, and if the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition, exchanges the operation precedence of the target tensor reshape operator and the target tensor transpose operator in the target data model, thereby approximating the operation precedence of the two tensor reshape operators or approximating the operation precedence of the two tensor transpose operators, which contributes more to the operations of the tensor reshape operator and the tensor transpose operator, and improves the operation efficiency of the entire data model. In addition, after exchanging the operation precedence of the target tensor reshape operator and the target tensor transpose operator, the operator expression of the tensor transpose operator is adjusted to ensure that the operation result remains unchanged, thereby reducing the impact of exchanging the operation precedence of the target tensor reshape operator and the target tensor transpose operator on the data model.

[0066] Example 2 of the present application provides a data model construction method, as shown in Figure 4, the data model construction method includes the following steps:

[0067] Step S301: Construct a target data model based on a predetermined model framework, where the target data model includes a plurality of tensor transpose operators and a plurality of tensor reshape operators.

[0068] In this step, a corresponding predefined model framework can be used based on the model type of the target data model. For example, if the target data model is a neural network model, a corresponding neural network model framework including an input layer, multiple hidden layers and an output layer can be used to construct the target data model.

[0069] Step S302: The order of the multiple tensor transpose operators and tensor reshape operators is adjusted.

[0070] In this step, the order of the plurality of tensor transpose operators and the plurality of tensor reshape operators in the target data model is adjusted according to the data model adjustment method in the above embodiment.

[0071] Compared with the prior art, in the data model construction method according to the embodiment of the present application, a target data model is constructed using a predetermined model framework, and then the order of multiple tensor transpose operators and multiple tensor reshape operators in the target data model is adjusted by the data model adjustment method according to the above embodiment, thereby improving the computational efficiency of the constructed target data model.

[0072] A third embodiment of the present application provides a data model adjustment device. As shown in Fig. 5, the data model adjustment device includes an operator acquisition module 401, a determination module 402, and a data model adjustment module 403. The operator acquisition module 401 is configured to acquire a target tensor reshape operator and a target tensor transpose operator in a target data model, where the target tensor reshape operator is a tensor reshape operator between two tensor transpose operators in operation order, and the target tensor transpose operator is one of the two tensor transpose operators, or the target tensor transpose operator is a tensor transpose operator between two tensor reshape operators in operation order, and the target tensor reshape operator is one of the two tensor reshape operators. The determination module 402 is configured to determine whether the target tensor reshape operator and the target tensor transpose operator satisfy a trade-off condition. The data model adjustment module 403 is configured to exchange the operation precedence of the target tensor reshape operator and the target tensor transpose operator in the target data model when the target tensor reshape operator and the target tensor transpose operator satisfy an exchange condition, and further adjust the operator expression of the tensor transpose operator so that the operation result does not change after exchanging the operation precedence of the target tensor reshape operator and the target tensor transpose operator.

[0073] Compared with the prior art, in the data model adjustment device according to the embodiments of the present application, when one tensor reshape operator is between two tensor transpose operators in the target data model, or when one tensor transpose operator is between two tensor reshape operators, the operator acquisition module 401 acquires the target tensor reshape operator and the target tensor transpose operator, the judgment module 402 judges whether the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition, and if the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition, the data model adjustment module 403 exchanges the operation precedence of the target tensor reshape operator and the target tensor transpose operator in the target data model, thereby making the operation precedence of the two tensor reshape operators adjacent or the operation precedence of the two tensor transpose operators adjacent, which can contribute more to the operations of the tensor reshape operator and the tensor transpose operator and improve the operation efficiency of the entire data model. In addition, after exchanging the operation precedence of the target tensor reshape operator and the target tensor transpose operator, the data model adjustment module 403 further adjusts the operator expression of the tensor transpose operator so that the operation result remains unchanged, thereby reducing the impact of exchanging the operation precedence of the target tensor reshape operator and the target tensor transpose operator on the data model.

[0074] A fourth embodiment of the present application provides a data model construction device. As shown in Fig. 6, the data model construction device includes a model construction module 501 and a model adjustment module 502. The model construction module 501 is configured to construct a target data model based on a predetermined model framework, where the target data model includes a plurality of tensor transpose operators and a plurality of tensor reshape operators. The model adjustment module 502 is configured to perform order adjustment on the plurality of tensor transpose operators and tensor reshape operators using the data model adjustment method according to the above embodiment.

[0075] Compared with the prior art, in the data model construction device according to the embodiment of the present application, after the model construction module 501 constructs a target data model using a predetermined model framework, the model adjustment module 502 uses the data model adjustment method in the above embodiment to perform order adjustment on multiple tensor transpose operators and multiple tensor reshape operators in the target data model, thereby improving the computational efficiency of the constructed target data model.

[0076] In some embodiments, the data model in the above embodiments can be a model for performing corresponding tasks in different fields and can be applied to various fields, including but not limited to image processing, speech processing, and NLP (Natural Language Processing).

[0077] Accordingly, the input tensor in the above embodiments may be corresponding target data in the relevant field, such as, but not limited to, target image, target audio, target text, etc.

[0078] A fifth embodiment of the present application provides an electronic device. As shown in Fig. 7, the electronic device includes at least one processor 601 and a storage device 602 communicatively connected to the at least one processor 601. The storage device 602 stores commands executable by the at least one processor 601, and when the commands are executed by the at least one processor 601, the at least one processor 601 can execute the data model adjustment method or the data model construction method in each of the above embodiments.

[0079] The storage device and the processor are connected by a bus, which may include any number of interconnected buses and bridges, connecting one or more processors to various circuits of the storage device. The bus may connect various other circuits, such as peripheral devices, voltage regulators, and power management circuits, which are well known and will not be further described herein. The bus interface provides an interface between the bus and a transceiver. The transceiver may be a single element or multiple elements, such as multiple receivers and transmitters, and is used as a unit to communicate with other devices via a transmission medium. Data processed by the processor is transmitted over a wireless medium via an antenna, which receives and transmits data to the processor.

[0080] The processor is responsible for bus management and general processing, and may further provide a variety of functions for timing, peripheral interfacing, voltage regulation, power management, and other control functions. The memory device is configured to store data used by the processor when performing operations.

[0081] A sixth embodiment of the present application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the above-described method embodiments.

[0082] That is, as will be understood by those skilled in the art, all or part of the steps of the methods according to the above embodiments can be realized by instructing related hardware through a program. The program is stored in a storage medium and includes a plurality of commands for causing a device (which may be a microcontroller, a chip, etc.) or a processor to execute all or part of the steps of the methods according to the embodiments of the present application. The storage medium includes various media capable of storing program code, such as a USB disk, a portable hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.

[0083] The above are only specific embodiments of the present application, and the protection scope of the present application is not limited thereto. Any modifications or replacements made by those skilled in the art within the technical scope disclosed in the present application will fall within the protection scope of the present application.

Claims

1. A data model adjustment method executed by an electronic device, comprising: Obtaining a target tensor reshape operator and a target tensor transpose operator in a target data model, wherein the target tensor reshape operator is a tensor reshape operator whose operation precedence is between two tensor transpose operators, and the target tensor transpose operator is either one of the two tensor transpose operators, or the target tensor transpose operator is a tensor transpose operator whose operation precedence is between the operation precedences of two tensor reshape operators, and the target tensor reshape operator is either one of the two tensor reshape operators; determining whether the target tensor reshape operator and the target tensor transpose operator satisfy a trade-off condition; If the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition, exchanging the operation precedence of the target tensor reshape operator and the target tensor transpose operator in the target data model; adjusting the operator expression of the tensor transpose operator so that the operation result before and after the exchange of the operation precedence of the target tensor reshape operator and the target tensor transpose operator remains unchanged. A data model adjustment method comprising:

2. The step of determining whether the target tensor reshape operator and the target tensor transpose operator satisfy a trade-off condition comprises: obtaining input and output tensors of the target tensor reshape operator; determining a plurality of data dimension map groups corresponding to the target tensor reshape operator based on the input tensor and the output tensor; determining whether the target tensor reshape operator and the target tensor transpose operator satisfy a trade-off condition based on the plurality of data dimension map groups and the target tensor transpose operator; the input tensor comprises a plurality of input tensor dimension values, and the output tensor comprises a plurality of output tensor dimension values; Each of the data dimension map groups includes a correspondence between a plurality of the input tensor dimension values ​​and a plurality of the output tensor dimension values.

2. The method of claim 1, wherein the data model is adjusted based on the data model.

3. The step of determining whether the target tensor reshape operator and the target tensor transpose operator satisfy an exchange condition based on the plurality of data dimension map groups and the target tensor transpose operator includes: determining whether a tensor transpose operation corresponding to the target tensor transpose operator is an inter-group transpose operation of the plurality of data dimension map groups; determining that the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition when the tensor transpose operation corresponding to the target tensor transpose operator is a transpose operation between groups of the plurality of data dimension map groups; determining that the target tensor reshape operator and the target tensor transpose operator do not satisfy the exchange condition when a tensor transpose operation corresponding to the target tensor transpose operator is not a transpose operation between groups of the plurality of data dimension map groups.

3. The data model adjustment method according to claim 2.

4. Adjusting the operator representation of the target tensor transpose operator comprises: adjusting an operator expression of the target tensor transpose operator based on the plurality of data dimension map groups.

3. The data model adjustment method according to claim 2.

5. adjusting an operator expression of the target tensor transpose operator based on the plurality of data dimension map groups, an operator expression of the target tensor transpose operator including a plurality of transpose dimension values; When the target tensor reshape operator is placed before the target tensor transpose operator in the operation order, the plurality of transposed dimension values ​​correspond one-to-one to the output tensor dimension values, and the plurality of transposed dimension values ​​are converted into input tensor dimension values ​​corresponding to the plurality of transposed dimension values ​​based on the data dimension map group.

5. The data model adjustment method according to claim 4.

6. adjusting an operator expression of the target tensor transpose operator based on the plurality of data dimension map groups, When the target tensor reshape operator is placed before the target tensor transpose operator in the operation order, the plurality of transpose dimension values ​​correspond one-to-one to the input tensor dimension values, and the plurality of transpose dimension values ​​are converted into output tensor dimension values ​​corresponding to the plurality of transpose dimension values ​​based on the data dimension map group.

6. The data model adjustment method according to claim 5.

7. determining a plurality of data dimension map groups corresponding to the target tensor reshape operator based on the input tensor and the output tensor, performing a Euclidean algorithm on the plurality of input tensor dimension values ​​and the plurality of output tensor dimension values ​​to obtain the plurality of data dimension map groups; performing a Euclidean algorithm on the plurality of input tensor dimension values ​​and the plurality of output tensor dimension values ​​to obtain the plurality of data dimension map groups, s1: Obtain the first input tensor dimension value K1 in the input tensor and the first output tensor dimension value R1 in the output tensor, use the larger of K1 and R1 as the numerator and the smaller of K1 and R1 as the denominator, and find the quotient Q1 and remainder W1 between K1 and R1; s2: If the remainder W1 is 0 and the quotient Q1 is not 1, obtain the second tensor dimension value in the tensor to which the tensor dimension value of the denominator belongs; if the numerator is R1 and the denominator is K1, obtain the second input tensor dimension value K2 in the input tensor; if the numerator is K1 and the denominator is R1, obtain the second output tensor dimension value R2 in the output tensor; s3: If the remainder W1 is not 0 and the quotient Q1 is 1, obtain the second input tensor dimension value K2 and the second output tensor dimension value R2, and calculate the quotient Q2 and remainder W2 of K1*K2 and R1*R2; s4: If the remainder W1 is not 0 and the quotient Q1 is 1, calculate the product K1*R1 of the numerator K1 and the denominator R1, and obtain the second tensor dimension value of the tensor to which the denominator belongs; s5: Repeat steps s2 to s4 until the quotient becomes 1 and the remainder becomes 0, and output one data dimension map group G0 = (in: {0, 1 ...}, out: {0, 1 ...}), where 0, 1 ... are the order numbers of the acquired input tensor dimension values ​​and output tensor dimension values; s6: Further new input tensor dimension values ​​and output tensor dimension values ​​are obtained in sequence, and steps s2 to s5 are executed until calculations for all input tensor dimension values ​​and output tensor dimension values ​​are completed.

3. The data model adjustment method according to claim 2.

8. The target data model includes a neural network model, a machine learning model, and a decision tree model; The target data model is used to adjust the layout of the data.

8. The data model adjustment method according to claim 1, wherein:

9. constructing a target data model based on a predefined model framework, the target data model including a plurality of tensor transpose operators and a plurality of tensor reshape operators; and adjusting the order of the plurality of tensor transpose operators and tensor reshape operators by the data model adjustment method according to any one of claims 1 to 7. A data model construction method comprising:

10. an operator acquisition module configured to acquire a target tensor reshape operator and a target tensor transpose operator in a target data model, wherein the target tensor reshape operator is a tensor reshape operator whose operation precedence is between two tensor transpose operators, and the target tensor transpose operator is one of the two tensor transpose operators, or the target tensor transpose operator is a tensor transpose operator whose operation precedence is between the operation precedences of two tensor reshape operators, and the target tensor reshape operator is one of the two tensor reshape operators; a determining module configured to determine whether the target tensor reshape operator and the target tensor transpose operator satisfy a trade-off condition; a data model adjustment module configured to, when the target tensor reshape operator and the target tensor transpose operator satisfy the exchange condition, exchange an operation order in the target data model between the target tensor reshape operator and the target tensor transpose operator, and adjust an operator expression of the tensor transpose operator so that an operation result does not change after exchanging the operation order between the target tensor reshape operator and the target tensor transpose operator. A data model adjustment device comprising:

11. a model construction module that constructs a target data model based on a predetermined model framework, the target data model including a plurality of tensor transpose operators and a plurality of tensor reshape operators; a model adjustment module that adjusts the order of the plurality of tensor transpose operators and tensor reshape operators by the data model adjustment method according to any one of claims 1 to 7. A data model construction device comprising:

12. A data model adjustment method according to any one of claims 1 to 7, comprising: at least one processor; and a storage device connected in communication with the at least one processor, wherein commands executable by the at least one processor are stored in the storage device, and when the commands are executed by the at least one processor, the at least one processor executes the data model adjustment method according to any one of claims 1 to 7. An electronic device characterized by:

13. A computer-readable storage medium having a computer program stored thereon, the computer program being adapted to execute the data model adjustment method according to any one of claims 1 to 7 when executed by a processor. A computer-readable storage medium comprising: