Model optimization method and device, storage medium and electronic device

By acquiring terminal computing power information, determining parallel computing strategies, and pruning network models, the problem of underutilization of computing resources on terminal devices is solved, achieving more efficient utilization of computing resources and model optimization.

CN114692863BActive Publication Date: 2026-02-13GUANGDONG OPPO MOBILE TELECOMMUNICATIONS CORP LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011632659.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-31
Publication Date
2026-02-13
Estimated Expiration
2041-08-15

AI Technical Summary

Technical Problem

In existing technologies, network models struggle to effectively utilize computing power on terminal devices, resulting in underutilization of computing resources.

Method used

By acquiring the terminal's computing power information, a parallel computing strategy is determined, and the network model is pruned according to this strategy to remove unnecessary parallel computing channels and optimize the model to adapt to the terminal's computing power.

Benefits of technology

By effectively utilizing the computing power of the terminal, the model size can be reduced, the computation time shortened, and the running efficiency of the model on the terminal device improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114692863B_ABST
    Figure CN114692863B_ABST
Patent Text Reader

Abstract

The application discloses a model optimization method and device, a storage medium and an electronic device. The method comprises the following steps: obtaining a to-be-optimized model, and obtaining computing capability information of a terminal to which the to-be-optimized model is expected to be deployed; obtaining a parallel computing strategy of the to-be-optimized model according to the computing capability information, wherein the parallel computing strategy is used to describe channels of the to-be-optimized model that can be parallel computed by the terminal; determining a pruning strategy for the to-be-optimized model according to the parallel computing strategy, wherein the pruning strategy is used to describe channels of the to-be-optimized model that need to be pruned; and pruning the to-be-optimized model according to the pruning strategy for the to-be-optimized model to obtain an optimized model. In this way, the parallel computing strategy for the to-be-optimized model is obtained by using the computing capability information of the terminal, and the to-be-optimized model is pruned according to the parallel computing strategy, so that the computing capability of the terminal can be effectively utilized, the model volume can be compressed, and the model computing time can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of artificial intelligence, in particular to a model optimization method and device, a storage medium and an electronic device. BACKGROUND

[0002] At present, with the continuous development of artificial intelligence technology, network models are deployed on terminal devices such as smart phones, tablet computers and the like, for enhancing the processing capability of the terminal devices. For example, through the image optimization model deployed by the terminal device, the image captured by the terminal device can be optimized, and the image quality can be improved. In the related art, after the training of the network model is completed, the trained network model is deployed to the terminal device. Although the network model can run on the deployed terminal device, the network model cannot effectively utilize the computing capability of the deployment device. SUMMARY

[0003] The present application provides a model optimization method, device, storage medium and electronic device, which can optimize the network model in a targeted manner, so that the computing capability of the deployment device can be effectively utilized.

[0004] In a first aspect, the present application provides a model optimization method, comprising:

[0005] obtaining a to-be-optimized model, and obtaining computing capability information of a terminal to which the to-be-optimized model is expected to be deployed;

[0006] obtaining a parallel computing strategy of the to-be-optimized model according to the computing capability information, the parallel computing strategy being used to describe channels of the to-be-optimized model that can be computed in parallel on the terminal;

[0007] determining a pruning strategy for the to-be-optimized model according to the parallel computing strategy, the pruning strategy being used to describe channels of the to-be-optimized model that need to be pruned;

[0008] pruning the to-be-optimized model according to the pruning strategy to obtain an optimized model.

[0009] In a second aspect, the present application provides a model optimization device, comprising:

[0010] a model obtaining module, configured to obtain a to-be-optimized model, and obtain computing capability information of a terminal to which the to-be-optimized model is expected to be deployed;

[0011] a parallel analysis module, configured to obtain a parallel computing strategy of the to-be-optimized model according to the computing capability information, the parallel computing strategy being used to describe channels of the to-be-optimized model that can be computed in parallel on the terminal;

[0012] a pruning analysis module configured to determine a pruning strategy for the to-be-optimized model according to the parallel computing strategy, the pruning strategy being used to describe channels of parallel computing that need to be pruned in the to-be-optimized model; and

[0013] a model pruning module configured to prune the to-be-optimized model according to the pruning strategy, to obtain an optimized model.

[0014] In a third aspect, the present application provides a storage medium having a computer program stored thereon, which, when loaded by a processor of an electronic device, executes any of the model optimization methods provided in the present application.

[0015] In a fourth aspect, the present application further provides an electronic device, which comprises a processor and a memory, the memory storing a computer program, and the processor executes any of the model optimization methods provided in the present application by loading the computer program.

[0016] In the present application, the to-be-optimized model is obtained, and the computing capability information of a terminal to which the to-be-optimized model is expected to be deployed is obtained. The parallel computing strategy of the to-be-optimized model is obtained according to the computing capability information, and the parallel computing strategy is used to describe channels of the to-be-optimized model that can be parallel computed by the terminal. The pruning strategy for the to-be-optimized model is determined according to the parallel computing strategy, and the pruning strategy is used to describe channels of parallel computing that need to be pruned in the to-be-optimized model. The to-be-optimized model is pruned according to the pruning strategy for the to-be-optimized model, to obtain an optimized model. In this way, the parallel computing strategy for the to-be-optimized model is obtained by using the computing capability information of the terminal, and the to-be-optimized model is pruned according to the parallel computing strategy. Not only the computing capability of the terminal can be effectively utilized, but also the model size can be compressed, and the model computing time can be further reduced. BRIEF DESCRIPTION OF DRAWINGS

[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed in the embodiment description will be briefly introduced. Obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0018] Figure 1 is a flowchart of a model optimization method provided in an embodiment of the present application.

[0019] Figure 2 is an example diagram of a model optimization interface provided in an embodiment of the present application.

[0020] Figure 3 is an example diagram of a selection sub-interface provided in an embodiment of the present application.

[0021] Figure 4 is an example diagram of a parallel computing strategy obtained in an embodiment of the present application.

[0022] Figure 5 is an example diagram of parallel computing strategy A, parallel computing strategy B and parallel computing strategy C obtained in an embodiment of the present application.

[0023] Figure 6 is a schematic diagram of a parallel computing strategy corresponding to an optimization model obtained according to the parallel computing strategy in an embodiment of the present application.

[0024] Figure 7 is another flow diagram of a model optimization method provided in an embodiment of the present application.

[0025] Figure 8 is a schematic diagram of deployment of a model to be optimized to a terminal by an electronic device in an embodiment of the present application.

[0026] Figure 9 is a structural diagram of a model optimization apparatus provided in an embodiment of the present application.

[0027] Figure 10 is a structural diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0028] It should be noted that the principles of the present application are exemplified by implementation in a suitable computing environment. The following description is based on the exemplified embodiments of the present application, which should not be considered as limiting other embodiments of the present application not described in detail.

[0029] The relationship terms such as first and second involved in the following embodiments of the present application are only used to distinguish one object or operation from another object or operation, and do not mean that there is an actual sequential relationship between the objects or operations.

[0030] Artificial intelligence (Artificial Intelligence, AI) is the theory, method, technology and application system of using digital computer or digital computer controlled machine to simulate, extend and expand human intelligence, perceive environment, acquire knowledge and use knowledge to obtain optimal results. In other words, artificial intelligence is a comprehensive technology of computer science, which tries to understand the essence of intelligence and produce a new intelligent machine that can react in a similar way to human intelligence. Artificial intelligence is to study the design principles and implementation methods of various intelligent machines, so that machines have the functions of perception, reasoning and decision-making.

[0031] Artificial intelligence technology is a comprehensive discipline, involving a wide range of fields, both hardware and software level technology. Artificial intelligence basic technology generally includes, such as sensors, special artificial intelligence chips, cloud computing, distributed storage, big data processing technology, operation / interaction system, mechatronics and other technologies. Artificial intelligence software technology mainly includes computer vision technology, speech processing technology, natural language processing technology and machine learning / deep learning and other fields.

[0032] Among them, machine learning (Machine Learning, ML) is a multi-disciplinary subject, involving probability theory, statistics, approximation theory, convex analysis, algorithm complexity theory and other disciplines. It is a subject that studies how computers simulate or implement human learning behavior to acquire new knowledge or skills, reorganize existing knowledge structure to continuously improve their performance. Machine learning is the core of artificial intelligence and the fundamental approach to making computers intelligent. Its applications are widespread in various fields of artificial intelligence. Machine learning and deep learning usually include artificial neural networks, belief networks, reinforcement learning, transfer learning, inductive learning and other technologies. Using machine learning technology and the corresponding training data set, a network model that implements different functions can be trained, for example, based on a training data set, a network model for gender classification can be trained, and based on another training data set, an image optimization network model can be trained.

[0033] The scheme provided by the embodiments of the present application relates to machine learning technology of artificial intelligence, which is specifically explained as follows:

[0034] The model optimization method, model optimization device, storage medium and electronic device provided by the embodiments of the present application are provided, wherein the execution subject of the model optimization method can be the model optimization device provided by the embodiments of the present application, or the electronic device provided by the embodiments of the present application, wherein the model optimization device can be realized by hardware or software. The physical form of the electronic device can be a smart phone, a tablet computer, a vehicle-mounted computer, a palm computer, a notebook computer, a server or a desktop computer, etc. The device is equipped with a processor and has processing capability.

[0035] Please refer to Figure 1 , Figure 1 The flowchart of the model optimization method provided by the embodiments of the present application is shown. The model optimization method, as shown in Figure 1 The flowchart of the model optimization method provided by the embodiments of the present application can be as follows:

[0036] In 110, the model to be optimized is obtained, and the computing capability information of the terminal to be deployed is obtained.

[0037] The following describes the electronic device as the execution subject of the model optimization method.

[0038] In this embodiment, the electronic device first acquires the model to be optimized. The source of the model to be optimized is not specifically limited here; for example, the electronic device can acquire the model locally or from another electronic device. Furthermore, the training state of the model to be optimized is not specifically limited in this application; it can be a model that has already been trained, or a model that has been randomly initialized but has not yet been trained.

[0039] For example, when an electronic device receives a model optimization instruction input by a user, it can obtain the model to be optimized based on the user's input instruction. Alternatively, when it receives a model optimization request transmitted by another electronic device, it can obtain the model to be optimized based on the received model optimization request.

[0040] It should be noted that the embodiments of this application do not impose specific limitations on the settings of model optimization instructions and model optimization requests, and can be configured by those skilled in the art according to actual needs.

[0041] For example, electronic devices can receive input model optimization instructions through a model optimization interface that includes an instruction input interface, such as... Figure 2 As shown, the command input interface can be in the form of an input box. Users can enter the model identifier information of the network model to be optimized and then enter confirmation information (such as pressing the Enter key) to input the model optimization command to the electronic device. This command carries the model identifier information of the network model to be optimized, instructing the electronic device to use the network model corresponding to the identifier information as the model to be optimized. Furthermore, the model optimization interface also includes the prompt message "Please select the network model to be optimized."

[0042] For example, in Figure 2 The model optimization interface shown also includes an "Open" control. When the electronic device detects that this "Open" control has been triggered, it will overlay a selection sub-interface (such as...) on top of the model optimization interface. Figure 3As shown in FIG. 6, the selection sub-interface (for example, the selection sub-interface 601 shown in FIG. 6) provides the user with icons of locally-stored network models that can be optimized, such as icons of network model A, network model B, network model C, network model D, network model E, network model F, and the like, for the user to find and select an icon of a network model that needs to be optimized.

[0043] For another example, the electronic device receives a model optimization request transmitted by another electronic device, and parses model identification information carried in the model optimization request, the model identification information indicating a to-be-optimized model that needs to be optimized. Accordingly, the electronic device obtains the to-be-optimized model that needs to be optimized from the local or another electronic device according to the model identification information.

[0044] As described above, after obtaining the to-be-optimized model, the electronic device further obtains computing capability information of a terminal to which the to-be-optimized model is expected to be deployed. The computing capability information is used to describe the computing processing capability of the terminal that can be used to run the to-be-optimized model, such as the computing capability (including a computing unit (also referred to as a hardware engine, an operation acceleration unit, etc.), a memory, etc.) of a processor (which can be a general central processor or a special processor such as a neural network processor) used to run the to-be-optimized model.

[0045] For example, the to-be-optimized model is a voiceprint recognition model used for voiceprint recognition, which is expected to be deployed to a smartphone and run by a digital signal processor in the smartphone. The electronic device obtains the computing capability information of the digital signal processor.

[0046] In 120, a parallel computing strategy of the to-be-optimized model is obtained according to the computing capability information, and the parallel computing strategy is used to describe a channel of the to-be-optimized model that can be computed in parallel in the terminal.

[0047] It should be noted that for the topology of the network model, the network model can be divided into different layers, and the layers can be further divided into different channels. Different channels can be computed in parallel under the support of the computing capability.

[0048] Correspondingly, in the embodiment of the present application, after obtaining the to-be-optimized model and obtaining the computing capability information of the terminal to which the to-be-optimized model is expected to be deployed, the electronic device further analyzes the topology structure of the network model according to the computing capability information, and obtains a parallel computing strategy of the to-be-optimized model, which is used to describe the to-be-optimized model in the channel capable of parallel computing of the terminal.

[0049] For example, refer to Figure 4 , which shows a 4-layer to-be-optimized model parallel computing strategy. The first (①) layer of the to-be-optimized model is divided into a channel and a g channel, the second (②) layer is divided into a b channel and a g channel, the third (③) layer is divided into a c channel and an e channel, and the fourth (④) layer is divided into a d channel and an e channel. Among them, the a channel, the b channel, the c channel and the d channel can be parallel computed in the terminal, and the g channel, the h channel, the e channel and the f channel can be parallel computed in the terminal. For example, assuming that the required computing time of each of the a channel, the b channel, the c channel and the d channel is 100 ms, and the required computing time of each of the g channel, the h channel, the e channel and the f channel is 90 ms, then according to the foregoing parallel computing strategy, the to-be-optimized model is deployed to the terminal, and the total computing time required is 100+90=190 (ms).

[0050] In 130, a pruning strategy for the to-be-optimized model is determined according to the parallel computing strategy, which is used to describe the parallel computing channel that needs to be pruned in the to-be-optimized model.

[0051] It should be noted that in the embodiment of the present application, the terminal capable of parallel computing in the terminal is taken as the channel that can be pruned. Correspondingly, after obtaining the parallel computing strategy of the to-be-optimized model according to the computing capability information of the terminal, the electronic device further determines a pruning strategy for the to-be-optimized model according to the parallel computing strategy, which is used to describe the parallel computing channel that needs to be pruned in the to-be-optimized model.

[0052] For example, for Figure 4 the parallel computing strategy shown, the pruning strategy for the to-be-optimized model determined can prune the a channel, the b channel, the c channel and the d channel, or prune the g channel, the h channel, the e channel and the f channel.

[0053] In 140, the to-be-optimized model is pruned according to the pruning strategy for the to-be-optimized model, and an optimized model is obtained.

[0054] As described above, after determining the pruning strategy for the to-be-optimized model according to the parallel computing strategy, the electronic device further prunes the to-be-optimized model according to the pruning strategy, and the pruned to-be-optimized model is denoted as an optimized model.

[0055] For example, assume that the network model to be optimized is as follows: Figure 4 The g channel, h channel, e channel and f channel in the parallel computing strategy shown are pruned, and the optimized model obtained will include the a channel, b channel, c channel and d channel that can be computed in parallel. As can be seen, the computing time of the model to be optimized according to the foregoing parallel computing strategy is 190 ms, and the computing time of the optimized model after pruning is 190-90 = 100 (ms), and the volume of the optimized model is also effectively compressed compared with the model to be optimized.

[0056] As can be seen from the foregoing, the application obtains a model to be optimized, and obtains computing capability information of a terminal to which the model to be optimized is expected to be deployed; obtains a parallel computing strategy of the model to be optimized according to the computing capability information, the parallel computing strategy being used to describe channels of the model to be optimized that can be computed in parallel on the terminal; determines a pruning strategy for the model to be optimized according to the parallel computing strategy, the pruning strategy being used to describe channels of the model to be optimized that need to be pruned; and prunes the model to be optimized according to the pruning strategy for the model to be optimized to obtain an optimized model. In this way, the parallel computing strategy for the model to be optimized is obtained by using the computing capability information of the terminal, and the model to be optimized is pruned according to the parallel computing strategy, which not only effectively utilizes the computing capability of the terminal, but also compresses the model volume and further reduces the model computing time.

[0057] Optionally, in an embodiment, obtaining the parallel computing strategy of the model to be optimized according to the computing capability information comprises:

[0058] The model compiler compiles the model to be optimized according to the computing capability information to obtain the parallel computing strategy.

[0059] The model compiler can be regarded as a collection of a plurality of tool sets, and these tools can be combined for use to optimize the network model. For example, when a network model needs to be deployed to a smart phone and the central processor of the smart phone is used for computation, the model compiler can compile the network model according to the computing capability information of the central processor, so that the network model can be computed faster on the central processor of the smart phone.

[0060] Parallel computing is an important step to accelerate model computation, because operations such as convolution and matrix computation are a large number of computations that can be performed in parallel, and how to optimize the parallel structure is crucial to improving the performance of the model. Two problems need to be considered: one is parallelism, and the other is data sharing. If data is not shared, data read and write consumption will increase. However, if shared data is used as much as possible, a computing structure needs to be designed. Based on this, in the embodiments of the application, the electronic device compiles the model to be optimized according to the computing capability information of the terminal by using the model compiler, thereby obtaining the parallel computing strategy of the model to be optimized.

[0061] It should be noted that the model compiler used in the embodiments of the present application is not specifically limited, and a model compiler with parallel computing acceleration capability can be selected by a person of ordinary skill in the art according to actual needs.

[0062] For example, a TVM compiler can be used to compile the model to be optimized. The TVM compiler proposes the concept of memoryscope, which classifies data calculation into parallelizable and non-parallelizable. For parallelizable calculation, multi-threading can be used for parallel calculation, and for non-parallelizable calculation, it needs to wait for the completion of dependent data calculation.

[0063] Optionally, in an embodiment, when the plurality of parallel computing strategies are obtained, the pruning strategy for the model to be optimized is determined according to the parallel computing strategy, comprising:

[0064] (1) determining a candidate pruning strategy for the model to be optimized according to each parallel computing strategy, the candidate pruning strategy being used to describe a parallel computing channel that can be pruned in the model to be optimized;

[0065] (2) quality evaluation is performed on each candidate pruning strategy to obtain a quality score of each candidate pruning strategy;

[0066] (3) the candidate pruning strategy with the highest quality score is taken as the pruning strategy for the model to be optimized.

[0067] It can be understood that for the same model to be optimized, there can be multiple feasible parallel computing strategies. The embodiments of the present application explain how to determine the pruning strategy when there are multiple parallel computing strategies.

[0068] Wherein, when the plurality of parallel computing strategies are obtained, the electronic device determines a candidate pruning strategy for the model to be optimized according to each parallel computing strategy, and the candidate pruning strategy is used to describe a parallel computing channel that can be pruned in the model to be optimized. It should be noted that the candidate pruning strategy corresponding to one parallel computing strategy can be one or multiple.

[0069] As described above, when the plurality of parallel computing strategies are obtained, the plurality of corresponding candidate pruning strategies are obtained. At this point, an optimal candidate pruning strategy can be selected from the plurality of candidate pruning strategies as the pruning strategy for the model to be optimized, and the pruning strategy is used for pruning processing, so as to obtain an optimized model that can maximize the utilization of terminal computing capability.

[0070] The quality of each candidate pruning strategy is evaluated according to a pre-configured quality evaluation strategy, and the quality score of each candidate pruning strategy is obtained. The configuration of the quality evaluation strategy is not specifically limited here and can be configured by a person of ordinary skill in the art according to actual needs. For example, the precision drop value of the to-be-optimized model caused by the application of the candidate pruning strategy can be used as the quality evaluation standard, in which case the smaller the precision drop value, the higher the quality score; or the calculation time reduction value of the to-be-optimized model caused by the application of the candidate pruning strategy can be used as the quality evaluation standard, in which case the greater the calculation time reduction value, the higher the quality score.

[0071] As described above, after the quality score of each candidate pruning strategy is evaluated, the candidate pruning strategy with the highest quality score among the multiple candidate pruning strategies can be selected as the pruning strategy for the to-be-optimized model, and the pruning strategy is used to prune the to-be-optimized model to obtain an optimized model that can maximize the use of the computing power of the terminal.

[0072] For example, referring to Figure 5 , it is assumed that three different parallel computing strategies are determined for the to-be-optimized model, which are parallel computing strategy A, parallel computing strategy B, and parallel computing strategy C. It should be noted that the same letters in different parallel computing strategies do not represent the same channel.

[0073] For parallel computing strategy A, the first (①) layer of the to-be-optimized model is divided into a channel and a g channel, the second (②) layer is divided into a b channel and a g channel, the third (③) layer is divided into a c channel and an e channel, and the fourth (④) layer is divided into a d channel and an e channel. The a channel, the b channel, the c channel, and the d channel can be calculated in parallel on the terminal, and the g channel, the h channel, the e channel, and the f channel can be calculated in parallel on the terminal. For example, it is assumed that the calculation time required for each of the a channel, the b channel, the c channel, and the d channel is 100 ms, and the calculation time required for each of the g channel, the h channel, the e channel, and the f channel is 90 ms. According to parallel computing strategy A, the total calculation time required for deploying the to-be-optimized model to the terminal is 100+90=190 (ms). A plurality of candidate pruning strategies are determined for parallel computing strategy A, which are a candidate pruning strategy for pruning the a channel, the b channel, the c channel, and the d channel, and a candidate pruning strategy for pruning the g channel, the h channel, the e channel, and the f channel.

[0074] For parallel computing strategy B, the first (①) layer of the to-be-optimized model is divided into a channel, e channel and i channel, the second (②) layer is divided into b channel, f channel and j channel, the third (③) layer is divided into c channel, g channel and k channel, and the fourth (④) layer is divided into d channel, h channel and l channel. Among them, a channel and b channel can be calculated in parallel on the terminal, c channel and d channel can be calculated in parallel on the terminal, e channel and f channel can be calculated in parallel on the terminal, g channel and h channel can be calculated in parallel on the terminal, i channel and j channel can be calculated in parallel on the terminal, and k channel and l channel can be calculated in parallel on the terminal. For example, assuming that the required calculation time of a channel and b channel is 30ms respectively, the required calculation time of c channel and d channel is 45ms respectively, the required calculation time of e channel and f channel is 45ms respectively, the required calculation time of g channel and h channel is 40ms respectively, the required calculation time of i channel and j channel is 15ms respectively, and the required calculation time of k channel and l channel is 15ms respectively, then according to the parallel computing strategy B, the total calculation time required for deploying the to-be-optimized model to the terminal is 30+45+45+40+15+15=190(ms). For parallel computing strategy B, a plurality of candidate pruning strategies are determined, which are candidate pruning strategies of pruning a channel and b channel, candidate pruning strategies of pruning c channel and d channel, candidate pruning strategies of pruning e channel and f channel, candidate pruning strategies of pruning g channel and h channel, candidate pruning strategies of pruning i channel and j channel, and candidate pruning strategies of pruning k channel and l channel.

[0075] For parallel computing strategy C, the first (①) layer of the to-be-optimized model is divided into a channel and e channel, the second (②) layer is divided into b channel and f channel, the third (③) layer is divided into c channel and g channel, and the fourth (④) layer is divided into d channel and h channel. Among them, a channel, b channel, c channel and d channel can be calculated in parallel on the terminal, e channel and f channel can be calculated in parallel on the terminal, and g channel and h channel can be calculated in parallel on the terminal. For example, assuming that the required calculation time of a channel, b channel, c channel and d channel is 110ms respectively, the required calculation time of e channel and f channel is 50ms respectively, and the required calculation time of g channel and h channel is 30ms respectively, then according to the parallel computing strategy C, the total calculation time required for deploying the to-be-optimized model to the terminal is 110+50+30=190(ms). For parallel computing strategy C, a plurality of candidate pruning strategies are determined, which are candidate pruning strategies of pruning a channel, b channel, c channel and d channel, candidate pruning strategies of pruning e channel and f channel, and candidate pruning strategies of pruning g channel and h channel.

[0076] If the candidate pruning strategy of cutting the g channel and the h channel corresponding to the parallel computing strategy C is determined as the candidate pruning strategy with the highest quality score, the electronic device determines the candidate pruning strategy of cutting the g channel and the h channel corresponding to the parallel computing strategy C as the pruning strategy for the to-be-optimized model. Correspondingly, when pruning processing is performed, the g channel and the h channel of the to-be-optimized model are cut according to the parallel computing strategy C to obtain the optimized model.

[0077] Optionally, in an embodiment, quality evaluation is performed on each candidate pruning strategy to obtain a quality score of each candidate pruning strategy, including:

[0078] (1) pruning processing is performed on the to-be-optimized model according to each candidate pruning strategy to obtain a candidate optimized model corresponding to each candidate pruning strategy;

[0079] (2) quality evaluation is performed on each candidate optimized model in multiple quality dimensions to obtain multiple quality dimension scores;

[0080] (3) the multiple quality dimension scores of each candidate optimized model are fused to obtain a quality score of the candidate pruning strategy corresponding to each candidate optimized model.

[0081] The embodiments of the present application provide an optional quality evaluation strategy for a candidate pruning strategy.

[0082] For a candidate pruning strategy, the electronic device can perform pruning processing on the to-be-optimized model according to the candidate pruning strategy, and the to-be-optimized model pruned according to the candidate pruning strategy is denoted as a candidate optimized model.

[0083] Then, quality evaluation is performed on the candidate optimized model in multiple quality dimensions to obtain multiple quality dimension scores. It should be noted that if the to-be-optimized model obtained is a model that has been trained, the candidate optimized model pruned from the to-be-optimized model is fine-tuned before quality evaluation is performed on the candidate optimized model, and quality evaluation is performed on the candidate optimized model after fine-tuning is completed. If the to-be-optimized model obtained is a model that has not been trained, the candidate optimized model pruned from the to-be-optimized model is trained before quality evaluation is performed on the candidate optimized model, and quality evaluation is performed on the candidate optimized model after training is completed.

[0084] Wherein, for selecting which quality dimension, the person skilled in the art can select according to actual needs, and the embodiments of the present application do not make specific limitations thereto. For example, the precision dimension, the calculation time dimension and the power consumption dimension can be selected, wherein, for the precision dimension, the precision reduction value of the candidate optimization model compared with the to-be-optimized model (for example, respectively deploying the candidate optimization model and the to-be-optimized model to the terminal, testing the calculation precision of the terminal running the to-be-optimized model, and testing the calculation precision of the terminal running the candidate optimization model, and the difference between the two precisions is the precision reduction value) can be used as the quality evaluation standard, and the smaller the precision reduction value is, the higher the quality score is; for the calculation time dimension, the calculation time reduction value of the candidate optimization model compared with the to-be-optimized model (for example, respectively deploying the candidate optimization model and the to-be-optimized model to the terminal, measuring the calculation time of the terminal running the to-be-optimized model, and measuring the calculation time of the terminal running the candidate optimization model, and the difference between the two times is the time reduction value) can be used as the quality evaluation standard, and the greater the time reduction value is, the higher the quality score is; for the power consumption dimension, the power consumption reduction value of the candidate optimization model compared with the to-be-optimized model (for example, respectively deploying the candidate optimization model and the to-be-optimized model to the terminal, measuring the power consumption value of the terminal running the to-be-optimized model, and measuring the power consumption value of the terminal running the candidate optimization model, and the difference between the two power consumption values is the power consumption reduction value) can be used as the quality evaluation standard, and the greater the power consumption reduction value is, the higher the quality score is.

[0085] As above, for a candidate optimization model, the quality dimension scores of the candidate optimization model in multiple different quality dimensions can be evaluated. In order to more accurately reflect its quality, the embodiments of the present application fuse the multiple quality dimension scores of the candidate optimization model according to the configured fusion strategy to obtain a fusion score, and the fusion score is taken as the quality score of the candidate optimization model, that is, the quality score of the candidate pruning strategy corresponding to the candidate optimization model.

[0086] According to the quality evaluation strategy as above, the quality score of each candidate pruning strategy determined according to the parallel computing strategy can be evaluated.

[0087] It should be noted that the above fusion strategy is not specifically limited in the embodiments of the present application, and can be configured by the person skilled in the art according to actual needs.

[0088] Optionally, fusing the multiple quality dimension scores of each candidate optimization model to obtain the quality score of the candidate pruning strategy corresponding to each candidate optimization model comprises:

[0089] The multiple quality dimension scores of each candidate optimization model are weighted and summed, and the obtained weighted sum value is taken as the quality score of the candidate pruning strategy corresponding to each candidate optimization model.

[0090] The embodiments of the present application provide an optional fusion strategy.

[0091] wherein, in fusing the multiple quality dimension scores of each candidate optimization model, the electronic device performs a weighted summation on the multiple quality dimension scores of each candidate optimization model according to the weight assigned to each quality dimension, and takes the obtained weighted sum value as the quality score of the candidate pruning strategy corresponding to each candidate optimization model.

[0092] It should be noted that the present embodiment does not make specific limitations on how the weight of each quality dimension is distributed, and the weight sum value of all quality dimensions is 1 as a constraint, which can be distributed by those skilled in the art according to actual needs. For example, assuming that the precision dimension, the calculation time dimension and the power consumption dimension are selected, the weight of the precision dimension can be assigned to “0.7”, the weight of the calculation time dimension can be assigned to “0.2”, and the weight of the power consumption dimension can be assigned to “0.1”.

[0093] Optionally, in an embodiment, the model optimization method provided by the present application further comprises:

[0094] (1) adjusting the parallel computing strategy according to the pruning strategy for the to-be-optimized model to obtain a parallel computing strategy corresponding to the optimization model;

[0095] (2) deploying the optimization model to the terminal according to the parallel computing strategy corresponding to the optimization model.

[0096] In the present embodiment, the optimization model is also deployed to the terminal.

[0097] According to the above description, those skilled in the art can understand that, since the optimization model is obtained by pruning the to-be-optimized model according to the pruning strategy for the to-be-optimized model, the optimization model has some channels pruned compared with the to-be-optimized model, which will result in that the parallel computing strategy originally applicable to the to-be-optimized model is not applicable to the optimization model.

[0098] Therefore, when deploying the terminal to the terminal, the parallel computing strategy is first adjusted according to the pruning strategy for the to-be-optimized model to obtain a parallel computing strategy corresponding to the optimization model, and then the optimization model is deployed to the terminal according to the parallel computing strategy corresponding to the optimization model.

[0099] For example, referring to Figure 6 , Figure 6 The left side shows a parallel computing strategy corresponding to a to-be-optimized model, and the optimization model obtained by pruning the to-be-optimized model has g channel, h channel, e channel and f channel pruned compared with the to-be-optimized model, Figure 6 The right side shows a parallel computing strategy corresponding to the optimization model, and when the optimization model is deployed to the terminal according to the parallel computing strategy corresponding to the optimization model, the a channel, the b channel, the c channel and the d channel in the optimization model will be parallel computed on the terminal.

[0100] Optionally, in an embodiment, the terminal comprises a neural network processor, and the computing capability information of the terminal to which the to-be-optimized model is expected to be deployed is acquired, comprising:

[0101] (1) acquiring the computing capability information of the neural network processor;

[0102] deploying the optimized model to the terminal according to the parallel computing strategy corresponding to the optimized model, comprising:

[0103] (2) deploying the optimized model to the neural network processor according to the parallel computing strategy corresponding to the optimized model.

[0104] In the embodiment of the application, the terminal comprises a neural network processor,

[0105] It should be noted that the neural network processor at least comprises a computing unit (also referred to as a computing unit, a hardware engine, an operation acceleration unit, etc.) for executing a computing task, and a memory for storing model data and related data (such as original data required for computation, intermediate data during computation, result data, etc.) of model computation.

[0106] The convolution computing unit is also referred to as a convolution computing engine, and can comprise a plurality of multiplication-add cells (MAC) in the inside. The number of multiplication-add cells can be several thousand, for example, the convolution computing unit can comprise 4096 multiplication-add cells, and the 4096 multiplication-add cells can be further divided into 16 cells, and each cell can perform a maximum element number of 256 vector inner product operations.

[0107] The vector computing unit is also referred to as a single instruction multiple data (SIMD) processing unit. The vector computing unit is an element-level vector computing engine, which can process common arithmetic operations such as addition, subtraction, multiplication and division between vectors, and can also process bit-level logical operations such as AND, OR, NOT and XOR. In addition, the vector computing unit supports common activation function operations such as rectified linear unit (ReLU) and PRelU.

[0108] In the embodiment of the application, when the electronic device acquires the computing capability information of the terminal, the computing capability information of the neural network processor in the terminal is specifically acquired, and the to-be-optimized model is optimized according to the computing capability information, to obtain an optimized model adapted to the neural network processor. For specific optimization process, please refer to the related description in the above embodiment, which will not be repeated here.

[0109] After the optimization model adapted to the neural network processor in the terminal is obtained, and the corresponding parallel computing strategy of the optimization model is obtained, the electronic device deploys the optimization model to the neural network processor according to the parallel computing strategy of the corresponding optimization model. In this way, the optimization model can maximize the use of the computing power of the neural network processor.

[0110] Please refer to Figure 7 , Figure 7 Another flowchart of the model optimization method provided by the embodiment of the present application is provided, which is implemented by an electronic device. As shown in Figure 7 The flowchart of the model optimization method provided by the embodiment of the present application can be as follows:

[0111] In 210, the electronic device obtains a to-be-optimized model, and obtains the computing capability information of a terminal to which the to-be-optimized model is expected to be deployed.

[0112] In the embodiment of the present application, the electronic device first obtains a to-be-optimized model that needs to be optimized. The source of the to-be-optimized model is not specifically limited here, for example, the electronic device can obtain the to-be-optimized model from the local, or can obtain the to-be-optimized model from other electronic devices. In addition, the training state of the to-be-optimized model is not specifically limited in the present application, which can be a model that has been trained, or a model that has been randomly initialized and has not been trained.

[0113] For example, the electronic device can obtain the to-be-optimized model that needs to be optimized according to the model optimization instruction input by the user when receiving the model optimization instruction input by the user, or can obtain the to-be-optimized model that needs to be optimized according to the received model optimization request when receiving the model optimization request transmitted by other electronic devices.

[0114] As described above, after obtaining the to-be-optimized model, the electronic device further obtains the computing capability information of the terminal to which the to-be-optimized model is expected to be deployed. The computing capability information is used to describe the computing processing capability of the terminal that can be used to run the to-be-optimized model, such as the computing capability (including the computing unit (also known as hardware engine, operation acceleration unit, etc.), memory, etc.) of the processor (which can be a general central processor or a special processor such as a neural network processor) used to run the to-be-optimized model.

[0115] For example, the to-be-optimized model is a voiceprint recognition model used for voiceprint recognition, which is expected to be deployed to a smartphone and run by a digital signal processor in the smartphone, and the electronic device obtains the computing capability information of the digital signal processor.

[0116] In 220, the electronic device compiles the to-be-optimized model according to the computing capability information by a model compiler to obtain a plurality of parallel computing strategies of the to-be-optimized model.

[0117] The model compiler can be regarded as a collection of a plurality of tool sets, which can be combined for use to optimize the network model. For example, when a network model needs to be deployed to a smart phone and the central processor of the smart phone is used for calculation, the model compiler can be used to compile the network model according to the computing capability information of the central processor, so that the network model can be calculated faster on the central processor of the smart phone.

[0118] Parallel computing is an important step for accelerating model calculation, because operations such as convolution and matrix calculation are a large number of operations that can be performed in parallel. How to optimize the parallel structure is crucial to improving the performance of the model. Two problems need to be considered: one is parallelism, and the other is data sharing. If data is not shared, data read and write consumption will increase. If shared data is used as much as possible, a computing structure needs to be designed. Based on this, in the embodiments of the present application, the electronic device compiles the to-be-optimized model according to the computing capability information of the terminal by a model compiler, thereby obtaining a parallel computing strategy of the to-be-optimized model.

[0119] It should be noted that the model compiler used in the embodiments of the present application is not specifically limited, and a model compiler with parallel computing acceleration capability can be selected by a person skilled in the art according to actual needs.

[0120] For example, a TVM compiler can be used to compile the to-be-optimized model. The TVM compiler proposes the concept of memoryscope, which classifies data calculation into parallel and non-parallel. For parallel computing, multi-threading can be used for parallel computing. For non-parallel computing, it needs to wait for the dependent data calculation to be completed.

[0121] In 230, the electronic device determines a candidate pruning strategy for the to-be-optimized model according to each parallel computing strategy, and performs quality evaluation on each candidate pruning strategy to obtain a quality score of each candidate pruning strategy.

[0122] When a plurality of parallel computing strategies are obtained, the electronic device determines a candidate pruning strategy for the to-be-optimized model according to each parallel computing strategy. The candidate pruning strategy is used to describe a parallel computing channel that can be removed in the to-be-optimized model. It should be noted that the candidate pruning strategy corresponding to one parallel computing strategy can be one or a plurality of candidate pruning strategies.

[0123] As described above, obtaining multiple parallel computing strategies will yield multiple corresponding candidate pruning strategies. Therefore, the optimal candidate pruning strategy can be selected from these to prune the model to be optimized, thereby obtaining an optimized model that maximizes the utilization of the terminal's computing power.

[0124] For each candidate pruning strategy, the electronic device evaluates its quality according to a pre-configured quality assessment strategy, thereby obtaining a quality score for each candidate pruning strategy. The configuration of the quality assessment strategy is not specifically limited here and can be configured by those skilled in the art according to actual needs. For example, the decrease in accuracy of the model to be optimized caused by applying the candidate pruning strategy can be used as the quality assessment standard; in this case, the smaller the decrease in accuracy, the higher the quality score. Alternatively, the reduction in computation time of the model to be optimized caused by applying the candidate pruning strategy can be used as the quality assessment standard; in this case, the greater the reduction in computation time, the higher the quality score.

[0125] In step 240, the electronic device selects the candidate pruning strategy with the highest quality score as the pruning strategy for the model to be optimized, and performs pruning on the model to be optimized according to the pruning strategy for the model to be optimized, thereby obtaining the optimized model.

[0126] As shown above, after evaluating the quality score of each candidate pruning strategy, the candidate pruning strategy with the highest quality score among multiple candidate pruning strategies can be used as the pruning strategy for the model to be optimized. This pruning strategy is then used to prune the model to be optimized, resulting in an optimized model that maximizes the use of the terminal's computing power.

[0127] For example, please refer to Figure 5 Suppose that three different parallel computing strategies are determined for the model to be optimized: parallel computing strategy A, parallel computing strategy B, and parallel computing strategy C. It should be noted that in different parallel computing strategies, the same letter does not represent the same channel.

[0128] wherein, for parallel computing strategy A, the first (1) layer of the to-be-optimized model is divided into a channel and a g channel, the second (2) layer is divided into a b channel and a g channel, the third (3) layer is divided into a c channel and an e channel, and the fourth (4) layer is divided into a d channel and an e channel. Among them, the a channel, the b channel, the c channel and the d channel can be calculated in parallel on the terminal, and the g channel, the h channel, the e channel and the f channel can be calculated in parallel on the terminal. For example, assuming that the required calculation time of each of the a channel, the b channel, the c channel and the d channel is 100 ms, and the required calculation time of each of the g channel, the h channel, the e channel and the f channel is 90 ms, then according to the parallel computing strategy A, the total calculation time required for deploying the to-be-optimized model to the terminal is 100+90=190 (ms). For parallel computing strategy A, a plurality of candidate pruning strategies are determined, which are candidate pruning strategies of pruning the a channel, the b channel, the c channel and the d channel, and candidate pruning strategies of pruning the g channel, the h channel, the e channel and the f channel.

[0129] For parallel computing strategy B, the first (1) layer of the to-be-optimized model is divided into an a channel, an e channel and an i channel, the second (2) layer is divided into a b channel, an f channel and a j channel, the third (3) layer is divided into a c channel, a g channel and a k channel, and the fourth (4) layer is divided into a d channel, an h channel and an l channel. Among them, the a channel and the b channel can be calculated in parallel on the terminal, the c channel and the d channel can be calculated in parallel on the terminal, the e channel and the f channel can be calculated in parallel on the terminal, the g channel and the h channel can be calculated in parallel on the terminal, the i channel and the j channel can be calculated in parallel on the terminal, and the k channel and the l channel can be calculated in parallel on the terminal. For example, assuming that the required calculation time of each of the a channel and the b channel is 30 ms, the required calculation time of each of the c channel and the d channel is 45 ms, the required calculation time of each of the e channel and the f channel is 45 ms, the required calculation time of each of the g channel and the h channel is 40 ms, the required calculation time of each of the i channel and the j channel is 15 ms, and the required calculation time of each of the k channel and the l channel is 15 ms, then according to the parallel computing strategy B, the total calculation time required for deploying the to-be-optimized model to the terminal is 30+45+45+40+15+15=190 (ms). For parallel computing strategy B, a plurality of candidate pruning strategies are determined, which are candidate pruning strategies of pruning the a channel and the b channel, candidate pruning strategies of pruning the c channel and the d channel, candidate pruning strategies of pruning the e channel and the f channel, candidate pruning strategies of pruning the g channel and the h channel, candidate pruning strategies of pruning the i channel and the j channel, and candidate pruning strategies of pruning the k channel and the l channel.

[0130] For the parallel computing strategy C, the first (1) layer of the to-be-optimized model is divided into a channel and an e channel, the second (2) layer is divided into a b channel and an f channel, the third (3) layer is divided into a c channel and a g channel, and the fourth (4) layer is divided into a d channel and an h channel. Among them, the a channel, the b channel, the c channel and the d channel can be calculated in parallel on the terminal, the e channel and the f channel can be calculated in parallel on the terminal, and the g channel and the h channel can be calculated in parallel on the terminal. For example, assuming that the required calculation time of each of the a channel, the b channel, the c channel and the d channel is 110 ms, the required calculation time of each of the e channel and the f channel is 50 ms, and the required calculation time of each of the g channel and the h channel is 30 ms, then according to the parallel computing strategy C, the to-be-optimized model is deployed to the terminal, and the total calculation time required is 110+50+30=190 (ms). A plurality of candidate pruning strategies are determined for the parallel computing strategy C, which are the candidate pruning strategy of pruning the a channel, the b channel, the c channel and the d channel, the candidate pruning strategy of pruning the e channel and the f channel, and the candidate pruning strategy of pruning the g channel and the h channel.

[0131] If the candidate pruning strategy of pruning the g channel and the h channel corresponding to the parallel computing strategy C is determined as the candidate pruning strategy with the highest quality score, the electronic device determines the candidate pruning strategy of pruning the g channel and the h channel corresponding to the parallel computing strategy C as the pruning strategy for the to-be-optimized model.

[0132] As described above, after determining the pruning strategy for the to-be-optimized model according to the parallel computing strategy, the electronic device further prunes the to-be-optimized model according to the pruning strategy, and the pruned to-be-optimized model is denoted as an optimized model. For example, the candidate pruning strategy of pruning the g channel and the h channel corresponding to the parallel computing strategy C is determined as the pruning strategy for the to-be-optimized model, and the g channel and the h channel of the to-be-optimized model are pruned to obtain the optimized model during the pruning process.

[0133] In 250, the electronic device adjusts the parallel computing strategy according to the pruning strategy for the to-be-optimized model, and obtains a parallel computing strategy corresponding to the optimized model.

[0134] In 260, the electronic device deploys the optimized model to the terminal according to the parallel computing strategy corresponding to the optimized model.

[0135] According to the above description, those skilled in the art can understand that, since the optimized model is obtained by pruning the to-be-optimized model according to the pruning strategy for the to-be-optimized model, the optimized model prunes part of the channels compared to the to-be-optimized model, which will result in that the parallel computing strategy originally applicable to the to-be-optimized model is not applicable to the optimized model.

[0136] Therefore, when deploying the terminal to the terminal, the pruning strategy for the to-be-optimized model is used to adjust the parallel computing strategy, to obtain a parallel computing strategy corresponding to the optimized model, and then the optimized model is deployed to the terminal according to the parallel computing strategy corresponding to the optimized model.

[0137] For example, referring to Figure 8 , the entity of the electronic device is a server, and the entity of the terminal is a smart phone. After the server obtains a to-be-optimized model expected to be deployed to the smart phone, the server obtains the computing capability information of the smart phone, and obtains a parallel computing strategy of the to-be-optimized model according to the computing capability information, and then determines a pruning strategy for the to-be-optimized model according to the parallel computing strategy. Then, the server further prunes the to-be-optimized model according to the pruning strategy for the to-be-optimized model, to obtain an optimized model, adjusts the parallel computing strategy according to the pruning strategy for the to-be-optimized model, to obtain a parallel computing strategy corresponding to the optimized model, and finally deploys the optimized model to the terminal according to the parallel computing strategy corresponding to the optimized model.

[0138] For example, referring to Figure 9 To better implement the model optimization method provided in the present application, the present application further provides a model optimization device 300, as shown in Figure 9 , the model optimization device 300 can include:

[0139] a model obtaining module 310, configured to obtain a to-be-optimized model, and obtain computing capability information of a terminal to which the to-be-optimized model is expected to be deployed;

[0140] a parallel analysis module 320, configured to obtain a parallel computing strategy of the to-be-optimized model according to the computing capability information, the parallel computing strategy being used to describe channels of the to-be-optimized model that can be parallel computed in the terminal;

[0141] a pruning analysis module 330, configured to determine a pruning strategy for the to-be-optimized model according to the parallel computing strategy, the pruning strategy being used to describe channels of the to-be-optimized model that need to be pruned in parallel computing; and

[0142] a model pruning module 340, configured to prune the to-be-optimized model according to the pruning strategy for the to-be-optimized model, to obtain an optimized model.

[0143] Optionally, in an embodiment, when obtaining the parallel computing strategy of the to-be-optimized model according to the computing capability information, the parallel analysis module 320 is configured to:

[0144] compile the to-be-optimized model according to the computing capability information by using a model compiler, to obtain the parallel computing strategy.

[0145] Optionally, in an embodiment, when determining the pruning strategy for the to-be-optimized model according to the parallel computing strategy, the pruning analysis module 330 is configured to:

[0146] When the plurality of parallel computing strategies are obtained, a candidate pruning strategy for the to-be-optimized model is determined according to each parallel computing strategy, and the candidate pruning strategy is used to describe a channel of parallel computation that can be pruned in the to-be-optimized model;

[0147] The quality of each candidate pruning strategy is evaluated to obtain a quality score of each candidate pruning strategy;

[0148] The candidate pruning strategy with the highest quality score is taken as the pruning strategy for the to-be-optimized model.

[0149] Optionally, in an embodiment, when the quality of each candidate pruning strategy is evaluated to obtain a quality score of each candidate pruning strategy, the pruning analysis module 330 is configured to:

[0150] The to-be-optimized model is pruned according to each candidate pruning strategy to obtain a candidate optimized model corresponding to each candidate pruning strategy;

[0151] The quality of each candidate optimized model is evaluated in a plurality of quality dimensions to obtain a plurality of quality dimension scores;

[0152] The plurality of quality dimension scores of each candidate optimized model are fused to obtain a quality score of the candidate pruning strategy corresponding to each candidate optimized model.

[0153] Optionally, in an embodiment, when the plurality of quality dimension scores of each candidate optimized model are fused to obtain a quality score of the candidate pruning strategy corresponding to each candidate optimized model, the pruning analysis module 330 is configured to:

[0154] The plurality of quality dimension scores of each candidate optimized model are weighted and summed, and the obtained weighted sum value is taken as the quality score of the candidate pruning strategy corresponding to each candidate optimized model.

[0155] Optionally, in an embodiment, the model optimization apparatus provided in the present application further comprises a model deployment module configured to:

[0156] The parallel computing strategy is adjusted according to the pruning strategy for the to-be-optimized model to obtain a parallel computing strategy of a corresponding optimized model;

[0157] The optimized model is deployed to a terminal according to the parallel computing strategy of the corresponding optimized model.

[0158] Optionally, in an embodiment, the terminal comprises a neural network processor, and when the computing capability information of the terminal to which the to-be-optimized model is expected to be deployed is obtained, the model obtaining module 310 is configured to:

[0159] obtaining computing capability information of the neural network processor;

[0160] In deploying the optimization model to the terminal according to the parallel computing strategy corresponding to the optimization model, the model deployment module is configured to:

[0161] deploying the optimization model to the neural network processor according to the parallel computing strategy corresponding to the optimization model.

[0162] It should be noted that the model optimization apparatus 300 provided by the embodiments of the present application and the model optimization method in the above embodiments belong to the same concept, and the specific implementation process is described in detail in the above related embodiments, which will not be repeated here.

[0163] The embodiments of the present application also provide an electronic device, comprising a memory and a processor, wherein the processor is configured to execute the steps in the model optimization method provided by the embodiments of the present application by invoking the computer program stored in the memory.

[0164] Please refer to Figure 10 , Figure 10 The structural schematic diagram of the electronic device 400 provided by the embodiments of the present application is shown in FIG. 4.

[0165] The electronic device 400 can include a network interface 410, a memory 420, a processor 430, and a screen component, etc. Those skilled in the art can understand that the structure of the electronic device 400 shown in FIG. 4 does not constitute a limitation on the electronic device 400, and can include more or fewer components than shown, or combine certain components, or different component arrangements. Figure 10

[0166] The network interface 410 can be used for network connection between devices.

[0167] The memory 420 can be used to store computer programs and data. The computer program stored in the memory 420 includes executable codes. The computer program can be divided into various functional modules. The processor 430 executes various functional applications and data processing by running the computer program stored in the memory 420.

[0168] The processor 430 is the control center of the electronic device 400, and connects all parts of the electronic device 400 through various interfaces and lines. By running or executing the computer program stored in the memory 420 and calling the data stored in the memory 420, the processor 430 executes various functions and processes data of the electronic device 400, and thus controls the whole electronic device 400.

[0169] ​In the embodiments of the present application, the processor 430 in the electronic device 400 loads executable code corresponding to one or more computer programs into the memory 420 according to the following instructions, and executes the executable code by the processor 430 to perform the following steps:

[0170] obtain a to-be-optimized model, and obtain computing capability information of a terminal to which the to-be-optimized model is expected to be deployed;

[0171] obtain a parallel computing strategy of the to-be-optimized model according to the computing capability information, the parallel computing strategy being used to describe channels of parallel computing of the to-be-optimized model that can be performed on the terminal;

[0172] determine a pruning strategy for the to-be-optimized model according to the parallel computing strategy, the pruning strategy being used to describe channels of parallel computing of the to-be-optimized model that need to be pruned; and

[0173] prune the to-be-optimized model according to the pruning strategy for the to-be-optimized model, to obtain an optimized model.

[0174] Optionally, in an embodiment, when the parallel computing strategy of the to-be-optimized model is obtained according to the computing capability information, the processor 430 is configured to perform:

[0175] compile the to-be-optimized model according to the computing capability information by using a model compiler, to obtain the parallel computing strategy.

[0176] Optionally, in an embodiment, when the pruning strategy for the to-be-optimized model is determined according to the parallel computing strategy, the processor 430 is configured to perform:

[0177] when a plurality of parallel computing strategies are obtained, determine a candidate pruning strategy for the to-be-optimized model according to each parallel computing strategy, the candidate pruning strategy being used to describe channels of parallel computing of the to-be-optimized model that can be pruned;

[0178] perform quality evaluation on each candidate pruning strategy, to obtain a quality score of each candidate pruning strategy;

[0179] select the candidate pruning strategy with the highest quality score as the pruning strategy for the to-be-optimized model.

[0180] Optionally, in an embodiment, when the quality evaluation on each candidate pruning strategy is performed to obtain the quality score of each candidate pruning strategy, the processor 430 is configured to perform:

[0181] perform pruning processing on the to-be-optimized model according to each candidate pruning strategy, to obtain a candidate optimized model corresponding to each candidate pruning strategy;

[0182] perform quality evaluation on each candidate optimized model in a plurality of quality dimensions, to obtain a plurality of quality dimension scores;

[0183] The multiple quality dimension scores of each candidate optimization model are fused to obtain a quality score of the candidate pruning strategy corresponding to each candidate optimization model.

[0184] Optionally, in an embodiment, when the multiple quality dimension scores of each candidate optimization model are fused to obtain a quality score of the candidate pruning strategy corresponding to each candidate optimization model, the processor 430 is configured to perform:

[0185] The multiple quality dimension scores of each candidate optimization model are weighted and summed, and the obtained weighted sum value is taken as the quality score of the candidate pruning strategy corresponding to each candidate optimization model.

[0186] Optionally, in an embodiment, the processor 430 is further configured to perform:

[0187] The parallel computing strategy is adjusted according to the pruning strategy for the to-be-optimized model to obtain a parallel computing strategy of the corresponding optimization model;

[0188] The optimization model is deployed to the terminal according to the parallel computing strategy of the corresponding optimization model.

[0189] Optionally, in an embodiment, the terminal includes a neural network processor, and when the computing capability information of the terminal to which the to-be-optimized model is expected to be deployed is obtained, the processor 430 is configured to perform:

[0190] The computing capability information of the neural network processor is obtained;

[0191] When the optimization model is deployed to the terminal according to the parallel computing strategy of the corresponding optimization model, the model deployment module is configured to:

[0192] The optimization model is deployed to the neural network processor according to the parallel computing strategy of the corresponding optimization model.

[0193] It should be noted that the electronic device 400 provided by the embodiments of the present application and the model optimization method in the above embodiments belong to the same concept, and the specific implementation process is described in detail in the above related embodiments, which will not be repeated here.

[0194] The present application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by the processor of the electronic device provided by the embodiments of the present application, causes the processor of the electronic device to perform the steps in any of the model optimization methods suitable for the electronic device described above. The storage medium can be a magnetic disk, an optical disk, a read-only memory (ROM), a random access memory (RAM), or the like.

[0195] The model optimization method, device, storage medium and electronic equipment provided by the present application are described in detail above, and the principles and implementation modes of the present application are described in this paper. The above description of the embodiments is only used to help understand the method of the present application and its core idea; at the same time, for those skilled in the art, according to the idea of the present application, the specific implementation mode and application range will be changed, and the above description should not be understood as a limitation of the present application.

Claims

1. A model optimization method, characterized by, The model optimization method comprises: obtaining a to-be-optimized model, and obtaining computing capability information of a terminal to which the to-be-optimized model is expected to be deployed; wherein the to-be-optimized model is a voiceprint recognition model used for voiceprint recognition; obtaining a parallel computing strategy of the to-be-optimized model according to the computing capability information, the parallel computing strategy being used to describe channels of the to-be-optimized model that can be computed in parallel on the terminal; determining a pruning strategy for the to-be-optimized model according to the parallel computing strategy, the pruning strategy being used to describe channels of the to-be-optimized model that need to be pruned; pruning the to-be-optimized model according to the pruning strategy to obtain an optimized model; when the optimized voiceprint recognition model is deployed to the terminal, adjusting the parallel computing strategy according to the pruning strategy to obtain an optimized parallel computing strategy of the optimized voiceprint recognition model, and deploying the optimized voiceprint recognition model to the terminal according to the optimized parallel computing strategy of the optimized voiceprint recognition model.

2. The model optimization method of claim 1, wherein, The obtaining of the parallel computing strategy of the to-be-optimized model according to the computing capability information comprises: compiling the to-be-optimized model according to the computing capability information by using a model compiler to obtain the parallel computing strategy.

3. The model optimization method of claim 1, wherein, When a plurality of parallel computing strategies are obtained, the determining of the pruning strategy for the to-be-optimized model according to the parallel computing strategy comprises: determining a candidate pruning strategy for the to-be-optimized model according to each parallel computing strategy, the candidate pruning strategy being used to describe channels of the to-be-optimized model that can be pruned; performing quality evaluation on each candidate pruning strategy to obtain a quality score of each candidate pruning strategy; taking the candidate pruning strategy with the highest quality score as the pruning strategy.

4. The model optimization method of claim 3, wherein, The performing of quality evaluation on each candidate pruning strategy to obtain a quality score of each candidate pruning strategy comprises: performing pruning on the to-be-optimized model according to each candidate pruning strategy to obtain a candidate optimized model corresponding to each candidate pruning strategy; performing quality evaluation on each candidate optimized model in a plurality of quality dimensions to obtain a plurality of quality dimension scores; fusing the plurality of quality dimension scores of each candidate optimized model to obtain a quality score of the candidate pruning strategy corresponding to each candidate optimized model.

5. The model optimization method of claim 4, wherein, The fusing of the plurality of quality dimension scores of each candidate optimized model to obtain a quality score of the candidate pruning strategy corresponding to each candidate optimized model comprises: performing weighted summation on the plurality of quality dimension scores of each candidate optimized model, and taking a weighted sum value obtained as the quality score of the candidate pruning strategy corresponding to each candidate optimized model.

6. The model optimization method of claim 1, wherein, The model optimization method further comprises: adjusting the parallel computing strategy according to the pruning strategy to obtain a parallel computing strategy corresponding to the optimized model; deploying the optimized model to the terminal according to the parallel computing strategy corresponding to the optimized model.

7. The model optimization method of claim 6, wherein, The terminal comprises a neural network processor, and the obtaining of the computing capability information of the terminal to which the to-be-optimized model is expected to be deployed comprises: obtaining computing capability information of the neural network processor. The deploying the optimization model to the terminal according to the parallel computing strategy corresponding to the optimization model comprises: The deploying the optimization model to the neural network processor according to the parallel computing strategy corresponding to the optimization model.

8. A model optimization apparatus characterized by comprising: The model optimization apparatus comprises: A model obtaining module, configured to obtain a to-be-optimized model and obtain computing capability information of a terminal to which the to-be-optimized model is expected to be deployed; wherein the to-be-optimized model is a voiceprint recognition model used for voiceprint recognition; A parallel analysis module, configured to obtain a parallel computing strategy of the to-be-optimized model according to the computing capability information, the parallel computing strategy being used to describe channels of the to-be-optimized model that can be computed in parallel at the terminal; A pruning analysis module, configured to determine a pruning strategy for the to-be-optimized model according to the parallel computing strategy, the pruning strategy being used to describe channels of the to-be-optimized model that need to be pruned in parallel computation; A model pruning module, configured to prune the to-be-optimized model according to the pruning strategy to obtain an optimization model; A model deployment module, configured to, when deploying the optimized voiceprint recognition model to the terminal, adjust the parallel computing strategy according to the pruning strategy to obtain a parallel computing strategy of the optimized voiceprint recognition model, and deploy the optimized voiceprint recognition model to the terminal according to the parallel computing strategy of the optimized voiceprint recognition model.

9. A storage medium having stored thereon a computer program, characterized in that The computer program is loaded by the processor of the electronic device to execute the model optimization method as claimed in any one of claims 1-7. 10.An electronic device comprising a processor and a memory storing a computer program, wherein, The processor executes the model optimization method as claimed in any one of claims 1-7 by loading the computer program.

Citation Information

Patent Citations

  • Multi-granularity-based deep neural network structured sparse system and method

    CN110276450A

  • Structured network model compression acceleration method based on multistage pruning

    CN110619385A