Invocation methods and invocation devices of the inference framework
By providing API-encapsulated inference framework calling methods, unified input and output tensor representation and resource management, it solves the adaptation problem of inference chips and frameworks from different manufacturers, and improves the application efficiency and compatibility of artificial intelligence inference models.
Patent Information
- Application Number
- CN202111555823.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-17
- Publication Date
- 2024-09-03
- Estimated Expiration
- 2041-12-17
AI Technical Summary
Due to the lack of relevant standards for artificial intelligence inference chips, each chip manufacturer has different implementation methods, which requires users to develop application software separately for each manufacturer's inference chip and inference framework, which increases the application difficulty and usage time of artificial intelligence inference models.
Provides a calling method and calling interface for the reasoning framework. The reasoning process is encapsulated through the API. Users can implement the adaptation of different reasoning frameworks through a set of calling processes, shield the underlying differences of chips from various manufacturers, unify the representation of input and output tensors, and reduce Resources are occupied and released when inference is not needed.
It reduces the application difficulty of artificial intelligence reasoning models, reduces the time of using artificial intelligence reasoning models, improves application efficiency, and achieves compatibility and resource management of cross-vendor reasoning frameworks.
Smart Images

Figure CN114169525B
Abstract
Description
Technical Field
[0001] The present application relates to the field of artificial intelligence technology, and in particular to a method and device for calling an inference framework. Background Art
[0002] With the rapid development of artificial intelligence technology, various cloud, edge, and end artificial intelligence inference chips continue to emerge, artificial intelligence computing power continues to increase, and image, video, and voice applications based on artificial intelligence technology are rapidly implemented, playing a huge role in improving production efficiency.
[0003] Due to the lack of relevant standards for AI inference chips, the implementation methods of various chip manufacturers vary. For example, in order to give full play to the efficiency of AI inference chips, the inference frameworks of various chip manufacturers will be deeply optimized according to the characteristics of AI inference chips, resulting in different formats, usage processes and methods of AI inference models. Based on this, when users use inference chips provided by different manufacturers, they need to develop a set of application software for each AI inference chip and inference framework provided by each manufacturer, which increases the difficulty of applying AI inference models and the time it takes for users to use AI inference models. Summary of the invention
[0004] The present application provides a calling method and calling interface of an inference framework, which is conducive to reducing the application difficulty of artificial intelligence inference models, reducing the time users spend using artificial intelligence inference models, and improving the application efficiency of artificial intelligence inference models.
[0005] In a first aspect, the present application provides a method for calling an inference framework, which is applied to an inference device including an application programming interface (API), where the API is obtained by encapsulating the inference process of the inference framework, and the method includes: the inference device obtains the operating parameters of the inference model based on the API; the inference device initializes the inference device based on the API; the inference device generates a calculation graph using the operating parameters of the inference model, and obtains an input tensor based on the calculation graph; the inference device obtains input data, and assigns a value to the input tensor using the input data to obtain the assigned input tensor; the inference device inputs the assigned input tensor into the calculation graph to obtain an output tensor, and obtains an inference result based on the output tensor.
[0006] In the calling method of the reasoning framework provided in the present application, each chip manufacturer encapsulates the reasoning process of the reasoning framework into an API based on the method of the present application. The user can implement reasoning through the reasoning model through a set of calling processes based on the API. Each chip manufacturer can remain unchanged from the internal logic of the original reasoning framework, and the user can also only apply one set of calling processes to implement the adaptation process of different reasoning frameworks, which is conducive to reducing the application difficulty of the artificial intelligence reasoning model, reducing the time of using the artificial intelligence reasoning model, and improving the application efficiency of the artificial intelligence reasoning model.
[0007] In combination with the first aspect, in some implementations of the first aspect, input tensors and output tensors are uniformly represented by handles.
[0008] The calling method of the reasoning framework provided in the embodiment of the present application, in which input tensors and output tensors are uniformly represented by handles, can shield the differences in the underlying chips of various manufacturers. Users can obtain input tensors and output tensors through handles without having to understand the underlying methods of chips of various manufacturers. This is conducive to reducing the application difficulty of artificial intelligence reasoning models, reducing the time of using artificial intelligence reasoning models, and improving the application efficiency of artificial intelligence reasoning models.
[0009] In combination with the first aspect, in certain implementations of the first aspect, the inference device obtains an input tensor according to a computational graph, including: the inference device obtains at least one of the following information of the input tensor according to the computational graph: number, shape, data layout, data type, or storage location; the inference device creates an input tensor based on at least one information.
[0010] In combination with the first aspect, in certain implementations of the first aspect, the inference device obtains an input tensor according to a computation graph, including: the inference device obtains at least one of the following information of the input tensor according to the computation graph: number, shape, data layout, data type, or storage location; the inference device obtains a reference handle of the input tensor according to at least one information; the inference device obtains the input tensor according to the reference handle of the input tensor.
[0011] In combination with the first aspect, in some implementations of the first aspect, the API exists in at least one of the following forms: a dynamic link library, a static link library, or an executable file.
[0012] In combination with the first aspect, in some implementations of the first aspect, the above method also includes: the inference device determines whether there is un-inferred data in the input data; if there is no un-inferred data, the inference device releases the resources corresponding to the generated calculation graph.
[0013] The calling method of the reasoning framework provided in the present application releases the resources corresponding to the generated calculation graph when there is no unreasoned data. The previously allocated resources can be released when reasoning is not needed, which is conducive to reducing memory space and saving resources.
[0014] In the second aspect, the present application provides a calling device for an inference framework, including: an acquisition module and a processing module. Among them, the acquisition module is used to: acquire the operating parameters of the inference model based on the application program interface API; the processing module is used to: initialize the device based on the API; generate a calculation graph using the operating parameters of the inference model, and obtain the input tensor according to the calculation graph; the acquisition module is also used to: acquire input data; the processing module is also used to: assign values to the input tensor using the input data to obtain the assigned input tensor; input the assigned input tensor into the calculation graph to obtain the output tensor, and, according to the output tensor, obtain the inference result.
[0015] In combination with the second aspect, in certain implementations of the second aspect, input tensors and output tensors are uniformly represented by handles.
[0016] In combination with the second aspect, in certain implementations of the second aspect, the above-mentioned acquisition module is also used to: obtain at least one of the following information of the input tensor according to the computational graph: number, shape, data layout, data type or storage location; the above-mentioned processing module is also used to: create an input tensor based on at least one information.
[0017] In combination with the second aspect, in certain implementations of the second aspect, the above-mentioned acquisition module is also used to: obtain at least one of the following information of the input tensor according to the computational graph: number, shape, data layout, data type or storage location, and obtain a reference handle of the input tensor based on at least one information; and obtain the input tensor based on the reference handle of the input tensor.
[0018] In combination with the second aspect, in some implementations of the second aspect, the API exists in at least one of the following forms: a dynamic link library, a static link library, or an executable file.
[0019] In conjunction with the second aspect, in some implementations of the second aspect, the apparatus further includes a judgment module. The judgment module is used to judge whether there is unreasoned data in the input data; the processing module is also used to: when there is no unreasoned data, the inference device releases resources corresponding to the generated computation graph.
[0020] In a third aspect, the present application provides a device for calling a reasoning framework, comprising a processor and a memory. The processor is used to read instructions stored in the memory to execute the method in any possible implementation of the first aspect.
[0021] Optionally, there are one or more processors and one or more memories.
[0022] Optionally, the memory may be integrated with the processor, or the memory may be provided separately from the processor.
[0023] In the specific implementation process, the memory can be a non-transitory memory, such as a read-only memory (ROM), which can be integrated with the processor on the same chip or can be set on different chips respectively. The embodiments of the present application do not limit the type of memory and the setting method of the memory and the processor.
[0024] The calling device of the reasoning framework in the third aspect mentioned above can be a chip. The processor can be implemented by hardware or by software. When implemented by hardware, the processor can be a logic circuit, an integrated circuit, etc.; when implemented by software, the processor can be a general-purpose processor, which is implemented by reading the software code stored in the memory. The memory can be integrated in the processor or can be located outside the processor and exist independently.
[0025] In a fourth aspect, the present application provides a computer-readable storage medium having a computer program (also referred to as code or instruction) which, when executed on a computer, enables the computer to execute a method in any possible implementation of the first aspect.
[0026] In a fifth aspect, the present application provides a computer program product, which includes: a computer program (also referred to as code, or instructions), which, when executed, enables a computer to execute a method in any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0028] Figure 1 A schematic flowchart of a method for calling an inference framework provided in an embodiment of the present application;
[0029] Figure 2 A schematic block diagram of a device for calling an inference framework provided in an embodiment of the present application;
[0030] Figure 3 A schematic block diagram of another invocation device of an inference framework provided in an embodiment of the present application.
[0031] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0032] The technical solution in this application will be described below in conjunction with the accompanying drawings.
[0033] In order to facilitate understanding of the embodiments of the present application, relevant terms in the embodiments of the present application are first introduced.
[0034] 1. Inference Model
[0035] The inference model may be a trained neural network model, which can be applied to actual scenarios. The trained neural network model is obtained by training the initial neural network model with large amounts of data.
[0036] 2. Inference Chip
[0037] An inference chip refers to a chip that uses an inference model for inference prediction. It can be used as a coprocessor to accelerate deep learning inference, or as a main processor to receive video streams, images or other data from an Ethernet interface or a universal serial bus (USB) interface to perform inference and other computer vision tasks.
[0038] Inference chips can be deployed in the cloud, edge, and terminal. According to the deployment location, inference AI chips can be divided into cloud inference chips, edge inference chips, and terminal inference chips.
[0039] Cloud inference chips are mainly used in large-scale data centers and servers in the field of artificial intelligence. Edge inference chips are mainly used in execution or acceleration devices. Terminal inference chips are mainly used in smartphones, autonomous driving, robots, smart homes and other devices.
[0040] 3. Reasoning Framework
[0041] The inference framework is committed to solving the compatibility and adaptation between various types of inference chips from multiple manufacturers and various training frameworks and inference models in the application scenarios of artificial intelligence & internet of things (AIoT), while improving the running performance of inference models on inference chips. It can efficiently migrate the trained models from the cloud to heterogeneous inference chips for execution, shorten the development and deployment cycle of artificial intelligence applications, and help accelerate the industrialization of artificial intelligence.
[0042] 4. Computational Graph
[0043] A computational graph is a graphical representation of the computational process. It is a "language" for describing equations. A computational graph can include nodes (i.e. variables) and edges (i.e. simple functions).
[0044] 5. Operator
[0045] In a narrow sense, an operator is a mapping from one function space to another function space (or to itself).
[0046] In a broad sense, an operator is a generalization of a function space to any space, where any space can be a vector space, an inner product space, a Banach space, or a Hilbert space, etc.
[0047] 6. Library files
[0048] A library file is a type of file on a computer that provides users with some ready-to-use variables, functions, or classes.
[0049] Among them, library files can be divided into static link libraries and dynamic link libraries. The difference between static link libraries and dynamic link libraries is reflected in the linking stage of the program: static link libraries are copied to the target program during the linking stage of the program; dynamic link libraries are not copied to the target program during the linking stage, but are dynamically loaded into the memory by the system when the target program is running for the target program to call.
[0050] Generally speaking, the file extension of a static link library in Windows is .lib, and the file extension of a dynamic link library is .dll; the file extension of a static link library in Linux is .a, and the file extension of a dynamic link library is .so.
[0051] 7. Executable files
[0052] An executable file is a file that can be loaded and executed by an operating system. In different operating system environments, executable programs are presented differently. For example, in a Windows operating system, an executable program can be a .exe file, a .sys file, or a .com file.
[0053] With the rapid development of artificial intelligence technology, various cloud, edge, and end artificial intelligence inference chips continue to emerge, artificial intelligence computing power continues to increase, and image, video, and voice applications based on artificial intelligence technology are rapidly implemented, playing a huge role in improving production efficiency.
[0054] Due to the lack of relevant standards for AI inference chips, the implementation methods of various chip manufacturers vary. For example, in order to give full play to the efficiency of AI inference chips, the inference frameworks of various chip manufacturers will be deeply optimized according to the characteristics of AI inference chips, resulting in different formats, usage processes and methods of AI inference models. Based on this, when users use inference chips provided by different manufacturers, they need to develop a set of application software for each AI inference chip and inference framework provided by each manufacturer, which increases the difficulty of applying AI inference models and the time it takes for users to use AI inference models.
[0055] In order to solve this problem, many companies have explored it, and there are currently two possible implementation methods. One possible implementation method is to separate the operator definition and operator implementation of the computational graph in the artificial intelligence reasoning framework, and design an intermediate layer to associate the operator definition in the reasoning model with the operator implementation developed by each manufacturer. However, this method currently designs operator scheduling and data layout based on the characteristics of the central processing unit (CPU) and graphics processing unit (GPU), which may not be suitable for the neural network processing unit (NPU). Instead, it will limit the reasoning execution efficiency of the NPU device. Therefore, it has not been widely supported by NPU manufacturers.
[0056] Another possible implementation method is to use compiler technology to compile and optimize the calculation graphs generated by different training frameworks into a calculation graph of a specified format at the front end, and then each manufacturer will perform in-depth optimization of the calculation graph of the specified format based on the characteristics of the inference chip at the back end, and finally generate a software library (such as so dynamic link library, etc.) that can run on the target inference device. However, the calculation graph of the specified format in this method has not yet been standardized. At the same time, the back-end optimization development based on compiler technology is difficult and has a long cycle. It is difficult for each manufacturer to migrate to a new technical architecture in a short period of time, so the progress of the inference framework in this regard is very slow.
[0057] In view of this, the embodiments of the present application provide a calling method and a calling device for the reasoning framework, which are conducive to reducing the application difficulty of the artificial intelligence reasoning model, reducing the time of using the artificial intelligence reasoning model, and improving the application efficiency of the artificial intelligence reasoning model.
[0058] Before introducing the calling method and calling device of the reasoning framework provided in the embodiment of the present application, the following explanation is made:
[0059] "At least one" in the embodiments of the present application refers to one or more, and "plurality" refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone, where A and B can be singular or plural. The character " / " generally indicates that the associated objects before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single items or plural items. For example, at least one of a, b and c can represent: a, or b, or c, or a and b, or a and c, or b and c, or a, b and c, where a, b, c can be single or multiple.
[0060] Figure 1 A schematic flow chart of a method 100 for calling a reasoning framework provided in an embodiment of the present application, the method 100 can be applied to a reasoning device including an API. The API is obtained by encapsulating the reasoning process of the reasoning framework. The reasoning device including the API can be applied to fields such as vision, audio or natural language processing.
[0061] The method 100 may include the following steps:
[0062] S101. The inference device obtains the operating parameters of the inference model based on the API.
[0063] The inference device is deployed with an inference model, and can perform inference through the inference model to obtain an inference result. The inference device can also be called a computing device, and the embodiment of the present application does not limit the name of the device deployed with the inference model.
[0064] Optionally, the inference model may be deployed on an inference chip, and the inference device may include the inference chip, and inference is performed through the inference model in the inference chip to obtain an inference result.
[0065] The reasoning framework of each chip manufacturer can be deeply optimized according to the characteristics of the reasoning chip, resulting in different reasoning processes of the reasoning framework. Based on the method of this application, each chip manufacturer can encapsulate the reasoning process of the reasoning framework into an API and save it in the reasoning device, that is, each chip manufacturer encapsulates the reasoning process through the reasoning model into multiple functions or multiple executable files, and the user can call the multiple functions or multiple executable files through a set of calling processes to obtain the reasoning results through the reasoning model. Among them, the API includes the multiple functions or exists in the form of multiple executable files.
[0066] The reasoning process of the inference framework of each chip manufacturer is different, which may lead to different formats of the inference model. Each chip manufacturer can encapsulate the function of calling the operating parameters of the inference model of each chip manufacturer in the API. Users can obtain the operating parameters of the inference model of each chip manufacturer based on the function of calling the operating parameters of the inference model in the API encapsulated by each chip manufacturer.
[0067] Optionally, each chip manufacturer may encapsulate the operating parameters of the inference model of each chip manufacturer in a configuration file, and the inference device may obtain the operating parameters of the inference model in the configuration file by calling a function of the operating parameters of the inference model in an API.
[0068] Optionally, the formats of the inference models of different chip manufacturers may be different, and the above configuration file may also include the target format of the inference model supported by the inference device, the parameters required for conversion into the target format, and the operating parameters of the inference model in the target format.
[0069] S102: The inference device initializes the inference device based on the API.
[0070] The inference device can be initialized by calling the initialization function in the API.
[0071] The initialization parameters of each chip manufacturer may be different. Each chip manufacturer can encapsulate their own initialization functions into initialization functions and save them in the API. The inference device can initialize the inference device of each chip manufacturer by calling the initialization function in the API of each chip manufacturer.
[0072] Optionally, the initialization function in each chip manufacturer's API may initialize the inference device by calling initialization parameters of the respective inference device.
[0073] Optionally, each chip manufacturer may encapsulate the initialization parameters of the inference device in a configuration file. When the inference device calls the initialization function in the API, it may obtain the initialization parameters in the configuration file and use the initialization parameters to initialize the inference device.
[0074] S103: The inference device generates a computational graph using the operating parameters of the inference model, and obtains an input tensor based on the computational graph.
[0075] A computational graph is a representation of an inference model. When an inference device calls an inference model for inference, it is necessary to generate a computational graph from the inference model and use the computational graph for inference.
[0076] The inference device can generate a computational graph by calling the computational graph creation function in the API and using the running parameters of the inference model.
[0077] A computational graph can be represented by a handle, for example, GraphDataHandle.
[0078] Exemplarily, the inference device calls the computation graph creation function to obtain a reference handle of the computation graph, such as GraphDataHandle, and the inference device can obtain the computation graph according to the location pointed to by the reference handle. The reference handle of the computation graph can be understood as a pointer in a programming language, which describes the location of the computation graph in memory.
[0079] Optionally, a reference handle to a computation graph (eg, GraphDataHandle) may be encapsulated in a structure, such as a Graph structure.
[0080] It should be understood that the handle in the embodiment of the present application can also be called a reference handle, and the embodiment of the present application is not limited to this.
[0081] The inference device obtains the input tensor according to the computation graph, and there are two possible implementations. In one possible implementation, the inference device creates the input tensor according to the computation graph.
[0082] Exemplarily, the inference device obtains at least one of the following information of the input tensor according to the computation graph: number, shape, data layout, data type or storage location; and the inference device creates the input tensor according to the at least one information.
[0083] The inference device may obtain at least one of the number of input tensors, the shape of each tensor, the data layout, the data type, or the storage location by calling the calculation graph input information acquisition function in the API, according to the calculation graph. The inference device may create an input tensor according to the at least one information by calling the input tensor creation function in the API.
[0084] In another possible implementation, the inference device obtains a reference handle of the input tensor according to the computation graph, and then obtains the input tensor from the reference handle of the input tensor.
[0085] Exemplarily, the inference device obtains at least one of the following information of the input tensor according to the computation graph: number, shape, data layout, data type or storage location; the inference device obtains a reference handle of the input tensor according to the at least one information; the inference device obtains the input tensor according to the reference handle of the input tensor (e.g., TensorDataHandle).
[0086] The reference handle of the input tensor can be understood as a pointer in a programming language. The pointer describes the location of the input tensor in the memory. The inference device can obtain the input tensor according to the location indicated by the pointer.
[0087] The inference device can obtain at least one of the number of input tensors, the shape of each tensor, the data layout, the data type, or the storage location according to the calculation graph by calling the calculation graph input information acquisition function in the API. The inference device can obtain the reference handle of the input tensor according to the at least one information by calling the input tensor reference function in the API. The inference device can obtain the input tensor according to the reference handle of the input tensor by calling the input tensor acquisition function in the API.
[0088] S104: The inference device obtains input data, and uses the input data to assign values to input tensors to obtain assigned input tensors.
[0089] Input data is the data input into the computation graph, that is, the data that needs to be inferred.
[0090] For example, the input data may be a picture, voice or text, etc. The embodiment of the present application does not limit the form of the input data.
[0091] The inference device can call the input tensor assignment function in the API to assign values to the input tensor using the input data to obtain the assigned input tensor.
[0092] S105. The inference device inputs the assigned input tensor into the computation graph to obtain an output tensor.
[0093] The inference device inputs the assigned input tensor into the computation graph, and can obtain at least one of the shape, data layout, data type, or storage location of each output tensor by calling the output tensor information acquisition function in the API. The inference device can obtain the reference handle (e.g., TensorDataHandle) of the output tensor according to the at least one information by calling the output tensor reference function in the API. The inference device can obtain the output tensor according to the reference handle of the output tensor.
[0094] S106. The inference device obtains an inference result based on the output tensor.
[0095] The inference device can obtain the output tensor data, that is, the inference result, by calling the output tensor acquisition function in the API.
[0096] Optionally, the inference device may copy the inference result to a host device (host) of the computer, and the host performs subsequent operations after obtaining the inference result.
[0097] The calling method of the reasoning framework provided in the embodiment of the present application, each chip manufacturer encapsulates the reasoning process of the reasoning framework into multiple functions based on the method of the present application, and the user can implement reasoning through the reasoning model through a set of calling processes. Each chip manufacturer can remain unchanged. The internal logic of the original reasoning framework, and the user can also only apply one set of calling processes to implement the adaptation process of different reasoning frameworks, which is conducive to reducing the application difficulty of the artificial intelligence reasoning model, reducing the time of using the artificial intelligence reasoning model, and improving the application efficiency of the artificial intelligence reasoning model.
[0098] Optionally, in the above method 100, the input tensor and the output tensor can be uniformly represented by a handle. For example, the input tensor and the output tensor can both be represented by a variable of the reference handle TensorDataHandle type.
[0099] The calling method of the reasoning framework provided in the embodiment of the present application, in which input tensors and output tensors are uniformly represented by handles, can shield the differences in the underlying chips of various manufacturers. Users can obtain input tensors and output tensors through handles without having to understand the underlying methods of chips of various manufacturers. This is conducive to reducing the application difficulty of artificial intelligence reasoning models, reducing the time of using artificial intelligence reasoning models, and improving the application efficiency of artificial intelligence reasoning models.
[0100] Optionally, the above-mentioned input tensor and output tensor can also be encapsulated in a structure. For example, both the input tensor and the output tensor can be encapsulated with a reference handle TensorDataHandle using a tensor (Tensor) structure.
[0101] For example, the Tensor structure can be:
[0102] struct Tensor{
[0103] TensorDataHandle handle;
[0104] }
[0105] Optionally, the TensorDataHandle variable can be a character pointer type, i.e., char*. The TensorDataHandle variable can also be an untyped pointer, i.e., void*. The TensorDataHandle variable can also be an integer pointer, i.e., int*. The embodiment of the present application does not limit the type of the variable.
[0106] The calling method of the reasoning framework provided in the embodiment of the present application, when the calculation graph uses input tensor or output tensor information, the input tensor and output tensor are encapsulated using a unified Tensor structure, so that the input or output (i.e., TensorDataHandle) of a calculation graph has changed, but because it is encapsulated inside the Tensor, the Tensor structure variable corresponding to the TensorDataHandle remains unchanged, which is beneficial to ensure the accuracy of the input tensor or output tensor information, and is beneficial to solving the problem of dynamic changes in the input tensor or output tensor in the calculation graph reasoning framework.
[0107] As an optional embodiment, the above API may exist in at least one of the following forms: a dynamic link library, a static link library or an executable file.
[0108] The user can obtain multiple functions from the dynamic link library and / or the static link library according to the calling process, and use the multiple functions to call the reasoning model to obtain the reasoning result.
[0109] Exemplarily, the multiple functions may include the above-mentioned initialization function, computation graph creation function, computation graph input information acquisition function, input tensor creation function, input tensor reference function, input tensor acquisition function, input tensor assignment function, computation graph inference function, output tensor information acquisition function, output tensor reference function and output tensor acquisition function, etc.
[0110] Optionally, the above-mentioned multiple functions can also be called multiple modules, which may include an initialization module, a computational graph creation module, a computational graph input information acquisition module, an input tensor creation module, an input tensor reference module, an input tensor acquisition module, an input tensor assignment module, a computational graph reasoning module, an output tensor information acquisition module, an output tensor reference module, and an output tensor acquisition module, etc.
[0111] The inference device can initialize the inference device by calling the initialization module. The inference device can generate a calculation graph by calling the calculation graph creation module. The inference device can obtain at least one of the number of input tensors, the shape of each tensor, the data layout, the data type, or the storage location by calling the calculation graph input information acquisition module. It should be understood that other modules can implement corresponding functions, which will not be repeated here.
[0112] Optionally, the above-mentioned multiple functions can also be referred to as multiple interfaces, which may include an initialization interface, a computational graph creation interface, a computational graph input information acquisition interface, an input tensor creation interface, an input tensor reference interface, an input tensor acquisition interface, an input tensor assignment interface, a computational graph inference interface, an output tensor information acquisition interface, an output tensor reference interface, and an output tensor acquisition interface, etc.
[0113] The inference device can initialize the inference device by calling the initialization interface. The inference device can generate a computational graph by calling the computational graph creation interface. The inference device can obtain at least one of the number of input tensors, the shape of each tensor, the data layout, the data type, or the storage location by calling the computational graph input information acquisition interface. It should be understood that other interfaces can implement corresponding functions, which will not be described one by one here.
[0114] Users can execute multiple executable files according to the calling process to call the inference model and obtain the inference results.
[0115] Optionally, the API may exist in the form of a dynamic link library and a configuration file. Alternatively, the API may exist in the form of a static link library and a configuration file. Alternatively, the API may exist in the form of an executable file and a configuration file.
[0116] Each chip manufacturer can determine whether to set a configuration file based on the reasoning process of its own reasoning framework. The configuration file may include information such as the initialization parameters of the above-mentioned reasoning model, the target format of the reasoning model supported by the reasoning device, the parameters required for conversion to the target format, and the operating parameters of the reasoning model in the target format.
[0117] As an optional embodiment, the method 100 further includes: the inference device determines whether there is any un-inferred data in the input data; if there is no un-inferred data, the inference device releases the resources corresponding to the generated computation graph.
[0118] The resources corresponding to the generated computation graph may be the resources allocated by the inference device for generating the computation graph.
[0119] Exemplarily, the resources corresponding to the generated computation graph may include resources such as data structures allocated by the inference device for generating the computation graph, resources of the computation graph, operator parameters, and parameters of convolution kernels.
[0120] In the absence of un-inferred data, the inference device can call the computation graph release function (or computation graph release module, or computation graph release interface) in the API to release the resources allocated by the inference device for generating the computation graph.
[0121] Input data can be input into the computation graph one by one or in batches.
[0122] For example, the input data is 10 pictures, and when the input data is input into the computation graph, the inference device may input the pictures into the computation graph one by one. Alternatively, the input data is divided into 4 groups, each group of 5 pictures, and when the input data is input into the computation graph, the inference device may input the pictures into the computation graph one group after another.
[0123] When input data is input into the computation graph one by one, the inference device can determine whether there is unreasoned data in the input data after inputting an input data into the computation graph to obtain the inference result; if there is unreasoned data, continue to execute the above S104 and S105. If there is no unreasoned data, the inference device releases the resources corresponding to the generated computation graph.
[0124] The calling method of the reasoning framework provided in the embodiment of the present application releases the resources corresponding to the generated calculation graph when there is no unreasoned data. The previously allocated resources can be released when reasoning is not needed, which is conducive to reducing memory space and saving resources.
[0125] Optionally, in the inference process, when there is no un-inferred data, the inference device releases the reference handle of the output tensor, that is, clears the reference handle of the output tensor to 0 or deletes the reference handle of the output tensor. The inference device may also release the reference handle of the input tensor or create resources corresponding to the input tensor.
[0126] Exemplarily, the resources corresponding to creating the input tensor may include resources such as memory space, data structure, and cache allocated by the inference device to create the input tensor.
[0127] The inference device can call the output tensor reference release function (or output tensor reference release module, or output tensor reference release interface) in the API to release the reference handle of the output tensor.
[0128] The inference device can call the input tensor reference release function (or input tensor reference release module, or input tensor reference release interface) in the API to release the reference handle of the input tensor.
[0129] The inference device can call the input tensor release function (or input tensor release module, or input tensor release interface) in the API to release the resources allocated by the inference device for creating the input tensor.
[0130] Optionally, in the inference process, when there is no un-inferred data, the inference device releases the resources corresponding to the initialized inference device.
[0131] Exemplarily, the resources corresponding to creating the input tensor may include resources such as memory space, data results, and initialization parameters allocated by the inference device for initializing the inference device.
[0132] The inference device calls an inference device release function (or an inference device release module, or an inference device release interface) to release the resources allocated by the inference device for initializing the inference device.
[0133] It should be understood that, in the absence of un-inferred data, the inference process can release the resources allocated by the inference device for implementing the various steps involved in the above method 100.
[0134] The order of execution of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present application.
[0135] Combined with the above Figure 1 , describes in detail the calling method of the reasoning framework provided in the embodiment of the present application, and will be combined with Figure 2 and Figure 3 , describes in detail the calling device of the reasoning framework provided in the embodiment of the present application.
[0136] Figure 2 A calling device 200 of a reasoning framework provided in an embodiment of the present application is shown. The device 200 includes: an acquisition module 210 and a processing module 220. Among them, the acquisition module 210 is used to: obtain the operating parameters of the reasoning model based on the application program interface API; the processing module 220 is used to: initialize the device based on the API; generate a calculation graph using the operating parameters of the reasoning model, and obtain the input tensor according to the calculation graph; the acquisition module 210 is also used to: obtain input data; the processing module 220 is also used to: assign values to the input tensor using the input data to obtain the assigned input tensor; input the assigned input tensor into the calculation graph to obtain the output tensor, and, according to the output tensor, obtain the reasoning result.
[0137] Optionally, input and output tensors are represented uniformly by handles.
[0138] Optionally, the acquisition module 210 is further used to: acquire at least one of the following information of the input tensor according to the computation graph: number, shape, data layout, data type or storage location; the processing module is further used to: create an input tensor according to at least one information.
[0139] Optionally, the acquisition module 210 is also used to: acquire at least one of the following information of the input tensor according to the computation graph: number, shape, data layout, data type or storage location, and acquire a reference handle of the input tensor based on at least one of the information; and, obtain the input tensor based on the reference handle of the input tensor.
[0140] Optionally, the API exists in at least one of the following forms: a dynamic link library, a static link library, or an executable file.
[0141] Optionally, the apparatus 200 further includes a judgment module. The judgment module is used to judge whether there is unreasoned data in the input data; the processing module 220 is also used to: when there is no unreasoned data, the inference device releases resources corresponding to the generated computation graph.
[0142] It should be understood that the device 200 here is embodied in the form of a functional module. The term "module" here may refer to an application specific integrated circuit (ASIC), an electronic circuit, a processor (such as a shared processor, a proprietary processor or a group processor, etc.) and a memory for executing one or more software or firmware programs, a merged logic circuit and / or other suitable components that support the described functions. In an optional example, those skilled in the art may understand that the device 200 may be specifically the reasoning device in the above-mentioned embodiment, or the function of the reasoning device in the above-mentioned embodiment may be integrated in the device 200, and the device 200 may be used to execute the various processes and / or steps corresponding to the reasoning device in the above-mentioned method embodiment, and to avoid repetition, it will not be repeated here.
[0143] The above-mentioned device 200 has the function of implementing the corresponding steps performed by the inference device in the above-mentioned method 100; the above-mentioned function can be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules corresponding to the above-mentioned function. For example, the above-mentioned acquisition module can be a communication interface, such as a transceiver interface.
[0144] Figure 3 Another invocation device 300 of an inference framework provided in an embodiment of the present application is shown. The device 300 includes: a processor 310, a communication interface 320, and a memory 330. The processor 310, the communication interface 320, and the memory 330 communicate with each other through an internal connection path, the memory 330 is used to store instructions, and the processor 310 is used to execute the instructions stored in the memory 330 to control the communication interface to send signals and / or receive signals.
[0145] The above-mentioned device 300 is used to execute each process and step in the calling method 100 of the above-mentioned reasoning framework. Among them, the processor 310 is used to: obtain the operating parameters of the reasoning model based on the API; initialize the device 300 based on the API; generate a calculation graph using the operating parameters of the reasoning model, and obtain the input tensor according to the calculation graph; obtain input data, and use the input data to assign values to the input tensor to obtain the assigned input tensor; input the assigned input tensor into the calculation graph to obtain the output tensor, and obtain the reasoning result according to the output tensor.
[0146] It should be understood that the device 300 can be used to execute the various steps and / or processes corresponding to the reasoning device in the above-mentioned method embodiment. Optionally, the memory 330 may include a read-only memory and a random access memory, and provide instructions and data to the processor 310. A portion of the memory 330 may also include a non-volatile random access memory. For example, the memory 330 may also store information about the device type. The processor 310 can be used to execute instructions stored in the memory 330, and when the processor 310 executes instructions stored in the memory 330, the processor 310 is used to execute the various steps and / or processes of the above-mentioned method embodiment corresponding to the reasoning device.
[0147] It should be understood that in the embodiment of the present application, the processor 310 of the above-mentioned device 300 may be a central processing unit (CPU), and the processor 310 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.
[0148] In the implementation process, each step of the above method can be completed by an integrated logic circuit of hardware in a processor or an instruction in the form of software. The steps of the method disclosed in conjunction with the embodiment of the present application can be directly embodied as a hardware processor for execution, or a combination of hardware and software units in a processor for execution. The software unit can be located in a storage medium mature in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in a memory, and the processor executes the instructions in the memory, and completes the steps of the above method in conjunction with its hardware. To avoid repetition, it is not described in detail here.
[0149] The present application provides a computer-readable storage medium, which is used to store a computer program. The computer program is used to implement the method corresponding to the reasoning device in the above embodiment.
[0150] The present application provides a computer program product, which includes a computer program (also referred to as code or instruction). When the computer program runs on a computer, the computer can execute the method corresponding to the reasoning device in the above embodiment.
[0151] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0152] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0153] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0154] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0155] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0156] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the various embodiments of the present application. The aforementioned storage media include: various media that can store program codes, such as USB flash drives, mobile hard disks, read-only memories (ROM), random access memories (RAM), magnetic disks or optical disks.
[0157] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
Claims
1. A method for calling an inference framework, characterized in that: Applied to an inference device including an application program interface API, wherein the API is obtained by encapsulating the inference process of an inference framework, the method includes: The inference device obtains the operating parameters of the inference model based on the API; The inference device obtains and initializes the inference device based on the API; The inference device generates a computation graph using the operating parameters of the inference model, and obtains an input tensor according to the computation graph; The inference device acquires input data, and uses the input data to assign a value to the input tensor to obtain an assigned input tensor; the input data is a picture; The inference device inputs the assigned input tensor into the computation graph to obtain an output tensor; The inference device obtains an inference result according to the output tensor; The step of obtaining an input tensor according to the computation graph includes: The inference device obtains at least one of the following information of the input tensor according to the computation graph: number, shape, data layout, data type, or storage location; The inference device creates the input tensor according to the at least one information; or, The inference device obtains a reference handle of the input tensor according to the at least one information; The inference device obtains the input tensor according to the reference handle of the input tensor; The method further comprises: The inference device determines whether there is uninferred data in the input data; In the absence of the un-inferred data, the inference device releases resources corresponding to generating the computation graph; The input tensor and the output tensor are uniformly represented by a handle; the API exists in at least one of the following forms: a dynamic link library, a static link library or an executable file.
2. A device for calling an inference framework, characterized in that: include: An acquisition module is used to obtain the operating parameters of the inference model based on the application program interface API; A processing module, configured to initialize the device based on the API; Generate a computation graph using the operating parameters of the inference model, and obtain an input tensor according to the computation graph; The acquisition module is also used to: acquire input data; the input data is a picture; The processing module is further used to: assign a value to the input tensor using the input data to obtain an assigned input tensor; input the assigned input tensor into the calculation graph to obtain an output tensor, and obtain an inference result according to the output tensor; The device also includes a judgment module; The judging module is used for: Determining whether there is unreasoned data in the input data; The processing module is also used for: In the absence of the un-inferred data, the inference device releases resources corresponding to generating the computation graph; The processing module is specifically used for the inference device to obtain at least one of the following information of the input tensor according to the computation graph: number, shape, data layout, data type or storage location; the inference device to create the input tensor according to the at least one information; or the inference device to obtain the reference handle of the input tensor according to the at least one information; the inference device to obtain the input tensor according to the reference handle of the input tensor.
3. A device for calling an inference framework, characterized in that: include: A processor is coupled to a memory, wherein the memory is used to store a computer program, and when the processor calls the computer program, the device is caused to execute the method of claim 1.
4. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, which includes instructions for implementing the method according to claim 1.
5. A computer program product, comprising computer program code, characterized in that: When the computer program code is executed on a computer, the computer is caused to implement the method as claimed in claim 1 .
