Operator implementation method, model inference method and database system
By storing the model feature table of machine learning operators in the database system and using database query statements to process the feature tables, the problem of large data flow and conversion overhead in the integration of machine learning models and database systems is solved, and efficient model execution optimization and cost reduction are achieved.
Patent Information
- Application Number
- CN202211313007.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-25
- Publication Date
- 2025-08-26
- Estimated Expiration
- 2042-10-25
AI Technical Summary
In the prior art, the integration of machine learning models and database systems has high overhead in data flow and data conversion, high development costs, and the database system cannot effectively utilize the execution optimization technology of machine learning models.
The model feature table of the machine learning operator is stored in the database system, and the input feature table and model feature table are directly called and processed through the database query statement to realize the operation logic of the machine learning operator and eliminate the need for the machine learning system architecture.
It realizes the tight integration of the machine learning model and the database system, reduces data flow and conversion overhead, reduces development costs, and uses the optimization technology of the database system to optimize the execution process.
Smart Images

Figure CN115905166B_ABST
Abstract
Description
Technical Field
[0001] One or more embodiments of this specification relate to the field of computer technology, and in particular, to an operator implementation method, a model reasoning method, and a database system. Background Art
[0002] Machine learning studies and builds specialized algorithms (or models) that enable computers to learn from data and statistical information, optimize model parameters, and ultimately use the models for prediction and inference. Current machine learning models are increasingly data-driven, requiring the machine learning systems used to manage them to collaborate with database systems at both the data and functional levels to create effective solutions in practical applications.
[0003] In one related technology, the database system and machine learning system are treated as two independent systems. The database system is responsible only for data management, while the machine learning system is responsible only for model organization, training, and inference. This means that the database system needs to export data to the machine learning framework for model training and inference. At the same time, the machine learning system also needs to forward the training and inference results of the machine learning model to the database system for storage. Therefore, a large amount of data flow and data conversion overhead is inevitably generated between the two systems. At the same time, to adapt to different machine learning models, different data flow and data conversion functions need to be developed multiple times, which incurs high development costs.
[0004] In another related technology, a user-defined function programming model is used to re-implement the training and inference algorithms of the corresponding machine learning model in the database system, migrating the machine learning code from the machine learning system to the database system. This solution essentially compiles the machine learning model into a binary file and integrates it into the database system kernel, while writing user-defined functions to call and load the machine learning model integrated into the database system. Therefore, although this solution avoids the overhead of data flow and data conversion, on the one hand, it is necessary to rewrite the corresponding user-defined function for each new machine learning model and compile it into the database system kernel. On the other hand, because the database system treats the binary file as a black box, it is impossible to estimate its execution cost, nor can it use its native query optimization technology to optimize its execution process. Summary of the Invention
[0005] In view of this, one or more embodiments of this specification provide an operator implementation method, a model reasoning method, and a database system. One or more embodiments of this specification provide the following technical solutions:
[0006] According to a first aspect of one or more embodiments of this specification, a method for implementing an operator is provided, which is applied to a database system. The database system stores a model feature table, which is obtained by converting model parameters and their values contained in a machine learning operator. The method includes:
[0007] Receive a query statement corresponding to the machine learning operator, where the query statement is used to implement the operation logic of the machine learning operator;
[0008] Execute the query statement to call and process the input feature table and the model feature table based on the operation logic; wherein the input feature table is obtained by converting the input parameters and values of the machine learning operator.
[0009] According to a second aspect of one or more embodiments of this specification, a model reasoning method is proposed, including:
[0010] Get input data for any machine learning operator in the machine learning model;
[0011] Providing the input data to any one of the machine learning operators for processing, wherein any one of the machine learning operators is implemented by the method described in any one of the first aspects above;
[0012] Obtain output data obtained by any of the machine learning operators to determine the inference result of the machine learning model based on the output data.
[0013] According to a third aspect of one or more embodiments of this specification, a database system is provided, including a database and a database management system;
[0014] The database is used to store a model feature table, which is obtained by converting model parameters and their values contained in the machine learning operator;
[0015] The database management system is used to execute the method as described in any one of the first aspects above to implement the machine learning operator corresponding to the model feature table.
[0016] According to a fourth aspect of one or more embodiments of this specification, an electronic device is provided, including:
[0017] A processor; a memory for storing processor-executable instructions; wherein the processor implements the steps of any method in the first aspect or the second aspect by running the executable instructions.
[0018] According to a fifth aspect of one or more embodiments of this specification, a computer-readable storage medium is provided, on which executable instructions are stored; wherein, when the instructions are executed by a processor, the steps of any method in the above-mentioned first aspect or second aspect are implemented.
[0019] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the specification and, together with the description, serve to explain the principles of the specification.
[0021] Figure 1 This is a schematic diagram of the architecture of a database system provided in this specification according to an exemplary embodiment.
[0022] Figure 2 This is a flowchart of a method for implementing a machine learning operator provided in this specification according to an exemplary embodiment.
[0023] Figure 3 This is a schematic diagram of a scenario for generating an input feature table of a convolutional layer operator according to an exemplary embodiment provided in this specification.
[0024] Figure 4 This is a schematic diagram of a scenario for generating a model feature table of a fully connected layer operator according to an exemplary embodiment provided in this specification.
[0025] Figure 5 This is a schematic diagram of a scenario for implementing a convolutional layer operator based on a database query statement according to an exemplary embodiment provided in this specification.
[0026] Figure 6 This is a schematic diagram of a scenario for implementing a fully connected layer operator based on a database query statement according to an exemplary embodiment provided in this specification.
[0027] Figure 7 This is a flowchart of a model reasoning method provided in this specification according to an exemplary embodiment.
[0028] Figure 8 It is a structural diagram of a device provided in this specification according to an exemplary embodiment.
[0029] Figure 9 This is a block diagram of a device for implementing a learning operator according to an exemplary embodiment of the present specification.
[0030] Figure 10 This is a block diagram of a model reasoning device provided in this specification according to an exemplary embodiment. DETAILED DESCRIPTION
[0031] Exemplary embodiments will be described in detail herein, with examples illustrated in the accompanying drawings. In the following description, when referring to the drawings, identical numerals in different figures represent identical or similar elements, unless otherwise indicated. The implementations described in the following exemplary embodiments are not intended to represent all implementations consistent with one or more embodiments of this specification. Rather, they are merely examples of apparatuses and methods consistent with certain aspects of one or more embodiments of this specification, as detailed in the appended claims.
[0032] It should be noted that in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the method may include more or fewer steps than those described in this specification. In addition, a single step described in this specification may be broken down into multiple steps for description in other embodiments, and multiple steps described in this specification may be combined into a single step for description in other embodiments.
[0033] Figure 1 This is a schematic diagram of the architecture of a database system provided by this specification according to an exemplary embodiment. Figure 1 As shown, the database system includes a database management system and a database managed by it, the database is used to store a model feature table, and the model feature table is obtained by converting the model parameters and their values contained in the machine learning operator; the database management system is used to execute the implementation method of any operator described below to implement the machine learning operator corresponding to the model feature table. Among them, the database management system (Database Management System, DBMS) is a large-scale software for manipulating and managing databases. It is a comprehensive management framework for establishing, using and maintaining databases. It manages and controls the database in a unified manner to ensure the security, integrity and functionality of the database. Specifically, users can access data in the database by entering SQL (Structured Query Language) statements in the DBMS, and database administrators can also perform database maintenance work by entering SQL statements in the DBMS. The database involved in the embodiment of this specification is specifically a relational database, which means that each database table in the database has a structured table structure, and the database management system involved in the embodiment of this specification is specifically a database management system for relational databases, and the implementation method of the machine learning operator involved in the embodiment of this specification is actually applied to Figure 1The database management system in the database management system maintains SQL script statements for implementing various machine learning operators. Specifically, each machine learning operator corresponds to a predefined database query statement. By executing the database query statement, the corresponding operation logic and function of the machine learning operator can be implemented.
[0034] Figure 1 The database shown stores a model feature table corresponding to each machine learning operator, wherein the model feature table corresponding to any machine learning operator is obtained by converting the model parameters and their values contained in any machine learning operator. For example, for a deep learning operator, it may contain various weights and bias parameters obtained through training. When the database stores these model parameters, they are no longer stored in the form of a tuple table (a two-dimensional array containing only sequential numbers and values) as in the related art, but are structured and stored in the database in a specifically organized table structure (i.e., a model feature table). At the same time, when a machine learning operator needs to be called later, it is no longer necessary to first read the model parameter tuple table and the model hyperparameters to establish the framework of the machine learning operator as in the traditional way, and then use the framework to perform the standard machine learning operator calculation process. Instead, the database query statement corresponding to the machine learning operator is directly executed to call the input feature table and the model feature table for processing, thereby realizing the operation logic and function corresponding to the machine learning operator, wherein the input feature table is converted from the input parameters and their values of the machine learning operator. Since database query statements are computer programming statements for database tables, they will be converted into calculations and operations on the database tables they call when executed. Therefore, by using a model feature table to store the model parameters of the machine learning operator and converting the input parameters and their values of the machine learning operator into an input feature table, it can be coordinated with the database query statement corresponding to the machine learning operator to realize the conversion of the traditional operation process of the machine learning operator into a standard operation on the relational database table in the database, thereby eliminating the architectural requirements of the machine learning system necessary for reconstructing the framework of the machine learning operator in the related technology, and completing the functions of the machine learning system only through the characteristics of the database system itself, realizing the close integration of the machine learning model and the database system. The following is a detailed introduction to the implementation method of the machine learning operator involved in the embodiments of this specification.
[0035] Figure 2 This is a flowchart of a method for implementing a machine learning operator according to an exemplary embodiment of the present specification. Figure 1 The database system shown in , wherein the database system stores a model feature table, which is obtained by converting the model parameters and their values contained in the machine learning operator; Figure 2 As shown, the method includes the following steps:
[0036] S202: Receive a query statement corresponding to the machine learning operator, where the query statement is used to implement the operation logic of the machine learning operator.
[0037] In the embodiments of this specification, a machine learning operator refers to a specific functional structure in a machine learning model, which can be regarded as a function, including a specific input structure and an output structure, for processing the input data or intermediate data of the machine learning model. At the same time, a machine learning model can also be regarded as a module with a certain function composed of one or more machine learning operators in a certain organizational pattern. Therefore, the parameters contained in the machine learning operator can also be called model parameters. The model parameters here specifically refer to the parameters (as parameters in the calculation formula) that a trained machine learning operator directly participates in the calculation when it is triggered by input data and performs processing calculations. Different from the hyperparameters of the machine learning operator, the hyperparameters are parameters used to determine the structure of the machine learning operator, so as to cooperate with the model parameters to help build the required machine learning operator and form a corresponding calculation mode.
[0038] The database system pre-stores a model feature table corresponding to the machine learning operator. The model feature table is obtained by converting the model parameters and their values contained in the machine learning operator. Specifically, it is obtained by converting the model parameter tuple table corresponding to the machine learning operator stored in the database system. The model parameter tuple table only stores the values of the model parameters contained in the machine learning operator in sequence. The column fields of the table only include a tuple number field and a model parameter value field in ascending order. Each table item in the table represents a model parameter. The value of any table item in the model parameter value field is used to describe the value of the model parameter corresponding to the table item. The value of any table item in the tuple number field is used to describe the position of the model parameter corresponding to the table item in the model parameter tuple table. The converted model feature table will have other structured fields in addition to the tuple number field and the model parameter value field. These fields are used to cooperate with the database query statement corresponding to the machine learning operator to implement the operation logic of the machine learning operator from the table operation level.
[0039] The database system can receive, recognize, and execute database query statements input by users or generated by scripts. When the database system receives a database query statement corresponding to any machine learning operator, it will execute the database query statement, thereby calling the model feature table corresponding to the machine learning operator to implement the operation logic of the machine learning operator.
[0040] S204: Execute the query statement to call and process the input feature table and the model feature table based on the operation logic; wherein the input feature table is obtained by converting the input parameters and values of the machine learning operator.
[0041] When executing a database query statement corresponding to a machine learning operator, the database system will call the input feature table and model feature table corresponding to the machine learning operator for processing, and store the output data of the machine learning operator generated after executing the database query statement in the form of an output feature table in the database system, wherein the model feature table has been pre-stored in the database system, and the input feature table can be directly obtained from the call source described in the database query statement, or also pre-stored in the database system (in this case, the call source is the database system). Of course, the input feature table does not necessarily need to be pre-generated and directly called by the database query statement, but can be temporarily generated and immediately called during the execution of the database query statement.
[0042] The input feature table corresponding to a machine learning operator is obtained by converting the input parameters and their values of the machine learning operator when the machine learning operator is called and used. Specifically, it is obtained by converting the input parameter tuple table corresponding to the machine learning operator. The input parameter tuple table only stores the input parameters and their values of the machine learning operator in sequence. The column fields of the table only include a tuple number field and an input parameter value field in ascending order. Each table item in the table represents an input parameter. The value of any table item in the input parameter value field is used to describe the value of the input parameter corresponding to the table item. The value of any table item in the tuple number field is used to describe the position of the input parameter corresponding to the table item in the input parameter tuple table. The converted model feature table will have other structured fields in addition to the tuple number field and the model parameter value field. These fields are used to cooperate with the database query statement corresponding to the machine learning operator to implement the operation logic of the machine learning operator from the table operation level.
[0043] It should be noted that although the model feature table is obtained by transforming the model parameter tuple table, and the input feature table is obtained by transforming the input parameter tuple table, this does not mean that the model feature table and the model parameter tuple table, as well as the input feature table and the input parameter tuple table are necessarily different in form. In fact, the model feature table relative to the model parameter tuple table, and the input feature table relative to the input parameter tuple table, generate new fields and assign values to each table item on the new fields. Therefore, even if the name, number and values of the fields are the same, since their connotations have changed, the model feature table and the model parameter tuple table, as well as the input feature table and the input parameter tuple table, still need to be regarded as different database tables. At the same time, the above two transformation processes are also indispensable, and we cannot assume that the above two transformation processes do not exist just because of the consistency in form after the transformation.
[0044] In an embodiment of the present specification, the database system stores an input parameter tuple table and an input feature mapping table corresponding to the machine learning operator, wherein the fields of the input parameter tuple table include an input parameter value field and an input parameter connection field, the fields of the input feature mapping table include an input parameter description field and an input parameter connection field, and the input feature table is obtained by executing a first connection statement on the input feature mapping table and the input parameter tuple table and connecting based on the values in the input parameter connection field; and / or,
[0045] The database system stores a model parameter tuple table and a model feature mapping table corresponding to the machine learning operator, wherein the fields of the model parameter tuple table include a model parameter value field and a model parameter connection field, and the fields of the model feature mapping table include a model parameter description field and a model parameter connection field. The model feature table is obtained by executing a second connection statement on the model feature mapping table and the model parameter tuple table and connecting based on the values in the model parameter connection field.
[0046] In the embodiments of the present specification, the input feature table is obtained by executing a first connection statement to connect the input feature mapping table and the input parameter tuple table, and / or the model feature table is obtained by executing a second connection statement to connect the model feature mapping table and the model parameter tuple table. The connection statement involved in the embodiments of the present specification refers to a basic statement in SQL, which is often used for multi-table join query, including left connection statement, right connection statement and inner connection statement. Its function is to connect the table items of two database tables according to certain rules to form a new database table. The new database table obtained by connection usually inherits the fields of the two database tables to be connected. Of course, it can also be output as a new database table with default fields after removing unnecessary column fields through select statement. It should be noted that the name of any field involved in the embodiments of the present specification does not represent the program field name in its actual application. The names of the fields defined in the embodiments of the present specification are only described from the level of functional relationship to facilitate the discussion of the processing process of various table operations based on fields.
[0047] In the embodiments of this specification, the input feature mapping table and the input parameter tuple table's input parameter connection field serve as a reference for connecting the two tables. Specifically, each entry in the input feature mapping table is connected to an entry in the input parameter tuple table that has the same value as that entry in the input parameter connection field to obtain the input feature table. Similarly, the model feature mapping table and the model parameter tuple table's model parameter connection field serve as a reference for connecting the two tables. Specifically, each entry in the model feature mapping table is connected to an entry in the model parameter tuple table that has the same value as that entry in the model parameter connection field to obtain the model feature table. The input feature table obtained by connection can omit the input parameter connection field, that is, the fields of the input feature table can include an input parameter value field and at least one input parameter description field. Similarly, the model feature table obtained by connection can also omit the model parameter connection field, that is, the fields of the model feature table can include a model parameter value field and at least one model parameter description field.
[0048] It should be noted that, for each item in the input tuple table involved in the embodiment of this specification, the value of the input parameter connection field is not repeated, and its value range is the same as the value range of the input parameter connection field in the input feature mapping table, which can ensure that each item in the input feature mapping table can match a certain item in the input parameter tuple table and be connected, that is, the total number of items in the input feature table is the same as the total number of items in the input feature mapping table, and the input feature mapping table is generated based on the hyperparameters of the machine learning operator, and is a hyperparameter factor for assisting in generating the input feature table; for each item in the model tuple table involved in the embodiment of this specification, the value of the model parameter connection field is not repeated, and its value range is the same as the value range of the model parameter connection field in the model feature mapping table, which can ensure that each item in the model feature mapping table can match a certain item in the model parameter tuple table and be connected, that is, the total number of items in the model feature table is the same as the total number of items in the model feature mapping table, and the model feature mapping table is generated based on the hyperparameters of the machine learning operator, and is a hyperparameter factor for assisting in generating the model feature table.
[0049] In one embodiment, the first connection statement and / or the second connection statement may also be executed independently of the query statement. Specifically, before executing the database query statement, the database system may pre-execute the first connection statement and store the generated input feature table in the database system, and pre-execute the second connection statement and store the generated model feature table in the database system.
[0050] In another embodiment, the first connection statement and / or the second connection statement may be included in the query statement. In an embodiment of the present specification, the first connection statement and / or the second connection statement may be nested in the database query statement, so that during the execution of the database query statement, the input parameter tuple table and / or the model parameter tuple table corresponding to the machine learning operator is called to execute the first connection statement and / or the second connection statement included in the database query statement, temporarily generate the corresponding input feature table and / or the model feature table, and then further call the temporarily generated corresponding input feature table and / or the model feature table to implement the operation logic of the machine learning operator. Since the database system already stores a pre-generated model feature table (here also the model feature table generated by the second connection statement), nesting the second connection statement in the database query statement here can make the temporarily generated model feature table be called first during the execution of the solution, thereby preventing the calculation error caused by the model update delay (the model parameters of the machine learning operator have been updated, but the model feature table stored in the database system has not been synchronized and updated in time). In an embodiment of the present specification, by including the first connection statement and / or the second connection statement in the database query statement, it is possible to avoid preparing the input feature table in advance. At the same time, the temporarily generated model feature table can also ensure that it uses the latest model parameters of the machine learning operator, thereby further ensuring the correctness of the operation.
[0051] As mentioned above, a machine learning model can be regarded as a combination of a series of machine learning operators, which often involves a multi-layer structure, that is, the output of a machine learning operator is the input of another machine learning operator. For example, in a typical deep learning model, it usually includes a pooling layer operator, a convolution layer operator, and a fully connected layer operator, and the input and output of each operator are connected, thereby forming a deep neural network structure. Therefore, in the embodiment of this specification, the input parameter tuple table can be an output feature table obtained by outputting another machine learning operator, and the output feature table generated by executing the query statement can also be used as an input parameter tuple table or input feature table of another machine learning operator. Specifically, other machine learning operators can also be independently implemented by a database system, and it is required that the input parameter tuple table of the machine learning operator has the same table structure as the output feature table obtained by outputting the other machine learning operator, and the output feature table obtained by outputting the machine learning operator has the same table structure as the input parameter tuple table or input feature table of the further machine learning operator. At the same time, the database system records the connection relationship of each machine learning operator. In this way, any machine learning model can be reproduced by the database system, realizing the storage mechanism and call mechanism of the machine learning model based on the database system.
[0052] The following takes the machine learning operator as a convolutional layer operator as an example to illustrate the execution process of the first connection statement involved in the embodiment of this specification.
[0053] In an embodiment of this specification, the machine learning operator includes a convolutional layer operator, and the input feature map is generated based on the input feature map size, convolution kernel size, padding length, and stride corresponding to the convolutional layer operator;
[0054] The input parameter description field in the input feature mapping table includes a submatrix sequence number field and a local sequence number field, and the input parameter connection field in the input feature mapping table includes a global sequence number field; wherein, the value of any table item in the submatrix sequence number field in the input feature mapping table is used to describe: the submatrix obtained by splitting the input feature map and performing convolution calculation with the convolution kernel to which the feature element corresponding to the any table item in the input feature map belongs, the value of the any table item in the local sequence number field is used to describe: the position of the feature element corresponding to the any table item in the submatrix to which it belongs in the input feature map, and the value of the any table item in the global sequence number field is used to describe: the position of the feature element corresponding to the any table item in the input feature map in the input feature map;
[0055] The input parameter connection field in the input parameter tuple table includes a tuple number field in increasing order, and the fields of the input feature table include a submatrix number field, a local number field and an input parameter value field;
[0056] The first connection statement is used to connect any table entry in the input parameter tuple table to a table entry in the input feature map table whose global sequence number is the same as the tuple sequence number of any table entry during execution.
[0057] Figure 3 This is a schematic diagram of a scenario for generating an input feature table of a convolution layer operator according to an exemplary embodiment of the present specification. Figure 3 As shown, assuming that the input parameter of the convolutional layer operator is the 4*4 input feature map shown in the figure, then the input feature map will be stored in the database system in the form of the input parameter tuple table in the figure in the initial state. It is not difficult to find that the fields of the input parameter tuple table include the tuple sequence number field and the input parameter value field, and the total of 16 table entries represent the 16 feature elements in the 4*4 input feature map, among which the column where the tuple sequence number field is located is an array that increases sequentially starting from 1, and the column where the input parameter value field is located records the values corresponding to the 16 feature elements arranged from left to right and from top to bottom in the input feature map.
[0058] In the embodiments of this specification, an input feature map table is also generated based on the hyperparameters corresponding to the convolution layer operator (including input feature map size, convolution kernel size, padding length and step size). Figure 3 For example, the input feature map size corresponding to the convolution layer operator is 4*4, the convolution layer size is 3*3, the padding length is 0, and the stride is 1. Therefore, the logic of the actual convolution can be simulated by the above hyperparameters to determine 4 sub-matrices from the input feature map, where the size of each sub-matrix is the same as the convolution kernel size, and the parameters in each sub-matrix are the calculation parameters that are multiplied by the convolution kernel pixel by pixel during the subsequent convolution operation. Taking the submatrix in the dotted box of the input feature map in the figure as an example, the submatrix is stored in the input feature mapping table with 9 entries marked with the submatrix sequence number 1, wherein any of the 9 entries represents a feature element in the submatrix, and the local sequence number of any entry records the relative position of the feature element corresponding to the entry in the submatrix (using numbers 1 to 9 to identify different local positions), and the global sequence number of any entry records the relative position of the feature element corresponding to the entry in the entire input feature map (using numbers 1 to 36 to identify different global positions). The value rules of these positions follow the principle of increasing in sequence from left to right and from top to bottom. For example, Figure 3 The global serial number map corresponding to the input feature map is also shown. This map reflects the global serial number value of each feature element in the input feature map. Therefore, the global serial number of each feature element in the submatrix within the dotted box of the input feature map can be directly determined. Similarly, the other three submatrices can also be recorded in the input feature map in the form of multiple entries with different submatrix serial numbers. It is not difficult to deduce that Figure 3 The input feature map shown contains a total of 4*9=36 entries.
[0059] In the embodiment of this specification, the first connection statement is used to connect any table item in the input parameter tuple table to the table item in the input feature map table whose global sequence number is the same as the tuple sequence number of any table item during execution. Figure 3For example, the tuple number of the first table item in the input parameter tuple table is 1, and it will be connected to the table item in the input feature map table with a local sequence number of 1. It is not difficult to infer that the input feature map table contains a total of 4 table items with a local sequence number of 1, so the first table item in the input parameter tuple table will be copied into 4 and connected to the corresponding 4 table items in the input feature map table. Similarly, each other table item in the input parameter tuple table will be connected to the corresponding 4 table items in the input feature map table, so that after the two tables are connected, an input feature table with unfiltered fields is generated. Then, through the select statement, only the sub-feature sequence number field, the local sequence number field and the input parameter value field are retained to obtain the final input feature table. It can be found that the input feature table stores the feature element values contained in each sub-matrix in units of sub-matrices. By executing the above first connection statement, the input feature map can be stored in the database system in the form of an input feature table, wherein the fields of the input feature table include the sub-matrix sequence number field, the local sequence number field and the input parameter value field. As an exemplary implementation, the first connection statement can be implemented by an inner connection statement, which can be written as:
[0060] GREATE TEMP TABLE input feature table (
[0061] SELECT submatrix number,
[0062] Local serial number,
[0063] Input parameter value
[0064] FROM input parameter tuple table INNER JOIN input feature map table
[0065] ON input parameter tuple table.tuple number = input feature map table.local number)".
[0066] The following takes the machine learning operator as a fully connected layer operator as an example to illustrate the execution process of the second connection statement involved in the embodiment of this specification.
[0067] In an embodiment of this specification, the machine learning operator includes a fully connected layer operator, and the model feature map is generated based on the input feature map size and the output feature map size corresponding to the fully connected layer operator;
[0068] The model parameter description field in the model feature mapping table includes a fully connected group sequence number field and a local sequence number field, and the model parameter connection field in the model feature mapping table includes a global sequence number field; wherein, the value of any table item in the fully connected group sequence number field in the model feature mapping table is used to describe: the fully connected group to which the weight parameter corresponding to any table item belongs, the value of any table item in the local sequence number field is used to describe: the position of the weight parameter corresponding to any table item in the fully connected group to which it belongs, and the value of any table item in the global sequence number field is used to describe: the position of the weight parameter corresponding to any table item in all weight parameters;
[0069] The model parameter connection field in the model parameter tuple table includes a tuple sequence number field and a model parameter value field in ascending order, and the field of the model feature table includes a full connection group sequence number field, a local sequence number field and a model parameter value field;
[0070] The second connection statement is used to connect any table item in the model parameter tuple table to the table item in the model feature mapping table whose global serial number is the same as the tuple serial number of any table item during execution.
[0071] Figure 4 This is a schematic diagram of a scenario for generating a model feature table of a fully connected layer operator according to an exemplary embodiment of this specification. Figure 4 As shown, assuming that the model parameters of the fully connected layer operator are the fully connected group set shown in the figure (containing a total of 36 weight parameters), then the fully connected group set will be stored in the database system in the form of the model parameter tuple table in the figure in the initial state. It is not difficult to find that the fields of the model parameter tuple table include the tuple sequence number field and the model parameter value field, and the total of 36 table entries represent the 36 weight parameters in the fully connected group set, among which the column where the tuple sequence number field is located is an array that increases sequentially starting from 1, and the column where the model parameter value field is located records the corresponding values of the 36 weight parameters contained in each fully connected group in the fully connected group set.
[0072] In the embodiment of this specification, a model feature map table is also generated based on the hyperparameters corresponding to the fully connected layer operator (including the input feature map size and the output feature map size). Figure 4For example, the input feature map size corresponding to the fully connected layer operator is 3*3, and the output feature map size is 2*2. Therefore, the logic of actually executing the fully connected layer operation can be simulated by the above hyperparameters. First, the fully connected group set is split into 2*2=4 fully connected groups, where the number of weight parameters contained in each fully connected group is the same as the number of feature elements contained in the input feature map, both 3*3=9. The parameters in each fully connected group are the calculation parameters that are multiplied by the input feature map pixel by pixel when performing the subsequent fully connected layer operation. Taking the fully connected group in the dotted box of the fully connected group set in the figure as an example, the fully connected group is stored in the model feature mapping table with 9 entries marked with the fully connected group number 1, wherein any of the 9 entries represents a weight parameter in the fully connected group, and the local serial number of any entry records the relative position of the weight parameter corresponding to the any entry within the fully connected group (using numbers 1 to 9 to identify different local positions), and the global serial number of any entry records the relative position of the corresponding feature element of the any entry in the entire fully connected group set (using numbers 1 to 36 to identify different global positions). The value rules of these positions follow the principle of increasing in sequence from left to right and from top to bottom. For example, Figure 4 The global serial number diagram corresponding to the fully connected group set is also shown. This diagram reflects the global serial number values of each weight parameter in the fully connected group set. Therefore, the global serial number of each weight parameter in the fully connected group within the dotted box of the fully connected group set can be directly determined. Similarly, the other three fully connected groups can also be recorded in the model feature mapping table in the form of multiple entries with different fully connected group serial numbers. It is not difficult to infer that Figure 3 The model feature mapping table shown contains a total of 4*9=36 entries.
[0073] In the embodiment of this specification, the second connection statement is used to connect any table item in the model parameter tuple table to the table item in the model feature mapping table whose global serial number is the same as the tuple serial number of any table item during execution. Figure 4For example, the tuple number of the first table item in the model parameter tuple table is 1, and it will be connected to the table item in the model feature mapping table whose local sequence number is also 1. It is not difficult to infer that the model feature mapping table contains a total of 1 table item with a local sequence number of 1, so the first table item in the model parameter tuple table will be connected to the corresponding 1 table item in the model feature mapping table. Similarly, each other table item in the model parameter tuple table will be connected to the corresponding 1 table item in the model feature mapping table, thereby generating a model feature table with unfiltered fields after the two tables are connected. Then, through the select statement, only the fully connected group sequence number field, the local sequence number field and the model parameter value field are retained to obtain the final model feature table. It can be found that the model feature table stores the weight parameter values contained in each fully connected group in units of fully connected groups. By executing the above second connection statement, it is possible to store the fully connected group set in the form of a model feature table in the database system, wherein the fields of the model feature table include the fully connected group sequence number field, the local sequence number field and the model parameter value field. As an exemplary implementation, the second connection statement can be implemented by an inner connection statement, which can be written as:
[0074] GREATE TEMP TABLE model feature table (
[0075] SELECT fully connected group number,
[0076] Local serial number,
[0077] Model parameter values
[0078] FROM model parameter tuple table INNER JOIN model feature mapping table
[0079] ON model parameter tuple table.tuple number = model feature mapping table.local number)".
[0080] In addition to the implementation method of the second connection statement mentioned above, the model feature table can also be generated directly on the basis of the model parameter tuple table by expanding the fields. Specifically, two new fields can be created for the model parameter tuple table, namely the fully connected group sequence number field and the local sequence number field, and if the value of any table item in the tuple sequence number is x, then the value of any table item in the fully connected group sequence number field is INT(x / w1), and the value of any table item in the local sequence number field is x%w2, where INT() represents rounding down and % represents the remainder. Finally, the select statement is used to select only the fully connected group sequence number field, the local sequence number field and the model parameter value field to obtain the final model feature table.
[0081] The following uses the machine learning operator as a convolutional layer operator to illustrate the implementation method of the machine learning operator involved in the embodiment of this specification. In the embodiment of this specification, the machine learning operator includes a convolutional layer operator, and the fields of the input feature table include a submatrix sequence number field, a local sequence number field, and an input parameter value field; wherein, the value of any table item in the submatrix sequence number field in the input feature table is used to describe: the submatrix obtained by splitting the input feature map for convolution calculation with the convolution kernel to which the feature element corresponding to any table item in the input feature map belongs, and the value of any table item in the local sequence number field is used to describe: the position of the feature element corresponding to any table item in the input feature map in the submatrix to which it belongs;
[0082] The fields of the model feature table include a convolution kernel sequence number field, a local sequence number field, and a model parameter value field; wherein the value of the convolution kernel sequence number field of any table entry in the model feature table is used to describe: the convolution kernel to which the feature element corresponding to any table entry belongs, and the value of the local sequence number field of any table entry is used to describe: the position of the feature element corresponding to any table entry in the convolution kernel to which it belongs;
[0083] The fields of the output feature table generated by executing the query statement include a convolution kernel number field, a submatrix number field, and an output parameter value field;
[0084] The calling and processing of the input feature table and the model feature table based on the operation logic includes: calculating each sub-matrix group table item with the same sub-matrix sequence number in the input feature table and each convolution kernel group table item with the same convolution kernel sequence number in the model feature table, and summing the products obtained by multiplying the input parameter value and the model parameter value of any sub-matrix group table item with the table item with the same local sequence number in any convolution kernel group table item as the output parameter value of the table item in the output feature table corresponding to the sub-matrix sequence number of any sub-matrix group table item and the convolution kernel sequence number of any convolution kernel group.
[0085] Figure 5 This is a schematic diagram of a scenario in which a convolutional layer operator is implemented based on a database query statement according to an exemplary embodiment of the present specification. Figure 5As shown, the 4*4 input feature map as the input parameter of the convolution layer operator can be converted into the form of a corresponding input feature table, for example, obtained by the conversion of the first connection statement in the aforementioned embodiment, and the two 3*3 convolution kernels as the model parameters of the convolution layer operator can be converted into the form of a corresponding model feature table. As shown in the model feature table in the figure, the fields of the model feature table include the convolution kernel sequence number field, the local sequence number field and the model parameter value field, and it contains a total of 2*3*3=18 table items, of which the 1st to 9th table items represent the convolution kernel in the upper part of the figure, and the 10th to 18th table items represent the convolution kernel in the lower part of the figure. Any entry in the model feature table represents a feature element in the convolution kernel. The value of the convolution kernel sequence number of any entry indicates which convolution kernel the feature element corresponding to the entry belongs to (different convolution kernels are identified by the numbers 1 or 2). The value of the local sequence number of any entry indicates the relative position of the feature element corresponding to the entry on the convolution kernel to which it belongs (different local positions are identified by the numbers 1 to 9). The model parameter value of any entry indicates the value of the feature element corresponding to the entry.
[0086] After the input feature table and the model feature table are prepared, the database query statement corresponding to the convolutional layer operator is executed to call and process the input feature table and the model feature table. Specifically, the table entries with the same submatrix sequence number in the input feature table are grouped as a group of submatrix group table entries, and the table entries with the same convolution kernel sequence number in the model feature table are grouped as a group of convolution kernel group table entries. This results in four groups of submatrix group table entries and two groups of convolution kernel group table entries. Each of the four groups of submatrix group table entries and each of the two groups of convolution kernel group table entries are then used for processing. Specifically, the processing process between any sub-matrix group table entry and any convolution group table entry is carried out in the following manner: the products obtained by multiplying the input parameter values and model parameter values of any sub-matrix group table entry and any convolution kernel group table entry with the same local serial number are summed respectively, and the summed result is used as the output parameter value of the table entry in the output feature table corresponding to the sub-matrix serial number of any sub-matrix group table entry and the convolution kernel serial number of any convolution kernel group. Taking the submatrix group table item with submatrix sequence number 1 and the convolution kernel group table item with convolution kernel sequence number 1 in the figure as an example, it can be found that each table item in the submatrix group table item can just match one table item in the convolution kernel group table item. For example, the first table item in the input feature table has the same local sequence number as the first table item in the model feature table. Therefore, the input parameter values and model parameter values contained in these two table items can be multiplied to obtain a product. Similarly, there are a total of 9 groups of paired table items. By summing the products obtained by multiplying the parameter values of each pair of table items, the output parameter value 2*3+1*1+3*1+5*1+1*5+3*1+5*0+7*1+4*2=38 obtained by processing the submatrix group table item and the convolution kernel group table item can be obtained. Then the output parameter value is written into the output parameter value field in the output feature table corresponding to the table item with submatrix sequence number 1 and convolution kernel sequence number 1.
[0087] like Figure 5 As shown, the fields of the output feature table finally obtained include a convolution kernel serial number field, a submatrix serial number field and an output parameter value field. Obviously, the output feature table can be used to characterize the output feature map obtained by the traditional convolution layer. Among them, any table item in the output feature table is used to characterize a feature element in the output feature map, the convolution kernel serial number of any table item is used to describe the output feature map to which the corresponding feature element belongs (using numbers 1 or 2 to identify different output feature maps), the submatrix serial number of any table item is used to describe the relative position of the corresponding feature element in the output feature map to which it belongs (using numbers 1 to 4 to identify different local positions), and the output eigenvalue of any table item is used to describe the value of the corresponding feature element. So far, the embodiment of this specification implements the operation logic of the convolution layer operator through operations between relational database tables, and the output feature map obtained is also represented in the form of a database table of the output feature table.
[0088] Optionally, the query statement includes a third connection statement for calling the input feature table and the model feature table, the third connection statement being used to connect the table items in the model feature table to the table items with the same local sequence number in the input feature table during execution to obtain a feature connection table, wherein the fields of the feature connection table include a submatrix sequence number field, a convolution kernel sequence number field, an input parameter value field, and a model parameter value field;
[0089] The query statement includes a multiplication statement and a corresponding summation statement for the feature connection table; wherein the multiplication statement is used to multiply the input parameter value of each table item in the feature connection table with the model parameter value during execution to obtain the product corresponding to each table item, and the summation statement is used to sum the products corresponding to the table items with the same submatrix sequence number and the same convolution kernel sequence number in the feature connection table during execution, as the output parameter value of the table item corresponding to the same submatrix sequence number and the same convolution kernel sequence number in the output feature table.
[0090] In the embodiment of this specification, the operation logic of the convolution layer operator can also be implemented by nesting the third connection statement, the multiplication statement and the summation statement in the query statement. Figure 5 As shown, the model feature table and the input feature table can first be connected using the third connection statement to obtain a feature connection table. The connection is based on connecting entries with the same local sequence number in the two tables. A select statement is then used to filter the required fields to obtain the feature connection table. It is important to note that during the connection process, each entry in the input feature table has two entries in the model feature table to connect to. In this case, the number of entries in the input feature table is expanded to meet the connection requirements. As shown in the figure, the fields in the feature connection table include the convolution kernel sequence number field, the submatrix sequence number field, the input parameter value field, and the model parameter value field. It has a total of 72 entries, twice the number of entries in the input feature table. After obtaining the feature connection table, a multiplication statement is further used to obtain the product corresponding to each table item in the feature connection table (directly multiplying the input parameter value with the model parameter value), and then a summation statement is used to sum the products corresponding to the table items with the same submatrix sequence number and the same convolution kernel sequence number. The summation result is used as the output parameter value of the table item corresponding to the same submatrix sequence number and the same convolution kernel sequence number in the output feature table. As an exemplary implementation method, the database query statement can be specifically implemented through an inner join statement, which can be written as:
[0091] GREATE TEMP TABLE output characteristic table (
[0092] SELECT convolution kernel number,
[0093] Submatrix number,
[0094] SUM(input feature table.input parameter value*model feature table.model parameter value)
[0095] FROM input feature table INNER JOIN model feature table
[0096] ON Input feature table. Local serial number = Model feature table. Local serial number
[0097] GROUP BY (convolution kernel number, sub-matrix number)".
[0098] The following describes the implementation method of the machine learning operator involved in the embodiment of this specification by taking the machine learning operator as a fully connected layer operator. In the embodiment of this specification, the machine learning operator includes a fully connected layer operator, and the fields of the input feature table include a local sequence number field and an input parameter value field in ascending order;
[0099] The fields of the model feature table include a fully connected group sequence number field, a local sequence number field, and a model parameter value field; wherein the value of any table item in the fully connected group sequence number field in the model feature mapping table is used to describe: the fully connected group to which the weight parameter corresponding to any table item belongs, and the value of any table item in the local sequence number field is used to describe: the position of the weight parameter corresponding to any table item in the fully connected group to which it belongs;
[0100] The fields of the output feature table generated by executing the query statement include a fully connected group sequence number field and an output parameter value field;
[0101] The calling and processing of the input feature table and the model feature table based on the operation logic includes: calculating each fully connected group table entry with the same fully connected group sequence number in the model feature table with the table entry in the input feature table, and summing the products obtained by multiplying the input parameter value and the model parameter value of any fully connected group table entry with the table entry with the same local sequence number in the input feature table as the output parameter value of the table entry in the output feature table corresponding to the fully connected group sequence number of any fully connected group table entry.
[0102] Figure 6 This is a schematic diagram of a scenario in which a fully connected layer operator is implemented based on a database query statement according to an exemplary embodiment of this specification. Figure 6As shown, the fully connected group set containing 36 weight parameters as the model parameters of the fully connected layer operator can be converted into the form of a corresponding input feature table, for example, obtained by converting the second connection statement in the aforementioned embodiment, and the 3*3 input feature map as the input parameter of the fully connected layer operator can be converted into the form of a corresponding input feature table. As shown in the input feature table in the figure, the fields of the input feature table include a local sequence number field and an input parameter value field, and it contains a total of 3*3=9 entries. Any table item in the input feature table represents a feature element in the input feature map, and the value of the local sequence number of any table item indicates the relative position of the feature element corresponding to any table item on the input feature map (using numbers 1 to 9 to identify different local positions), and the input parameter value of any table item indicates the value of the feature element corresponding to any table item.
[0103] After the input feature table and the model feature table are prepared, the database query statement corresponding to the fully connected layer operator will be executed to call and process the input feature table and the model feature table. Specifically, the table items with the same fully connected group sequence number in the model feature table are divided into a group of fully connected group table items as a whole, thereby obtaining 4 groups of fully connected group table items, and then each group of fully connected group table items in the 4 groups of fully connected group table items is used to process the input feature table. Specifically, the processing process between any fully connected group table item and the input feature table is based on the following method: the products obtained by multiplying the input parameter value and the model parameter value of any fully connected group table item with the table item with the same local sequence number in the input feature table are summed respectively, and the summed result is used as the output parameter value of the table item in the output feature table corresponding to the fully connected group sequence number of any fully connected group table item. Taking the input feature table and the fully connected group table item with the fully connected group number 1 in the figure as an example, it can be found that each table item in the input feature table can just match one table item in the fully connected group table item. For example, the first table item in the input feature table has the same local sequence number as the first table item in the model feature table. Therefore, the input parameter values and model parameter values contained in these two table items can be multiplied to obtain a product. Similarly, there are a total of 9 groups of paired table items. By summing the products obtained by multiplying the parameter values of each pair of table items, the output parameter value 2*5+1*1+3*3+5*4+1*7+3*1+5*0+7*3+4*2=79 obtained by processing the fully connected group table item and the input feature table can be obtained. Then the output parameter value is written into the output parameter value field in the output feature table corresponding to the table item with the fully connected group number 1.
[0104] like Figure 6As shown, the fields of the output feature table finally obtained include a fully connected group sequence number field and an output parameter value field. Obviously, the output feature table can be used to characterize the output feature map obtained by the traditional fully connected layer. Among them, any table item in the output feature table is used to characterize a feature element in the output feature map, and the fully connected group sequence number of any table item is used to describe the relative position of the corresponding feature element in its output feature map (using numbers 1 to 4 to identify different local positions), and the output feature value of any table item is used to describe the value of the corresponding feature element. So far, the embodiment of this specification implements the operation logic of the fully connected layer operator through operations between relational database tables, and the output feature map obtained is also represented in the form of a database table of the output feature table.
[0105] Optionally, the query statement includes a fourth connection statement for calling the input feature table and the model feature table, the fourth connection statement being used to connect, during execution, table entries in the input feature table to table entries with the same local sequence number in the model feature table to obtain a feature connection table, wherein the fields of the feature connection table include a full connection sequence number field, an input parameter value field, and a model parameter value field;
[0106] The query statement includes a multiplication statement and a corresponding summation statement for the feature connection table; wherein the multiplication statement is used to multiply the input parameter value of each table item in the feature connection table with the model parameter value during execution to obtain the product corresponding to each table item, and the summation statement is used to sum the products corresponding to the table items with the same fully connected group number in the feature connection table during execution as the output parameter value of the table item corresponding to the same fully connected group number in the output feature table.
[0107] In the embodiment of this specification, the operation logic of the fully connected layer operator can also be realized by nesting the fourth connection statement, the multiplication statement and the summation statement in the query statement. Figure 6As shown, the model feature table and the input feature table can first be connected using the fourth connection statement to obtain a feature connection table. The connection is based on connecting the entries with the same local sequence number in the two tables. At the same time, the required fields are filtered through the select statement to finally obtain the feature connection table. It should be noted that during the connection process, each entry in the model feature table is connected to an entry in the model feature table. From another perspective, each entry in the input feature table is copied four times to connect to the model feature table. As shown in the figure, it can be seen that the fields of the feature connection table include a fully connected group sequence number field, an input parameter value field, and a model parameter value field, and it contains a total of 36 entries, the same number of entries in the model feature table. After obtaining the feature connection table, a multiplication statement is further used to obtain the product corresponding to each entry in the feature connection table (by directly multiplying the input parameter value with the model parameter value). Then, a summation statement is used to sum the products corresponding to the entries with the same fully connected group sequence number. The resulting summation will serve as the output parameter value for the entry in the output feature table corresponding to the same fully connected group sequence number. As an exemplary implementation, the database query statement can be implemented by an inner join statement, which can be written as:
[0108] GREATE TEMP TABLE output characteristic table (
[0109] SELECT full connection group number,
[0110] SUM(input feature table.input parameter value*model feature table.model parameter value)
[0111] FROM input feature table INNER JOIN model feature table
[0112] ON Input feature table. Local serial number = Model feature table. Local serial number
[0113] GROUP BY fully connected group number)".
[0114] In addition to the machine learning operators mentioned in the above embodiments, other machine learning operators, such as deconvolution layer operators, pooling layer operators, activation layer operators, normalization layer operators, residual block operators (Residual Block), identity block operators (Indentity Block), dense block operators (Dense Block) and other deep learning operators can be implemented in the database system in the form of database query statements through the method described above.
[0115] The embodiments of this specification propose a method for implementing a machine learning operator based on a database system, by converting the model parameters contained in the machine learning operator into a model feature table stored in the database system, and converting the input parameters of the machine learning operator into an input feature table in the database system, and using the database query statement to call and process the input feature table and the model feature table to implement the operation logic of the machine learning operator. Through the embodiments of this specification, the model parameters of the machine learning operator contained in the machine learning model are successfully converted into a relational database table in the database system, and at the same time, the database query statement native to the database system is used to convert the traditional operation process of the machine learning operator into a standard operation on the relational database table in the database. In this way, various machine learning models can be easily assembled into machine learning operators implemented based on the database system, so that the process of calling and using the machine learning model only requires the participation of the database system without the participation of the traditional machine learning system, thereby realizing the close integration of the machine learning model and the database system. Since the embodiments of this specification do not require the participation of a machine learning system, they can fundamentally avoid the resource overhead and development costs of data flow and data conversion between the machine learning system and the database system. At the same time, since the machine learning operators are converted into corresponding database query statements for implementation, rather than being implemented by compiling manually written user-defined functions into the database system kernel, a large amount of development costs and compilation costs are reduced. At the same time, as standard database query statements, they can also be recognized by the database system and their execution costs can be estimated, and the conditions for optimizing their execution process through the database system's native query optimization technology are met.
[0116] Figure 7 This is a flowchart of a model reasoning method provided by this specification according to an exemplary embodiment. Figure 1 The database system shown in ; Figure 7 As shown, the method includes the following steps:
[0117] S702: Obtain input data for any machine learning operator in the machine learning model.
[0118] S704: Providing the input data to any one of the machine learning operators for processing, where the any one of the machine learning operators is implemented by the implementation method of any one of the aforementioned operators.
[0119] S706: Obtain output data obtained by any of the machine learning operators to determine the inference result of the machine learning model based on the output data.
[0120] Figure 7 The technical details of the implementation of the machine learning operators involved in the embodiment shown are in Figure 2Detailed descriptions are given in the examples and will not be repeated here.
[0121] As mentioned above, since the machine learning model can be regarded as a combination of a series of machine learning operators, when the machine learning model is used for model reasoning, the machine learning operators contained therein may be called multiple times. At this time, the implementation method of the machine learning operator described above can be used to implement the call of the machine learning operator in the machine learning model, provide the input data (derived from the external input of the machine learning model, or from the output of a machine learning operator in the machine learning model) to the machine learning operator and execute the corresponding database query statement to run the corresponding operation logic. After obtaining the output data corresponding to the machine learning operator obtained after executing the database query statement, if the machine learning operator is the last layer of the machine learning model, the output result is used as the model output of the machine learning model and the corresponding reasoning result is generated; if the machine learning operator is not the last layer of the machine learning model, it is used as the input data of the machine learning operator of the next layer in the machine learning model, and the overall reasoning process of the machine learning model is continued. After finally obtaining the model output of the machine learning model, the corresponding reasoning result is generated based on the model output. The embodiment of this specification implements a storage mechanism and calling mechanism for a machine learning model based on a database system.
[0122] Figure 8 This is a schematic diagram of a device structure provided by this specification according to an exemplary embodiment. Figure 8 At the hardware level, the device includes a processor 802, an internal bus 804, a network interface 806, a memory 808, and a non-volatile memory 810. Of course, it may also include hardware required for other functions. One or more embodiments of this specification can be implemented based on software, such as the processor 802 reading the corresponding computer program from the non-volatile memory 810 into the memory 808 and then running it. Of course, in addition to software implementation, one or more embodiments of this specification do not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.
[0123] like Figure 9 As shown, Figure 9 This is a block diagram of a device for implementing a learning operator according to an exemplary embodiment of the present invention. The device can be applied to Figure 8 The device shown in the figure is used to implement the technical solution of this specification. Figure 1 The database system shown in , wherein the database system stores a model feature table, wherein the model feature table is obtained by converting the model parameters and values contained in the machine learning operator; the device includes:
[0124] The statement receiving unit 901 is used to receive a query statement corresponding to the machine learning operator, and the query statement is used to implement the operation logic of the machine learning operator.
[0125] The statement execution unit 902 is used to execute the query statement to call and process the input feature table and the model feature table based on the operation logic; wherein the input feature table is obtained by converting the input parameters and values of the machine learning operator.
[0126] Optionally, the database system stores an input parameter tuple table and an input feature mapping table corresponding to the machine learning operator, wherein the fields of the input parameter tuple table include an input parameter value field and an input parameter connection field, the fields of the input feature mapping table include an input parameter description field and an input parameter connection field, and the input feature table is obtained by executing a first connection statement on the input feature mapping table and the input parameter tuple table and connecting based on the values in the input parameter connection field; and / or,
[0127] The database system stores a model parameter tuple table and a model feature mapping table corresponding to the machine learning operator, wherein the fields of the model parameter tuple table include a model parameter value field and a model parameter connection field, and the fields of the model feature mapping table include a model parameter description field and a model parameter connection field. The model feature table is obtained by executing a second connection statement on the model feature mapping table and the model parameter tuple table and connecting based on the values in the model parameter connection field.
[0128] Optionally, the input feature mapping table and / or the model feature mapping table are generated based on hyperparameters of the machine learning operator.
[0129] Optionally, the first connection statement and / or the second connection statement are included in the query statement.
[0130] Optionally, the input parameter tuple table is an output feature table obtained by outputting another machine learning operator.
[0131] Optionally, the machine learning operator includes a convolutional layer operator, and the input feature map is generated based on the input feature map size, convolution kernel size, padding length, and stride corresponding to the convolutional layer operator;
[0132] The input parameter description field in the input feature mapping table includes a submatrix sequence number field and a local sequence number field, and the input parameter connection field in the input feature mapping table includes a global sequence number field; wherein, the value of any table item in the submatrix sequence number field in the input feature mapping table is used to describe: the submatrix obtained by splitting the input feature map and performing convolution calculation with the convolution kernel to which the feature element corresponding to the any table item in the input feature map belongs, the value of the any table item in the local sequence number field is used to describe: the position of the feature element corresponding to the any table item in the submatrix to which it belongs in the input feature map, and the value of the any table item in the global sequence number field is used to describe: the position of the feature element corresponding to the any table item in the input feature map in the input feature map;
[0133] The input parameter connection field in the input parameter tuple table includes a tuple number field in increasing order, and the fields of the input feature table include a submatrix number field, a local number field and an input parameter value field;
[0134] The first connection statement is used to connect any table entry in the input parameter tuple table to a table entry in the input feature map table whose global sequence number is the same as the tuple sequence number of any table entry during execution.
[0135] Optionally, the machine learning operator includes a fully connected layer operator, and the model feature map is generated based on the input feature map size and the output feature map size corresponding to the fully connected layer operator;
[0136] The model parameter description field in the model feature mapping table includes a fully connected group sequence number field and a local sequence number field, and the model parameter connection field in the model feature mapping table includes a global sequence number field; wherein, the value of any table item in the fully connected group sequence number field in the model feature mapping table is used to describe: the fully connected group to which the weight parameter corresponding to any table item belongs, the value of any table item in the local sequence number field is used to describe: the position of the weight parameter corresponding to any table item in the fully connected group to which it belongs, and the value of any table item in the global sequence number field is used to describe: the position of the weight parameter corresponding to any table item in all weight parameters;
[0137] The model parameter connection field in the model parameter tuple table includes a tuple sequence number field and a model parameter value field in ascending order, and the field of the model feature table includes a full connection group sequence number field, a local sequence number field and a model parameter value field;
[0138] The second connection statement is used to connect any table item in the model parameter tuple table to the table item in the model feature mapping table whose global serial number is the same as the tuple serial number of any table item during execution.
[0139] Optionally, the machine learning operator includes a convolutional layer operator, and the fields of the input feature table include a submatrix sequence number field, a local sequence number field, and an input parameter value field; wherein, the value of any table item in the submatrix sequence number field of the input feature table is used to describe: the submatrix obtained by splitting the input feature map and performing convolution calculation with the convolution kernel to which the feature element corresponding to any table item in the input feature map belongs, and the value of any table item in the local sequence number field is used to describe: the position of the feature element corresponding to any table item in the input feature map in the submatrix to which it belongs;
[0140] The fields of the model feature table include a convolution kernel sequence number field, a local sequence number field, and a model parameter value field; wherein the value of the convolution kernel sequence number field of any table entry in the model feature table is used to describe: the convolution kernel to which the feature element corresponding to any table entry belongs, and the value of the local sequence number field of any table entry is used to describe: the position of the feature element corresponding to any table entry in the convolution kernel to which it belongs;
[0141] The fields of the output feature table generated by executing the query statement include a convolution kernel number field, a submatrix number field, and an output parameter value field;
[0142] The statement execution unit 902 is specifically used to: calculate each sub-matrix group table entry with the same sub-matrix sequence number in the input feature table and each convolution kernel group table entry with the same convolution kernel sequence number in the model feature table, and sum the products obtained by multiplying the input parameter value and model parameter value of any sub-matrix group table entry with the table entry with the same local sequence number in any convolution kernel group table entry as the output parameter value of the table entry in the output feature table corresponding to the sub-matrix sequence number of any sub-matrix group table entry and the convolution kernel sequence number of any convolution kernel group.
[0143] Optionally, the query statement includes a third connection statement for calling the input feature table and the model feature table, the third connection statement being used to connect the table items in the model feature table to the table items with the same local sequence number in the input feature table during execution to obtain a feature connection table, wherein the fields of the feature connection table include a submatrix sequence number field, a convolution kernel sequence number field, an input parameter value field, and a model parameter value field;
[0144] The query statement includes a multiplication statement and a corresponding summation statement for the feature connection table; wherein the multiplication statement is used to multiply the input parameter value of each table item in the feature connection table with the model parameter value during execution to obtain the product corresponding to each table item, and the summation statement is used to sum the products corresponding to the table items with the same submatrix sequence number and the same convolution kernel sequence number in the feature connection table during execution, as the output parameter value of the table item corresponding to the same submatrix sequence number and the same convolution kernel sequence number in the output feature table.
[0145] Optionally, the machine learning operator includes a fully connected layer operator, and the fields of the input feature table include a local sequence number field and an input parameter value field in ascending order;
[0146] The fields of the model feature table include a fully connected group sequence number field, a local sequence number field, and a model parameter value field; wherein the value of any table item in the fully connected group sequence number field in the model feature mapping table is used to describe: the fully connected group to which the weight parameter corresponding to any table item belongs, and the value of any table item in the local sequence number field is used to describe: the position of the weight parameter corresponding to any table item in the fully connected group to which it belongs;
[0147] The fields of the output feature table generated by executing the query statement include a fully connected group sequence number field and an output parameter value field;
[0148] The statement execution unit 902 is specifically used to: calculate each fully connected group table entry with the same fully connected group sequence number in the model feature table with the table entry in the input feature table, and sum the products obtained by multiplying the input parameter value and the model parameter value of any fully connected group table entry with the table entry with the same local sequence number in the input feature table as the output parameter value of the table entry in the output feature table corresponding to the fully connected group sequence number of any fully connected group table entry.
[0149] Optionally, the query statement includes a fourth connection statement for calling the input feature table and the model feature table, the fourth connection statement being used to connect, during execution, table entries in the input feature table to table entries with the same local sequence number in the model feature table to obtain a feature connection table, wherein the fields of the feature connection table include a full connection sequence number field, an input parameter value field, and a model parameter value field;
[0150] The query statement includes a multiplication statement and a corresponding summation statement for the feature connection table; wherein the multiplication statement is used to multiply the input parameter value of each table item in the feature connection table with the model parameter value during execution to obtain the product corresponding to each table item, and the summation statement is used to sum the products corresponding to the table items with the same fully connected group number in the feature connection table during execution as the output parameter value of the table item corresponding to the same fully connected group number in the output feature table.
[0151] like Figure 10 As shown, Figure 10 This is a block diagram of a model inference device provided in accordance with an exemplary embodiment of the present specification. The device can be applied to Figure 8 The device shown in the figure is used to implement the technical solution of this specification. Figure 1 The database system shown in , including:
[0152] The input data acquisition unit 1001 is used to obtain input data for any machine learning operator in the machine learning model.
[0153] The machine learning operator processing unit 1002 is used to provide the input data to any of the machine learning operators for processing, and any of the machine learning operators is implemented by the implementation method of any of the aforementioned operators.
[0154] The output data acquisition unit 1003 is used to obtain the output data obtained by any machine learning operator to determine the inference result of the machine learning model based on the output data.
[0155] Accordingly, this specification also provides a device, which includes a processor; a memory for storing processor-executable instructions; wherein the processor is configured to implement the steps of the implementation method of the machine learning operator or the model inference method provided in all the above method embodiments.
[0156] Accordingly, this specification also provides a computer-readable storage medium on which executable instructions are stored; wherein, when the instructions are executed by the processor, the steps of the implementation method of the machine learning operator or the model reasoning method provided in all the above method embodiments are implemented.
[0157] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to the partial description of the method embodiments. The device embodiments described above are merely illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this specification. A person of ordinary skill in the art can understand and implement it without paying any creative work.
[0158] The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, laptop computer, cellular phone, camera phone, smartphone, personal digital assistant, media player, navigation device, email transceiver, game console, tablet computer, wearable device, or any combination of these devices.
[0159] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0160] Memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.
[0161] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information using any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves.
[0162] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0163] The foregoing description of this specification describes specific embodiments. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0164] The terms used in one or more embodiments of this specification are for the purpose of describing specific embodiments only and are not intended to limit one or more embodiments of this specification. The singular forms "a," "an," "the," and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.
[0165] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when..." or "when..." or "in response to determining."
[0166] The above description is merely a preferred embodiment of one or more embodiments of this specification and is not intended to limit one or more embodiments of this specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of this specification shall be included in the scope of protection of one or more embodiments of this specification.
Claims
1. An operator implementation method is applied to a database system, wherein the database system stores a model feature table, a model parameter tuple table corresponding to a machine learning operator, and a model feature mapping table, wherein: The fields of the model parameter tuple table include a model parameter value field and a model parameter connection field, the fields of the model feature mapping table include a model parameter description field and a model parameter connection field, the model feature table is obtained by executing a second connection statement on the model feature mapping table and the model parameter tuple table and connecting based on the values in the model parameter connection field, the machine learning operator includes a convolutional layer operator and a fully connected layer operator, and the method includes: Receive a query statement corresponding to the machine learning operator, where the query statement is used to implement the operation logic of the machine learning operator; Execute the query statement to call and process the input feature table and the model feature table based on the operation logic; wherein the database system stores the input parameter tuple table and the input feature mapping table corresponding to the machine learning operator, wherein the fields of the input parameter tuple table include an input parameter value field and an input parameter connection field, and the fields of the input feature mapping table include an input parameter description field and an input parameter connection field, and the input feature table is obtained by executing a first connection statement between the input feature mapping table and the input parameter tuple table and connecting based on the values in the input parameter connection field.
2. The method according to claim 1, wherein the input feature mapping table and / or the model feature mapping table are generated based on the hyperparameters of the machine learning operator. 3 . The method according to claim 1 , wherein the first connection statement and / or the second connection statement are included in the query statement.
4. The method according to claim 1, wherein the input parameter tuple table is an output feature table obtained by outputting another machine learning operator.
5. The method according to claim 1, wherein the input feature map is generated based on the input feature map size, convolution kernel size, padding length, and stride corresponding to the convolution layer operator; The input parameter description field in the input feature map table includes a submatrix sequence number field and a local sequence number field, and the input parameter connection field in the input feature map table includes a global sequence number field; wherein, The value of any table item in the submatrix sequence number field of the input feature map is used to describe: the submatrix obtained by splitting the input feature map and used for convolution calculation with the convolution kernel, to which the feature element corresponding to the any table item in the input feature map belongs; the value of any table item in the local sequence number field is used to describe: the position of the feature element corresponding to the any table item in the submatrix to which it belongs in the input feature map; the value of any table item in the global sequence number field is used to describe: the position of the feature element corresponding to the any table item in the input feature map in the input feature map; The input parameter connection field in the input parameter tuple table includes a tuple number field in increasing order, and the fields of the input feature table include a submatrix number field, a local number field and an input parameter value field; The first connection statement is used to connect any table entry in the input parameter tuple table to a table entry in the input feature map table whose global sequence number is the same as the tuple sequence number of any table entry during execution.
6. The method according to claim 1, wherein the model feature map is generated based on the input feature map size and the output feature map size corresponding to the fully connected layer operator; The model parameter description field in the model feature mapping table includes a fully connected group sequence number field and a local sequence number field, and the model parameter connection field in the model feature mapping table includes a global sequence number field; wherein, The value of the fully connected group sequence number field of any table item in the model feature map is used to describe: the fully connected group to which the weight parameter of the corresponding table item belongs, the value of the local sequence number field of any table item is used to describe: the position of the weight parameter corresponding to the any table item in the fully connected group to which it belongs, and the value of the global sequence number field of any table item is used to describe: the position of the weight parameter corresponding to the any table item in all weight parameters; The model parameter connection field in the model parameter tuple table includes a tuple sequence number field and a model parameter value field in ascending order, and the field of the model feature table includes a full connection group sequence number field, a local sequence number field and a model parameter value field; The second connection statement is used to connect any table item in the model parameter tuple table to the table item in the model feature mapping table whose global serial number is the same as the tuple serial number of any table item during execution.
7. The method according to claim 1, wherein the fields of the input feature table include a submatrix sequence number field, a local sequence number field, and an input parameter value field; wherein, The value of the submatrix sequence number field of any table entry in the input feature table is used to describe: the submatrix obtained by splitting the input feature map and used for convolution calculation with the convolution kernel, to which the feature element corresponding to the any table entry in the input feature map belongs; the value of the local sequence number field of any table entry is used to describe: the position of the feature element corresponding to the any table entry in the submatrix to which it belongs in the input feature map; The fields of the model feature table include a convolution kernel sequence number field, a local sequence number field, and a model parameter value field; wherein the value of the convolution kernel sequence number field of any table entry in the model feature table is used to describe: the convolution kernel to which the feature element corresponding to any table entry belongs, and the value of the local sequence number field of any table entry is used to describe: the position of the feature element corresponding to any table entry in the convolution kernel to which it belongs; The fields of the output feature table generated by executing the query statement include a convolution kernel number field, a submatrix number field, and an output parameter value field; The calling and processing of the input feature table and the model feature table based on the operation logic includes: calculating each sub-matrix group table item with the same sub-matrix sequence number in the input feature table and each convolution kernel group table item with the same convolution kernel sequence number in the model feature table, and summing the products obtained by multiplying the input parameter value and the model parameter value of any sub-matrix group table item with the table item with the same local sequence number in any convolution kernel group table item as the output parameter value of the table item in the output feature table corresponding to the sub-matrix sequence number of any sub-matrix group table item and the convolution kernel sequence number of any convolution kernel group.
8. The method according to claim 7, wherein the query statement includes a third connection statement for calling the input feature table and the model feature table, the third connection statement being used to connect the table items in the model feature table to the table items with the same local sequence number in the input feature table during execution to obtain a feature connection table, wherein the fields of the feature connection table include a submatrix sequence number field, a convolution kernel sequence number field, an input parameter value field, and a model parameter value field; The query statement includes a multiplication statement and a corresponding summation statement for the feature connection table; wherein, The multiplication statement is used to multiply the input parameter value of each table item in the feature connection table with the model parameter value during execution to obtain the product corresponding to each table item. The summation statement is used to sum the products corresponding to the table items with the same submatrix number and the same convolution kernel number in the feature connection table during execution, as the output parameter value of the table item corresponding to the same submatrix number and the same convolution kernel number in the output feature table.
9. The method according to claim 1, wherein the fields of the input feature table include a local sequence number field and an input parameter value field in ascending order; The fields of the model feature table include a fully connected group number field, a local number field and a model parameter value field; wherein, The value of the fully connected group sequence number field of any table item in the model feature map is used to describe: the fully connected group to which the weight parameter corresponding to any table item belongs, and the value of the local sequence number field of any table item is used to describe: the position of the weight parameter corresponding to any table item in the fully connected group to which it belongs; The fields of the output feature table generated by executing the query statement include a fully connected group sequence number field and an output parameter value field; The calling and processing of the input feature table and the model feature table based on the operation logic includes: calculating each fully connected group table entry with the same fully connected group sequence number in the model feature table with the table entry in the input feature table, and summing the products obtained by multiplying the input parameter value and the model parameter value of any fully connected group table entry with the table entry with the same local sequence number in the input feature table as the output parameter value of the table entry in the output feature table corresponding to the fully connected group sequence number of any fully connected group table entry.
10. The method according to claim 9, wherein the query statement includes a fourth connection statement for calling the input feature table and the model feature table, the fourth connection statement being used to connect the table items in the input feature table to the table items with the same local sequence number in the model feature table during execution to obtain a feature connection table, wherein the fields of the feature connection table include a full connection sequence number field, an input parameter value field, and a model parameter value field; The query statement includes a multiplication statement and a corresponding summation statement for the feature connection table; wherein, The multiplication statement is used to multiply the input parameter value of each table item in the feature connection table with the model parameter value during execution to obtain the product corresponding to each table item. The summation statement is used to sum the products corresponding to the table items with the same fully connected group number in the feature connection table during execution as the output parameter value of the table item corresponding to the same fully connected group number in the output feature table.
11. A model inference method, comprising: Get input data for any machine learning operator in the machine learning model; Providing the input data to any one of the machine learning operators for processing, wherein the any one of the machine learning operators is implemented by the method according to any one of claims 1 to 10; Obtain output data obtained by any of the machine learning operators to determine the inference result of the machine learning model based on the output data.
12. A database system, comprising a database and a database management system; The database is used to store the model feature table, the model parameter tuple table corresponding to the machine learning operator, and the model feature mapping table, wherein: The fields of the model parameter tuple table include a model parameter value field and a model parameter connection field, the fields of the model feature mapping table include a model parameter description field and a model parameter connection field, the model feature table is obtained by executing a second connection statement on the model feature mapping table and the model parameter tuple table and connecting based on the values in the model parameter connection field, and the machine learning operator includes a convolutional layer operator and a fully connected layer operator; The database management system is used to execute the method as described in any one of claims 1 to 10 to implement the machine learning operator corresponding to the model feature table.
13. An electronic device, characterized in that: include: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 11 by running the executable instructions.
14. A computer-readable storage medium having computer instructions stored thereon, characterized in that: When the instruction is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
Citation Information
Patent Citations
Construction of machine learning model
CN109657803A
Database query method and device, computer equipment and storage medium
CN110990400A