CN114004335A - Data processing method and device, electronic equipment and storage medium - Google Patents

Data processing method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114004335A
CN114004335A CN202111266095.8A CN202111266095A CN114004335A CN 114004335 A CN114004335 A CN 114004335A CN 202111266095 A CN202111266095 A CN 202111266095A CN 114004335 A CN114004335 A CN 114004335A
Authority
CN
China
Prior art keywords
shape
target neural
neural network
data
network
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111266095.8A
Other languages
Chinese (zh)
Inventor
李周洋
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Sensetime Technology Development Co Ltd
Original Assignee
Shanghai Sensetime Technology Development Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Sensetime Technology Development Co Ltd filed Critical Shanghai Sensetime Technology Development Co Ltd
Priority to CN202111266095.8A priority Critical patent/CN114004335A/en
Publication of CN114004335A publication Critical patent/CN114004335A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/04Architecture, e.g. interconnection topology
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/15Correlation function computation including computation of convolution operations
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F17/00Digital computing or data processing equipment or methods, specially adapted for specific functions
    • G06F17/10Complex mathematical operations
    • G06F17/16Matrix or vector computation, e.g. matrix-matrix or matrix-vector multiplication, matrix factorization
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/40Transformation of program code
    • G06F8/41Compilation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06NCOMPUTING ARRANGEMENTS BASED ON SPECIFIC COMPUTATIONAL MODELS
    • G06N3/00Computing arrangements based on biological models
    • G06N3/02Neural networks
    • G06N3/08Learning methods

Abstract

The present disclosure provides a data processing method, apparatus, electronic device and storage medium, wherein the method comprises: obtaining a calculation graph obtained by compiling a training code based on a target neural network; the calculation graph comprises a shape operation relation and a data operation relation, wherein the shape operation relation and the data operation relation are respectively a shape calculation rule and a data calculation rule corresponding to each network layer in a target neural network represented by a data form; and responding to an execution instruction for the computation graph, and executing to obtain an execution result for the target neural network training code based on the training data to be trained and the shape operation relation and the data operation relation contained in the computation graph. The method and the device can be compatible with input training data of various sizes in the execution stage, the determined execution result is not easy to make mistakes, the accuracy is high, and efficient network training is further ensured.

Description

Data processing method and device, electronic equipment and storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a data processing method and apparatus, an electronic device, and a storage medium.
Background
In order to efficiently train the neural network model, codes for realizing the neural network model can be written by utilizing a deep learning framework, and the codes for realizing the neural network model can be operated through the framework. The deep learning framework needs to compile a neural network model into a static calculation graph, and model training aiming at a plurality of training data can be realized by executing the calculation graph for a plurality of times.
In the process of compiling the computation graph, the tensor shape corresponding to the model input or output is usually fixed, and in order to ensure smooth model training, the same shape must be used in the process of executing the computation graph.
However, in the case that the size of the training data input in the execution phase does not match the compiling phase, a problem of execution error will be caused.
Disclosure of Invention
The embodiment of the disclosure at least provides a data processing method, a data processing device, an electronic device and a storage medium, which take the execution operations of different training data sizes into consideration and improve the training efficiency and accuracy.
In a first aspect, an embodiment of the present disclosure provides a data processing method, where the method includes:
obtaining a calculation graph obtained by compiling a training code based on a target neural network; the calculation graph comprises a shape operation relation and a data operation relation, wherein the shape operation relation and the data operation relation are respectively a shape calculation rule and a data calculation rule corresponding to each network layer in a target neural network represented by a data form;
and responding to an execution instruction for the computational graph, and executing to obtain an execution result for the target neural network training code based on training data to be trained and the shape operation relation and the data operation relation contained in the computational graph.
With the above data processing method, the computation graph compiled based on the target neural network training code may be obtained first, so that in response to the execution instruction for the computation graph, the execution result for the target neural network training code may be obtained by executing based on the shape operation relationship and the data operation relationship included in the computation graph. According to the method, the shape calculation rules and the data calculation rules of each network layer of the target neural network are determined by utilizing the shape calculation relationship and the data calculation relationship in the compiling stage, and specific data size is not limited, so that the execution stage can be compatible with input training data of various sizes, the determined execution result is not prone to error, the accuracy is high, and efficient network training is further ensured.
In a possible embodiment, the executing, based on the training data to be trained and the shape operational relationship and the data operational relationship included in the computation graph, the executing obtains an execution result for the target neural network training code, and includes:
determining a shape result output by each network layer of the target neural network based on the training data to be trained and the shape operation relation contained in the calculation graph;
acquiring a distributed memory space based on the shape result output by each network layer of the target neural network;
and executing the data operation relation by using the allocated memory space to obtain the execution result.
Here, first, determination regarding the shape operation relationship may be performed, and in the case of determining the shape result output by each network layer of the target neural network, a memory space may be allocated in advance for the subsequent data operation relationship, thereby improving the efficiency of code execution.
In a possible embodiment, the determining, based on the training data to be trained and the shape operation relationship included in the computation graph, a shape result output by each network layer of the target neural network includes:
taking the data size of the training data to be trained as input data of the shape operation relation contained in the calculation graph;
and determining a shape result output by each network layer of the target neural network based on the input data, the network size corresponding to each network layer of the target neural network and the shape calculation rule corresponding to each network layer in the target neural network.
In a possible embodiment, the determining the shape result output by each network layer of the target neural network based on the input data, the network size corresponding to each network layer of the target neural network, and the shape calculation rule corresponding to each network layer in the target neural network includes:
determining a shape result output by the first network layer of the target neural network based on the input data, the network size corresponding to the first network layer of the target neural network and the shape calculation rule;
for each network layer except the first network layer, determining a shape result output by the network layer according to the following steps;
determining a shape result output by the current network layer of the target neural network based on the shape result output by the last network layer of the target neural network, the network size corresponding to the last network layer of the target neural network and the shape calculation rule;
and circulating the steps until a shape result output by the last network layer of the target neural network is obtained.
Here, the shape calculation from network layer to network layer may be performed for the target neural network, that is, the shape result output by the first network layer may be determined first, and then the second, third, and so on may be calculated layer by layer until the shape result output by the last network layer. Since the shape calculation rules executed are the same for each network layer, this will make the overall calculation process faster.
In a possible embodiment, the determining the shape result output by each network layer of the target neural network based on the input data, the network size corresponding to each network layer of the target neural network, and the shape calculation rule corresponding to each network layer in the target neural network includes:
combining the shape calculation rules corresponding to each network layer in the target neural network to obtain the shape calculation rules aiming at the target neural network;
and determining a 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 rule aiming at the target neural network.
Here, the merging operation of the shape calculation rules corresponding to the respective network layers can be performed, thereby reducing the complexity of the shape calculation and improving the execution efficiency.
In a possible implementation manner, the executing the data operation relationship by using the allocated memory space to obtain the execution result includes:
taking the data value of the training data to be trained and the network parameter value generated by each network layer of the target neural network in the compiling process as input data;
and executing an operation process on the input data based on the data calculation rule by using the allocated memory space to obtain the execution result.
In the process of performing the data operation relationship, the data value of the training data to be trained and the network parameter value generated by each network layer of the target neural network in the compiling process are required to be used as input data, then the execution result can be determined based on the data calculation rule, and the determined execution result can guide the next round of network training, so that the smooth performance of the training is ensured.
In a possible implementation manner, the operation of determining the shape result output by each network layer of the target neural network is executed on a first platform, and the operation of executing the data operation relation by using the allocated memory space is executed on a second platform;
wherein the first platform and the second platform belong to heterogeneous platforms.
Here, since the shape operation and the data operation may involve different operation modes, efficient performance of the two operations can be ensured by the heterogeneous platform.
In one possible implementation, the shape operational relationship and the data operational relationship are performed in one of the following ways:
under the condition that the first platform executes the shape operation relation corresponding to each network layer of the target neural network, executing the data operation relation corresponding to each network layer of the target neural network on the second platform;
and under the condition that the first platform executes the shape operation relation corresponding to the current network layer of the target neural network and the second platform executes the data operation relation corresponding to the current network layer of the target neural network, executing the shape operation relation corresponding to the next network layer of the target neural network in parallel on the first platform.
In one possible embodiment, after the determining the shape result output by each network layer of the target neural network, the method further includes:
verifying whether the shape result output by each network layer of the target neural network conforms to a preset shape result;
and under the condition that the preset shape result is verified to be met, executing a step of acquiring the allocated memory space based on the shape result output by each network layer of the target neural network.
Here, the shape result output by each network layer may be verified to improve the accuracy of the subsequent execution result.
In a second aspect, an embodiment of the present disclosure further provides an apparatus for data processing, where the apparatus includes:
the acquisition module is used for acquiring a calculation graph obtained by compiling a training code based on a target neural network; the calculation graph comprises a shape operation relation and a data operation relation, wherein the shape operation relation and the data operation relation are respectively a shape calculation rule and a data calculation rule corresponding to each network layer in a target neural network represented by a data form;
and the execution module is used for responding to an execution instruction aiming at the computational graph, and executing to obtain an execution result aiming at the target neural network training code based on training data to be trained and the shape operation relation and the data operation relation contained in the computational graph.
In a third aspect, an embodiment of the present disclosure further provides an electronic device, including: a processor, a memory and a bus, the memory storing machine-readable instructions executable by the processor, the processor and the memory communicating via the bus when the electronic device is running, the machine-readable instructions when executed by the processor performing the steps of the method of data processing according to the first aspect and any of its various embodiments.
In a fourth aspect, the disclosed embodiments also provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, performs the steps of the method for data processing according to the first aspect and any of its various embodiments.
For the description of the effects of the data processing apparatus, the electronic device, and the computer-readable storage medium, reference is made to the description of the data processing method, which is not repeated herein.
In order to make the aforementioned objects, features and advantages of the present disclosure more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present disclosure, the drawings required for use in the embodiments will be briefly described below, and the drawings herein incorporated in and forming a part of the specification illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the technical solutions of the present disclosure. It is appreciated that the following drawings depict only certain embodiments of the disclosure and are therefore not to be considered limiting of its scope, for those skilled in the art will be able to derive additional related drawings therefrom without the benefit of the inventive faculty.
Fig. 1 shows a flow chart of a method of data processing provided by an embodiment of the present disclosure;
fig. 2 is a schematic application diagram of a data processing method provided by an embodiment of the present disclosure;
FIG. 3 is a schematic diagram of a data processing apparatus provided by an embodiment of the present disclosure;
fig. 4 shows a schematic diagram of an electronic device provided by an embodiment of the present disclosure.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present disclosure more clear, the technical solutions of the embodiments of the present disclosure will be described clearly and completely with reference to the drawings in the embodiments of the present disclosure, and it is obvious that the described embodiments are only a part of the embodiments of the present disclosure, not all of the embodiments. The components of the embodiments of the present disclosure, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present disclosure, presented in the figures, is not intended to limit the scope of the claimed disclosure, but is merely representative of selected embodiments of the disclosure. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the disclosure without making creative efforts, shall fall within the protection scope of the disclosure.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
The term "and/or" herein merely describes an associative relationship, meaning that three relationships may exist, e.g., a and/or B, may mean: a exists alone, A and B exist simultaneously, and B exists alone. In addition, the term "at least one" 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, C, and may mean including any one or more elements selected from the group consisting of A, B and C.
It has been found that, in the process of compiling the computation graph, the tensor shape corresponding to the input or output of the model is usually fixed, and in order to ensure the smooth model training, the same shape must be used in the process of executing the computation graph.
However, in the case that the size of the training data input in the execution phase does not match the compiling phase, a problem of execution error will be caused.
One possible reason for these computation graphs to require a fixed shape is: the tensor size needs to be known in advance for global allocation of memory and other resources, or for relevant optimization using shape information.
Thus, in the case of training data of different sizes, it is required to unify the data into one size first. The unified means includes clipping and filling, and the like, and the means limits the design of the model algorithm.
At present, a possible improvement method is that when generating the computation graph, a plurality of predefined input sizes are used to generate the corresponding computation graph, and the computation graph is combined into a computation graph set. In this way, the input dimensions are trimmed or filled to the nearest predefined dimension when actually calculated. This approach has the disadvantage of requiring multiple computation graphs to be compiled and stored, and also requires subtle changes to the input data.
Based on the above research, the present disclosure provides a method, an apparatus, an electronic device, and a storage medium for performing data processing of network code execution based on a computation graph including a shape operation relationship and a data operation relationship, which consider execution operations of different training data sizes, and improve training efficiency and accuracy.
To facilitate understanding of the present embodiment, first, a data processing method disclosed in the embodiments of the present disclosure is described in detail, where an execution subject of the data processing method provided in the embodiments of the present disclosure is generally an electronic device with certain computing capability, and the electronic device includes, for example: a terminal device, which may be a User Equipment (UE), a mobile device, a User 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, or a server or other processing device. In some possible implementations, the method of data processing may be implemented by a processor calling computer readable instructions stored in a memory.
Referring to fig. 1, which is a flowchart of a method for processing data provided in the embodiment of the present disclosure, the method includes steps S101 to S102, where:
s101: obtaining a calculation graph obtained by compiling a training code based on a target neural network; the calculation graph comprises a shape operation relation and a data operation relation, and the shape representation information and the data operation relation are respectively a shape calculation rule and a data calculation rule corresponding to each network layer in the target neural network represented by a data form;
s102: and responding to an execution instruction for the computation graph, and executing to obtain an execution result for the target neural network training code based on the training data to be trained and the shape operation relation and the data operation relation contained in the computation graph.
In order to facilitate understanding of the method for data processing provided by the embodiments of the present disclosure, first, a brief description is provided below for an application scenario of the method. The data processing method in the embodiment of the disclosure may be mainly applied to any scene with network training requirements, for example, may be applied to training of a vehicle detection network in an unmanned scene, and may also be applied to training of a pedestrian detection network in a road monitoring scene, and the like.
In order to efficiently execute the training of the neural network, in the related art, the neural network may be compiled into a static computational graph, and the network training for a plurality of training data may be realized by executing the computational graph for a plurality of times. However, since the tensor shape corresponding to the input or output of the model is usually fixed in the process of compiling the computation graph at present, once the size of the training data input in the execution stage is not matched with that in the compilation stage, the problem of execution error is caused.
In order to solve the above problem, embodiments of the present disclosure provide a data processing method, an apparatus, an electronic device, and a storage medium, so as to perform operations with different training data sizes, and improve training efficiency and accuracy.
For different application scenarios, the target neural network is also different, and the corresponding target neural network training codes are also different. Taking the field of unmanned application as an example, the target neural network may be a target detection neural network for detecting surrounding vehicles or pedestrians, and the corresponding target neural network training code is used to indicate that the relevant source code related to training the target detection neural network is used.
In order to take account of different sizes of training data, the embodiment of the present disclosure may consider from two dimensions in the process of performing computation graph compilation and execution thereof.
One of the two is a shape operation relationship, which is a shape calculation rule corresponding to each network layer in the target neural network represented by a data form, where the shape calculation rule may include a precedence relationship of shape calculation, a specifically adopted calculation rule, and the like. In this way, even if training data having a size different from that of the compiling stage is used in the execution stage of the computation graph in the following, it is possible to achieve both the shape determination and the shape determination of the shape result output by each network layer in the following based on the shape computation rule once the shape of the input training data is determined.
The other is a data operation relationship, the data operation relationship is a data calculation rule corresponding to each network layer in the target neural network represented by a data form, and the data calculation rule may include a precedence relationship of data calculation, a specifically adopted calculation rule, and the like. Thus, even if training data of a size different from that of the compiling stage is used in the subsequent execution stage for the computation graph, the calculation graph can be compatible.
In the embodiment of the present disclosure, the execution of the computation graph may be obtained based on a response to the execution instruction, that is, based on the training data to be trained and the shape operation relationship and the data operation relationship included in the computation graph, the execution result of the training code for the target neural network may be obtained by executing. The training data to be trained may be a large number of vehicle pictures acquired in an unmanned driving scene, or may be a large number of pedestrian pictures acquired in a road monitoring scene, or the like.
The related execution instruction may be triggered when the user has a network training requirement, or may be a related instruction that is automatically generated after successful compilation, for example, an instruction that specifies a path and executes a function in a module included in the following module by loading: $ erl-nonshell-pa path-s module fun.
In addition, the disclosed embodiments may correspond to one execution result in the case of executing the computation graph once, and the execution result may be determined based on the corresponding shape computation rule and data computation rule in the case of inputting the training data to the shape computation relationship and the data computation relationship. That is, the execution of the related network code may be understood as a network training process, and in each training process, the output result may be determined, and then the related network parameters determined in the compiling stage may be adjusted. By adjusting the network parameters, the trained network parameter values of the target neural network can be obtained.
In a specific application, the above-mentioned related computation graph compilation can be realized based on a deep learning framework. For example, network training code is constructed as TFGraph using the deep learning framework of TensorFlow, and the TensorRT compiles the target neural network training code into a computational graph. Here, the computation graph representing the deep learning network may be composed of a shape operation and a data operation. The specific arithmetic operation may include convolution, matrix multiplication, and the like.
The data processing method provided by the embodiment of the disclosure can execute the target neural network training code according to the following steps:
determining shape results output by each network layer of a target neural network based on training data to be trained and shape operation relations contained in a calculation graph;
secondly, acquiring a distributed memory space based on a shape result output by each network layer of the target neural network;
and thirdly, executing the data operation relation by using the allocated memory space to obtain an execution result.
Here, the shape operation may be performed first to obtain a shape result, and a memory space may be allocated according to the shape result, and then the allocated memory may be used to perform the mathematical operation. This is mainly in view of the fact that the shape-related operation corresponds to a calculation between data shapes, for example, a matrix multiplication operation between an input shape and a shape corresponding to a network layer, and the data-related operation corresponds to an operation between data values, for example, a matrix multiplication operation between an input data value and a network parameter value corresponding to a network layer, and in the case that the former determines a memory space, the memory space can be pre-allocated, which makes the subsequent data operation more efficient.
In order to better implement the above shape operation relationship and data operation relationship, it is necessary to briefly describe the two relationships (i.e., the shape operation relationship and the data operation relationship) abstracted in the compiling process.
Here, before the abstract representation of the two relationships is made, an any notation can be introduced to indicate the dimensions that can be varied. For example, (any,4) represents a two-dimensional tensor, the first of which is variable. (any ) means that both dimensions may vary. Note that the overall dimension may still be fixed at this time. In most deep learning algorithms, the tensor dimension is invariant.
Based on the above-described correlation representation of variable dimensions, a computation operation of a network can be mapped to a data computation and a shape computation. For example, the mathematical definition of the matrix multiplication C [ n, l ] ═ a [ n, m ] x B [ m, l ], may imply the shape result, which may be abstracted separately into a shape computation function matmul _ shape, which corresponds to the shape computation rule, and, similarly, into a data computation function matmul _ calc, which corresponds to the data computation rule. Such a matrix multiplication corresponds to a matmul _ shape and a matmul _ calc on the computation graph.
To facilitate understanding of the computational graph, a specific computational graph may be illustrated with reference to FIG. 2.
As shown in fig. 2, in the case where the Tensor (Tensor) shape correspondence of the input layer is (4,3,.
Then, as the next layer input, by Add shape (corresponding to the second shape operation) and Add calc (corresponding to the second data operation), it can be determined that the output Tensor shape corresponds to (4,32,.
Wherein, "? "represents a variable dimension (e.g., a variable one-dimensional dimension), and indicates that, in the process of generating the computation graph, the dimension value of the corresponding dimension is not specifically limited, and in the process of subsequently executing the computation graph, the dimension value corresponding to the shape is determined, which makes the method provided by the embodiment of the present disclosure well compatible with input data of various shapes, and avoids execution errors.
Based on the above description, the embodiments of the present disclosure can set forth the execution procedures regarding the shape operation relationship and the data operation relationship, respectively, from two aspects.
In a first aspect: the disclosed embodiments may perform the shape operation relationship as follows:
step one, taking the data size of training data to be trained as input data of a shape operation relation contained in a calculation graph;
and secondly, determining a shape result output by each network layer of the target neural network based on the input data, the network size corresponding to each network layer of the target neural network and the shape calculation rule corresponding to each network layer in the target neural network.
Here, the data size of the training data may be used as input data of the shape arithmetic relationship. In this way, the shape result output by each network layer of the target neural network can be determined based on the input data, the network size corresponding to each network layer of the target neural network, and the shape calculation rule corresponding to each network layer in the target neural network.
In the embodiment of the present disclosure, the shape result output by each network layer of the target neural network may be determined on a network layer-by-network layer basis, that is, the shape result output by the first network layer may be determined first, and then the shape results output by the second network layer, the third network layer, and the last network layer may be determined based on the output result.
The shape result output by the first network layer may 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 rule. Taking matrix multiplication as an example of the shape calculation rule, here, the shape result of the output may be determined to be C [5, l ] when the input data is determined to be A [5,4] and the net size corresponding to the first net layer is B [4, l ].
In addition, regarding other network layers, the shape result output by the last network layer of the target neural network and the network size corresponding to the last network layer of the target neural network may be substituted into the shape calculation rule, so as to determine the shape result output by the current network layer of the target neural network.
The related specific shape calculation rules are similar to the related description of the first network layer, and are not described herein again.
And under the condition that the shape result output by the last network layer is determined, determining a loss function value related to the target neural network to be trained based on the shape result, adjusting the target neural network to be trained based on the loss function value, and training the adjusted target neural network again by executing the calculation graph again until the network converges to obtain the trained target neural network.
Considering that the shape calculation may be a series of scalar calculations, which have combinability, a plurality of shape calculations may be combined into one, that is, the shape calculation rules corresponding to each network layer in the target neural network may be combined to obtain the shape calculation rule for the target neural network in the embodiments of the present disclosure. For example, several consecutive reshape operations, whose shape calculation is equivalent to one reshape _ shape. For example, there are several consecutive matrix multiplications, the shape calculation of which is equivalent to a matmul _ shape. The complexity of shape calculation can be reduced through the merging operation, and the execution efficiency is improved.
In a second aspect: the embodiments of the present disclosure may perform the data operation relationship according to the following steps:
step one, taking a data value of training data to be trained and a network parameter value generated in a compiling process of each network layer of a target neural network as input data;
and step two, executing an operation process on the input data based on the data calculation rule by using the allocated memory space to obtain an execution result.
Here, the data values of the training data and the network parameter values generated by each network layer of the target neural network in the compiling process may be used as input data, and the execution result may be obtained by performing the operation process on the input data by using the data calculation rule.
The shape operation corresponds to a correlation operation related to a data shape, where the data operation corresponds to a correlation operation between specific data values, for example, a data value of training data with 5 × 4 dimensions and a network parameter value with 4 × 1 dimensions are subjected to a matrix operation to obtain an execution result with 5 × 1 dimensions. Similar to the shape operation, the data operation may also be determined network layer by network layer, and details about the determination process are not described herein.
In order to better adapt to the operation between different data types, the execution operation related to the shape operation relation can be executed on a first platform, the execution operation related to the data operation relation can be executed on a second platform, and the two platforms belong to heterogeneous platforms.
In a particular application, the data computation is typically a tensor, which can be performed on a particular acceleration device, while the shape computation is typically a scalar, which can be performed on a Central Processing Unit (CPU).
In the embodiment of the present disclosure, when the first platform executes the shape operation relationship corresponding to each network layer of the target neural network, the second platform executes the data operation relationship corresponding to each network layer of the target neural network, or when the first platform executes the shape operation relationship corresponding to the current network layer of the target neural network, and when the second platform executes the data operation relationship corresponding to the current network layer of the target neural network, the first platform executes the shape operation relationship corresponding to the next network layer of the target neural network in parallel, that is, the data calculation of the previous operation and the shape calculation of the next operation can be executed in parallel, which further improves the execution efficiency.
Here, in order to ensure the accuracy of the execution result, it may be verified whether the shape result output by each network layer of the target neural network conforms to the preset shape result, and only when the shape result output by each network layer of the target neural network conforms to the preset shape result, the step of obtaining the allocated memory space based on the shape result output by each network layer of the target neural network is executed, so as to ensure the accuracy of the subsequent execution result.
The preset shape result may be predetermined, and once the shape size of the input training data is determined, the shape result output by each corresponding network layer is also determined. Therefore, under the condition that the actually output shape result does not accord with the preset shape result, namely the fact that the execution shape calculation has problems is explained, the data calculation can be stopped, and compared with the direct data calculation, the waste of calculation resources is avoided on the premise that the accuracy of the execution result is ensured.
It will be understood by those skilled in the art that in the method of the present invention, the order of writing the steps does not imply a strict order of execution and any limitations on the implementation, and the specific order of execution of the steps should be determined by their function and possible inherent logic.
Based on the same inventive concept, a data processing apparatus corresponding to the data processing method is also provided in the embodiments of the present disclosure, and because the principle of the apparatus in the embodiments of the present disclosure for solving the problem is similar to the method of the embodiments of the present disclosure for the data processing, the implementation of the apparatus may refer to the implementation of the method, and repeated details are not described again.
Referring to fig. 3, a schematic diagram of a data processing apparatus provided in an embodiment of the present disclosure is shown, where the apparatus includes: an acquisition module 301 and an execution module 302; wherein the content of the first and second substances,
an obtaining module 301, configured to obtain a calculation graph obtained by compiling a training code based on a target neural network; the calculation graph comprises a shape operation relation and a data operation relation, and the shape representation information and the data operation relation are respectively a shape calculation rule and a data calculation rule corresponding to each network layer in the target neural network represented by a data form;
the execution module 302 is configured to, in response to an execution instruction for the computation graph, execute to obtain an execution result for the target neural network training code based on the training data to be trained and the shape operation relationship and the data operation relationship included in the computation graph.
With the above data processing apparatus, the computation graph compiled based on the target neural network training code may be obtained first, so that in response to the execution instruction for the computation graph, the execution result for the target neural network training code may be obtained by execution based on the shape operation relationship and the data operation relationship included in the computation graph. According to the method, the shape calculation rules and the data calculation rules of each network layer of the target neural network are determined by utilizing the shape calculation relationship and the data calculation relationship in the compiling stage, and specific data size is not limited, so that the execution stage can be compatible with input training data of various sizes, the determined execution result is not prone to error, the accuracy is high, and efficient network training is further ensured.
In a possible implementation manner, the execution module 302 is configured to execute the following steps to obtain an execution result of the target neural network training code based on the training data to be trained and the shape operation relationship and the data operation relationship included in the computation graph:
determining a shape result output by each network layer of the target neural network based on training data to be trained and a shape operation relation contained in the calculation graph;
acquiring a distributed memory space based on a shape result output by each network layer of the target neural network;
and executing the data operation relation by using the allocated memory space to obtain an execution result.
In a possible implementation manner, the execution module 302 is configured to determine a shape result 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 according to the following steps:
taking the data size of training data to be trained as input data of the shape operation relation contained in the calculation diagram;
and determining a shape result output by each network layer of the target neural network based on the input data, the network size corresponding to each network layer of the target neural network and the shape calculation rule corresponding to each network layer in the target neural network.
In a possible implementation manner, the execution module 302 is configured to determine the shape result output by each network layer of the target neural network based on the input data, the network size corresponding to each network layer of the target neural network, and the shape calculation rule corresponding to each network layer in the target neural network according to the following steps:
determining a shape result output by the first network layer of the target neural network based on the input data, the network size corresponding to the first network layer of the target neural network and the shape calculation rule;
for each network layer except the first network layer, determining a shape result output by the network layer according to the following steps;
determining a shape result output by a current network layer of the target neural network based on the shape result output by the last network layer of the target neural network, the network size corresponding to the last network layer of the target neural network and the shape calculation rule;
and circulating the steps until a shape result output by the last network layer of the target neural network is obtained.
In a possible implementation manner, the execution module 302 is configured to determine the shape result output by each network layer of the target neural network based on the input data, the network size corresponding to each network layer of the target neural network, and the shape calculation rule corresponding to each network layer in the target neural network according to the following steps:
combining the shape calculation rules corresponding to each network layer in the target neural network to obtain the shape calculation rules aiming at the target neural network;
and determining a 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 rule aiming at the target neural network.
In a possible implementation manner, the execution module 302 is configured to execute the data operation relationship by using the allocated memory space, and obtain an execution result according to the following steps:
taking a data value of training data to be trained and a network parameter value generated in the compiling process of each network layer of the target neural network as input data;
and executing an operation process on the input data based on the data calculation rule by using the allocated memory space to obtain an execution result.
In a possible implementation manner, the operation of determining the shape result output by each network layer of the target neural network is executed on a first platform, and the operation of executing the data operation relationship by using the allocated memory space is executed on a second platform;
wherein the first platform and the second platform belong to heterogeneous platforms.
In one possible embodiment, the shape operational relationship and the data operational relationship are performed in one of the following ways:
under the condition that the first platform executes the shape operation relation corresponding to each network layer of the target neural network, executing the data operation relation corresponding to each network layer of the target neural network on the second platform;
and under the condition that the first platform executes the shape operation relation corresponding to the current network layer of the target neural network and the second platform executes the data operation relation corresponding to the current network layer of the target neural network, executing the shape operation relation corresponding to the next network layer of the target neural network in parallel on the first platform.
In a possible implementation, the execution module 302 is further configured to:
after determining the shape result output by each network layer of the target neural network, verifying whether the shape result output by each network layer of the target neural network conforms to a preset shape result; and under the condition that the preset shape result is verified to be met, executing the shape result output by each network layer based on the target neural network to obtain the allocated memory space.
The description of the processing flow of each module in the device and the interaction flow between the modules may refer to the related description in the above method embodiments, and will not be described in detail here.
An embodiment of the present disclosure further provides an electronic device, as shown in fig. 4, which is a schematic structural diagram of the electronic device provided in the embodiment of the present disclosure, and the electronic device includes: a processor 401, a memory 402, and a bus 403. The memory 402 stores machine-readable instructions executable by the processor 401 (for example, execution instructions corresponding to the obtaining module 301 and the executing module 302 in the apparatus in fig. 3, and the like), when the electronic device is operated, the processor 401 and the memory 402 communicate through the bus 403, and when the machine-readable instructions are executed by the processor 401, the following processes are performed:
obtaining a calculation graph obtained by compiling a training code based on a target neural network; the calculation graph comprises a shape operation relation and a data operation relation, and the shape representation information and the data operation relation are respectively a shape calculation rule and a data calculation rule corresponding to each network layer in the target neural network represented by a data form;
and responding to an execution instruction for the computation graph, and executing to obtain an execution result for the target neural network training code based on the training data to be trained and the shape operation relation and the data operation relation contained in the computation graph.
The embodiments of the present disclosure also provide a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, performs the steps of the data processing method described in the above method embodiments. The storage medium may be a volatile or non-volatile computer-readable storage medium.
The embodiments of the present disclosure also provide a computer program product, where the computer program product carries a program code, and instructions included in the program code may be used to execute the steps of the data processing method described in the foregoing method embodiments, which may be referred to specifically in the foregoing method embodiments, and are not described herein again.
The computer program product may be implemented by hardware, software or a combination thereof. In an alternative embodiment, the computer program product is embodied in a computer storage medium, and in another alternative embodiment, the computer program product is embodied in a Software product, such as a Software Development Kit (SDK), or the like.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the system and the apparatus described above may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. In the several embodiments provided in the present disclosure, it should be understood that the disclosed system, apparatus, and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present disclosure may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present disclosure may be embodied in the form of a software product, which 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) to execute all or part of the steps of the method according to the embodiments of the present disclosure. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
Finally, it should be noted that: the above-mentioned embodiments are merely specific embodiments of the present disclosure, which are used for illustrating the technical solutions of the present disclosure and not for limiting the same, and the scope of the present disclosure is not limited thereto, and although the present disclosure is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive of the technical solutions described in the foregoing embodiments or equivalent technical features thereof within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present disclosure, and should be construed as being included therein. Therefore, the protection scope of the present disclosure shall be subject to the protection scope of the claims.

Claims (12)

1. A method of data processing, the method comprising:
obtaining a calculation graph obtained by compiling a training code based on a target neural network; the calculation graph comprises a shape operation relation and a data operation relation, wherein the shape operation relation and the data operation relation are respectively a shape calculation rule and a data calculation rule corresponding to each network layer in a target neural network represented by a data form;
and responding to an execution instruction for the computational graph, and executing to obtain an execution result for the target neural network training code based on training data to be trained and the shape operation relation and the data operation relation contained in the computational graph.
2. The method according to claim 1, wherein the executing obtains an execution result for the target neural network training code based on the training data to be trained and the shape operational relationship and the data operational relationship included in the computation graph, and comprises:
determining a shape result output by each network layer of the target neural network based on the training data to be trained and the shape operation relation contained in the calculation graph;
acquiring a distributed memory space based on the shape result output by each network layer of the target neural network;
and executing the data operation relation by using the allocated memory space to obtain the execution result.
3. The method according to claim 2, wherein the determining the shape result 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 comprises:
taking the data size of the training data to be trained as input data of the shape operation relation contained in the calculation graph;
and determining a shape result output by each network layer of the target neural network based on the input data, the network size corresponding to each network layer of the target neural network and the shape calculation rule corresponding to each network layer in the target neural network.
4. The method of claim 3, wherein determining the shape result output by each network layer of the target neural network based on the input data, the network size corresponding to each network layer of the target neural network, and the shape calculation rule corresponding to each network layer of the target neural network comprises:
determining a shape result output by the first network layer of the target neural network based on the input data, the network size corresponding to the first network layer of the target neural network and the shape calculation rule;
for each network layer except the first network layer, determining a shape result output by the network layer according to the following steps;
determining a shape result output by the current network layer of the target neural network based on the shape result output by the last network layer of the target neural network, the network size corresponding to the last network layer of the target neural network and the shape calculation rule;
and circulating the steps until a shape result output by the last network layer of the target neural network is obtained.
5. The method of claim 3, wherein determining the shape result output by each network layer of the target neural network based on the input data, the network size corresponding to each network layer of the target neural network, and the shape calculation rule corresponding to each network layer of the target neural network comprises:
combining the shape calculation rules corresponding to each network layer in the target neural network to obtain the shape calculation rules aiming at the target neural network;
and determining a 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 rule aiming at the target neural network.
6. The method according to any one of claims 3 to 5, wherein the performing the data operation relationship by using the allocated memory space to obtain the performing result comprises:
taking the data value of the training data to be trained and the network parameter value generated by each network layer of the target neural network in the compiling process as input data;
and executing an operation process on the input data based on the data calculation rule by using the allocated memory space to obtain the execution result.
7. The method according to any one of claims 2 to 6, wherein the operation of determining the shape result output by each network layer of the target neural network is performed on a first platform, and the operation of performing the data operation relationship by using the allocated memory space is performed on a second platform;
wherein the first platform and the second platform belong to heterogeneous platforms.
8. The method of claim 7, wherein the shape operational relationship and the data operational relationship are performed in one of:
under the condition that the first platform executes the shape operation relation corresponding to each network layer of the target neural network, executing the data operation relation corresponding to each network layer of the target neural network on the second platform;
and under the condition that the first platform executes the shape operation relation corresponding to the current network layer of the target neural network and the second platform executes the data operation relation corresponding to the current network layer of the target neural network, executing the shape operation relation corresponding to the next network layer of the target neural network in parallel on the first platform.
9. The method of any one of claims 2 to 8, wherein after said determining the shape result output by each network layer of the target neural network, the method further comprises:
verifying whether the shape result output by each network layer of the target neural network conforms to a preset shape result;
and under the condition that the preset shape result is verified to be met, executing a step of acquiring the allocated memory space based on the shape result output by each network layer of the target neural network.
10. An apparatus for data processing, the apparatus comprising:
the acquisition module is used for acquiring a calculation graph obtained by compiling a training code based on a target neural network; the calculation graph comprises a shape operation relation and a data operation relation, wherein the shape operation relation and the data operation relation are respectively a shape calculation rule and a data calculation rule corresponding to each network layer in a target neural network represented by a data form;
and the execution module is used for responding to an execution instruction aiming at the computational graph, and executing to obtain an execution result aiming at the target neural network training code based on training data to be trained and the shape operation relation and the data operation relation contained in the computational graph.
11. An electronic device, comprising: a processor, a memory and a bus, the memory storing machine-readable instructions executable by the processor, the processor and the memory communicating over the bus when the electronic device is operating, the machine-readable instructions when executed by the processor performing the steps of the method of data processing according to any of claims 1 to 9.
12. A computer-readable storage medium, characterized in that a computer program is stored on the computer-readable storage medium, which computer program, when being executed by a processor, performs the steps of the method of data processing according to one of the claims 1 to 9.
CN202111266095.8A 2021-10-28 2021-10-28 Data processing method and device, electronic equipment and storage medium Pending CN114004335A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111266095.8A CN114004335A (en) 2021-10-28 2021-10-28 Data processing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111266095.8A CN114004335A (en) 2021-10-28 2021-10-28 Data processing method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114004335A true CN114004335A (en) 2022-02-01

Family

ID=79924819

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111266095.8A Pending CN114004335A (en) 2021-10-28 2021-10-28 Data processing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114004335A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115658331A (en) * 2022-12-28 2023-01-31 杭州登临瀚海科技有限公司 Compiling method and device of dynamic neural network, electronic equipment and storage medium
CN116055778A (en) * 2022-05-30 2023-05-02 荣耀终端有限公司 Video data processing method, electronic device and readable storage medium

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116055778A (en) * 2022-05-30 2023-05-02 荣耀终端有限公司 Video data processing method, electronic device and readable storage medium
CN116055778B (en) * 2022-05-30 2023-11-21 荣耀终端有限公司 Video data processing method, electronic device and readable storage medium
CN115658331A (en) * 2022-12-28 2023-01-31 杭州登临瀚海科技有限公司 Compiling method and device of dynamic neural network, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
US11816559B2 (en) Dilated convolution using systolic array
CN112199190B (en) Memory allocation method and device, storage medium and electronic equipment
CN114004335A (en) Data processing method and device, electronic equipment and storage medium
CN112947933A (en) Operator execution method and device, computer equipment and storage medium
CN111104120A (en) Neural network compiling method and system and corresponding heterogeneous computing platform
EP3938950A1 (en) Spatially sparse convolutional neural networks for inking applications
CN111984400A (en) Memory allocation method and device of neural network
Phillips et al. A CUDA implementation of the High Performance Conjugate Gradient benchmark
CN112200300A (en) Convolutional neural network operation method and device
CN107402905B (en) Neural network-based computing method and device
CN114461221A (en) Compiling method, compiling device, electronic device, and storage medium
CN108470211B (en) Method and device for realizing convolution calculation and computer storage medium
CN110889497A (en) Learning task compiling method of artificial intelligence processor and related product
CN111008631A (en) Image association method and device, storage medium and electronic device
CN114168154A (en) Model data processing method and device, electronic equipment and storage medium
CN114398040A (en) Neural network reasoning method, device, computer equipment and storage medium
CN116560666B (en) AI front end unified computing method, device and medium based on multi-level code generation
CN116484947B (en) Operator automatic generation method, device, equipment and medium
US20170147943A1 (en) Global data flow optimization for machine learning programs
CN109766123A (en) Application program packaging method and device
CN113031954A (en) Code compiling method and device, electronic equipment, storage medium and heterogeneous system
CN115268936B (en) Optimization method and device for calculation chart compilation
CN116560621A (en) Baseboard management controller chip adapting method, system, equipment and medium
CN114356342A (en) Compiling method and device
CN113760380A (en) Method, device, equipment and storage medium for determining running code of network model

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination