Data processing method and apparatus, and device, storage medium and program product
By mapping and compiling the input data format of the neural network model and the processor attribute information, a final model file adapted to different data formats is generated, which solves the problem of low data format flexibility during processor runtime and realizes the processing of multiple data Efficient handling of formats.
Patent Information
- Application Number
- PCT/CN2024/076547
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-03-22
- Filing Date
- 2024-02-07
- Publication Date
- 2024-09-26
AI Technical Summary
When the neural network model is run through the processor, the shape of the input data is fixed, resulting in the processor having low flexibility in input data and being unable to adapt to the processing needs of different data formats.
By obtaining the input data format and initial model file of the neural network model, operator mapping is performed to obtain the sub-data format, and the processor attribute information is combined for compilation processing to generate the final model file matching the processor, thereby realizing the processing of different data formats. flexible processing.
It improves the flexibility of the processor when running neural network models, can adapt to the processing of multiple data formats, reduces the need to manually generate final model files, and improves processing efficiency.
Smart Images

Figure CN2024076547_26092024_PF_FP
Abstract
Description
Data processing method, device, equipment, storage medium and program product
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on March 22, 2023, application number 202310295178.2, and application name “Data processing method, device, equipment, storage medium and program product”, all contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of data processing technology, and specifically to a data processing method, apparatus, device, storage medium, and program product. Background Art
[0003] With the development of science and technology, the application of neural network models is becoming more and more extensive. Generally, a neural network model can be run through a processor to process the input data of the neural network model.
[0004] Currently, when a neural network model is run through a processor, the shape of the input data of the neural network model can only be fixed and cannot be changed. That is, the shape of the input data of the processor can only be fixed, which makes the flexibility of the neural network model run through the processor to process the input data low.
[0005] Summary of the Invention
[0006] The embodiments of the present application provide a data processing method, apparatus, device, storage medium, and program product, which can solve the technical problem of low flexibility when processing input data through a neural network model running on a processor.
[0007] An embodiment of the present application provides a data processing method, which is applied to an electronic device, wherein the electronic device includes a processor, including:
[0008] Obtaining the data format of input data of the neural network model, and obtaining an initial model file of the neural network model, wherein the initial model file includes operators of the neural network model;
[0009] According to the above operator, the above data format is mapped to obtain the sub-data format of the input data of the above operator;
[0010] Obtaining attribute information of the processor, and compiling the initial model file according to the attribute information and the sub-data format to obtain a final model file that matches the processor;
[0011] The processor runs the final model file to process the data to be processed of the neural network model to obtain a processing result of the data to be processed.
[0012] Accordingly, an embodiment of the present application provides a data processing device, which is applied to an electronic device. The electronic device includes a processor, including:
[0013] An acquisition module, configured to acquire the data format of input data of a neural network model and to acquire an initial model file of the neural network model, wherein the initial model file includes operators of the neural network model;
[0014] A mapping module, configured to perform mapping processing on the above data format according to the above operator to obtain a sub-data format of the input data of the above operator;
[0015] A compiling module, configured to obtain attribute information of the processor and compile the initial model file according to the attribute information and the sub-data format to obtain a final model file that matches the processor;
[0016] The processing module is used to process the data to be processed of the neural network model by running the final model file through the processor to obtain the processing result of the data to be processed.
[0017] In addition, an embodiment of the present application also provides an electronic device, including a processor and a memory, wherein the memory stores a computer program, and the processor is used to run the computer program in the memory to implement the data processing method provided in the embodiment of the present application.
[0018] In addition, an embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. The computer program is suitable for loading by a processor to execute any data processing method provided in the embodiment of the present application.
[0019] In addition, an embodiment of the present application also provides a computer program product, including a computer program, which implements any data processing method provided in the embodiment of the present application when executed by a processor.
[0020] In the embodiment of the present application, the data format of the input data of the neural network model is usually fixed, but the data format may change during the processor's operation of the neural network model. Therefore, in order to improve the flexibility of the processor in operating the neural network model, the data format that may change can be obtained in advance. The data format that may change is determined by the operators included in the neural network model. Therefore, in the embodiment of the present application, the data format of the input data of the neural network model and the initial model file of the neural network model can be obtained. The initial model file includes the operator of the neural network model. Then, according to the operator, the data format is mapped to obtain the sub-data format of the operator's input data, that is, the data format that changes under the influence of the operator. Next, the attribute information of the processor is obtained, and the model file is compiled and processed according to the attribute information and the sub-data format to obtain a final model file that matches the processor, so that the final model file includes the sub-data format and the final model file is a file supported by the processor. Therefore, when the data format of the data to be processed of the neural network model is the data format of the input data of the neural network model, the final model file can be directly run by the processor to process the data to be processed of the neural network model to obtain the processing result of the data to be processed. There is no need to manually generate the final model file in the process of processing the data to be processed, thereby improving the flexibility of the neural network model run by the processor in processing the data to be processed. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0022] FIG1 is a schematic diagram of a data processing scenario according to an embodiment of the present application;
[0023] FIG2 is a flow chart of a data processing method according to an embodiment of the present application;
[0024] FIG3 is a flow chart of another data processing method provided in an embodiment of the present application;
[0025] FIG4 is a schematic diagram of a sub-data format and a sub-graph provided in an embodiment of the present application;
[0026] FIG5 is a schematic diagram of a data processing method provided in an embodiment of the present application;
[0027] FIG6 is a schematic diagram of the structure of a data processing device provided in an embodiment of the present application;
[0028] FIG7 is a schematic structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0029] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without making creative efforts are within the scope of protection of this application.
[0030] Embodiments of the present application provide a data processing method, apparatus, device, storage medium, and program product. The apparatus may be an electronic device, the storage medium may be a computer storage medium, and the program product may be a computer program product. The data processing apparatus may be integrated into an electronic device, which may be a server, a terminal, or other device.
[0031] Among them, the server can be an independent physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, network acceleration services (Content Delivery Network, CDN), as well as big data and artificial intelligence platforms.
[0032] Furthermore, multiple servers can form a blockchain, and the servers are nodes on the blockchain.
[0033] The terminal may be a smartphone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited thereto. The terminal and the server may be connected directly or indirectly via wired or wireless communication, and this application does not impose any restrictions thereon.
[0034] For example, as shown in Figure 1, the server obtains the data format of the input data of the neural network model and the initial model file of the neural network model, which includes the operator of the neural network model; maps the data format according to the operator to obtain the sub-data format of the operator's input data; obtains the attribute information of the processor, and compiles the initial model file based on the attribute information and the sub-data format to obtain a final model file that matches the processor. The server sends the final model file to the terminal, and the terminal runs the final model file on the processor to process the data to be processed of the neural network model and obtains the processing result of the data to be processed.
[0035] In addition, the term "a plurality of" in the embodiments of the present application refers to two or more than two. The terms "first" and "second" in the embodiments of the present application are used to distinguish descriptions and should not be understood to imply relative importance.
[0036] The methods provided in the embodiments of this application mainly involve artificial intelligence technology. For example, the solutions provided in the embodiments of this application involve artificial intelligence computer vision technology and machine learning technology, which are specifically illustrated by the following embodiments. It should be noted that the order of description of the following embodiments does not limit the preferred order of the embodiments.
[0037] In this embodiment, the description will be made from the perspective of a data processing device. The data processing device can be specifically integrated into a device such as a server or a terminal. In order to facilitate the description of the data processing method of this application, the following detailed description will be given with the data processing device integrated in the terminal, that is, the terminal will be used as the execution subject.
[0038] Please refer to Figure 2, which is a flow chart of a data processing method provided in one embodiment of the present application. The data processing method may include:
[0039] S201. Obtain the data format of the input data of the neural network model, and obtain the initial model file of the neural network model, where the initial model file includes the operators of the neural network model.
[0040] The neural network model is a statistical learning algorithm that attempts to simulate the structure and function of biological neural networks. It mainly includes an input layer, a hidden layer, and an output layer. The input layer is used to receive input data as input to the neural network model, the hidden layer is used to perform various processing on the input data, and the output layer is used to output the prediction results of the neural network model according to different tasks.
[0041] Neural network models are trained on data, using training datasets to establish a mapping relationship between samples and labels. This mapping relationship can be a linear or nonlinear function that effectively reflects the relationship between similar samples and labels, or the mapping relationship. This allows the neural network model to generate predictions based on the input data that have this mapping relationship.
[0042] The data format of the input data may refer to the form of existence of the tensor corresponding to the input data, which may include at least one of a data type and a data shape. The data type refers to the storage format of the input data, for example, the data type may be an integer (int) or a floating point (float). The data shape refers to the layout of the input data, for example, the data shape of the input data may be (N, C, H, W) or (N, H, W, C), where N represents the number, C represents the number of channels, H represents the height, and W represents the width. (1, 3, 224, 224) and (1, 3, 448, 448) represent two data shapes.
[0043] The data format of the input data may include at least one, and the user may set the data format of the input data according to actual needs.
[0044] The initial model file refers to a file including a neural network model, which may include operators of the neural network model and network flow information of the neural network model, etc.
[0045] In one possible implementation, the initial model file may include the identifier and model parameters of the operator of the neural network model, or the initial model file may also include the identifier, model parameters and code for implementing the operator of the neural network model.
[0046] A neural network model refers to an algorithmic mathematical model that imitates the behavioral characteristics of an animal neural network and performs information processing. It can be a trained neural network model, or it can be an initialized neural network model, that is, an untrained neural network model.
[0047] The type of neural network model can be selected according to actual conditions. For example, the neural network model can be a recursive neural network model or an autoencoder, etc., which is not limited in the embodiments of the present application.
[0048] An operator (OP) may refer to a mapping from one function space to another function space, which may be understood as a computing unit. For example, an operator may be a convolution operator or a pooling operator.
[0049] The terminal may first obtain the data format of the input data of the neural network model, and then obtain the initial model file of the neural network model, or the terminal may first obtain the initial model file of the neural network model, and then obtain the data format of the input data of the neural network model, or the terminal may obtain the initial model file of the neural network model while obtaining the data format of the input data of the neural network model.
[0050] The method for the terminal to obtain the data format and the initial model file can be selected according to actual conditions, and is not limited in this embodiment of the present application.
[0051] S202: Map the data format according to the operator to obtain a sub-data format of the operator's input data.
[0052] A sub-data format can be the format of an operator's input data or the format of an operator's output data. For example, if the neural network model is operator op1 → operator op2 → operator op3, then the sub-data format of operator op3's input data can be the sub-data format of operator op2's output data.
[0053] Therefore, by mapping the data format according to the operator, the sub-data format of the operator's output data can also be obtained.
[0054] In an embodiment of the present application, the data format may change during the processor's operation of the neural network model. Since these changes may be determined by the operators included in the neural network model, in order to improve the flexibility of the processor in operating the neural network model, the data format that may change may be obtained in advance. To this end, a correspondence between the data format of the input data of the neural network model and the sub-data format of the input data of the operator can be established for different operators. Based on this, in an embodiment of the present application, the mapping process can be a mapping from the data format of the input data of the neural network model to the sub-data format of the input data of the operator, that is, the data format of the input data in the corresponding relationship is known, and the sub-data format of the input data of the operator in the corresponding relationship is determined.
[0055] The corresponding relationships constructed for different operators are different. Therefore, when mapping the data format according to the operator to obtain the sub-data format of the operator's input data, the corresponding relationship of the operator can be determined according to the operator, and then the data format can be mapped to obtain the sub-data format of the operator's input data, that is, based on the data format of the input data in the corresponding relationship, the sub-data format of the input data of the operator in the corresponding relationship is determined.
[0056] The neural network model includes at least one operator, and at least one operator can process the input data of the neural network model in turn. Therefore, for each operator, the operator also has its own input data, and the input data of each operator can be obtained based on the input data of the neural network model. The data format of the operator's input data may be the same as or different from the data format of the input data of the neural network model. For example, the neural network model is operator op1→operator op2→operator op3. The input data of operator op1 can be the input data of the neural network model, the input data of operator op2 can be the processing result obtained after operator op1 processes its input data, and the input data of operator op3 can be the processing result obtained after operator op2 processes its input data.
[0057] A sub-data format refers to the data format of each operator's input data (or output data). Since operators are part of a neural network model, the data format of an operator's input data (or output data) can be called a sub-data format. The data format of a neural network model's input data is the overall data format of the neural network model. The sub-data format is relative to the overall data format and reflects the phased changes in the data format.
[0058] In some embodiments, each operator may have a pre-set format mapping scheme, and the corresponding format mapping scheme is stored, and the stored format mapping scheme can be called. It should be noted that the format mapping schemes of different operators may be the same or different. In some cases, the format mapping schemes of operators of the same type may be the same. In this case, the format mapping scheme corresponding to each operator may be stored. Of course, in order to save storage space, the format mapping scheme corresponding to each operator may also be stored. For example, if operator 1 and operator 2 belong to the same type of operator, the sub-data format of the input data of operator 1 and operator 2 is the same, and operator 1 and operator 3 belong to different types of operators, then when storing the format mapping scheme, the corresponding format mapping schemes may be stored for operator 1, operator 2, and operator 3 respectively, or the corresponding format mapping schemes may be stored for operators of the type of operator 1 and operator 2, and the corresponding format mapping schemes may be stored for operators of the type of operator 3.
[0059] The format mapping scheme reflects the mapping relationship between the data format of the input data and the sub-data format of the operator's input data. In this way, when the sub-data format of the operator's input data needs to be determined, the corresponding format mapping scheme can be called to determine the sub-data format of the input data. In this case, according to the operator, the data format is mapped to obtain the sub-data format of the operator's input data, including:
[0060] Get the format mapping scheme corresponding to the operator; for example, you can call the format mapping scheme of the operator.
[0061] The data format is mapped through the format mapping scheme to obtain the sub-data format of the operator's input data.
[0062] The format mapping scheme may exist in the form of a format mapping function or in the form of a format mapping table, which is not limited in this application example.
[0063] In an embodiment of the present application, a format mapping scheme corresponding to each operator is pre-set. The format mapping scheme can reflect the rules based on which each operator is mapped to obtain the data format of the operator's input data. Then, using the format mapping scheme, the data format of the neural network model's input data is directly mapped to obtain the sub-data format of the operator's input data. This sub-data format of the operator's input data can be obtained without performing other operations, thereby improving the speed of obtaining the sub-data format of the operator's input data.
[0064] For example, the data format is d1, the neural network model is operator op1→operator op2→operator op3, the format mapping scheme corresponding to operator op1 is s1, the format mapping scheme corresponding to operator op2 is s2, and the format mapping scheme corresponding to operator op3 is s3. Then, d1 is mapped through s1 to obtain the sub-data format of the input data of operator op1, d1 is mapped through s2 to obtain the sub-data format of the input data of operator op2, and d1 is mapped through s3 to obtain the sub-data format of the input data of operator op3.
[0065] In other embodiments, the process of mapping the data format according to the operator to obtain the sub-data format of the operator's input data may also be:
[0066] Filter out the startup operator from various operators and use the data format as the sub-data format of the input data of the startup operator;
[0067] According to the startup operator, the sub-data format of the input data of the startup operator is mapped to obtain the sub-data format of the output data of the startup operator;
[0068] If there is a next operator in the operator list, the sub-data format of the output data of the starting operator is used as the data format, and the next operator is used as the starting operator. The process returns to the step of using the data format as the sub-data format of the input data of the starting operator.
[0069] If the next operator of the initiating operator does not exist in the operator, the sub-data format of the input data of the operator is determined according to the sub-data format of the input data of the initiating operator.
[0070] The startup operator selected from various operators can be understood as the first operator in the neural network model.
[0071] The startup operator can be the operator that is executed first in the neural network model. For example, if the data format is d1 and the neural network model is operator op1 → operator op2 → operator op3, then operator op1 is the startup operator, and d1 is used as the sub-data format of the input data of operator op1. According to operator op1, d1 is mapped to obtain the sub-data format d2 of the output data of operator op1. Since there is the next operator "operator op2" of operator op1, sub-data format d2 is used as the sub-data format of the input data of operator op2. According to operator op2, d2 is mapped to obtain the sub-data format d3 of the output data of operator op2. Since there is the next operator "operator op3" of operator op2, sub-data format d3 is used as the sub-data format of the input data of operator op3. According to operator op3, d3 is mapped to obtain the sub-data format d4 of the output data of operator op3. Since there is no next operator of operator op3, the calculation is stopped, and the sub-data format of the input data of operator op1 is obtained to be d1, the sub-data format of the input data of operator op2 is obtained to be d2, and the sub-data format of the input data of operator op3 is obtained to be d3.
[0072] In an embodiment of the present application, the sub-data format of the input data of each operator can be determined based on the connection relationship between the operators, thereby fully considering the dynamic changes in the operations of the operators inside the neural network model and improving the accuracy of the sub-data format of the input data of the operator.
[0073] At this time, according to the startup operator, the sub-data format of the input data of the startup operator is mapped to obtain the sub-data format of the output data of the startup operator. The process can be:
[0074] According to the first format mapping scheme corresponding to the startup operator, the sub-data format of the input data of the startup operator is mapped to obtain the sub-data format of the output data of the startup operator.
[0075] Among them, when the startup operator is the first operator of the neural network model, the first format mapping scheme corresponding to the first operator can be the same as the format mapping scheme corresponding to the first operator.
[0076] Alternatively, according to the startup operator, the sub-data format of the input data of the startup operator is mapped to obtain the sub-data format of the output data of the startup operator. The process may also be:
[0077] According to the model parameters of the startup operator, the sub-data format of the input data of the startup operator is mapped to obtain the sub-data format of the output data of the startup operator.
[0078] The model parameters of the activation operator may refer to parameters that change the sub-data format of the input data of the activation operator. For example, when the activation operator is a convolution operator, the model parameters of the activation operator may refer to the size of the convolution kernel and the sliding step size of the convolution operator.
[0079] In an embodiment of the present application, a startup operator is screened out from various operators, and the data format is used as the sub-data format of the input data of the startup operator; according to the startup operator, the sub-data format of the input data of the startup operator is mapped to obtain the sub-data format of the output data of the startup operator; if there is a next operator of the startup operator in the operator, the sub-data format of the output data of the startup operator is used as the data format, and the next operator is used as the startup operator, and the process returns to execute the step of using the data format as the sub-data format of the input data of the startup operator; if there is no next operator of the startup operator in the operator, the sub-data format of the input data of the operator is determined according to the sub-data format of the input data of the startup operator, so as to obtain the sub-data format of the input data of the next operator according to the sub-data format of the output data of the startup operator.
[0080] In other embodiments, the process of mapping the data format according to the operator to obtain the sub-data format of the operator's input data may also be:
[0081] Filtering out an operator to be processed from the operators, and determining a historical operator before the operator to be processed in the neural network model;
[0082] According to the historical operators, the data format is mapped to obtain the sub-data format of the input data of the operator to be processed;
[0083] The sub-data format of the input data of the operator to be processed is determined according to the sub-data format of the input data of the operator to be processed.
[0084] Among them, the terminal can arbitrarily filter out the operators to be processed from the operators, or the terminal can also filter out the operators to be processed from the operators in sequence according to the execution order of each operator in the neural network model.
[0085] The operator to be processed can be any operator in the neural network model. For example, the neural network model is operator op1 → operator op2 → operator op3. If the operator to be processed is randomly selected from the operators, the operator to be processed selected from the operators for the first time may be operator op1, operator op2, or operator op3. If the operators to be processed are selected from the operators in the order of the operators in the neural network model, the operator to be processed selected from the operators for the first time is operator op1, the operator to be processed selected from the operators for the second time is operator op2, and the operator to be processed selected from the operators for the third time is operator op3.
[0086] The historical operator before the operator to be processed in the neural network model may refer to an operator whose execution order in the neural network model is before the execution order of the operator to be processed. For example, if the neural network model is operator op1 → operator op2 → operator op3, the execution order of operator op1 precedes the execution order of operator op2, and the execution order of operator op2 precedes the execution order of operator op3, when the operator to be processed is operator op2, the historical operator is operator op1, and when the operator to be processed is operator op3, the historical operator may include at least one of operator op1 and operator op2.
[0087] It should be understood that if the operator to be processed is a startup operator, since there is no historical operator for the startup operator in the neural network model, after obtaining the operator to be processed, the terminal can determine whether the operator to be processed is a startup operator. If it is a startup operator, the data format is used as the sub-data format of the input data of the operator to be processed. If it is not a startup operator, the historical operator before the operator to be processed in the neural network model is determined.
[0088] In an embodiment of the present application, an operator to be processed is selected from the operators, and historical operators preceding the operator to be processed in the neural network model are determined. Based on the historical operators, the data format is mapped to obtain the sub-data format of the input data of the operator to be processed. The sub-data format of the input data of the operator to be processed is then used as the sub-data format of the input data of the operator, thereby obtaining the sub-data format of the input data of each operator. In this way, the sub-data format of the input data of the operator can be determined in any order, which improves the flexibility of the determination.
[0089] In a possible implementation, the process of mapping the data format according to the historical operator to obtain the sub-data format of the input data of the operator to be processed may be:
[0090] Determine conversion model parameters based on model parameters of historical operators;
[0091] According to the conversion model parameters, the data format is mapped to obtain the sub-data format of the input data of the operator to be processed.
[0092] The conversion model parameters may be model parameters used for mapping the data format, thereby achieving the sub-data format of the input data of the operator to be processed based on the estimated conversion model parameters. For example, the neural network model is operator op1→operator op2→operator op3, the operator to be processed is operator op3, and the historical operators are operator op1 and operator op2. The conversion model parameters are determined based on the model parameters of operator op1 and the model parameters of operator op2, and then the data format is mapped based on the conversion model parameters to obtain the sub-data format of the output data of operator op2. The sub-data format of the output data of operator op2 is then used as the sub-data format of the input data of operator op3, so that there is no need to obtain the sub-data format of the output data of the historical operator (operator op1) that is not adjacent to operator op3.
[0093] In this embodiment, the conversion model parameters are determined based on the model parameters of the historical operator, and then the data format is mapped based on the conversion model parameters to obtain the sub-data format of the input data of the operator to be processed. This achieves the goal of calculating the sub-data format of the input data of the operator to be processed without obtaining the sub-data format of the output data of non-adjacent historical operators, thereby simplifying the determination method and improving the efficiency of determining the sub-data format of the input data of the operator to be processed.
[0094] Alternatively, the process of mapping the data format according to the historical operator to obtain the sub-data format of the input data of the operator to be processed can be:
[0095] Filter out the startup operator from the historical operators and use the data format as the sub-data format of the input data of the startup operator;
[0096] According to the startup operator, the sub-data format of the input data of the startup operator is mapped to obtain the sub-data format of the output data of the startup operator;
[0097] If the next operator of the start operator exists in the history operator, the sub-data format of the output data of the start operator is used as the data format, and the next operator is used as the start operator. The process returns to the step of using the data format as the sub-data format of the input data of the start operator.
[0098] If the next operator of the starting operator does not exist in the historical operators, the sub-data format of the input data of the starting operator will be used as the sub-data format of the input data of the operator to be processed.
[0099] S203: Acquire attribute information of the processor, and compile the initial model file according to the attribute information and the sub-data format to obtain a final model file of the processor.
[0100] The processor may refer to the final execution unit for information processing and program running, which may include at least one of a central processing unit (CPU), a graphics processing unit (GPU), and a neural network processor (NPU).
[0101] The attribute information of a processor may refer to information describing the characteristics of the processor. For example, the attribute information of a processor may be the instruction set supported by the processor, the operator type supported by the processor, or the type of processor. The attribute information of different processors is different. For example, the instruction sets supported by different processors are different. Some processors produced by some manufacturers support the x86 / x64 instruction set, while some processors produced by some manufacturers support the arm instruction set. Therefore, in an embodiment of the present application, the initial model file is compiled according to the attribute information of the processor so that the compiled final model file is a file supported by the processor.
[0102] Compilation can refer to the process of generating processor executable code from a given neural network model. In the embodiment of the present application, the compilation process mainly converts the sub-data format of the neural network model and the input data of each operator into processor executable code. The file consisting of the executable code obtained at this time can be called the final model file.
[0103] And according to the sub-data format, the initial model file is compiled and processed, so that the compiled final model file includes the sub-data format, that is, the compiled final model file can include not only each operator, but also the sub-data format of each operator. Therefore, according to the attribute information and the sub-data format, the initial model file is compiled and processed to obtain the final model file of the processor, so that the final model file can be a file supported by the processor and containing the sub-data format, so that when the final model file is run by the processor, the data to be processed with the data format can be processed by the final model file, and then the data to be processed with the data format can be processed by the neural network model. Since the data format can be any data format, the embodiment of the present application can realize the input of data to be processed in multiple data formats to the processor, thereby improving the flexibility of the neural network model running by the processor in processing the data to be processed.
[0104] Moreover, in an embodiment of the present application, the data format is mapped according to the operator to obtain the sub-data format of the operator's input data, and then the initial model file is compiled according to the attribute information and the sub-data format to obtain the final model file that matches the processor, so that there is no need to set the sub-data format according to the attribute information of the processor, so that the sub-data format can be determined by the embodiment of the present application regardless of the processor. Therefore, the embodiment of the present application maps the data format according to the operator to obtain the sub-data format of the operator's input data, and compiles the initial model file according to the attribute information and the sub-data format to obtain the final model file of the processor. The method has universality.
[0105] It should be noted that when an electronic device includes multiple processors, after compiling the initial model file according to the attribute information and sub-data format, a final model file for each processor can be obtained, and the operators included in the final model file are the operators supported by the processor.
[0106] For example, the initial model file includes operators op1 and op2, the processor includes a central processing unit and a neural network processor, the central processing unit supports operator op1, and the neural network processor supports operator op2. Then the final model file matching the central processing unit may include operator op1, and the final model file matching the neural network processor may include operator op2.
[0107] In some embodiments, the processor includes multiple processors that compile the initial model file according to the attribute information and the sub-data format to obtain the final model file of the processor, including:
[0108] Get the original computation graph, which includes nodes, each of which represents an operator.
[0109] According to the attribute information, the original computation graph is divided into subgraphs matching each processor;
[0110] According to the attribute information, sub-data format and sub-graph, the initial model file is compiled and processed to obtain the final model file of each processor.
[0111] In the embodiments of the present application, the operators in the initial model file exist in the form of an original computation graph. The original computation graph is a data structure that includes nodes and edges. Nodes represent operators, and edges represent the flow of data within the operators. A subgraph can be a portion of the original computation graph. A subgraph can include at least one operator, and all operators included in the subgraph are operators that match the processor.
[0112] Since different processors support different operators, and operators that a processor does not support cannot run on the processor, in an embodiment of the present application, multiple processors are included, and then the original computation graph is divided according to the attribute information of each processor to obtain a subgraph that matches each processor, that is, a subgraph supported by each processor. Then, based on the attribute information, sub-data format, and subgraph, the initial model file is compiled and processed to obtain a final model file that matches each processor. Based on the original computation graph, the entire computation process can be quickly determined, and then the operators assigned to different processors can be quickly determined, thereby improving the efficiency of determining the final model file.
[0113] For example, the original computation graph may be operator op1→operator op2→operator op3, where operator op1 is an operator supported by the central processing unit, and operators op2 and op3 are operators supported by the neural network processing. Then, the original computation graph is divided, and the subgraph matching the neural network processor is operator op2→operator op3, and the subgraph matching the central processing unit is operator op1.
[0114] In other embodiments, in order to increase the speed at which subsequent processors run the final model file, the original computation graph is divided according to attribute information to obtain a subgraph matching each processor. The process may be:
[0115] Determine the starting operator in the original computation graph and, based on the attribute information, start traversing from the starting operator;
[0116] If the starting operator matches the attribute information, the starting operator is marked, and the subordinate operator of the starting operator is used as the starting operator. The execution returns to the steps starting from the starting operator according to the attribute information.
[0117] If the startup operator does not match the attribute information, the marked startup operator is separated from the original computation graph to obtain a subgraph that matches the attribute information. The subordinate operator of the startup operator is used as the startup operator, and the execution is returned to the steps starting from the startup operator according to the attribute information.
[0118] The subgraph matching the attribute information is used as the subgraph matching each processor.
[0119] For example, the original computation graph is op1 → operator op2 → operator op3 → operator op4 → operator op5. Operator op3 is an operator supported by the central processing unit, and operators op1, op2, op4, and op5 are operators supported by the neural network processor. The starting operator in the original computation graph is operator op1.
[0120] The traversal starts from operator op1. Since operator op1 is an operator supported by the neural network processor, operator op1 is marked, and the subordinate operator of operator op1 is operator op2. Since operator op2 is an operator supported by the neural network processor, operator op2 is marked, and the subordinate operator of operator op2 is operator op3. Since operator op3 is not an operator supported by the neural network processor, the marked operator op1 and the marked operator op2 are separated, and the subgraph matching the neural network processor is op1→operator op2.
[0121] Because operator op3 has a lower-level operator "operator op4", traversal starts from operator op4. Since operator op4 is an operator supported by the neural network processor, operator op4 is marked. The lower-level operator of operator op4 is operator op5. Since operator op5 is an operator supported by the neural network processor, operator op5 is marked. Since there is no lower-level operator of operator op5, the marked operator op4 and the marked operator op5 are separated, and the subgraph matching the neural network processor is op4→operator op5.
[0122] At this time, the final model files matching the neural network processor may include two, one final model file matching the neural network processor includes the subgraph "op1→operator op2", and the other final model file matching the neural network processor includes the subgraph "op4→operator op5".
[0123] In an embodiment of the present application, a startup operator in the original computation graph is determined, and traversal is started from the startup operator according to the attribute information; if the startup operator is an operator that matches the attribute information, the startup operator is marked, and the subordinate operator of the startup operator is used as the startup operator, and the step of traversal from the startup operator according to the attribute information is returned; if the startup operator is an operator that does not match the attribute information, the marked startup operator is divided out from the original computation graph to obtain a subgraph that matches the attribute information, and the subordinate operator of the startup operator is used as the startup operator, and the step of traversal from the startup operator according to the attribute information is returned; the subgraph that matches the attribute information is used as a subgraph that matches each processor, so that multiple operators that match the processor and have edges can be divided into the same subgraph, so that multiple operators that match the processor and have edges can be stored in the same final model file, so that when the final model file is subsequently run by the processor, the number of times the processor is called can be reduced, and the speed at which the processor runs the final model file can be improved.
[0124] In other embodiments, when the data format is a data shape, the model file is compiled according to the attribute information, the sub-data format, and the sub-graph to obtain the final model file for each processor as follows:
[0125] According to the original computation graph, determine the initial data type of the subgraph’s input data;
[0126] Determine the final data type of the input data of the subgraph according to the attribute information;
[0127] The initial model file is compiled according to the attribute information, sub-data format, initial data type and final data type to obtain the final model file of each processor.
[0128] The initial data type may be a pre-set data type, and the final data type may be a data type supported by the processor. Therefore, in order to obtain a final model file supported by the processor, the initial model file may be compiled based on the attribute information, sub-data format, initial data type, and final data type to obtain a final model file for each processor.
[0129] The process of compiling the initial model file according to the attribute information, sub-data format, initial data type and final data type to obtain the final model file matching each processor can be as follows:
[0130] If the initial data type and the final data type are different, obtain the data type conversion operator;
[0131] Adjust the subgraph according to the data type conversion operator to obtain a first adjusted subgraph;
[0132] The initial model file is compiled according to the attribute information, the sub-data format and the first adjusted sub-graph to obtain a final model file matching each processor.
[0133] If the initial data type and the final data type are different, it indicates that the final data type needs to be converted to the initial data type. Therefore, a data type conversion operator can be added to the subgraph to convert the data type of the input data of the subgraph to the initial data type so that the final model file can be run through the processor later.
[0134] If the initial data type and the final data type are the same, indicating that there is no need to convert the final data type, the initial model file can be directly compiled according to the attribute information, sub-data format and sub-graph to obtain the final model file that matches the processor.
[0135] For example, the processor is CoreML, and the initial data type of the CoreML input data is Int32. If the final data type of the input data of the original computation graph is Int64, a data type conversion operator (cast operator) is added to the subgraph to obtain the first adjusted subgraph.
[0136] The above method checks the legality of the subgraph, and adjusts the subgraph if the legality of the subgraph does not meet the requirements, so that the final model file can be obtained using the legal subgraph, ensuring the correctness of the final model file.
[0137] In other embodiments, when the data format is a data shape, the process of compiling the initial model file according to the attribute information, the sub-data format, and the sub-graph to obtain the final model file matching each processor may also be:
[0138] Determine, according to the original computation graph, a first initial data type of the output data of the subgraph;
[0139] Determining a first final data type of output data of the subgraph according to the attribute information;
[0140] If the first initial data type and the first final data type are not the same, obtaining an output data type conversion operator;
[0141] Adjust the subgraph according to the output data type conversion operator to obtain a third adjusted subgraph;
[0142] The initial model file is compiled according to the attribute information, the sub-data format and the third adjusted sub-graph to obtain a final model file matching each processor.
[0143] If the first initial data type and the first final data type are different, it indicates that the first final data type needs to be converted into the first initial data type. Therefore, an output data type conversion operator can be added to the subgraph to convert the data type of the output data of the subgraph into the first initial data type, so that the data type of the output data when the final model file is subsequently run through the processor meets the user's requirements.
[0144] If the first initial data type and the first final data type are the same, indicating that the first final data type does not need to be converted, the model file can be directly compiled according to the attribute information, sub-data format and sub-graph to obtain the final model file that matches the processor.
[0145] For example, the processor is CoreML, and the first initial data type of the output data of CoreML is Flat32. If the first final data type of the output data of the original computation graph is Int8, an output data type conversion operator is added to the subgraph to obtain a third adjusted subgraph.
[0146] It should be understood that the terminal can also obtain the initial data type, the final data type, the first initial data type and the first final data type at the same time, and then adjust the sub-image according to the initial data type, the final data type, the first initial data type and the first final data type to obtain the fourth adjusted sub-image.
[0147] For example, the processor is CoreML, the initial data type of CoreML's input data is Int32, and the first initial data type of CoreML's output data is Flat32. If the final data type of the input data of the original calculation graph is Int64 and the first final data type of the output data of the original calculation graph is Int8, then a data type conversion operator and an output data type conversion operator are added to the subgraph to obtain the fourth adjusted subgraph.
[0148] In other embodiments, the initial model file is compiled based on the attribute information, sub-data format, and sub-graph to obtain a final model file that matches each processor, including:
[0149] Determine the type of operators in the subgraph;
[0150] If the type of the operator in the subgraph is a preset type, the operator in the subgraph is adjusted to obtain a second adjusted subgraph;
[0151] The initial model file is compiled according to the attribute information, the sub-data format and the second adjusted sub-graph to obtain a final model file matching each processor.
[0152] Since some operations can be implemented by different operators, and the speeds of running different operators through the processor are different, the preset type of the operator can be set in advance. If the type of the operator in the subgraph is the preset type, the operator in the subgraph is adjusted to obtain a second adjusted subgraph. Then, according to the attribute information, the sub-data format and the second adjusted subgraph, the initial model file is compiled and processed to obtain the final model file matching each processor, so that the processor is faster when running the operator in the final model file matching the processor.
[0153] For example, the addition operator in the subgraph can be converted into a subtraction operator, and the addition operation can be implemented through the subtraction operator. The division operator in the subgraph can be converted into a multiplication operator, and the division operation can be implemented through the multiplication operator. The convolution operator and the addition operator in the subgraph can be fused into one operator.
[0154] S204: When the data to be processed is input into the neural network model, the processor runs the final model file to process the data to be processed to obtain a processing result of the data to be processed.
[0155] The type of data to be processed can be selected according to actual conditions. For example, the data to be processed can be an image to be processed, or another example is that the data to be processed can be audio to be processed, etc. This embodiment of the present application does not limit this.
[0156] The type of processing for the data to be processed can be selected according to actual conditions. For example, the data to be processed can be classified, or text can be extracted from the data to be processed. This embodiment of the present application does not limit this.
[0157] After obtaining the final model file, the terminal may immediately run the final model file through the processor, or the terminal may also run the final model file through the processor after obtaining the running instruction.
[0158] If the terminal includes multiple processors, that is, there are multiple final model files matching the processors, the terminal can call each processor and run each final model file according to the execution order of the operators in each final model file.
[0159] For example, the final model file includes the final model file f1 and the final model file f2. The execution order of the operators in the final model file f1 precedes the execution order of the operators in the final model file f2. The final model file f1 is the final model file that matches the central processing unit, and the final model file f2 is the final model file that matches the neural network processor. After the terminal obtains the data to be processed, it first calls the central processing unit to run the final model file f1 to process the data to be processed to obtain candidate data, and then calls the neural network processor to run the final model file f2 to process the candidate data to obtain the processing result of the data to be processed, thereby realizing the processing of the data to be processed through the neural network model.
[0160] In some embodiments, the processor runs the final model file to process the data to be processed of the neural network model to obtain a processing result of the data to be processed, including:
[0161] Determine the data format of the data to be processed by the neural network model;
[0162] If the data format of the data to be processed does not match the sub-data format in the final model file, the data format of the data to be processed is adjusted to obtain the adjusted data to be processed;
[0163] The final model file is run by the processor to process the adjusted data to be processed, and a processing result of the data to be processed is obtained.
[0164] The mismatch between the data format of the data to be processed and the sub-data format in the final model file may refer to that the data format of the data to be processed is different from the sub-data format of the startup operator in the final model file.
[0165] For example, the final model file includes operator op1→operator op2→operator op3, and the data format of the to-be-processed data does not match the sub-data format in the final model file, which may mean that the data format of the to-be-processed data is different from the sub-data format of operator op1.
[0166] The terminal can obtain the sub-data format from the final model file, or, after obtaining the sub-data format, the terminal can associate the identifier of each operator with the sub-data format and store it in the format storage unit, and then obtain the sub-data format corresponding to the operator in the final model file from the format storage unit.
[0167] In an embodiment of the present application, before the data to be processed is processed through the final model file, the data format of the data to be processed is first checked. If the data format of the data to be processed does not match the sub-data format in the final model file, the data format of the data to be processed is corrected to obtain adjusted data to be processed; finally, the final model file is run by the processor to process the adjusted data to be processed, so as to process the adjusted data to be processed through the neural network model to obtain the processing result of the data to be processed.
[0168] During the final model file execution phase, the data format of the data to be processed is checked. If the data format of the data to be processed is found to be unreasonable, the data format of the data to be processed is corrected, thereby ensuring smooth execution of the processing of the data to be processed and obtaining accurate processing results.
[0169] In other embodiments, the processor runs the final model file to process the data to be processed of the neural network model to obtain a processing result of the data to be processed, including:
[0170] Processing the data to be processed by the neural network model by running the final model file through the processor to obtain a candidate processing result of the data to be processed;
[0171] determining an output data format of the candidate processing result;
[0172] According to the final model file, the output data format of the candidate processing results is adjusted to obtain the processing results of the data to be processed.
[0173] In an embodiment of the present application, when the data format is mapped according to the operator, the sub-data format of the operator's input data and the sub-data format of the output data can be obtained at the same time, that is, the final model file can simultaneously include the sub-data format of the input data and the sub-data format of the output data of each operator. Then, after obtaining the candidate processing result, the terminal can determine whether the output data format of the candidate processing result is the same as the sub-data format of the output data of the operator in the final model file. If not, the output data format of the candidate processing result is adjusted to the sub-data format of the output data of the operator in the final model file to obtain the processing result, thereby improving the accuracy of the processing result.
[0174] As can be seen from the above, in an embodiment of the present application, the data format of the input data of the neural network model is obtained, and the initial model file of the neural network model is obtained, and the initial model file includes the operator of the neural network model. Then, according to the operator, the data format is mapped to obtain the sub-data format of the input data of the operator; the attribute information of the processor is obtained, and according to the attribute information and the sub-data format, the model file is compiled to obtain a final model file that matches the processor, so that the final model file includes the sub-data format and the final model file is a file supported by the processor, so that when the data format of the data to be processed of the neural network model is the data format of the input data of the neural network model, the final model file can be run by the processor to process the data to be processed of the neural network model and obtain the processing result of the data to be processed. Since the data format of the input data of the neural network model can be any data format, the embodiment of the present application can realize the input of multiple data formats of the data to be processed to the processor, thereby improving the flexibility of the neural network model running by the processor in processing the data to be processed.
[0175] The method described in the above embodiment is further described in detail below with examples.
[0176] In this embodiment, the data format is a data shape, the sub-data format is a sub-data shape, the format mapping scheme is a shape mapping scheme, the to-be-processed data is an image, and the data processing is text extraction. This embodiment can be implemented using an inference engine, which is a system component that applies logical rules to a knowledge base to infer new information.
[0177] Please refer to Figure 3, which is a flow chart of a data processing method provided in an embodiment of the present application. The data processing method flow may include:
[0178] S301. The terminal obtains the data shape of the input data of the trained neural network model, and obtains the model file of the trained neural network model.
[0179] The model file of the trained neural network model includes the operators of the trained neural network model. The file format of the model file of the trained neural network model can be a general file, for example, the model file of the trained neural network model can be an Open Neural Network Exchange (ONNX) model file or an NCNN model file.
[0180] S302: The terminal converts the file format of the acquired model file to obtain an initial model file supported by the inference engine.
[0181] Since the inference engine has its own recognizable file format, after obtaining the model file of the trained neural network model, the terminal can convert the file format of the model file of the trained neural network model to obtain an initial model file supported by the inference engine.
[0182] For example, when the inference engine is a self-developed inference engine and the model file of the trained neural network model is an ONNX model file, the ONNX model file can be converted into an Extended Network (XNet) model file.
[0183] S303: The terminal obtains the shape mapping scheme corresponding to each operator in the initial model file, and performs mapping processing on the data shape through the shape mapping scheme to obtain the sub-data shape of the input data and the sub-data shape of the output data of the operator.
[0184] S304. The terminal stores the sub-data shape of the operator's input data and the sub-data shape of the operator's output data in the initial model file to obtain a candidate model file, and stores the sub-data shape of the operator's input data and the sub-data shape of the operator's output data in the format storage unit.
[0185] For example, the sub-data shape of the input data and the sub-data shape of the output data of the operator may be as shown in FIG4 in the format storage unit.
[0186] S301-S304 may be referred to as a model conversion phase, for example, as shown in Figure 5. The model conversion phase refers to converting an initial model file in a common file format into a model file in a file format automatically defined by the inference engine.
[0187] It should be understood that there can be at least one data shape. After mapping the data shapes, the sub-data shapes of the operator's input data and output data for each data shape can be obtained. In other words, the candidate model file and format storage unit can include the sub-data shapes of the operator's input data and output data for all data shapes.
[0188] S305. The terminal obtains an original calculation graph corresponding to the candidate model file. The original calculation graph includes nodes, each node represents an operator, and an edge of the original calculation graph represents a flow direction of data of the node.
[0189] S306. The terminal obtains the attribute information of the neural network processor and the attributes of the central processing unit, and divides the original calculation graph according to the attribute information to obtain a subgraph matching the neural network processor and a subgraph matching the central processing unit.
[0190] This step can be called the computational graph partitioning step. The computational graph partitioning step can be performed by the subgraph partitioning unit and the operator selection unit in the inference engine. The subgraph partitioning unit is a general unit that can be used to accelerate subgraph partitioning in hardware. Based on the operator selection unit, a subgraph is selected. All operators in the subgraph are operators selected by the operator selection unit, and there are no operators on the paths between operators in the subgraph that are not selected by the operator selection unit.
[0191] The operator selection unit is used to configure different neural network processors. Different neural network processors support different operators. The operator selection unit is used to select operators that are implemented in the neural network processor and have better performance.
[0192] S307. The terminal determines the initial data type of the input data and the first initial data type of the output data of the subgraph according to the original calculation graph, and determines the final data type of the input data and the first final data type of the output data of the subgraph according to the attribute information.
[0193] S308. If the initial data type is different from the final data type, the terminal obtains a data type conversion operator.
[0194] S309: If the first initial data type is different from the first final data type, the terminal obtains an output data type conversion operator.
[0195] S3010: The terminal adjusts the subgraph according to the data type conversion operator and / or the output data type conversion operator to obtain a fourth adjusted subgraph.
[0196] The subgraphs in S307-S3010 may be subgraphs that match the neural network processor and subgraphs that match the central processing unit. S307-S3010 may be referred to as subgraph legitimacy checking steps, which may be performed by a checking and correction unit. Specifically, the checking and correction unit is used to check whether the data type of the input data of the original computation graph is the same as the data type of the input data of the subgraph, and to check whether the data type of the output data of the original computation graph is the same as the data type of the output data of the subgraph.
[0197] S3011: The terminal determines the type of the operator in the fourth adjusted subgraph. If the type of the operator in the fourth adjusted subgraph is a preset type, the terminal adjusts the operator in the fourth adjusted subgraph to obtain a second adjusted subgraph.
[0198] S3012. The terminal compiles the candidate model file according to the attribute information and the second adjusted subgraph to obtain the final model file of the neural network processor and the final model file of the central processing unit.
[0199] Among them, S3012 can be executed by a conversion unit, that is, converting the operator definition in the candidate model file into the operator definition of the neural network processor and the operator definition of the central processing unit.
[0200] S3011 - S3012 may be referred to as subgraph optimization steps, which may be performed by a subgraph optimization unit configured to optimize the subgraph.
[0201] S305-S3012 can be called the model compilation phase, for example, as shown in Figure 5. The model compilation phase is performed once before the trained neural network model is executed, and a specific processor can be selected for implementation.
[0202] In one possible implementation, during the model compilation phase, the intermediate representation of the neural network processor can also be stored in the cache storage unit. For example, when the neural network processor is a CoreML processor, the mlmodelc file can be stored in the cache storage unit, and when the neural network processor is a processor produced by a specific manufacturer, the om file can be stored in the cache storage unit.
[0203] S3013. The terminal obtains the image to be processed of the trained neural network model and determines the data shape of the image tensor corresponding to the image to be processed.
[0204] S3014. The terminal obtains the sub-data shape of the input data of the sub-graph in the final model file of the neural network processor from the format storage unit, and checks the data shape of the image tensor based on the sub-data shape of the input data of the sub-graph in the final model file of the neural network processor.
[0205] S3015. If the data shape of the image tensor does not match the sub-data shape of the input data of the sub-graph in the final model file of the neural network processor, the terminal modifies the data shape of the image tensor to obtain an adjusted image tensor.
[0206] For example, the subgraph in the final model file of the neural network processor can be as shown in Figure 4. The subgraph includes operators op1, op2, op3, and op4. Operator op1 is an input node, that is, operator op1 is a starting operator. The data shape of the image tensor is checked according to the sub-data shape of the input data of operator op1.
[0207] S3016. The terminal calls the neural network processor to run the final model file of the neural network processor, performs feature processing on the adjusted image tensor, and obtains the original features corresponding to the image to be processed.
[0208] S3017. The terminal obtains the sub-data shape of the output data of the sub-graph in the final model file of the neural network processor from the format storage unit, and checks the output data shape of the original feature based on the sub-data shape of the output data of the sub-graph in the final model file of the neural network processor.
[0209] S3018. If the output data shape does not match the sub-data shape of the output data of the operator in the final model file of the neural network processor, the terminal modifies the output data shape of the original feature to the sub-data shape of the output data of the sub-graph in the final model file of the neural network processor to obtain the candidate feature corresponding to the image to be processed.
[0210] For example, the subgraph in the final model file of the neural network processor can be as shown in Figure 4. The subgraph includes operators op1, op2, op3, and op4. Operator op4 is the output node, that is, operator op4 is the last operator. The output data shape of the original feature is checked according to the sub-data shape of the output data of operator op4.
[0211] In an embodiment of the present application, the output data shape of the output data of the neural network model processor is checked to avoid errors in the data shape of the output data when there are multiple data shapes.
[0212] S3019. The terminal calls the central processing unit to run the final model file of the central processing unit, performs feature recognition on the candidate features, and obtains the text corresponding to the image to be processed.
[0213] When the terminal calls the central processing unit to run the final model file of the central processing unit, it can also check the data shape of the candidate features and the data shape of the text corresponding to the image to be processed. For details, please refer to the process of checking the data shape of the image tensor and the output data shape when calling the neural network processor to run the final model file of the neural network processor. The embodiments of this application will not be repeated here.
[0214] S3013-S3019 can be executed through a processing module, which can also be called an execution module. The execution module calls the interface improved by the manufacturer of the neural network processor to call the neural network processor.
[0215] S3013-S3019 can be called the model execution stage, that is, the process of deploying the trained neural network model to the neural network processor and the central processing unit in this embodiment, which can include the model conversion stage, the model compilation stage and the model execution stage.
[0216] Compared to central processing units (CPUs), neural network processors (NPUs) have greater computing power and are more focused on high-density computing. For example, the theoretical peak computing power of a NPU (theoretical peak computing power refers to the maximum number of floating-point / fixed-point calculations that the hardware can complete in a given period of time) reaches 11T FLOP / s (FLOP / s represents the number of floating-point calculations that can be completed per second), while the theoretical peak computing power of a large core of a central processing unit is only 96G FLOP / s.
[0217] Therefore, the embodiment of the present application deploys a trained neural network model through a neural network processor, which can improve the speed of extracting text from the image to be processed through the trained neural network model.
[0218] Furthermore, the central processing unit in the embodiment of the present application may be a self-developed high-performance processor. Deploying a trained neural network model on the self-developed high-performance processor may also improve the speed of extracting text from the image to be processed through the trained neural network model.
[0219] Since the power consumption of a neural network processor is lower than that of an image processor, the embodiment of the present application deploys a trained neural network model through a neural network processor, which can reduce the power consumption when extracting text from an image to be processed through the trained neural network model.
[0220] Therefore, an embodiment of the present application provides a usage framework for a neural network processor, which is combined with self-developed high-performance operators to greatly improve the text extraction speed of the trained neural network model deployed on the neural network processor and the central processing unit.
[0221] The specific implementation method and beneficial effects of this embodiment can be specifically referred to the above-mentioned data processing method embodiment, and this embodiment will not be repeated here.
[0222] To facilitate better implementation of the data processing method provided in the embodiment of the present application, the embodiment of the present application also provides a device based on the above data processing method. The meanings of the terms are the same as those in the above data processing method, and the specific implementation details can be referred to the description in the method embodiment.
[0223] For example, as shown in FIG6 , the data processing device may include:
[0224] The acquisition module 601 is used to obtain the data format of the input data of the neural network model and obtain the initial model file of the neural network model, where the initial model file includes the operators of the neural network model.
[0225] The mapping module 602 is used to perform mapping processing on the data format according to the operator to obtain the sub-data format of the operator's input data.
[0226] The compiling module 603 is used to obtain the attribute information of the processor and compile the initial model file according to the attribute information and the sub-data format to obtain the final model file of the processor.
[0227] The processing module 604 is used to process the data to be processed by running the final model file through the processor when the data to be processed is input into the neural network model to obtain the processing result of the data to be processed.
[0228] In a possible implementation, the mapping module 602 is specifically configured to perform:
[0229] Get the format mapping scheme corresponding to the operator;
[0230] The data format is mapped through the format mapping scheme to obtain the sub-data format of the operator's input data.
[0231] In a possible implementation, the mapping module 602 is specifically configured to perform:
[0232] Filter out the startup operator from the operators and use the data format as the sub-data format of the input data of the startup operator;
[0233] According to the startup operator, the sub-data format of the input data of the startup operator is mapped to obtain the sub-data format of the output data of the startup operator;
[0234] If there is a next operator in the operator list, the sub-data format of the output data of the starting operator is used as the data format, and the next operator is used as the starting operator. The process returns to the step of using the data format as the sub-data format of the input data of the starting operator.
[0235] If the next operator of the initiating operator does not exist in the operator, the sub-data format of the input data of the operator is determined according to the sub-data format of the input data of the initiating operator.
[0236] In a possible implementation, the mapping module 602 is specifically configured to perform:
[0237] Filtering out an operator to be processed from the operators, and determining a historical operator before the operator to be processed in the neural network model;
[0238] According to the historical operators, the data format is mapped to obtain the sub-data format of the input data of the operator to be processed;
[0239] The sub-data format of the input data of the operator to be processed is determined according to the sub-data format of the input data of the operator to be processed.
[0240] In a possible implementation, the mapping module 602 is specifically configured to perform:
[0241] Determine conversion model parameters based on model parameters of historical operators;
[0242] According to the conversion model parameters, the data format is mapped to obtain the sub-data format of the input data of the operator to be processed.
[0243] In a possible implementation, the processor includes multiple processors. Accordingly, the compiling module 603 is specifically configured to execute:
[0244] Get the original computation graph, which includes nodes, each of which represents an operator.
[0245] According to the attribute information, the original computation graph is divided into subgraphs matching each processor;
[0246] According to the attribute information, sub-data format and sub-graph, the initial model file is compiled and processed to obtain the final model file of each processor.
[0247] In a possible implementation, the compiling module 603 is specifically configured to execute:
[0248] According to the original computation graph, determine the initial data type of the subgraph’s input data;
[0249] Determine the final data type of the input data of the subgraph according to the attribute information;
[0250] The model file is compiled according to the attribute information, sub-data format, initial data type and final data type to obtain the final model file of each processor.
[0251] In a possible implementation, the compiling module 603 is specifically configured to execute:
[0252] If the initial data type and the final data type are different, obtain the data type conversion operator;
[0253] Adjust the subgraph according to the data type conversion operator to obtain a first adjusted subgraph;
[0254] The initial model file is compiled according to the attribute information, the sub-data format and the first adjusted sub-graph to obtain a final model file for each processor.
[0255] In a possible implementation, the compiling module 603 is specifically configured to execute:
[0256] Determine the type of operators in the subgraph;
[0257] If the type of the operator in the subgraph is a preset type, the operator in the subgraph is adjusted to obtain a second adjusted subgraph;
[0258] The initial model file is compiled according to the attribute information, the sub-data format and the second adjusted sub-graph to obtain a final model file for each processor.
[0259] In a possible implementation, the processing module 604 is specifically configured to execute:
[0260] Determine the data format of the data to be processed by the neural network model;
[0261] If the data format of the data to be processed does not match the sub-data format in the final model file, the data format of the data to be processed is adjusted to obtain the adjusted data to be processed;
[0262] The final model file is run by the processor to process the adjusted data to be processed, and a processing result of the data to be processed is obtained.
[0263] In a possible implementation, the processing module 604 is specifically configured to execute:
[0264] Processing the data to be processed by the neural network model by running the final model file through the processor to obtain a candidate processing result of the data to be processed;
[0265] determining an output data format of the candidate processing result;
[0266] According to the final model file, the output data format of the candidate processing results is adjusted to obtain the processing results of the data to be processed.
[0267] During specific implementation, the above modules can be implemented as independent entities, or they can be arbitrarily combined and implemented as the same or several entities. The specific implementation methods and corresponding beneficial effects of the above modules can be found in the previous method embodiments and will not be repeated here.
[0268] The embodiment of the present application further provides an electronic device, which may be a server or a terminal, etc. As shown in FIG7 , it shows a schematic diagram of the structure of the electronic device involved in the embodiment of the present application. Specifically:
[0269] The electronic device may include components such as a processor 701 with one or more processing cores, a memory 702 with one or more computer-readable storage media, a power supply 703, and an input unit 704. Those skilled in the art will appreciate that the electronic device structure shown in FIG7 does not limit the electronic device and may include more or fewer components than shown, or combine certain components, or arrange the components differently.
[0270] Processor 701 is the control center of the electronic device. It connects all parts of the electronic device using various interfaces and circuits. It executes computer programs and / or modules stored in memory 702 and accesses data stored in memory 702 to perform various functions of the electronic device and process data. Optionally, processor 701 may include one or more processing cores. Preferably, processor 701 may integrate an application processor and a modem processor. The application processor primarily handles the operating system, user interface, and application programs, while the modem processor primarily handles wireless communications. It is understood that the modem processor may not be integrated into processor 701.
[0271] The memory 702 can be used to store computer programs and modules. The processor 701 executes various functional applications and data processing by running the computer programs and modules stored in the memory 702. The memory 702 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, a computer program required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 702 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage device. Accordingly, the memory 702 may also include a memory controller to provide the processor 701 with access to the memory 702.
[0272] The electronic device also includes a power supply 703 for supplying power to various components. Preferably, the power supply 703 can be logically connected to the processor 701 via a power management system, thereby enabling the power management system to manage charging, discharging, and power consumption. The power supply 703 can also include one or more DC or AC power supplies, a recharging system, a power failure detection circuit, a power converter or inverter, a power status indicator, and other arbitrary components.
[0273] The electronic device may further include an input unit 704, which may be configured to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function control.
[0274] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail herein. Specifically, in this embodiment, the processor 701 in the electronic device loads the executable files corresponding to one or more computer program processes into the memory 702 according to the following instructions, and the processor 701 runs the computer program stored in the memory 702, thereby implementing the data processing method provided in the aforementioned embodiment.
[0275] The specific implementation methods and corresponding beneficial effects of the above operations can be found in the detailed description of the data processing method above, which will not be repeated here.
[0276] Those skilled in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be accomplished by a computer program, or by controlling related hardware through a computer program. The computer program may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0277] To this end, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. The computer program can be loaded by a processor to execute the steps of any data processing method provided in the embodiment of the present application.
[0278] The specific implementation methods and corresponding beneficial effects of the above operations can be found in the previous embodiments and will not be described in detail here.
[0279] The computer-readable storage medium may include a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0280] Since the computer program stored in the computer-readable storage medium can execute the steps in any data processing method provided in the embodiments of the present application, the beneficial effects that can be achieved by any data processing method provided in the embodiments of the present application can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0281] According to one aspect of the present application, a computer program product is provided, the computer program product including a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium and executes the computer program, causing the computer device to perform the above-mentioned data processing method.
[0282] The above is a detailed introduction to a data processing method, device, equipment, storage medium and program product provided in the embodiments of the present application. Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core ideas. At the same time, for technical personnel in this field, based on the ideas of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A data processing method, applied to an electronic device, wherein the electronic device includes a processor, and the method includes: Acquire the data format of input data of the neural network model, and acquire the initial model file of the neural network model, wherein the initial model file includes operators of the neural network model; According to the operator, mapping processing is performed on the data format to obtain a sub-data format of the input data of the operator; Acquire the attribute information of the processor, and compile the initial model file according to the attribute information and the sub-data format to obtain a final model file of the processor; When the data to be processed is input into the neural network model, the processor runs the final model file to process the data to be processed to obtain a processing result of the data to be processed.
2. The data processing method according to claim 1, wherein mapping the data format according to the operator to obtain the sub-data format of the input data of the operator comprises: Obtaining a format mapping scheme corresponding to the operator; The data format is mapped using the format mapping solution to obtain a sub-data format of the input data of the operator.
3. The data processing method according to claim 1 or 2, wherein mapping the data format according to the operator to obtain the sub-data format of the input data of the operator comprises: Filtering out a startup operator from the operators, and using the data format as a sub-data format of input data of the startup operator; According to the startup operator, mapping processing is performed on the sub-data format of the input data of the startup operator to obtain the sub-data format of the output data of the startup operator; If the next operator of the start operator exists in the operator, the sub-data format of the output data of the start operator is used as the data format, and the next operator is used as the start operator, and the step of using the data format as the sub-data format of the input data of the start operator is returned to be executed; If the next operator of the initiating operator does not exist in the operators, the sub-data format of the input data of the operator is determined according to the sub-data format of the input data of the initiating operator.
4. The data processing method according to any one of claims 1 to 3, wherein mapping the data format according to the operator to obtain the sub-data format of the input data of the operator comprises: Filtering out an operator to be processed from the operators, and determining a historical operator before the operator to be processed in the neural network model; According to the historical operator, mapping processing is performed on the data format to obtain a sub-data format of the input data of the operator to be processed; According to the sub-data format of the input data of the operator to be processed, the sub-data format of the input data of the operator is determined.
5. The data processing method according to claim 4, wherein mapping the data format according to the historical operator to obtain the sub-data format of the input data of the operator to be processed comprises: Determining conversion model parameters according to the model parameters of the historical operator; According to the conversion model parameters, the data format is mapped to obtain the sub-data format of the input data of the operator to be processed.
6. The data processing method according to any one of claims 1 to 5, wherein the processor comprises a plurality of processors, and the initial model file is compiled according to the attribute information and the sub-data format to obtain the final model file of the processor, comprising: Obtaining an original computation graph, wherein the original computation graph includes nodes, and the nodes represent the operators; According to the attribute information, the original computation graph is divided to obtain a subgraph matching each of the processors; The initial model file is compiled according to the attribute information, the sub-data format and the sub-graph to obtain a final model file of each processor.
7. The data processing method according to claim 6, wherein the initial model file is compiled according to the attribute information, the sub-data format and the sub-graph to obtain a final model file for each processor, comprising: Determine the initial data type of the input data of the subgraph according to the original computation graph; Determining, according to the attribute information, a final data type of the input data of the subgraph; The initial model file is compiled according to the attribute information, the sub-data format, the initial data type and the final data type to obtain a final model file for each processor.
8. The data processing method according to claim 7, wherein the initial model file is compiled according to the attribute information, the sub-data format, the initial data type and the final data type to obtain the final model file of each processor, comprising: If the initial data type and the final data type are different, obtaining a data type conversion operator; Adjust the subgraph according to the data type conversion operator to obtain a first adjusted subgraph; The initial model file is compiled according to the attribute information, the sub-data format and the first adjusted sub-graph to obtain a final model file for each of the processors.
9. The data processing method according to any one of claims 6 to 8, wherein the initial model file is compiled according to the attribute information, the sub-data format and the sub-graph to obtain a final model file for each processor, comprising: Determine the type of operator in the subgraph; If the type of the operator in the subgraph is a preset type, adjusting the operator in the subgraph to obtain a second adjusted subgraph; The initial model file is compiled according to the attribute information, the sub-data format and the second adjusted sub-graph to obtain a final model file for each of the processors.
10. The data processing method according to any one of claims 1 to 9, wherein the processor runs the final model file to process the data to be processed of the neural network model to obtain the processing result of the data to be processed, comprising: Determining the data format of the data to be processed by the neural network model; If the data format of the data to be processed does not match the sub-data format in the final model file, adjusting the data format of the data to be processed to obtain adjusted data to be processed; The processor runs the final model file to process the adjusted data to be processed, and obtains a processing result of the data to be processed.
11. The data processing method according to any one of claims 1 to 10, wherein the processing of the to-be-processed data of the neural network model by running the final model file by the processor to obtain the processing result of the to-be-processed data comprises: The processor runs the final model file to process the data to be processed of the neural network model to obtain a candidate processing result of the data to be processed; Determining an output data format of the candidate processing result; According to the final model file, the output data format of the candidate processing result is adjusted to obtain the processing result of the data to be processed.
12. A data processing device, applied to an electronic device, wherein the electronic device comprises a processor, comprising: An acquisition module, used to acquire the data format of input data of a neural network model, and to acquire an initial model file of the neural network model, wherein the initial model file includes operators of the neural network model; A mapping module, used to perform mapping processing on the data format according to the operator to obtain a sub-data format of the input data of the operator; A compiling module, used for acquiring the attribute information of the processor, and compiling the initial model file according to the attribute information and the sub-data format to obtain a final model file of the processor; A processing module is used to process the data to be processed by running the final model file through the processor when the data to be processed is input into the neural network model, so as to obtain the processing result of the data to be processed.
13. An electronic device comprising a processor and a memory, wherein the memory stores a computer program, and the processor is used to run the computer program in the memory to execute the data processing method according to any one of claims 1 to 11.
14. A computer-readable storage medium storing a computer program, wherein the computer program is suitable for being loaded by a processor to execute the data processing method according to any one of claims 1 to 11.
15. A computer program product, wherein the computer program product stores a computer program, wherein the computer program is suitable for being loaded by a processor to execute the data processing method according to any one of claims 1 to 11.
Citation Information
Patent Citations
Neural network operator division method, device and equipment
CN111860820A
Operation method and device, electronic equipment and storage medium
CN112947935A
Method and device for inserting conversion operator
CN113449841A
Model processing method and device, electronic equipment and storage medium
CN115660049A
Electronic device with storage device implementation
US20220066660A1
Cited By
Data updating method and device and electronic equipment
CN119848061A
