Model conversion method and device, computer device, storage medium and computer program product

By analyzing, updating, and validating deep learning models, the problem of low model conversion efficiency is solved, and the adaptability and efficient conversion of models in different environments are achieved.

CN118966302BActive Publication Date: 2026-01-09BEIJING QINGCHENG JIZHI TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411097575.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-12
Publication Date
2026-01-09
Estimated Expiration
2044-08-12

AI Technical Summary

Technical Problem

The low efficiency of model conversion in existing technologies is mainly due to the need to manually rewrite code, which consumes too much time and manpower.

Method used

The deep learning model to be processed is analyzed to obtain graph structure information and weight information. The graph structure is updated according to the configuration information, and the transformed model is constructed. Finally, the model is verified to determine the target model.

Benefits of technology

It improves model conversion efficiency, expands the application scope of the model, enables it to adapt to new scenarios in different environments, and avoids the inefficiency of manually rewriting code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118966302B_ABST
    Figure CN118966302B_ABST
Patent Text Reader

Abstract

The application relates to a model conversion method and device, computer equipment, a storage medium and a computer program product. The method comprises the following steps: performing analysis processing on a to-be-processed deep learning model to obtain graph structure information and weight information corresponding to the to-be-processed deep learning model; updating the graph structure information corresponding to the to-be-processed deep learning model according to configuration information corresponding to the to-be-processed deep learning model to obtain updated graph structure information corresponding to the to-be-processed deep learning model; constructing a converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, the weight information and the configuration information corresponding to the to-be-processed deep learning model; obtaining a target verification result of the converted deep learning model; and in the case that the target verification result meets a preset verification result, taking the converted deep learning model as a target converted deep learning model. The method can improve the efficiency of model conversion.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of computer, in particular to a model conversion method and device, computer equipment, computer readable storage medium and computer program product. BACKGROUND

[0002] At present, in order to expand the application scope of the model, how to effectively convert the model is very important.

[0003] In the prior art, when the model is converted, the code is usually rewritten manually; However, this method consumes a lot of time and manpower, resulting in low efficiency of model conversion. SUMMARY

[0004] Therefore, it is necessary to provide a model conversion method, device, computer equipment, computer readable storage medium and computer program product capable of improving the efficiency of model conversion.

[0005] In a first aspect, the present application provides a model conversion method, comprising:

[0006] analyzing the to-be-processed deep learning model to obtain graph structure information and weight information corresponding to the to-be-processed deep learning model;

[0007] updating the graph structure information corresponding to the to-be-processed deep learning model according to the configuration information corresponding to the to-be-processed deep learning model, to obtain updated graph structure information corresponding to the to-be-processed deep learning model;

[0008] constructing a converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, weight information and configuration information corresponding to the to-be-processed deep learning model;

[0009] verifying the converted deep learning model to obtain a target verification result of the converted deep learning model;

[0010] In the case where the target verification result meets a preset verification result, the converted deep learning model is taken as a target converted deep learning model.

[0011] In one embodiment, the constructing a converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, weight information and configuration information corresponding to the to-be-processed deep learning model comprises:

[0012] performing format conversion processing on the weight information corresponding to the to-be-processed deep learning model to obtain processed weight information corresponding to the to-be-processed deep learning model;

[0013] According to the updated graph structure information, the processed weight information and the configuration information corresponding to the to-be-processed deep learning model, a converted deep learning model corresponding to the to-be-processed deep learning model is constructed.

[0014] In one of the embodiments, the verification on the converted deep learning model obtains a target verification result of the converted deep learning model, which includes:

[0015] Performance information of the converted deep learning model is obtained.

[0016] According to the performance information, the target verification result of the converted deep learning model is determined.

[0017] In one of the embodiments, after the to-be-processed deep learning model is parsed and processed to obtain the graph structure information and the weight information corresponding to the to-be-processed deep learning model, the method further includes:

[0018] The graph structure information corresponding to the to-be-processed deep learning model is verified to obtain a first verification result, and the weight information corresponding to the to-be-processed deep learning model is verified to obtain a second verification result.

[0019] According to the configuration information corresponding to the to-be-processed deep learning model, the graph structure information corresponding to the to-be-processed deep learning model is updated to obtain updated graph structure information corresponding to the to-be-processed deep learning model, which includes:

[0020] In the case that the first verification result and the second verification result both satisfy a preset condition, according to the configuration information corresponding to the to-be-processed deep learning model, the graph structure information corresponding to the to-be-processed deep learning model is updated to obtain updated graph structure information corresponding to the to-be-processed deep learning model.

[0021] In one of the embodiments, before the graph structure information corresponding to the to-be-processed deep learning model is updated according to the configuration information corresponding to the to-be-processed deep learning model to obtain updated graph structure information corresponding to the to-be-processed deep learning model, the method further includes:

[0022] Application scenario information corresponding to the to-be-processed deep learning model is obtained.

[0023] According to the application scenario information, a corresponding relationship between application scenario information and configuration information is queried to obtain the configuration information corresponding to the to-be-processed deep learning model.

[0024] In one of the embodiments, in the case that the target verification result satisfies a preset verification result, the converted deep learning model is taken as a target converted deep learning model, and the method further includes:

[0025] Based on the model saving instructions, determine the saving path of the deep learning model after target conversion;

[0026] The target-converted deep learning model is saved according to the specified save path.

[0027] Secondly, this application also provides a model conversion apparatus, comprising:

[0028] The model parsing module is used to parse the deep learning model to be processed, and obtain the graph structure information and weight information corresponding to the deep learning model to be processed.

[0029] The information update module is used to update the graph structure information corresponding to the deep learning model to be processed according to the configuration information corresponding to the deep learning model to be processed, so as to obtain the updated graph structure information corresponding to the deep learning model to be processed.

[0030] The model building module is used to build the transformed deep learning model corresponding to the deep learning model to be processed based on the updated graph structure information, weight information and configuration information corresponding to the deep learning model to be processed.

[0031] The model verification module is used to verify the transformed deep learning model and obtain the target verification result of the transformed deep learning model.

[0032] The target determination module is used to select the transformed deep learning model as the target transformed deep learning model when the target verification result meets the preset verification result.

[0033] Thirdly, this application also provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to perform the following steps:

[0034] The deep learning model to be processed is parsed to obtain the graph structure information and weight information corresponding to the deep learning model to be processed.

[0035] Based on the configuration information corresponding to the deep learning model to be processed, the graph structure information corresponding to the deep learning model to be processed is updated to obtain the updated graph structure information corresponding to the deep learning model to be processed.

[0036] Based on the updated graph structure information, weight information and configuration information corresponding to the deep learning model to be processed, construct the transformed deep learning model corresponding to the deep learning model to be processed.

[0037] verify the converted deep learning model to obtain a target verification result of the converted deep learning model;

[0038] In a case where the target verification result meets a preset verification result, the converted deep learning model is taken as a target converted deep learning model.

[0039] In a fourth aspect, the present application also provides a computer readable storage medium, which has a computer program stored thereon, and the computer program is executed by a processor to implement the following steps:

[0040] performing analysis processing on a to-be-processed deep learning model to obtain graph structure information and weight information corresponding to the to-be-processed deep learning model;

[0041] updating the graph structure information corresponding to the to-be-processed deep learning model according to configuration information corresponding to the to-be-processed deep learning model to obtain updated graph structure information corresponding to the to-be-processed deep learning model;

[0042] constructing a converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, the weight information and the configuration information corresponding to the to-be-processed deep learning model;

[0043] verifying the converted deep learning model to obtain a target verification result of the converted deep learning model;

[0044] In a case where the target verification result meets a preset verification result, the converted deep learning model is taken as a target converted deep learning model.

[0045] In a fifth aspect, the present application also provides a computer program product, which includes a computer program, and the computer program is executed by a processor to implement the following steps:

[0046] performing analysis processing on a to-be-processed deep learning model to obtain graph structure information and weight information corresponding to the to-be-processed deep learning model;

[0047] updating the graph structure information corresponding to the to-be-processed deep learning model according to configuration information corresponding to the to-be-processed deep learning model to obtain updated graph structure information corresponding to the to-be-processed deep learning model;

[0048] constructing a converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, the weight information and the configuration information corresponding to the to-be-processed deep learning model;

[0049] verifying the converted deep learning model to obtain a target verification result of the converted deep learning model;

[0050] In a case where the target verification result meets a preset verification result, the converted deep learning model is taken as a target converted deep learning model.

[0051] The model conversion method, device, computer device, storage medium and computer program product described above first perform parsing processing on the to-be-processed deep learning model to obtain graph structure information and weight information corresponding to the to-be-processed deep learning model, then update the graph structure information corresponding to the to-be-processed deep learning model according to configuration information corresponding to the to-be-processed deep learning model to obtain updated graph structure information corresponding to the to-be-processed deep learning model, then construct a converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, weight information and configuration information corresponding to the to-be-processed deep learning model, then perform verification on the converted deep learning model to obtain a target verification result of the converted deep learning model, and finally, in a case where the target verification result meets a preset verification result, take the converted deep learning model as a target converted deep learning model. In this way, when the model is converted, the to-be-processed deep learning model is parsed, updated and converted, so that the to-be-processed deep learning model can run in different environments, which is conducive to expanding the application range of the to-be-processed deep learning model, and thus the to-be-processed deep learning model can better adapt to new scenarios. Moreover, the entire process does not require manual intervention, avoiding the defects that manual code rewriting is easy to consume a large amount of time and manpower, resulting in low efficiency of model conversion, and thus improving the efficiency of model conversion. BRIEF DESCRIPTION OF DRAWINGS

[0052] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related art, the following will briefly introduce the drawings needed to be used in the description of the embodiments of the present application or the related art. Obviously, the drawings in the following description only some embodiments of the present application, and for those skilled in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.

[0053] Figure 1 A flowchart of a model conversion method in an embodiment;

[0054] Figure 2 A flowchart of a step of constructing a converted deep learning model corresponding to a to-be-processed deep learning model in an embodiment;

[0055] Figure 3 A flowchart of a model conversion method in another embodiment;

[0056] Figure 4 A flowchart of a text representation method of a dynamic computation graph and a model conversion system in an embodiment;

[0057] Figure 5 A structural block diagram of a model conversion device in an embodiment;

[0058] Figure 6 An internal structural diagram of a computer device in an embodiment. DETAILED DESCRIPTION

[0059] In order to make the purposes, technical solutions and advantages of the present application clearer, further detailed description will be made to the present application in combination with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application, and are not used to limit the present application.

[0060] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present application are all information and data authorized by the user or authorized by all parties, and the collection, use and processing of the related data need to comply with relevant regulations.

[0061] In an exemplary embodiment, as shown in Figure 1 A model conversion method is provided, and the present embodiment is exemplified by the method applied to a server; it can be understood that the method can also be applied to a terminal, and can also be applied to a system including a terminal and a server, and is realized through the interaction between the terminal and the server. The terminal can be, but is not limited to, various personal computers, notebook computers, smart phones and tablet computers; the server can be realized by an independent server or a server cluster composed of multiple servers. In the present embodiment, the method includes the following steps:

[0062] Step S101: performing analysis processing on a to-be-processed deep learning model to obtain graph structure information and weight information corresponding to the to-be-processed deep learning model.

[0063] The to-be-processed deep learning model refers to a deep learning model that needs to be converted. It should be noted that the to-be-processed deep learning model includes two model formats of ONNX (Open Neural Network Exchange) and PyTorch (a deep learning framework).

[0064] Further, the to-be-processed deep learning model can refer to an image processing model used to identify the image type of a to-be-processed image, and the to-be-processed deep learning model can also refer to a text processing model used to identify the sentiment type of a to-be-processed text.

[0065] The image processing model includes a transformer model, and is configured to output a recognition result of the image to be processed, such as an image type.

[0066] The text processing model includes a GPT-2 (Generative Pretrained Transformer 2) model, and is configured to output a recognition result of the text to be processed, such as a sentiment type.

[0067] The analysis processing refers to a processing process corresponding to the graph structure information and the weight information of the deep learning model to be processed.

[0068] The graph structure information refers to node information, edge information, layer information, and connection information between layers of the deep learning model to be processed. For example, in the image processing model, the graph structure information refers to layer information of convolutional layers and pooling layers, and connection order between layers; in the text processing model, the graph structure information refers to layer information of word embedding layers, and connection mode between layers.

[0069] The weight information refers to parameter values of connected neurons or layers in the deep learning model. For example, in the image processing model, the weight information includes values in a convolution kernel; in the text processing model, the weight information includes weights of various gates (such as a forget gate, an input gate, and an output gate).

[0070] Exemplarily, the server acquires the deep learning model to be processed in response to a model conversion instruction for the deep learning model to be processed; then, the server performs analysis processing on the deep learning model to be processed to obtain analysis information; then, the server extracts the graph structure information and the weight information in the analysis information; then, the server performs format conversion processing on the graph structure information and the weight information in the analysis information to obtain text format graph structure information and weight information as the graph structure information and the weight information corresponding to the deep learning model to be processed.

[0071] In step S102, the graph structure information corresponding to the deep learning model to be processed is updated according to configuration information corresponding to the deep learning model to be processed, to obtain updated graph structure information corresponding to the deep learning model to be processed.

[0072] The configuration information is used to represent various parameters and setting information of the deep learning model to be processed. For example, in the image processing model, the configuration information refers to image input specification information; in the text processing model, the configuration information refers to word embedding dimension information.

[0073] The updated graph structure information refers to the graph structure information of the deep learning model to be processed after being updated.

[0074] Exemplarily, the server obtains node information and edge information in graph structure information corresponding to the to-be-processed deep learning model; then, the server updates the node information and the edge information respectively according to configuration information corresponding to the to-be-processed deep learning model, to obtain updated node information and updated edge information; and then, the server takes the updated node information and the updated edge information as updated graph structure information corresponding to the to-be-processed deep learning model.

[0075] In step S103, a converted deep learning model corresponding to the to-be-processed deep learning model is constructed according to the updated graph structure information, the weight information and the configuration information corresponding to the to-be-processed deep learning model.

[0076] The converted deep learning model refers to a deep learning model constructed according to the updated graph structure information, the weight information and the configuration information corresponding to the to-be-processed deep learning model.

[0077] Further, the converted deep learning model can refer to an image processing model used to identify the image type of a to-be-processed image, or can refer to a text processing model used to identify the sentiment type of a to-be-processed text.

[0078] Exemplarily, the server constructs an initial deep learning model according to the updated graph structure information, the weight information and the configuration information corresponding to the to-be-processed deep learning model; then, the server tests the initial deep learning model by using a verification set to obtain a test result of the initial deep learning model, such as the accuracy, the recall rate, the mean square error, the loss value and the running time of the initial deep learning model; and finally, in a case where the test result meets a preset condition (for example, the accuracy of the initial deep learning model is 92%, which is greater than a preset accuracy of 90%), the server optimizes and adjusts the initial deep learning model according to the actual running situation and the performance index of the initial deep learning model by using an optimization technique (such as graph fusion, constant folding and layer fusion), to obtain an optimized and adjusted initial deep learning model as the converted deep learning model.

[0079] In step S104, the converted deep learning model is verified to obtain a target verification result of the converted deep learning model.

[0080] The target verification result is used to represent the comprehensive verification situation of the converted deep learning model, such as the calculation speed and the memory occupation of the converted deep learning model.

[0081] Exemplarily, the server obtains a verification index corresponding to the converted deep learning model; then, the server verifies the converted deep learning model according to the verification index to obtain a target verification result of the converted deep learning model.

[0082] Step S105, in the case that the target verification result meets the preset verification result, the converted deep learning model is taken as a target converted deep learning model.

[0083] The preset verification result refers to a preset verification result, such as a preset calculation speed (for example, 10 milliseconds), a preset memory occupation (for example, 50 MB), etc.

[0084] The target converted deep learning model refers to a converted deep learning model whose target verification result meets the preset verification result.

[0085] Further, the target converted deep learning model can refer to an image processing model used for identifying the image type of a to-be-processed image, and the target converted deep learning model can also refer to a text processing model used for identifying the sentiment type of a to-be-processed text.

[0086] Illustratively, the server acquires the preset verification result corresponding to the converted deep learning model, and judges the target verification result of the converted deep learning model according to the preset verification result; then, in the case that the target verification result meets the preset verification result, the server takes the converted deep learning model as the target converted deep learning model; for example, the preset calculation speed is 10 milliseconds, the preset memory occupation is 50 MB, the calculation speed of the converted deep learning model is 8 milliseconds, and the preset memory occupation is 30 MB, all of which meet the preset verification result, i.e., the converted deep learning model is taken as the target converted deep learning model.

[0087] In the model conversion method, the to-be-processed deep learning model is first parsed to obtain graph structure information and weight information corresponding to the to-be-processed deep learning model, then the graph structure information corresponding to the to-be-processed deep learning model is updated according to configuration information corresponding to the to-be-processed deep learning model to obtain updated graph structure information corresponding to the to-be-processed deep learning model, then a converted deep learning model corresponding to the to-be-processed deep learning model is constructed according to the updated graph structure information, the weight information and the configuration information corresponding to the to-be-processed deep learning model, then the converted deep learning model is verified to obtain a target verification result of the converted deep learning model, and finally, when the target verification result meets a preset verification result, the converted deep learning model is taken as a target converted deep learning model. In this way, when the model is converted, the to-be-processed deep learning model is parsed, updated and converted, so that the to-be-processed deep learning model can run in different environments, which is beneficial to expand the application range of the to-be-processed deep learning model, and thus the to-be-processed deep learning model can better adapt to new scenarios. Moreover, the whole process does not need manual intervention, which avoids the defect that manual code rewriting is easy to consume a lot of time and manpower, resulting in low efficiency of model conversion, and thus the efficiency of model conversion is improved.

[0088] In one exemplary embodiment, as shown in Figure 2 The step S103 of constructing a converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, the weight information and the configuration information corresponding to the to-be-processed deep learning model specifically includes the following steps:

[0089] The step S201 of performing format conversion processing on the weight information corresponding to the to-be-processed deep learning model to obtain processed weight information corresponding to the to-be-processed deep learning model.

[0090] The step S202 of constructing a converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, the processed weight information and the configuration information corresponding to the to-be-processed deep learning model.

[0091] The processed weight information refers to the weight information after format conversion processing.

[0092] Exemplarily, the server acquires initial format information of weight information corresponding to the to-be-processed deep learning model, and acquires target format information of weight information of the converted deep learning model, such as TensorProto format of the ONNX model; then, the server performs format conversion processing on the weight information corresponding to the to-be-processed deep learning model according to conversion instructions between the initial format information and the target format information, to obtain processed weight information corresponding to the to-be-processed deep learning model; then, the server constructs the converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information corresponding to the to-be-processed deep learning model, the processed weight information, and the configuration information.

[0093] For example, the server determines all node information and edge information of the ONNX model as GraphProto object information of the ONNX model according to the updated graph structure information corresponding to the to-be-processed deep learning model; then, the server adds the weight information in the TensorProto format of the ONNX model to the GraphProto object information of the ONNX model, to obtain merged GraphProto object information of the ONNX model; then, the server sets input, output, and intermediate node information of the ONNX model as attribute information of the ONNX model according to parameter and variable values in the configuration information; finally, the server constructs the ONNX model according to the merged GraphProto object information of the ONNX model and the attribute information of the ONNX model.

[0094] In this embodiment, the weight information corresponding to the to-be-processed deep learning model is processed by format conversion processing, so that the processed weight information can be better combined with the updated graph structure information and the configuration information, which is conducive to constructing a model that better meets specific needs, and further promotes the reuse and integration of the model.

[0095] In one exemplary embodiment, the above step S104 verifies the converted deep learning model to obtain a target verification result of the converted deep learning model, and specifically includes the following contents: acquiring performance information of the converted deep learning model; determining the target verification result of the converted deep learning model according to the performance information.

[0096] The performance information is used to represent the performance of the converted deep learning model, such as calculation speed, memory occupation, etc.

[0097] Exemplarily, the server inputs data samples with different features and complexities into the converted deep learning model to obtain output information (such as output content, output time, etc.) output by the converted deep learning model; then, the server determines performance information of the converted deep learning model according to the output information; and then, the server combines the performance information to obtain combined performance information as a target verification result of the converted deep learning model.

[0098] In this embodiment, the performance information of the converted deep learning model is obtained, so that the performance of the converted deep learning model on various indicators can be objectively and accurately determined, and the determination accuracy of the quality of the converted deep learning model is improved.

[0099] In one exemplary embodiment, after the step S101 of analyzing the to-be-processed deep learning model to obtain the graph structure information and the weight information corresponding to the to-be-processed deep learning model, the step S101 specifically includes the following contents: verifying the graph structure information corresponding to the to-be-processed deep learning model to obtain a first verification result, and verifying the weight information corresponding to the to-be-processed deep learning model to obtain a second verification result.

[0100] Then, the step S102 of updating the graph structure information corresponding to the to-be-processed deep learning model according to the configuration information corresponding to the to-be-processed deep learning model to obtain updated graph structure information corresponding to the to-be-processed deep learning model specifically includes the following contents: in the case that the first verification result and the second verification result both satisfy a preset condition, updating the graph structure information corresponding to the to-be-processed deep learning model according to the configuration information corresponding to the to-be-processed deep learning model to obtain updated graph structure information corresponding to the to-be-processed deep learning model.

[0101] The first verification result is used to represent the verification situation of the graph structure information corresponding to the to-be-processed deep learning model, such as whether the definition of nodes and edges in the graph structure information is correct, whether there is invalid connection or circular dependency, etc.

[0102] The second verification result is used to represent the verification situation of the weight information corresponding to the to-be-processed deep learning model, such as whether the weight information meets the expected format and range.

[0103] The preset condition is a pre-set judgment condition, which is used to judge the first verification result and the second verification result at the same time. It should be noted that the preset condition is determined according to the situation.

[0104] Exemplarily, the server checks the graph structure information corresponding to the to-be-processed deep learning model, obtains checking information of the graph structure information as a first checking result, and checks the weight information corresponding to the to-be-processed deep learning model, obtains checking information of the weight information as a second checking result; then, the server predefines a condition, judges the first checking result and the second checking result; for example, if the first checking result is that the definition of nodes and edges in the graph structure information is correct, there is no invalid connection or circular dependency, and the second checking result is that the weight information is in an expected format and range, it is indicated that the first checking result and the second checking result both satisfy the predefined condition, otherwise it is indicated that the first checking result and the second checking result do not satisfy the predefined condition; then, in the case that the first checking result and the second checking result both satisfy the predefined condition, the server obtains node information and edge information in the graph structure information corresponding to the to-be-processed deep learning model; then, the server updates the node information and the edge information respectively according to the configuration information corresponding to the to-be-processed deep learning model, obtains updated node information and updated edge information; and then, the server takes the updated node information and the updated edge information as the updated graph structure information corresponding to the to-be-processed deep learning model.

[0105] In this embodiment, by checking the graph structure information and the weight information respectively to obtain the first checking result and the second checking result, the accuracy of the basic framework and the parameters of the to-be-processed deep learning model can be ensured, which is beneficial to improve the reliability and stability of the to-be-processed deep learning model.

[0106] In one exemplary embodiment, before the step S102, the updating of the graph structure information corresponding to the to-be-processed deep learning model according to the configuration information corresponding to the to-be-processed deep learning model to obtain the updated graph structure information corresponding to the to-be-processed deep learning model, specifically includes the following contents: obtaining application scenario information corresponding to the to-be-processed deep learning model; and querying a corresponding relationship between the application scenario information and the configuration information according to the application scenario information to obtain the configuration information corresponding to the to-be-processed deep learning model.

[0107] The application scenario information is used to represent a specific field corresponding to data processing of the to-be-processed deep learning model. For example, in an image processing model, the application scenario information can be face recognition; and in a text processing model, the application scenario information can be long text sentiment recognition.

[0108] The corresponding relationship between the application scenario information and the configuration information is used to represent the association information between the application scenario information and the configuration information. For example, in the case that the application scenario information of the image processing model is face recognition, the corresponding configuration information is that the input image size is set to a high resolution, and so on. In the case that the application scenario information of the text processing model is long text sentiment recognition, the corresponding configuration information is that the word embedding dimension is set to 256 or 512, and so on.

[0109] Exemplarily, the server determines the application scenario information corresponding to the to-be-processed deep learning model according to the processing data type of the to-be-processed deep learning model. For example, if the processing data type is a large amount of social media text, the corresponding application scenario information is sentiment analysis. Then, the server queries the corresponding relationship between the application scenario information and the configuration information according to the application scenario information, obtains the configuration information corresponding to the application scenario information as the configuration information corresponding to the to-be-processed deep learning model.

[0110] In this embodiment, by selecting appropriate configuration information for different application scenario information, the use of overly complex or mismatched model architectures and parameters is avoided, thereby saving computing resources and time costs, and further improving the determination efficiency of the configuration information corresponding to the to-be-processed deep learning model.

[0111] In one exemplary embodiment, after the above step S105, in the case that the target verification result meets the preset verification result, the converted deep learning model is taken as the target converted deep learning model, and the following contents are specifically included: determining a saving path of the target converted deep learning model according to a model saving instruction; and saving the target converted deep learning model according to the saving path.

[0112] The model saving instruction refers to instruction information corresponding to saving the target converted deep learning model.

[0113] The saving path refers to path information corresponding to saving the target converted deep learning model.

[0114] Exemplarily, the server determines the saving path corresponding to the model saving instruction as the saving path of the target converted deep learning model according to the model saving instruction. Then, the server calls a saving function of the target converted deep learning model, and saves the target converted deep learning model in the form of a file according to the saving path.

[0115] In this embodiment, by determining the saving path of the target converted deep learning model and saving the target converted deep learning model, it is convenient to directly reuse the target converted deep learning model in subsequent same or similar tasks, which is beneficial to save the time and resources of retraining or converting the model.

[0116] In one exemplary embodiment, as shown in Figure 3 Another model conversion method is provided, which is exemplified by being applied to a server and includes the following steps:

[0117] In step S301, the to-be-processed deep learning model is parsed to obtain graph structure information and weight information corresponding to the to-be-processed deep learning model.

[0118] In step S302, the graph structure information corresponding to the to-be-processed deep learning model is checked to obtain a first checking result, and the weight information corresponding to the to-be-processed deep learning model is checked to obtain a second checking result.

[0119] In step S303, when the first checking result and the second checking result both satisfy a preset condition, application scenario information corresponding to the to-be-processed deep learning model is obtained; the application scenario information is used to query a corresponding relationship between the application scenario information and configuration information, to obtain configuration information corresponding to the to-be-processed deep learning model; and the graph structure information corresponding to the to-be-processed deep learning model is updated according to the configuration information corresponding to the to-be-processed deep learning model, to obtain updated graph structure information corresponding to the to-be-processed deep learning model.

[0120] In step S304, the weight information corresponding to the to-be-processed deep learning model is format-converted to obtain processed weight information corresponding to the to-be-processed deep learning model.

[0121] In step S305, a converted deep learning model corresponding to the to-be-processed deep learning model is constructed according to the updated graph structure information, the processed weight information, and the configuration information corresponding to the to-be-processed deep learning model.

[0122] In step S306, performance information of the converted deep learning model is obtained.

[0123] In step S307, a target checking result of the converted deep learning model is determined according to the performance information.

[0124] In step S308, when the target checking result satisfies a preset checking result, the converted deep learning model is taken as a target converted deep learning model.

[0125] In the model conversion method, when the model is converted, the to-be-processed deep learning model is parsed, updated and converted, so that the to-be-processed deep learning model can run in different environments, which is beneficial to expand the application range of the to-be-processed deep learning model, and thus the to-be-processed deep learning model can better adapt to new scenes. Moreover, the whole process does not need manual intervention, avoiding the defects of consuming a lot of time and manpower by manually rewriting the code, and thus improving the efficiency of model conversion.

[0126] In one exemplary embodiment, in order to more clearly illustrate the model conversion method provided by the embodiments of the present application, the model conversion method is specifically described below with one specific embodiment. In one embodiment, as shown in Figure 4 In one embodiment, as shown in the above figure, the present application also provides a text representation method of a dynamic computation graph and a model conversion system. When the model is converted, the to-be-processed deep learning model is first parsed to obtain the graph structure information and weight information corresponding to the to-be-processed deep learning model, then the graph structure information corresponding to the to-be-processed deep learning model is updated according to the configuration information corresponding to the to-be-processed deep learning model to obtain the updated graph structure information corresponding to the to-be-processed deep learning model, then the converted deep learning model corresponding to the to-be-processed deep learning model is constructed according to the updated graph structure information, weight information and configuration information corresponding to the to-be-processed deep learning model, and then the converted deep learning model is verified to obtain the target verification result of the converted deep learning model. Finally, in the case that the target verification result meets the preset verification result, the converted deep learning model is taken as the target converted deep learning model. Specifically, it includes the following contents:

[0127] 1. A text representation method of a dynamic computation graph.

[0128] (1) Computation graph structure file (tensor and op): defines the nodes (tensor) and operations (op) in the computation graph, and describes the attributes, input-output relationship, etc. of each node and operation in a text manner.

[0129] (2) Weight region: stores the weight information of each node in the computation graph, and ensures the integrity and consistency of the weight in the model conversion and optimization process.

[0130] (3) Configuration file: defines some additional parameters such as variable values, which dynamically adjust the dimension information and edge information in the computation graph through these parameters.

[0131] (4) Custom operator region: allows users to customize operators according to needs and reference them in the computation graph, enhancing the flexibility and expandability of the system.

[0132] 2. Model system generation process.

[0133] (1) Analyze graph structure: Check the tensor and op definitions in the computation graph structure file to ensure that the graph does not have invalid edges and nodes.

[0134] (2) Read weight region: Ensure that each weight exists in the weight region and perform a check.

[0135] (3) Read configuration file: Based on the definitions in the configuration file, dynamically adjust the dimension information and edge information in the graph structure.

[0136] (4) Generate model file: Based on the type of model to be generated (such as ONNX, PyTorch), write the required weights and parameters, and save the model to the specified path.

[0137] 3. Computation graph text representation generation process.

[0138] (1) Parse original model: Parse ONNX, PyTorch, and other original models to obtain the graph structure and weight information in the model.

[0139] (2) Write computation graph structure file: Write tensor and op information to the computation graph structure file, and write weight information to the weight region.

[0140] 4. ONNX model file generation.

[0141] (1) Analyze graph structure: Based on the structure file of the dynamic computation graph, create an ONNX GraphProto object containing all nodes (tensors and ops).

[0142] (2) Add weights: Convert the weight data in the weight region to ONNX TensorProto format and add it to GraphProto.

[0143] (3) Configure parameters: Set the input, output, and intermediate node properties of the ONNX model based on the parameter and variable values in the configuration file.

[0144] (4) Save model: Use the onnx.save_model function of ONNX to save the constructed GraphProto object as an ONNX model file.

[0145] 5. PyTorch model file generation.

[0146] (1) Analyze graph structure: Based on the structure file of the dynamic computation graph, define the model structure using PyTorch's torch.nn.Module class.

[0147] (2) Add weights: Load the weight data in the weight area into each layer of the PyTorch model, and assign values using the state_dict method.

[0148] (3) Configure parameters: Set the hyperparameters and layer properties of the PyTorch model according to the parameter and variable values in the configuration file.

[0149] (4) Save the model: Use the torch.save function of PyTorch to save the defined model object as a PyTorch model file.

[0150] 6. Check and optimize adjustments.

[0151] (1) Graph structure verification: Verify the parsed model graph structure to ensure that the definition of nodes and edges is correct, and there is no invalid connection or circular dependency.

[0152] (2) Weight verification: Check the weight area of the model to ensure that all necessary weights have been correctly loaded and meet the expected format and range.

[0153] (3) Performance optimization: According to the actual running situation and performance indicators of the model, apply optimization techniques (such as graph fusion, constant folding, layer fusion, etc.) to optimize and adjust the model. The specific optimization techniques are defined by the user.

[0154] (4) Consistency check: Ensure that the adjusted model maintains consistent behavior and performance on different platforms and hardware.

[0155] (5) Performance evaluation: Evaluate whether the optimized model performance meets the expected target, such as calculation speed, memory occupancy, and accuracy, etc.

[0156] (6) Adjustment judgment: According to the performance evaluation results, judge whether further adjustment is needed. If needed, return to the configuration file adjustment step and re-perform the dynamic adjustment and model file generation process; if not needed, end the process.

[0157] The above embodiment, when the model is converted, the to-be-processed deep learning model is parsed, updated and converted, so that the to-be-processed deep learning model can run in different environments, which is beneficial to expand the application range of the to-be-processed deep learning model, and the to-be-processed deep learning model can better adapt to new scenes; Moreover, the whole process does not need manual intervention, which avoids the defect that the manual code rewriting method easily consumes a lot of time and manpower, and the efficiency of model conversion is low, and the efficiency of model conversion is improved. At the same time, the technical scheme unifies the dynamic calculation graph text representation method, solves the complexity problem of the existing AI (Artificial Intelligence, Artificial Intelligence) compiler when processing multiple model formats, significantly improves the efficiency and accuracy of model conversion and optimization. Through strict checking of the graph structure, weight area and configuration file, the stability and reliability of the model are ensured. At the same time, the introduction of the self-defined operator area improves the flexibility and expansibility of the system, and better adapts to the needs of different application scenarios.

[0158] It should be understood that, although each step in the flowchart involved in each embodiment as described above is displayed in sequence according to the arrow, these steps are not necessarily executed in sequence according to the arrow. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other sequences. Moreover, at least part of the steps in the flowchart involved in each embodiment as described above can include multiple steps or multiple stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution sequence of these steps or stages is not necessarily sequential, but can be alternately executed with other steps or steps or stages in other steps.

[0159] Based on the same inventive concept, the embodiment of the present application also provides a model conversion device for implementing the above-mentioned model conversion method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme described in the above method, so the specific limitations in one or more model conversion device embodiments provided below can refer to the limitations of the model conversion method in the above text, which will not be repeated here.

[0160] In one exemplary embodiment, as shown in Figure 5 A model conversion device is provided, comprising: a model parsing module 501, an information updating module 502, a model building module 503, a model checking module 504 and a target determining module 505, wherein:

[0161] The model analysis module 501 is configured to analyze the to-be-processed deep learning model to obtain graph structure information and weight information corresponding to the to-be-processed deep learning model.

[0162] The information updating module 502 is configured to update the graph structure information corresponding to the to-be-processed deep learning model according to configuration information corresponding to the to-be-processed deep learning model to obtain updated graph structure information corresponding to the to-be-processed deep learning model.

[0163] The model construction module 503 is configured to construct a converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, the weight information, and the configuration information corresponding to the to-be-processed deep learning model.

[0164] The model verification module 504 is configured to verify the converted deep learning model to obtain a target verification result of the converted deep learning model.

[0165] The target determination module 505 is configured to determine the converted deep learning model as a target converted deep learning model when the target verification result meets a preset verification result.

[0166] In an exemplary embodiment, the model construction module 503 is further configured to perform format conversion processing on the weight information corresponding to the to-be-processed deep learning model to obtain processed weight information corresponding to the to-be-processed deep learning model, and construct the converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, the processed weight information, and the configuration information corresponding to the to-be-processed deep learning model.

[0167] In an exemplary embodiment, the model verification module 504 is further configured to obtain performance information of the converted deep learning model, and determine the target verification result of the converted deep learning model according to the performance information.

[0168] In an exemplary embodiment, the model conversion apparatus further includes an information verification module configured to verify the graph structure information corresponding to the to-be-processed deep learning model to obtain a first verification result, and verify the weight information corresponding to the to-be-processed deep learning model to obtain a second verification result.

[0169] In an exemplary embodiment, the information updating module 502 is further configured to update the graph structure information corresponding to the to-be-processed deep learning model according to the configuration information corresponding to the to-be-processed deep learning model to obtain the updated graph structure information corresponding to the to-be-processed deep learning model when the first verification result and the second verification result both meet a preset condition.

[0170] In an example embodiment, the model conversion apparatus further comprises an information query module configured to obtain application scenario information corresponding to the to-be-processed deep learning model; and query a corresponding relationship between the application scenario information and configuration information according to the application scenario information to obtain configuration information corresponding to the to-be-processed deep learning model.

[0171] In an example embodiment, the model conversion apparatus further comprises a model saving module configured to determine a saving path of the target converted deep learning model according to a model saving instruction; and save the target converted deep learning model according to the saving path.

[0172] The modules in the model conversion apparatus can be implemented by software, hardware, or a combination thereof. The modules can be embedded in or independent of a processor in a computer device in hardware form, or stored in a memory in the computer device in software form, so as to be called and executed by a processor to perform operations corresponding to the modules.

[0173] In an example embodiment, a computer device is provided, which can be a server. An internal structure diagram of the computer device can be as shown in Figure 6 The computer device comprises a processor, a memory, an input / output interface, and a communication interface. The processor, the memory, and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for running the operating system and the computer program in the non-volatile storage medium. The database of the computer device is configured to store graph structure information, weight information, and the like. The input / output interface of the computer device is configured to exchange information between the processor and external devices. The communication interface of the computer device is configured to communicate with external terminals through a network connection. The computer program is executed by the processor to implement a model conversion method.

[0174] Those skilled in the art can understand that Figure 6 The structure shown in the above

[0175] In an exemplary embodiment, a computer device is also provided, comprising a memory and a processor, the memory storing a computer program, and the processor implementing the steps in the above method embodiments when executing the computer program.

[0176] In an exemplary embodiment, a computer readable storage medium is provided, storing a computer program, and the computer program implementing the steps in the above method embodiments when executed by a processor.

[0177] In an exemplary embodiment, a computer program product is provided, comprising a computer program, and the computer program implementing the steps in the above method embodiments when executed by a processor.

[0178] A person of ordinary skill in the art can understand that all or part of the processes in the above method embodiments can be completed by a computer program instructing related hardware. The computer program can be stored in a non-volatile computer readable storage medium, and when executed, can include the processes of the above method embodiments. Any reference to a memory, database, or other medium used in the embodiments provided in the present application can include at least one of a non-volatile and volatile memory. The non-volatile memory can include a read-only memory (ROM), a magnetic tape, a floppy disk, a flash memory, an optical storage, a high-density embedded non-volatile memory, a resistive memory (ReRAM), a magnetoresistive random access memory (MRAM), a ferroelectric memory (FRAM), a phase change memory (PCM), a graphene memory, etc. The volatile memory can include a random access memory (RAM) or an external cache memory, etc. As an illustration but not limitation, the RAM can be in various forms, such as a static random access memory (SRAM) or a dynamic random access memory (DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., without being limited thereto.

[0179] Any combination of the technical features in the above embodiments can be made, and for the sake of brevity, not all possible combinations are described, however, any combination of the technical features is deemed to be within the scope of the present disclosure as long as there is no inconsistency.

[0180] The above embodiments only express several implementation manners of the present application, and the description is relatively specific and detailed, but it should not be understood as a limitation on the patent scope of the present application. It should be pointed out that for ordinary skilled persons in the art, several modifications and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.

Claims

1. A model conversion method characterized by, The method comprises: parsing a to-be-processed deep learning model to obtain graph structure information and weight information corresponding to the to-be-processed deep learning model; determining application scenario information corresponding to the to-be-processed deep learning model according to a processing data type of the to-be-processed deep learning model, querying a corresponding relationship between application scenario information and configuration information according to the application scenario information, and obtaining configuration information corresponding to the to-be-processed deep learning model; updating the graph structure information corresponding to the to-be-processed deep learning model according to the configuration information corresponding to the to-be-processed deep learning model, and obtaining updated graph structure information corresponding to the to-be-processed deep learning model; constructing a converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, the weight information, and the configuration information corresponding to the to-be-processed deep learning model; obtaining performance information of the converted deep learning model, determining a target verification result of the converted deep learning model according to the performance information, and determining the performance information according to output information of the converted deep learning model; in a case where the target verification result meets a preset verification result corresponding to the converted deep learning model, taking the converted deep learning model as a target converted deep learning model.

2. The method of claim 1, wherein, The method comprises: performing format conversion processing on the weight information corresponding to the to-be-processed deep learning model to obtain processed weight information corresponding to the to-be-processed deep learning model; constructing the converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, the processed weight information, and the configuration information corresponding to the to-be-processed deep learning model.

3. The method of claim 1, wherein, After parsing the to-be-processed deep learning model to obtain the graph structure information and the weight information corresponding to the to-be-processed deep learning model, the method further comprises: verifying the graph structure information corresponding to the to-be-processed deep learning model to obtain a first verification result, and verifying the weight information corresponding to the to-be-processed deep learning model to obtain a second verification result; The method comprises: in a case where the first verification result and the second verification result both meet a preset condition, updating the graph structure information corresponding to the to-be-processed deep learning model according to the configuration information corresponding to the to-be-processed deep learning model to obtain the updated graph structure information corresponding to the to-be-processed deep learning model.

4. The method according to any one of claims 1 to 3, characterized in that, After the target verification result meets the preset verification result corresponding to the converted deep learning model, the method further comprises: determining a saving path of the target converted deep learning model according to a model saving instruction. According to the saving path, the target converted deep learning model is saved.

5. A model conversion apparatus characterized by comprising: The device comprises: The model analysis module is configured to analyze a to-be-processed deep learning model to obtain graph structure information and weight information corresponding to the to-be-processed deep learning model. The information query module is configured to determine application scenario information corresponding to the to-be-processed deep learning model according to a processing data type of the to-be-processed deep learning model, and query a corresponding relationship between the application scenario information and configuration information to obtain configuration information corresponding to the to-be-processed deep learning model according to the application scenario information. The information update module is configured to update the graph structure information corresponding to the to-be-processed deep learning model according to the configuration information corresponding to the to-be-processed deep learning model to obtain updated graph structure information corresponding to the to-be-processed deep learning model, and the configuration information is determined according to the application scenario information corresponding to the to-be-processed deep learning model. The model construction module is configured to construct a converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, the weight information, and the configuration information corresponding to the to-be-processed deep learning model. The model verification module is configured to obtain performance information of the converted deep learning model, determine a target verification result of the converted deep learning model according to the performance information, and the performance information is determined according to output information of the converted deep learning model. The target determination module is configured to determine the converted deep learning model as a target converted deep learning model if the target verification result meets a preset verification result corresponding to the converted deep learning model.

6. The apparatus of claim 5, wherein, The model construction module is further configured to perform format conversion processing on the weight information corresponding to the to-be-processed deep learning model to obtain processed weight information corresponding to the to-be-processed deep learning model, and construct a converted deep learning model corresponding to the to-be-processed deep learning model according to the updated graph structure information, the processed weight information, and the configuration information corresponding to the to-be-processed deep learning model.

7. The apparatus of claim 5, wherein, The device further comprises an information verification module configured to verify the graph structure information corresponding to the to-be-processed deep learning model to obtain a first verification result, and verify the weight information corresponding to the to-be-processed deep learning model to obtain a second verification result, and the information update module is further configured to update the graph structure information corresponding to the to-be-processed deep learning model according to the configuration information corresponding to the to-be-processed deep learning model to obtain updated graph structure information corresponding to the to-be-processed deep learning model if the first verification result and the second verification result both meet a preset condition. 8.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-7. The processor executes the computer program to implement the steps of the method of any one of claims 1 to 4.

9. A computer readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 4.

10. A computer program product comprising a computer program, characterized in that, The computer program is executed by the processor to implement the steps of the method of any one of claims 1 to 4.

Citation Information

Patent Citations

  • Model conversion method and device, equipment, storage medium and product

    CN118095365A