Model reasoning optimization method and device, electronic equipment and storage medium
By obtaining sample data information to determine the compilation strategy, compiling and optimizing the deep learning model, the problems of high development costs and poor optimization effects in the existing technology are solved, and efficient model inference optimization is achieved.
Patent Information
- Application Number
- CN202411761614.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-03-21
AI Technical Summary
The existing model inference optimization method that implements model inference optimization through compilation optimization requires a significant change in the existing model inference code, which increases the development workload and cost. In addition, when using the default parameter configuration without experience, the inference optimization effect is poor.
By obtaining the data information of the sample data set, the compilation strategy of the model to be optimized is determined, and the original model is compiled based on the strategy, and replaced with the optimized compilation model for inference.
It reduces development workload and cost, ensures the applicability of compilation strategies, and improves the optimization effect of model inference.
Smart Images

Figure CN119670892A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of machine learning technology, and in particular to a model reasoning optimization method, device, electronic device and computer-readable storage medium. Background Art
[0002] Model inference refers to the use of trained deep learning models for prediction, classification and other tasks on a given test data set, and is a key link in deep learning applications. By optimizing the computational overhead and performance of the model inference process through optimization technology, the model performance and efficiency can be improved, thereby improving the response speed and processing power of the model in actual deployment.
[0003] Compilation optimization is one of the key means of optimizing model reasoning in related technologies. By optimizing the program code, the program can reduce the time and resource consumption as much as possible during execution. However, the existing method of optimizing model reasoning through compilation optimization requires a significant change to the existing model reasoning code, which increases the development workload and has high development costs. In addition, the existing compilation optimization method will use the default parameter configuration without experience, and the reasoning optimization effect is poor. Summary of the invention
[0004] According to a first aspect of the present disclosure, a model reasoning optimization method is provided, comprising: obtaining an original model of a model to be optimized; running model reasoning on the original model based on a sample data set, and obtaining data information of each sample data in the sample data set; determining a compilation strategy of the model to be optimized based on the data information, and compiling the original model of the model to be optimized based on the compilation strategy; replacing the original model with an optimized compiled model, and running model reasoning based on the compiled model.
[0005] According to a second aspect of the present disclosure, a model reasoning optimization device is provided, comprising: an acquisition module, used to acquire an original model of a model to be optimized; an operation module, used to operate model reasoning on the original model based on a sample data set, and to acquire data information of each sample data in the sample data set; a compilation module, used to determine a compilation strategy of the model to be optimized based on the data information, and to compile the original model of the model to be optimized based on the compilation strategy; the operation module is also used to replace the original model with an optimized compiled model, and to operate model reasoning based on the compiled model.
[0006] According to a third aspect of the present disclosure, there is provided an electronic device, comprising: a processor; and a memory storing a program, wherein the program comprises instructions, which, when executed by the processor, cause the processor to perform the above-mentioned model reasoning optimization method.
[0007] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to enable the computer to execute the above-mentioned model reasoning optimization method.
[0008] The exemplary embodiments of the present disclosure may have some or all of the following beneficial effects:
[0009] In the model reasoning optimization method provided in the example implementation of the present disclosure, the original model of the model to be optimized is obtained; model reasoning is performed on the original model based on a sample data set, and data information of each sample data in the sample data set is obtained; the compilation strategy of the model to be optimized is determined based on the data information, and the original model of the model to be optimized is compiled based on the compilation strategy; the original model is replaced with the optimized compiled model, and model reasoning is performed based on the compiled model. The embodiment of the present disclosure compiles the original model of the model to be optimized by obtaining data information of each sample data in the sample data set, and determining the compilation strategy of the model to be optimized based on the data information. The embodiment of the present disclosure can automatically determine the compilation strategy of the model to be optimized based on the data information of the sample data, thereby reducing the development workload and saving development costs. In addition, determining the compilation strategy based on the sample data information can ensure the applicability of the selected compilation strategy, thereby improving the optimization effect of model reasoning.
[0010] It is to be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] Further details, features and advantages of the present disclosure are disclosed in the following description of exemplary embodiments in conjunction with the accompanying drawings, in which:
[0012] Figure 1 A flow chart of a model reasoning optimization method according to an exemplary embodiment of the present disclosure is shown;
[0013] Figure 2 A flowchart of another model reasoning optimization method according to an exemplary embodiment of the present disclosure is shown;
[0014] Figure 3 A method flow chart of automatic compilation optimization in another model reasoning optimization method according to an exemplary embodiment of the present disclosure is shown;
[0015] Figure 4 A schematic block diagram of a model reasoning optimization device according to an exemplary embodiment of the present disclosure is shown;
[0016] Figure 5 A structural block diagram of an exemplary electronic device that can be used to implement the embodiments of the present disclosure is shown. DETAILED DESCRIPTION
[0017] Embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although certain embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be construed as being limited to the embodiments described herein, which are instead provided for a more thorough and complete understanding of the present disclosure. It should be understood that the drawings and embodiments of the present disclosure are only for exemplary purposes and are not intended to limit the scope of protection of the present disclosure.
[0018] It should be understood that the various steps described in the method embodiments of the present disclosure may be performed in different orders and / or in parallel. In addition, the method embodiments may include additional steps and / or omit the steps shown. The scope of the present disclosure is not limited in this respect.
[0019] The term "including" and its variations used in this document are open inclusions, that is, "including but not limited to". The term "based on" means "based at least in part on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one other embodiment"; the term "some embodiments" means "at least some embodiments". Relevant definitions of other terms will be given in the description below. It should be noted that the concepts of "first", "second", etc. mentioned in this disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0020] It should be noted that the modifications of "one" and "plurality" mentioned in the present disclosure are illustrative rather than restrictive, and those skilled in the art should understand that unless otherwise clearly indicated in the context, it should be understood as "one or more".
[0021] The names of the messages or information exchanged between multiple devices in the embodiments of the present disclosure are only used for illustrative purposes and are not used to limit the scope of these messages or information.
[0022] The following describes the aspects of the present disclosure with reference to the accompanying drawings for explanation.
[0023] The present application embodiment first provides a model reasoning optimization method. Figure 1 As shown, the model reasoning optimization method specifically includes the following steps:
[0024] S110: Obtaining the original model of the model to be optimized;
[0025] S120: running model inference on the original model based on the sample data set, and obtaining data information of each sample data in the sample data set;
[0026] S130: determining a compilation strategy of the model to be optimized based on the data information, and compiling the original model of the model to be optimized based on the compilation strategy;
[0027] S140: Replace the original model with the optimized compiled model, and run model reasoning based on the compiled model.
[0028] The disclosed embodiment compiles the original model of the model to be optimized by obtaining data information of each sample data in the sample data set and determining the compilation strategy of the model to be optimized based on the data information. The disclosed embodiment can automatically determine the compilation strategy of the model to be optimized based on the data information of the sample data, reducing the development workload and saving development costs. In addition, determining the compilation strategy based on the sample data information can ensure the applicability of the selected compilation strategy, thereby improving the optimization effect of model reasoning.
[0029] Next, in another embodiment, the above steps are described in more detail.
[0030] In step S110, the original model of the model to be optimized is obtained.
[0031] In an embodiment of the present application, the above-mentioned model to be optimized is a model that requires reasoning optimization.
[0032] In the embodiments of the present application, the original model refers to a model trained by a machine learning algorithm. The original model can be used to perform specific tasks. For example, the original model can be used to perform tasks such as target detection, image classification, and semantic segmentation.
[0033] In an embodiment of the present application, the above-mentioned original model can be a PyTorch model trained by an open source deep learning framework (PyTorch) based on machine learning and deep learning. PyTorch is an open source machine learning library that supports users in creating neural networks by providing a variety of deep learning tools. For example, PyTorch contains many pre-trained models for fields such as computer vision and natural language processing. Users can fine-tune the pre-trained model using a training data set to obtain a machine learning model that can better adapt to specific tasks.
[0034] In an embodiment of the present application, the above-mentioned reasoning optimization refers to optimizing the model reasoning process of the original model of the above-mentioned model to be optimized. Among them, the model reasoning process refers to the process of using the trained original model to operate on the newly input data to achieve corresponding prediction, classification and other tasks. Furthermore, the above-mentioned reasoning optimization aims to reduce the size of the original model, reduce memory usage, and accelerate the reasoning speed through various strategies and technical means, such as model quantization, pruning, knowledge distillation, compilation optimization, and hardware acceleration, thereby improving the response speed and processing power of the original model in actual deployment.
[0035] In an embodiment of the present application, the above-mentioned acquisition of the original model of the model to be optimized can be implemented as follows: the original model obtained by the above-mentioned training is loaded into the central processing unit (CPU) of an electronic device used to execute the model reasoning optimization method of the embodiment of the present application.
[0036] The embodiment of the present application mainly performs inference optimization on the original model of the model to be optimized by the above-mentioned compilation optimization method. Exemplarily, after obtaining the original model of the model to be optimized, the inference optimization process can be implemented by the following steps S120 to S140.
[0037] In step S120, model inference is performed on the original model based on the sample data set, and data information of each sample data in the sample data set is obtained.
[0038] In an embodiment of the present application, the sample data set is an input data set for running the model reasoning process. Exemplarily, if the original model of the model to be optimized is an image classification model trained by a machine learning algorithm, the image classification model can classify the input image into different categories, for example, the image classification model can classify the input image into cats or dogs. Then the sample data set may include multiple animal images, and the process of running the model reasoning is to input the animal images in the sample data set into the trained image classification model, and obtain the classification results based on the image classification model.
[0039] In an embodiment of the present application, the data information may include shape information of each sample data in the sample data set. For example, if the sample data set is image data, the shape information may be the resolution of the image, for example, 2k, 4k, 1080p, etc.
[0040] In the embodiment of the present application, the original model is a PyTorch model obtained by training based on PyTorch, then the data structure of the sample data in the sample data set can be a tensor, and the data information is the shape of the tensor. A tensor is a digital container in a machine learning program. It is a multilinear mapping that can describe physical quantities with size and multiple directions. It is essentially an array of various dimensions. The shape of a tensor includes the order of the tensor and the dimension of each order. The dimension refers to the element data of each order. The shape of a tensor is [D 0 ,D 1 ,...D n-1 ], where D 0 To D n-1 is an arbitrary positive integer. For example, if the shape of a tensor is expressed as [3,4], it means that there are 3 elements in the first dimension and 4 elements in the second dimension, and the tensor is a matrix with 3 rows and 4 columns.
[0041] In an embodiment of the present application, the data information of each sample data in the sample data set can be obtained based on a preset toolkit. Specifically, in the process of model reasoning based on the original model, input detection can be performed on the sample data input to the model reasoning based on the preset toolkit to obtain and save the data information of the sample data.
[0042] In an embodiment of the present application, the preset toolkit is a pre-developed toolkit, and by calling the application programming interface (API) of the toolkit to package the original model, the operation of performing input detection on the sample data inferred by the input model can be implemented.
[0043] In step S130 , a compilation strategy of the model to be optimized is determined based on the data information, and the original model of the model to be optimized is compiled based on the compilation strategy.
[0044] In the embodiment of the present application, the above compilation strategy refers to the compilation method adopted when performing compilation optimization on the original model.
[0045] In the embodiment of the present application, the above-mentioned compilation strategy can be line-level optimization, escape analysis, virtual call optimization, compiler inline cache, just-in-time compilation, etc., and the embodiment of the present application does not make any special limitations on this.
[0046] In the embodiment of the present application, the above compilation strategy can be determined based on data information. For example, taking the original model as an image classification model, if the image data obtained as input to the image classification model are all 1920*1080 images, the input data is determined to be static input, and the compilation strategy applicable to static input can be used. The model compilation only needs to consider the 1920*1080 input situation and compile for this resolution.
[0047] In the embodiment of the present application, further, the above-mentioned determination of the compilation strategy of the model to be optimized based on the data information can also be implemented as follows: determining the model information of the original model; determining the compilation strategy of the model to be optimized based on the data information and the model information.
[0048] In the embodiment of the present application, the above model information may include a model type. Exemplarily, according to the characteristics of the calculation form, the above original model can be divided into a memory-intensive model and a calculation-intensive model.
[0049] In the embodiments of the present application, the above-mentioned memory-intensive refers to computing tasks that mainly involve a large number of memory read and write operations during execution. Such operators usually need to frequently read data from the memory, perform some simple calculation operations, and then write the results back to the memory. The performance of memory-intensive operators is limited by memory bandwidth and access latency, and is not much limited by computing power.
[0050] In the embodiments of the present application, the above-mentioned computationally intensive refers to a computing task that mainly involves a large number of computing operations during execution, but relatively few accesses to memory. Such operators mainly rely on the computing power of the CPU or GPU, and often do not have particularly high requirements for memory bandwidth and access latency. Some numerical computation-intensive algorithms, such as matrix multiplication, convolution operations, and complex mathematical function calculations, are generally considered to be computationally intensive operations.
[0051] In an embodiment of the present application, the above-mentioned process of determining the compilation strategy of the model to be optimized based on data information and model information can be implemented, exemplarily, as follows: based on the shape of the sample data and the model type, the compilation strategy is determined from a preset configuration, that is, the inference optimization configuration compilation strategy of the original model is configured by comprehensively considering the tensor shape and the type of the original model.
[0052] Exemplarily, if the input sample data is of a static type, the corresponding compilation strategy only needs to be compiled for one shape. If the input sample data is of a discrete dynamic type, the corresponding compilation strategy will support all discrete shapes and provide optimal compilation support for the shape that appears the most times among all shapes in the sample, so that the reasoning performance of the shape can be as good as possible. For sample data of continuous dynamic types and discrete dynamic types, the selection of the above-mentioned optimal shape is based on the distribution of all input shapes, and the shape with the highest probability in the distribution is selected, and the value of the shape (length or width, etc.) is a multiple of 8, which is beneficial to GPU calculation.
[0053] If the model is compute-intensive, the corresponding compilation strategy will enable additional tuning for operators with high computational intensity (linear layers, convolutions, etc.); if the model is memory-intensive, the corresponding compilation strategy will enable GPU optimization (CudaGraph) to improve the inference speed.
[0054] In an embodiment of the present application, the preset configuration may be a plurality of compilation strategies pre-configured based on experience. Exemplarily, the preset configuration may include the correspondence between the data information and model type and the compilation strategy. When it is determined that the data information and / or model type meet the configuration conditions of a certain compilation strategy, the compilation strategy is configured as a compilation strategy for performing reasoning optimization.
[0055] In an embodiment of the present application, the above compilation process can be implemented based on the compilation backend.
[0056] In the embodiment of the present application, illustratively, at least one of the above-mentioned compilation backends can be deployed.
[0057] In an embodiment of the present application, when there are two or more compilation backends, the process of compiling the original model of the model to be optimized based on the compilation strategy can be implemented as follows: compile and optimize the model reasoning process of the original model based on each compilation backend in at least one compilation backend; based on the compilation optimization results of each compilation backend, determine the target compilation result from each compilation optimization result.
[0058] In an embodiment of the present application, the compilation optimization of the model reasoning process of the original model based on each compilation backend in at least one compilation backend can be specifically implemented as follows: the compilation backend determines the compilation strategy from the above-mentioned preset configuration based on the data information and the model type, and compiles and optimizes the original model based on the compilation strategy.
[0059] In the embodiment of the present application, the above-mentioned compilation optimization results based on each compilation backend, and determining the target compilation result from each compilation optimization result can be implemented as follows: by comparing the different compilation results of multiple compilation backends, the result with the best performance is selected and returned. Exemplarily, the above-mentioned best performance result is determined based on the reasoning speed of the original model, for example, it can be the compilation result with the fastest reasoning speed of the original model after compilation optimization.
[0060] Exemplarily, the specific implementation of the above-mentioned best performance result can be as follows: after each compilation backend completes compilation, it will use the model compiled by the current backend and combine it with the previously obtained input information to perform inference testing to obtain the inference speed (performance). The compilation result with the best performance is confirmed based on the inference speed of all compilation backends.
[0061] In the embodiment of the present application, the above-mentioned compilation backend can be any one or more of PyTorch's API (torch.compile), PyTorch integrated toolkit (torch tensorrt), high-performance deep learning inference engine (TensorRT), inference framework (OnnxRuntime) based on Open Neural Network Exchange (Onnx), and open source toolkit (OpenVino), or other compilation backends, which are not specifically limited in the embodiment of the present application.
[0062] In an embodiment of the present application, multiple different compilation backends are integrated, and each compilation backend will determine a more commonly used compilation strategy for the original model based on data information and model type, and refer to pre-set configuration rules, and select the best compilation result from multiple compilation results, thereby improving the optimization effect of compilation optimization on original model reasoning.
[0063] In an embodiment of the present application, the process of determining the compilation strategy of the model to be optimized based on the data information and compiling the original model of the model to be optimized based on the compilation strategy can also be executed by the preset toolkit.
[0064] In step S140 , the original model is replaced with the optimized compiled model, and model reasoning is performed based on the compiled model.
[0065] In the embodiment of the present application, the compiled model is a model obtained by compiling and optimizing the original model through the above steps S110 to S130.
[0066] In an embodiment of the present application, the above-mentioned replacement of the original model with the optimized compiled model can be performed by the above-mentioned preset toolkit.
[0067] In the embodiment of the present application, the original model can be packaged through the API of the preset toolkit. Specifically, the preset toolkit adds a line of code to the original model, which is the compilation optimization code. When the model reasoning is run on the original model, the compilation optimization code automatically executes the above-mentioned process of obtaining the data information of each sample data in the sample data set; determining the compilation strategy of the model to be optimized based on the data information, and compiling the original model of the model to be optimized based on the compilation strategy; and replacing the original model with the optimized compiled model.
[0068] In the embodiment of the present application, the above-mentioned compilation optimization process of the original model is automatically executed through the above-mentioned preset toolkit, without significantly changing the existing model reasoning code, and the reasoning optimization of the original model is achieved while ensuring that the development workload is not significantly increased. In addition, the above-mentioned automatic compilation process can also determine the appropriate compilation strategy for the original model based on data information and model type, solving the problem that the default parameter configuration used in the related technology may not obtain the ideal acceleration effect, or even fail to start the compilation.
[0069] In an embodiment of the present application, after the original model is replaced with a compiled model that has been compiled and optimized, when model reasoning is run again, model reasoning is run based on the compiled model, which can speed up the model reasoning.
[0070] The model reasoning optimization method provided by the embodiment of the present disclosure compiles the original model of the model to be optimized by obtaining data information of each sample data in the sample data set and determining the compilation strategy of the model to be optimized based on the data information. The embodiment of the present disclosure can automatically determine the compilation strategy of the model to be optimized based on the data information of the sample data, thereby reducing the development workload and saving development costs. In addition, determining the compilation strategy based on the sample data information can ensure the applicability of the selected compilation strategy, thereby improving the optimization effect of model reasoning.
[0071] Next, in another embodiment, the process of the above-mentioned model reasoning optimization method is described in detail. Figure 2 The model reasoning optimization method shown in FIG. 1 includes two stages, namely, the model input detection stage and the automatic compilation optimization stage, wherein:
[0072] The above model input detection phase includes the following steps:
[0073] S210: Loading the original model of the model to be optimized.
[0074] In an embodiment of the present application, the above-mentioned model to be optimized is a model that requires reasoning optimization.
[0075] In the embodiment of the present application, the original model is a PyTorch model trained by a machine learning algorithm based on the PyTorch framework. The original model can be used to perform specific tasks. For example, the original model can be used to perform tasks such as target detection, image classification, and semantic segmentation.
[0076] In an embodiment of the present application, this step is used to load the original model obtained by the above training into the CPU or GPU of an electronic device used to execute the model inference optimization method of an embodiment of the present application.
[0077] S220: Run model reasoning based on the original model.
[0078] In the embodiment of the present application, this step is used to run model reasoning based on the original model. The model reasoning process refers to the process of using the trained original model to operate on the newly input data to achieve the corresponding prediction, classification and other tasks.
[0079] S230: Perform input detection on the input data of the original model.
[0080] In the embodiment of the present application, input detection can be performed on the input data of the original model through a preset toolkit.
[0081] In an embodiment of the present application, the data structure of the above-mentioned input data is a tensor, and the above-mentioned input detection is used to obtain the shape of the tensor.
[0082] The above automatic compilation optimization phase includes the following steps:
[0083] S240: Load the original model again.
[0084] In an embodiment of the present application, after the model inference process is run once on the original model in the above-mentioned model input detection stage, this step is used to load the above-mentioned original model again into the CPU or GPU of the electronic device used to execute the model inference optimization method of the embodiment of the present application when the model inference is performed again.
[0085] S250: Automatically compile and optimize based on the input detection result.
[0086] In an embodiment of the present application, when the model reasoning is run again, the compilation optimization of the original model can be performed through the above-mentioned preset toolkit, and the compiled and optimized model can be used to replace the original model.
[0087] In the embodiment of the present application, the compilation optimization process is as follows: Figure 3As shown, the following can be achieved: by analyzing the model and input information, the model characteristics and the shape of the input information are determined; based on expert experience, the correspondence between the input information and the model and the compilation strategy is pre-set, and the corresponding preset configuration is obtained; after the input information is obtained based on the input detection of step S230, the compilation backend combines the input information and the model type, determines the appropriate compilation configuration from the above preset configuration, and performs compilation optimization to obtain the compilation result.
[0088] In the embodiment of the present application, the input information may be the shape of the input data, which may include a variety of different types, and may be, for example, a fixed size, a continuous dynamic size, or a discrete dynamic size, etc. The model feature may be a model type, and may be, for example, computationally intensive or memory-intensive.
[0089] In the embodiment of the present application, the above-mentioned compilation backend may include torch.compile, torch tensorrt, TensorRT, OnnxRuntime, OpenVino, etc. Each compilation backend will perform compilation configuration with expert experience according to the characteristics of the current model to achieve the best compilation effect; by comparing the compilation results of multiple backends, the result with the best performance is selected and returned.
[0090] In the embodiment of the present application, the preset toolkit implements two major functions: (1) model input detection; (2) compiling and optimizing the original model and replacing the original model. The method of using the preset toolkit is to wrap the original model with the API of the preset toolkit. Specifically, the preset toolkit wraps the original model by adding a line of code, and then implements an optimization process divided into two stages: model input detection stage and automatic compilation optimization stage, so as to automatically realize the compilation optimization of the PyTorch model.
[0091] S260: Run model reasoning based on the optimized model.
[0092] The above mainly introduces the solution provided by the embodiment of the present application from the perspective of the method. In order to achieve the above functions, it includes hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should easily appreciate that, in combination with the units and algorithm steps of each example described in the embodiments disclosed herein, the present invention can be implemented in the form of hardware or a combination of hardware and computer software. Whether a function is executed in the form of hardware or computer software driving hardware 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 exceed the scope of the present invention.
[0093] The embodiment of the present application can divide the functional modules of the model reasoning optimization device according to the above method example. For example, each functional module can be divided according to each function, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware or software functional module.
[0094] The present application embodiment provides a model reasoning optimization device. Figure 4 As shown, the model reasoning optimization device 400 may include an acquisition module 410, an operation module 420 and a compilation module 430, wherein:
[0095] An acquisition module 410 is used to acquire an original model of a model to be optimized;
[0096] An operation module 420 is used to run model reasoning on the original model based on the sample data set, and obtain data information of each sample data in the sample data set;
[0097] A compiling module 430, used to determine a compiling strategy of the model to be optimized based on the data information, and compile the original model of the model to be optimized based on the compiling strategy;
[0098] The running module 420 is also used to replace the original model with the optimized compiled model and run model reasoning based on the compiled model.
[0099] In an embodiment of the present application, the above-mentioned model to be optimized is a model that requires reasoning optimization.
[0100] In the embodiments of the present application, the original model refers to a model trained by a machine learning algorithm. The original model can be used to perform specific tasks. For example, the original model can be used to perform tasks such as target detection, image classification, and semantic segmentation.
[0101] In an embodiment of the present application, the above-mentioned acquisition module is specifically used to: load the original model obtained by the above-mentioned training into the central processing unit (CPU) of an electronic device used to execute the model reasoning optimization method of the embodiment of the present application.
[0102] In an embodiment of the present application, the sample data set is an input data set for running the model reasoning process. Exemplarily, if the original model of the model to be optimized is an image classification model trained by a machine learning algorithm, the image classification model can classify the input image into different categories, for example, the image classification model can classify the input image into cats or dogs. Then the sample data set may include multiple animal images, and the process of running the model reasoning is to input the animal images in the sample data set into the trained image classification model, and obtain the classification results based on the image classification model.
[0103] In the embodiment of the present application, the above-mentioned compilation module is specifically used to: determine the model information of the original model; and determine the compilation strategy of the model to be optimized based on the data information and the model information.
[0104] In the embodiment of the present application, the above compilation strategy refers to the compilation method adopted when performing compilation optimization on the original model.
[0105] In an embodiment of the present application, the above-mentioned compilation module is also used to: deploy at least one compilation backend, and the compilation backend is used to compile and optimize the model reasoning process based on the original model.
[0106] In an embodiment of the present application, the above-mentioned compilation module is specifically used to: compile and optimize the model reasoning process of the original model based on each compilation backend in at least one compilation backend; based on the compilation optimization results of each compilation backend, determine the target compilation result from each compilation optimization result.
[0107] In an embodiment of the present application, the above-mentioned compilation module specifically implements the above-mentioned compilation optimization of the model reasoning process of the original model based on each compilation backend in at least one compilation backend by executing the following steps: the compilation backend determines the compilation strategy from the above-mentioned preset configuration based on the data information and the model type, and compiles and optimizes the original model based on the compilation strategy.
[0108] In the embodiment of the present application, the compilation module implements the compilation optimization results based on each compilation backend by executing the following steps, and determines the target compilation result from each compilation optimization result: by comparing the different compilation results of multiple compilation backends, the result with the best performance is selected and returned. Exemplarily, the best performance result is determined based on the reasoning speed of the original model, for example, it can be the compilation result with the fastest reasoning speed of the original model after compilation optimization.
[0109] In an embodiment of the present application, the data structure of each sample data in the above-mentioned sample data set is a tensor, and the data information is a shape; the above-mentioned model information includes a model type, and the model type includes a computationally intensive model and a memory-intensive model.
[0110] In the embodiment of the present application, the above-mentioned compilation module is specifically used to: determine the compilation strategy from the preset configuration based on the shape and model type of the sample data.
[0111] In an embodiment of the present application, the preset configuration may be a plurality of compilation strategies pre-configured based on experience. Exemplarily, the preset configuration may include the correspondence between the data information and model type and the compilation strategy. When it is determined that the data information and / or model type meet the configuration conditions of a certain compilation strategy, the compilation strategy is configured as a compilation strategy for performing reasoning optimization.
[0112] In an embodiment of the present application, the above-mentioned compilation module is also used to: package the original model through a preset toolkit; wherein the preset toolkit packages the original model by adding compilation optimization code to the code of the original model, and the above-mentioned compilation optimization code is used to execute the acquisition of data information of each sample data in the sample data set, determine the compilation strategy of the model to be optimized based on the data information, and compile the original model of the model to be optimized based on the compilation strategy, and replace the original model with the optimized compiled model.
[0113] In addition, the specific implementation details of the above-mentioned model reasoning optimization device have been described in detail in the corresponding position of the model reasoning optimization method, so they will not be repeated here.
[0114] It should be noted that the division of modules in the embodiments of the present application is schematic and is merely a logical function division. There may be other division methods in actual implementation.
[0115] Figure 5 This is a schematic diagram of the structure of an electronic device in an embodiment of the present application. Figure 5 , which shows a structural schematic diagram of an electronic device 500 suitable for implementing the embodiments of the present application. Figure 5 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0116] like Figure 5 As shown, the electronic device 500 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 to a random access memory (RAM) 503 to implement the voice control method of the embodiment described in the present disclosure. In the RAM 503, various programs and data required for the operation of the electronic device 500 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0117] Typically, the following devices may be connected to the I / O interface 505: an input device 506 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 508 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 509. The communication device 509 may allow the electronic device 500 to communicate with other devices wirelessly or by wire to exchange data. Although Figure 5The electronic device 500 is shown with various devices, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0118] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a non-transitory computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart, thereby implementing the voice control method as described above. In such an embodiment, the computer program can be downloaded and installed from the network through the communication device 509, or installed from the storage device 508, or installed from the ROM 502. When the computer program is executed by the processing device 501, the above-mentioned functions defined in the method of the embodiment of the present application are executed.
[0119] It should be noted that the computer-readable medium disclosed above may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: 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 the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that may be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The computer readable signal medium may also be any computer readable medium other than a computer readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0120] In some embodiments, the client and the server may communicate using any currently known or future developed network protocol such as HTTP (HyperText Transfer Protocol), and may be interconnected with any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network ("LAN"), a wide area network ("WAN"), an internet (e.g., the Internet), and a peer-to-peer network (e.g., an ad hoc peer-to-peer network), as well as any currently known or future developed network.
[0121] The computer-readable medium may be included in the electronic device, or may exist independently without being installed in the electronic device.
[0122] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device:
[0123] Obtain the original model of the model to be optimized;
[0124] Run model inference on the original model based on the sample data set, and obtain data information of each sample data in the sample data set;
[0125] Determine a compilation strategy of the model to be optimized based on the data information, and compile the original model of the model to be optimized based on the compilation strategy;
[0126] Replace the original model with the optimized compiled model and run model inference based on the compiled model.
[0127] Optionally, when the above one or more programs are executed by the electronic device, the electronic device may also execute other steps described in the above embodiments.
[0128] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including, but not limited to, object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may 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 may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0129] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0130] The units involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of a unit does not, in some cases, constitute a limitation on the unit itself.
[0131] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, without limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), and the like.
[0132] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, 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 foregoing.
[0133] The above description is only a preferred embodiment of the present disclosure and an explanation of the technical principles used. Those skilled in the art should understand that the scope of disclosure involved in the present disclosure is not limited to the technical solutions formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosed concept. For example, the above features are replaced with the technical features with similar functions disclosed in the present disclosure (but not limited to) by each other to form a technical solution.
[0134] In addition, although each operation is described in a specific order, this should not be understood as requiring these operations to be performed in the specific order shown or in a sequential order. Under certain circumstances, multitasking and parallel processing may be advantageous. Similarly, although some specific implementation details are included in the above discussion, these should not be interpreted as limiting the scope of the present disclosure. Some features described in the context of a separate embodiment can also be implemented in a single embodiment in combination. On the contrary, the various features described in the context of a single embodiment can also be implemented in multiple embodiments individually or in any suitable sub-combination mode.
[0135] Although the subject matter has been described in language specific to structural features and / or methodological logical actions, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. On the contrary, the specific features and actions described above are merely example forms of implementing the claims.
Claims
1. A model reasoning optimization method, characterized in that: include: Obtain the original model of the model to be optimized; Running model inference on the original model based on the sample data set, and obtaining data information of each sample data in the sample data set; Determining a compilation strategy of the model to be optimized based on the data information, and compiling the original model of the model to be optimized based on the compilation strategy; The original model is replaced with the optimized compiled model, and model reasoning is performed based on the compiled model.
2. The model reasoning optimization method according to claim 1, characterized in that: The determining the compilation strategy of the model to be optimized based on the data information includes: Determining model information of the original model; A compilation strategy for the model to be optimized is determined based on the data information and the model information.
3. The model reasoning optimization method according to claim 2, characterized in that: The method further comprises: At least one compilation backend is deployed, and the compilation backend is used to compile and optimize the model reasoning process based on the original model.
4. The model reasoning optimization method according to claim 3, characterized in that: The compiling the original model of the model to be optimized based on the compilation strategy includes: Performing compilation optimization on the model reasoning process of the original model based on each of the at least one compilation backend; Based on the compilation optimization results of each of the compilation backends, a target compilation result is determined from each of the compilation optimization results.
5. The model reasoning optimization method according to claim 1, characterized in that: The data structure of each sample data in the sample data set is a tensor, and the data information is a shape; the model information includes a model type, and the model type includes a computationally intensive model and a memory-access intensive model.
6. The model reasoning optimization method according to claim 5, characterized in that: The determining the compilation strategy of the model to be optimized based on the data information includes: The compilation strategy is determined from a preset configuration based on the shape of the sample data and the model type.
7. The model reasoning optimization method according to claim 1, characterized in that: The method further comprises: Packaging the original model by using a preset toolkit; Among them, the preset toolkit packages the original model by adding compilation optimization code to the code of the original model, and the compilation optimization code is used to execute the acquisition of data information of each sample data in the sample data set, and the compilation strategy of the model to be optimized is determined based on the data information, and the original model of the model to be optimized is compiled based on the compilation strategy, and the original model is replaced with the optimized compiled model.
8. A model reasoning optimization device, characterized in that: include: An acquisition module is used to obtain the original model of the model to be optimized; An operation module, used to run model reasoning on the original model based on the sample data set, and obtain data information of each sample data in the sample data set; A compiling module, used to determine a compiling strategy of the model to be optimized based on the data information, and compile the original model of the model to be optimized based on the compiling strategy; The running module is also used to replace the original model with the optimized compiled model and run model reasoning based on the compiled model.
9. An electronic device, comprising: processor; as well as Memory for storing programs, The program includes instructions, which, when executed by the processor, cause the processor to perform the method according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium storing computer instructions, wherein: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-7.