Method, system and device for driving deep learning model based on database and medium

By setting up model tables and relational tables in the database, combined with the internal interface of the deep learning library, the problem of model storage and compatibility of deep learning methods in the database is solved, and the direct storage and call of the deep learning model is realized, which improves the learning performance and reduces the cost. reduce the development workload.

CN118747175AActive Publication Date: 2024-10-08SHENZHEN TECH UNIV

Patent Information

Application Number
CN202410753082.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-12
Publication Date
2024-10-08
Estimated Expiration
2044-06-12

AI Technical Summary

Technical Problem

Existing in-database deep learning methods cannot provide model storage functions, and there are compatibility issues, making it difficult to write user-defined functions and causing incompatible versions.

Method used

By setting up model tables and relationship tables in the database, the deep learning library is linked to the database source program and uses internal interfaces for data interaction to achieve model storage and training inference, avoiding incompatibility between the external deep learning library and the database and reducing development work. .

Benefits of technology

It realizes the direct storage and calling of deep learning models in the database, reduces the ETL process, improves learning performance, and reduces development workload.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118747175A_ABST
    Figure CN118747175A_ABST
Patent Text Reader

Abstract

The invention provides a method, system and device for driving a deep learning model based on a database and a medium, the system comprises the database and a deep learning library, and the database comprises a model table and a relation table; the deep learning library is linked into a source program of the database and performs data interaction through an internal interface; the method comprises the steps of obtaining a model execution statement and obtaining a corresponding grammar node according to the model execution statement; converting the syntax node into an execution plan; the deep learning library interactively executes the model execution plan with the model table and the relation table to obtain a model processing result; and adjusting the model table according to a model processing result. According to the embodiment of the invention, the model table is set in the database to store the corresponding deep learning model, and the deep learning library is encapsulated and linked into the database source program, so that a user can directly call the model in the database through the SQL statement of the database, and the overhead of extracting database system data by an external deep learning framework is avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of database and deep learning model, 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 great success in many fields, including computer vision, natural language processing, and speech recognition. Deep learning is usually run on specialized deep learning systems (such as TensorFlow and PyTorch), and deep learning tasks require a large amount of data. The storage and management of this data is usually the responsibility of the database management system, and SQL databases dominate the database management system. Usually, database management systems and deep learning systems are regarded as two independent fields. However, when applying deep learning, the two need to work together to form a solution: the deep learning system requires an ETL (Extract-Transform-Load) process to extract data from the database management system, and then use the extracted data for deep learning model training and reasoning. However, this ETL process will bring additional development work and the data transmission process will cause performance loss.

[0003] To solve the above problems, the industry has proposed a new concept: "deep learning in the database", which is to directly extract data inside the database and perform deep learning training and reasoning tasks. The most mainstream deep learning solution in the database is to encapsulate the deep learning function and register it as a database user-defined function, so that these user-defined functions can be called in SQL statements to obtain deep learning capabilities. When the deep learning system needs to perform model training or reasoning, it needs to extract data from the database management system. However, the existing method "deep learning in the database" still has certain drawbacks. It is necessary to import function definitions into the database. If these user-defined functions are written by 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 reasoning. 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 the existing deep learning method in the database that cannot provide model storage and has 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, wherein 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 the model data, and the deep learning library is used to perform model training and model reasoning; 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] Acquire a model execution statement from the model statement set, and acquire a corresponding syntax node according to the model execution statement;

[0007] Convert 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] According to the model processing result, adjust the deep learning model stored in the model table.

[0010] In some embodiments of the present invention, the step of acquiring a model execution statement from a model statement set and acquiring 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] Acquire 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 the step of obtaining the model processing result includes:

[0018] According to the deep learning model and the model data, obtaining an interface header file;

[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 according to the deep learning model and the model data includes:

[0021] According to the type of the model data in the relationship table, a first mapping type is established, wherein the first mapping type can map the model data to a type defined by the deep learning library;

[0022] According to the deep learning model and the model data, obtaining a first structure that can be called by the deep learning library;

[0023] According to the execution steps of the model execution plan, obtaining a first function executable by the deep learning library;

[0024] 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;

[0025] The dynamic library is linked into 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 reasoning, the 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, the deep learning library executing the model execution plan according to the deep learning model and the model data, and obtaining the model processing result, also 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 to use the model data as the inference input data of the third model, executes the inference function, and obtains the inference data result;

[0034] The deep learning library transmits the inference data results to the database.

[0035] In the 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 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 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 a 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, which stores a program executable by a processor, and is characterized in that 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 the embodiment of the present invention has at least the following beneficial effects: the method based on database-driven deep learning model provided by the 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 SQL statement of the database 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 is a flowchart of a method based on database-driven deep learning model provided by 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 an embodiment of the present invention;

[0041] Figure 3 It is a diagram of an execution architecture of a method based on a database-driven deep learning model provided by an embodiment of the present invention;

[0042] Figure 4 It is a schematic diagram of syntax nodes of a method based on a database-driven deep learning model provided by an embodiment of the present invention;

[0043] Figure 5 It 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] Embodiments of the present invention are described in detail below, examples of which 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 only used to explain the present invention, and cannot be understood 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., and orientations or positional relationships indicated are based on the orientations or positional relationships shown in the accompanying drawings, and 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, and therefore should not be understood as a limitation on the present invention.

[0047] In the description of the present invention, "several" means one or more, "more" means more than two, "greater than", "less than", "exceed" etc. are understood as not including the number itself, and "above", "below", "within" etc. are understood as including the number itself. If there is a description of "first" or "second", it is only used for the purpose of distinguishing the technical features, and cannot be understood as indicating or implying the relative importance or implicitly indicating the number of the indicated technical features or implicitly indicating the order of the indicated technical features.

[0048] In the description of the present invention, unless otherwise clearly defined, terms such as setting, installing, connecting, etc. 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 the 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 SQL statement of the database 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.

[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 that is optimized and improved on the basis of PostgreSQL and aims to provide high-performance, high-reliability and high-security database services;

[0054] Model training: refers to using a labeled data set 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:Central Processing Unit, 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 Figure 1-2 , Figure 1 A flowchart of a method for driving a deep learning model based on a database provided in an embodiment of the present invention, Figure 2 The present invention 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 reasoning. 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 method and system based on the database-driven deep learning model of the above method embodiment allows users to store the deep learning model in the database, so that the trained deep learning model does not need to be output to an external database, but can be directly stored in the database. Further, the model can be directly called in the database through the SQL statement of the database, without the need for an additional ETL process, reducing the time for extracting data from the external database, so that the learning performance is improved. In order to store the deep learning model, a model table is set in the database. The model table is a system table of openGauss, and its relationship table definition is hard-coded in the database source code and generated when the database is initialized. The following are some fields of the model table of the embodiment of the present invention, including: mode l name, type NameData (actually a string), indicating the name of the model; mode ltype, type text, indicating the type of the model, used to save the name of the deep learning model format; mode ldata, type bytea, indicating model data, the embodiment of the present invention serializes the deep learning model into a binary string for storage. The database also includes a relational data table for storing model data, which can be used to train a deep learning model, or use these data and a model for model reasoning. The database also includes a deep learning library, which can perform model training and model reasoning of the deep learning model through a preset deep learning computing device, such as a CPU, NPU, etc. In the embodiment of the present invention, the model table, the relationship table and the deep learning library are all set inside the database, so that the training and reasoning process of the deep learning model only needs to be used to call and execute the corresponding functions using SQL statements, without additional development work. The following introduces the specific steps of the method based on the database-driven deep learning model. In step S100, when the user performs relevant processing of the deep learning model, he first needs to determine what the requirements for the deep learning model are in a task. The requirements include but are not limited to importing the deep learning model from an external system into the database; using the deep learning model to perform model training and model reasoning tasks; deleting the deep model stored in the model table; after the user determines the requirements, the corresponding SQL statement is obtained according to the requirements and input into the database of the system. The SQL engine of the database 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 group 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 an independent internal interface is used to realize the interaction between the database and the deep learning library. Such a setting enables the deep learning library to directly call the model and data in the database, and also avoids the conflict between the deep learning library and the same symbol definition in the database during compilation, causing an error. Further, 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, which enables users to use different deep learning libraries to complete deep learning calculations according to different hardware facilities. In step S400, after the deep learning library executes the model execution plan, the stored model in the model table may change to a certain extent. For example, the model execution plan of the deep model imported from the outside, the model execution plan of the model deleted, or the execution plan of the model training will change the deep learning model stored in the model table (adding a new model, deleting the model in the table, and training the 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, thereby eliminating the dependence on external deep learning libraries. Users also do not need to write the logic of deep learning tasks through user-defined functions, thereby reducing development work.

[0066] Reference Figure 3-4 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:

[0067] Step S110, expanding 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, obtaining a second execution statement from the model statement set, executing the first execution statement, the second execution statement, or a combination of the first execution statement and the second execution statement, to 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 statement 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 "Import model from local file -> Model storage"; statement (2) reads the model from the local file system using "model-path" as the path, then reads data from the "source-table" relational table, uses the column named "features-co l umn" in the table as features, and the column named "target-co l umn" as the label to train the model. The trained model is named "model-name" and saved in 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" relationship 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) reads the model named "model-name" from the model table, and then reads the column named "features-co l umn" from the "source-table" as the feature for model inference, and then returns the inference result, corresponding to Figure 4 "Read model from model table -> model inference"; statement (5) will search for 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 above statement. In the embodiment of the above statement, the database does not include 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 extending the model statement set to achieve the corresponding function; it can be understood that the function added by extension is not limited to the above-mentioned "importing model from local file" function, but also includes 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 reasoning 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 a number of 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 to the 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 according to 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; for scenarios where the model is read and trained, such as Figure 5 As shown, the vertex of the tree is StoreMode l, which represents the model after training is completed. The child node of the vertex is TrainDLMode l, which represents the completion of deep learning model training calculation. The left child node Material l and its child node Scan node will scan data from the relationship table, and the acquired data will be materialized and temporarily stored by Material l; if the model needs to be read from the model table, there is a right child node LoadMode l node to read the model data from the model table. According to the execution order of the above nodes, the model execution plan is obtained. Further, for model reasoning, a Pred ictBy node can be generated as an execution tree, and the expression is finally expressed as a SQL function call inside the database; for model deletion, a Drop node can be generated, which can use the model name and a flag indicating that the deleted object is a model, and the tuple corresponding to the model name will be deleted from the model table during execution.

[0081] 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 the step of obtaining the model processing result includes:

[0082] Step S310, obtaining an interface header file according to 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 step S310 to step S320, the implementation of the StoreMode 1, TrainDLMode 1, LoadMode 1 nodes and db4ai_predict_using_d l_mode 1 functions mentioned in the above-mentioned embodiments needs to interact with the deep learning library. However, since the database source program and the deep learning library 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 cause a large number of symbol conflict errors during compilation and linking. Therefore, the embodiment of this aspect 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 symbol (type, variable and function, etc.) used by this interface does 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-mentioned interface header file implemented by different hardware computing devices (CPU, NPU, etc.) is packaged as 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 according to different hardware facilities. The embodiment of the present invention implements two different deep learning backends according to different hardware devices. These backends are all based on the deep learning library LibTorch. They include: a backend suitable for CPU devices; a backend with a certain type of NPU added, 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 the 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 the model data includes:

[0086] Step S311, establishing a first mapping type according to 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, obtaining a first structure that can be called by the deep learning library according to the deep learning model and the model data;

[0088] Step S313, obtaining a first function executable by the deep learning library according to the execution steps of the model execution plan;

[0089] Step S314, 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;

[0090] Step S315, linking 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 content of the interface header file includes: DataType enumeration type, which represents the type of tuple data. The data type in the relationship 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; Tensor structure, representing the tensor required by the deep learning library, DataSource structure, representing the data set required for deep learning, DLMode l structure, representing the deep learning model. The above three structures are the first structures. The interface header file also contains a function interface class, which contains: 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 as an interface header file to interact with the deep learning backend. The interface header file defines 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. Refer to Figure 5 In some embodiments of the present invention, when the model execution plan includes model training, the steps of 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 include:

[0092] Step S321, the database executes the first node in the secondary node, scans and obtains the model data corresponding to the model execution plan from the relationship table, 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 the second model;

[0095] Step S324: the database executes the fifth node and stores the second model into the model table through the interface header file.

[0096] It should be noted that steps S321 to S324 introduce the process of the database mobilizing the model execution plan during model training, such as Figure 5 As shown in the figure, model training is an execution process of multiple nodes. The direct flow of model training is as follows: Scan node (i.e., the first node) scans and obtains the relationship table tuple and returns it to Mater ia l node (i.e., the second node). Mater ia l node temporarily stores the tuple array in memory and returns the data to TrainDLMode l node (i.e., the fourth node). LoadMode l (i.e., the third node) node reads the model (i.e., the untrained first model) from the model table according to the model name and returns it to TrainDLMode l node. TrainDLMode l node completes the calculation of model training after obtaining the data and model, and returns the trained model (i.e., the second model) to StoreMode l node, which saves the model to the model table and ends the execution of the plan. 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 reasoning, the secondary node is mobilized to obtain the corresponding deep learning model and model data and transmit them to the deep learning library through the interface header file, and the deep learning library executes the model execution plan according to the deep learning model and model data to obtain the model processing result, which also 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 to use the model data as the inference input data of the third model, executes the inference function, and obtains the inference data result;

[0100] 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 an 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 inside the database. In one embodiment of the present invention, the function is "db4ai_predict_using_d l_model l", and 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 will use the following statement to use the deep learning function in the database:

[0104] #Import the model from outside and save it into the model table, named mode l 1:

[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 mode 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 reasoning, and use the column 'picture' of the relational table 'cifar_10' as the reasoning 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 model statements and the functions they implement are implemented based on the SQL engine. The SQL engine converts the above SQL statements into syntax nodes, and then converts the syntax nodes of each statement into one or more secondary nodes according to the functions of the syntax nodes, and obtains the model execution plan that the database can execute according to the secondary nodes or the combination of secondary nodes. 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 reasoning and model deletion, and realizes 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 : is a structural diagram of a computer device provided by an embodiment of the present invention, the computer device includes:

[0121] The processor 801 may be implemented by a general-purpose central processing unit (CPU), a microprocessor, an application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used 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 by software or firmware, the relevant program codes are stored in the memory 802, and the processor 801 calls and executes the method of the embodiments of this application;

[0123] Input / output interface 803, used to implement information input and output;

[0124] The communication interface 804 is used to realize the communication interaction between the present apparatus and other devices. The communication can be realized through a wired manner (such as USB, network cable, etc.) or a wireless manner (such as mobile network, WI FI, Bluetooth, etc.);

[0125] A bus 805 that transmits information between the various components of the device (e.g., the processor 801, the memory 802, the input / output interface 803, and the 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] As a non-transient computer-readable storage medium, the memory 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 devices. In some embodiments, the memory may optionally include a memory remotely arranged relative to the processor, and these remote memories may 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 implemented to be located in one place, or may also 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] It will be appreciated by those skilled in the art that all or some of the steps and systems in the disclosed method above may be implemented as software, firmware, hardware and appropriate combinations thereof. Some physical components or all physical components may be implemented as software executed by a processor, such as a central processing unit, a digital signal processor or a microprocessor, or may be implemented as hardware, or may be implemented as an integrated circuit, such as an application specific integrated circuit. Such software may be distributed on a computer-readable medium, which may include a computer storage medium (or a non-transitory medium) and a communication medium (or a temporary medium). As known to those skilled in the art, the term computer storage medium includes volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information (such as computer-readable instructions, data structures, program modules or other data). Computer storage media include, but are not limited to, RAM, ROM, EEPROM, flash memory or other memory technologies, 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 may be used to store desired information and may be accessed by a computer. Furthermore, it is well known to those skilled in the art that communication media generally include 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-mentioned implementation mode. Technical personnel familiar with the field can also make various equivalent deformations or substitutions under the shared conditions without violating the spirit of the present invention. These equivalent deformations 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: The system is applied to 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; the deep learning library is linked to the source program of the database and performs data interaction through an internal interface; the method includes: Acquire a model execution statement from the model statement set, and acquire a corresponding syntax node according to the model execution statement; Convert the syntax node into a model execution plan; 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; According to the model processing result, adjust the deep learning model stored in the model table.

2. The method based on database-driven deep learning model according to claim 1, characterized in that: The step of acquiring a model execution statement from a model statement set and acquiring a corresponding syntax node according to the model execution statement comprises: 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; Acquire 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 based on database-driven deep learning model according to claim 1, characterized in that: 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 based on database-driven deep learning model according to claim 3, characterized in that: The deep learning library interacts with the model table and the relationship table through the internal interface to execute the model execution plan, and the step of obtaining the model processing result includes: According to the deep learning model and the model data, obtaining an interface header file; 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.

5. The method based on database-driven deep learning model according to claim 4, characterized in that: The step of obtaining an interface header file according to the deep learning model and the model data includes: According to the type of the model data in the relationship table, a first mapping type is established, wherein the first mapping type can map the model data to a type defined by the deep learning library; According to the deep learning model and the model data, obtaining a first structure that can be called by the deep learning library; According to the execution steps of the model execution plan, obtaining a first function executable by the deep learning library; 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; The dynamic library is linked into the source program of the database.

6. The method based on database-driven deep learning model according to claim 4, characterized in that: 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.

7. The method based on database-driven deep learning model according to claim 4, characterized in that: When the model execution plan includes the model reasoning, 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 to use the model data as the inference input data of the third model, executes the inference function, and obtains the inference data result; The deep learning library transmits the inference data results to the database.

8. 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 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 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 as described in any one of claims 1-7.

9. 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 a database-driven deep learning model as described in any one of claims 1-7.

10. 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 7 when executed by the processor.

Citation Information

Patent Citations

  • Zookeeper-based multi-source data wide area access system and method

    CN111552737A

  • Query-based database linkage distributed deep learning system, and method therefor

    US20240143611A1

Cited By

  • Deep learning model training method

    CN120409595A

  • Parameterized three-dimensional modeling method and system based on natural language and database driving

    CN120781574A