Framework modification method, device, computer equipment and storage medium
By modifying the initialization and data conversion methods of the deep learning framework, the problem of hybrid computing between quantum chips and deep learning frameworks was solved, realizing efficient hybrid computing and model training between quantum devices and deep learning frameworks.
Patent Information
- Application Number
- CN202311056898.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-08-22
- Publication Date
- 2025-12-26
- Estimated Expiration
- 2043-08-22
AI Technical Summary
Quantum chips cannot be used in hybrid computing with deep learning frameworks because of problems such as the inability to extract intermediate data, the non-differentiability of quantum computing nodes, and the isolation of parameters, which prevent direct differentiation and parameter optimization.
A framework modification method is provided, which receives modification instructions, utilizes initialization, prediction and feedback modification function information to initialize the computation graph and encoding and weight dictionary of the quantum device, transforms the input data into quantum input data, and calculates the loss value to generate the target quantum framework, thereby realizing hybrid computation of quantum device and deep learning framework.
It realizes hybrid computing of quantum devices and deep learning frameworks, improving computational efficiency and the ability of model training to learn and converge quickly.
Smart Images

Figure CN116862009B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of quantum computing, and in particular to a framework modification method and device, computer equipment, a storage medium and a computer program product. BACKGROUND
[0002] Deep learning frameworks are tools used to build, train, and deploy deep neural networks. They provide a range of functions and tools that make it easier for researchers and developers to build and manage large-scale neural networks.
[0003] Quantum chips are chips based on the principles of quantum mechanics, used to build the core components of quantum computers. They usually contain a series of quantum bits (qubits) and circuits to control, read and measure qubits. Compared with traditional computing chips, they have stronger parallel computing capabilities, high precision, etc.
[0004] However, when quantum chips are used as hardware computing devices for large-scale data processing as a computing graph node, there are limitations such as the inability to extract intermediate data and the inability to directly differentiate computing graph nodes with quantum computing participation, which prevent quantum chips from being used for hybrid computing with deep learning frameworks. SUMMARY
[0005] Therefore, it is necessary to provide a framework modification method and device, computer equipment, a computer readable storage medium and a computer program product that can enable quantum devices to perform hybrid computing with deep learning frameworks.
[0006] In a first aspect, the present application provides a framework modification method. The method comprises:
[0007] receiving a modification instruction; the modification instruction carries initialization information, prediction modification function information and feedback modification function information;
[0008] initializing the to-be-improved framework environment according to the initialization information, to obtain a target framework environment; the target framework environment includes an initial computing graph, an initial encoding dictionary and an initial weight dictionary;
[0009] According to the prediction modification function information, the input data of the quantum computing node in the initial computing graph is converted into quantum input data; the quantum input data is used for quantum device execution to obtain a quantum prediction result;
[0010] According to the feedback modification function information, a loss value corresponding to the quantum prediction result is calculated, and a target bias corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary is determined according to the loss value; a target encoding dictionary and a target weight dictionary are generated by preprocessing the target bias, to obtain a target quantum framework.
[0011] In one of the embodiments, the initialization of the to-be-improved framework environment according to the initialization information in combination with the quantum device comprises:
[0012] According to the initialization information, the quantum device is instantiated to obtain an initial calculation graph; the initial calculation graph has quantum computing nodes;
[0013] The parameters of the proposed layer and the parameters of the gate circuit are loaded and initialized.
[0014] In one of the embodiments, the conversion of the input data of the quantum computing nodes in the initial calculation graph into quantum input data according to the predicted transformation function information comprises:
[0015] The input data is converted into quantum signals, and each parameter in the initial encoding dictionary and the initial weight dictionary in the converted quantum signals is converted into quantum input data.
[0016] In one of the embodiments, according to the feedback transformation function information, a loss value corresponding to the quantum prediction result is calculated, and a target bias corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary is determined according to the loss value, comprising:
[0017] The positive offset result and the negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary are calculated respectively, and a temporary bias corresponding to each quantum gate is calculated based on the positive offset result, the negative offset result and the loss value;
[0018] The temporary biases corresponding to each quantum gate are combined and preprocessed to obtain the target bias corresponding to each quantum gate in the encoding dictionary and the weight dictionary;
[0019] The target encoding dictionary and the target weight dictionary are generated by the target bias to obtain a target quantum framework.
[0020] In one of the embodiments, the calculation of the positive offset result and the negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary, and the calculation of the temporary bias based on the positive offset result, the negative offset result and the loss value, comprise: obtaining the positive offset parameter and the negative offset parameter corresponding to the initial encoding dictionary and the initial weight dictionary; calculating the positive offset result and the negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the positive offset parameter and the negative offset parameter; obtaining the temporary offset based on the positive offset result, the negative offset result and the loss value.
[0021] In a second aspect, the application further provides a hybrid computing method based on the transformation method, comprising:
[0022] Receiving sample data; the sample data carries label data;
[0023] The sample data is input into the initial model for training to obtain a target model; the initial model is executed on a quantum target framework; and the quantum target framework is obtained according to the framework transformation method in any one of the above embodiments.
[0024] In a third aspect, the present application further provides a framework transformation device, which comprises:
[0025] The receiving module is configured to receive a transformation instruction; the transformation instruction carries initialization information, prediction transformation function information, and feedback transformation function information.
[0026] The initialization module is configured to initialize a target framework environment according to the initialization information and in combination with a quantum device to improve the framework environment, so as to obtain the target framework environment; the target framework environment comprises an initial calculation graph, an initial encoding dictionary, and an initial weight dictionary.
[0027] The prediction transformation module is configured to convert input data of a quantum computing node in the initial calculation graph into quantum input data according to the prediction transformation function information; the quantum input data is used for quantum device execution to obtain a quantum prediction result.
[0028] The feedback transformation module is configured to calculate a loss value corresponding to the quantum prediction result according to the feedback transformation function information, and determine a target deviation corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the loss value, generate a target encoding dictionary and a target weight dictionary through preprocessing of the target deviation, and obtain a target quantum framework.
[0029] In a fourth aspect, the present application further provides a hybrid computing device based on the transformation method, which comprises:
[0030] The sample receiving module is configured to receive sample data; the sample data carries label data.
[0031] The training module is configured to input the sample data into an initial model for training to obtain a target model; the initial model is executed on a quantum target framework; and the quantum target framework device is obtained according to the framework transformation device in any one of the above embodiments.
[0032] In a fifth aspect, the present application further provides a computer device. The computer device comprises a memory and a processor, the memory stores a computer program, and the processor implements the steps of the method in any one of the above embodiments when executing the computer program.
[0033] In a sixth aspect, the present application further provides a computer readable storage medium. The computer readable storage medium stores a computer program, and the computer program is executed by a processor to implement the steps of the method in any one of the above embodiments.
[0034] In a seventh aspect, the present application also provides a computer program product. The computer program product comprises a computer program which, when executed by a processor, implements the steps of the method in any one of the above embodiments.
[0035] The above framework modification method, device, computer device, storage medium and computer program product, the server first receives the modification instruction, the modification instruction includes initialization information, prediction modification function information and feedback modification function information, and then the framework environment to be improved is modified according to the information in the modification instruction, so that the target quantum framework after modification can enable the quantum device and the deep learning framework to perform hybrid computing. BRIEF DESCRIPTION OF DRAWINGS
[0036] Figure 1 The application environment diagram of the framework modification method in one embodiment;
[0037] Figure 2 The computing diagram in one embodiment;
[0038] Figure 3 The quantum device diagram in one embodiment;
[0039] Figure 4 The structural block diagram of the framework modification device in one embodiment;
[0040] Figure 5 The structural block diagram of the hybrid computing device based on the modification method in one embodiment;
[0041] Figure 6 The internal structure diagram of the computer device in one embodiment. DETAILED DESCRIPTION
[0042] In order to make the purpose, technical scheme and advantages of the present application clearer, the present application will be further described in detail below in combination with the drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and do not limit the present application.
[0043] Pytorch is a deep learning model training framework that can automatically use the backward differential gradient update algorithm and the chain rule according to the forward calculation graph. As long as the forward calculation process is constructed by using the operation function in the Pytorch calculation library (i.e., the forward calculation graph is constructed), the developer does not need to consider the complex backward propagation and chain rule to construct the gradient differential propagation algorithm, and Pytorch can inversely update the gradient according to the forward construction calculation graph to achieve the learning and training of the training parameters. However, Pytorch as a classic computing device parallel acceleration framework has the following three problems:
[0044] 1. PyTorch relies on classical computing devices for both forward and backward propagation. Due to the need for parameter training and updates, PyTorch requires saving intermediate data during computation and utilizing it in subsequent calculations. This makes backward propagation particularly difficult in heterogeneous computing architectures, especially on non-von Neumann architectures, because a computation graph node is a "black box" relative to the entire computation graph. 2. Secondly, the nodes in the computation graph, i.e., the expressions participating in the feedforward computation, must be differentiable. If the expressions are not differentiable, mathematical tools or computational processes need to be manually constructed to achieve differentiation and obtain the partial derivatives. 3. The parameters in the computation graph nodes (i.e., `torch.nn.parameter`) must ensure that the partial derivative function of the function they participate in is enabled, the computation graph node containing the parameter must be within the overall computation graph, and the node cannot be located in an isolated subgraph. Only when these three conditions are met can the optimizer update the parameters.
[0045] When a quantum heterogeneous computing device participates in PyTorch training as a hardware computing device in a computational graph node, all three of the aforementioned problems arise. Viewing a quantum computing device from the perspective of a von Neumann architecture-based computing device reveals it to be a "black box" because it cannot extract intermediate data (extracting intermediate data would invalidate the computation results). Quantum computing mathematically involves tensor products, which makes direct differentiation impossible for computational graph nodes involving quantum computing; algorithms must be manually designed to achieve differentiation. Furthermore, the parameters in a quantum computational graph node (i.e., `torch.nn.parameter`) are neither differentiable nor independent in terms of feedforward and feedback, and their computation in the form of tensor products results in the parameters existing as isolated subgraphs within the computational graph. This makes it impossible for quantum computing chips to naturally perform heterogeneous hybrid computing with the PyTorch architecture.
[0046] In one embodiment, such as Figure 1 As shown, a framework modification method is provided for application to a server, including the following steps:
[0047] S102, Receive modification instructions; the modification instructions carry initialization information, prediction modification function information, and feedback modification function information.
[0048] The modification instruction is an instruction received by the computer from an external device to modify the framework. After the computer receives the instruction, the framework to be improved is improved according to initialization information, prediction modification function information and feedback modification function information carried by the modification instruction. The framework to be improved can be any one of TensorFlow (an open source deep learning framework developed by Google), PyTorch (an open source deep learning framework developed by Facebook) and Caffe (an open source deep learning framework).
[0049] The initialization information refers to all information required for initializing the framework, including parameter values, weights and bias parameters. The prediction modification function information refers to information required for modifying the prediction function. Similarly, the feedback modification function information refers to information required for modifying the feedback function.
[0050] In S104, the framework environment to be improved is initialized according to the initialization information in combination with the quantum device to obtain a target framework environment. The target framework environment includes an initial computation graph, an initial encoding dictionary and an initial weight dictionary.
[0051] The target framework environment refers to a framework that can be further modified to adapt to quantum device computing after initialization, such as a target Pytorch architecture.
[0052] Optionally, the server initializes the computation graph, the encoding dictionary and the weight dictionary in the framework to be improved according to the initial information, so that the framework to be improved adapts to the transition from classical computing to quantum device carrying. After initializing the computation graph, the encoding dictionary and the weight dictionary in the framework to be improved according to the initialization information, the corresponding initial computation graph, initial target encoding dictionary and initial weight field are obtained. The computation graph is a graph model used to describe the structure and computation process of a deep learning model, which includes various neural network layers, activation functions, loss functions and other components, as well as their connections and computation relationships.
[0053] Optionally, the initialization method includes random initialization, leader initialization and constant initialization.
[0054] Optionally, the quantum device is a device that performs computation and processing based on the principles of quantum mechanics. Unlike the binary bits (bits) used by classical computers, quantum computers use quantum bits (qubits), which can be in a superposition state of 0 and 1 at the same time, so that more complex computation and processing operations can be performed. In this embodiment, the quantum device can be a quantum chip, a superconducting quantum chip or a quantum computer.
[0055] S106, convert the input data of the quantum computing node in the initial computing graph into quantum input data according to the prediction transformation function information; the quantum input data is used for execution by the quantum device to obtain a quantum prediction result.
[0056] For example, in combination with Figure 2 As shown in the figure, Figure 2 is a computing graph schematic diagram in an embodiment, wherein input represents input, w represents weight, b represents bias, Params represents parameter, Conv represents convolution layer, Rule represents activation function, Loss represents loss function, and Tensor generally refers to a data object on a node or an edge in the graph, which can be a scalar, a vector, a matrix, or a high-dimensional array, etc. Conv, Rule, and Loss represent different nodes.
[0057] The quantum device can perform calculation on the data involved as a quantum computing node in the initial computing graph. Therefore, when the quantum computing node receives the output data of the data of the previous computing node and takes the output data as input data, the input data is first converted into quantum input data, so that the quantum device processes the data to obtain a corresponding quantum prediction result.
[0058] For example, if the quantum computing node is used for prediction model training result, the quantum prediction result represents a model prediction value. In other embodiments, the quantum prediction result can represent a numerical value output by any quantum computing node.
[0059] S108, calculate a loss value corresponding to the quantum prediction result according to the feedback transformation function information, and determine a target deviation of each quantum gate in the encoding dictionary and the weight dictionary corresponding to the loss value, generate a target encoding dictionary and a target weight dictionary through preprocessing of the target deviation, and obtain a target quantum framework.
[0060] According to the feedback transformation function information, the server first calculates a loss value corresponding to the quantum prediction result, then calculates a target deviation of each quantum gate in the initial encoding dictionary and the initial weight dictionary corresponding to each loss value, and determines a target encoding dictionary and a target weight dictionary according to the loss value and the target deviation of each quantum gate in the initial encoding dictionary and the initial weight dictionary, to obtain a target quantum framework.
[0061] In the above framework transformation method, the server first receives a transformation instruction, the transformation instruction includes initialization information, prediction transformation function information, and feedback transformation function information, then transforms the framework environment to be improved according to the information in the transformation instruction, so that the target quantum framework after transformation can enable the quantum device to perform hybrid calculation with the deep learning framework.
[0062] In one of the embodiments, the initialization of the to-be-improved framework environment according to the initialization information in combination with the quantum device includes: instantiating the quantum device according to the initialization information to obtain an initial calculation graph; the initial calculation graph has quantum computing nodes; and the parameters of the designed layer and the parameters of the gate circuit are loaded and initialized.
[0063] For example, the initialization is described by taking the to-be-improved framework as a Pytorch framework. When the server constructs the overall calculation graph, the Pytorch instantiates the quantum calculation graph node. The instantiation refers to
[0064] Optionally, in the PyTorch, the instantiation can also be understood as creating an object. For example, when creating a PyTorch tensor, a tensor object can be created by instantiating the Tensor class.
[0065] Optionally, a quantum calculation graph node containing two quantum bits can be created, and the Hadamard gate and CNOT gate operations are added to the node to instantiate the quantum device. By printing the node information, the structure and operation of the node can be viewed.
[0066] Then, the parameters of the designed layer and the parameters of the gate circuit are loaded and initialized, and the parameters of the designed layer and the parameters of the gate circuit after the initialization are put into the initial encoding dictionary and the initial weight dictionary.
[0067] For example, the parameters of the designed layer are loaded into the dictionary gateDict as the calculation parameters of the gate circuit, a random parameter is loaded as the initial calculation parameter of the gate circuit during the initialization, and the sub-dictionary is put into the dictionary encoderDict (encoding dictionary) for subsequent backward access. Finally, the designed gate circuit is loaded, the necessary data is filled into the gateDict (gate dictionary) according to the requirements, a random torch.nn.parameter parameter is loaded as the calculation parameter of the gate circuit, and the sub-dictionary is put into the dictionary weightDict (weight dictionary) for subsequent backward access.
[0068] In the above embodiment, the initialization of the calculation graph and the parameters of the designed layer and the gate circuit can help the model to learn and converge to a better solution faster when the model training is performed on the framework improvement method.
[0069] In one of the embodiments, the initialization of the to-be-improved framework environment according to the initialization information in combination with the quantum device includes: instantiating the quantum device according to the initialization information to obtain an initial calculation graph; the initial calculation graph has quantum computing nodes; and the parameters of the designed layer and the parameters of the gate circuit are loaded and initialized.
[0070] An example of a computation graph is a directed acyclic graph composed of nodes and edges, where nodes represent operations (e.g., tensor operations and function calls), and edges represent dependencies. In a computation graph, each node contains input tensors and output tensors, i.e., computation graph nodes. Instantiation generally refers to creating an instance of a class. A class is an abstract concept that describes the properties and behaviors of a data type, while an instance is a concrete, actual object that has the properties and behaviors defined by the class.
[0071] When the server uses the quantum computing node to calculate the prediction result, the output of the previous node of the quantum computation graph node is taken as the input of the quantum computation graph node, and the input data is converted into a quantum input signal so that the quantum device can perform corresponding calculations.
[0072] Optionally, the server first converts the input data into a quantum signal and converts each parameter in the initial encoding dictionary and the initial weight field included in the quantum signal into quantum input data. In other embodiments, each parameter in the quantum signal can be converted into quantum input data by a preset conversion rule.
[0073] An example of the process of converting input data into quantum input data in an embodiment is as follows:
[0074] In the forward Pytorch, the output result of the previous connected node of the quantum computation graph node is loaded into the memory of the host from the computation graph. The output result exists in the size of BatchSize*N.
[0075] The output result is polled in a for loop, and the size of the for loop is BatchSize from 0 to (BatchSize-1). There are (1*N) data in each round, and the data exists in the form of a vector. The following steps are performed in the for loop:
[0076] First step in the for loop: assign the calculation parameters of the sub-dictionary in the encoderDict to the data in this round (1*N) in order.
[0077] Second step in the for loop: edit the sub-dictionary in the encoderDict into an assembly language side according to the assembly syntax of QASM2.0 in order. Save it into the file of QASMfp.
[0078] Third step in the for loop: edit the sub-dictionary in the weightDict into an assembly language side according to the assembly syntax of QASM2.0 in order. Save it into the file of QASMfp.
[0079] for loop, the fourth step is to deliver the edited QASMfp file to the superconducting quantum computing device, and the QASMfp file is a complete QASM2.0 assembly file that can be directly executed by the superconducting quantum computing device.
[0080] for loop, the fifth step is to obtain the calculation result from the superconducting quantum computing device and save it into a list for delivery to the next graph node.
[0081] In the above embodiment, by converting the input data into quantum signals, the data can be embedded into the quantum device. Such quantum embedding can represent the data in a high-dimensional quantum space, which can provide better feature expression capability. By appropriate feature mapping, the input data can be mapped to the representation of quantum states, so as to better capture the structure and features of the input data.
[0082] In one of the embodiments, the above-mentioned calculating the loss value corresponding to the quantum prediction result according to the feedback modification function information, and determining the target deviation of each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the loss value, comprises: calculating the positive offset result and the negative offset result of each quantum gate in the initial encoding dictionary and the initial weight dictionary respectively, and calculating the temporary deviation based on the positive offset result, the negative offset result and the loss value; preprocessing the loss value and the temporary deviation of each quantum gate to obtain the target deviation of each quantum gate in the encoding dictionary and the weight dictionary; and generating a target encoding dictionary and a target weight dictionary through the target deviation to obtain a target quantum framework.
[0083] wherein the positive offset parameter refers to adding to obtain the corresponding positive offset parameter; conversely, subtracting to obtain the corresponding negative offset parameter. In other embodiments, the parameters can be positively offset and negatively offset according to actual conditions, and are not limited to Optionally, the positive offset parameter and the negative offset parameter can be pre-calculated and stored in the memory.
[0084] Optionally, the above-mentioned calculating the positive offset result and the negative offset result of each quantum gate in the initial encoding dictionary and the initial weight dictionary respectively, and calculating the temporary deviation based on the positive offset result, the negative offset result and the loss value, comprises: obtaining the positive offset parameter and the negative offset parameter corresponding to the initial encoding dictionary and the initial weight dictionary; calculating the positive offset result and the negative offset result of each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the positive offset parameter and the negative offset parameter; and obtaining the temporary offset based on the positive offset result, the negative offset result and the loss value.
[0085] Wherein, the positive offset result and the negative offset result are to replace the parameters of each quantum in the initial encoding dictionary and the initial weight dictionary with the positive offset parameters, and to perform a circuit operation to obtain a positive offset result; similarly, the parameters of each quantum in the initial encoding dictionary and the initial weight dictionary are replaced with the negative offset parameters, and a circuit operation is performed to obtain a negative offset result.
[0086] Optionally, after obtaining the positive and negative offset results, the positive offset result and the negative offset result are subtracted, and the difference is normalized. For example, the difference is multiplied by The normalization is performed to ensure the normalization of the quantum state, that is, to ensure that the probability of the quantum state is 1.
[0087] Further, the result of each quantum gate corresponding to the initial encoding dictionary and the initial weight field after normalization is multiplied by the loss value, and all the results of the quantum gates after normalization and the loss value can form a matrix. The trace of the matrix is calculated to obtain the temporary deviation of each gate.
[0088] Then, the temporary deviations of the initial weight dictionary are combined respectively to form a matrix to be processed and preprocessed. For example, the average can be taken in the column direction to obtain the modification vector of the initial weight dictionary, and the initial weight dictionary is modified according to the modification vector of the initial weight dictionary to obtain the target weight dictionary. Similarly, the above processing method can also be used to obtain the target encoding dictionary.
[0089] It should be noted that in other embodiments, the average can also be taken in the row direction, and variance operation can also be performed, and the specific calculation method is not limited in the embodiment. In the embodiment, the average is better than other calculation methods.
[0090] For example, the feedback modification function can be modified in the following way:
[0091] Step 1: In the feedback link (backward), Pytorch feeds back the loss calculated by the node receiving the output result of the quantum circuit node in the calculation graph to the quantum circuit node.
[0092] Step 2: The loss return result is polled by a for loop, and the size of the for loop is BatchSize from 0 to (BatchSize-1). There are (1*M) data in each round, which is called feedback loss, and the data exists in the form of a vector. M is the number of quantum bits in the quantum circuit.
[0093] The following steps are performed in the for loop (the loop is called an outer loop, and the loop round is called k rounds):
[0094] The first step in the first for loop: copy two copies of the parameters of each gate in encoderDict and weightsDict (assuming that there are j gates in encoderDict and v gates in weightsDict), the first copy of the parameters needs to be added, called the positive offset parameters, the second copy of the parameters needs to be subtracted, called the negative offset parameters. Perform the second for loop in the first for loop, and the size of the second for loop is the number of gates in encoderDict.
[0095] The following steps are performed in the second for loop, which loops through each gate in encoderDict, where i gate represents the i-th gate in encoderDict:
[0096] 1. Replace the parameters of the i gate with the positive offset parameters, and do not modify the remaining parameters, and perform a circuit run to obtain a (1*M) vector result, which is marked as "i gate positive offset result".
[0097] 2. Replace the parameters of the i gate with the negative offset parameters, and do not modify the remaining parameters, and perform a circuit run to obtain a (1*M) vector result, which is marked as "i gate negative offset result".
[0098] 3. Subtract the i gate positive offset result and the i gate negative offset result, and multiply the difference by 0.707, and the product result vector is marked as "i gate temporary deviation".
[0099] 4. Multiply the I gate temporary deviation by the current feedback loss of the outer loop to obtain a matrix, and calculate the trace of the matrix, which is called "i gate final deviation of the k-th round"
[0100] 5. Record the final deviation of each gate in encoderDict
[0101] After the second for loop in the first for loop is completed, perform the third for loop, and the size of the third for loop is the number of gates in weightsDict.
[0102] The following steps are performed in the third for loop, which loops through each gate in weightsDict, where w gate represents the w-th gate in weightsDict:
[0103] 1. Replace the parameters of the w gate with the positive offset parameters, and do not modify the remaining parameters, and perform a circuit run to obtain a (1*M) vector result, which is marked as "i gate positive offset result".
[0104] 2. Replace the parameters of the w gate with the negative offset parameters, and the remaining parameters are not modified, and perform a circuit operation to obtain a (1*M) vector result, which is marked as "i gate negative offset result".
[0105] 3. Subtract the w gate positive and negative offset results, multiply the difference by 0.707, and the product result vector is marked as "w gate temporary deviation".
[0106] 4. Multiply the I gate temporary deviation by the current feedback loss of the outer loop to obtain a matrix, and calculate the trace of the matrix, which is called "w gate kth round final deviation"
[0107] 5. Record the final deviation of each gate in weightsDict
[0108] Step 3: Each outer loop obtains a (1*j) and a (1*w) vector. Combine all the vectors obtained in the outer loop to form a (N*j) and a (N*w) matrix. Average the two matrices in the column direction to obtain an (1*j) size encoder feedback vector and an (1*w) size weights modification vector. The encoder feedback vector is used to feed back to the previous layer graph calculation node.
[0109] Step 4: Loop through weightsDict, and add the parameters of the gates in weightsDict to the parameters at the corresponding positions in the weights modification vector in order to obtain the new weight parameters of the gates in weightsDict.
[0110] In one embodiment, the application also provides a hybrid computing method based on the modification method, comprising: receiving sample data; the sample data carries label data; inputting the sample data into an initial model for training to obtain a target model; the initial model is executed on a quantum target framework; the quantum target framework is obtained according to the framework modification method in any one of the above embodiments.
[0111] The server obtains sample data and inputs the sample data into an initial model for training. The sample data refers to data used for model training, which can be image data, text data, etc. The initial model refers to any kind of untrained machine learning model; the target model refers to a trained model. For example, if the initial model is a machine learning model for text recognition, the target model is a trained model capable of recognizing text. Since the initial model is executed on a quantum target framework, when executing the feedforward function of the model, the feedforward function of the instantiation function is jumped, and the steps of converting the input data of the quantum calculation node in the initial calculation graph into the quantum input data recorded in the prediction modification function information in any one of the above embodiments are executed.
[0112] Exemplary, in conjunction with Figure 3 shown, Figure 3 is a schematic diagram of a quantum device in an embodiment, which is composed of three parts, |0> represents the input, H and Y represent the proposed layer, the cross circle represents the weight layer, and the X gate is used. In initialization, the gateDict of the H and Y gates has been put into the encoderDict.
[0113] It should be understood that, although the steps in the flowcharts involved in the embodiments described above are shown in sequence according to the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, the execution of these steps is not strictly limited in sequence, and these steps can be executed in other orders. Moreover, at least part of the steps in the flowcharts involved in the embodiments described above can include multiple steps or stages, which are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but can be executed alternately or alternately with at least part of other steps or steps or stages in other steps.
[0114] Based on the same inventive concept, the embodiments of the present application also provide a framework reconstruction device for implementing the above-mentioned framework reconstruction method. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme described in the above method, so the specific limitations in one or more framework reconstruction device embodiments provided below can refer to the limitations of the framework reconstruction method in the above, which will not be repeated here.
[0115] In one embodiment, as Figure 4 shown, a framework reconstruction device is provided, comprising: a receiving module 100, an initialization module 200, a prediction reconstruction module 300 and a feedback reconstruction module 400, wherein:
[0116] The receiving module 100 is configured to receive a reconstruction instruction; the reconstruction instruction carries initialization information, prediction reconstruction function information and feedback reconstruction function information.
[0117] The initialization module 200 is configured to initialize the framework environment to be improved according to the initialization information in combination with the quantum device, to obtain a target framework environment; the target framework environment includes an initial calculation graph, an initial encoding dictionary and an initial weight dictionary.
[0118] The prediction reconstruction module 300 is configured to convert the input data of the quantum computing node in the initial calculation graph into quantum input data according to the prediction reconstruction function information; the quantum input data is used for quantum device execution to obtain a quantum prediction result.
[0119] The feedback modification module 400 is configured to calculate a loss value corresponding to the quantum prediction result according to the feedback modification function information, and determine a target bias corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the loss value, generate a target encoding dictionary and a target weight dictionary by preprocessing the target bias, and obtain a target quantum framework.
[0120] In one of the embodiments, the initialization module 200 includes:
[0121] The instantiation unit is configured to instantiate the quantum device according to the initialization information to obtain an initial calculation graph, and the initial calculation graph has quantum calculation nodes.
[0122] The loading unit is configured to load and initialize the assumed layer parameters and the gate circuit parameters.
[0123] In one of the embodiments, the prediction modification module 300 includes:
[0124] The conversion unit is configured to convert the input data into quantum signals, and convert each parameter in the initial encoding dictionary and the initial weight dictionary in the converted quantum signals into quantum input data.
[0125] In one of the embodiments, the feedback modification module 400 includes:
[0126] The bias calculation unit is configured to calculate a positive offset result and a negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary respectively, and calculate a temporary bias corresponding to each quantum gate based on the positive offset result, the negative offset result, and the loss value.
[0127] The combination unit is configured to combine the temporary biases corresponding to each quantum gate and perform preprocessing to obtain a target bias corresponding to each quantum gate in the encoding dictionary and the weight dictionary.
[0128] The target unit is configured to generate a target encoding dictionary and a target weight dictionary by preprocessing the target bias to obtain a target quantum framework.
[0129] In one of the embodiments, the bias calculation unit includes:
[0130] The parameter acquisition subunit is configured to acquire a positive offset parameter and a negative offset parameter corresponding to the initial encoding dictionary and the initial weight dictionary.
[0131] The offset calculation subunit is configured to calculate a positive offset result and a negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the positive offset parameter and the negative offset parameter.
[0132] The temporary calculation subunit is configured to obtain a temporary offset based on the positive offset result, the negative offset result, and the loss value.
[0133] The above framework modification and each module in the hybrid computing device based on the modification method can be realized by software, hardware, and a combination thereof, in whole or in part. The above modules can be embedded in or independent of a processor in a computer device in hardware form, or can be stored in a memory in a computer device in software form, so as to be called and executed by a processor to perform the operations corresponding to the above modules.
[0134] In one embodiment, a computer device, which can be a server, has an internal structure diagram as shown in Figure 6 The computer device includes a processor, a memory, an input / output interface (I / O), and a communication interface. The processor, the memory, and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for running the operating system and the computer program in the non-volatile storage medium. The database of the computer device is configured to store modification data. The input / output interface of the computer device is configured to exchange information between the processor and external devices. The communication interface of the computer device is configured to communicate with external terminals through a network connection. The computer program is executed by the processor to implement a framework modification method.
[0135] Those skilled in the art can understand that Figure 6 The structure shown in the above embodiment is only a block diagram of part of the structure related to the scheme of the present application, and does not constitute a limitation on the computer device to which the scheme of the present application is applied. Specifically, the computer device can include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0136] In one embodiment, a computer device is provided, comprising a memory and a processor, the memory storing a computer program, and the processor implementing the following steps when executing the computer program: receiving a refactoring instruction; the refactoring instruction carrying initialization information, prediction refactoring function information, and feedback refactoring function information; initializing a framework environment to be improved according to the initialization information in combination with a quantum device to obtain a target framework environment; the target framework environment comprising an initial computation graph, an initial encoding dictionary, and an initial weight dictionary; converting input data of a quantum computing node in the initial computation graph into quantum input data according to the prediction refactoring function information; the quantum input data being used for quantum device execution to obtain a quantum prediction result; calculating a loss value corresponding to the quantum prediction result according to the feedback refactoring function information, and determining a target bias corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the loss value, generating a target encoding dictionary and a target weight dictionary through preprocessing of the target bias to obtain a target quantum framework.
[0137] In one embodiment, the processor implements the following steps when executing the computer program: initializing a framework environment to be improved according to the initialization information in combination with a quantum device to obtain a target framework environment, comprising: instantiating the quantum device according to the initialization information to obtain an initial computation graph; the initial computation graph having quantum computing nodes; loading and initializing the proposed layer parameters and the gate circuit parameters.
[0138] In one embodiment, the processor implements the following steps when executing the computer program: converting input data of a quantum computing node in the initial computation graph into quantum input data according to the prediction refactoring function information, comprising: converting the input data into a quantum signal, and converting each parameter in the initial encoding dictionary and the initial weight dictionary in the quantum signal into quantum input data.
[0139] In one embodiment, the processor implements the following steps when executing the computer program: calculating a loss value corresponding to the quantum prediction result according to the feedback refactoring function information, and determining a target bias corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the loss value, comprising: calculating a positive offset result and a negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary, respectively, and calculating a temporary bias based on the positive offset result, the negative offset result, and the loss value; combining the temporary biases corresponding to each quantum gate and preprocessing to obtain the target bias corresponding to each quantum gate in the encoding dictionary and the weight dictionary; generating the target encoding dictionary and the target weight dictionary through the target bias to obtain the target quantum framework.
[0140] In one embodiment, the processor implements the calculation of the positive offset result and the negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary respectively when executing the computer program, and calculates the temporary offset corresponding to each quantum gate based on the positive offset result, the negative offset result and the loss value, including: obtaining the positive offset parameter and the negative offset parameter corresponding to the initial encoding dictionary and the initial weight dictionary; calculating the positive offset result and the negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the positive offset parameter and the negative offset parameter; obtaining the temporary offset based on the positive offset result, the negative offset result and the loss value.
[0141] In one embodiment, a computer device is provided, including a memory and a processor, the memory storing a computer program, and the processor implementing the following steps when executing the computer program: receiving sample data; the sample data carrying label data; inputting the sample data into an initial model for training to obtain a target model; the initial model being executed on a quantum target framework; the quantum target framework being obtained by the framework modification method in any one of the above embodiments.
[0142] In one embodiment, a computer readable storage medium is provided, storing a computer program thereon, and the computer program being executed by a processor to implement the following steps: receiving a modification instruction; the modification instruction carrying initialization information, prediction modification function information and feedback modification function information; initializing the framework environment to be improved in combination with a quantum device according to the initialization information to obtain a target framework environment; the target framework environment including an initial computation graph, an initial encoding dictionary and an initial weight dictionary; converting the input data of the quantum computing node in the initial computation graph into quantum input data according to the prediction modification function information; the quantum input data being used for quantum device execution to obtain a quantum prediction result; calculating a loss value corresponding to the quantum prediction result according to the feedback modification function information, and determining a target offset corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the loss value, generating a target encoding dictionary and a target weight dictionary by preprocessing the target offset, and obtaining a target quantum framework.
[0143] In one embodiment, the computer program is executed by the processor to implement the initialization of the framework environment to be improved in combination with the quantum device according to the initialization information to obtain the target framework environment, including: instantiating the quantum device according to the initialization information to obtain an initial computation graph; the initial computation graph having quantum computing nodes; loading and initializing the assumed layer parameters and the gate circuit parameters
[0144] In one embodiment, the computer program, when executed by the processor, implements the conversion of the input data of the quantum computing node in the initial computing graph into quantum input data according to the prediction transformation function information, including: converting the input data into a quantum signal, and converting each parameter in the initial encoding dictionary and the initial weight dictionary in the converted quantum signal into quantum input data. In one embodiment, the computer program, when executed by the processor, implements the calculation of the loss value corresponding to the quantum prediction result according to the feedback transformation function information, and determines the target bias corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the loss value, including: calculating the positive offset result and the negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary, respectively, and calculating the temporary bias corresponding to each quantum gate based on the positive offset result, the negative offset result and the loss value; combining the temporary bias corresponding to each quantum gate and preprocessing to obtain the target bias corresponding to each quantum gate in the encoding dictionary and the weight dictionary; obtaining the target quantum framework by generating the target encoding dictionary and the target weight dictionary from the target bias.
[0145] In one embodiment, the computer program, when executed by the processor, implements the calculation of the positive offset result and the negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary, respectively, and the calculation of the temporary bias corresponding to each quantum gate based on the positive offset result, the negative offset result and the loss value, including: obtaining the positive offset parameter and the negative offset parameter corresponding to the initial encoding dictionary and the initial weight dictionary; calculating the positive offset result and the negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the positive offset parameter and the negative offset parameter; obtaining the temporary offset based on the positive offset result, the negative offset result and the loss value.
[0146] In one embodiment, a computer readable storage medium is provided, and the computer readable storage medium stores a computer program. The computer program, when executed by the processor, implements the following steps: receiving sample data; the sample data carries label data; inputting the sample data into an initial model for training to obtain a target model; the initial model is executed on a quantum target framework; the quantum target framework is obtained according to the framework transformation method in any one of the above embodiments.
[0147] In one embodiment, a computer program product is provided, comprising a computer program which, when executed by a processor, implements the following steps: receiving a refactoring instruction; the refactoring instruction carrying initialization information, prediction refactoring function information, and feedback refactoring function information; initializing, according to the initialization information, a framework environment to be improved in combination with a quantum device, to obtain a target framework environment; the target framework environment comprising an initial calculation graph, an initial encoding dictionary, and an initial weight dictionary; converting, according to the prediction refactoring function information, input data of a quantum computing node in the initial calculation graph into quantum input data; the quantum input data being used for quantum device execution to obtain a quantum prediction result; calculating, according to the feedback refactoring function information, a loss value corresponding to the quantum prediction result, and determining, according to the loss value, a target bias corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary, generating a target encoding dictionary and a target weight dictionary through preprocessing of the target bias, to obtain a target quantum framework.
[0148] In one embodiment, the computer program, when executed by the processor, implements the initializing, according to the initialization information, of the framework environment to be improved in combination with the quantum device to obtain the target framework environment, comprises: instantiating, according to the initialization information, the quantum device to obtain an initial calculation graph; the initial calculation graph having quantum computing nodes; loading and initializing the assumed layer parameters and the gate circuit parameters
[0149] In one embodiment, the computer program, when executed by the processor, implements the converting, according to the prediction refactoring function information, of the input data of the quantum computing node in the initial calculation graph into quantum input data, comprises: converting the input data into a quantum signal, and converting each parameter in the initial encoding dictionary and the initial weight dictionary in the converted quantum signal into quantum input data. In one embodiment, the computer program, when executed by the processor, implements the calculating, according to the feedback refactoring function information, of a loss value corresponding to the quantum prediction result, and the determining, according to the loss value, of a target bias corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary, comprises: respectively calculating a positive offset result and a negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary, and calculating a temporary bias corresponding to each quantum gate based on the positive offset result, the negative offset result, and the loss value; combining the temporary biases corresponding to each quantum gate and preprocessing to obtain the target bias corresponding to each quantum gate in the encoding dictionary and the weight dictionary; generating the target encoding dictionary and the target weight dictionary through the target bias to obtain the target quantum framework.
[0150] In one embodiment, the computer program, when executed by the processor, implements the steps of calculating the positive offset result and the negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary respectively, and calculating the temporary offset corresponding to each quantum gate based on the positive offset result, the negative offset result and the loss value, including: obtaining the positive offset parameter and the negative offset parameter corresponding to the initial encoding dictionary and the initial weight dictionary; calculating the positive offset result and the negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the positive offset parameter and the negative offset parameter; obtaining the temporary offset based on the positive offset result, the negative offset result and the loss value.
[0151] In one embodiment, a computer program product is provided, including a computer program, which, when executed by a processor, implements the following steps: receiving sample data; the sample data carrying label data; inputting the sample data into an initial model for training to obtain a target model; the initial model being executed on a quantum target framework; the quantum target framework being obtained according to the framework modification method in any one of the above embodiments.
[0152] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a non-volatile computer readable storage medium, and when the computer program is executed, the processes of the above-mentioned embodiments of the methods can be included. Any reference to memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (Read-Only Memory, ROM), magnetic tape, floppy disk, flash memory, optical storage, high-density embedded non-volatile memory, resistive memory (ReRAM), magnetoresistive random access memory (Magnetoresistive Random Access Memory, MRAM), ferroelectric memory (Ferroelectric Random Access Memory, FRAM), phase change memory (Phase Change Memory, PCM), graphene memory, etc. Volatile memory can include random access memory (Random Access Memory, RAM) or external cache memory, etc. As an illustration but not limitation, RAM can be in various forms, such as static random access memory (Static Random Access Memory, SRAM) or dynamic random access memory (Dynamic Random Access Memory, DRAM), etc. The database involved in the embodiments provided in the present application can include at least one of a relational database and a non-relational database. The non-relational database can include a distributed database based on a block chain, etc., without being limited thereto. The processor involved in the embodiments provided in the present application can be a general-purpose processor, a central processing unit, a graphics processing unit, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., without being limited thereto.
[0153] Any combination of the technical features of the above embodiments can be made. In order to make the description simple, all possible combinations of the technical features in the above embodiments are not described, however, as long as the combination of the technical features does not exist contradictory, it should be considered as the scope of the present application.
[0154] The above embodiments only express several implementation manners of the present application, and the description is more specific and detailed, but it should not be understood as a limitation on the scope of the patent of the present application. It should be noted that for ordinary skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are within the scope of protection of the present application. Therefore, the scope of protection of the present application should be subject to the appended claims.
Claims
1. A method of frame modification, characterized by, The method comprises: receiving a transformation instruction; the transformation instruction carries initialization information, a prediction transformation function information and a feedback transformation function information; initializing a to-be-improved framework environment according to the initialization information, to obtain a target framework environment; the target framework environment comprises an initial calculation graph, an initial encoding dictionary and an initial weight dictionary; converting input data of a quantum computing node in the initial calculation graph into quantum input data according to the prediction transformation function information; the quantum input data is used for execution by the quantum device to obtain a quantum prediction result; calculating a loss value corresponding to the quantum prediction result according to the feedback transformation function information, and determining a target bias corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the loss value, generating a target encoding dictionary and a target weight dictionary through preprocessing of the target bias, to obtain a target quantum framework.
2. The method of claim 1, wherein, The method comprises: instantiating the quantum device according to the initialization information to obtain an initial calculation graph; the initial calculation graph has the quantum computing node; loading and initializing the proposed layer parameters and the gate circuit parameters.
3. The method of claim 1, wherein, The method comprises: converting the input data into quantum signals, and converting each parameter in the initial encoding dictionary and the initial weight dictionary in the converted quantum signals into the quantum input data.
4. The method of claim 1, wherein, The method comprises: calculating a positive offset result and a negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary respectively, and calculating a temporary bias based on the positive offset result, the negative offset result and the loss value; combining the temporary biases corresponding to each quantum gate and preprocessing to obtain a target bias corresponding to each quantum gate in the encoding dictionary and the weight dictionary; generating a target encoding dictionary and a target weight dictionary through the target bias to obtain a target quantum framework.
5. The method of claim 4, wherein, The method comprises: obtaining a positive offset parameter and a negative offset parameter corresponding to the initial encoding dictionary and the initial weight dictionary; calculating the positive offset result and the negative offset result corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the positive offset parameter and the negative offset parameter; obtaining the temporary bias based on the positive offset result, the negative offset result and the loss value.
6. A hybrid computational method based on a framework remodeling method, characterized by, The method comprises: Receive sample data; the sample data carries label data; Input the sample data into an initial model for training to obtain a target model; the initial model is executed on a quantum target framework; the quantum target framework is obtained according to the framework transformation method in any one of claims 1-5.
7. A frame modification device, characterized in that The device comprises: A receiving module for receiving a transformation instruction; the transformation instruction carries initialization information, a prediction transformation function information and a feedback transformation function information; An initialization module for initializing a target framework environment according to the initialization information in combination with a quantum device to be improved framework environment; the target framework environment comprises an initial calculation graph, an initial encoding dictionary and an initial weight dictionary; A prediction transformation module for converting input data of a quantum computing node in the initial calculation graph into quantum input data according to the prediction transformation function information; the quantum input data is used for the quantum device to execute to obtain a quantum prediction result; A feedback transformation module for calculating a loss value corresponding to the quantum prediction result according to the feedback transformation function information, and determining a target bias corresponding to each quantum gate in the initial encoding dictionary and the initial weight dictionary according to the loss value, generating a target encoding dictionary and a target weight dictionary through preprocessing of the target bias to obtain a target quantum framework.
8. A hybrid computing device based on a framework retrofit method, characterized by, The device comprises: A sample receiving module for receiving sample data; the sample data carries label data; A training module for inputting the sample data into an initial model for training to obtain a target model; the initial model is executed on a quantum target framework; the quantum target framework is obtained according to the framework transformation method in any one of claims 1-5. 9.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is configured to perform the method according to any one of claims 1-8 when the computer program is executed by the processor. The processor executes the computer program to realize the steps of the method in any one of claims 1 to 5 or 6.
10. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed by the processor to realize the steps of the method in any one of claims 1 to 5 or 6.
Citation Information
Patent Citations
Cognitive memory graph indexing, storage and retrieval
CN107533553A
Quantum program optimization method based on machine learning framework and related equipment
CN114372583A