A method and device for determining and operating an operator
Through recursive search and depth-first traversal, the operator with the best performance in the neural network model is determined, which solves the problem of wasting computing resources of the neural network model on complex platforms and achieves efficient multi-platform deployment and performance improvement.
Patent Information
- Application Number
- CN202110461352.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-04-27
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-04-27
AI Technical Summary
When existing neural network models are run on complex computing platforms, it is difficult to select operators with excellent performance, resulting in a waste of computing resources and performance bottlenecks, especially when deployed on mobile devices.
By obtaining the search space of the operation to be searched in the neural network, running multiple operators, and recursively searching according to the operating parameters to determine the target operator with the best performance, combined with the depth-first traversal and deduplication mechanism to ensure that the optimal operation is also selected for dependent operations. sub, providing a unified interface to hide platform details.
It significantly improves the performance of neural networks, reduces search time and computing resource overhead, is suitable for multi-platform deployment, and enhances the performance of neural network models on mobile devices.
Smart Images

Figure CN113312175B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of artificial intelligence technology, and in particular to an operator determination and operation method and device. Background Art
[0002] In recent years, with the explosive research and development of neural networks, their powerful feature extraction and fitting capabilities have enabled them to be widely used in image recognition, natural language processing, speech recognition and other fields. In order to improve the performance of neural network models, researchers generally design deeper and more complex networks, which greatly increases the number of model parameters and the amount of calculation, resulting in higher and higher requirements for hardware resources (such as CPU, memory, bandwidth), and very expensive costs. At the same time, it is also very difficult to directly deploy such a complex neural network on mobile devices with limited computing power and battery life (such as mobile phones, drones, robots, smart glasses), which limits its wider application. Therefore, researchers also consider improving the performance of neural network models by speeding up the network's computing speed.
[0003] Existing neural networks are generally composed of various operations, among which the most commonly used operations include convolution and matrix multiplication. Because of the huge amount of calculation involved, the running speed of convolution and matrix multiplication has a decisive influence on the training and reasoning performance of neural networks. In order to make full use of the architectural features of each computing platform to obtain a better acceleration effect, convolution and matrix multiplication operations are often subdivided into various operators in engineering practice. Different operators are oriented to different scenarios, and their performance under different operating configurations is also different, and there may be mutual dependence between operators of different operations. In order to meet the demand for computing power of neural networks, in recent years, not only traditional computing platforms such as CPUs and GPUs have begun to accelerate the speed of updates and iterations, but also new embedded neural network processors (NPUs) have gradually emerged, and the platforms that neural networks need to adapt to are becoming increasingly complex. For a given neural network model and operating environment, how to select operators with excellent performance from many operators has become a difficult problem. Summary of the invention
[0004] The present invention aims to solve the technical problems in the related art at least to a certain extent. To achieve the above object, in a first aspect, the present invention provides an operator determination method, which comprises:
[0005] Acquire a first search space corresponding to the operation to be searched in the neural network, wherein the first search space includes a plurality of operators;
[0006] Running the multiple operators of the first search space, when a first operator among the multiple operators calls a target operation, searching a second search space corresponding to the target operation; and
[0007] According to the operating parameters of the multiple operators, a target operator corresponding to the operation to be searched is determined from the multiple operators.
[0008] To achieve the above object, in a second aspect, the present invention provides an operator determination device, comprising:
[0009] An acquisition module, used to acquire a first search space corresponding to the operation to be searched in the neural network, wherein the first search space includes a plurality of operators;
[0010] A search module, configured to run the multiple operators in the first search space, and when a first operator among the multiple operators calls a target operation, search a second search space corresponding to the target operation;
[0011] A determination module is used to determine a target operator corresponding to the operation to be searched from the multiple operators according to the operating parameters of the multiple operators.
[0012] Using the operator determination method or device of the present invention, by obtaining all operators running on the target platform of the operation to be searched as the first search space, running multiple operators in the first search space, and determining their corresponding operating parameters, and finding the target operator with the best performance according to the operating parameters. And determine the target operation that the first operator depends on through recursive search, and recursively search the operator and its dependent operations through depth-first traversal and other methods to ensure that when the operator calls the target operation, the operation it depends on will also select the target operator, and design a deduplication mechanism to avoid redundant search, further reducing the search time and computing resource overhead. The present invention also considers how to provide a unified user interface when the model needs to be deployed on multiple platforms, hide the platform details, and provide users with a unified representation, which is very practical for the deployment scenario of the neural network model.
[0013] To achieve the above object, in a third aspect, the present invention provides a method for operating a neural network, comprising:
[0014] Determine all operations performed by the neural network during its operation; and
[0015] During the operation of the neural network, a target operator of each operation is executed, wherein the target operator is determined using the operator determination method as described above.
[0016] To achieve the above-mentioned object, in a fourth aspect, the present invention provides a neural network operation device, comprising:
[0017] A processing module, configured to determine all operations performed when the neural network is running;
[0018] An operation module is used to execute the target operator of each operation during the operation of the neural network, wherein the target operator is determined using the operator determination method as described above.
[0019] The method or device for operating a neural network of the present invention obtains the cache serialization file of the target operator of each operation on the corresponding target platform, deserializes it to determine the corresponding target operator, and operates according to the target operator. When the operator calls the target operation, it ensures that the operation it depends on will also select the target operator, thereby greatly enhancing the performance of the neural network and having strong practicality for the training and deployment of neural networks with interdependent operations.
[0020] To achieve the above-mentioned purpose, in a fifth aspect, the present invention provides a non-temporary computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it implements the operator determination method according to the first aspect of the present invention or the neural network operation method according to the third aspect of the present invention.
[0021] To achieve the above-mentioned objectives, in a sixth aspect, the present invention provides a computing device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the operator determination method according to the first aspect of the present invention or the neural network operation method according to the third aspect of the present invention is implemented.
[0022] The non-temporary computer-readable storage medium and computing device according to the present invention have similar beneficial effects as the operator determination method according to the first aspect of the present invention or the neural network operation method according to the third aspect of the present invention, which will not be described in detail here. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 A schematic diagram of a flow chart of an operator determination method according to an embodiment of the present invention;
[0024] Figure 2 A schematic diagram of a process for determining a target operator according to an embodiment of the present invention;
[0025] Figure 3 A schematic diagram of a multi-process search according to an embodiment of the present invention;
[0026] Figure 4 A schematic diagram of a recursive search process according to an embodiment of the present invention;
[0027] Figure 5 A schematic diagram of a process for recursively determining operating parameters according to an embodiment of the present invention;
[0028] Figure 6 A schematic diagram of a multi-operator dependency search according to an embodiment of the present invention;
[0029] Figure 7 A schematic diagram of the structure of an operator determination device according to an embodiment of the present invention;
[0030] Figure 8 A schematic diagram of a flow chart of a method for operating a neural network according to an embodiment of the present invention;
[0031] Fig. 9 A schematic diagram of the operation of running a neural network model according to an embodiment of the present invention;
[0032] Fig.10 Schematic diagram of the structure of a neural network operating device according to an embodiment of the present invention. DETAILED DESCRIPTION
[0033] The embodiments of the present invention will be described in detail below with reference to the accompanying drawings. When describing the drawings, unless otherwise indicated, the same reference numerals in different drawings represent the same or similar elements. It should be noted that the embodiments described in the following exemplary embodiments do not represent all embodiments of the present invention. They are only examples of devices and methods consistent with some aspects disclosed in the present invention as detailed in the claims, and the scope of the present invention is not limited to this. The features of the various embodiments of the present invention can be combined with each other without contradiction.
[0034] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In the description of the present invention, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.
[0035] In recent years, deep neural networks have been widely used in image recognition, speech recognition, autonomous driving, natural language processing and other fields due to their good generalization and easy training. At the same time, due to the continuous expansion of applications and the continuous increase in data volume, neural networks have an increasing demand for computing power. In order to meet the demand for computing power from neural networks, in recent years, not only have traditional computing platforms such as CPUs and GPUs begun to accelerate the pace of updates and iterations, but new embedded neural network processors (NPUs) have also gradually emerged, and the platforms that neural networks need to adapt to are becoming increasingly complex.
[0036] Neural networks are generally composed of various operations, among which the most commonly used operations are convolution and matrix multiplication. Because of the huge amount of calculation involved, the running speed of convolution and matrix multiplication has a decisive influence on the training and reasoning performance of neural networks. In order to make full use of the architectural features of each computing platform to obtain a better acceleration effect, convolution and matrix multiplication operations are often subdivided into various operators in engineering practice. Different operators are oriented to different scenarios, and their performance under different operating configurations is also different. In addition, operators of different operations may be interdependent.
[0037] Given a neural network model and operating environment, how to select an operator with excellent performance from many operators becomes a difficult problem. Existing work mainly adopts two strategies, heuristic search and brute force search, to select the optimal operator. Among them, heuristic search is divided into two types, one is based on rules set by manual experience, and the other is to use machine learning and neural networks as heuristic algorithms. Brute force search will traverse and execute all operators and finally select an operator with the shortest time. However, the heuristic method and brute force search method still have the following problems:
[0038] (1) It is impossible to reduce the search time and system resource overhead while selecting the optimal operator. The principle of the heuristic method is based on empirical guesswork. This method can often only find the local optimal solution rather than the global optimal solution. Although the brute force search algorithm can find the global optimal solution, since it needs to run all operators, its search time is generally hundreds of times the running time of the neural network, and the search process may fail due to insufficient computing resources.
[0039] (2) There is no scientific and unified management of multiple computing platforms. Different computing platforms may have different search strategies, and the existing solutions do not unify the search interfaces of multiple computing platforms.
[0040] (3) There is no fundamental solution to the operator dependency problem. The existing solutions do not solve the problem that an operator of an algorithm may call multiple other algorithms.
[0041] The present invention ensures that the operator with the best performance is selected by actually running the operator on the target platform, and solves the problems of slow operation and high resource demand of traditional brute force search methods by dynamically pruning the operator search space. The operator and its dependent operations are recursively searched by depth-first traversal, and a deduplication mechanism is designed to avoid redundant searches, further reducing search time and computing resource overhead. The present invention also extracts the abstract interface of the search strategy of multiple platforms, hides the platform details, and provides users with a unified representation, effectively unifying the search interface of multiple platforms and improving search efficiency.
[0042] First, some concepts are defined to better explain the present invention.
[0043] operation: various operations in neural networks.
[0044] operation id: operation ID, used to distinguish different operations.
[0045] shape: shape, used to describe data.
[0046] param: User-defined properties of the operation.
[0047] device id: platform ID, used to distinguish different platforms.
[0048] cache: The cache that stores search results.
[0049] Hit: The cache contains the content being searched.
[0050] OpenCL: A mobile GPU paradigm.
[0051] Figure 1 FIG. 1 is a flow chart of an operator determination method according to an embodiment of the present invention, including steps S1 to S3 .
[0052] In step S1, a first search space corresponding to the operation to be searched in the neural network is obtained, and the first search space includes multiple operators. In an embodiment of the present invention, an interface is provided to return a list of searchable operations, and only those operations implemented by multiple operators can be searched, such as matrix multiplication, convolution operations, etc. After the user sets the operation to be searched and the target platform, all operators running the operation on the target platform can be determined to constitute the first search space of the operation. It can be understood that when the user does not want to search for a certain convolution in the model, the convolution operation can be set not to be searched through the configuration file.
[0053] In the embodiment of the present invention, applicable neural network operations include but are not limited to matrix multiplication, convolution, deconvolution, and pooling operations. Operators are specific implementation methods of operations. For example, operators of convolution operations can include fast Fourier operators, winograd operators, direct convolution operators, im2col operators, etc. Different operators of these operations have different performances under different operating configurations, such as different hardware and different input sizes. Therefore, for each operation, a search is required to obtain the operator with the best performance of the operation.
[0054] In an embodiment of the present invention, after the user has set the operation to be searched and the target platform, it can be determined that the key in the cache is set to a four-tuple of (device id, operation id, shape, param). What is stored in the cache is a key-value pair, and the value corresponding to the key can be uniquely found through the key. The key of the cache is a unique identifier. For example, cache c = {1: "operation1", 2: "operation2"}, where c represents cache, 1 and 2 represent keys, respectively, and "operation1" and "operation2" represent the values corresponding to key 1 and key 2. It can be understood that the multi-data group that constitutes the key can also be set according to the actual application scenario, and the present invention does not limit this.
[0055] In step S2, the multiple operators in the first search space are run, and when a first operator among the multiple operators calls a target operation, a second search space corresponding to the target operation is searched.
[0056] In step S3, according to the operating parameters of the multiple operators, the target operator corresponding to the operation to be searched is determined from the multiple operators. In an embodiment of the present invention, the operating parameters include the operating time of the operator and / or the computing resources occupied by the operator during operation, and the target operator includes an operator whose operating parameters meet the operating conditions, and the operating conditions include the shortest operating time of the operator and / or the best operating performance of the operator. It can be understood that the target operator represents an operator that meets certain operating conditions, such as the shortest operating time and the best operating performance, where the operating performance can be calculated, for example, based on the operating time and the occupied computing resources. In some embodiments, the target operator with the best operating performance is, for example, an operator with a short operating time and the least occupied computing resources, but the embodiment of the present invention is not limited thereto. In an embodiment of the present invention, the corresponding operating parameters are selected according to the operating conditions that the target operator needs to meet for calculation and statistics, thereby determining the target operator corresponding to the operation to be searched. The above-mentioned shortest operating time and / or the best operating performance as operating conditions are only exemplary descriptions, and the present invention is not limited thereto.
[0057] Figure 2 It is a schematic diagram of a process of determining a target operator according to an embodiment of the present invention, including steps S31 to S33.
[0058] In step S31, the ranking of the multiple operators is obtained. In an embodiment of the present invention, all operators in the first search space can be ranked according to rules set by manual experience, thereby, the search for the target operator can be run more optimally, and when a certain operation is not searched, the operation can also select an operator with the best possible performance to run. The ranking rules can be given by manual testing, for example, and the rules are set based on manual experience. For example, for the convolution operator under the CPU platform, the operator written in assembly language is the fastest, so it is ranked first, the performance written in NEON language is second, followed by the fallback operator written in C++, and finally the brute force operator written in C++.
[0059] In step S32, a corresponding subprocess is created for the operator, and an execution configuration is passed to the subprocess, where the execution configuration includes historical optimal operating parameters. Figure 3 The figure shows a schematic diagram of a multi-process search according to an embodiment of the present invention. In the embodiment of the present invention, each operator to be run is used as a parent process. According to the operating environment configuration specified in the target platform, the required computing resources are allocated for the operator, and a child process is created to execute the operator and count the running time. Among them, the parent process needs to pass the execution configuration to the child process, and the execution configuration includes the computing resources required by the child process, the relevant parameters of the operator to be executed by the child process, and the historical optimal operating parameters, such as the historical shortest operator running time. It can be understood that the historical shortest operator running time is the shortest operator running time currently maintained in a search space. As the optimal operator search proceeds, the historical shortest operator running time may change. In the execution configuration passed from the parent process to the child process, the current latest historical shortest operator running time is always passed to the child process. That is, in the embodiment of the present invention, the current latest historical optimal operating parameters are always passed to the child process.
[0060] In step S33, according to the order of the multiple operators, the subprocesses corresponding to each of the operators are run in sequence until the subprocesses corresponding to each of the operators are terminated, the operating parameters of each of the operators are determined according to the operating results of the subprocesses, and the operators whose operating parameters meet the operating conditions and / or whose operating parameters are less than the historical optimal operating parameters are used as the target operators of the operations to be searched. In an embodiment of the present invention, the subprocesses corresponding to all operators are run in sequence, the operating parameters corresponding to each subprocess are determined until the subprocesses corresponding to each of the operators are terminated, and the operators whose operating parameters meet the operating conditions and / or whose operating parameters are less than the historical optimal operating parameters are used as the target operators of the operations to be searched, for example, the operator corresponding to the subprocess with the best operating parameters is determined as the target operator of the operations to be searched.
[0061] In an embodiment of the present invention, the subprocess is run according to the configuration transfer, and the running parameters of the subprocess are recorded. When the running parameters of the subprocess exceed the historical optimal running parameters contained in the execution configuration (for example, when the running time of the subprocess exceeds the historical shortest operator running time contained in the execution configuration), it means that the operator being run cannot be the operator with the best performance, and there is no need to continue running the operator. The running of the subprocess is directly settled and the invalid running time is returned to the parent process. The parent process recycles the computing resources opened up in step S32 and then starts running the next operator. Therefore, it is not necessary to run all operators completely. By dynamically pruning the operator running, the problems of slow running and large resource requirements of the traditional brute force search method are solved, the search efficiency is effectively improved, and computing resources are saved. It can be understood that, considering the performance jitter in the actual environment, a certain fault tolerance mechanism can be given in the embodiment of the present invention, that is, the time to wait before the subprocess ends is the historical shortest operator running time plus the fault tolerance time, so as to improve the stability and reliability of the search operation.
[0062] In an embodiment of the present invention, after each operator in the search space is run once, the operator with the best running parameters can be determined as the target operator of the operation, that is, when the subprocesses created for each operator are completed, it indicates that each operator has been run once, and the shortest running time can be determined based on the running time returned by the subprocess of each operator, and the corresponding operator is the target operator of the operation.
[0063] In an embodiment of the present invention, after a target operator of an operation is determined, the determined target operator is written into a cache in a cache format, wherein the cache format includes a tuple formed according to the attributes of the operating platform and the attributes of the operation to be searched, for example, a four-tuple (device id, operation id, shape, param) is used as a key, and the operator serialized target is written into the cache as a value, that is, all searched operating configurations (deviceid, operation id, shape, param) and the target operator with the best performance under the configuration are saved in the cache.
[0064] In an embodiment of the present invention, when the running operator needs to call the target operation, a recursive search is performed to determine the target operation called by the operator and its corresponding optimal operator and running time. The operator and its dependent operations are recursively searched through a depth-first traversal method, and a deduplication mechanism is designed to avoid redundant searches, thereby further reducing search time and computing resource overhead. Figure 4 It is a schematic diagram of the process of recursive search according to an embodiment of the present invention, including steps S331 to S332.
[0065] In step S331, a target operator corresponding to a target operation called by each first operator and an operating parameter corresponding to the target operator of the target operation are determined. Figure 5 It is a schematic diagram of a process of recursively determining operating parameters according to an embodiment of the present invention, including steps S3311 to S3315.
[0066] In step S3311, a second search space corresponding to the target operation called by the first operator is determined. In an embodiment of the present invention, the second search space of the next level target operation called by the operator is determined according to the target platform, that is, all operators of the next level operation called by the operator running in the target platform. Figure 6 The figure shows a schematic diagram of a multi-operator dependency search according to an embodiment of the present invention. In the embodiment of the present invention, an operator of operation0 needs to call operation1 and operation3, and the search space of operation1 and operation3 is the second search space corresponding to the target operation called by the operator.
[0067] In step S3312, it is determined whether each operator in the second search space continues to call other target operations, and the corresponding second search space is determined until the bottom-level search space is reached, and the operators in the bottom-level search space no longer call the target operation. In an embodiment of the present invention, if an operator of operation1 needs to call operation2, the search space of operation2 is the corresponding second search space. Similarly, if an operator of operation3 also needs to call operation2, the search space of operation2 is also the corresponding second search space. However, if the operators of operation2 do not need to call the target operation, the search space of operation2 is the bottom-level search space.
[0068] In step S3313, the target operator and the corresponding operating parameters in the bottom-level search space are determined, written into the cache and passed to the upper-level search space. In an embodiment of the present invention, the first search space of operation2 is determined and all operators in the search space are run according to the above method, so as to determine the target operator of operation2 and its operating parameters, and write the search results into the cache according to the above cache format. It can be understood that after the target operator of operation2 is determined and written into the cache, the operating parameters of the target operator are returned to the upper-level search space (i.e., the search space of operation1 and operation3) as the operating parameters of the operator that calls operation2.
[0069] In step S3314, the target operator and the corresponding operating parameters in each level of search space are determined in turn and written into the cache until the second search space corresponding to the target operation called by the first operator is returned. In an embodiment of the present invention, all operators are continued to be run in the second search space of operation1 and the target operator and its operating parameters of operation1 are determined. It can be understood that the operating parameters of the operator that calls operation2 are the operating parameters of the target operator of operation2 determined in the above steps. Similarly, all operators are continued to be run in the second search space of operation3 and the target operator and its operating parameters of operation3 are determined. It can be understood that the operating parameters of the operator that calls operation2 are also the operating parameters of the target operator of operation2.
[0070] In step S3315, the target operator and its operating parameters corresponding to the target operation called by the first operator are determined according to the operating parameters of the operator in the second search space. In an embodiment of the present invention, the operating parameters of the operator at the previous level are determined according to the corresponding operating parameters of the target operator in each level of the search space. It can be understood that when an operator only calls one operation, the operating time of the target operator of the operation is used as the operating parameter of the operator, for example, the operator that calls operation2 in operation1, and its operating time is the operating parameter of the target operator of operation2; when an operator calls multiple operations, the operating parameters of the operator are determined according to the operating parameters of the target operation called by it, for example, the operator that calls operation1 and operation3 in operation0, and its operating parameters are determined according to the operating parameters of the target operators of operation1 and operation3. This can effectively solve the problem of operator dependency, while ensuring that the operation it depends on will also select the optimal operator.
[0071] In step S332, the operator whose operating parameters in the first search space meet the operating conditions and / or whose operating parameters are less than the historical optimal operating parameters is determined as the target operator. In an embodiment of the present invention, when the operator calls the target operation, its corresponding operating parameters are determined according to the above-mentioned recursive search. For the operator that does not call the target operation, the subprocess is directly run to record its operating parameters. It can be understood that when the operating parameters of the subprocess are better than the historical optimal operating parameters, the subprocess is directly closed and the subprocess of the next operator is entered for operation. After running all the operators in the first search space, the operator corresponding to the subprocess whose operating parameters meet the operating conditions and / or whose operating parameters are less than the historical optimal operating parameters can be selected as the target operator according to the operating parameters of each operator.
[0072] In the embodiment of the present invention, the cache is searched for the target operator of the next level operation to be called; when the cache contains the target operator of the next level operation to be called, the next level operation is no longer searched. Figure 6 As shown, both operation1 and operation3 call operation2. For example, when searching for the target operator of operation1, the target operator of operation2 will be searched recursively. After the search for the target operator of operation2 is completed, the result will be written into the cache. Then, when searching for the target operator of operation3, when the operator that needs to call operation2 is run, the cache is first searched to see whether the target operator of operation2 exists. If the cache hits, the running parameters of the target operator of operation2 are directly returned without having to search operation2 again. In this way, deduplication is performed to avoid redundant search, effectively improving search efficiency.
[0073] In the embodiment of the present invention, a unified upper layer interface is provided as a search interface for different target platforms. According to the multi-platform search structure of the embodiment of the present invention, considering the multiple computing platforms such as CPU, GPU, OpenCL, etc., a unified upper layer interface (API, Application Programming Interface) is provided in the embodiment of the present invention for the convenience of use, including but not limited to: obtaining the operator search space, running and timing, etc. Each computing platform implements the unified interface, and the specific implementation method varies from platform to platform. For example, for the interface get_search_space(shape, param) for obtaining the operator search space, the pseudo code for implementing the interface on the GPU platform is as follows:
[0074]
[0075] Therefore, an abstract interface of the search strategy of multiple platforms is extracted, the platform details are hidden, and a unified representation is provided to users. Considering that when the model needs to be deployed on multiple platforms, a unified usage interface can be provided, which is very practical for the deployment scenario of neural network models.
[0076] In an embodiment of the present invention, a query step may also be included, that is, according to the attributes of the operation to be searched, querying in the cache whether there is a third operator corresponding to the operation to be searched; when the third operator exists in the cache, determining the third operator as the target operator; when the third operator does not exist in the cache, executing the step of obtaining the first search space corresponding to the operation to be searched in the neural network. For the operation to be searched, it is possible to check whether the cache hits based on the (device id, operation id, shape, param) quaternary group. If the cache hits, the corresponding third operator is directly returned; if the cache does not hit the third operator, the first search space of the operation on the target platform is obtained. In this way, repeated searches for operations of determined target operators can be avoided, thereby improving search efficiency.
[0077] In an embodiment of the present invention, after completing the search for the target operator of all operations, the cache obtained from the search is serialized into a persistent device. For example, the operator serialization target only contains the name of the operator, and the corresponding operator can be found according to the name of the operator. It can be understood that a unique identifier can be obtained by deserializing the serialization target of the operator, and the unique identifier corresponds to an operator instance. In an embodiment of the present invention, a mapping map between all current operator names and operator instances will be created. If the content in the map is {"algo_name0": algo0}, the serialization target of the operator only contains the name of the operator. In the subsequent operation of the neural network, the target is deserialized to obtain "algo_name0", and then the operator corresponding to the name is searched in the map.
[0078] The operator determination method of the embodiment of the present invention is adopted, by obtaining all operators running on the target platform of the operation to be searched as the first search space, running all operators in sequence, and creating a subprocess for the operator when it is running, recording the operating parameters, and when its operating parameters exceed the currently existing historical optimal operating parameters, the subprocess is dynamically pruned and the operator is no longer run, thereby effectively saving the search time, improving the search efficiency and saving computing resources, and solving the problems of slow search and large resource requirements on the premise of finding the operator with the best performance; and determining the target operator and operating parameters of the target operation called by the operator through recursive search, recursively searching the operator and the operation called by the operator through depth-first traversal, ensuring that when the operator calls the target operation, the operation it depends on will also select the target operator, and designing a deduplication mechanism to avoid redundant search, further reducing the search time and computing resource overhead. The present invention also considers how to provide a unified user interface when the model needs to be deployed on multiple platforms, hide the platform details, and provide users with a unified representation, which has strong practicality for the deployment scenario of the neural network model.
[0079] The embodiment of the second aspect of the present invention further provides an operator determination device. Figure 7 FIG. 7 is a schematic diagram of the structure of an operator determination device 700 according to an embodiment of the present invention, which includes an acquisition module 701 , a search module 702 and a determination module 703 .
[0080] The acquisition module 701 is used to acquire a first search space corresponding to the operation to be searched in the neural network, and the first search space includes multiple operators.
[0081] The search module 702 is used to run the multiple operators in the first search space, and when a first operator among the multiple operators calls a target operation, search a second search space corresponding to the target operation.
[0082] The determination module 703 is used to determine the target operator corresponding to the to-be-searched operation from the multiple operators according to the operating parameters of the multiple operators.
[0083] In the embodiment of the present invention, the operator determination device 700 further includes a query module 704 ( Figure 7 (not shown), the query module 704 is used to query whether there is a third operator corresponding to the operation to be searched in the cache according to the attributes of the operation to be searched; when the third operator exists in the cache, the third operator is determined as the target operator; when the third operator does not exist in the cache, the first search space corresponding to the operation to be searched in the neural network is acquired by the acquisition module 701.
[0084] In the embodiment of the present invention, the operator determination device 700 further includes a writing module 705 ( Figure 7), the writing module 705 is used to write the determined target operator into the cache according to the cache format. In an embodiment of the present invention, the cache format includes a tuple formed according to the attributes of the operating platform and the attributes of the operation to be searched. In an embodiment of the present invention, the target operator includes an operator whose operating parameters meet the operating conditions, and the operating conditions include the shortest operating time of the operator and / or the best operating performance of the operator.
[0085] In an embodiment of the present invention, the determination module 703 is also used to obtain the order of the multiple operators; create a corresponding sub-process for each operator, and pass the execution configuration to the sub-process, the execution configuration including the historical optimal operating parameters; according to the order of the multiple operators, run the sub-process corresponding to each operator in turn until the sub-process corresponding to each operator is completed, determine the operating parameters of each operator according to the operating results of the sub-process, and use the operator whose operating parameters meet the operating conditions and / or whose operating parameters are less than the historical optimal operating parameters as the target operator to be searched.
[0086] In an embodiment of the present invention, the determination module 703 is also used to determine the target operator corresponding to the target operation called by each first operator and the operating parameters corresponding to the target operator of the target operation; and determine the operator in the first search space whose operating parameters meet the operating conditions and / or whose operating parameters are less than the historical optimal operating parameters as the target operator.
[0087] In an embodiment of the present invention, the determination module 703 is also used to determine the second search space corresponding to the target operation called by the first operator; determine whether each operator in the second search space continues to call other target operations, and determine the corresponding second search space until the bottom-level search space is reached, and the operators in the bottom-level search space no longer call the target operation; determine the target operator and corresponding operating parameters in the bottom-level search space, write them into the cache and pass them to the previous level search space; determine the target operator and corresponding operating parameters in each level of search space in turn and write them into the cache until the second search space corresponding to the target operation called by the first operator is returned; determine the target operator and its operating parameters corresponding to the target operation called by the first operator according to the operating parameters of the operator in the second search space. In an embodiment of the present invention, the operating parameters of the previous level operator are determined according to the operating parameters corresponding to the target operator in each level of search space and written into the cache.
[0088] In an embodiment of the present invention, the determination module 703 is further used to search whether there is a target operator of the next level operation called in the cache; when the target operator of the next level operation called in the cache exists, the next level operation is no longer searched. In an embodiment of the present invention, a unified upper layer interface is provided as a search interface for different target platforms.
[0089] The more specific implementation of each module of the operator determination device 700 can refer to the description of the operator determination method of the present invention, and has similar beneficial effects, which will not be repeated here.
[0090] The embodiment of the third aspect of the present invention also provides a method for operating a neural network. Figure 8 It is a schematic flow chart of a method for operating a neural network according to an embodiment of the present invention, including steps S01 to S02.
[0091] In step S01, all operations during the operation of the neural network are determined. In an embodiment of the present invention, after the neural network model is deployed to the target operation platform, all operations and environment configurations required for the neural network model operation environment can be determined.
[0092] In step S02, during the operation of the neural network, the target operator of each operation is executed, wherein the target operator is determined using the operator determination method described above. In an embodiment of the present invention, when executing the operation, first search whether the execution configuration of the operation includes the target operator; or when executing the operation, first search whether the target operator exists in the cache.
[0093] Fig. 9 The diagram is a schematic diagram of the operation of the neural network model according to an embodiment of the present invention. After searching by the operator determination method described above, the cache serialization file is obtained, which records the optimal operator and related execution configuration of each operation on the corresponding target platform. When the deployed neural network model is executed, the cache serialization file is first loaded and parsed, and the serialization file content is deserialized and set to the execution strategy of each operation or directly saved in the memory.
[0094] In the embodiment of the present invention, the method for setting the execution configuration is to set the corresponding operator after deserialization to the execution configuration of each operation according to the deserialized device, operation, shape, param and other information before execution. Each operation first checks whether its execution configuration is empty when running. If it is not empty, the operator in the configuration is executed. If it is empty, the first operator that can be executed in the current environment configuration is taken from the manually set operator list to ensure that each operation is run with its best performance operator.
[0095] In the embodiment of the present invention, the cache search method can also be used for execution. For example, each operation first searches the cache according to the (device, operation, shape, param) quaternary group as the key when running. If it is hit, the operator corresponding to the key in the cache is executed. If it is not hit, the first operator that can be executed in the current environment configuration is taken from the manually set operator list for execution, which can also ensure that each operation is executed with its best performance operator.
[0096] A specific example is given below to better explain the present invention. When the deployed neural network model is running, the cache serialization file containing the relevant information of each operation target operator is first loaded. Taking the convolution operation as an example, its pseudo code at runtime is as follows:
[0097]
[0098]
[0099] Among them, the execution configuration exec_policy contains the operator algo with the best performance. First, check whether the target operator in your execution configuration is empty. If it is not empty, execute the target operator directly; if the execution configuration is empty, search the cache for the target operator in the current running environment. If it is found, write the target operator to your execution configuration and execute it; if the target operator is not found, select the first available operator from the operator list sorted based on manual experience for execution.
[0100] The method for operating a neural network according to an embodiment of the present invention obtains the cache serialization file of the target operator of each operation on the corresponding target platform, deserializes it to determine the corresponding target operator, and operates it according to the optimal operator. When the operator calls the target operation, it ensures that the operations it depends on will also select the target operator, thereby greatly enhancing the performance of the neural network and having strong practicality for the training and deployment of neural networks with interdependent operations.
[0101] The embodiment of the fourth aspect of the present invention also provides a device for operating a neural network. Fig.10 It is a schematic structural diagram of a neural network operating device 1000 according to an embodiment of the present invention, comprising a processing module 1001 and an operating module 1002 .
[0102] The processing module 1001 is used to determine all operations when the neural network is running.
[0103] The operation module 1002 is used to execute the target operator of each operation during the operation of the neural network, wherein the target operator is determined using the operator determination method as described above.
[0104] In the embodiment of the present invention, the running module 1002 is further used to first search whether the execution configuration of the operation includes the target operator when executing the operation; or first search whether the target operator exists in the cache when executing the operation.
[0105] In the embodiment of the present invention, the running module 1002 is further configured to select the first-ranked operator for execution according to a sorting rule when the execution configuration does not include the target operator or the target operator does not exist in the cache.
[0106] The more specific implementation of each module of the neural network operating device 1000 can be found in the description of the neural network operating method of the present invention, and has similar beneficial effects, which will not be repeated here.
[0107] An embodiment of the fifth aspect of the present invention proposes a non-temporary computer-readable storage medium having a computer program stored thereon. When the program is executed by a processor, it implements the operator determination method according to the first aspect of the present invention or the neural network operation method according to the third aspect of the present invention.
[0108] Generally speaking, the computer instructions for implementing the method of the present invention can be carried by any combination of one or more computer-readable storage media. Non-transitory computer-readable storage media can include any computer-readable media except for the signal itself that is temporarily propagating.
[0109] Computer readable storage media can be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or devices, or any combination of the above. More specific examples of computer readable storage media (a non-exhaustive list) include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, device or device.
[0110] Computer program code for performing the operation of the present invention can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages, in particular, Python suitable for neural network computing and platform frameworks based on TensorFlow, PyTorch, etc. can be used. The program code can be executed entirely on the user's computer, partially on the user's computer, as an independent software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer can be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computer (for example, using an Internet service provider to connect through the Internet).
[0111] The embodiment of the sixth aspect of the present invention provides a computing device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the operator determination method according to the first aspect of the present invention or the neural network operation method according to the third aspect of the present invention is implemented. It can be understood that the computing device of the present invention can be a server or a terminal device with limited computing power.
[0112] The non-temporary computer-readable storage medium and computing device according to the fifth and sixth aspects of the present invention can be implemented with reference to the contents specifically described in the embodiment according to the first aspect of the present invention, and have similar beneficial effects as the operator determination method according to the embodiment of the first aspect of the present invention or the neural network operation method according to the embodiment of the third aspect of the present invention, which will not be described in detail herein.
[0113] Although the embodiments of the present invention have been shown and described above, it should be understood that the above embodiments are exemplary and should not be construed as limitations on the present invention. A person skilled in the art may change, modify, replace and vary the above embodiments within the scope of the present invention.
Claims
1. An operator determination method, characterized in that: include: Acquire a first search space corresponding to the operation to be searched in the neural network, wherein the first search space includes a plurality of operators; Running the multiple operators of the first search space, when a first operator among the multiple operators calls a target operation, searching a second search space corresponding to the target operation; as well as Determining a target operator corresponding to the to-be-searched operation from the multiple operators according to the operating parameters of the multiple operators includes: Obtaining the order of the multiple operators; Creating a corresponding subprocess for each operator and passing an execution configuration to the subprocess, wherein the execution configuration includes historical optimal operating parameters; According to the order of the multiple operators, the subprocesses corresponding to each operator are run in sequence until the subprocesses corresponding to each operator are completed, and the operating parameters of each operator are determined according to the operating results of the subprocesses, and the operators whose operating parameters meet the operating conditions and / or whose operating parameters are less than the historical optimal operating parameters are used as the target operators to be searched.
2. The operator determination method according to claim 1, characterized in that: The method further comprises: According to the attribute of the operation to be searched, querying in the cache whether there is a third operator corresponding to the operation to be searched; When the third operator exists in the cache, determining the third operator as the target operator; When the third operator does not exist in the cache, the step of obtaining the first search space corresponding to the operation to be searched in the neural network is performed.
3. The operator determination method according to claim 1, characterized in that: After determining the target operator corresponding to the operation to be searched, the method further includes: The determined target operator is written into the cache according to the cache format.
4. The operator determination method according to claim 3, characterized in that: The cache format includes a tuple formed according to the attributes of the operating platform and the attributes of the operation to be searched.
5. The operator determination method according to any one of claims 1 to 4, characterized in that: The target operator includes an operator whose operating parameters satisfy operating conditions, and the operating conditions include that the operating time of the operator is the shortest and / or the operating performance of the operator is the best.
6. The operator determination method according to claim 1, characterized in that: The step of determining the operating parameters of each operator according to the operating result of the subprocess, and taking the operator whose operating parameters meet the operating conditions and / or whose operating parameters are less than the historical optimal operating parameters as the target operator to be searched comprises: Determine a target operator corresponding to a target operation called by each first operator and an operating parameter corresponding to the target operator of the target operation; An operator in the first search space whose operating parameter satisfies the operating condition and / or whose operating parameter is less than the historical optimal operating parameter is determined as the target operator.
7. The operator determination method according to claim 6, characterized in that: The determining of the target operator corresponding to the target operation called by each first operator and the operating parameters corresponding to the target operator of the target operation includes: Determine a second search space corresponding to the target operation called by the first operator; Determine whether each operator in the second search space continues to call other target operations, and determine the corresponding second search space until the lowest search space is reached, and the operators in the lowest search space no longer call the target operation; Determine the target operator and corresponding operating parameters in the bottom-level search space, write them into the cache and pass them to the upper-level search space; Determine the target operator and the corresponding operation parameters in each level of search space in turn and write them into the cache until returning to the second search space corresponding to the target operation called by the first operator; A target operator and its operating parameters corresponding to the target operation called by the first operator are determined according to the operating parameters of the operator in the second search space.
8. The operator determination method according to claim 7, characterized in that: The step of sequentially determining the target operator and the corresponding operating parameters in each level of the search space and writing them into the cache comprises: The operating parameters of the operator at the previous level are determined according to the operating parameters corresponding to the target operator in each level of search space and written into the cache.
9. The operator determination method according to claim 8, characterized in that: The determining of the target operator corresponding to the target operation called by each first operator and the operating parameters corresponding to the target operator of the target operation further includes: Searching the cache for a target operator of the next-level operation to be called; When the target operator of the next-level operation called exists in the cache, the search for the next-level operation is no longer continued.
10. The operator determination method according to any one of claims 1, characterized in that: Provide a unified upper-level interface as a search interface for different target platforms.
11. An operator determination device, characterized in that: include: An acquisition module, used to acquire a first search space corresponding to the operation to be searched in the neural network, wherein the first search space includes a plurality of operators; A search module, configured to run the multiple operators in the first search space, and when a first operator among the multiple operators calls a target operation, search a second search space corresponding to the target operation; A determination module, configured to determine, from the multiple operators according to the operation parameters of the multiple operators, a target operator corresponding to the operation to be searched, comprising: obtaining a ranking of the multiple operators; A corresponding subprocess is created for each of the operators, and an execution configuration is passed to the subprocess, wherein the execution configuration includes a historical optimal operating parameter; the subprocess corresponding to each of the operators is run in sequence according to the order of the multiple operators until the subprocess corresponding to each of the operators is completed, and the operating parameters of each operator are determined according to the operating results of the subprocess, and the operator whose operating parameters meet the operating conditions and / or whose operating parameters are less than the historical optimal operating parameters is used as the target operator of the operation to be searched.
12. A method for operating a neural network, characterized in that: include: Determine all operations performed by the neural network during its operation; as well as During the operation of the neural network, a target operator of each operation is executed, wherein the target operator is determined using the operator determination method according to any one of claims 1 to 10.
13. The method for operating a neural network according to claim 12, characterized in that: During the operation of the neural network, the target operator for executing each operation includes: When executing the operation, first search whether the execution configuration of the operation contains the target operator; or When executing the operation, first check whether the target operator exists in the cache.
14. The method for operating a neural network according to claim 13, characterized in that: When the execution configuration does not include the target operator or the target operator does not exist in the cache, the first-ranked operator is selected for execution according to the sorting rule.
15. A neural network operating device, characterized in that: include: A processing module, configured to determine all operations performed when the neural network is running; An operation module is used to execute a target operator of each operation during the operation of the neural network, wherein the target operator is determined by the operator determination method according to any one of claims 1 to 10.
16. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the operator determination method according to any one of claims 1 to 10 or the neural network operation method according to any one of claims 12 to 14 is implemented.
17. A computing device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the operator determination method according to any one of claims 1 to 10 or the neural network operation method according to any one of claims 12 to 14 is implemented.
