Method, system, device and medium based on database-driven deep learning model
By setting up model tables and internal interfaces within the database, deep learning model training and inference can be performed directly within the database, solving the model storage and compatibility issues in existing technologies, improving learning performance and reducing development workload.
Patent Information
- Application Number
- CN202410753082.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-12
- Publication Date
- 2025-09-19
- Estimated Expiration
- 2044-06-12
AI Technical Summary
Existing in-database deep learning methods cannot provide model storage and have low compatibility, resulting in increased development effort and performance loss.
Set up a model table in the database to store deep learning models, interact with the deep learning library through an internal interface, and perform model training and inference directly in the database, avoiding additional ETL processes and external library dependencies.
It reduces the time of extracting data from external databases, improves learning performance, avoids incompatibility between external deep learning libraries and databases, and reduces development workload.
Smart Images

Figure CN118747175B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of databases and deep learning models, and in particular to a method, system, device and medium for driving a deep learning model based on a database. Background Art
[0002] Deep learning has achieved tremendous success in many fields, including computer vision, natural language processing, and speech recognition. Deep learning is typically run on specialized deep learning systems (such as TensorFlow and PyTorch). Deep learning tasks require large amounts of data, which is typically stored and managed by database management systems (DBMSs), with SQL databases predominant among them. Database management systems and deep learning systems are often viewed as separate domains. However, when applying deep learning, the two must collaborate to form a solution: Deep learning systems require an Extract-Transform-Load (ETL) process to extract data from the DBMS, and then use this data for deep learning model training and inference. However, this ETL process incurs additional development effort, and the data transfer process can result in performance losses.
[0003] To address these issues, the industry has proposed a new concept: "in-database deep learning." This involves extracting data directly from the database and executing deep learning training and inference tasks. Currently, the most popular in-database deep learning solution encapsulates deep learning functionality and registers it as database user-defined functions. These functions can then be called within SQL statements to gain deep learning capabilities. When the deep learning system needs to perform model training or inference, it extracts data from the database management system. However, the existing method of "deep learning in the database" still has certain drawbacks. It requires importing function definitions into the database. If these user-defined functions are written by the users themselves, then writing these functions is difficult and increases development work. If the function definitions are imported from ready-made database plug-ins, there may be SQL syntax compatibility issues between different databases. This method does not provide model storage function. The model trained in the database must be exported outside the database for storage and imported from outside the database when used for inference. In addition, the deep learning library in this method will be overly dependent on the user environment. The deep learning library referenced in the user-defined function is associated with the user environment. Therefore, if the user updates the deep learning library, the user-defined function written with the old deep learning library may report an error due to incompatibility of the deep learning library version. Summary of the Invention
[0004] The present invention aims to solve at least one of the technical problems existing in the prior art. To this end, the present invention proposes a method, system, device, and medium based on a database-driven deep learning model, which can solve the problems of existing deep learning methods in the database that cannot provide model storage and have low compatibility.
[0005] In a first aspect, an embodiment of the present invention provides a method for driving a deep learning model based on a database, which is applied to a system based on a database-driven deep learning model. The system includes a database and a deep learning library, wherein the database includes a model table and a relationship table; the model table is used to store the deep learning model, the relationship table is used to store model data, and the deep learning library is used to perform model training and model inference; the deep learning library is linked to the source program of the database and performs data interaction through an internal interface; the method includes:
[0006] Obtain a model execution statement from the model statement set, and obtain a corresponding syntax node according to the model execution statement;
[0007] Converting the syntax node into a model execution plan;
[0008] The deep learning library interacts with the model table and the relationship table through the internal interface to execute the model execution plan and obtain a model processing result;
[0009] Adjust the deep learning model stored in the model table according to the model processing result.
[0010] In some embodiments of the present invention, the step of obtaining a model execution statement from a model statement set and obtaining a corresponding syntax node according to the model execution statement includes:
[0011] Expanding the model statement set to obtain a first execution statement, wherein the first execution statement is used to enable the database to obtain the deep learning model from a third-party file;
[0012] Obtain a second execution statement from the model statement set, execute the first execution statement, the second execution statement, or a combination of the first execution statement and the second execution statement, and obtain a syntax node corresponding to the deep learning model.
[0013] In some embodiments of the present invention, the step of converting the syntax node into a model execution plan includes:
[0014] Dividing the syntax node into a plurality of secondary nodes according to the type of the model execution statement;
[0015] Acquire the execution plan tree according to the secondary node;
[0016] The model execution plan is obtained according to the subordinate relationships and node functions of the secondary nodes in the execution plan tree.
[0017] In some embodiments of the present invention, the deep learning library interacts with the model table and the relationship table through the internal interface to execute the model execution plan and obtain the model processing result, including:
[0018] Obtain an interface header file according to the deep learning model and the model data;
[0019] The secondary node is mobilized to obtain the corresponding deep learning model and the model data and transmit them to the deep learning library through the interface header file. The deep learning library executes the model execution plan according to the deep learning model and the model data to obtain the model processing result.
[0020] In some embodiments of the present invention, the step of obtaining an interface header file based on the deep learning model and the model data includes:
[0021] Establishing a first mapping type according to the type of the model data in the relationship table, wherein the first mapping type is capable of mapping the model data to a type defined by the deep learning library;
[0022] Obtaining, according to the deep learning model and the model data, a first structure that can be called by the deep learning library;
[0023] Obtaining a first function executable by the deep learning library according to the execution steps of the model execution plan;
[0024] Encapsulating the first mapping type, the first structure, and the first function into an interface header file, and packaging the code for implementing the interface header file based on the deep learning library into a dynamic library;
[0025] The dynamic library is linked to the source program of the database.
[0026] In some embodiments of the present invention, when the model execution plan includes the model training, the step of mobilizing the secondary node to obtain the corresponding deep learning model and the model data and transmitting them to the deep learning library through the interface header file, and the deep learning library executing the model execution plan according to the deep learning model and the model data to obtain the model processing result includes:
[0027] The database executes a first node in the secondary nodes, scans and obtains the model data corresponding to the model execution plan from the relationship table, and temporarily stores the model data in a second node;
[0028] The database executes the third node in the secondary node, obtains the first model corresponding to the model execution plan from the model table, and transmits the first model to the deep learning library through the interface header file;
[0029] The database calls the deep learning library to execute the fourth node in the secondary node, and performs the model training according to the first model and the model data to obtain a second model;
[0030] The database executes the fifth node, calls the deep learning library through the interface header file, serializes the second model and stores it in the model table.
[0031] In some embodiments of the present invention, when the model execution plan includes the model inference, the step of mobilizing the secondary node to obtain the corresponding deep learning model and the model data and transmitting them to the deep learning library through the interface header file, and the deep learning library executing the model execution plan according to the deep learning model and the model data to obtain the model processing result, further includes:
[0032] The database calls the inference function implemented by the deep learning library through the interface header file according to the execution function of the sixth node in the secondary node;
[0033] The database calls the deep learning library and uses the model data as inference input data of the third model, executes the inference function, and obtains an inference data result;
[0034] The deep learning library transmits the inference data results to the database.
[0035] In a second aspect, an embodiment of the present invention discloses a system based on a database-driven deep learning model, the system comprising a database and a deep learning library, the database comprising a model table and a relationship table; the model table is used to store the deep learning model, the relationship table is used to store the model data, and the deep learning library is used to perform model training and model reasoning; the deep learning library is linked into the source program of the database and performs data interaction through an internal interface; the system is used to execute the method based on a database-driven deep learning model described in the embodiment of the above aspect.
[0036] In a third aspect, an embodiment of the present invention provides a computer device comprising a memory and a processor, wherein the memory is used to store at least one program, and the processor is used to load the at least one program to execute the method based on database-driven deep learning model described in the embodiment of the above aspect.
[0037] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium storing a program executable by a processor, wherein the program executable by the processor is used to execute the method based on a database-driven deep learning model as described in the above-mentioned embodiment when executed by the processor.
[0038] The method based on database-driven deep learning model according to an embodiment of the present invention has at least the following beneficial effects: the method based on database-driven deep learning model provided by an embodiment of the present invention sets a model table in the database to store the corresponding deep learning model, so that the user can call the model directly in the database through the database's SQL statement without the need for an additional ETL process, thereby reducing the time for extracting data from the external database and improving the learning performance; at the same time, by encapsulating and linking the deep learning library into the database source program, the incompatibility between the external deep learning library and the database is avoided, and the user does not need to write the logic of the deep learning task through user-defined functions, thereby reducing the development work. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 This is a flowchart of a method for driving a deep learning model based on a database according to an embodiment of the present invention;
[0040] Figure 2 is a schematic diagram of a system based on a database-driven deep learning model provided by one embodiment of the present invention;
[0041] Figure 3 This is a diagram of an execution architecture of a method based on a database-driven deep learning model provided by one embodiment of the present invention;
[0042] Figure 4 This is a schematic diagram of syntax nodes of a method based on a database-driven deep learning model provided by one embodiment of the present invention;
[0043] Figure 5 This is a schematic diagram of secondary nodes of a method based on database-driven deep learning model provided by one embodiment of the present invention;
[0044] Figure 6 It is a structural diagram of a computer device provided by another embodiment of the present invention. DETAILED DESCRIPTION
[0045] The following describes embodiments of the present invention in detail. Examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended only to explain the present invention and are not to be construed as limiting the present invention.
[0046] In the description of the present invention, it should be understood that descriptions involving orientations, such as up, down, front, back, left, right, etc., indicating orientations or positional relationships, are based on the orientations or positional relationships shown in the accompanying drawings. They are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation. Therefore, they cannot be understood as limitations on the present invention.
[0047] In the description of the present invention, "several" means one or more, "many" means more than two, "greater than," "less than," and "exceed" are understood to exclude the number itself, while "above," "below," and "within" are understood to include the number itself. The use of "first" and "second" in the description is solely for the purpose of distinguishing technical features and should not be construed as indicating or implying relative importance, implicitly specifying the number of the indicated technical features, or implicitly specifying the order of the indicated technical features.
[0048] In the description of the present invention, unless otherwise clearly defined, terms such as setting, installing, and connecting should be understood in a broad sense, and technicians in the relevant technical field can reasonably determine the specific meanings of the above terms in the present invention based on the specific content of the technical solution.
[0049] The method based on database-driven deep learning model provided by an embodiment of the present invention sets a model table in the database to store the corresponding deep learning model, so that users can call the model directly in the database through the database's SQL statement without the need for an additional ETL process, thereby reducing the time for extracting data from the external database and improving the learning performance; at the same time, by encapsulating and linking the deep learning library into the database source program, the incompatibility between the external deep learning library and the database is avoided, and users do not need to write the logic of the deep learning task through user-defined functions, thereby reducing development work.
[0050] The concepts involved in the present invention are explained below:
[0051] ETL process: ETL is a combination of three processes: Extract, Transform, and Load. It is mainly used to extract data from the source system and load it into the target system after a series of transformations.
[0052] SQL: (Structured Query Language) is a standard programming language for managing and operating relational database management systems. It is widely used to perform various operations such as querying, updating, inserting, and deleting data in the database.
[0053] openGauss: An open-source relational database management system, optimized and improved based on PostgreSQL, designed to provide high-performance, high-reliability, and high-security database services.
[0054] Model training: This refers to using a labeled dataset to adjust model parameters so that the model can accurately classify or predict the data;
[0055] Model inference: refers to using the trained model to predict or classify new data;
[0056] CPU:Centra l Processing Un it, central processing unit;
[0057] NPU: Neural Processing Unit, neural network processor;
[0058] The control method of the embodiment of the present invention is further described below based on the accompanying drawings.
[0059] Reference Figures 1 and 2 , Figure 1 A flowchart of a method for driving a deep learning model based on a database is provided in an embodiment of the present invention. Figure 2 This is a schematic diagram of a system based on a database-driven deep learning model provided by an embodiment of the present invention. The method is applied to the system based on a database-driven deep learning model. The system includes a database and a deep learning library. The database includes a model table and a relationship table. The model table is used to store the deep learning model, the relationship table is used to store the model data, and the deep learning library is used to perform model training and model inference. The deep learning library is linked to the source program of the database and performs data interaction through an internal interface. The method specifically includes but is not limited to the following steps:
[0060] Step S100, obtaining a model execution statement from a model statement set, and obtaining a corresponding syntax node according to the model execution statement;
[0061] Step S200, converting the syntax node into a model execution plan;
[0062] Step S300: The deep learning library interacts with the model table and the relationship table through the internal interface to execute the model execution plan and obtain the model processing result;
[0063] Step S400: Adjust the deep learning model stored in the model table according to the model processing result.
[0064] It should be noted that the database-driven deep learning model method and system based on the above-mentioned method embodiment allows users to store deep learning models within the database, eliminating the need to export trained deep learning models to an external database and allowing them to be stored directly within the database. Furthermore, users can call models directly within the database using SQL statements, eliminating the need for an additional ETL process. This reduces the time it takes to extract data from external databases and improves learning performance. To store deep learning models, a model table is set up within the database. This model table is an OpenGauss system table whose relational table definition is hard-coded in the database source code and generated during database initialization. The following are some fields of the model table in the embodiment of the present invention, including: mode 1 name, of type NameData (actually a string), representing the name of the model; mode 1 type, of type text, representing the model type, used to store the name in deep learning model format; mode 1 data, of type bytea, representing model data. In the embodiment of the present invention, deep learning models are serialized into binary strings for storage. The database also includes relational data tables for storing model data. This data can be used to train deep learning models or to perform model inference using this data and a model. The database also includes a deep learning library, which can perform model training and model inference of deep learning models through preset deep learning computing devices, such as CPUs and NPUs. By placing the model table, relationship table, and deep learning library within the database, the embodiment of the present invention enables the training and inference processes of deep learning models to be called and executed using SQL statements, without the need for additional development work. The following describes the specific steps of a method for driving a deep learning model based on a database. In step S100, when performing related processing on a deep learning model, the user first needs to determine the requirements for the deep learning model in a task. The requirements include but are not limited to importing a deep learning model from an external system into a database; performing model training and model inference tasks using the deep learning model; and deleting the deep model stored in the model table. After the user determines the requirements, the user obtains the corresponding SQL statement based on the requirements and inputs it into the system's database. The database's SQL engine parses the input source SQL text statement into a series of syntax nodes through the SQL compiler. In step S200, the SQL engine organizes these syntax nodes into a syntax tree. After the syntax tree is processed by the SQL engine, a model execution plan is obtained. The model execution plan is a set of operator nodes organized into a tree. The execution logic of the model execution plan is driven from top to bottom starting from the root node, the results of each node are returned from bottom to top, and finally the root node returns the result of the entire model execution plan.In step S300, after obtaining the execution plan, the deep learning library can execute the model execution plan. In the embodiment of the present invention, the deep learning library is not directly linked to the source program of the database, but rather implements the interaction between the database and the deep learning library through an independent internal interface. This setting enables the deep learning library to directly call the model and data in the database, while also avoiding conflicts and errors caused by the same symbol definitions in the deep learning library and the database during compilation. Furthermore, since the internal interface is independent of the database, the deep learning library can use any type of deep learning backend to call the interface to execute the model execution plan without being restricted by different deep learning backend environments. This allows users to use different deep learning libraries to complete deep learning calculations based on different hardware facilities. In step S400, after the deep learning library executes the model execution plan, the models stored in the model table may undergo certain changes. For example, the model execution plan for importing a deep model from the outside, the model execution plan for deleting a model, or the execution plan for model training will change the deep learning model stored in the model table (adding a new model, deleting a model in the table, or training a model in the table as a new model). Therefore, it is necessary to adjust the model stored in the model table based on the specific model execution plan.
[0065] Furthermore, the embodiment of the present invention also packages and encapsulates the deep learning library and links it into the database source program. The scheduling process of the deep learning model can be executed only based on steps S100 to S400 of the above-mentioned embodiment, without the need for additional links to external deep learning libraries, eliminating the dependence on external deep learning libraries, and users do not need to write the logic of deep learning tasks through user-defined functions, thereby reducing development work.
[0066] Reference Figures 3 and 4 In some embodiments of the present invention, the steps of obtaining a model execution statement from a model statement set and obtaining a corresponding syntax node according to the model execution statement include:
[0067] Step S110: Expand the model statement set to obtain a first execution statement, wherein the first execution statement is used to enable the database to obtain a deep learning model from a third-party file;
[0068] Step S120: Obtain a second execution statement from the model statement set, execute the first execution statement, the second execution statement, or a combination of the first execution statement and the second execution statement, and obtain a syntax node corresponding to the deep learning model.
[0069] It should be noted that if Figure 3As shown, in steps S110 to S120, before mobilizing the data in the database, the original SQL statement needs to be expanded (i.e., the first execution statement) according to the requirements of the deep learning model drive, and then combined with the existing SQL statements in the database (i.e., the second execution statement) to form the final execution statement, which is compiled by the SQL engine to drive the deep learning task. For example, in some embodiments of the present invention, the SQL statements involved include:
[0070] CREATE MODEL[mode l-name]FROM[mode l-path]······(1)
[0071] CREATE MODEL[mode l-name]FROM[mode l-path]FEATURES[features-co l umn]TARGET[target-co l umn]FROM[source-tab le]······(2)
[0072] CREATE MODEL[mode l-name]USING[mode l-name]FEATURES[features-co lumn]TARGET[target-co l umn]FROM[source-tab le]······(3)
[0073] PREDICT BY[mode l-name](FEATURES[features-co l umn])FROM[source-tab le](4)
[0074] DROP MODEL[mode l-name]······(5)
[0075] Statement (1) reads the model from the local file system using "mode l-path" as the path, names the model "mode l-name" and saves it to the model table, corresponding to Figure 4 In the “Import model from local file -> Model storage”; statement (2) reads the model from the local file system with “model l-path” as the path, and then reads the data from the “source-table” relational table, and trains the model with the column named “features-co l umn” as the feature and the column named “target-co l umn” as the label. The trained model is named “model l-name” and saved to the model table, corresponding to Figure 4In the "Import model from local file -> Model training -> Model storage"; statement (3) will read the model named "model l-name" from the model table, and then read the data from the "source-table le" relational table, using the column named "features-co l umn" in the table as features and the column named "target-co l umn" as labels to train the model, and then save the newly trained model to the model table, corresponding to Figure 4 In the "Read model from model table -> model training -> model storage" statement (4) will read the model named "model l-name" from the model table, and then read the column named "features-co l umn" from "source-table le" as the feature for model inference, and then return the inference result, corresponding to Figure 4 "Read model from model table->model inference"; statement (5) will find the model named "model l-name" from the model table and delete it from the model table, corresponding to Figure 4 "Delete model". In the embodiment of the above statement, the database does not include the SQL statements (1) and (2) related to "importing model from local file", that is, the original database does not support the function of "importing model from local file", so the new SQL statement can be added to the database by expanding the model statement set to achieve the corresponding function; it can be understood that the functions added by expansion are not limited to the above-mentioned "importing model from local file" function, but also include any processing logic that drives the deep learning model. Further, in order to process the above statement, the SQL statement needs to be converted into a syntax node through the SQL engine. For model creation and training statements, the compiler will generate a CreateDLMode lStmt node when processing the statement; for model inference statements, the compiler will generate a Pred ictBy node; for model deletion statements, the compiler will generate a Drop node. These nodes record the information of the input statement and are used for subsequent processing. This step is equivalent to converting the SQL statement string into a C / C++ structure, which contains all the necessary information.
[0076] Reference Figure 5 In some embodiments of the present invention, the step of converting a syntax node into a model execution plan includes:
[0077] Step S210 , dividing the syntax node into several secondary nodes according to the type of the model execution statement;
[0078] Step S220, obtaining an execution plan tree according to the secondary node;
[0079] Step S230 , obtaining a model execution plan according to the subordinate relationships and node functions of the secondary nodes in the execution plan tree.
[0080] It should be noted that after the SQL engine converts the SQL statement into a syntax node, it will continue to convert the syntax node into an execution plan tree according to the execution information contained inside, and obtain the model execution method according to the execution plan tree. Each execution plan tree includes several secondary nodes. When the execution plan tree includes only one secondary node, the tree only needs to execute one step; when the execution plan tree includes multiple secondary nodes, the tree forms a model execution plan based on the subordinate relationship of the secondary nodes and the functions that the secondary nodes can achieve, so as to facilitate direct execution by the deep learning library. For example, as shown in the figure, for model creation and training, the CreateDLMode lStmt node generated in the above-mentioned embodiment will be expanded into an execution tree. For scenarios where no training is required and only the model is imported, the execution tree has only one StoreMode l node. At this time, when executing, the StoreMode l node will directly save the imported model to the model table; and for scenarios where the model is read and trained, such as Figure 5 As shown, the vertex of the tree is StoreMode 1, which represents the storage of the model after training. The child node of this vertex is TrainDLMode 1, which represents the completion of deep learning model training calculation. The left child node Mater ia l and its child node Scan node will scan data from the relational table, and the obtained data will be materialized and temporarily stored by Mater ia l; if the model needs to be read from the model table, there is a right child node LoadMode 1 node that will read the model data from the model table. According to the execution order of the above nodes, the model execution plan is obtained. Furthermore, for model reasoning, a Pred ictBy node can be generated as an execution tree, and the expression is ultimately represented as a SQL function call inside the database; for model deletion, a Drop node can be generated. This node can use the model name and a flag indicating that the deleted object is the model. When executed, the tuple corresponding to the model name will be deleted from the model table.
[0081] In some embodiments of the present invention, the deep learning library interacts with the model table and the relationship table through an internal interface to execute the model execution plan and obtain the model processing result, including:
[0082] Step S310: Obtain an interface header file based on the deep learning model and model data;
[0083] Step S320: mobilize the secondary node to obtain the corresponding deep learning model and model data and transmit them to the deep learning library through the interface header file. The deep learning library executes the model execution plan according to the deep learning model and model data to obtain the model processing result.
[0084] It should be noted that in steps S310 to S320, the implementation of the StoreMode 1, TrainDLMode 1, LoadMode 1 nodes, and the db4ai_predict_using_d l_mode 1 function mentioned in the above embodiment requires interaction with the deep learning library. However, since the database source program and the deep learning library both define many symbols, and the definitions of these symbols are likely to conflict, simply linking the deep learning library into the database source program will result in a large number of symbol conflict errors during compilation and linking. Therefore, the present embodiment defines a header file as an interface, which will serve as an intermediate bridge for the interaction between the database source program and the deep learning library. Any symbols (types, variables, and functions, etc.) used by this interface do not depend on the database source code or the deep learning library, so that the database source program and the deep learning library cannot see each other's symbols and can only interact through the types, variables, and functions defined by the interface. Further, the deep learning library code of the above interface header file implemented by different hardware computing devices (CPU, NPU, etc.) is packaged into a dynamic library, which is named libd l backend.so in the embodiment of the present invention. Since the definition of this interface is independent of the deep learning library, different deep learning libraries can provide deep learning computing capabilities by implementing this interface. This allows users to use different deep learning libraries to complete deep learning calculations based on different hardware facilities. The embodiment of the present invention implements two different deep learning backends based on different hardware devices. These backends are all based on the deep learning library LibTorch. They include: a backend suitable for CPU devices; a backend that adds a certain type of NPU, such as the backend suitable for the Ascend 910b training card of the Ascend PyTorch adapter library. A configuration item 'd l_device' is added during configuration compilation, with a value of 'CPU' or 'Ascend910b'. During compilation, a corresponding backend is compiled according to this configuration item and named libd lbackend.so. This dynamic library is linked to the database program during linking.
[0085] In some embodiments of the present invention, the step of obtaining an interface header file according to the deep learning model and model data includes:
[0086] Step S311: establishing a first mapping type based on the type of the model data in the relationship table, wherein the first mapping type can map the model data to a type defined by the deep learning library;
[0087] Step S312: Obtain a first structure that can be called by the deep learning library based on the deep learning model and model data;
[0088] Step S313: Obtain a first function executable by the deep learning library according to the execution steps of the model execution plan;
[0089] Step S314: encapsulate the first mapping type, the first structure, and the first function into an interface header file, and package the code for implementing the interface header file based on the deep learning library into a dynamic library;
[0090] Step S315: link the dynamic library to the source program of the database.
[0091] It should be noted that in steps S311 to S313, the embodiment of the present invention comprehensively defines the type of the interface header file. The contents of the interface header file include: the DataType enumeration type, which represents the type of tuple data. The data type in the relational table is mapped to this type, and then the DataType type is mapped to the type defined by the deep learning library, that is, the first mapping type; the Tensor structure, which represents the tensor required by the deep learning library, the DataSource structure, which represents the data set required for deep learning, and the DLMode l structure, which represents the deep learning model. The above three structures are the first structures. The interface header file also contains a function interface class, which includes: train function, which will perform model training and be called by TrainDLMode l node; pred ict function: this function will perform model inference and be used by db4ai_pred ict_using_d l_mode l function; loadDLMode l function: deserialize a character array into a deep learning model and be used by LoadMode l node; saveDLMode l function: serialize a deep learning model into a byte array and be used by StoreMode l node. The above four functions are the first function. In steps S314 to S315, the first mapping type, the first structure and the first function are encapsulated into an interface header file to interact with the deep learning backend. The interface header file defines the types and functions that are not related to the deep learning library, including data types, tensor data, deep learning models, serialization and deserialization functions, model training and inference functions. Reference Figure 5 In some embodiments of the present invention, when the model execution plan includes model training, the steps of mobilizing a secondary node to obtain the corresponding deep learning model and model data and transmitting them to the deep learning library through an interface header file, and the deep learning library executing the model execution plan according to the deep learning model and model data to obtain the model processing result include:
[0092] Step S321: The database executes the first node in the secondary node, scans the relationship table to obtain the model data corresponding to the model execution plan, and temporarily stores the model data in the second node;
[0093] Step S322: The database executes the third node in the secondary node, obtains the first model corresponding to the model execution plan from the model table, and transmits the first model to the deep learning library through the interface header file;
[0094] Step S323: The database calls the deep learning library to execute the fourth node in the secondary node, and performs model training according to the first model and model data to obtain a second model;
[0095] Step S324: The database executes the fifth node and stores the second model in the model table through the interface header file.
[0096] It should be noted that steps S321 to S324 describe the process of the database mobilizing the model execution plan during model training, such as Figure 5 As shown, model training is a multi-level node execution process. The direct model training process is as follows: the Scan node (i.e., the first node) scans and obtains the relationship table tuples and returns them to the Mater ia l node (i.e., the second node). The Mater ia l node temporarily stores the tuple array in memory and returns the data to the TrainDLMode l node (i.e., the fourth node). The LoadMode l node (i.e., the third node) reads the model (i.e., the untrained first model) from the model table based on the model name and returns it to the TrainDLMode l node. After obtaining the data and model, the TrainDLMode l node completes the model training calculation and returns the trained model (i.e., the second model) to the StoreMode l node. The StoreMode l node saves the model to the model table and ends the planned execution. This execution logic can ensure the stable execution of model training driven by the deep learning library and can store the trained model in the model table.
[0097] In some embodiments of the present invention, when the model execution plan includes model inference, mobilizing the secondary node to obtain the corresponding deep learning model and model data and transmitting them to the deep learning library through the interface header file, and the deep learning library executing the model execution plan according to the deep learning model and model data to obtain the model processing result, further includes:
[0098] Step S325: The database obtains the third model from the model table and the model data from the relationship table through the interface header file according to the execution function of the sixth node in the secondary node;
[0099] Step S326: The database calls the deep learning library and uses the model data as the inference input data of the third model, executes the inference function, and obtains the inference data result;
[0100] In step S327, the deep learning library transmits the inference data results to the database.
[0101] It should be noted that steps S325 to S327 introduce the process of the database mobilizing the model execution plan during model inference. The model inference process is the execution process of a single secondary node. The direct flow of model inference is as follows: the Pred ictBy node (i.e., the sixth node) generated by the above-mentioned embodiment is processed as an expression, and the expression is ultimately represented as an SQL function call within the database. In one embodiment of the present invention, the function is "db4ai_predict_us ing_d l_mode l". The parameters of the function are the model name and the data tuple. When the function is executed, the model is first read from the model table according to the model name, and then the data tuple is used as the model inference input, and the calculated result is used as the output.
[0102] In the second aspect, an embodiment of the present invention discloses a system based on a database-driven deep learning model, the system includes a database and a deep learning library, the database includes a model table and a relationship table; the model table is used to store the deep learning model, the relationship table is used to store the model data, and the deep learning library is used to perform model training and model reasoning; an internal interface is set between the database and the deep learning library; the system is used to execute the method based on the database-driven deep learning model of the embodiment of the above aspect.
[0103] The following is an overall implementation example based on a system driven by a database deep learning model. For example, a user would use the following statement to use the deep learning function in the database:
[0104] #Import the model from the outside and save it to the model table, named modell1:
[0105] CREATE MODEL mode l 1from "resnet18-cifar10-trained.pt";
[0106] #Import the model from the outside, use the column 'picture' in the relational table 'cifar10' as the feature and the column 'l abel' as the label for training, and then save it to the model table and name it model l2
[0107] CREATE MODEL mode l2 from"resnet18-cifar10-untrained.pt"FEATURESpicture TARGET l abe l FROM cifar10;
[0108] #Read model mode l 1 from the model table, use the column 'picture' in the relational table 'cifar10' as the feature and the column 'l abe l' as the label for training, then save it to the model table and name it mode l3
[0109] CREATE MODEL mode l3 USING mode l 1FEATURES picture TARGET l abe lFROM cifar10;
[0110] #Use the model in the model table for inference, and use the column 'picture' of the relational table 'cifar_10' as the inference input:
[0111] SELECT id,PREDICT BY mode l 1(FEATURES picture)as"PREDICT"FROMcifar10_test l im it 5;
[0112] SELECT id,PREDICT BY mode l2(FEATURES picture)as"PREDICT"FROMcifar10_test l imit 5;
[0113] SELECT id,PREDICT BY mode l3(FEATURES picture)as"PREDICT"FROMcifar10_test l imit 5;
[0114] #Delete the existing model in the model table:
[0115] DROP MODEL mode l 1;
[0116] DROP MODEL mode l2;
[0117] DROP MODEL mode l3;
[0118] The above-mentioned model statements and the functions they implement are implemented based on the SQL engine. The SQL engine converts the above-mentioned SQL statements into syntax nodes. Then, based on the functions of each syntax node, the syntax node of each statement is converted into one or more secondary nodes. Based on the secondary nodes or combinations of secondary nodes, a model execution plan that can be executed by the database is obtained. The deep learning library implements the interface header file according to the specified computing hardware (CPU or NPU) and is packaged as a dynamic library. The database calls the dynamic library through the interface header file and executes the model execution plan in the database to obtain the relevant results of model import, model training, model inference and model deletion, realizing the in-library drive of the deep learning model.
[0119] In a third aspect, an embodiment of the present invention discloses a computer device comprising a memory and a processor, wherein the memory is used to store at least one program, and the processor is used to load at least one program to execute the method based on a database-driven deep learning model of the embodiment of the above aspect.
[0120] like Figure 6 As shown, Figure 6 FIG. 1 is a structural diagram of a computer device provided by one embodiment of the present invention, wherein the computer device includes:
[0121] The processor 801 may be implemented using a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is configured to execute relevant programs to implement the technical solutions provided in the embodiments of the present application.
[0122] The memory 802 can be implemented in the form of a read-only memory (ROM), a static storage device, a dynamic storage device, or a random access memory (RAM). The memory 802 can store an operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 802 and is called by the processor 801 to execute the method of the embodiments of this application.
[0123] Input / output interface 803, used to implement information input and output;
[0124] Communication interface 804, used to implement communication interaction between the apparatus and other devices, which can be achieved through wired means (such as USB, network cable, etc.) or wireless means (such as mobile network, Wi-Fi, Bluetooth, etc.);
[0125] Bus 805 , which transmits information between various components of the device (e.g., processor 801 , memory 802 , input / output interface 803 , and communication interface 804 );
[0126] The processor 801 , the memory 802 , the input / output interface 803 and the communication interface 804 are connected to each other in communication within the device via a bus 805 .
[0127] In a fourth aspect, an embodiment of the present invention discloses a computer-readable storage medium, which stores a program executable by a processor. When the program executable by the processor is executed by the processor, it is used to execute the method based on a database-driven deep learning model of the embodiment of the above aspect.
[0128] The memory, as a non-transient computer-readable storage medium, can be used to store non-transient software programs and non-transient computer executable programs. In addition, the memory may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory optionally includes a memory remotely located relative to the processor, and these remote memories can be connected to the processor via a network. Examples of the above-mentioned networks include but are not limited to the Internet, an intranet, a local area network, a mobile communication network and a combination thereof. The device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and are located in one place, or may be distributed to multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0129] Those skilled in the art will appreciate that all or some of the steps and systems in the method disclosed above can be implemented as software, firmware, hardware, and appropriate combinations thereof. Some physical components or all physical components can be implemented as software executed by a processor, such as a central processing unit, a digital signal processor, or a microprocessor, or implemented as hardware, or implemented as an integrated circuit, such as an application-specific integrated circuit. Such software can be distributed on a computer-readable medium, and the computer-readable medium can include computer storage media (or non-transitory media) and communication media (or temporary media). As known to those skilled in the art, the term computer storage media is included in any method or technology for storing information (such as computer-readable instructions, data structures, program modules, or other data) and is volatile and non-volatile, removable, and non-removable. Computer storage media includes, but is not limited to, RAM, ROM, EEPROM, flash memory, or other memory technology, CD-ROM, digital versatile disks (DVD), or other optical disk storage, magnetic cassettes, magnetic tapes, disk storage, or other magnetic storage devices, or any other medium that can be used to store desired information and can be accessed by a computer. Furthermore, as is well known to those skilled in the art, communication media typically includes computer-readable instructions, data structures, program modules, or other data in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery media.
[0130] The above is a specific description of the preferred implementation of the present invention, but the present invention is not limited to the above implementation. Those skilled in the art can also make various equivalent modifications or substitutions under the shared conditions that do not violate the spirit of the present invention. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present invention.
Claims
1. A method based on database-driven deep learning model, characterized in that: A system for driving a deep learning model based on a database includes a database and a deep learning library. The database includes a model table and a relationship table. The model table is used to store the deep learning model, the relationship table is used to store model data, and the deep learning library is used to perform model training and model inference. The deep learning library is linked to the source program of the database and performs data interaction through an internal interface. The method includes: Obtain a model execution statement from the model statement set, and obtain a corresponding syntax node according to the model execution statement; Converting the syntax node into a model execution plan; Establishing a first mapping type according to the type of the model data in the relationship table, wherein the first mapping type is capable of mapping the model data to a type defined by the deep learning library; Obtaining, according to the deep learning model and the model data, a first structure that can be called by the deep learning library; Obtaining a first function executable by the deep learning library according to the execution steps of the model execution plan; Encapsulating the first mapping type, the first structure, and the first function into an interface header file, and packaging the code for implementing the interface header file based on the deep learning library into a dynamic library; Linking the dynamic library to the source program of the database; Mobilizing a secondary node to obtain the corresponding deep learning model and the model data and transmitting them to the deep learning library through the interface header file, wherein the deep learning library executes the model execution plan according to the deep learning model and the model data to obtain a model processing result; Adjust the deep learning model stored in the model table according to the model processing result.
2. The method according to claim 1, wherein: The step of obtaining a model execution statement from a model statement set and obtaining a corresponding syntax node according to the model execution statement includes: Expanding the model statement set to obtain a first execution statement, wherein the first execution statement is used to enable the database to obtain the deep learning model from a third-party file; Obtain a second execution statement from the model statement set, execute the first execution statement, the second execution statement, or a combination of the first execution statement and the second execution statement, and obtain a syntax node corresponding to the deep learning model.
3. The method according to claim 1, wherein: The step of converting the syntax node into a model execution plan includes: Dividing the syntax node into a plurality of secondary nodes according to the type of the model execution statement; Acquire the execution plan tree according to the secondary node; The model execution plan is obtained according to the subordinate relationships and node functions of the secondary nodes in the execution plan tree.
4. The method according to claim 3, wherein: When the model execution plan includes the model training, the step of mobilizing the secondary node to obtain the corresponding deep learning model and the model data and transmitting them to the deep learning library through the interface header file, and the deep learning library executing the model execution plan according to the deep learning model and the model data to obtain the model processing result includes: The database executes a first node in the secondary nodes, scans and obtains the model data corresponding to the model execution plan from the relationship table, and temporarily stores the model data in a second node; The database executes the third node in the secondary node, obtains the first model corresponding to the model execution plan from the model table, and transmits the first model to the deep learning library through the interface header file; The database calls the deep learning library to execute the fourth node in the secondary node, and performs the model training according to the first model and the model data to obtain a second model; The database executes the fifth node, calls the deep learning library through the interface header file, serializes the second model and stores it in the model table.
5. The method according to claim 3, wherein: When the model execution plan includes the model inference, the step of mobilizing the secondary node to obtain the corresponding deep learning model and the model data and transmitting them to the deep learning library through the interface header file, and the deep learning library executing the model execution plan according to the deep learning model and the model data to obtain the model processing result, further includes: The database calls the inference function implemented by the deep learning library through the interface header file according to the execution function of the sixth node in the secondary node; The database calls the deep learning library and uses the model data as inference input data of the third model, executes the inference function, and obtains an inference data result; The deep learning library transmits the inference data results to the database.
6. A system based on a database-driven deep learning model, characterized in that: The system includes a database and a deep learning library, wherein the database includes a model table and a relationship table; the model table is used to store deep learning models, the relationship table is used to store model data, and the deep learning library is used to perform model training and model inference; the deep learning library is linked to the source program of the database and performs data interaction through an internal interface; The system is used to execute the method based on database-driven deep learning model described in any one of claims 1-5.
7. A computer device, characterized in that: It includes a memory and a processor, the memory is used to store at least one program, and the processor is used to load the at least one program to execute the method based on database-driven deep learning model according to any one of claims 1 to 5.
8. A computer-readable storage medium storing a program executable by a processor, characterized in that: The processor-executable program is used to execute the method based on a database-driven deep learning model as described in any one of claims 1 to 5 when executed by the processor.
Citation Information
Patent Citations
Zookeeper-based multi-source data wide area access system and method
CN111552737A