A method, apparatus, electronic device, and storage medium for data processing
By using the shape operation relationship and data operation relationship in the calculation graph, the problem of mismatch in training of the training data in neural network model is solved, and efficient and accurate network training is achieved.
Patent Information
- Application Number
- CN202111266095.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-28
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2041-10-28
Smart Images

Figure CN114004335B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technologies, and in particular, to a method, an apparatus, an electronic device, and a storage medium for data processing. Background Art
[0002] In order to efficiently implement the training of a neural network model, code for implementing the neural network model can be written using a deep learning framework, and the code of the neural network model can be run through the framework. Among them, the deep learning framework generally needs to first compile the neural network model into a static computational graph, and the model training for multiple training data can be realized by executing the computational graph multiple times.
[0003] During the process of compiling the computational graph, the tensor shapes corresponding to the model input or output are usually fixed, and in order to ensure the smooth progress of model training, the same shapes must be used during the execution of the computational graph.
[0004] However, in the case where the size of the training data input during the execution stage does not match that during the compilation stage, it will lead to a problem of execution error. Summary of the Invention
[0005] The embodiments of the present disclosure at least provide a method, an apparatus, an electronic device, and a storage medium for data processing, which take into account the execution operations for different training data sizes and improve the training efficiency and accuracy.
[0006] In a first aspect, the embodiments of the present disclosure provide a method for data processing, and the method includes:
[0007] Obtain a computational graph compiled based on the training code of a target neural network; wherein, the computational graph includes a shape operation relationship and a data operation relationship, and the shape operation relationship and the data operation relationship are respectively shape calculation rules and data calculation rules corresponding to each network layer in the target neural network represented in a data form;
[0008] In response to an execution instruction for the computational graph, based on the training data to be trained and the shape operation relationship and the data operation relationship included in the computational graph, execute to obtain an execution result for the training code of the target neural network.
[0009] By using the above data processing method, a computation graph compiled based on the training code of the target neural network can be obtained first. In this way, in response to an execution instruction for the computation graph, the execution result for the training code of the target neural network can be obtained based on the shape operation relationship and data operation relationship included in the computation graph. In the compilation stage of the present disclosure, the shape calculation rules and data calculation rules of each network layer of the target neural network are determined using the shape operation relationship and data operation relationship, without limiting the specific data size. This enables the execution stage to be compatible with input training data of various sizes, and the determined execution result is not prone to errors and has a high accuracy, thereby further ensuring the efficient progress of network training.
[0010] In a possible implementation manner, obtaining the execution result for the training code of the target neural network based on the training data to be trained and the shape operation relationship and data operation relationship included in the computation graph includes:
[0011] Determining the shape results output by each network layer of the target neural network based on the training data to be trained and the shape operation relationship included in the computation graph;
[0012] Obtaining the allocated memory space based on the shape results output by each network layer of the target neural network;
[0013] Executing the data operation relationship using the allocated memory space to obtain the execution result.
[0014] Here, the determination of the shape operation relationship can be carried out first. In the case of determining the shape results output by each network layer of the target neural network, the memory space can be pre-allocated for the subsequent data operation relationship, thereby improving the execution efficiency of the code.
[0015] In a possible implementation manner, determining the shape results output by each network layer of the target neural network based on the training data to be trained and the shape operation relationship included in the computation graph includes:
[0016] Taking the data size of the training data to be trained as the input data of the shape operation relationship included in the computation graph;
[0017] Determining the shape results output by each network layer of the target neural network based on the input data, the network sizes corresponding to each network layer of the target neural network, and the shape calculation rules corresponding to each network layer in the target neural network.
[0018] In a possible implementation, determining the shape results of the output of each network layer of the target neural network based on the input data, the network sizes corresponding to each network layer of the target neural network, and the shape calculation rules corresponding to each network layer in the target neural network includes:
[0019] Based on the input data, the network size corresponding to the first network layer of the target neural network, and the shape calculation rules, determining the shape result of the output of the first network layer of the target neural network;
[0020] For each network layer except the first network layer, determining the shape result of the output of this network layer according to the following steps;
[0021] Based on the shape result of the output of the previous network layer of the target neural network, the network size corresponding to the previous network layer of the target neural network, and the shape calculation rules, determining the shape result of the output of the current network layer of the target neural network;
[0022] Looping in this way until the shape result of the output of the last network layer of the target neural network is obtained.
[0023] Here, shape operations can be performed layer by layer on the target neural network, that is, first, the shape result of the output of the first network layer can be determined, and then the second, third, etc. can be calculated layer by layer until the shape result of the output of the last network layer. Since the shape calculation rules executed in the process of each network layer are the same, this will make the entire calculation process faster.
[0024] In a possible implementation, determining the shape results of the output of each network layer of the target neural network based on the input data, the network sizes corresponding to each network layer of the target neural network, and the shape calculation rules corresponding to each network layer in the target neural network includes:
[0025] Merging the shape calculation rules corresponding to each network layer in the target neural network to obtain the shape calculation rules for the target neural network;
[0026] Based on the input data, the network size corresponding to the last network layer of the target neural network, and the shape calculation rules for the target neural network, determining the shape result of the output of the target neural network.
[0027] Here, an operation of merging the shape calculation rules corresponding to each network layer can be performed, thereby reducing the complexity of shape calculation and improving the execution efficiency.
[0028] In a possible implementation, using the allocated memory space to execute the data operation relationship to obtain the execution result includes:
[0029] Use the data values of the training data to be trained and the network parameter values generated by each network layer of the target neural network during the compilation process as input data;
[0030] Utilize the allocated memory space to perform an operation process on the input data based on the data calculation rule to obtain the execution result.
[0031] Here, during the process of data operation relationships, the data values of the training data to be trained and the network parameter values generated by each network layer of the target neural network during the compilation process are required as input data. Then, based on the data calculation rule, the execution result can be determined, and the determined execution result can guide the next round of network training, thus ensuring the smooth progress of the training.
[0032] In a possible implementation manner, the operation of determining the shape results of the outputs of each network layer of the target neural network runs on a first platform, and the operation of performing the data operation relationship by using the allocated memory space runs on a second platform;
[0033] Wherein, the first platform and the second platform belong to heterogeneous platforms.
[0034] Here, since the shape operation and the data operation may involve different operation methods, the setting of heterogeneous platforms can ensure the efficient execution of the two operations.
[0035] In a possible implementation manner, the shape operation relationship and the data operation relationship are executed in the following manner:
[0036] After the shape operation relationships corresponding to each network layer of the target neural network are completed on the first platform, then the data operation relationships corresponding to each network layer of the target neural network are executed on the second platform;
[0037] When the shape operation relationship corresponding to the current network layer of the target neural network is completed on the first platform and the data operation relationship corresponding to the current network layer of the target neural network is executed on the second platform, the shape operation relationship corresponding to the next network layer of the target neural network is executed in parallel on the first platform.
[0038] In a possible implementation manner, after determining the shape results of the outputs of each network layer of the target neural network, the method further includes:
[0039] Verify whether the shape results of the outputs of each network layer of the target neural network conform to the preset shape results;
[0040] In the case where a preset shape result is verified, perform the step of obtaining the allocated memory space based on the shape results output by each network layer of the target neural network.
[0041] Here, the shape results output by each network layer can be verified to improve the accuracy of subsequent execution results.
[0042] In a second aspect, an embodiment of the present disclosure further provides a data processing apparatus, where the apparatus includes:
[0043] An acquisition module, configured to acquire a computation graph compiled based on target neural network training code; wherein, the computation graph includes shape operation relationships and data operation relationships, and the shape operation relationships and data operation relationships are respectively shape calculation rules and data calculation rules corresponding to each network layer in the target neural network represented in data form;
[0044] An execution module, configured to, in response to an execution instruction for the computation graph, execute an execution result for the target neural network training code based on training data to be trained and the shape operation relationships and data operation relationships included in the computation graph.
[0045] In a third aspect, an embodiment of the present disclosure further provides an electronic device, including: a processor, a memory, and a bus, where the memory stores machine-readable instructions executable by the processor. When the electronic device runs, the processor communicates with the memory through the bus, and when the machine-readable instructions are executed by the processor, the steps of the data processing method according to any one of the first aspect and its various embodiments are executed.
[0046] In a fourth aspect, an embodiment of the present disclosure further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is run by a processor, the steps of the data processing method according to any one of the first aspect and its various embodiments are executed.
[0047] For the effect descriptions of the above data processing apparatus, electronic device, and computer-readable storage medium, refer to the descriptions of the above data processing method, which will not be elaborated here.
[0048] To make the above objects, features, and advantages of the present disclosure more obvious and understandable, the following specifically enumerates preferred embodiments and, in conjunction with the accompanying drawings, makes the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS
[0049] To more clearly illustrate the technical solutions of the embodiments of the present disclosure, the following will briefly introduce the accompanying drawings required for the embodiments. The accompanying drawings herein are incorporated into the specification and form a part of this specification. These drawings show the embodiments consistent with the present disclosure and, together with the specification, are used to illustrate the technical solutions of the present disclosure. It should be understood that the following drawings only show some embodiments of the present disclosure and should not be regarded as limiting the scope. For those of ordinary skill in the art, other related drawings can be obtained based on these drawings without creative efforts.
[0050] Figure 1 The flowchart of a data processing method provided by an embodiment of the present disclosure is shown;
[0051] Figure 2 The application schematic diagram of a data processing method provided by an embodiment of the present disclosure is shown;
[0052] Figure 3 The schematic diagram of a data processing device provided by an embodiment of the present disclosure is shown;
[0053] Figure 4 The schematic diagram of an electronic device provided by an embodiment of the present disclosure is shown. Detailed implementation manners
[0054] To make the objectives, technical solutions, and advantages of the embodiments of the present disclosure clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present disclosure with reference to the accompanying drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only some, rather than all, of the embodiments of the present disclosure. Usually, the components of the embodiments of the present disclosure described and shown in the accompanying drawings herein can be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed present disclosure, but merely represents the selected embodiments of the present disclosure. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present disclosure without creative efforts fall within the scope of protection of the present disclosure.
[0055] It should be noted that similar reference numerals and letters denote similar items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.
[0056] As used herein, the term "and / or" merely describes an associated relationship and indicates that there can be three relationships. For example, A and / or B can represent three cases: A exists alone, both A and B exist simultaneously, and B exists alone. Additionally, the term "at least one" as used herein means any one of a plurality or any combination of at least two of a plurality. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.
[0057] It has been found through research that during the process of compiling a computational graph, the tensor shapes corresponding to the model inputs or outputs are usually fixed. In order to ensure the smooth progress of model training, the same shapes must be used during the execution of the computational graph.
[0058] However, in the case where the size of the training data input during the execution phase does not match the compilation phase, it will lead to problems with incorrect execution.
[0059] One possible reason for these computational graphs to require fixed shapes is that it is necessary to know the size of the tensors in advance for global allocation of memory and other resources, or to perform related optimizations using the shape information.
[0060] Thus, in the case where the sizes of the training data are different, this requires unifying the data into a single size first. Means of unification include cropping and padding, etc., and these means limit the design of the model algorithm.
[0061] Currently, a possible improvement method is that when generating a computational graph, use several predefined input sizes to generate corresponding computational graphs and form a set of computational graphs. In this way, when actually computing, crop or pad the input size to the closest predefined size. The disadvantage of this method is that it is necessary to compile and store multiple computational graphs, and still make minor changes to the input data.
[0062] Based on the above research, the present disclosure provides a method, apparatus, electronic device, and storage medium for data processing in network code execution based on a computational graph including shape operation relationships and data operation relationships, taking into account execution operations for different training data sizes and improving the efficiency and accuracy of training.
[0063] To facilitate the understanding of this embodiment, a method for data processing disclosed in this embodiment of the present disclosure will be introduced in detail first. The execution subject of the data processing method provided in this embodiment of the present disclosure is generally an electronic device with certain computing capabilities. Such an electronic device may include, for example: a terminal device, a server, or other processing devices. The terminal device may be a user equipment (UE), a mobile device, a user terminal, a terminal, a cellular phone, a cordless phone, a personal digital assistant (PDA), a handheld device, a computing device, a vehicle-mounted device, a wearable device, etc. In some possible implementation manners, the data processing method may be implemented by a processor invoking computer-readable instructions stored in a memory.
[0064] See Figure 1 As shown in the figure, it is a flowchart of the data processing method provided in this embodiment of the present disclosure. The method includes steps S101 to S102, where:
[0065] S101: Obtain a computation graph compiled based on the training code of the target neural network; where the computation graph includes shape operation relationships and data operation relationships. The shape representation information and data operation relationships are respectively the shape calculation rules and data calculation rules corresponding to each network layer in the target neural network represented in data form;
[0066] S102: In response to an execution instruction for the computation graph, based on the training data to be trained and the shape operation relationships and data operation relationships included in the computation graph, execute to obtain an execution result for the training code of the target neural network.
[0067] To facilitate the understanding of the data processing method provided in this embodiment of the present disclosure, the application scenario of this method will be briefly described first. The data processing method in this embodiment of the present disclosure can be mainly applied to any scenario with network training requirements. For example, it can be applied to the training of a vehicle detection network in an unmanned driving scenario, and can also be applied to the training of a pedestrian detection network in a road monitoring scenario, etc.
[0068] In order to efficiently execute the training of a neural network, in the related art, the neural network can be first compiled into a static computation graph, and the network training for multiple training data can be realized by executing the computation graph multiple times. However, since the tensor shapes corresponding to the model input or output are usually fixed during the compilation of the computation graph currently, once the size of the training data input during the execution stage does not match that in the compilation stage, it will cause a problem of execution error.
[0069] To solve the above problems, the embodiments of the present disclosure provide a method, an apparatus, an electronic device, and a storage medium for data processing, so as to take into account execution operations for different sizes of training data and improve the training efficiency and accuracy.
[0070] For different application scenarios, the target neural network here is different, and the corresponding target neural network training code is also different. Taking the field of autonomous driving applications as an example, the target neural network here can be a target detection neural network for detecting surrounding vehicles or pedestrians, and the corresponding target neural network training code indicates the relevant source code for training the target detection neural network.
[0071] To take into account training data of different sizes, the embodiments of the present disclosure can consider from two dimensions during the process of computational graph compilation and its execution.
[0072] One of them is the shape operation relationship. The shape operation relationship is the shape calculation rule corresponding to each network layer in the target neural network represented in the form of data. The shape calculation rule here can include the sequence relationship of shape calculations, the specific calculation rules adopted, etc. In this way, even if training data of a different size from the compilation stage is used during the subsequent execution stage of the computational graph, it can still be taken into account. Once the shape of the input training data is determined, based on the above shape calculation rules, the shape results of the subsequent network layers are also determined.
[0073] The other is the data operation relationship. The data operation relationship is the data calculation rule corresponding to each network layer in the target neural network represented in the form of data. The data calculation rule here can include the sequence relationship of data calculations, the specific calculation rules adopted, etc. In this way, even if training data of a different size from the compilation stage is used during the subsequent execution stage of the computational graph, it can still be taken into account.
[0074] The execution of the computational graph in the embodiments of the present disclosure can be obtained based on the response to the execution instruction. That is, based on the training data to be trained and the shape operation relationship and data operation relationship included in the computational graph, the execution result of the target neural network training code can be obtained. The training data to be trained can be a large number of vehicle pictures collected in the autonomous driving scenario, or a large number of pedestrian pictures collected in the road monitoring scenario, etc.
[0075] Among them, the above-mentioned execution instruction can be triggered when the user has a network training requirement, or can be an automatically generated relevant instruction after successful compilation. For example, the following instruction to load a specified path and execute the function in the included module: $erl - noshell - pa path - s module fun.
[0076] In addition, in each case where a computation graph is executed in an embodiment of the present disclosure, there may be a corresponding execution result, which may be determined based on corresponding shape calculation rules and data calculation rules when training data is input into the shape operation relationship and the data operation relationship. That is to say, the execution of the network code can be understood as a process of network training. In each training process, an output result can be determined, and then the relevant network parameters determined in the compilation stage can be adjusted. By adjusting the network parameters, the network parameter values of the trained target neural network can be obtained.
[0077] In specific applications, the above-mentioned compilation of the computation graph may be implemented based on a deep learning framework. For example, using the TensorFlow deep learning framework to construct network training code into a TFGraph, and TensorRT compiles the target neural network training code into a computation graph. Here, the computation graph used to represent the deep learning network may be composed of shape operations and data operations. Specific operation operations may include convolution, matrix multiplication, etc.
[0078] The data processing method provided by the embodiments of the present disclosure can execute the target neural network training code according to the following steps:
[0079] Step 1: Based on the training data to be trained and the shape operation relationship included in the computation graph, determine the shape results output by each network layer of the target neural network;
[0080] Step 2: Based on the shape results output by each network layer of the target neural network, obtain the allocated memory space;
[0081] Step 3: Use the allocated memory space to execute the data operation relationship to obtain an execution result.
[0082] Here, the shape operation can be executed first to obtain the shape result, and the memory space can be allocated according to the shape result, and then the mathematical operation can be executed using the allocated memory. This is mainly because the shape operation corresponds to the calculation between data shapes. For example, it can be a matrix multiplication operation between the input shape and the shape corresponding to the network layer, while the data operation corresponds to the operation between data values. For example, it can be a matrix multiplication operation between the input data value and the network parameter value corresponding to the network layer. After the memory space is determined in the former, the memory space can be pre-allocated, which makes the subsequent data operation more efficient.
[0083] In order to better execute the above-mentioned shape operation relationship and data operation relationship, it is necessary to briefly explain these two relationships (i.e., the shape operation relationship and the data operation relationship) abstracted during the compilation process.
[0084] Here, before abstractly representing two relationships, the any symbol can be introduced to represent variable dimensions. For example, (any, 4) represents a two-dimensional tensor where the first dimension is variable. (any, any) means both dimensions can vary. Note that the total number of dimensions can still be fixed at this time. In most deep learning algorithms, the tensor dimensions are invariants.
[0085] Based on the above representations of variable dimensions, the computational operations of a network can be corresponded to a data calculation and a shape calculation. For example, for matrix multiplication C[n, l] = A[n, m] x B[m, l], its mathematical definition can imply the shape result. Here, it can be abstracted into a shape calculation function matmul_shape, which corresponds to the shape calculation rule. Similarly, it can also be abstracted into a data calculation function matmul_calc, which corresponds to the data calculation rule. In this way, a matrix multiplication corresponds to a matmul_shape and a matmul_calc on the computational graph.
[0086] To facilitate the understanding of computational graphs, an example of a specific computational graph can be referred to Figure 2 for illustration.
[0087] As Figure 2 shown, when the shape of the tensor in the input layer corresponds to (4, 3,?,?), through Convolution shape (corresponding to the first shape operation) and Convolution calc (corresponding to the first data operation), it can be determined that the shape of the output tensor corresponds to (4, 32,?,?).
[0088] Then, as the input to the next layer, through Add shape (corresponding to the second shape operation) and Add calc (corresponding to the second data operation), it can be determined that the shape of the output tensor corresponds to (4, 32,?,?).
[0089] Among them, "?" represents a variable dimension (such as a variable one-dimensional dimension), indicating that during the process of generating the computational graph, the dimension value of the corresponding dimension is not specifically limited, and during the subsequent process of executing the computational graph, the dimension value corresponding to the shape is determined. To a certain extent, this enables the method provided by the embodiments of the present disclosure to be well compatible with input data of various shapes and avoid execution errors.
[0090] Based on the above description, next, the embodiments of the present disclosure can respectively elaborate on the execution processes of the shape operation relationship and the data operation relationship from two aspects.
[0091] First aspect: The embodiments of the present disclosure can perform shape operation relationships according to the following steps:
[0092] Step 1: Use the data size of the training data to be trained as the input data for the shape operation relationship included in the computational graph.
[0093] Step 2: Based on the input data, the network sizes corresponding to each network layer of the target neural network, and the shape calculation rules corresponding to each network layer in the target neural network, determine the shape results output by each network layer of the target neural network.
[0094] Here, the data size of the training data can be used as the input data for the shape operation relationship first. In this way, based on the input data, the network sizes corresponding to each network layer of the target neural network, and the shape calculation rules corresponding to each network layer in the target neural network, the shape results output by each network layer of the target neural network can be determined.
[0095] In the embodiments of the present disclosure, the shape results output by each network layer of the target neural network can be determined layer by layer. That is, here, the shape result output by the first network layer can be determined first, and then, based on this output result, the shape results output by the second network layer, the third network layer, and so on until the last network layer can be determined in turn.
[0096] Among them, the shape result output by the first network layer can be determined by substituting the input data and the network size corresponding to the first network layer of the target neural network into the shape calculation rules. Taking matrix multiplication operation as an example of the shape calculation rules, here, when it is determined that the input data is A[5,4] and the network size corresponding to the first network layer is B[4,1], the output shape result can be determined as C[5,1].
[0097] In addition, for other network layers, here, the shape result output by the previous network layer of the target neural network and the network size corresponding to the previous network layer of the target neural network can be substituted into the shape calculation rules to determine the shape result output by the current network layer of the target neural network.
[0098] The specific shape calculation rules are similar to the relevant description content of the first network layer above and will not be elaborated here.
[0099] When the shape result output by the last network layer is determined, the loss function value of the target neural network to be trained can be determined based on this shape result. Based on this loss function value, the target neural network to be trained can be adjusted. By executing the computational graph again, the adjusted target neural network can be trained again until the network converges to obtain the trained target neural network.
[0100] Considering that shape calculation can be a series of scalar calculations with composability, multiple shape calculations can be combined into one. That is, the embodiments of the present disclosure can combine the shape calculation rules corresponding to each network layer in the target neural network to obtain the shape calculation rules for the target neural network. For example, several consecutive reshape operations are shape-calculation equivalent to a single reshape_shape. Several consecutive matrix multiplications are shape-calculation equivalent to a single matmul_shape. The complexity of shape calculation can be reduced through the combination operation, improving the execution efficiency.
[0101] Second aspect: The embodiments of the present disclosure can execute the data operation relationship according to the following steps:
[0102] Step 1: Use the data values of the training data to be trained and the network parameter values generated by each network layer of the target neural network during the compilation process as input data;
[0103] Step 2: Use the allocated memory space to perform an operation process on the input data based on the data calculation rules to obtain an execution result.
[0104] Here, the data values of the training data and the network parameter values generated by each network layer of the target neural network during the compilation process can be used as input data. By performing an operation process on the input data through the data calculation rules, an execution result can be obtained.
[0105] In contrast to the shape operation which corresponds to operations related to data shapes, the data operation here corresponds to operations related to specific data values. For example, it can be a matrix operation between the data values of a 5×4-dimensional training data and a 4×1-dimensional network parameter value to obtain a 5×1-dimensional execution result. Similar to the shape operation, the data operation here can also be determined layer by layer, and the determination process will not be elaborated here.
[0106] To better adapt to operation operations between different data types, the execution operation related to the shape operation relationship can be run on the first platform, and the execution operation related to the data operation relationship can be run on the second platform. The two platforms are heterogeneous platforms.
[0107] In specific applications, data calculations are usually tensors and can be executed on specific acceleration devices, while shape calculations are usually scalars and can be executed on a central processing unit (CPU).
[0108] In the embodiments of the present disclosure, it may be that after the shape operation relationships corresponding to each network layer of the target neural network are executed on the first platform, the data operation relationships corresponding to each network layer of the target neural network are then executed on the second platform. It may also be that after the shape operation relationship corresponding to the current network layer of the target neural network is executed on the first platform and the data operation relationship corresponding to the current network layer of the target neural network is executed on the second platform, the shape operation relationship corresponding to the next network layer of the target neural network is executed in parallel on the first platform. That is, the data calculation of the previous operation and the shape calculation of the next operation can be executed in parallel, which will further improve the execution efficiency.
[0109] Here, in order to ensure the accuracy of the execution result, it can be verified whether the shape results output by each network layer of the target neural network conform to the preset shape results. Only when it is verified that they conform to the preset shape results, the step of obtaining the allocated memory space based on the shape results output by each network layer of the target neural network is executed, thereby ensuring the accuracy of the subsequent execution results.
[0110] The preset shape results can be pre-determined. Once the shape and size of the input training data are determined, the shape results output by the corresponding network layers are also determined. In this way, when the actually output shape results do not conform to the preset shape results, it indicates that there is a problem in performing the shape calculation, and the data operation can be stopped. Compared with directly performing the data operation, while ensuring the accuracy of the execution result, it also avoids wasting computing resources.
[0111] Those skilled in the art can understand that in the above method of the specific embodiment, the writing order of each step does not mean a strict execution order that constitutes any limitation to the implementation process. The specific execution order of each step should be determined according to its function and possible internal logic.
[0112] Based on the same inventive concept, in the embodiments of the present disclosure, there is also provided a data processing device corresponding to the data processing method. Since the principle of solving problems by the device in the embodiments of the present disclosure is similar to the above data processing method in the embodiments of the present disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.
[0113] Referring to Figure 3 As shown, it is a schematic diagram of a data processing device provided by an embodiment of the present disclosure. The device includes: an acquisition module 301 and an execution module 302; wherein,
[0114] The acquisition module 301 is configured to acquire a computation graph compiled based on the training code of the target neural network; wherein, the computation graph includes shape operation relationships and data operation relationships, and the shape representation information and the data operation relationships are respectively the shape calculation rules and data calculation rules corresponding to each network layer in the target neural network represented in data form;
[0115] An execution module 302, configured to, in response to an execution instruction for a computation graph, execute to obtain an execution result for a target neural network training code based on training data to be trained and shape operation relationships and data operation relationships included in the computation graph.
[0116] With the apparatus for data processing described above, a computation graph compiled based on a target neural network training code can be obtained first. In this way, in response to an execution instruction for the computation graph, an execution result for the target neural network training code can be executed based on the shape operation relationships and data operation relationships included in the computation graph. In the compilation stage of the present disclosure, shape operation relationships and data operation relationships are used to determine shape calculation rules and data calculation rules for each network layer of the target neural network, without limiting the specific data size. This enables the execution stage to be compatible with input training data of various sizes, and the determined execution result is not easily incorrect and has a high accuracy, thereby further ensuring the efficient progress of network training.
[0117] In a possible implementation manner, the execution module 302 is configured to execute to obtain an execution result for a target neural network training code based on training data to be trained and shape operation relationships and data operation relationships included in the computation graph according to the following steps:
[0118] Based on training data to be trained and shape operation relationships included in the computation graph, determine shape results output by each network layer of the target neural network;
[0119] Based on the shape results output by each network layer of the target neural network, obtain allocated memory spaces;
[0120] Use the allocated memory spaces to execute data operation relationships to obtain an execution result.
[0121] In a possible implementation manner, the execution module 302 is configured to determine shape results output by each network layer of the target neural network according to the following steps based on training data to be trained and shape operation relationships included in the computation graph:
[0122] Use the data size of the training data to be trained as input data for the shape operation relationships included in the computation graph;
[0123] Based on the input data, network sizes corresponding to each network layer of the target neural network, and shape calculation rules corresponding to each network layer in the target neural network, determine shape results output by each network layer of the target neural network.
[0124] In a possible implementation, the execution module 302 is configured to determine the shape results output by each network layer of the target neural network according to the following steps based on the input data, the network sizes corresponding to each network layer of the target neural network, and the shape calculation rules corresponding to each network layer in the target neural network:
[0125] Based on the input data, the network size corresponding to the first network layer of the target neural network, and the shape calculation rules, determine the shape result output by the first network layer of the target neural network;
[0126] For each network layer except the first network layer, determine the shape result output by this network layer according to the following steps;
[0127] Based on the shape result output by the previous network layer of the target neural network, the network size corresponding to the previous network layer of the target neural network, and the shape calculation rules, determine the shape result output by the current network layer of the target neural network;
[0128] Repeat this loop until the shape result output by the last network layer of the target neural network is obtained.
[0129] In a possible implementation, the execution module 302 is configured to determine the shape results output by each network layer of the target neural network according to the following steps based on the input data, the network sizes corresponding to each network layer of the target neural network, and the shape calculation rules corresponding to each network layer in the target neural network:
[0130] Merge the shape calculation rules corresponding to each network layer in the target neural network to obtain the shape calculation rules for the target neural network;
[0131] Based on the input data, the network size corresponding to the last network layer of the target neural network, and the shape calculation rules for the target neural network, determine the shape result output by the target neural network.
[0132] In a possible implementation, the execution module 302 is configured to perform data operation relationships using the allocated memory space according to the following steps to obtain an execution result:
[0133] Use the data values of the training data to be trained and the network parameter values generated by each network layer of the target neural network during compilation as input data;
[0134] Use the allocated memory space to perform an operation process on the input data based on the data calculation rules to obtain an execution result.
[0135] In a possible implementation, the operation of determining the shape results output by each network layer of the target neural network runs on the first platform, and the operation of performing data operation relationships using the allocated memory space runs on the second platform;
[0136] Among them, the first platform and the second platform are heterogeneous platforms.
[0137] In a possible implementation manner, the shape operation relationship and the data operation relationship are executed in the following manner:
[0138] After the shape operation relationship corresponding to each network layer of the target neural network is completed on the first platform, the data operation relationship corresponding to each network layer of the target neural network is then executed on the second platform;
[0139] When the shape operation relationship corresponding to the current network layer of the target neural network is completed on the first platform, and the data operation relationship corresponding to the current network layer of the target neural network is executed on the second platform, the shape operation relationship corresponding to the next network layer of the target neural network is executed in parallel on the first platform.
[0140] In a possible implementation manner, the execution module 302 is further configured to:
[0141] After determining the shape results output by each network layer of the target neural network, verify whether the shape results output by each network layer of the target neural network conform to the preset shape results; in the case of verifying that they conform to the preset shape results, execute the step of obtaining the allocated memory space based on the shape results output by each network layer of the target neural network.
[0142] For the description of the processing flow of each module in the device and the interaction flow between each module, reference can be made to the relevant descriptions in the above method embodiments, which will not be elaborated here.
[0143] This disclosure embodiment also provides an electronic device, as Figure 4 shown, which is a schematic structural diagram of the electronic device provided by this disclosure embodiment, including: a processor 401, a memory 402, and a bus 403. The memory 402 stores machine-readable instructions executable by the processor 401 (for example, Figure 3 the execution instructions corresponding to the acquisition module 301 and the execution module 302 in the device), when the electronic device runs, the processor 401 communicates with the memory 402 through the bus 403, and when the machine-readable instructions are executed by the processor 401, the following processing is performed:
[0144] Obtain a computational graph compiled based on the training code of the target neural network; wherein, the computational graph includes a shape operation relationship and a data operation relationship, and the shape representation information and the data operation relationship are respectively the shape calculation rules and data calculation rules corresponding to each network layer in the target neural network represented in data form;
[0145] In response to an execution instruction for a computation graph, based on training data to be trained and the shape operation relationship and data operation relationship included in the computation graph, an execution result for the training code of the target neural network is obtained through execution.
[0146] An embodiment of the present disclosure also provides a computer-readable storage medium, on which a computer program is stored. When the computer program is run by a processor, it executes the steps of the data processing method described in the foregoing method embodiment. Wherein, the storage medium may be a volatile or non-volatile computer-readable storage medium.
[0147] An embodiment of the present disclosure also provides a computer program product, which carries program code. The instructions included in the program code can be used to execute the steps of the data processing method described in the foregoing method embodiment. For details, reference can be made to the foregoing method embodiment, which will not be elaborated herein.
[0148] Among them, the above computer program product can be specifically implemented in a manner of hardware, software, or a combination thereof. In an optional embodiment, the computer program product is specifically embodied as a computer storage medium. In another optional embodiment, the computer program product is specifically embodied as a software product, such as a Software Development Kit (SDK), etc.
[0149] Those skilled in the art can clearly understand that for the convenience and conciseness of description, the specific working processes of the systems and devices described above can refer to the corresponding processes in the foregoing method embodiments, which will not be elaborated herein. In several embodiments provided by the present disclosure, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of the units is only a logical function division, and there may be other division methods in actual implementation. Also, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed couplings or direct couplings or communication connections to each other can be through some communication interfaces. The indirect couplings or communication connections of the devices or units can be in an electrical, mechanical, or other forms.
[0150] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they can be located in one place, or distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0151] In addition, in each embodiment of the present disclosure, each functional unit may be integrated into a processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit.
[0152] If the above-mentioned functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such an understanding, the technical solution of the present disclosure, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing an electronic device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in each embodiment of the present disclosure. The aforementioned storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs that can store program codes.
[0153] Finally, it should be noted that the above-mentioned embodiments are only specific implementation manners of the present disclosure, used to illustrate the technical solutions of the present disclosure, rather than limiting them. The protection scope of the present disclosure is not limited thereto. Although the present disclosure has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that: any person skilled in the art within the technical scope disclosed by the present disclosure can still modify the technical solutions recorded in the foregoing embodiments, or can easily think of changes, or perform equivalent replacements on some of the technical features; and these modifications, changes, or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present disclosure, and should all be covered by the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be subject to the protection scope of the claims.
Claims
1. A method for data processing, characterized in that, The method includes: Obtaining a computation graph compiled based on the training code of a target neural network; wherein, the computation graph includes shape operation relationships and data operation relationships, and the shape operation relationships and data operation relationships are respectively the shape calculation rules and data calculation rules corresponding to each network layer in the target neural network represented in data form; In response to an execution instruction for the computation graph, taking the data size of the training data to be trained as the input data of the shape operation relationships included in the computation graph; Merging the shape calculation rules corresponding to each network layer in the target neural network to obtain the shape calculation rules for the target neural network; Based on the input data, the network size corresponding to the last network layer of the target neural network, and the shape calculation rules for the target neural network, determining the shape result output by the target neural network; Based on the shape results output by each network layer of the target neural network, obtaining the allocated memory space; Using the allocated memory space to execute the data operation relationships to obtain the execution result of the training code of the target neural network.
2. The method according to claim 1, characterized in that The determining the shape results output by each network layer of the target neural network based on the input data, the network sizes corresponding to each network layer of the target neural network, and the shape calculation rules corresponding to each network layer in the target neural network includes: Based on the input data, the network size corresponding to the first network layer of the target neural network, and the shape calculation rules, determining the shape result output by the first network layer of the target neural network; For each network layer except the first network layer, determining the shape result output by this network layer according to the following steps: Based on the shape result output by the previous network layer of the target neural network, the network size corresponding to the previous network layer of the target neural network, and the shape calculation rules, determining the shape result output by the current network layer of the target neural network; Looping in this way until the shape result output by the last network layer of the target neural network is obtained.
3. The method according to claim 1 or 2, characterized in that, The using the allocated memory space to execute the data operation relationships to obtain the execution result includes: Taking the data values of the training data to be trained and the network parameter values generated during the compilation of each network layer of the target neural network as input data; Using the allocated memory space to perform an operation process on the input data based on the data calculation rules to obtain the execution result.
4. The method according to any one of claims 1 to 3, characterized in that The operation of determining the shape results output by each network layer of the target neural network runs on a first platform, and the operation of using the allocated memory space to execute the data operation relationships runs on a second platform; Wherein, the first platform and the second platform are heterogeneous platforms.
5. The method according to claim 4, wherein Execute the shape operation relationships and the data operation relationships in the following way: After the shape operation relationships corresponding to each network layer of the target neural network are completed on the first platform, then execute the data operation relationships corresponding to each network layer of the target neural network on the second platform; When the shape operation relationship corresponding to the current network layer of the target neural network is completed on the first platform and the data operation relationship corresponding to the current network layer of the target neural network is executed on the second platform, the shape operation relationship corresponding to the next network layer of the target neural network is executed in parallel on the first platform.
6. The method according to any one of claims 1 to 5, characterized in that After determining the shape results output by each network layer of the target neural network, the method further includes: verifying whether the shape results output by each network layer of the target neural network conform to the preset shape results; when it is verified that the results conform to the preset shape results, performing the step of obtaining the allocated memory space based on the shape results output by each network layer of the target neural network.
7. A data processing device, characterized in that, The apparatus includes: an acquisition module, configured to acquire a computation graph compiled based on the training code of the target neural network; wherein, the computation graph includes a shape operation relationship and a data operation relationship, and the shape operation relationship and the data operation relationship are respectively the shape calculation rules and data calculation rules corresponding to each network layer in the target neural network represented in data form; an execution module, configured to, in response to an execution instruction for the computation graph, use the data size of the training data to be trained as the input data of the shape operation relationship included in the computation graph; merge the shape calculation rules corresponding to each network layer in the target neural network to obtain the shape calculation rules for the target neural network; determine the shape result output by the target neural network based on the input data, the network size corresponding to the last network layer of the target neural network, and the shape calculation rules for the target neural network; obtain the allocated memory space based on the shape results output by each network layer of the target neural network; and use the allocated memory space to execute the data operation relationship to obtain the execution result for the training code of the target neural network.
8. An electronic device, characterized in that, including: a processor, a memory, and a bus, where the memory stores machine-readable instructions executable by the processor. When the electronic device runs, the processor communicates with the memory through the bus. When the machine-readable instructions are executed by the processor, the steps of the data processing method according to any one of claims 1 to 6 are executed.
9. A computer-readable storage medium, characterized in that, A computer program is stored on the computer-readable storage medium. When the computer program is run by a processor, the steps of the data processing method according to any one of claims 1 to 6 are executed.
Citation Information
Patent Citations
Data processing method and data processing equipment
CN113449857A
Data processing method and related product
CN113554157A