Data processing method, machine learning framework, and related devices

By creating tensor data and computation graphs in the quantum computing model and executing machine learning models layer by layer, the problem of low debugging efficiency is solved, and efficient debugging and development are achieved.

CN116523059BActive Publication Date: 2026-04-10ORIGIN QUANTUM COMPUTING TECH (HEFEI) CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
ORIGIN QUANTUM COMPUTING TECH (HEFEI) CO LTD
Filing Date
2022-01-24
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

Developing machine learning models that incorporate quantum programs is inefficient and difficult.

Method used

Input data is obtained by calling the data structure module and tensor data is created. A machine learning model is created using the quantum module and the classical module. The computational layer to be executed is determined. A computational graph is created based on the forward propagation relationship. The model is executed layer by layer and the output results are determined, including the loss function of the training layer and the optimization of the model in the optimizer layer.

Benefits of technology

It reduces the difficulty of debugging machine learning models, improves development efficiency, and enables the model to be run layer by layer to facilitate problem localization, thereby improving debugging efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116523059B_ABST
    Figure CN116523059B_ABST
Patent Text Reader

Abstract

The application discloses a data processing method, a machine learning framework and related equipment, which are applied to an electronic device including a machine learning framework, the machine learning framework includes a data structure module, a quantum module and a classical module, and the method includes the following steps: calling the data structure module to obtain input data and creating tensor data including the input data, calling the quantum module and the classical module to create a machine learning model, the machine learning model includes a plurality of calculation layers and a forward propagation relationship between the plurality of calculation layers; determining a first calculation layer to be executed corresponding to the tensor data from the plurality of calculation layers; creating a calculation graph including a sub-computation graph corresponding to the first calculation layer based on the forward propagation relationship; and determining an output result of the machine learning model based on the calculation graph. Based on the above technical scheme, the difficulty of debugging the machine learning model can be reduced, and the development efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application belongs to the technical field of quantum computing, and particularly relates to a data processing method, a machine learning framework and related equipment. BACKGROUND

[0002] Machine learning models are widely used in artificial intelligence research due to their excellent performance. By training machine learning models using labeled training data, an expected machine learning model can be obtained, which can then be used for specific application work such as speech recognition and image recognition. Machine learning models do not need to be manually set up for specific application work, and can establish corresponding work standards through training, which has good adaptability to different application work. With the development of quantum computing, machine learning models containing quantum programs are also increasing.

[0003] In related technologies, during the development of machine learning models containing quantum programs, the program needs to be constantly debugged. When the machine learning model is complex, a large amount of work is required to debug it, and the debugging efficiency is low. SUMMARY

[0004] The purpose of the present application is to provide a data processing method, a machine learning framework and related equipment, which aims to reduce the debugging difficulty of machine learning models containing quantum programs and improve the development efficiency.

[0005] To achieve the above purpose, the first aspect of the embodiments of the present application provides a data processing method applied to an electronic device including a machine learning framework, the machine learning framework including a data structure module, a quantum module and a classical module, the method comprising:

[0006] calling the data structure module to obtain input data and create tensor data including the input data, calling the quantum module and the classical module to create a machine learning model, the machine learning model including a plurality of calculation layers and a forward propagation relationship between the plurality of calculation layers;

[0007] determining a first calculation layer to be executed corresponding to the tensor data from the plurality of calculation layers;

[0008] creating a calculation graph including a sub-computation graph corresponding to the first calculation layer based on the forward propagation relationship;

[0009] determining an output result of the machine learning model based on the calculation graph.

[0010] Optionally, the creating a calculation graph including a sub-computation graph corresponding to the first calculation layer based on the forward propagation relationship comprises:

[0011] determining whether there is an unexecuted second computing layer associated with the first computing layer based on the forward propagation relationship;

[0012] if there is an unexecuted second computing layer associated with the first computing layer, executing the second computing layer, and determining a computing relationship between an output of the second computing layer and an output of the first computing layer;

[0013] adding a sub-computing graph corresponding to the first computing layer into a computing graph corresponding to the second computing layer based on the computing relationship, to obtain a new computing graph.

[0014] Optionally, the method further comprises:

[0015] if there is no unexecuted second computing layer associated with the first computing layer, creating the computing graph corresponding to the first computing layer.

[0016] Optionally, the adding the sub-computing graph corresponding to the first computing layer into the computing graph corresponding to the second computing layer based on the computing relationship, to obtain the new computing graph, comprises:

[0017] adding, as a successor node of an output corresponding computing node of the second computing layer, an output corresponding computing node of the first computing layer into the computing graph corresponding to the second computing layer based on the computing relationship;

[0018] adding, as a predecessor node of the output corresponding computing node of the first computing layer, a dependent variable corresponding computing node of the first computing layer into the computing graph corresponding to the second computing layer, to obtain the new computing graph.

[0019] Optionally, the determining the output result of the machine learning model based on the computing graph comprises:

[0020] executing the first computing layer based on the computing graph, to obtain an output of the first computing layer;

[0021] determining the output result of the machine learning model based on the output of the first computing layer.

[0022] Optionally, the method further comprises:

[0023] calling the classical module to create a training layer of the machine learning model;

[0024] inputting an output result of the machine learning model into the training layer, to add a sub-computing graph corresponding to the training layer into the computing graph based on a relationship between the training layer and the machine learning model;

[0025] updating parameters of the machine learning model based on the computation graph, to obtain a trained machine learning model.

[0026] Optionally, the training layer comprises a loss function layer and an optimizer layer, and the classical module comprises:

[0027] a loss function unit configured to calculate a loss function of the machine learning model;

[0028] an optimizer unit configured to update parameters of the machine learning model based on the loss function when training the machine learning model, to optimize the machine learning model;

[0029] The calling of the classical module to create the training layer of the machine learning model comprises:

[0030] calling the loss function unit to create the loss function layer;

[0031] calling the optimizer unit to create the optimizer layer.

[0032] Optionally, the inputting of the output result of the machine learning model into the training layer comprises:

[0033] inputting the output result of the machine learning model into the loss function layer, to calculate a value of the loss function of the machine learning model, and adding a computation node corresponding to the value of the loss function as a successor node of a computation node corresponding to the output result of the machine learning model, to the computation graph;

[0034] The updating of parameters of the machine learning model based on the computation graph, to obtain a trained machine learning model, comprises:

[0035] when it is determined that the value of the loss function does not satisfy a preset condition, inputting the value of the loss function into the optimizer layer, to update the parameters of the machine learning model based on the value of the loss function and the computation graph;

[0036] determining the value of the loss function of the machine learning model after the updating of the parameters;

[0037] when it is determined that the value of the loss function satisfies a preset condition, taking the machine learning model after the updating of the parameters as the trained machine learning model.

[0038] Optionally, the updating of the parameters of the machine learning model based on the value of the loss function and the computation graph comprises:

[0039] compute a gradient of the loss function with respect to parameters of the machine learning model based on the value of the loss function and the computation graph;

[0040] update the parameters of the machine learning model based on the gradient and a gradient descent algorithm.

[0041] Optionally, the computing the gradient of the loss function with respect to parameters of the machine learning model based on the value of the loss function and the computation graph comprises:

[0042] determining a path from a computation node corresponding to the loss function to a computation node corresponding to the parameters of the machine learning model in the computation graph;

[0043] computing an intermediate gradient of each computation node on the path with respect to a predecessor node of the computation node based on the value of the loss function;

[0044] multiplying all the computed intermediate gradients to obtain the gradient of the loss function with respect to the parameters.

[0045] In a second aspect, the present application provides a data processing apparatus applied to an electronic device comprising a machine learning framework, the machine learning framework comprising a data structure module, a quantum module and a classical module, the apparatus comprising:

[0046] a first creating module configured to call the data structure module to obtain input data and create tensor data comprising the input data, and call the quantum module and the classical module to create a machine learning model, the machine learning model comprising a plurality of computation layers and a forward propagation relationship between the plurality of computation layers;

[0047] a determining module configured to determine a first computation layer to be executed corresponding to the tensor data from the plurality of computation layers;

[0048] a second creating module configured to create a computation graph comprising a computation node corresponding to the first computation layer based on the forward propagation relationship;

[0049] an outputting module configured to determine an output result of the machine learning model based on the computation graph.

[0050] Optionally, the second creating module is further configured to:

[0051] determine whether there is an unexecuted second computation layer associated with the first computation layer before the first computation layer based on the forward propagation relationship;

[0052] when there is an unexecuted second computation layer associated with the first computation layer, execute the second computation layer, and determine a computation relationship between an output of the second computation layer and an output of the first computation layer.

[0053] add the sub-computing graph corresponding to the first computing layer into the computing graph corresponding to the second computing layer based on the computing relationship, to obtain a new computing graph.

[0054] Optionally, the apparatus further includes:

[0055] a third creating module configured to create the computing graph corresponding to the first computing layer when there is no unexecuted second computing layer associated with the first computing layer.

[0056] Optionally, the second creating module is further configured to:

[0057] add, as a successor node of an output corresponding computing node of the second computing layer, the output corresponding computing node of the first computing layer into the computing graph corresponding to the second computing layer based on the computing relationship;

[0058] add, as a predecessor node of the output corresponding computing node of the first computing layer, a dependent variable corresponding computing node of the first computing layer into the computing graph corresponding to the second computing layer, to obtain a new computing graph.

[0059] Optionally, the output module is further configured to:

[0060] execute the first computing layer based on the computing graph, to obtain an output of the first computing layer;

[0061] determine an output result of the machine learning model based on the output of the first computing layer.

[0062] Optionally, the apparatus further includes:

[0063] a fourth creating module configured to invoke the classical module to create a training layer of the machine learning model;

[0064] an input module configured to input an output result of the machine learning model into the training layer, to add a sub-computing graph corresponding to the training layer into the computing graph based on a relationship between the training layer and the machine learning model;

[0065] an updating module configured to update a parameter of the machine learning model based on the computing graph, to obtain a trained machine learning model.

[0066] Optionally, the training layer includes a loss function layer and an optimizer layer, and the classical module includes:

[0067] a loss function unit configured to calculate a loss function of the machine learning model;

[0068] an optimizer unit configured to update parameters of the machine learning model based on the loss function when training the machine learning model to optimize the machine learning model;

[0069] The fourth creation module is further configured to:

[0070] invoke the loss function unit to create the loss function layer;

[0071] invoke the optimizer unit to create the optimizer layer.

[0072] Optionally, the input module is further configured to:

[0073] input an output result of the machine learning model into the loss function layer to calculate a value of the loss function of the machine learning model, and add a computing node corresponding to the value of the loss function as a successor node of a computing node corresponding to the output result of the machine learning model to the computation graph;

[0074] The update module is further configured to:

[0075] input the value of the loss function into the optimizer layer to update the parameters of the machine learning model based on the value of the loss function and the computation graph when it is determined that the value of the loss function does not satisfy a preset condition;

[0076] determine the value of the loss function of the machine learning model after the parameters are updated;

[0077] use the machine learning model after the parameters are updated as the trained machine learning model when it is determined that the value of the loss function satisfies the preset condition.

[0078] Optionally, the update module is further configured to:

[0079] calculate a gradient of the loss function with respect to the parameters of the machine learning model based on the value of the loss function and the computation graph;

[0080] update the parameters of the machine learning model based on the gradient and a gradient descent algorithm.

[0081] Optionally, the update module is further configured to:

[0082] determine a path from the computing node corresponding to the loss function to the computing node corresponding to the parameters of the machine learning model in the computation graph;

[0083] calculate an intermediate gradient of each computing node of a non-leaf node on the path with respect to a predecessor node of the computing node based on the value of the loss function;

[0084] multiply all the intermediate gradients calculated to obtain the gradient of the loss function with respect to the parameters.

[0085] In a third aspect, the present application provides a machine learning framework, the framework comprising:

[0086] a data structure module configured to obtain input data and create tensor data comprising the input data;

[0087] a quantum module configured to create a machine learning model;

[0088] a classical module configured to create a machine learning model, the machine learning model comprising a plurality of computing layers and a forward propagation relationship between the plurality of computing layers;

[0089] the classical module is further configured to determine, from the plurality of computing layers, a first computing layer to be executed corresponding to the tensor data; create a computation graph comprising a computing node corresponding to the first computing layer based on the forward propagation relationship; and determine an output result of the machine learning model based on the computation graph.

[0090] In a fourth aspect, the present application provides a storage medium, the storage medium storing a computer program, wherein the computer program is configured to execute the steps of the method of any one of the first aspect when running.

[0091] In a fifth aspect, the present application provides an electronic device comprising a memory and a processor, the memory storing a computer program, and the processor being configured to execute the steps of the method of any one of the first aspect by running the computer program.

[0092] Based on the above technical solution, for a machine learning model created by calling a machine learning framework, in a plurality of computing layers included in the machine learning model, a first computing layer to be executed is first determined, then a computation graph comprising a sub-computation graph corresponding to the first computing layer is created, and then an output result of the machine learning model is determined according to the computation graph, that is, each computation graph is created and executed immediately after the creation, without creating all computation graphs and then executing them, and thus when debugging the machine learning model, the machine learning model can be run layer by layer, and the debugging is performed according to the result of the layer-by-layer running, which facilitates locating the problem of the machine learning model, reduces the difficulty of debugging the machine learning model, and accelerates the debugging efficiency. BRIEF DESCRIPTION OF DRAWINGS

[0093] Figure 1 is a hardware structure block diagram of a computer terminal for a data processing method according to an exemplary embodiment.

[0094] Figure 2is a flowchart of a data processing method according to an example embodiment.

[0095] Figure 3 is a block diagram of a machine learning framework according to an example embodiment.

[0096] Figure 4 is a flowchart of step S23 included in a data processing method according to an example embodiment.

[0097] Figure 5 is a flowchart of step S233 included in a data processing method according to an example embodiment.

[0098] Figure 6 is a computational graph of a machine learning model according to an example embodiment.

[0099] Figure 7 is a flowchart of step S24 included in a data processing method according to an example embodiment.

[0100] Figure 8 is another flowchart of a data processing method according to an example embodiment.

[0101] Figure 9 is another flowchart of a data processing method according to an example embodiment.

[0102] Figure 10 is a block diagram of a classical module included in a data processing apparatus according to an example embodiment.

[0103] Figure 11 is a flowchart of step S95 included in a data processing method according to an example embodiment.

[0104] Figure 12 is a flowchart of step S97 included in a data processing method according to an example embodiment.

[0105] Figure 13 is a flowchart of step S971 included in a data processing method according to an example embodiment.

[0106] Figure 14 is a flowchart of step S9711 included in a data processing method according to an example embodiment.

[0107] Figure 15 is a block diagram of a data processing apparatus according to an example embodiment. DETAILED DESCRIPTION

[0108] The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.

[0109] The present invention first provides a data processing method, which can be applied to electronic devices, such as computer terminals, specifically ordinary computers, quantum computers, etc.

[0110] The following detailed explanation uses a computer terminal as an example. Figure 1 This is a hardware structure block diagram of a computer terminal illustrating a data processing method according to an exemplary embodiment. For example... Figure 1 As shown, a computer terminal may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing quantum circuit-based data processing methods are also shown. Optionally, the computer terminal may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the computer terminal described above. For example, the computer terminal may also include components that are more complex than those described above. Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.

[0111] The memory 104 can be used to store software programs and modules of application software, such as program instructions / modules corresponding to the data processing method in this embodiment. The processor 102 executes various functional applications and data processing by running the software programs and modules stored in the memory 104, thereby implementing the above-described method. The memory 104 may include high-speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to a computer terminal via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0112] The transmission device 106 is configured to receive or send data via a network. The network can include a wireless network provided by a communication provider of a computer terminal. In one example, the transmission device 106 includes a network interface controller (NIC) that can be connected to other network devices through a base station to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module configured to communicate with the Internet wirelessly.

[0113] It should be noted that a real quantum computer is a hybrid structure, which includes two parts: one part is a classical computer responsible for performing classical computation and control; the other part is a quantum device responsible for running a quantum program to implement quantum computation. The quantum program is a sequence of instructions written in a quantum language such as QRunes language that can run on a quantum computer, which supports quantum logic gate operations and ultimately realizes quantum computation. Specifically, the quantum program is a sequence of instructions for operating quantum logic gates in a certain time sequence.

[0114] In practical applications, due to the limitations of the development of quantum device hardware, quantum computation simulation is usually needed to verify quantum algorithms, quantum applications, and the like. Quantum computation simulation is a process of simulating the running of a quantum program corresponding to a specific problem by means of a virtual architecture (i.e., a quantum virtual machine) built by an ordinary computer. Generally, a quantum program corresponding to a specific problem needs to be constructed. The quantum program referred to in the embodiments of the present application is a program written in a classical language representing quantum bits and their evolution, in which quantum bits, quantum logic gates, and the like related to quantum computation are represented by corresponding classical codes.

[0115] As an embodiment of a quantum program, a quantum circuit, also known as a quantum logic circuit, is the most commonly used general quantum computation model, which represents a circuit for operating quantum bits in an abstract concept, and its composition includes quantum bits, a circuit (a time line), and various quantum logic gates, and finally the result needs to be read out through a quantum measurement operation.

[0116] Unlike a traditional circuit connected by metal wires to transmit voltage signals or current signals, in a quantum circuit, the circuit can be regarded as being connected by time, that is, the state of a quantum bit naturally evolves with time, and in this process, the quantum bit is operated according to the instruction of a Hamiltonian operator until it encounters a logic gate.

[0117] A quantum program corresponds to a total quantum circuit as a whole, and the quantum program refers to the total quantum circuit, wherein the total number of qubits in the total quantum circuit is the same as the total number of qubits of the quantum program. It can be understood that a quantum program can be composed of a quantum circuit, a measurement operation for a qubit in the quantum circuit, a register for storing measurement results, and a control flow node (jump instruction). A quantum circuit can include tens, hundreds or even thousands of quantum logic gate operations. The execution process of a quantum program is the process of executing all quantum logic gates in a certain time sequence. It should be noted that the time sequence refers to the time sequence of the execution of a single quantum logic gate.

[0118] It should be noted that in classical computing, the most basic unit is a bit, and the most basic control mode is a logic gate, which can be used to control the circuit through the combination of logic gates. Similarly, the way to process qubits is quantum logic gates. Using quantum logic gates can evolve quantum states, and quantum logic gates are the basis of quantum circuits. Quantum logic gates include single-bit quantum logic gates such as Hadamard gate (H gate), Pauli-X gate (X gate), Pauli-Y gate (Y gate), Pauli-Z gate (Z gate), RX gate (RX rotation gate), RY gate (RY rotation gate), RZ gate (RZ rotation gate), etc. Multi-bit quantum logic gates such as CNOT gate, CR gate, iSWAP gate, Toffoli gate, etc. Quantum logic gates are generally represented by unitary matrices, and unitary matrices are not only in matrix form, but also an operation and transformation. The effect of a general quantum logic gate on a quantum state is calculated by left multiplying the quantum state right vector corresponding to the vector. For example, the vector corresponding to the quantum state right vector |0> can be The vector corresponding to the quantum state right vector |1> can be

[0119] Figure 2 FIG. 1 is a flowchart of a data processing method according to an example embodiment. Referring to FIG. 1, Figure 2 The embodiment provides a data processing method, which can be applied to an electronic device including a machine learning framework 30 as shown in Figure 3 The machine learning framework 30 includes a data structure module 31, a quantum module 32, and a classical module 33. The method includes:

[0120] S21, calling the data structure module to obtain input data and creating tensor data including the input data, calling the quantum module and the classical module to create a machine learning model, the machine learning model including a plurality of calculation layers and a forward propagation relationship between the plurality of calculation layers.

[0121] S22, determining, from the plurality of computing layers, a first computing layer to be executed corresponding to the tensor data.

[0122] S23, creating a computation graph including a sub-computation graph corresponding to the first computing layer based on the forward propagation relationship.

[0123] S24, determining an output result of the machine learning model based on the computation graph.

[0124] Specifically, the machine learning framework 30 integrates a plurality of function sets for creating and training a machine learning model, and through the interface defined thereby, the functions can be conveniently called to implement related operations on the machine learning model. As shown in Figure 3 The machine learning framework 30 can include:

[0125] The data structure module 31 is configured to obtain input data and create tensor data including the input data;

[0126] The quantum module 32 is configured to create a machine learning model;

[0127] The classical module 33 is configured to create a machine learning model, the machine learning model including a plurality of computing layers and a forward propagation relationship between the plurality of computing layers;

[0128] The classical module 33 is further configured to determine, from the plurality of computing layers, a first computing layer to be executed corresponding to the tensor data; create a computation graph including a computing node corresponding to the first computing layer based on the forward propagation relationship; and determine an output result of the machine learning model based on the computation graph.

[0129] Specifically, the data structure module 31 defines a data structure of tensor data, and by calling the data structure module 31, the input data can be converted into tensor data for inputting into the machine learning model for forward calculation. Of course, in other possible embodiments, the data structure module 31 can also be configured to perform operations on tensor data, for example, the data structure module 31 can also define mathematical operations and logical operations between tensor data, and thus the data structure module 31 can be called to create a classical computing layer of a machine learning model based on the operation relationship between the tensor data, for example, a fully connected layer of a classical neural network defines the relationship between input data x and output data y through a function y = wx + b, where w and b are parameters. By converting the input data x, the parameter w, and the parameter b into tensor data, and calling the data structure module 31 to perform operations corresponding to the function on these tensor data, a fully connected layer can be constructed.

[0130] In a possible implementation, the data structure module 31 can be configured to arrange the input data according to a preset data structure to create tensor data for inputting the machine learning model, and create tensor data for inputting the machine learning model arranged according to the preset data structure and with numerical values. Then, in step S21, for the input data, the input data can be arranged according to the preset data structure to obtain tensor data, and the input data can be stored as part of the tensor data. For example, the input data obtained is 1, 2, 3, and the input data can be converted into a vector structure [1, 2, 3] as part of the tensor data. It should be noted that the input data can be data for training the machine learning model, or data to be predicted and classified.

[0131] It should be noted that the tensor data includes data values arranged according to a preset data structure, i.e., the input data described above, and can also include information of the tensor data calculated from the data values and gradient functions of the tensor data with respect to the data values. The information of the tensor data calculated from the data values can include variables of the tensor data, data value storage addresses, and data values, as long as it indicates that the corresponding node of the tensor data is a predecessor node of the corresponding node of the tensor data calculated from the data values. Taking the function relationship y = wx + b as an example, for the tensor data y, it includes data values corresponding to y such as [1, 2, 3], and also includes information of the tensor data calculated from w, x, and b of y, and gradient functions of y with respect to w, x, and b. In a possible implementation, the information can include data value storage addresses of w, x, and b, and the tensor data y includes a gradient function x of y with respect to w, a gradient function w of y with respect to x, and a gradient function 1 of y with respect to b. Then, when training the machine learning model, the gradient values of y with respect to w, x, and b are calculated by back propagation. Specifically, the data values of y, w, x, and b and the corresponding gradient functions can be directly obtained from the tensor data y, and the gradient values of y with respect to w, x, and b are calculated based on the data values and the corresponding gradient functions.

[0132] Specifically, for the quantum module 32, the quantum computing layer of the machine learning model can be created by calling the quantum module 32. The quantum computing layer is a program module containing a quantum program, which can be used to implement quantum computing of the corresponding quantum program. By encapsulating the quantum program according to certain standards, the quantum computing layer is convenient to use when creating and training the machine learning model. The part of the machine learning model implemented by quantum computing can be understood as the corresponding quantum computing layer. The quantum program is a program for implementing quantum computing. The quantum program can be obtained by calling the quantum module 32 to create quantum logic gates acting on quantum bits in a specific order, and the quantum program can be encapsulated to obtain the quantum computing layer.

[0133] Specifically, for the classical module 33, a classical computing layer for creating a machine learning model can be created by calling the classical module 33, which is a classical computing part in the machine learning model, which can be obtained by encapsulating the created classical computing program according to certain standards by the classical module 33, so that the classical computing layer is convenient for use when training the machine learning model. After creating the quantum computing layer and the classical computing layer, they can be encapsulated by the classical module 33 to create an abstract class layer that meets certain standards, which is realized by the method of class in the programming language. By encapsulating the quantum computing layer and the classical computing layer, a machine learning model that meets certain standards can be created, for example, the created abstract class layer defines the way of forward operation of the machine learning model, which is convenient for forward operation of the machine learning model to obtain the calculation result used to calculate the loss function when training the machine learning model, and the order relationship of gradient calculation when backward calculation can also be obtained. The classical module 33 can also be used to create a training layer of the machine learning model to train the machine learning model.

[0134] In addition, the classical module 33 can be called to determine the first computing layer to be executed corresponding to the tensor data from the plurality of computing layers; a computation graph including a computing node corresponding to the first computing layer is created based on the forward propagation relationship; and the output result of the machine learning model is determined based on the computation graph, and the forward operation of the machine learning model is completed. The specific operation process can be referred to the description of the related steps in the subsequent data processing method.

[0135] In step S21, the quantum module 32 can be called to create a quantum computing layer, the classical module 33 can be called to create a classical computing layer, and the classical module 33 can be used to encapsulate the quantum computing layer and the classical computing layer to obtain a machine learning model with mixed quantum computing and classical computing. Of course, the quantum module 32 can be called to create a quantum computing layer, and then the classical module 33 can be used to encapsulate the quantum computing layer to obtain a pure quantum machine learning model. At the same time, for the input target data, the data structure module 31 can be called to create tensor data containing the input data for inputting the machine learning model. The created machine learning model has a plurality of computing layers, for example, a plurality of quantum computing layers, or a plurality of classical computing layers, or a plurality of mixed quantum computing layers and classical computing layers. The plurality of computing layers have a forward propagation relationship to determine the data transmission relationship between the plurality of computing layers when the machine learning model is forward operated, for example, the output of one computing layer is the input of another computing layer.

[0136] In step S22, the to-be-executed calculation layer of the tensor data as the dependent variable can be determined according to the calculation relationship of the plurality of calculation layers in the machine learning model. For example, the machine learning model has two calculation layers, the first one is w=c*d, and the second one is y=w*x. The tensor data corresponding to the input data is x. At this time, since x is the dependent variable in the calculation layer y=w*x, the calculation layer can be taken as the to-be-executed first calculation layer.

[0137] After the first calculation layer is determined, step S23 is executed to create a new calculation graph, which can include the sub-calculation graph corresponding to the first calculation layer.

[0138] Optionally, in step S23, referring to Figure 4 , the calculation graph including the sub-calculation graph corresponding to the first calculation layer is created based on the forward propagation relationship, including:

[0139] S231, whether there is an unexecuted second calculation layer associated with the first calculation layer before the first calculation layer is determined based on the forward propagation relationship.

[0140] S232, if there is an unexecuted second calculation layer associated with the first calculation layer, the second calculation layer is executed, and the calculation relationship between the output of the second calculation layer and the output of the first calculation layer is determined.

[0141] S233, the sub-calculation graph corresponding to the first calculation layer is added to the calculation graph corresponding to the second calculation layer based on the calculation relationship, to obtain a new calculation graph.

[0142] In step S231, the output of the second calculation layer can be the input of the first calculation layer, i.e., the dependent variable, so the second calculation layer needs to be executed before the first calculation layer can be executed, and therefore the forward propagation relationship is used to determine whether there is an unexecuted second calculation layer before the first calculation layer.

[0143] In step S232, if the second calculation layer is not executed and has the aforementioned association with the first calculation layer, for example, the output of the second calculation layer is the input of the first calculation layer, the second calculation layer is executed. Specifically, the sub-calculation graph of the second calculation layer can be created first, then the sub-calculation graph is added to the calculation graph corresponding to the executed calculation layer, and then the second calculation layer is executed based on the calculation graph to obtain the output of the second calculation layer. In addition, the calculation relationship between the output and the output of the first calculation layer needs to be determined, for example, the output is the dependent variable of the output of the first calculation layer.

[0144] In step S233, the sub-calculation graph corresponding to the first calculation layer can be created, and then the sub-calculation graph is added to the calculation graph corresponding to the second calculation layer to obtain a new calculation graph.

[0145] Optionally, in step S233, referring to Figure 5 , the first computing layer corresponding sub-computing graph is added to the second computing layer corresponding computing graph based on the computing relationship, to obtain a new computing graph, including:

[0146] S2331, the output corresponding computing node of the first computing layer is added to the second computing layer corresponding computing graph as a successor node of the output corresponding computing node of the second computing layer, based on the computing relationship.

[0147] S2332, the dependent variable corresponding computing node of the first computing layer is added to the second computing layer corresponding computing graph as a predecessor node of the output corresponding computing node of the first computing layer, to obtain a new computing graph.

[0148] In step S2331, the output of the first computing layer is obtained according to the output of the second computing layer, so the output corresponding computing node of the first computing layer is added to the second computing layer corresponding computing graph as a successor node of the output corresponding computing node of the second computing layer, and the specific implementation can refer to the graph structure of the data structure, for example, the relationship can be represented according to a linked list.

[0149] In step S2332, the output of the first computing layer is also obtained according to the dependent variable other than the output of the second computing layer, so the dependent variable corresponding computing node of the first computing layer can be added to the computing graph as a predecessor node of the output corresponding computing node of the first computing layer, to obtain a new computing graph.

[0150] For example, referring to Figure 6, the machine learning model comprises a plurality of calculation layers, the first two calculation layers are w=c*d and y=w*x respectively, wherein x is tensor data, since the tensor data x is located in the calculation layer y=w*x, the calculation layer is a first calculation layer, and there is a second calculation layer w=c*d before the first calculation layer, therefore, when the calculation graph is created, a sub-computation graph 61 corresponding to the second calculation layer is created, and the sub-computation graph 61 is taken as a new calculation graph. When the sub-computation graph 61 is created, since c and d are dependent variables of w, the calculation node 611 corresponding to c and the calculation node 613 corresponding to d are taken as predecessor nodes of the calculation node 612 corresponding to w, the sub-computation graph 61 is created, and the first calculation layer is executed according to the sub-computation graph 61, and then the second calculation layer is executed. The calculation node 614 corresponding to the output y of the first calculation layer is taken as a successor node of the calculation node 612 corresponding to the output w of the second calculation layer, and is added to the calculation graph corresponding to the second calculation layer, that is, the sub-computation graph 61, and then for the calculation node 615 corresponding to x, since x is a dependent variable of y, the calculation node 615 is taken as a predecessor node of the calculation node 614 and is added to the calculation graph corresponding to the second calculation layer, to obtain a new calculation graph, which is composed of the calculation node 611, the calculation node 612, the calculation node 613, the calculation node 614 and the calculation node 615. Of course, for subsequent calculation layers, the same method can be used to first construct a sub-computation graph corresponding to the calculation layer, and then add the sub-computation graph to the calculation graph of the executed calculation layer to obtain a new calculation graph. And the output of the calculation layer can be obtained according to the new calculation graph.

[0151] Optionally, in step S24, referring to Figure 7 , determining an output result of the machine learning model based on the calculation graph, comprising:

[0152] S241, executing the first calculation layer based on the calculation graph to obtain the output of the first calculation layer.

[0153] S242, determining the output result of the machine learning model based on the output of the first calculation layer.

[0154] In step S241, the calculation node of the calculation graph can include a formula of forward operation, for example, for the calculation node 614 in Figure 6 , the calculation formula y=w*x can be stored in the calculation node 614, specifically, a list corresponding to the calculation node 614 can be created, and the calculation formula is stored in the list. Further, the output of the first calculation layer is calculated according to the predecessor node of the calculation node 614 and the calculation formula in the calculation node 614. It should be noted that, referring to Figure 6For the computing node 616 performing quantum computing, the quantum program corresponding to the respective quantum circuit 6161 is stored in the computing node 616, and the action of the quantum circuit 6161 on the quantum bit can be equivalent to the unitary matrix U(x; θ).

[0155] In step S242, according to the output of the first computing layer, the sub-computing graph of the subsequent computing layer can be continuously added to the computing graph of the executed computing layer, and the corresponding computing layer can be executed according to the obtained new computing graph, until all the computing layers are executed, and the output result of the machine learning model can be obtained, for example, the calculation result of the last computing layer can be the output result of the machine learning model.

[0156] Based on the above technical solution, for the machine learning model created by calling the machine learning framework, in the multiple computing layers included in the machine learning model, the first computing layer to be executed is first determined, and then a computing graph including the sub-computing graph corresponding to the first computing layer is created, and then the output result of the machine learning model is determined according to the computing graph, that is, for each computing layer, the computing graph is created and executed immediately, without creating the computing graphs of all the computing layers and then executing them, and then when debugging the machine learning model, the machine learning model can be run layer by layer, and the debugging can be performed according to the result of running layer by layer, so as to facilitate positioning the problem of the machine learning model, reduce the difficulty of debugging the machine learning model, and speed up the debugging efficiency.

[0157] Figure 8 Another flowchart of a data processing method according to an example embodiment is shown, see Figure 8 The method can be applied to an electronic device including a machine learning framework 30 as shown in Figure 3 The machine learning framework 30 includes a data structure module 31, a quantum module 32, and a classical module 33, and the method includes:

[0158] S81, calling the data structure module to obtain input data and create tensor data including the input data, calling the quantum module and the classical module to create a machine learning model, the machine learning model including multiple computing layers and a forward propagation relationship between the multiple computing layers.

[0159] S82, determining a first computing layer to be executed corresponding to the tensor data from the multiple computing layers.

[0160] S83, determining whether there is an unexecuted second computing layer associated with the first computing layer before the first computing layer based on the forward propagation relationship.

[0161] S84, if there is a second computing layer associated with the first computing layer and not executed, executing the second computing layer, and determining a computing relationship between the output of the second computing layer and the output of the first computing layer.

[0162] S85, adding the sub-computing graph corresponding to the first computing layer into the computing graph corresponding to the second computing layer based on the computing relationship, to obtain a new computing graph.

[0163] S86, if there is no second computing layer associated with the first computing layer and not executed, creating the computing graph corresponding to the first computing layer.

[0164] S87, determining the output result of the machine learning model based on the computing graph.

[0165] Wherein, step S81 and step S82 can refer to step S21 and step S22 respectively, and step S83 to step S85 can refer to step S231 to step S233 respectively, and step S87 can refer to step S24.

[0166] In step S83, if it is determined that there is no second computing layer associated with the first computing layer and not executed before the first computing layer, step S86 is entered to directly create the computing graph corresponding to the first computing layer. Specifically, the output of the first computing layer can be taken as the successor node of the dependent variable corresponding to the computing node of the first computing layer, and the corresponding computing graph can be created. Subsequently, the output result of the machine learning model can be determined according to the created computing graph.

[0167] Figure 9 Another flowchart of a data processing method according to an exemplary embodiment is shown, referring to Figure 9 The method can be applied to an electronic device comprising a machine learning framework 30 as shown in Figure 3 The machine learning framework 30 comprises a data structure module 31, a quantum module 32 and a classical module 33, and the method comprises:

[0168] S91, calling the data structure module to obtain input data and create tensor data comprising the input data, and calling the quantum module and the classical module to create a machine learning model, the machine learning model comprising a plurality of computing layers and a forward propagation relationship between the plurality of computing layers.

[0169] S92, determining a first computing layer to be executed corresponding to the tensor data from the plurality of computing layers.

[0170] S93, creating a computing graph comprising a sub-computing graph corresponding to the first computing layer based on the forward propagation relationship.

[0171] S94, determining an output result of the machine learning model based on the computation graph.

[0172] S95, invoking the classical module to create a training layer of the machine learning model.

[0173] S96, inputting the output result of the machine learning model into the training layer, so as to add a corresponding sub-computation graph of the training layer to the computation graph based on the relationship between the training layer and the machine learning model.

[0174] S97, updating parameters of the machine learning model based on the computation graph, so as to obtain a trained machine learning model.

[0175] Wherein, the step S91 to step S94 can refer to step S21 to step S24 respectively.

[0176] After obtaining the output result of the machine learning model, the step S95 can be executed to create a training layer for training the machine learning model. Of course, the training layer can also be created when the machine learning model is created, and the present application does not make specific limitation thereon.

[0177] Optionally, referring to Figure 10 , the training layer comprises a loss function layer and an optimizer layer, and the classical module 33 comprises:

[0178] a loss function unit 331 configured to calculate a loss function of the machine learning model;

[0179] an optimizer unit 332 configured to update parameters of the machine learning model based on the loss function when training the machine learning model, so as to optimize the machine learning model.

[0180] Optionally, referring to Figure 11 , in the step S95, the classical module is invoked to create a training layer of the machine learning model, comprising:

[0181] S951, invoking the loss function unit to create the loss function layer.

[0182] S952, invoking the optimizer unit to create the optimizer layer.

[0183] Specifically, the loss function unit 331 is configured to calculate a loss function of the machine learning model, for example, the square of the difference between the output result of the machine learning model and the label data, or the binary cross entropy between the output result and the label data. The optimizer unit 332 is configured to update the parameters of the machine learning model according to the gradient of the loss function with respect to the parameters of the machine learning model, and optimize the machine learning model by using a gradient descent algorithm. For example, the gradient descent algorithm used by the optimizer can be any one of a stochastic gradient descent (SGD) algorithm, an adaptive gradient algorithm (Adagrad), an adaptive moment estimation (Adam) algorithm, and other algorithms. The present application does not make specific limitations on the types of loss functions calculated by the loss function unit 331 and the method used by the optimizer unit 332 to update the parameters.

[0184] To train the machine learning model, the loss function unit 331 can be called to create the loss function layer, which is a packaged calculation module that defines the calculation method of the loss function. When the prediction result of the machine learning model is input into the loss function layer, the loss function of the machine learning model can be calculated according to the calculation method defined by the loss function layer. After the loss function layer is created, the optimizer unit 332 can be called to create the optimizer layer to update the parameters of the machine learning model according to the loss function after the prediction result is input into the loss function layer and the loss function is calculated, until the appropriate parameters are obtained to make the machine learning model achieve the expected effect, and the optimization of the machine learning model is completed.

[0185] In step S96, the output result is input into the training layer to start the training process of the machine learning model. At this time, the above-mentioned calculation method can be used to add the training layer corresponding sub-computation graph to the computation graph according to the relationship between the training layer and the machine learning model. Then in step S97, the parameters of the machine learning model are updated according to the computation graph to obtain the trained machine learning model.

[0186] Optionally, in step S96, the output result of the machine learning model is input into the training layer to add the training layer corresponding sub-computation graph to the computation graph based on the relationship between the training layer and the machine learning model, including:

[0187] The output result of the machine learning model is input into the loss function layer to calculate a value of the loss function of the machine learning model, and the value of the loss function is added to the computational graph as a successor node of the output result corresponding computational node of the machine learning model.

[0188] Since the value of the loss function is calculated according to the output result of the machine learning model, the value of the loss function, that is, the output of the loss function, can be added to the computational graph as a successor node of the output result corresponding computational node of the machine learning model. Referring to Figure 6 , the output result corresponding computational node of the machine learning model is 617, and the value of the loss function Loss can be added to the computational graph as a successor node of the computational node 617.

[0189] Optionally, in step S97, referring to Figure 12 , the parameters of the machine learning model are updated based on the computational graph to obtain the trained machine learning model, including:

[0190] S971, when it is determined that the value of the loss function does not satisfy the preset condition, the value of the loss function is input into the optimizer layer to update the parameters of the machine learning model based on the value of the loss function and the computational graph.

[0191] S972, the value of the loss function of the machine learning model after updating the parameters is determined.

[0192] S973, when it is determined that the value of the loss function satisfies the preset condition, the machine learning model after updating the parameters is taken as the trained machine learning model.

[0193] In step S971, whether the value of the loss function satisfies the preset condition can be determined by comparing the value of the loss function with a preset threshold value, for example, when it is determined that the value of the loss function is greater than or equal to the threshold value, the value of the loss function is input into the optimizer layer. Of course, other methods can also be used to determine that the value of the loss function does not satisfy the preset condition, as long as the current machine learning model can be determined to not meet the expectation through the value of the preset function. When the preset condition is not satisfied, the value of the loss function is input into the optimizer layer, the gradient of the loss function with respect to the parameters of the machine learning model can be calculated based on the chain rule of differentiation using the value of the loss function and the relationship between the data corresponding computational nodes in the computational graph, and then the parameters of the machine learning model are updated based on the gradient descent algorithm.

[0194] In step 972, after updating the parameters of the machine learning model, the value of the corresponding loss function is recalculated. It is determined whether the value of the loss function meets the preset condition. If not, it can return to step S971 to continue updating the parameters of the machine learning model according to the value of the loss function. If yes, it can proceed to step S973.

[0195] In step S973, when it is determined that the value of the loss function meets the preset condition, for example, the value of the loss function is less than a threshold, it means that the difference between the output result of the machine learning model and the label data is small, and the machine learning model can achieve the expected application effect. Therefore, the machine learning model after updating the parameters is regarded as the trained machine learning model, and the updating of the parameters is stopped.

[0196] Optionally, referring to Figure 13 In step S971, the parameters of the machine learning model are updated based on the value of the loss function and the computation graph, including:

[0197] S9711, calculating the gradient of the loss function with respect to the parameters of the machine learning model based on the value of the loss function and the computation graph.

[0198] S9712, updating the parameters of the machine learning model based on the gradient and the gradient descent algorithm.

[0199] In step S9711, for example, the partial derivative of the loss function with respect to its parameters can be calculated to obtain the gradient of the loss function with respect to the parameters. In step S9712, the obtained gradient is input into the related formula of the gradient descent algorithm to update the parameters of the machine learning model. The gradient reflects the direction in which the loss function changes fastest. By using the gradient descent algorithm, the parameters can be quickly changed, and the speed of the change of the value of the loss function can be improved, so as to quickly find the parameters corresponding to the value of the loss function that meets the preset condition, and obtain the machine learning model that meets the requirements.

[0200] Optionally, referring to Figure 14 In step S9711, the gradient of the loss function with respect to the parameters of the machine learning model is calculated based on the value of the loss function and the computation graph, including:

[0201] S97111, determining the path from the calculation node corresponding to the loss function to the calculation node corresponding to the parameter of the machine learning model in the computation graph.

[0202] S97112, calculating the intermediate gradient of each calculation node on the path with respect to the predecessor node of the calculation node based on the value of the loss function.

[0203] S97113, multiply all the intermediate gradients calculated to obtain the gradient of the loss function with respect to the parameters.

[0204] In step S97111, the shortest path between the loss function and the selected parameter can be determined in the computation graph. Then in step S97112, for each computing node on the path, the intermediate gradient of the computing node with respect to its predecessor node is calculated. Since the non-leaf node has no predecessor node, the non-leaf node cannot calculate the corresponding intermediate gradient, and the non-leaf node is generally a parameter, so it is not necessary to calculate the gradient as the endpoint of the path.

[0205] After the intermediate gradient is calculated, step S97113 is performed to multiply all the intermediate gradients corresponding to the aforementioned path, and the gradient of the loss function with respect to the parameter can be obtained according to the chain rule.

[0206] Figure 15 is a block diagram of a data processing apparatus according to an exemplary embodiment, which can be applied to an electronic device including a machine learning framework 30 as shown in Figure 3 The machine learning framework 30 includes a data structure module 31, a quantum module 32, and a classical module 33. The apparatus 150 includes:

[0207] A first creation module 151 is configured to call the data structure module to obtain input data and create tensor data including the input data, and call the quantum module and the classical module to create a machine learning model, the machine learning model including a plurality of computing layers and a forward propagation relationship between the plurality of computing layers.

[0208] A determination module 152 is configured to determine a first computing layer to be executed corresponding to the tensor data from the plurality of computing layers.

[0209] A second creation module 153 is configured to create a computation graph including a computing node corresponding to the first computing layer based on the forward propagation relationship.

[0210] An output module 154 is configured to determine an output result of the machine learning model based on the computation graph.

[0211] Optionally, the second creation module 153 is further configured to:

[0212] determine whether there is an unexecuted second computing layer associated with the first computing layer before the first computing layer based on the forward propagation relationship;

[0213] when there is an unexecuted second computing layer associated with the first computing layer, execute the second computing layer, and determine a computing relationship between an output of the second computing layer and an output of the first computing layer.

[0214] add the sub-computing graph corresponding to the first computing layer into the computing graph corresponding to the second computing layer based on the computing relationship, to obtain a new computing graph.

[0215] Optionally, the apparatus 150 further includes:

[0216] a third creating module, configured to create the computing graph corresponding to the first computing layer when there is no unexecuted second computing layer associated with the first computing layer.

[0217] Optionally, the second creating module 153 is further configured to:

[0218] add, as a successor node of an output corresponding computing node of the second computing layer, the output corresponding computing node of the first computing layer into the computing graph corresponding to the second computing layer based on the computing relationship;

[0219] add, as a predecessor node of the output corresponding computing node of the first computing layer, a dependent variable corresponding computing node of the first computing layer into the computing graph corresponding to the second computing layer, to obtain a new computing graph.

[0220] Optionally, the output module 154 is further configured to:

[0221] execute the first computing layer based on the computing graph, to obtain an output of the first computing layer;

[0222] determine an output result of the machine learning model based on the output of the first computing layer.

[0223] Optionally, the apparatus 150 further includes:

[0224] a fourth creating module, configured to invoke the classical module to create a training layer of the machine learning model;

[0225] an input module, configured to input an output result of the machine learning model into the training layer, to add a sub-computing graph corresponding to the training layer into the computing graph based on a relationship between the training layer and the machine learning model;

[0226] an updating module, configured to update a parameter of the machine learning model based on the computing graph, to obtain a trained machine learning model.

[0227] Optionally, as Figure 3 shown, the training layer includes a loss function layer and an optimizer layer, and the classical module 33 includes:

[0228] a loss function unit 331, configured to calculate a loss function of the machine learning model;

[0229] The optimizer unit 332 is configured to update parameters of the machine learning model based on the loss function when training the machine learning model, so as to optimize the machine learning model.

[0230] The fourth creation module is further configured to:

[0231] The loss function unit is called to create the loss function layer.

[0232] The optimizer unit is called to create the optimizer layer.

[0233] Optionally, the input module is further configured to:

[0234] The output result of the machine learning model is input into the loss function layer, so as to calculate a value of the loss function of the machine learning model, and the value of the loss function is added to the computational graph as a successor node of a corresponding computing node of the output result of the machine learning model.

[0235] The update module is further configured to:

[0236] When it is determined that the value of the loss function does not satisfy a preset condition, the value of the loss function is input into the optimizer layer, so as to update the parameters of the machine learning model based on the value of the loss function and the computational graph.

[0237] The value of the loss function of the machine learning model after the parameters are updated is determined.

[0238] When it is determined that the value of the loss function satisfies a preset condition, the machine learning model after the parameters are updated is taken as the trained machine learning model.

[0239] Optionally, the update module is further configured to:

[0240] The gradient of the loss function with respect to the parameters of the machine learning model is calculated based on the value of the loss function and the computational graph.

[0241] The parameters of the machine learning model are updated based on the gradient and a gradient descent algorithm.

[0242] Optionally, the update module is further configured to:

[0243] The path from the computing node corresponding to the loss function to the computing node corresponding to the parameters of the machine learning model is determined in the computational graph.

[0244] The intermediate gradient of each computing node of a non-leaf node on the path with respect to a predecessor node of the computing node is calculated based on the value of the loss function.

[0245] multiply all the intermediate gradients calculated to obtain the gradient of the loss function with respect to the parameters.

[0246] As to the apparatus in the above-mentioned embodiments, the specific manners in which the respective modules perform operations have been described in detail in the embodiments of the method, and thus will not be described in detail here.

[0247] Still another embodiment of the present application further provides a storage medium, wherein a computer program is stored in the storage medium, and the computer program is arranged to execute the steps in the above-mentioned data processing method embodiments when running.

[0248] Specifically, in the present embodiment, the above-mentioned storage medium can include but is not limited to: a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various media that can store computer programs.

[0249] Still another embodiment of the present application further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is arranged to execute the computer program to perform the steps in the above-mentioned data processing method embodiments.

[0250] Specifically, the above-mentioned electronic device can further comprise a transmission device and an input-output device, wherein the transmission device is connected to the processor, and the input-output device is connected to the processor.

[0251] Specifically, in the present embodiment, the above-mentioned processor can be arranged to execute the following steps through the computer program:

[0252] calling the data structure module to obtain input data and create tensor data comprising the input data, calling the quantum module and the classical module to create a machine learning model, the machine learning model comprising a plurality of computing layers and a forward propagation relationship between the plurality of computing layers;

[0253] determining a first computing layer to be executed corresponding to the tensor data from the plurality of computing layers;

[0254] creating a computing graph comprising a sub-computing graph corresponding to the first computing layer based on the forward propagation relationship;

[0255] determining an output result of the machine learning model based on the computing graph.

[0256] The above detailed description of the structure, features and effects of the present application is based on the embodiments shown in the drawings. The above description is only the preferred embodiments of the present application, but the present application is not limited to the embodiments shown in the drawings. Any changes or modifications made in accordance with the concept of the present application, or equivalent embodiments with equivalent changes, are still within the scope of the present application.

Claims

1. A data processing method, characterized in that, Applied to electronic devices including a machine learning framework, the machine learning framework comprising a data structure module, a quantum module, and a classical module, the method includes: The data structure module is invoked to obtain input data and create tensor data including the input data. The quantum module and the classical module are invoked to create a machine learning model. The machine learning model includes multiple computational layers and the forward propagation relationship between the multiple computational layers. The computation layer with the tensor data as the dependent variable is determined from among the multiple computation layers as the first computation layer to be executed; Based on the forward propagation relationship, a computation graph is created that includes the sub-computation graph corresponding to the first computation layer, comprising: Based on the forward propagation relationship, determine whether there is an unexecuted second computation layer associated with the first computation layer before the first computation layer; if there is an unexecuted second computation layer associated with the first computation layer, execute the second computation layer and determine the computation relationship between the output of the second computation layer and the output of the first computation layer; based on the computation relationship, add the sub-computation graph corresponding to the first computation layer to the computation graph corresponding to the second computation layer to obtain a new computation graph; The output of the machine learning model is determined based on the computation graph.

2. The method as described in claim 1, characterized in that, The method further includes: If there is no unexecuted second computation layer associated with the first computation layer, then the computation graph corresponding to the first computation layer is created.

3. The method as described in claim 1, characterized in that, The step of adding the sub-computation graph corresponding to the first computational layer to the computational graph corresponding to the second computational layer based on the computational relationship to obtain a new computational graph includes: Based on the computational relationship, the computational node corresponding to the output of the first computational layer is added to the computational graph corresponding to the output of the second computational layer as the successor node of the second computational layer. The computational node corresponding to the dependent variable of the first computational layer is added to the computational graph corresponding to the output of the first computational layer as the predecessor node of the first computational layer, and a new computational graph is obtained.

4. The method as described in claim 1, characterized in that, Determining the output of the machine learning model based on the computation graph includes: The first computation layer is executed based on the computation graph to obtain the output of the first computation layer; The output of the machine learning model is determined based on the output of the first computational layer.

5. The method as described in claim 1, characterized in that, The method further includes: The classic module is invoked to create the training layer of the machine learning model; The output of the machine learning model is input into the training layer, and a sub-computation graph corresponding to the training layer is added to the computation graph based on the relationship between the training layer and the machine learning model. The parameters of the machine learning model are updated based on the computation graph to obtain the trained machine learning model.

6. The method as described in claim 5, characterized in that, The training layer includes a loss function layer and an optimizer layer, and the classic module includes: The loss function unit is configured to compute the loss function of the machine learning model; An optimizer unit is configured to update the parameters of the machine learning model based on the loss function during training of the machine learning model in order to optimize the machine learning model. The step of calling the classic module to create the training layer of the machine learning model includes: The loss function layer is created by calling the loss function unit; The optimizer layer is created by invoking the optimizer unit.

7. The method as described in claim 6, characterized in that, The step of inputting the output of the machine learning model into the training layer, and adding a corresponding sub-computation graph of the training layer to the computation graph based on the relationship between the training layer and the machine learning model, includes: The output of the machine learning model is input into the loss function layer to calculate the value of the loss function of the machine learning model, and the calculation node corresponding to the value of the loss function is added to the computation graph as the successor node of the calculation node corresponding to the output of the machine learning model. The step of updating the parameters of the machine learning model based on the computation graph to obtain the trained machine learning model includes: When it is determined that the value of the loss function does not meet the preset conditions, the value of the loss function is input into the optimizer layer to update the parameters of the machine learning model based on the value of the loss function and the computation graph; Determine the value of the loss function of the machine learning model after updating the parameters; When the value of the loss function is determined to meet the preset conditions, the machine learning model with the updated parameters is used as the trained machine learning model.

8. The method as described in claim 7, characterized in that, The updating of the parameters of the machine learning model based on the value of the loss function and the computation graph includes: The gradient of the loss function with respect to the parameters of the machine learning model is calculated based on the value of the loss function and the computation graph. The parameters of the machine learning model are updated based on the gradient and gradient descent algorithm.

9. The method as described in claim 8, characterized in that, The step of calculating the gradient of the loss function with respect to the parameters of the machine learning model based on the value of the loss function and the computation graph includes: In the computation graph, determine the path from the computation node corresponding to the loss function to the computation node corresponding to the parameters of the machine learning model; Based on the value of the loss function, calculate the intermediate gradient of each computation node on the path relative to its predecessor node for each non-leaf node; Multiplying all the calculated intermediate gradients together yields the gradient of the loss function relative to the parameters.

10. A data processing apparatus, characterized in that, An electronic device incorporating a machine learning framework, the machine learning framework including a data structure module, a quantum module, and a classical module, the device comprising: The first creation module is used to call the data structure module to obtain input data and create tensor data including the input data, and to call the quantum module and the classical module to create a machine learning model. The machine learning model includes multiple computational layers and forward propagation relationships between the multiple computational layers. A determination module is used to determine, from among the multiple computation layers, the computation layer in which the tensor data is the dependent variable as the first computation layer to be executed; The second creation module is used to create a computation graph including the computation nodes corresponding to the first computation layer based on the forward propagation relationship, including: Based on the forward propagation relationship, determine whether there is an unexecuted second computation layer associated with the first computation layer before the first computation layer; if there is an unexecuted second computation layer associated with the first computation layer, execute the second computation layer and determine the computation relationship between the output of the second computation layer and the output of the first computation layer; based on the computation relationship, add the sub-computation graph corresponding to the first computation layer to the computation graph corresponding to the second computation layer to obtain a new computation graph; The output module is used to determine the output result of the machine learning model based on the computation graph.

11. A machine learning framework, characterized in that, The framework includes: The data structure module is configured to acquire input data and create tensor data including the input data; The quantum module is configured to create machine learning models; The classic module is configured to create a machine learning model, which includes multiple computational layers and forward propagation relationships between the multiple computational layers. The classic module is further configured to determine, from among the multiple computation layers, the computation layer with the tensor data as the dependent variable as the first computation layer to be executed; create a computation graph including the computation nodes corresponding to the first computation layer based on the forward propagation relationship, including: determining, based on the forward propagation relationship, whether there is an unexecuted second computation layer associated with the first computation layer before the first computation layer; if there is an unexecuted second computation layer associated with the first computation layer, then execute the second computation layer, and determine the computational relationship between the output of the second computation layer and the output of the first computation layer; add the sub-computation graph corresponding to the first computation layer to the computation graph corresponding to the second computation layer based on the computational relationship to obtain a new computation graph; and determine the output result of the machine learning model based on the computation graph.

12. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the method described in any one of claims 1 to 9 when it is run.

13. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1 to 9.

Citation Information

Patent Citations

  • Method and device for constructing deep learning network model, equipment and storage medium

    CN112270403A