Model compiling method and device based on machine learning, medium and product
Through the model compilation method based on machine learning, the operator information and data type definition information of the machine learning model are transformed using data structure relationships, and the network structure diagram is generated and the intermediate representation is generated, which solves the problems of complex and low efficiency in the existing technology, and improves efficiency.
Patent Information
- Application Number
- CN202311582570.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-23
- Publication Date
- 2025-05-23
AI Technical Summary
In the prior art, the process of generating operators and computational graphs of machine learning models is complicated, and the human-computer interaction efficiency is low.
A machine learning-based model compilation method is provided. By obtaining operator information and data type definition information in model compilation instructions, the graph structure is transformed using pre-configured data structure relationships, a network structure diagram is generated, and an intermediate representation is generated based on the graph.
The generation efficiency of intermediate representation and human-computer interaction efficiency are improved, and the additional configuration of intermediate representation-related framework interfaces are avoided.
Smart Images

Figure CN120029624A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of artificial intelligence, and in particular to a model compilation method, device, medium and product based on machine learning. Background Art
[0002] The Multi-Level Intermediate Representation (MLIR) framework is a new framework that aims to provide a flexible, extensible, and reusable compiler infrastructure. MLIR provides representations at multiple levels of abstraction, from high-level representations (such as Tensor representations) to low-level representations (such as LLVM representations). Multi-level representations allow the compiler to better understand and optimize computational graphs and operations at different levels.
[0003] In the related technology, developers learn MLIR-specific data structures, and in the process of designing machine learning models, they call the MLIR creator by constructing conversion functions and generate operators and computational graphs in the machine learning models.
[0004] However, the process of generating operators and computational graphs in the above process is relatively complicated, and the human-computer interaction efficiency is low. Summary of the invention
[0005] The embodiments of the present application provide a model compilation method, device, medium and product based on machine learning, which can improve the human-computer interaction efficiency of generating intermediate representations of machine learning models. The technical solution is as follows:
[0006] In one aspect, a model compilation method based on machine learning is provided, the method comprising:
[0007] Obtain a model compilation instruction, wherein the model compilation instruction includes operator information and data type definition information corresponding to the machine learning model, wherein the operator information and the data type definition information are information written in a first programming language;
[0008] Performing graph structure conversion on the operator information and the data type definition information based on a preconfigured data structure relationship to obtain a network structure graph corresponding to the machine learning model, wherein the network structure graph includes nodes corresponding to the operation operators and edges corresponding to the numerical parameters, and the data structure relationship includes a predefined operation encapsulation class and an attribute encapsulation class corresponding to the second programming language, the operation encapsulation class is used to construct the nodes and edges of the network structure graph, and the attribute encapsulation class is used to configure the nodes and edges;
[0009] An intermediate representation corresponding to the machine learning model is generated based on the network structure diagram, and the intermediate representation is a result of representing the machine learning model in a second programming language.
[0010] On the other hand, a model compilation device based on machine learning is provided, the device comprising:
[0011] An acquisition module, used to acquire a model compilation instruction, wherein the model compilation instruction includes operator information and data type definition information corresponding to the machine learning model, wherein the operator information and the data type definition information are information written in a first programming language;
[0012] A conversion module, configured to perform graph structure conversion on the operator information and the data type definition information based on a preconfigured data structure relationship to obtain a network structure graph corresponding to the machine learning model, wherein the operator information and the data type definition information are information automatically extracted from the model compilation instruction through keyword recognition, the network structure graph includes nodes corresponding to the operation operators, and edges corresponding to the numerical parameters, the data structure relationship includes a predefined operation encapsulation class and an attribute encapsulation class corresponding to the second programming language, the operation encapsulation class is used to construct the nodes and edges of the network structure graph, and the attribute encapsulation class is used to configure the nodes and edges;
[0013] A generation module is used to generate an intermediate representation corresponding to the machine learning model based on the network structure diagram, and the intermediate representation is a result of representing the machine learning model through a second programming language.
[0014] On the other hand, a computer device is provided, comprising a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the machine learning-based model compilation method provided in the above-mentioned embodiment of the present application.
[0015] On the other hand, a computer-readable storage medium is provided, in which at least one instruction, at least one program, a code set or an instruction set is stored, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the machine learning-based model compilation method provided in the above-mentioned embodiment of the present application.
[0016] On the other hand, a computer program product is provided. When the computer program product is run on a computer, the computer executes the machine learning-based model compilation method provided in the above-mentioned embodiment of the present application.
[0017] The beneficial effects brought by the technical solution provided by the embodiment of the present application include at least:
[0018] The information written in the first programming language is converted into an intermediate representation through a pre-configured data structure relationship, wherein the graph structure of the operator information and the data type definition information is automatically converted based on the data structure relationship, and the intermediate representation result corresponding to the machine learning model is generated based on the obtained network structure graph. The operator information and the data type definition information of the first programming language are converted through the conversion function in the data structure relationship to obtain the operation operator and numerical parameters corresponding to the second programming language, thereby composing and generating the intermediate representation, avoiding the additional configuration of the framework interface related to the intermediate representation during the development process, improving the generation efficiency of the intermediate representation, and improving the efficiency of human-computer interaction. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0020] Figure 1 It is a schematic diagram of a model compilation framework based on machine learning provided by an exemplary embodiment of the present application;
[0021] Figure 2 is a flowchart of a model compilation method based on machine learning provided by an exemplary embodiment of the present application;
[0022] Figure 3 is a schematic diagram of data structure relationship provided by an exemplary embodiment of the present application;
[0023] Figure 4 is a flowchart of a model compilation method based on machine learning provided by another exemplary embodiment of the present application;
[0024] Figure 5 is a flowchart of a model compilation method based on machine learning provided by another exemplary embodiment of the present application;
[0025] Figure 6 It is a schematic diagram of the position of Builder TableGen provided by an exemplary embodiment of the present application in the overall framework of building a network structure diagram;
[0026] Figure 7 It is a schematic diagram of the overall process of constructing a calculation operator provided by an exemplary embodiment of the present application;
[0027] Figure 8is a structural block diagram of a model compilation device based on machine learning provided by an exemplary embodiment of the present application;
[0028] Fig. 9 is a structural block diagram of a model compilation device based on machine learning provided by another exemplary embodiment of the present application;
[0029] Fig.10 It is a structural block diagram of a server provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION
[0030] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0031] First, the nouns involved in the embodiments of the present application are briefly introduced:
[0032] Intermediate Representation (IR) refers to an intermediate form of code representation generated during the compilation process. IR is generated after the source code has gone through the front-end compilation stages such as lexical analysis, syntax analysis, and semantic analysis, and is used for processing and conversion in the subsequent optimization and code generation stages. The IR compiler intermediate representation has nothing to do with the source code language and can be used for compilers of multiple source code languages; the IR compiler intermediate representation abstracts and simplifies the source code to a certain extent, removing some specific details and syntax sugar in the source code; the IR compiler intermediate representation can be low-level, close to the underlying machine representation, or intermediate, close to the representation of high-level languages. Different compilers can use different IR representations to adapt to different compilation optimization requirements and target platforms; the IR compiler intermediate representation usually has a clear structure and standardized operational semantics, allowing the compiler to perform various optimizations and analyses, such as constant folding, dead code elimination, loop optimization, etc.; the IR compiler intermediate representation can be directly mapped to the machine instructions or virtual machine instructions of the target platform, simplifying the subsequent code generation process.
[0033] By using the IR compiler intermediate representation, the flexibility, portability and optimization ability of the compiler can be improved, enabling the compiler to better convert source code into target code.
[0034] The Multi-Level Intermediate Representation (MLIR) framework is a new type of framework that aims to provide a flexible, extensible, and reusable compiler infrastructure. MLIR provides representations at multiple levels of abstraction, from high-level representations (such as tensor representations) to low-level representations (such as low-level virtual machines (LLVM) representations). Multi-level representations allow the compiler to better understand and optimize computational graphs and operations at different levels.
[0035] In related technologies, docking with multiple front-end model frameworks has become the most important part of the MLIR artificial intelligence (AI) compiler, and its versatility and user-friendliness are crucial. MLIR-based AI compiler frameworks usually choose a unified MLIR dialect as the unified access IR for different front-end frameworks. The MLIR-based front-end model parsing framework converts different front-end framework operator operations (Operator, referred to as Op) into MLIR unified Op according to semantics.
[0036] To solve this problem, the MLIR native framework provides an MLIR Builder to construct MLIROp. MLIR Builder is an application program interface (API) for building MLIR IR. MLIR Builder provides relevant APIs that allow users to create and modify various operations in MLIR IR, such as adding new operations, operation parameters, operation attributes, etc.
[0037] Users need to understand the data structure and related APIs of MLIR Builtin, such as the construction and use of related APIs for MLIR values, operations, types, and attributes. The learning cost and price of using MLIR Builder to construct MLIR Op are high, and the usability is poor.
[0038] In an embodiment of the present application, a scheme for constructing an MLIR Op is provided, which converts a machine learning model written by a user in a first programming language through a preset data structure relationship to obtain a corresponding network structure diagram, and generates a corresponding intermediate representation IR based on the network structure diagram, and automatically generates a packaged Op API from the user-defined Op based on the data structure relationship, thereby reducing workload and lowering the error rate of handwritten code.
[0039] Indicative, Figure 1 is a schematic diagram of a model compilation framework based on machine learning provided by an exemplary embodiment of the present application, such as Figure 1 As shown, first, the user writes a machine learning model in a first programming language and sends a model compilation instruction to the server 100. The server 100 obtains the model compilation instruction 110. The model compilation instruction 110 includes operator information and data type definition information corresponding to the machine learning model. The operator information and data type definition information are information written in the first programming language.
[0040] Based on the relationship between the operation encapsulation class 121 and the attribute encapsulation class 122 in the pre-configured data structure relationship 120 in the embodiment of the present application, the above operator information and data type definition information are converted into a network structure diagram 130 corresponding to the machine learning model, which includes nodes 131 corresponding to the operation operator and edges 132 corresponding to the numerical parameters. Among them, a conversion function 123 is also provided in the data structure relationship 120, and the conversion function is used to provide automatic call conversion between the first programming language and the second programming language, thereby completing the process of converting the above operator information into the operation operator and converting the data type definition information into the numerical parameter.
[0041] An intermediate representation 140 of the machine learning model is generated based on the generated network structure graph 130 .
[0042] It is worth noting that the above-mentioned servers can be independent physical servers, or they can be server clusters or distributed systems composed of multiple physical servers. They can also be cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), as well as big data and artificial intelligence platforms.
[0043] Among them, cloud technology refers to a hosting technology that unifies hardware, software, network and other resources in a wide area network or local area network to realize data computing, storage, processing and sharing. Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool, which is used on demand and flexible and convenient. Cloud computing technology will become an important support. The background services of the technical network system require a large amount of computing and storage resources, such as video websites, picture websites and more portal websites. With the high development and application of the Internet industry, in the future, each item may have its own identification mark, and all need to be transmitted to the background system for logical processing. Data of different levels will be processed separately. All kinds of industry data require strong system backing support, which can only be achieved through cloud computing.
[0044] In some embodiments, the above server can also be implemented as a node in a blockchain system.
[0045] It should be noted that the information, data, images, etc. involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0046] It should be understood that, although the terms first, second, etc. may be used in the present application to describe various information, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of the present application, the first parameter may also be referred to as the second parameter, and similarly, the second parameter may also be referred to as the first parameter. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".
[0047] Figure 2 1 is a flowchart of a model compilation method based on machine learning provided by an exemplary embodiment of the present application. The method can be executed by a terminal, or by a server, or by a terminal and a server in collaboration. In this embodiment, the method is applied to a server as an example for explanation. Figure 2 As shown, the method includes:
[0048] Step 201, obtain model compilation instructions, which include operator information and data type definition information corresponding to the machine learning model.
[0049] The operator information and the data type definition information are information written in the first programming language.
[0050] In some embodiments, the first programming language is a general language. Schematically, the first programming language includes C++ data structures and C++ Standard Template Library (STL).
[0051] That is, obtain a machine learning model written in a first programming language, and compile the machine learning model through a compiler.
[0052] The compilation process includes the compiler front-end, compiler mid-end and compiler back-end; the compiler front-end parses the deep learning models of different frameworks and converts them into a unified IR. Based on the unified IR, the compiler mid-end completes unified optimization. Finally, the compiler back-end converts the optimized IR into machine code that can be executed on the hardware.
[0053] Obtaining model compilation instructions refers to obtaining a machine learning model written in a framework corresponding to the first programming language.
[0054] Step 202: Perform graph structure conversion on the operator information and data type definition information based on the pre-configured data structure relationship to obtain a network structure graph corresponding to the machine learning model.
[0055] Among them, the network structure diagram includes nodes corresponding to operation operators and edges corresponding to numerical parameters. The data structure relationship includes pre-defined operation encapsulation classes and attribute encapsulation classes corresponding to the second programming language. The operation encapsulation class is used to construct the nodes and edges of the network structure diagram, and the attribute encapsulation class is used to configure the nodes and edges.
[0056] The data structure relationship also includes a conversion function, which is used to provide automatic call conversion between the first programming language and the second programming language. Optionally, the operator information and the data type definition information are mapped to the data structure relationship, and the operator information and the data type definition information corresponding to the first programming language are automatically converted through the conversion function to obtain an operation operator corresponding to the operator information and a numerical parameter corresponding to the data type definition information, wherein the operation operator and the numerical parameter are both expressions corresponding to the second programming language framework.
[0057] The operator information and data type definition information are information automatically extracted from the model compilation instruction through keyword recognition. In some embodiments, after obtaining the model compilation instruction, the content in the model compilation instruction is matched with the preset keywords, and the operator information and data type definition information are obtained from the model compilation instruction, so as to automatically generate nodes and edges corresponding to the operation operator based on the operator information and data type definition information, and form a network structure diagram corresponding to the machine learning model.
[0058] Indicative, Figure 3 is a schematic diagram of a data structure relationship provided by an exemplary embodiment of the present application, such as Figure 3 As shown, the data structure relationship mainly includes an operation encapsulation class 310 and an attribute encapsulation class 320, wherein the two encapsulation parts are described separately:
[0059] Operation encapsulation class (Op) 310: is the encapsulated operation class in the embodiment of the present application.
[0060] These include context builder functions (builder context) 311, operations (MLIR Operation) 312, values (MLIR Value) 313, and data shapes and type classes (Type) 314.
[0061] Context construction function 311: used to provide construction condition information when constructing a network structure diagram; wherein the context construction function 311 encapsulates context information (mlir context) 3111, global structure information (mlir Module) 3112 and function operation information (mlir FuncOp) 3113.
[0062] The context information 3111 is used to provide context description in the process of constructing the network structure diagram;
[0063] The global structure information 3112 is composed of a series of operations corresponding to the second programming language;
[0064] Function operation information 3113 is used to provide multiple operations corresponding to the second programming language.
[0065] Operation 312 is used to define an operation operator, and value 313 is used to define input and output parameters between operation operators.
[0066] The data shape and type class 314 is used to define operator configuration information and parameter configuration information. The data shape and type class 314 encapsulates a data shape class (vector shape) 3141 and a type class (Primitive Type) 3142. The data shape class 3141 is used to define the structure of data, such as one-dimensional data, two-dimensional matrix, etc., and the type class 3142 is used to define the type of data, such as integer, floating point, etc.
[0067] Attribute encapsulation class (Attribute) 320: is the attribute class encapsulated in the embodiment of the present application. The attributes in the attribute class can be used to describe and define the network structure diagram or a single operation Op.
[0068] These include the class friend function (friend class Op) 321 of the operation encapsulation class 310 and the class friend function (friend class builder context) 322 of the context builder function 311. When a class declares another class as a friend class, all member functions of the friend class can access the private member variables and private member functions of the class. That is, in order to facilitate the operation of the encapsulation class 310 and the context builder function 311 to access the private members of the Attribute class, other classes are prevented from directly accessing the private members of the class, thus protecting the encapsulation and security of the class.
[0069] The attribute encapsulation class 320 also encapsulates the data shape and type class (Type) 314 and the type class (PrimitiveType) 3142.
[0070] The above-mentioned operation encapsulation class and attribute encapsulation class are classes defined based on the second programming language. Optionally, the operation encapsulation class and attribute encapsulation class are classes defined in the programming language corresponding to the intermediate representation framework based on the intermediate representation framework. Schematically, the operation encapsulation class and attribute encapsulation class are classes defined based on the multi-level intermediate representation framework MLIR and based on the MLIR framework.
[0071] In the MLIR framework, function operation information (mlir FuncOp) is an operation used to represent a function, including the function name, input parameters, return value, and function body.
[0072] The global structure information (mlir Module) is the top-level structure in the MLIR framework, which represents a compilation unit and can contain multiple FuncOps and other global operations. Through MLIR Module, multiple functions and global operations can be combined into a complete compilation unit and uniformly optimized and converted.
[0073] In the related art, in MLIR Builder, context information (mlir context) is a context environment for managing MLIR intermediate representation objects.
[0074] In the embodiment of the present application, the Builder Context class data structure is redefined to uniformly encapsulate the Module, FuncOp, MLIR Context and other data structures in the MLIR framework. When creating a machine learning model, the relevant variables are obtained by constructing a Builder Context pointer. The neural network in deep learning is usually represented as a directed acyclic graph (DAG), where nodes represent neurons and edges represent connections between neurons. In MLIR, Value and Operation are components of DAG, Value represents the edge in the calculation graph, and Operation represents the node in the calculation graph. The representation of DAG enables MLIR to represent complex calculation graphs while supporting the optimization of multiple programming languages and hardware architectures. In the MLIR Builtin basic data structure, Value and Operation are defined and APIs are packaged separately.
[0075] In the embodiment of the present application, a data structure Op is redefined, and the Value and Operation of MLIR are encapsulated inside Op, and Op is used to replace Value and Operation to represent the deep learning calculation graph. Op is an abstract representation of all operation operators. In addition, the Attribute class and Type class are redefined in the embodiment of the present application, where the Type class includes Shape information and element data type information. Primitive Type information is defined to represent the element data type, and Primitive Type is a member class of Type.
[0076] The private member variables of the Builder Context class include MLIR Context / Module / FuncOp, etc., while the private members of Op include the Builder Context class and MLIR's Operation and Value, as well as our custom Type information. Attribute uses Op and Builder Context class friend functions as private variables of Attribute, and the Attribute class also includes Type and Primitive Type private classes.
[0077] Step 203: Generate an intermediate representation corresponding to the machine learning model based on the network structure graph.
[0078] The intermediate representation is the result of representing the machine learning model in a second programming language. In some embodiments, the intermediate representation includes a graph intermediate representation (graph IR), that is, a high-order intermediate representation, and the above network structure graph is used as the intermediate representation corresponding to the machine learning model.
[0079] Alternatively, after generating a network structure graph based on the MLIR framework, the network structure graph is transformed to obtain an intermediate representation corresponding to the machine learning model.
[0080] In summary, the model compilation method based on machine learning provided in the embodiment of the present application converts the information written in the first programming language into an intermediate representation through a pre-configured data structure relationship, wherein the operator information and data type definition information are automatically converted into a graph structure based on the data structure relationship, and the intermediate representation result corresponding to the machine learning model is generated based on the obtained network structure graph, and the operator information and data type definition information of the first programming language are converted through the conversion function in the data structure relationship to obtain the operation operator and numerical parameters corresponding to the second programming language, thereby composing and generating the intermediate representation, avoiding the additional configuration of the framework interface related to the intermediate representation during the development process, improving the generation efficiency of the intermediate representation, and improving the efficiency of human-computer interaction.
[0081] In the method provided in this embodiment, Attribute uses the friend functions of the Op and Builder Context classes as private variables of Attribute, so that the Op and Builder Context classes can conveniently access the private members of the Attribute class, thereby preventing other classes from directly accessing the private members of the class, thereby protecting the encapsulation and security of the class.
[0082] In an optional embodiment, when generating a graph structure conversion according to a preconfigured data structure relationship, the content written in the first programming language is mapped and matched with the data structure relationship. Figure 4 is a flowchart of a model compilation method based on machine learning provided by another exemplary embodiment of the present application. The method can be executed by a terminal, or by a server, or by a terminal and a server in collaboration. In this embodiment, the method is applied to a server as an example for explanation. Figure 4 As shown, the method includes:
[0083] Step 401, obtain model compilation instructions, which include operator information and data type definition information corresponding to the machine learning model.
[0084] The operator information and the data type definition information are information written in the first programming language.
[0085] Obtaining model compilation instructions refers to obtaining a machine learning model written in a framework corresponding to the first programming language.
[0086] Step 402: Map the operator information and the data type definition information to the data structure relationship, extract the operation operator indicated by the operator information, and extract the digital parameter indicated by the data type definition information.
[0087] Among them, the operator information is mapped to the data structure relationship to obtain the operation operator. In some embodiments, the operator information is algorithm information written in the first programming language, such as: addition, multiplication, convolution operation in a machine learning model, fully connected operation, etc. After mapping the operator information to the data structure relationship, the corresponding operation operator is extracted from the operator information, and the operation operator corresponding to the second programming language is generated. Among them, in this embodiment, the operation operator corresponding to the second programming language refers to the MLIR Operation corresponding to the MLIR framework. That is, after the user programs the operator information based on the C++ framework, the operation operator is extracted from the operator information through the data structure relationship, and the corresponding MLIR Operation is automatically generated. In some embodiments, based on the data structure relationship, it is also necessary to extract the configuration information corresponding to the operation operator from the model compilation instruction. Schematically, the operator information is used to indicate that the operation operator belongs to the addition operation, and the specific addition method of the addition operation is extracted from the model compilation instruction. For example, the addition types provided in the Attribute include addition type 1 (adding and taking the integer and discarding the decimal part), addition type 2 (adding and taking the integer and decimal parts), then the type 1 corresponding to the addition operation in the model compilation instruction is extracted, and this type is configured through the Attribute; or schematically, the operator information is used to indicate that the operation operator belongs to the convolution operation, and the convolution kernel size corresponding to the convolution operation is extracted from the model compilation instruction. For example, the convolution kernel sizes provided in the Attribute include 1×1, 3×3, etc., then the convolution kernel size 1×1 corresponding to the convolution operation in the model compilation instruction is extracted, and it is configured through the Attribute.
[0088] Similarly, the data type definition information is mapped to the data structure relationship to obtain the numerical parameter. In some embodiments, the data type definition information is algorithm information written in the first programming language, such as: integer, vector, matrix, etc. After mapping the data type definition information to the data structure relationship, the corresponding numerical parameter is extracted from the data type definition information, and the numerical parameter corresponding to the second programming language is generated. Among them, in this embodiment, the numerical parameter corresponding to the second programming language refers to the MLIR Value corresponding to the MLIR framework. That is, after the user programs the data type definition information based on the C++ framework, the numerical parameter is extracted from the data type definition information through the data structure relationship, and the corresponding MLIR Value is automatically generated. In some embodiments, based on the data structure relationship, it is also necessary to extract the configuration information corresponding to the numerical parameter from the model compilation instruction. Schematically, the data type definition information is used to indicate that the numerical parameter belongs to the vector, and the data type of the elements in the vector is extracted from the model compilation instruction. For example, the data type of the elements in the vector is extracted as integer type, and this data type is configured through the Attribute.
[0089] In some embodiments, the operation encapsulation class includes operations and values corresponding to the second programming language, and includes a context construction function corresponding to the second programming language, and the context construction function is used to provide construction condition information when constructing a network structure diagram. Among them, in the embodiment of the present application, the second programming language is a programming language corresponding to the MLIR framework as an example for explanation, then the operation encapsulation class Op includes MLIR Operation and MLIR Value corresponding to the MLIR framework, and includes a builder context corresponding to the MLIR framework.
[0090] The operator information is mapped and matched with the operation in the operation encapsulation class, and the operation operator indicated by the operator information is determined based on the context construction function; and the data type definition information is mapped and matched with the value in the operation encapsulation class, and the numerical parameter indicated by the data type definition information is determined based on the context construction function.
[0091] In some embodiments, the operator information is mapped and matched with the operations in the operation encapsulation class through a conversion function, and the operation operator corresponding to the operator information is determined based on the context construction function; the data type definition information is matched with the value in the operation encapsulation class through a conversion function, and the numerical parameters indicated by the data type definition information are determined based on the context construction function.
[0092] Optionally, the conversion function is used to establish an association relationship between operator information corresponding to the first programming language and an operation operator corresponding to the second programming language, and to establish an association relationship between data type definition information corresponding to the first programming language and numerical parameters corresponding to the second programming language. After determining the operation operator and the numerical parameter through the association relationship, the context construction function is used to generate nodes corresponding to the operation operator and edges corresponding to the numerical parameters.
[0093] In some embodiments, the attribute encapsulation class also includes candidate configuration information, operator configuration information and parameter configuration information are determined from the attribute encapsulation class, the operator information and data type definition information are mapped to the data structure relationship, the operation operator indicated by the operator information is extracted based on the operator configuration information, and the numerical parameter indicated by the data type definition information is extracted based on the parameter configuration information.
[0094] Optionally, the candidate configuration information includes encapsulated data shapes and type classes and encapsulated type classes; the operation encapsulation class encapsulates the data shapes and type classes; the data shapes and type classes encapsulate the data shape classes and type classes.
[0095] Step 403, using the operation operators as nodes and the numerical parameters as edges to construct a network structure graph.
[0096] Among them, the network structure diagram includes multiple operation operators and multiple edges. In some embodiments, the network structure diagram is a directed acyclic graph, that is, starting from the input node, passing through the intermediate node, and then output by the output node, thereby completing the entire data processing flow.
[0097] The operation operator is used as a node to characterize the processing algorithm corresponding to the data of the input node. For example, the convolution operation operator is used as an example to illustrate that the convolution operation is performed on the input data.
[0098] The value is used as an edge to represent the data type input to the post-order adjacent node, or to represent the data type output from the pre-order adjacent node.
[0099] Step 404: Generate an intermediate representation corresponding to the machine learning model based on the network structure graph.
[0100] The intermediate representation is the result of representing the machine learning model in a second programming language. In some embodiments, the intermediate representation includes a graph intermediate representation (graph IR), that is, a high-order intermediate representation, and the above network structure graph is used as the intermediate representation corresponding to the machine learning model.
[0101] In summary, the model compilation method based on machine learning provided in the embodiment of the present application converts the information written in the first programming language into an intermediate representation through a pre-configured data structure relationship, wherein the operator information and data type definition information are automatically converted into a graph structure based on the data structure relationship, and the intermediate representation result corresponding to the machine learning model is generated based on the obtained network structure graph, and the operator information and data type definition information of the first programming language are converted through the conversion function in the data structure relationship to obtain the operation operator and numerical parameters corresponding to the second programming language, thereby composing and generating the intermediate representation, avoiding the additional configuration of the framework interface related to the intermediate representation during the development process, improving the generation efficiency of the intermediate representation, and improving the efficiency of human-computer interaction.
[0102] The method provided in this embodiment determines the operation operator corresponding to the operator information and the numerical parameters corresponding to the data type definition information based on the mapping relationship between the pre-configured data structure relationship and the model compilation instruction, thereby constructing a network structure diagram and improving the efficiency of extracting the intermediate representation.
[0103] The method provided in this embodiment maps the operation and operator information in the operation encapsulation class to obtain the operation operator and numerical parameters, and configures the operation operator and numerical parameters through the configuration items in the attribute encapsulation class, thereby improving the extraction efficiency of the intermediate representation.
[0104] In an optional embodiment, during the graph structure conversion process, a pre-developed code table generator (TableGen) is used to automatically generate the first programming language code for constructing Op. Figure 5 is a flowchart of a model compilation method based on machine learning provided by another exemplary embodiment of the present application. The method can be executed by a terminal, or by a server, or by a terminal and a server in collaboration. In this embodiment, the method is applied to a server as an example for explanation. Figure 5 As shown, the method includes:
[0105] Step 501: Obtain model compilation instructions, which include operator information and data type definition information corresponding to the machine learning model.
[0106] The operator information and the data type definition information are information written in the first programming language.
[0107] Obtaining model compilation instructions refers to obtaining a machine learning model written in a framework corresponding to the first programming language.
[0108] Step 502: Generate an input operator node based on the pre-configured data structure relationship, operator information, and data type definition information. The input operator node is used to obtain input data for the machine learning model.
[0109] In some embodiments, when constructing an operator node, the user inputs the data structure in the C++ Standard Template Library (STL) and the data type in C++STL without converting the C++STL and MLIR data structures, and constructs the operator node based on the converted structure.
[0110] Optionally, through the data structure and data type Builder Context pointer in C++STL, the Context and FuncOp information of MLIR is obtained through the Builder Context pointer. Optionally, a private variable module pointer is encapsulated in the Builder Context class, that is, MLIR Module. When the network structure diagram is constructed through the Builder Context, the MLIR Module is initialized and constructed, that is, the Builder Context has a global unique MLIRModule. It can be understood that the network structure diagram composed of ops in a machine learning model corresponds to a Module in MLIR.
[0111] After obtaining the MLIR Context according to the pointer, the relevant dialect is loaded. In programming languages, Dialect refers to a variant or extension based on the main language with specific syntax, semantics, and functions. Dialect can add new language features, optimization rules, etc. to meet the needs of specific fields or simplify programming tasks. Dialect is usually extended and modified based on the main language, so it can share basic structures and libraries with the code of the main language.
[0112] That is, after obtaining the MLIR Context, determine and load the dialect involved in the process of compiling the intermediate representation, such as: MHLO (Multi-Headed Logits Optimization) dialect. MHLO dialect is a special dialect used to describe the graph operations of multi-headed logic optimization. MHLO dialect is an intermediate representation in TensorFlow, used to represent and optimize the computational graph for multi-headed logic.
[0113] The main design goal of the MHLO dialect is to provide a compact and extensible representation to efficiently represent and process multi-head logical operations. The MHLO dialect supports operations that describe multiple logical heads, such as matrix multiplication and convolution of multiple logical heads. This operation is a common operation in neural networks and can improve the flexibility and performance of the model. The MHLO dialect supports profiling operations to decompose multi-head operations into single-head operations. This allows the computational graph to be optimized and analyzed more before actual execution. The MHLO dialect provides a series of optimization rules for optimizing multi-head logical operations, such as fusion, rearrangement, dimensionality reduction, etc. These optimization rules can improve the efficiency and performance of the computational graph.
[0114] Based on the operator information and data type definition information input by the user through the first programming language, the computing operator node Op that needs to be constructed is first determined, and the data type Type of the input and output numerical parameters of the operator node is constructed according to the data type definition information, and the input Op of the computing operator node Op is constructed according to the Type information. In some embodiments, TableGen is called to automatically generate the input operator node of the computing operator node Op, that is, the input Op.
[0115] Step 503, generating a computing operator node based on the pre-configured data structure relationship, operator information and data type definition information, and the computing operator node is used to implement data operations of the machine learning model.
[0116] Optionally, TableGen is called to generate a computing operator node based on the generated input operator nodes, operator information, and data type definition information.
[0117] In the above process of calling TableGen to generate operator nodes, TableGen simplifies the construction process of operator nodes. In MLIR, TableGen is used to define and generate MLIR's operation Operation, Value, Attribute, Type and other information. By using TableGen, you can define the structure of MLIR without manually writing a lot of repetitive code. The TableGen file defines the structure and properties of the MLIR structure and generates the corresponding C++ code at compile time. This makes code generation more efficient and also helps ensure the correctness and consistency of the structure. For MLIR native data structures Operation, Value, Attribute and Type information, MLIR native TableGen can be used to generate them.
[0118] The Op, Attribute, and Type defined in the embodiments of the present application are all encapsulations of MLIR native data structures, and the Op defined in the embodiments of the present application is an abstract data structure of all Operators. For Ops with specific semantics, such as the convolution operator ConvOp, etc., the embodiments of the present application extend the TableGen of MLIR and provide a tool for generating and managing custom Ops, Types, and Attributes in the embodiments of the present application. The TableGen is taken as an example to illustrate that the user does not need to manually write a large amount of repetitive code, which improves work efficiency and code writing error rate while improving ease of use.
[0119] Figure 6 It is the position of Builder TableGen in the overall framework of building the network structure diagram. For example, taking the unified IR Dialect as MHLO IR, the MHLO Dialect defines more than 140 Ops, all of which are fine-grained Op610, while the front-end framework is coarse-grained Op611. Figure 6 As shown, Ops.td is a format defined by MLIR TableGen for describing and generating codes, which defines a domain specific language (DSL) for describing and generating MHLO Operations in codes. Ops.td can automatically generate C++ codes 640 of Op 630 and Attribute defined in the embodiment of the present application through Builder TableGen 620, and automatically generate Op header files, Op interface files and build function implementations of specific Ops.
[0120] MLIR TableGen is a tool for automatically generating C++ code. It uses the TableGen language to describe the rules for code generation. The specific process of MLIR TableGen generating C++ code is as follows:
[0121] 1. Write a TableGen source file. First, you need to write a TableGen source file, which describes the structure and properties of the C++ code to be generated. TableGen source files usually include definitions such as record types, fields, instructions, and operations.
[0122] 2. Run TableGen, taking the TableGen source file as input, and run the TableGen tool. The TableGen tool parses the source file and generates the corresponding C++ code.
[0123] 3. Generate C++ code. The C++ code generated by the TableGen tool includes some basic classes and conversion functions, as well as specific code implementations generated according to the rules defined in the source file.
[0124] 4. Compile the generated code, add the generated C++ code to the project, compile and link it, and generate an executable file or library.
[0125] MLIR TableGen describes the rules for code generation through TableGen source files, and then generates the corresponding C++ code. This code generation method can reduce the writing of repeated code and improve the maintainability and scalability of the code.
[0126] The Builder Tablegen in the embodiment of the present application is expanded on the basis of MLIR tableGen, and the generated content is the C++ construction method of the operator Op related to the machine learning model, and the data structure used for construction is Op, Type, and Attribue defined in the embodiment of the present application.
[0127] like Figure 6 As shown, the user writes the coarse-grained Op611 corresponding to the front-end framework, and the Op610 defined by MLIR is a fine-grained Op. The Op610 defined by MLIR is converted through Builder TableGen620 to generate the C++ code 640 of Op630 and Attribute defined in the embodiment of this application, and the coarse-grained Op611 is mapped to the C++ code 640 of Op630 and Attribute, thereby generating the Op and Attribute corresponding to the coarse-grained Op611, and constructing the corresponding operation operator node.
[0128] Step 504, generating an output operator node based on the pre-configured data structure relationship, operator information and data type definition information, and the output operator node is used to output the operation result of the machine learning model.
[0129] Step 505 , construct a network structure diagram corresponding to the learning model based on the input operator nodes, the calculation operator nodes and the output operator nodes.
[0130] Among them, the input operator node is used to receive data input of the machine learning model, and is usually the starting node of the network structure diagram; the output operator node is used to output the operation results of the machine learning model, and is usually the ending node of the network structure diagram.
[0131] Figure 7 is a schematic diagram of the overall process of constructing a calculation operator provided by an exemplary embodiment of the present application, such as Figure 7 As shown, the process includes: Step 701 , receiving the model compilation instruction input by the user, including operator information and configuration information of the shape of the data type, wherein the configuration information of the data type and shape is configured by using C++STL and data structure. Step 702 , create a Builder Context pointer. The Builder Context pointer is used to indicate the Context and FuncOp information obtained in the Builder Context corresponding to the model compilation instruction. Step 703 , get the MLIR Context, and load the relevant dialect. Step 704 , constructs a custom Type based on the input Vector shape and data type information. Schematically, the user inputs a Vector shape of (4, 3) to represent a matrix, and the input element data type is an integer, which determines the type of the input and output value on the left and right sides of the Operation in the DAG structure. Step 705 , construct the left and right input operators of the calculation operator according to Type. Optionally, call Builder TableGen to automatically generate constantOp as the input of the calculation operator, which is the inputOp of FuncOp. Among them, ConstantOp is an operation in TensorFlow or other deep learning models / frameworks that is used to create a tensor (Tensor) containing constant values. Using the ConstantOp operation, you can create various types of constant tensors, such as scalars (Scalar), vectors (Vector), matrices (Matrix), etc. ConstantOp can accept the value of a constant as input and return a constant tensor containing the value. Step 706, based on the ConstantOp input on the left and right, call Builder TableGen to automatically generate calculation operators. Step 707 , set the output of the calculation operator as the output of FuncOp and set it to OutputOp. Step 708 , according to the conversion interface provided by Builder Context, get the IR of MLIR unified Dialect.
[0132] Step 506: Generate an intermediate representation corresponding to the machine learning model based on the network structure graph.
[0133] The intermediate representation is the result of representing the machine learning model in the second programming language. In some embodiments, the intermediate representation includes a graph intermediate representation, that is, a high-order intermediate representation, and the above network structure graph is used as the intermediate representation corresponding to the machine learning model.
[0134] In summary, the model compilation method based on machine learning provided in the embodiment of the present application converts the information written in the first programming language into an intermediate representation through a pre-configured data structure relationship, wherein the operator information and data type definition information are automatically converted into a graph structure based on the data structure relationship, and the intermediate representation result corresponding to the machine learning model is generated based on the obtained network structure graph, and the operator information and data type definition information of the first programming language are converted through the conversion function in the data structure relationship to obtain the operation operator and numerical parameters corresponding to the second programming language, thereby composing and generating the intermediate representation, avoiding the additional configuration of the framework interface related to the intermediate representation during the development process, improving the generation efficiency of the intermediate representation, and improving the efficiency of human-computer interaction.
[0135] The method provided in the embodiment of the present application simplifies the complexity of the Op transformation process and reduces the user's learning cost by constructing a data structure relationship to replace the MLIR native Builder interface. In addition, in the embodiment of the present application, MLIRBuilder TableGen is designed and developed to replace the MLIR native TableGen, automatically generating C++ code for machine learning model-related Ops, reducing the code error rate and workload.
[0136] The method provided in the embodiment of the present application overcomes the cumbersome and complex problems of constructing native MLIR and automatically generating Ops, improves the versatility and ease of use of the deep learning compiler in the process of docking with the front-end framework, is conducive to the promotion and application of the deep learning framework, and helps the implementation of AI products.
[0137] Figure 8 is a model compilation device based on machine learning provided by an exemplary embodiment of the present application, such as Figure 8As shown, the device includes: an acquisition module 810, a conversion module 820 and a generation module 830;
[0138] An acquisition module 810 is used to acquire a model compilation instruction, wherein the model compilation instruction includes operator information and data type definition information corresponding to the machine learning model, and the operator information and the data type definition information are information written in a first programming language;
[0139] A conversion module 820 is used to perform graph structure conversion on the operator information and the data type definition information based on a preconfigured data structure relationship to obtain a network structure graph corresponding to the machine learning model, wherein the operator information and the data type definition information are information automatically extracted from the model compilation instruction through keyword recognition, the network structure graph includes nodes corresponding to the operation operators, and edges corresponding to the numerical parameters, the data structure relationship includes a predefined operation encapsulation class and an attribute encapsulation class corresponding to the second programming language, the operation encapsulation class is used to construct the nodes and edges of the network structure graph, and the attribute encapsulation class is used to configure the nodes and edges;
[0140] The generation module 830 is used to generate an intermediate representation corresponding to the machine learning model based on the network structure diagram, and the intermediate representation is the result of representing the machine learning model through a second programming language.
[0141] In an optional embodiment, if Fig. 9 As shown, the conversion module 820 includes:
[0142] A mapping unit 821, configured to map the operator information and the data type definition information with the data structure relationship, extract the operation operator indicated by the operator information, and extract the numerical parameter indicated by the data type definition information;
[0143] The construction unit 822 is used to construct the network structure diagram by using the operation operators as nodes and the numerical parameters as edges.
[0144] In an optional embodiment, the mapping unit 821 is also used to map the operator information and the data type definition information with the data structure relationship; the operator information and the data type definition information corresponding to the first programming language are automatically converted through the conversion function to obtain the operation operator corresponding to the operator information and the numerical parameter corresponding to the data type definition information.
[0145] In an optional embodiment, the attribute encapsulation class includes operations and values corresponding to the second programming language, and includes a context construction function corresponding to the second programming language, and the context construction function is used to provide construction condition information when constructing the network structure diagram;
[0146] The mapping unit 821 is further used to map and match the operator information with the operation in the attribute encapsulation class, and determine the operation operator indicated by the operator information based on the context construction function;
[0147] The mapping unit 821 is further configured to map and match the data type definition information with the value in the attribute encapsulation class, and determine the numerical parameter indicated by the data type definition information based on the context construction function.
[0148] In an optional embodiment, the context construction function includes at least one of context information, global structure information, and function operation information;
[0149] The context information is used to provide context description in the process of constructing the network structure diagram;
[0150] The global structure information is composed of a series of operations corresponding to the second programming language;
[0151] The function operation information is used to provide a plurality of operations corresponding to the second programming language.
[0152] In an optional embodiment, the attribute encapsulation class declares the operation encapsulation class and the context construction function as class friend functions as private variables of the attribute encapsulation class.
[0153] In an optional embodiment, the attribute encapsulation class includes candidate configuration information;
[0154] The mapping unit 821 is also used to determine the operator configuration information and parameter configuration information from the attribute encapsulation class; map the operator information and the data type definition information with the data structure relationship, extract the operation operator indicated by the operator information based on the operator configuration information, and extract the numerical parameter indicated by the data type definition information based on the parameter configuration information.
[0155] In an optional embodiment, the candidate configuration information includes the encapsulated data shape and type class and the encapsulated type class;
[0156] The operation encapsulation class encapsulates the data shape and type class;
[0157] The data shape and type classes encapsulate data shape classes and type classes.
[0158] In an optional embodiment, the conversion module 820 is further used to generate an input operator node based on the preconfigured data structure relationship, the operator information and the data type definition information, and the input operator node is used to obtain input data of the machine learning model;
[0159] The conversion module 820 is further used to generate a computing operator node based on the pre-configured data structure relationship, the operator information and the data type definition information, and the computing operator node is used to implement the data operation of the machine learning model;
[0160] The conversion module 820 is further used to generate an output operator node based on the pre-configured data structure relationship, the operator information and the data type definition information, and the output operator node is used to output the operation result of the machine learning model;
[0161] The conversion module 820 is also used to construct a network structure diagram corresponding to the machine learning model based on the input operator nodes, the calculation operator nodes and the output operator nodes.
[0162] In summary, the model compilation device based on machine learning provided in the embodiment of the present application converts the information written in the first programming language into an intermediate representation through a pre-configured data structure relationship, wherein the operator information and data type definition information are automatically converted into a graph structure based on the data structure relationship, and the intermediate representation result corresponding to the machine learning model is generated based on the obtained network structure graph, and the operator information and data type definition information of the first programming language are converted through the conversion function in the data structure relationship to obtain the operation operator and numerical parameters corresponding to the second programming language, thereby composing and generating the intermediate representation, avoiding the additional configuration of the framework interface related to the intermediate representation during the development process, improving the generation efficiency of the intermediate representation, and improving the efficiency of human-computer interaction.
[0163] It should be noted that the model compilation device based on machine learning provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the model compilation device based on machine learning provided in the above embodiment is based on the same concept as the model compilation method embodiment based on machine learning. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0164] The present application also provides a computer device, which includes a processor and a memory, wherein the memory stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the machine learning-based model compilation method provided by the above-mentioned various method embodiments. It should be noted that the computer device can be as follows Fig.10 Computer equipment provided.
[0165] Please refer to Fig.10 , which shows a schematic diagram of the structure of a computer device provided by an exemplary embodiment of the present application. Specifically, the computer device 1000 includes a central processing unit (CPU) 1001, a system memory 1004 including a random access memory (RAM) 1002 and a read-only memory (ROM) 1003, and a system bus 1005 connecting the system memory 1004 and the central processing unit 1001. The computer device 1000 also includes a basic input / output system (I / O system) 1006 that helps transmit information between various devices in the computer, and a large-capacity storage device 1007 for storing an operating system 1013, application programs 1014 and other program modules 1015.
[0166] The basic input / output system 1006 includes a display 1008 for displaying information and an input device 1009 such as a mouse and a keyboard for user inputting information. The display 1008 and the input device 1009 are connected to the central processing unit 1001 through an input / output controller 1010 connected to the system bus 1005. The basic input / output system 1006 may also include an input / output controller 1010 for receiving and processing inputs from a plurality of other devices such as a keyboard, a mouse, or an electronic stylus. Similarly, the input / output controller 1010 also provides output to a display screen, a printer, or other types of output devices.
[0167] The mass storage device 1007 is connected to the central processing unit 1001 through a mass storage controller (not shown) connected to the system bus 1005. The mass storage device 1007 and its associated computer readable medium provide non-volatile storage for the computer device 1000. That is, the mass storage device 1007 may include a computer readable medium (not shown) such as a hard disk or a CD-ROM drive.
[0168] Without loss of generality, the computer-readable medium may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented by any method or technology for storing information such as computer-readable instructions, data structures, program modules or other data. Computer storage media include RAM, ROM, EPROM, EEPROM, flash memory or other solid-state storage technologies, CD-ROM, DVD or other optical storage, tape cassettes, magnetic tapes, disk storage or other magnetic storage devices. Of course, those skilled in the art will appreciate that the computer storage media is not limited to the above. The above-mentioned system memory 1004 and mass storage device 1007 can be collectively referred to as memory.
[0169] The memory stores one or more programs, and the one or more programs are configured to be executed by one or more central processing units 1001. The one or more programs include instructions for implementing the above-mentioned model compilation method based on machine learning or the translation method based on a machine translation model. The central processing unit 1001 executes the one or more programs to implement the model compilation method based on machine learning or the translation method based on a machine translation model provided in the above-mentioned various method embodiments.
[0170] According to various embodiments of the present invention, the computer device 1000 can also be connected to a remote computer on the network through a network such as the Internet. That is, the computer device 1000 can be connected to the network 1012 through the network interface unit 1011 connected to the system bus 1005, or the network interface unit 1011 can be used to connect to other types of networks or remote computer systems (not shown).
[0171] The memory also includes one or more programs, which are stored in the memory, and the one or more programs include steps executed by a computer device in the machine learning-based model compilation method provided in an embodiment of the present invention.
[0172] An embodiment of the present application also provides a computer device, which includes a memory and a processor, wherein the memory stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded by the processor to implement the above-mentioned machine learning-based model compilation method.
[0173] An embodiment of the present application also provides a computer-readable storage medium, which stores at least one instruction, at least one program, a code set or an instruction set. The at least one instruction, the at least one program, the code set or the instruction set are loaded and executed by the processor to implement the above-mentioned machine learning-based model compilation method.
[0174] The present application also provides a computer program product. When the computer program product runs on a computer, it enables the computer to execute the model compilation method based on machine learning provided by the above-mentioned various method embodiments.
[0175] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the relevant hardware through a program, and the program can be stored in a computer-readable storage medium, which can be a computer-readable storage medium contained in the memory in the above embodiments; or it can be a computer-readable storage medium that exists alone and is not assembled in the terminal. The computer-readable storage medium stores at least one instruction, at least one program, code set or instruction set, and the at least one instruction, the at least one program, the code set or instruction set is loaded and executed by the processor to implement the above-mentioned model compilation method based on machine learning or the translation method based on the machine translation model. Optionally, the computer-readable storage medium may include: a read-only memory (ROM, Read Only Memory), a random access memory (RAM, Random Access Memory), a solid state drive (SSD, Solid State Drives) or an optical disk, etc. Among them, the random access memory may include a resistance random access memory (ReRAM, Resistance Random Access Memory) and a dynamic random access memory (DRAM, Dynamic Random Access Memory). The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0176] Those skilled in the art can understand that all or part of the steps of the above embodiments can be completed by hardware, or by a program to instruct the relevant hardware to complete, and the program can be stored in a computer-readable storage medium, and the above-mentioned storage medium can be a read-only memory, a disk or an optical disk, etc. The above description is only a preferred embodiment of the present application, and is not intended to limit the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. A model compilation method based on machine learning, It is characterized in that The method comprises: Obtain a model compilation instruction, wherein the model compilation instruction includes operator information and data type definition information corresponding to the machine learning model, wherein the operator information and the data type definition information are information written in a first programming language; Based on a preconfigured data structure relationship, the operator information and the data type definition information are converted into a graph structure to obtain a network structure graph corresponding to the machine learning model, wherein the network structure graph includes nodes corresponding to the operation operators and edges corresponding to the numerical parameters, and the data structure relationship includes a predefined operation encapsulation class and an attribute encapsulation class corresponding to the second programming language, the operation encapsulation class is used to construct the nodes and edges of the network structure graph, and the attribute encapsulation class is used to configure the nodes and edges, and the data structure relationship also includes a conversion function, and the conversion function is used to provide automatic call conversion between the first programming language and the second programming language; An intermediate representation corresponding to the machine learning model is generated based on the network structure diagram, and the intermediate representation is a result of representing the machine learning model in a second programming language.
2. The method according to claim 1, It is characterized in that The step of performing graph structure conversion on the operator information and the data type definition information based on the pre-configured data structure relationship to obtain a network structure graph corresponding to the machine learning model includes: Mapping the operator information and the data type definition information with the data structure relationship, extracting the operation operator indicated by the operator information, and extracting the numerical parameter indicated by the data type definition information; The network structure diagram is constructed by taking the operation operators as nodes and the numerical parameters as edges.
3. The method according to claim 2, It is characterized in that The mapping of the operator information and the data type definition information to the data structure relationship, extracting the operation operator indicated by the operator information, and extracting the numerical parameter indicated by the data type definition information includes: Mapping the operator information and the data type definition information to the data structure relationship; The operator information corresponding to the first programming language and the data type definition information are automatically converted through the conversion function to obtain an operation operator corresponding to the operator information and a numerical parameter corresponding to the data type definition information.
4. The method according to claim 2, It is characterized in that The attribute encapsulation class includes operations and values corresponding to the second programming language, and includes a context construction function corresponding to the second programming language, and the context construction function is used to provide construction condition information when constructing the network structure diagram; The mapping of the operator information and the data type definition information to the data structure relationship, extracting the operation operator indicated by the operator information, and extracting the numerical parameter indicated by the data type definition information includes: Mapping and matching the operator information with the operation in the attribute encapsulation class, and determining the operation operator indicated by the operator information based on the context construction function; The data type definition information is mapped and matched with the value in the attribute encapsulation class, and the numerical parameter indicated by the data type definition information is determined based on the context construction function.
5. The method according to claim 4, It is characterized in that The context construction function includes at least one of context information, global structure information, and function operation information; The context information is used to provide context description in the process of constructing the network structure diagram; The global structure information is composed of a series of operations corresponding to the second programming language; The function operation information is used to provide a plurality of operations corresponding to the second programming language.
6. The method according to claim 4, It is characterized in that The attribute encapsulation class declares the operation encapsulation class and the context construction function as class friend functions as private variables of the attribute encapsulation class.
7. The method according to claim 2, It is characterized in that The attribute encapsulation class includes candidate configuration information; The mapping of the operator information and the data type definition information to the data structure relationship, extracting the operation operator indicated by the operator information, and extracting the numerical parameter indicated by the data type definition information includes: Determine operator configuration information and parameter configuration information from the attribute encapsulation class; The operator information and the data type definition information are mapped to the data structure relationship, the operation operator indicated by the operator information is extracted based on the operator configuration information, and the numerical parameter indicated by the data type definition information is extracted based on the parameter configuration information.
8. The method according to claim 7, It is characterized in that The candidate configuration information includes the encapsulated data shape and type class and the encapsulated type class; The operation encapsulation class encapsulates the data shape and type class; The data shape and type classes encapsulate data shape classes and type classes.
9. The method according to any one of claims 1 to 8, It is characterized in that The step of performing graph structure conversion on the operator information and the data type definition information based on the pre-configured data structure relationship to obtain a network structure graph corresponding to the machine learning model includes: Generate an input operator node based on the preconfigured data structure relationship, the operator information and the data type definition information, wherein the input operator node is used to obtain input data of the machine learning model; Generate a computing operator node based on the pre-configured data structure relationship, the operator information and the data type definition information, wherein the computing operator node is used to implement data operations of the machine learning model; Generate an output operator node based on the preconfigured data structure relationship, the operator information and the data type definition information, wherein the output operator node is used to output the operation result of the machine learning model; A network structure diagram corresponding to the machine learning model is constructed based on the input operator nodes, the calculation operator nodes and the output operator nodes.
10. A model compilation device based on machine learning, It is characterized in that The device comprises: An acquisition module, used to acquire a model compilation instruction, wherein the model compilation instruction includes operator information and data type definition information corresponding to the machine learning model, wherein the operator information and the data type definition information are information written in a first programming language; A conversion module, configured to perform graph structure conversion on the operator information and the data type definition information based on a preconfigured data structure relationship to obtain a network structure graph corresponding to the machine learning model, wherein the operator information and the data type definition information are information automatically extracted from the model compilation instruction through keyword recognition, the network structure graph includes nodes corresponding to the operation operators, and edges corresponding to the numerical parameters, the data structure relationship includes a predefined operation encapsulation class and an attribute encapsulation class corresponding to the second programming language, the operation encapsulation class is used to construct the nodes and edges of the network structure graph, and the attribute encapsulation class is used to configure the nodes and edges; A generation module is used to generate an intermediate representation corresponding to the machine learning model based on the network structure diagram, and the intermediate representation is a result of representing the machine learning model through a second programming language.
11. The device according to claim 10, It is characterized in that The conversion module comprises: A mapping unit, used to map the operator information and the data type definition information with the data structure relationship, extract the operation operator indicated by the operator information, and extract the numerical parameter indicated by the data type definition information; A construction unit is used to construct the network structure diagram by using the operation operators as nodes and the numerical parameters as edges.
12. A computer device, It is characterized in that The computer device includes a processor and a memory, wherein the memory stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the machine learning-based model compilation method as described in any one of claims 1 to 9.
13. A computer-readable storage medium, It is characterized in that The readable storage medium stores at least one instruction, and the at least one instruction is loaded and executed by the processor to implement the machine learning-based model compilation method as described in any one of claims 1 to 9.
14. A computer program product, It is characterized in that It includes a computer program or an instruction, which, when executed by a processor, implements the model compilation method based on machine learning as described in any one of claims 1 to 9.