A large model fine-tuning method based on QAdapter and related device
By inserting a QAdapter layer with quantum circuit design into a pre-trained large model, only a small number of parameters need to be fine-tuned, which solves the problem of high training cost of large-scale models and achieves faster and more efficient fine-tuning results.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- ORIGIN QUANTUM COMPUTING TECH (HEFEI) CO LTD
- Filing Date
- 2025-01-03
- Publication Date
- 2026-07-14
AI Technical Summary
Existing technologies are costly and inefficient when fine-tuning large-scale deep learning models, making it difficult to achieve the same results as full parameter fine-tuning in downstream tasks.
A QAdapter layer is inserted into the pre-trained large model, and the parameters of the QAdapter layer are fine-tuned by the first and second quantum circuit layers designed by quantum circuits. The main structure of the pre-trained large model is frozen, and only the parameters of the QAdapter layer are adjusted to adapt to the new task.
The QAdapter layer fine-tuning method using quantum circuit design significantly reduces computational resource requirements and training time, improves fine-tuning efficiency, and can adapt to new tasks while maintaining model performance.
Smart Images

Figure CN122390102A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of quantum computing technology, and in particular to a large model fine-tuning method and related apparatus based on QAdapter. Background Technology
[0002] As large-scale model architectures are continuously proposed in classical fields, the scale of deep learning models is getting larger and larger. Training large-scale quantum machine learning models will lead to a significant increase in training costs. In order to reduce the training resources required for large models during fine-tuning, some large model fine-tuning methods have been proposed. Instead of fine-tuning all parameters of the large model, the proposed fine-tuning methods train a small number of parameters, so that the large model can still achieve results no less than those of full parameter fine-tuning in downstream tasks.
[0003] This invention proposes a QAdapter fine-tuning technique, which adds a QAdapter layer to the modules of a large model and fine-tunes the large model by updating the parameters in the QAdapter layer, so that it can still achieve good results in downstream tasks. Summary of the Invention
[0004] The purpose of this invention is to provide a large model fine-tuning method and related apparatus based on QAdapter to solve the technical problems in the prior art. It can fine-tune large models at a faster speed and in a more efficient manner.
[0005] In a first aspect, the present invention provides a method for fine-tuning large models based on QAdapter, comprising the following steps:
[0006] Construct a pre-trained large model, insert a QAdapter layer into the pre-trained large model, freeze the parameters of the main structure in the pre-trained large model during the training process, and adjust the parameters of the QAdapter layer.
[0007] A first quantum circuit layer and a second quantum circuit layer are set in the QAdapter layer. The first quantum circuit layer is configured to perform downlink mapping on the input data to the QAdapter layer to reduce the output dimension, and the second quantum circuit layer is configured to increase the data dimension to the same dimension as the input data.
[0008] In the large model fine-tuning method based on QAdapter described above, preferably, the pre-trained large model further includes a multi-head attention layer, a first feedforward neural network layer, a first residual connection block, a first normalization layer, a second feedforward neural network layer, a second residual connection block, and a second normalization layer connected sequentially from the input to the output. One of the QAdapter layers is inserted after the output of the first feedforward neural network layer and before the output of the first residual connection block, and the other QAdapter layer is inserted after the output of the second feedforward neural network layer and before the output of the second residual connection block.
[0009] In the large model fine-tuning method based on QAdapter described above, preferably, the QAdapter layer further includes a nonlinear layer and a third residual connection block. From the input to the output, the first quantum circuit layer, the nonlinear layer, the second quantum circuit layer, and the third residual connection block are connected sequentially, wherein:
[0010] The first quantum circuit layer is configured to perform down-mapping on the output of the first feedforward neural network layer or the second feedforward neural network layer to reduce the dimensionality of the output of the first feedforward neural network layer or the second feedforward neural network layer.
[0011] The nonlinear layer is configured to nonlinearly activate the output of the first feedforward neural network layer or the second feedforward neural network layer after the dimensionality reduction.
[0012] The second quantum circuit layer is configured to perform an up-mapping on the output of the nonlinear layer, increasing the output dimension of the nonlinear layer to the same dimension as the output of the first feedforward neural network layer or the second feedforward neural network layer.
[0013] In the large model fine-tuning method based on QAdapter described above, preferably, both the first quantum circuit layer and the second quantum circuit layer include a preset number of qubits and multiple data encoding layers that act sequentially on the qubits along the action sequence. Each data encoding layer includes a quantum rotation gate and a CX gate acting on the preset qubits. The control qubit of the CX gate is the qubit where the quantum rotation gate is located. The target qubit of the CX gate is the qubit where the corresponding quantum rotation gate of the data encoding layer in the next action sequence is located. The target qubit of the last data encoding layer is the qubit where the corresponding quantum rotation gate of the first data encoding layer is located.
[0014] In the large model fine-tuning method based on QAdapter described above, preferably, the quantum rotation gate includes one or more of the RX gate, RY gate, and RZ gate.
[0015] In the large model fine-tuning method based on QAdapter described above, preferably, both the first quantum circuit layer and the second quantum circuit layer include a preset number of qubits and multiple data encoding layers that are sequentially applied to the qubits along the action time sequence. When the number of qubits is less than the dimension of the input data, the input data is encoded into the data encoding layers one by one by taking the remainder by %.
[0016] In the large model fine-tuning method based on QAdapter described above, preferably, the first quantum circuit layer and the second quantum circuit layer further include a plurality of X gates and H gates arranged sequentially along the activation timing, wherein the activation timing of the X gates and H gates is located before the activation timing of the plurality of data encoding layers.
[0017] Secondly, the present invention also provides a large model fine-tuning device, the device comprising:
[0018] A pre-trained large model building module is used to build a pre-trained large model, insert a QAdapter layer into the pre-trained large model, freeze the parameters of the main structure in the pre-trained large model during the training process, and adjust the parameters of the QAdapter layer.
[0019] A quantum circuit construction module is used to set up a first quantum circuit layer and a second quantum circuit layer in the QAdapter layer. The first quantum circuit layer is configured to perform downlink mapping on the input data input to the QAdapter layer to reduce the output dimension, and the second quantum circuit layer is configured to increase the data dimension to the same dimension as the input data.
[0020] Thirdly, the present invention provides a storage medium storing a computer program, wherein the computer program is configured to implement the aforementioned method when running.
[0021] Fourthly, the present invention provides an electronic device including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to implement the aforementioned method.
[0022] Compared with existing technologies, this invention achieves fine-tuning of large pre-trained models by adding a QAdapter layer with quantum circuitry to the large model. Only a small number of parameters in the QAdapter and some parameters of the large model are trained to fit downstream tasks, which reduces a lot of training resources. The QAdapter layer with quantum circuitry can contain more information, making it easier for modules with the same number of parameters to adapt to downstream tasks after training. Attached Figure Description
[0023] Figure 1 This is a network block diagram of a quantum circuit construction system provided in an embodiment of the present invention;
[0024] Figure 2 This is a flowchart of a large model fine-tuning method based on QAdapter provided in an embodiment of the present invention;
[0025] Figure 3 This is a schematic diagram of the structure of a pre-trained large model provided in an embodiment of the present invention;
[0026] Figure 4 This is a schematic diagram of the structure of the QAdapter layer provided in an embodiment of this application;
[0027] Figure 5 This is a schematic diagram of the structure of the first quantum circuit provided in the embodiments of this application;
[0028] Figure 6 This is a schematic diagram of the structure of a second quantum circuit provided in an embodiment of this application;
[0029] Figure 7 This is a schematic diagram of a large model fine-tuning device provided in an embodiment of the present invention. Detailed Implementation
[0030] 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.
[0031] [Structure of a quantum circuit construction system]
[0032] Figure 1 This is a network block diagram of a quantum circuit construction system provided in an embodiment of this application. The quantum circuit construction system may include a network 110, a server 120, a wireless device 130, a client 140, a storage unit 150, a classical processing system 160, a quantum processing system 170, and may also include additional memory, a classical processor, a quantum processor, and other devices not shown.
[0033] Network 110 is a medium used to provide communication links between various devices and computers connected together within a quantum circuit construction system, including but not limited to the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. The connection method can be wired, wireless communication links, or fiber optic cables.
[0034] Server 120 and client 140 are conventional data processing systems that may contain data and applications or software tools that perform conventional computational processes. Client 140 may be a personal computer or a network computer, so the data may also be provided by server 120. Wireless device 130 may be a smartphone, tablet, laptop, smart wearable device, etc. Storage unit 150 may include database 151, which can be configured to store data such as qubit parameters, quantum logic gate parameters, quantum circuits, and quantum programs.
[0035] The classical processing system 160 (quantum processing system 170) may include a classical processor 161 (quantum processor 171) for processing classical data (quantum data) and a memory 163 (memory 172) for storing classical data (quantum data). The classical data (quantum data) may be a boot file, an operating system image, and an application program 162 (application program 173). The application program 162 (application program 173) may be used to implement a quantum algorithm compiled according to the quantum circuit construction method provided in the embodiments of this application.
[0036] Any data or information stored or generated in the classical processing system 160 (quantum processing system 170) can also be configured to be stored or generated in another classical (quantum) processing system in a similar manner, and any application executed therein can also be configured to be executed in another classical (quantum) processing system in a similar manner.
[0037] It should be noted that a true quantum computer has a hybrid structure, which includes at least... Figure 1 The system consists of two main parts: the classical processing system 160, which is responsible for performing classical calculations and control; and the quantum processing system 170, which is responsible for running quantum programs and thus realizing quantum computing.
[0038] The aforementioned classical processing system 160 and quantum processing system 170 can be integrated into a single device or distributed across two different devices. For example, the first device, including the classical processing system 160, runs a classical computer operating system that provides quantum application development tools and services, as well as the storage and network services required for quantum applications. Users develop quantum applications using the quantum application development tools and services on the second device and send the quantum program to the second device, including the quantum processing system 170, via the network services. The second device runs a quantum computer operating system, which parses the code of the quantum program and compiles it into instructions that can be recognized and executed by the quantum computer control system. The quantum processor 170 then implements the quantum algorithm corresponding to the quantum program based on these instructions.
[0039] In the classic silicon-based processing system 160, the units of the classic processor 161 are CMOS transistors. These computing units are not limited by time or coherence; that is, they are available at any time without time constraints. Furthermore, the number of these computing units in a silicon chip is sufficient; currently, a classic processor contains tens of thousands of computing units. The sufficient number of computing units and the fixed selectable computing logic of the CMOS transistors, such as AND logic, allow for computational efficiency through a combination of numerous CMOS transistors and limited logic functions.
[0040] Unlike the logic units in the classical processing system 160, the basic computational unit of the quantum processor 171 in the quantum processing system 170 is the qubit. The input of a qubit is limited by coherence and coherence time; that is, a qubit is limited by its available usage time and is not always readily available. Making full use of qubits within their available usage time is a key challenge in quantum computing. Furthermore, the number of qubits in a quantum computer is one of the representative indicators of its performance. Each qubit performs computational functions through on-demand configured logic functions. Given the limited number of qubits and the diverse logic functions available in quantum computing, such as Hadamard gates (H gates), Pauli-X gates (X gates), Pauli-Y gates (Y gates), Pauli-Z gates (Z gates), RX gates, RY gates, RZ gates, CR gates, iSWAP gates, Tofoli gates, etc., quantum computing requires combining a limited number of qubits with diverse combinations of logic functions to achieve computational effects.
[0041] Based on these differences, the design of logical functions applied to qubits (including the design of whether qubits are used and the design of the efficiency of each qubit's use) is crucial to improving the computational performance of quantum computers and requires specialized design. The aforementioned design considerations for qubits are technical issues that ordinary computing devices do not need to address.
[0042] [A method for fine-tuning large models based on QAdapter]
[0043] Reference Figure 2 As shown, an embodiment of the present invention provides a large model fine-tuning method based on QAdapter, including the following steps:
[0044] Step S101: Construct a pre-trained large model. In the embodiments provided by this invention, the pre-trained large model is preferably a Transformer module. A QAdapter layer is inserted into the pre-trained large model. The QAdapter layer can be regarded as an adapter, which is inserted at a specific position of the model (such as the input layer, hidden layer or output layer) to adapt to new task requirements. During the training process of the pre-trained large model, the parameters of the main structure in the pre-trained large model are frozen, and the parameters of the QAdapter layer are adjusted to achieve fine-tuning of the pre-trained large model. The QAdapter layer is updated during the fine-tuning process, while the original parameters of the pre-trained large model remain unchanged.
[0045] Step S101 provides a more flexible and efficient approach to adapt to new tasks. Instead of directly modifying the original parameters of the pre-trained large model, it inserts a new QAdapter layer inside the pre-trained large model and initializes the QAdapter layer with the parameters of the pre-trained large model. The QAdapter layer is initialized with the aim of making the output of the QAdapter layer close to the output of the original model. During training, only the parameters of the QAdapter layer are optimized, while the original parameters of the pre-trained large model remain fixed, and most of the weights of the pre-trained large model remain fixed.
[0046] The implementation process of the QAdapter layer is as follows: Prepare a pre-trained large model, which can be a Transformer, CNN, RNN, etc., without limitation; insert the QAdapter layer at an appropriate position in the pre-trained large model; initialize the QAdapter layer using the parameters of the pre-trained large model; fine-tune the model using training data for a specific task, and the optimizer will update the parameters of the QAdapter layer to minimize the task loss; evaluate the performance of the fine-tuned model on the validation set and test set.
[0047] Step S102: Set up a first quantum circuit layer and a second quantum circuit layer in the QAdapter layer. By embedding the quantum circuit design QAdapter layer in the pre-trained large model, only the parameters of these quantum circuits are fine-tuned. The quantum circuit design QAdapter layer can take advantage of the parallelism and quantum superposition properties of quantum computing, so that the fine-tuning process can theoretically be carried out at a faster speed. This can significantly reduce the demand for computing resources and training time, thereby improving the fine-tuning efficiency and fine-tuning the pre-trained large model at a faster speed and in a more efficient manner.
[0048] The Adapter layer limits the number of parameters by controlling the size of the intermediate dimension, which is much smaller than the original input dimension. This reduces the number of parameters while maintaining model performance. Specifically, the first quantum circuit layer is configured to perform a downlink mapping on the input data to the QAdapter layer, reducing the output dimension. The second quantum circuit layer is configured to increase the data dimension to the same dimension as the input data, thereby limiting the number of parameters added for each task and reducing the number of parameters in the pre-trained large model.
[0049] In summary, the QAdapter-based large model fine-tuning method, by combining quantum circuit design and the classical adapter concept, provides an efficient, fast, and flexible fine-tuning approach for large models, reducing computational resource requirements while maintaining model performance.
[0050] In one feasible implementation, refer to Figure 3 As shown, the pre-trained large model also includes a multi-head attention layer, a first feedforward neural network layer, a first residual connection block, a first normalization layer, a second feedforward neural network layer, a second residual connection block, and a second normalization layer, connected sequentially from the input to the output. One QAdapter layer is inserted after the output of the first feedforward neural network layer and before the output of the first residual connection block, and another QAdapter layer is inserted after the output of the second feedforward neural network layer and before the output of the second residual connection block. By adding QAdapter layers at key positions, the pre-trained large model can adapt to new tasks by fine-tuning a small number of parameters while keeping the pre-trained weights unchanged.
[0051] in:
[0052] Multi-head attention layers allow pre-trained large models to focus on different parts of the input sequence in different representation subspaces, enabling them to capture dependencies between different positions in the sequence.
[0053] The first and second feedforward neural network layers independently apply a fully connected feedforward network to the output at each position.
[0054] The first and second layers of normalization are used to normalize all features of each sample to accelerate training and improve model stability.
[0055] The first and second residual connect blocks, following each QAdapter layer, directly add the input to the sublayer's output to help gradient flow and mitigate the vanishing gradient problem in deep networks, allowing the model to learn deeper features.
[0056] The QAdapter layer is designed to adapt to new tasks by adjusting a small number of parameters while keeping most of the parameters of the pre-trained large model unchanged. One possible implementation refers to... Figure 4 As shown, the QAdapter layer also includes a nonlinear layer and a third residual connection block. From the input to the output, the first quantum circuit layer, the nonlinear layer, the second quantum circuit layer, and the third residual connection block are connected sequentially, wherein:
[0057] The first quantum circuit layer is a linear layer in a quantum neural network, used to realize linear transformations of quantum states. The first quantum circuit layer is configured to perform downlink mapping on the output of the first feedforward neural network layer or the second feedforward neural network layer, thereby reducing the dimensionality of the output of the first feedforward neural network layer or the second feedforward neural network layer.
[0058] The nonlinear layer is configured to nonlinearly activate the output of the first or second feedforward neural network layer after dimensionality reduction, thereby introducing nonlinear characteristics to allow pre-trained large models to learn more complex function mappings.
[0059] The second quantum circuit layer is a linear layer in the quantum neural network, used to realize the linear transformation of quantum states. The second quantum circuit layer is configured to perform an up-mapping on the output of the nonlinear layer, increasing the output dimension of the nonlinear layer to the same dimension as the output of the first or second feedforward neural network layer.
[0060] The QAdapter layer provided in this application offers a flexible way to fine-tune quantum neural networks by combining a first quantum circuit layer, a nonlinear layer, a second quantum circuit layer, and a third residual connection block. This allows the network to better adapt to specific downstream tasks and leverages the advantages of quantum computing, such as superposition and entanglement, to improve the performance and efficiency of the model.
[0061] In one feasible implementation, both the first quantum circuit layer and the second quantum circuit layer include a predetermined number of qubits and multiple data encoding layers that sequentially act on the qubits along the activation sequence. The data encoding layers are used to encode data onto the corresponding qubits. Those skilled in the art will understand that, after the data encoding layers, there are also an evolution layer and a measurement layer. The evolution layer is used to correlate the quantum state information of the qubits and evolve to obtain an output quantum state. The measurement layer is used to perform measurement operations on the qubits.
[0062] First, the data is encoded into the quantum circuit by the data encoding layer. Then, a parametric trainable logic gate is added. By training the parameters, the task can be fine-tuned. The characteristics of the quantum circuit are used to optimize and adjust the model to achieve better performance. Finally, through a series of measurement operations, the complete quantum computing process from encoding the input quantum state to the final measurement is completed.
[0063] Depending on whether the dimension of the input data is equivalent to the preset number of qubits, the embodiments provided in this application provide two quantum circuit structures, namely the first quantum circuit and the second quantum circuit.
[0064] In the first type of quantum circuit, the dimension of the input data is equal to the number of qubits. The data encoding layer includes quantum rotation gates and CX gates acting on preset qubits. Weights are encoded and entanglement is created through parameterized quantum rotation gates and CX gates, thereby realizing linear transformation of quantum states.
[0065] Quantum rotating gates typically include single-parameter logic gates such as RX gates, RY gates, or RZ gates. The rotation control parameters of these single-parameter logic gates are adjusted according to the data to be processed, and the parameters are encoded into the logic gates one by one. Preferably, the quantum rotating gate is an RY gate, which is a gate that rotates around the Y-axis. It is a parameterized rotating gate that can change the probability amplitude of the qubit in the Y-axis direction. Each parameter of the RY gate corresponds to a weight. In this way, the quantum circuit can simulate linear transformations.
[0066] The CX gate is a two-qubit gate. When the control qubit is |1>, it flips the target qubit. Through the operation of the CX gate, entanglement is generated between the qubits, which allows the quantum circuit to take into account the correlation between the qubits when processing the input data. In each data encoding layer, the control qubit of the CX gate is the qubit where the quantum rotation gate is located, and the target qubit of the CX gate is the qubit where the corresponding quantum rotation gate of the data encoding layer of the next action sequence is located. The target qubit of the last data encoding layer is the qubit where the corresponding quantum rotation gate of the first data encoding layer is located.
[0067] Furthermore, the first quantum circuit layer and the second quantum circuit layer also include several X gates and H gates arranged sequentially along the activation timing. The activation timing of the X gates and H gates is located before the activation timing of multiple data encoding layers. The qubits are first initialized through the X gates and H gates, and then encoded and entangled through the RY gates and CX gates.
[0068] The X-gate, also known as the Pauli-X gate or NOT gate, is used to flip a qubit from |0> to |1>, or from |1> to |0>. The H-gate, or Hadamard gate, is used to place a qubit in a superposition state, i.e., a superposition of |0> and |1> with equal probability.
[0069] For example, refer to Figure 5 As shown, in one feasible implementation, the input dimension of the first quantum circuit is 6, so the preset number of qubits is also 6, the output dimension is 2, and the final quantum circuit will output the state of two qubits, or obtain two classical bits by measurement.
[0070] The qubits are ordered from the least significant qubit to the most significant qubit, namely the first qubit, the second qubit, and so on. Since the output dimension is 2, the first qubit and the second qubit are measured during the measurement.
[0071] The data encoding layer, located in the first operating sequence, has two RY gates and two CX gates. The two RY gates operate on the first and second qubits, respectively. One CX gate controls the first qubit and targets the third qubit. The other CX gate controls the second qubit and targets the fourth qubit.
[0072] The data encoding layer located in the second action sequence has two RY gates and two CX gates. The two RY gates act on the third and fourth qubits respectively. One CX gate controls the third qubit and targets the fifth qubit. The other CX gate controls the fourth qubit and targets the sixth qubit.
[0073] The data encoding layer located at the last action time has two RY gates and two CX gates. The two RY gates act on the fifth and sixth qubits respectively. One CX gate controls the fifth qubit and targets the first qubit. The other CX gate controls the sixth qubit and targets the second qubit.
[0074] In the second type of quantum circuit, the dimension of the input data is not equal to the number of qubits. This is to prevent the number of qubits from being too large when the input dimension is too large. Thus, the parameters of the quantum circuit with small qubits are set for training. At this time, the input data is encoded into the data encoding layer one by one by taking the remainder.
[0075] For example, a quantum circuit uses four qubits. Assuming the input data dimension is (batch_size, 10), this means each batch has multiple data samples, each with 10 features. For each data sample, its 10 feature values will be encoded into four qubits. Since the number of qubits is less than the number of features, each feature value can be modulo 4. The remainder can be used as an index for the qubits. Thus, each feature value is mapped to a qubit. If the number of feature values exceeds the number of qubits, the mapping can be cyclically performed using the remainder. If the number of features in a data sample is less than the number of qubits, empty qubit positions can be filled with 0.
[0076] Reference Figure 6 As shown, in one feasible implementation, the input dimension of the first quantum circuit is 6, the preset number of qubits is 5, and the output dimension is 2. When encoding data into the quantum circuit, parameters are placed at 0, 1, 2, 3, 4, and 0 respectively, and the data is encoded in a modulo manner. The design of subsequent trainable logic gates can be done layer by layer, and each layer can be consistent. The final quantum circuit will output the state of two qubits, or two classical bits can be obtained by measurement.
[0077] The qubits are ordered from the least significant qubit to the most significant qubit, namely the first qubit, the second qubit, and so on. Since the output dimension is 2, the first qubit and the second qubit are measured during the measurement.
[0078] The data encoding layer, located in the first operating sequence, has two RY gates and two CX gates. The two RY gates operate on the first and second qubits, respectively. One CX gate controls the first qubit and targets the third qubit. The other CX gate controls the second qubit and targets the fourth qubit.
[0079] The data encoding layer located in the second action sequence has two RY gates and two CX gates. The two RY gates act on the third and fourth qubits respectively. One CX gate controls the third qubit and targets the fifth qubit. The other CX gate controls the fourth qubit and targets the first qubit.
[0080] The data encoding layer located at the last action time has two RY gates and two CX gates. The two RY gates act on the fifth qubit and the first qubit, respectively. One CX gate controls the fifth qubit and targets the second qubit. The other CX gate controls the first qubit and targets the third qubit.
[0081] Compared with existing technologies, this invention achieves fine-tuning of large pre-trained models by adding a QAdapter layer with quantum circuitry to the large model. Only a small number of parameters in the QAdapter and some parameters of the large model are trained to fit downstream tasks, which reduces a lot of training resources. The QAdapter layer with quantum circuitry can contain more information, making it easier for modules with the same number of parameters to adapt to downstream tasks after training.
[0082] [Structure of the pre-trained large model fine-tuning device]
[0083] See Figure 7 As shown, the pre-trained large model fine-tuning device includes:
[0084] The pre-trained large model building module is used to build a pre-trained large model, insert a QAdapter layer into the pre-trained large model, freeze the parameters of the main structure in the pre-trained large model during the training process, and adjust the parameters of the QAdapter layer.
[0085] The quantum circuit construction module is used to set up a first quantum circuit layer and a second quantum circuit layer in the QAdapter layer. The first quantum circuit layer is configured to perform downlink mapping on the input data to the QAdapter layer to reduce the output dimension, and the second quantum circuit layer is configured to increase the data dimension to the same dimension as the input data.
[0086] [Structure of storage media]
[0087] This invention also provides a storage medium storing a computer program, wherein the computer program is configured to implement the steps in any of the above method embodiments when running.
[0088] Specifically, in this embodiment, the storage medium can be configured to store a computer program for implementing the following steps:
[0089] Step S101: Construct a pre-trained large model, insert a QAdapter layer into the pre-trained large model, freeze the parameters of the main structure in the pre-trained large model during the training process, and adjust the parameters of the QAdapter layer.
[0090] Step S102: Set up a first quantum circuit layer and a second quantum circuit layer in the QAdapter layer. The first quantum circuit layer is configured to perform downlink mapping on the input data of the QAdapter layer to reduce the output dimension. The second quantum circuit layer is configured to increase the data dimension to the same dimension as the input data.
[0091] Structure of electronic devices
[0092] This invention also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program and the processor is configured to run the computer program to implement the steps in any of the above method embodiments.
[0093] Specifically, the aforementioned electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the aforementioned processor, and the input / output device is connected to the aforementioned processor.
[0094] Specifically, in this embodiment, the processor described above can be configured to implement the following steps via a computer program:
[0095] Step S101: Construct a pre-trained large model, insert a QAdapter layer into the pre-trained large model, freeze the parameters of the main structure in the pre-trained large model during the training process, and adjust the parameters of the QAdapter layer.
[0096] Step S102: Set up a first quantum circuit layer and a second quantum circuit layer in the QAdapter layer. The first quantum circuit layer is configured to perform downlink mapping on the input data of the QAdapter layer to reduce the output dimension. The second quantum circuit layer is configured to increase the data dimension to the same dimension as the input data.
[0097] The above description, based on the embodiments shown in the figures, details the structure, features, and effects of the present invention. The above description is only a preferred embodiment of the present invention, but the present invention is not limited to the scope of implementation shown in the figures. Any changes made in accordance with the concept of the present invention, or equivalent embodiments modified to have equivalent changes, that do not exceed the spirit covered by the specification and figures, should be within the protection scope of the present invention.
Claims
1. A method for fine-tuning large models based on QAdapter, characterized in that: Includes the following steps: Construct a pre-trained large model, insert a QAdapter layer into the pre-trained large model, freeze the parameters of the main structure in the pre-trained large model during the training process, and adjust the parameters of the QAdapter layer. A first quantum circuit layer and a second quantum circuit layer are set in the QAdapter layer. The first quantum circuit layer is configured to perform downlink mapping on the input data to the QAdapter layer to reduce the output dimension, and the second quantum circuit layer is configured to increase the data dimension to the same dimension as the input data.
2. The method according to claim 1, characterized in that: The pre-trained large model further includes a multi-head attention layer, a first feedforward neural network layer, a first residual connection block, a first layer normalization, a second feedforward neural network layer, a second residual connection block, and a second layer normalization, which are connected sequentially from the input to the output. One of the QAdapter layers is inserted after the output of the first feedforward neural network layer and before the output of the first residual connection block, and the other QAdapter layer is inserted after the output of the second feedforward neural network layer and before the output of the second residual connection block.
3. The method according to claim 2, characterized in that: The QAdapter layer further includes a nonlinear layer and a third residual connection block. From the input to the output, the first quantum circuit layer, the nonlinear layer, the second quantum circuit layer, and the third residual connection block are connected sequentially, wherein: The first quantum circuit layer is configured to perform down-mapping on the output of the first feedforward neural network layer or the second feedforward neural network layer to reduce the dimensionality of the output of the first feedforward neural network layer or the second feedforward neural network layer. The nonlinear layer is configured to nonlinearly activate the output of the first feedforward neural network layer or the second feedforward neural network layer after the dimensionality reduction. The second quantum circuit layer is configured to perform an up-mapping on the output of the nonlinear layer, increasing the output dimension of the nonlinear layer to the same dimension as the output of the first feedforward neural network layer or the second feedforward neural network layer.
4. The method according to claim 1, characterized in that: Both the first quantum circuit layer and the second quantum circuit layer include a preset number of qubits and multiple data encoding layers that act sequentially on the qubits along the activation time sequence. Each data encoding layer includes a quantum rotation gate and a CX gate that act on the preset qubits. The control qubit of the CX gate is the qubit where the quantum rotation gate is located. The target qubit of the CX gate is the qubit where the corresponding quantum rotation gate of the data encoding layer in the next activation time sequence is located. The target qubit of the last data encoding layer is the qubit where the corresponding quantum rotation gate of the first data encoding layer is located.
5. The method according to claim 4, characterized in that: The quantum rotation gate includes one or more of the RX gate, RY gate, and RZ gate.
6. The method according to claim 1, characterized in that: Both the first quantum circuit layer and the second quantum circuit layer include a preset number of qubits and multiple data encoding layers that act sequentially on the qubits along the action time sequence. When the number of qubits is less than the dimension of the input data, the input data is encoded into the data encoding layers one by one by taking the remainder by %.
7. The method according to claim 4 or 6, characterized in that: The first quantum circuit layer and the second quantum circuit layer further include a plurality of X gates and H gates arranged sequentially along the activation timing, wherein the activation timing of the X gates and H gates is located before the activation timing of the plurality of data encoding layers.
8. A large model fine-tuning device, characterized in that, The device includes: A pre-trained large model building module is used to build a pre-trained large model, insert a QAdapter layer into the pre-trained large model, freeze the parameters of the main structure in the pre-trained large model during the training process, and adjust the parameters of the QAdapter layer. A quantum circuit construction module is used to set up a first quantum circuit layer and a second quantum circuit layer in the QAdapter layer. The first quantum circuit layer is configured to perform downlink mapping on the input data input to the QAdapter layer to reduce the output dimension, and the second quantum circuit layer is configured to increase the data dimension to the same dimension as the input data.
9. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to implement the method described in any one of claims 1 to 7 when it is run.
10. 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 implement the method of any one of claims 1 to 7.