A co-processor cooperates with a trusted execution environment to implement a large model privacy inference method
By employing a collaborative approach between coprocessors and a trusted execution environment, the conflict between computational power and privacy protection in large language model inference is resolved. This approach enables an efficient and secure privacy-preserving inference process, ensuring that data is computed under end-to-end encryption.
Patent Information
- Application Number
- CN202611305728.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-26
- Publication Date
- 2026-11-27
AI Technical Summary
Existing Trusted Execution Environment (TEE) inference solutions lack the capacity for large-scale parallel computing and cannot meet the computational needs of large language models. Meanwhile, conventional coprocessor inference solutions lack privacy protection during data transmission, posing a risk of privacy leakage due to plaintext computation.
By employing a collaborative approach between a coprocessor and a trusted execution environment, the coprocessor performs linear operator operations while the trusted execution environment performs plaintext data decryption, nonlinear operator operations, and result re-encryption, forming a layer-by-layer encrypted iterative computation process that ensures data remains encrypted throughout the entire process.
It effectively reduces inference latency, improves the efficiency and security of privacy-preserving inference in large language models, and ensures the data privacy and security of user input, model intermediate states, and final results.
Smart Images

Figure CN123180339A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of model inference technology, and in particular to a method for privacy-preserving inference of large models through collaboration between a coprocessor and a trusted execution environment. Background Technology
[0002] With the rapid development of large language models (LLMs) such as GPT and LLaMA, cloud-based large language model inference has been widely applied in scenarios such as intelligent question answering and knowledge reasoning. Since the server can directly access user input and model output during the inference process, it may lead to the leakage of user privacy information. Therefore, privacy-preserving large language model inference has become an important research direction.
[0003] Common privacy inference schemes fall into two categories: one is inference schemes based on a Trusted Execution Environment (TEE), and the other is inference schemes based on conventional coprocessors, such as graphics processors.
[0004] Among them, the pure TEE inference solution has a high level of security isolation and can protect data privacy during the calculation process. However, it is limited by the computing power and secure memory specifications of the trusted execution environment, and its parallel computing capability is weak. It cannot adapt to the large-scale computing needs of large language models and has problems such as high inference latency and poor engineering implementation. Conventional coprocessors have powerful large-scale parallel computing capabilities and can efficiently handle matrix operations in model inference. However, existing solutions only perform encryption protection in the data input and output transmission links. The inference calculation inside the coprocessor is completed entirely based on plaintext features. The intermediate state of the model is stored in plaintext in the computing storage medium, which poses a serious risk of privacy leakage. Summary of the Invention
[0005] The embodiments of the present invention provide a method for privacy-preserving inference of large models in collaboration with a coprocessor and a trusted execution environment, which can reduce the computational pressure and data transmission overhead of the trusted execution environment and improve the efficiency of privacy-preserving inference of large language models.
[0006] To achieve the above objectives, in a first aspect, embodiments of the present invention provide a method for privacy-preserving inference of large models through collaboration between a coprocessor and a trusted execution environment, the method comprising: Acquire initial encrypted input data and auxiliary mask data; the initial encrypted input data is the data obtained by encrypting the embedding vector of the user's query text using a first random mask on the user's end; the auxiliary mask data is used to decrypt the intermediate encrypted results calculated on the first processor; the first processor is a coprocessor; The initial encrypted input data is used as the encrypted input data of the first layer of the target inference model. The first processor performs linear operator operations on the encrypted input data of the first layer of the network to obtain the encrypted intermediate result. The second processor decrypts the encrypted intermediate result based on the auxiliary mask data to obtain plaintext intermediate data, and performs nonlinear operator operations on the plaintext intermediate data within the second processor to obtain the plaintext calculation result corresponding to the first network layer; the second processor is a processor in a trusted execution environment; The second processor re-encrypts the plaintext calculation result using an output mask to obtain the encrypted output data corresponding to the first network layer, and then sends the encrypted output data back to the first processor. The encrypted output data is used as the encrypted input data of the next network layer to obtain the encrypted output data of the next network layer, until the inference of all network layers of the target inference model is completed, and the target encrypted inference result is obtained.
[0007] In one embodiment, after completing the inference of all network layers of the target inference model and obtaining the target encryption inference result, the method further includes: The target encrypted reasoning result is returned to the user terminal, so that the user terminal can decrypt the target encrypted reasoning result using the corresponding output mask to obtain the plaintext reasoning result and convert it into natural language output; the output mask is derived from the first random mask.
[0008] In one embodiment, obtaining auxiliary mask data includes: In the offline stage before online inference, the model parameters of the target inference model are obtained through the second processor. Based on the model parameters and the first random mask, the mask data corresponding to each network layer is pre-calculated, and the mask data of each layer is sealed and stored through a trusted sealing mechanism to obtain the auxiliary mask data.
[0009] In one embodiment, the step of performing linear operator operations on the encrypted input data of the first network layer through the first processor to obtain an intermediate encrypted result includes: When the first network layer is a self-attention layer, the first processor performs matrix multiplication with the query weight matrix, key weight matrix, and value weight matrix respectively based on the encrypted input data of the first network layer to obtain the encrypted query vector, encrypted key vector, and encrypted value vector, and performs position rotation encoding transformation on the encrypted query vector and the encrypted key vector to obtain the encrypted intermediate result corresponding to the self-attention layer. When the first network layer is a multilayer perceptron layer, the first processor performs matrix multiplication with the gate layer weight matrix and the upprojection layer weight matrix respectively based on the encrypted input data of the first network layer to obtain the encrypted gate vector and the encrypted upprojection vector, and generates the encrypted intermediate result corresponding to the multilayer perceptron layer.
[0010] In one embodiment, the step of decrypting the encrypted intermediate result based on the auxiliary mask data using a second processor to obtain plaintext intermediate data includes: When the first network layer is a self-attention layer, the second processor obtains the corresponding query mask, key mask and value mask in the auxiliary mask data, and subtracts the encrypted query vector, encrypted key vector and encrypted value vector from the corresponding mask element by element to recover the plaintext query vector, plaintext key vector and plaintext value vector, which are used as the plaintext intermediate data corresponding to the self-attention layer. When the first network layer is a multilayer perceptron layer, the second processor obtains the corresponding gating mask and upprojection mask from the auxiliary mask data, and subtracts the encrypted gating vector and encrypted upprojection vector from the corresponding mask element by element to recover the plaintext gating vector and plaintext upprojection vector, which are used as the plaintext intermediate data corresponding to the multilayer perceptron layer.
[0011] In one embodiment, the step of performing nonlinear operator operations on the plaintext intermediate data within the second processor to obtain the plaintext calculation result includes: When the first network layer is a self-attention layer, the second processor calculates the scaled dot product attention result based on the plaintext query vector, plaintext key vector and plaintext value vector obtained by decryption, and performs Softmax normalization operation on the scaled dot product attention result to obtain the plaintext calculation result corresponding to the self-attention layer. When the first network layer is a multilayer perceptron layer, the second processor performs SiLU activation function operation on the decrypted plaintext gate vector, and multiplies the activation result element-wise with the decrypted plaintext projection vector to obtain the plaintext calculation result corresponding to the multilayer perceptron layer.
[0012] In one embodiment, the step of re-encrypting the plaintext calculation result using an output mask by the second processor to obtain encrypted layer output data includes: The second processor obtains the output mask corresponding to the plaintext calculation result of the current layer from the auxiliary mask data; The plaintext calculation result is added element by element to the output mask to obtain the encryption layer output data corresponding to the first network layer.
[0013] Secondly, embodiments of the present invention provide a large-model privacy inference apparatus that coordinates a coprocessor and a trusted execution environment, comprising: An acquisition unit is used to acquire initial encrypted input data and auxiliary mask data; the initial encrypted input data is data obtained by encrypting the embedding vector of the user's query text using a first random mask on the user terminal; the auxiliary mask data is used to decrypt the intermediate encryption results calculated on the first processor; the first processor is a coprocessor; The first computing unit is used to take the initial encrypted input data as the encrypted input data of the first layer of the target inference model, and to perform linear operator operations on the encrypted input data of the first layer of the network layer through the first processor to obtain the encrypted intermediate result. The second computing unit is used to decrypt the encrypted intermediate result based on the auxiliary mask data through the second processor to obtain plaintext intermediate data, and to perform nonlinear operator operations on the plaintext intermediate data within the second processor to obtain the plaintext calculation result corresponding to the first network layer; the second processor is a processor in a trusted execution environment. The return unit is used to re-encrypt the plaintext calculation result by the second processor using an output mask to obtain the encrypted output data corresponding to the first network layer, and return the encrypted output data to the first processor. The processing unit is used to use the encrypted output data as the encrypted input data of the next network layer to obtain the encrypted output data of the next network layer, until the inference of all network layers of the target inference model is completed, and the target encrypted inference result is obtained.
[0014] Thirdly, embodiments of the present invention provide an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the large model privacy inference method described in the first aspect.
[0015] Fourthly, a computer-readable storage medium is provided, wherein at least one program is stored therein, the at least one program being executed by a processor to implement the steps of the large model privacy inference method as described in the first aspect.
[0016] Thus, the large model privacy inference method provided in this embodiment completes the linear operator operations of each layer of the model in the encrypted state by the coprocessor, and completes the decryption of the encrypted intermediate results, nonlinear operator operations and result re-encryption by the processor in the trusted execution environment. The calculation of all network layers of the target inference model is completed by the layer-by-layer encrypted state iteration, and finally the target encrypted inference result is obtained.
[0017] Based on the above execution method, the coprocessor can complete large-scale linear operations entirely on encrypted data, giving full play to its parallel computing advantages, handling high-density computational tasks in model inference, and effectively reducing the overall inference latency. At the same time, all decryption operations, nonlinear calculations, and re-encryption operations involving plaintext are completed within a trusted execution environment. This ensures that all feature data on the coprocessor side and in the inter-layer data transmission link remain encrypted throughout the process, and plaintext only exists briefly within the trusted execution environment. This effectively protects the data privacy and security of user input, intermediate model states, and final inference results, thereby improving the overall execution efficiency of privacy-preserving inference while ensuring privacy and security across the entire link. Attached Figure Description
[0018] Figure 1 This is a system architecture diagram corresponding to the large model privacy inference method provided in an embodiment of the present invention; Figure 2 This is one of the flowcharts corresponding to the large model privacy inference method provided in an embodiment of the present invention; Figure 3 The second schematic diagram of the large model privacy inference method provided in an embodiment of the present invention; Figure 4 A schematic diagram of a privacy-preserving inference device for a model provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation
[0019] To further illustrate the various embodiments, the present invention provides accompanying drawings. These drawings are part of the disclosure of the present invention, primarily used to illustrate the embodiments and to explain the operating principles of the embodiments in conjunction with the relevant descriptions in the specification. With reference to these drawings, those skilled in the art should be able to understand other possible implementations and the advantages of the present invention. Components in the drawings are not drawn to scale, and similar component symbols are generally used to represent similar components.
[0020] The present invention will now be further described in conjunction with the accompanying drawings and specific embodiments.
[0021] Reference Figure 1 The diagram shown is a system architecture diagram corresponding to a large model privacy inference method that uses a coprocessor and a trusted execution environment in collaboration, provided by an embodiment of the present invention. The overall architecture includes two parts: a user terminal 11 and a server terminal 12. The server terminal 12 deploys a target large language model 121 and is configured with a first processor 122 and a second processor 123. The two processors complete end-to-end privacy protection inference through the division of computing power and the interaction of encrypted data.
[0022] Client 11 is responsible for encrypting the original input and decrypting the final result. The client generates an independent random mask, performs element-wise concatenation encryption on the input embedding vector to obtain the initial encrypted input data, and uploads it to the server. The client holds the mask locally and, after receiving the encryption result returned by the server, performs decryption locally to obtain the plaintext output. The original plaintext data does not leave the client at any point in the process.
[0023] Server 12 splits the computational tasks into two types of processors based on operator characteristics. The first processor 122 is deployed in the general computing domain, carrying out all operator operations with linear homomorphic properties, including matrix multiplication, positional rotation encoding, residual connection, and layer normalization. It completes the computation entirely based on ciphertext data and does not access plaintext feature information. The second processor 123 runs in a trusted execution environment and is responsible for nonlinear operator operations that depend on plaintext and end-to-end mask management. In the offline stage, it completes the pre-computation and sealed storage of all auxiliary masks. In the online stage, it performs mask desealing, ciphertext decryption, nonlinear calculation, and result re-encryption. All plaintext data and masks exist only within the trusted domain.
[0024] The user terminal 11 and the server terminal 12 complete cross-processor interaction through encrypted intermediate results, which balances the efficiency of large-scale parallel computing and data privacy and security without changing the model inference logic or losing inference accuracy.
[0025] Furthermore, based on the above architecture, embodiments of the present invention provide a large-model privacy inference method, referring to... Figure 2 The diagram shown illustrates a flowchart of a large-model privacy inference method. In this embodiment, the method specifically includes the following steps: S201: Obtain the initial encrypted input data and auxiliary mask data.
[0026] The initial encrypted input data is the data obtained by encrypting the embedding vector of the user's question text using a first random mask on the user's end; the auxiliary mask data is used to decrypt the intermediate encrypted results calculated on the first processor; the first processor is a coprocessor.
[0027] Specifically, the initial encrypted input data is encrypted locally by the user and then uploaded to the inference server.
[0028] In some embodiments, a user can input a question text via voice or text in a preset model interaction window, such as the input box of an application equipped with a large language model. Then, after receiving the user's input question text, the user terminal needs to perform input embedding processing on the question text to obtain a corresponding plaintext embedding vector. The user terminal can then encrypt the embedding vector using a first random mask to obtain initial encrypted input data. In some embodiments, the encryption operation is performed using element-wise addition, i.e.: Encrypted input data = Embedding vector + First random mask.
[0029] The first random mask is a random vector generated using a One-Time Pad (OTP) method, and its dimension is consistent with that of the embedded vector to ensure that the mask can be operated on element-wise with the embedded vector. The user sends the initially encrypted input data to the server to initiate the subsequent privacy-preserving inference process. Since the first random mask is independently generated and held by the user, the server can only obtain the encrypted vector data and cannot reconstruct the plaintext information input by the user, thus ensuring the privacy and security of the user's input data from the source of inference.
[0030] The auxiliary mask data is a set of masks pre-computed offline, used to decrypt the encrypted intermediate results output by the first processor. The first processor is specifically a coprocessor with massively parallel computing capabilities, such as a graphics processing unit (GPU), or a hardware processor with parallel matrix operation acceleration capabilities, such as a tensor processing unit (TPU) or a neural processing unit (NPU), used to handle dense linear operator operations in model inference.
[0031] In this embodiment of the invention, the auxiliary mask data is pre-generated in the offline stage. The generation method can be as follows: in the offline stage before online inference, the model parameters of the target inference model are obtained by the second processor, the mask data corresponding to each network layer is pre-calculated according to the model parameters and the first random mask, and the mask data of each layer is sealed and stored through a trusted sealing mechanism to obtain the auxiliary mask data.
[0032] Specifically, the second processor is a computing unit running within a Trusted Execution Environment (TEE). The TEE is a secure, isolated execution environment provided by hardware security extensions (such as Intel SGX, AMD SEV, or ARM TrustZone technologies). It is isolated from the conventional operating system environment and provides confidentiality and integrity protection for the code and data running within it, and is only used to perform sensitive operations involving plaintext data.
[0033] Furthermore, during the preprocessing stage, when the second processor performs mask pre-computation, it generates corresponding mask data for each self-attention sublayer and multilayer perceptron sublayer of each decoder layer in the target inference model, and seals them uniformly to form a complete set of auxiliary masks for use in the online inference stage by desealing layer by layer; the specific process includes the following: (1) For the self-attention layer, the second processor obtains the first random mask. and the first random mask The query weight matrix of the self-attention layer respectively Key weight matrix Sum weight matrix Perform matrix multiplication to calculate the query mask, key mask, and value mask.
[0034] During the online inference phase, the query vector and key vector undergo further Rotary Positional Embedding (RoPE) transformation. To ensure that the offline pre-computed mask accurately matches the mask components of the online encrypted intermediate results, the second processor also needs to perform the same Rotary Positional Embedding transformation on the query mask and key mask as on the online side. The value mask, however, does not undergo this transformation. The corresponding calculation formula is as follows:
[0035]
[0036]
[0037] in, This is the query mask after weight transformation and position rotation encoding. This is the key mask after weight transformation and position rotation encoding. This is the value mask after weight transformation.
[0038] Based on this, the second processor uses the same first random mask. The output mask of the self-attention layer is derived. The output mask perfectly matches the dimension of the final plaintext calculation result of the self-attention layer, and together with the query mask, key mask, and value mask mentioned above, it constitutes the auxiliary mask data of the current self-attention layer.
[0039] After completing all mask calculations, the second processor will transform the query mask. Transformed key mask Value mask and pre-configured self-attention layer output mask It is stored in a sealed manner through a reliable sealing mechanism.
[0040] The self-attention layer output mask is one of the auxiliary mask data, used in conjunction with intermediate masks for decryption, such as the query mask, key mask, and value mask. The intermediate decryption mask is used in the online inference phase to decrypt the encrypted intermediate results output by the first processor to restore the plaintext intermediate data. The output mask is used in the online inference phase to re-encrypt the plaintext computation results obtained within the trusted execution environment, restoring the data to its encrypted state before it leaves the trusted domain. Together, they form a complete encryption / decryption logic loop within a single network layer, ensuring the matching and consistency of the entire masking system.
[0041] Specifically, the sealing operation relies on the Trusted Execution Environment's native sealing function: the aforementioned mask data... The sealed interface inside the Trusted Execution Environment (TEE) encrypts the mask data and generates an integrity verification tag, completing the encryption and sealing process. The sealed auxiliary mask data is stored in the server's local storage medium. Conventional operating systems and the first processor cannot parse the sealed content; the original mask value can only be read after a desealing operation is performed within the second processor. This ensures the security of the mask system from the storage perspective.
[0042] (2) For the multilayer perceptron layer, the second processor is also based on the first random mask. Perform offline pre-computation. First random mask. After linear transformation by the preceding self-attention layer, residual and normalization module, the input mask of the multilayer perceptron layer is obtained. The second processor will input the mask. Matrix multiplication is performed with the gate layer weight matrix and the upprojection layer weight matrix respectively to obtain the corresponding gate mask and upprojection mask. Simultaneously, the mask corresponding to the activated intermediate features and the final layer output mask after downprojection weight transformation are derived. The corresponding calculation formulas are as follows:
[0043]
[0044]
[0045] in, This is the gate layer weight matrix. Here is the weight matrix of the upper projection layer. This is the weight matrix for the lower projection layer; For gating mask, For the up-projection mask, For the lower projection mask, This is the mask corresponding to the intermediate calculation result after SiLU (Sigmoid LinearUnit) activation and element-wise multiplication. It is used to re-encrypt the intermediate plaintext result during the online inference stage. Unlike the self-attention layer, the operation process of the multilayer perceptron layer does not involve position rotation encoding transformation, so the mask does not need to undergo additional position encoding transformation operations.
[0046] The aforementioned gating mask, upper projection mask, intermediate feature mask, and lower projection output mask together constitute the auxiliary mask data corresponding to the current multilayer perceptron layer.
[0047] Among them, the gating mask and the upper projection mask are intermediate decryption masks, used to decrypt the encrypted intermediate results output by the first processor during the online inference stage; the lower projection output mask is a layer output mask, used to re-encrypt the plaintext calculation results in the trusted execution environment, forming a symmetrical encryption and decryption logic closed loop with the auxiliary mask data of the self-attention layer.
[0048] Furthermore, after completing the mask calculations for all layers of the multilayer perceptron, the second processor will obtain the gated mask. Upper projection mask Intermediate feature mask and the down-projection output mask It is stored in a sealed manner through a reliable sealing mechanism.
[0049] Specifically, the sealing operation also relies on the native sealing function of the Trusted Execution Environment (TEE), that is, the mask data of the aforementioned multi-layer perceptron layer is sent to the sealing interface inside the TEE, and the TEE processes the mask data. Encryption is performed and an integrity verification tag is generated to complete the encryption and sealing process; among which, the intermediate feature mask... Used in the online inference phase, the intermediate plaintext results calculated within the trusted execution environment are re-encrypted to ensure privacy and security when the intermediate data is transmitted back to the first processor for projection operations. The sealed multilayer perceptron auxiliary mask data is stored in the server's local storage medium. Conventional operating systems and the first processor cannot parse the sealed content; the original mask value can only be read after the desealing operation is performed within the second processor.
[0050] Since the decoder of a large language model is composed of multiple layers of network with a consistent structure and fixed model weight parameters, the auxiliary mask pre-computation of all decoder layers can be completed offline, constructing a unified model-level sealed mask set. This completely offloads mask computation to the offline stage, further reducing the computational burden of online inference. The specific execution process is as follows: In the offline initialization stage, the second processor loads all weight parameters of the target inference model and the total number of decoder layers, completing the reliable loading of model parameters; iterates through each decoder layer, performing complete mask derivation calculations for the self-attention sublayer and multilayer perceptron sublayer of that layer, generating independent self-attention mask sets and multilayer perceptron mask sets for each layer; a reliable sealing operation is performed on all masks generated for each layer, storing all sealed masks of all layers uniformly into the model-level auxiliary mask set, with each layer's mask corresponding one-to-one and not reused; the complete model-level sealed mask set is encrypted and stored on the server's local storage medium, and a unified desealing operation is performed when online inference starts, retrieving the corresponding mask layer by layer to participate in the computation as the inference progresses. This mechanism moves all mask calculations to the offline stage, while the online stage only needs to perform mask decapsulation and layer-by-layer retrieval, without performing any mask derivation calculations online. This further reduces the computational latency of online inference, while uniformly managing the mask data of the entire model, avoiding redundant calculations and storage.
[0051] It should be noted that each network layer of the target inference model independently generates a corresponding set of auxiliary mask data, starting from the first random mask. The auxiliary mask data for each network layer are independent and matched one-to-one. After the mask data for all network layers is calculated, it is securely stored through a trusted sealing mechanism, ensuring that sensitive mask-related information is not leaked outside the trusted execution environment. At this point, the preparation of the initial encrypted input data and auxiliary mask data in step S201 is complete, and the subsequent online layer-by-layer inference process can be initiated.
[0052] S202: The initial encrypted input data is used as the encrypted input data of the first layer of the target inference model. The first processor performs linear operator operations on the encrypted input data of the first layer of the network to obtain the encrypted intermediate result.
[0053] The target inference model is a Large Language Model (LLM), whose network structure includes multiple stacked network layers. During inference, calculations are performed layer by layer starting from the first network layer, and the output of the first network layer is used as the input of the next network layer. For the first network layer, its encrypted input data is the initial encrypted input data obtained in step S201. For subsequent network layers, their encrypted input data is the encrypted output data of the previous network layer.
[0054] The first processor is a coprocessor, a dedicated processor that assists the main processor (e.g., a central processing unit (CPU)) in performing specific types of computational tasks. It works in conjunction with the main processor: the main processor is responsible for task scheduling and logic control, while the coprocessor focuses on completing specific types of high-intensity computational tasks. In this embodiment of the invention, the first processor, as a coprocessor, is dedicated to performing linear operator operations with a high computational load during large language model inference, such as matrix multiplication and positional rotation encoding transformations—massive parallel computational tasks. These operations are characterized by high data parallelism and computational intensity, which are well-suited to the computational characteristics of the coprocessor. The coprocessor is configured with a massively parallel computing unit array, suitable for concurrently processing large batches of computational tasks, thereby sharing the computational burden on the general-purpose processor.
[0055] It should be noted that the coprocessor includes, but is not limited to, any one or more of a graphics processing unit (GPU), a neural processing unit (NPU), or a tensor processing unit (TPU). This embodiment of the invention uses a graphics processing unit as an example for illustration.
[0056] Since the data processed by the first processor is all encrypted, it is impossible to obtain the plaintext content corresponding to the data. Therefore, even if the first processor runs in a normal untrusted environment, it will not cause leakage of user privacy data.
[0057] S203: The second processor decrypts the encrypted intermediate result based on the auxiliary mask data to obtain plaintext intermediate data, and performs nonlinear operator operations on the plaintext intermediate data within the second processor to obtain the plaintext calculation result corresponding to the first network layer.
[0058] The second processor is a processor in a trusted execution environment.
[0059] The second processor is a computing unit running within a Trusted Execution Environment (TEE). The TEE is implemented using hardware security extension technologies (such as Intel SGX, AMDSEV, ARM TrustZone, etc.), and is hardware isolated from the conventional operating system runtime environment, providing confidentiality and integrity protection for the code and data running within it. In this step, plaintext decryption operations and nonlinear operator calculations are all performed within this secure domain, ensuring that plaintext data is not exposed outside the TEE.
[0060] During the decryption process, the second processor retrieves the mask value corresponding to the current encrypted intermediate result from the auxiliary mask data, subtracts the encrypted intermediate result from the corresponding mask element by element, and recovers the plaintext intermediate data. Since the auxiliary mask data has been pre-calculated offline and stored through a trusted sealing mechanism, decryption can be quickly completed by simply unsealing and reading it during online inference, without the need to perform mask transformation operations in real time, effectively reducing online computation latency.
[0061] After decryption, the second processor, within the trusted execution environment, performs corresponding nonlinear operator operations on the plaintext intermediate data according to the type of the current first network layer, to obtain the plaintext calculation result corresponding to the first network layer. Nonlinear operator operations are types of operations that cannot be directly performed on encrypted data during model inference and must be calculated based on plaintext data. The specific operation implementation methods for different network layers will be described in detail in subsequent embodiments.
[0062] S204: The second processor re-encrypts the plaintext calculation result using an output mask to obtain the encrypted output data corresponding to the first network layer, and then sends the encrypted output data back to the first processor.
[0063] It should be noted that this step is a connecting step in the single-round dual-processor collaborative computing. It is used to re-encrypt the plaintext computing results in the trusted execution environment and send them back, ensuring that the data is in an encrypted state throughout the process after leaving the trusted domain, so as to provide input for the subsequent dense-state iterative computing of the network layer.
[0064] Specifically, the second processor retrieves the output mask corresponding to the plaintext calculation result of the current layer from the auxiliary mask data. It then uses a one-time pad encryption method, adding the plaintext calculation result element-by-element to the output mask to obtain the encrypted layer output data corresponding to the first network layer. The output mask has the same dimension as the corresponding plaintext calculation result and has been pre-calculated and sealed in the offline stage; it is directly desealed and retrieved by the second processor in the online stage.
[0065] After encryption, the second processor transmits the encrypted layer output data out of the trusted execution environment and back to the first processor. Through re-encryption, the plaintext calculation result is encrypted and protected before leaving the trusted execution environment. The data in the first processor and the inter-layer transmission link is encrypted throughout the entire process, and the plaintext only appears briefly inside the trusted execution environment, thus achieving data privacy protection throughout the entire inference link.
[0066] S205: Use the encrypted output data as the encrypted input data of the next network layer to obtain the encrypted output data of the next network layer, until the inference of all network layers of the target inference model is completed, and obtain the target encrypted inference result.
[0067] Specifically, the encrypted output data of the previous network layer is used as the encrypted input data of the next network layer. For each subsequent network layer, the calculation process of steps S202 to S204 is repeated in sequence: the first processor performs the linear operator operation of the current layer in the encrypted state, and the second processor completes the decryption, nonlinear operator operation and result re-encryption and sends it back to the first processor.
[0068] After traversing all network layers of the target inference model, the output data of the last encrypted layer is the target encrypted inference result. This result can be returned to the user, who can decrypt it using the output mask derived from the first random mask with the same source, obtaining the plaintext natural language inference result. The server does not hold the root mask or the final plaintext data throughout the process, achieving end-to-end privacy protection.
[0069] Through a heterogeneous collaborative architecture with inter-layer iterations, this step achieves privacy protection across the entire inference chain of a large language model, while maximizing the parallel computing advantages of the coprocessor, effectively balancing data privacy and security with inference execution efficiency.
[0070] It should be noted that, after completing the inference of all network layers of the target inference model and obtaining the target encryption inference result in this embodiment of the invention, the following steps still need to be performed: The target encrypted reasoning result is returned to the user terminal, so that the user terminal can decrypt the target encrypted reasoning result using the corresponding output mask, obtain the plaintext reasoning result, and convert it into natural language output.
[0071] The output mask is derived from the first random mask.
[0072] Specifically, this step is executed after the inference calculations of all network layers of the target inference model are completed and the target encrypted inference result is obtained. It is used to return the inference result to the user and complete the final plaintext restoration, thereby achieving end-to-end privacy protection throughout the entire inference chain.
[0073] In this embodiment of the invention, the server returns the final target encrypted inference result to the user client that initiated the inference request. The target encrypted inference result is encrypted throughout the entire process of calculation, transmission and storage on the server. The server does not hold the root mask that can directly decrypt the result and cannot restore the inference result in plaintext form.
[0074] After receiving the target encrypted inference result, the user terminal performs a decryption operation on it using the corresponding output mask to obtain the inference feature vector in plaintext form. This vector is then post-processed and converted into readable natural language response content and presented to the user. The output mask is derived linearly layer by layer along the model network from the first random mask of this inference. It is homologous to the mask components of the target encrypted inference result and has a perfectly matched dimension, allowing for accurate reconstruction of the plaintext result through element-wise subtraction.
[0075] Since the first random mask is generated independently by the user and held throughout the process, the root key of the entire mask system exists only on the user's side. The server cannot restore the plaintext question input by the user or obtain the final plaintext reasoning result during the entire reasoning process. This truly achieves end-to-end privacy protection from input to output and further strengthens the security boundary of user data.
[0076] In this embodiment of the invention, the coprocessor completes the linear operator operations of each layer of the model in the encrypted state, and the processor in the trusted execution environment completes the decryption of the encrypted intermediate results, the nonlinear operator operations, and the result re-encryption. The calculation of all network layers of the target inference model is completed through layer-by-layer encrypted iteration, and the target encrypted inference result is finally obtained.
[0077] Based on the above execution method, the coprocessor can complete large-scale linear operations entirely on encrypted data, giving full play to its parallel computing advantages, handling high-density computational tasks in model inference, and effectively reducing the overall inference latency. At the same time, all decryption operations, nonlinear calculations, and re-encryption operations involving plaintext are completed within a trusted execution environment. This ensures that all feature data on the coprocessor side and in the inter-layer data transmission link remain encrypted throughout the process, and plaintext only exists briefly within the trusted execution environment. This effectively protects the data privacy and security of user input, intermediate model states, and final inference results, thereby improving the overall execution efficiency of privacy-preserving inference while ensuring privacy and security across the entire link.
[0078] As an extension and refinement of the above embodiments, S202 (performing linear operator operations on the encrypted input data of the first network layer by the first processor to obtain an intermediate encrypted result) in the above embodiments specifically includes the following two cases: When the first network layer is a self-attention layer, the first processor performs matrix multiplication with the query weight matrix, key weight matrix, and value weight matrix respectively based on the encrypted input data of the first network layer to obtain the encrypted query vector, encrypted key vector, and encrypted value vector, and performs position rotation encoding transformation on the encrypted query vector and the encrypted key vector to obtain the encrypted intermediate result corresponding to the self-attention layer.
[0079] Specifically, for the self-attention layer, let the encrypted input data of the first network layer be... The encrypted input data is a plaintext embedding vector embedded by the user end using a first random mask r. The encrypted data satisfies = +r. The first processor will encrypt the input data. Compare with the pre-trained query weight matrix respectively Key weight matrix Sum weight matrix Perform matrix multiplication to calculate the encrypted query vector. Encryption key vector and encrypted value vector :
[0080]
[0081]
[0082] in, , and These are the encrypted query vector, encrypted key vector, and encrypted value vector, respectively.
[0083] Based on this, in order to maintain operational consistency with the position rotation encoding transformation performed on the query mask and key mask during the offline stage, the first processor also performs operations on the encrypted query vector. and the encryption key vector Perform the RoPE transformation to obtain the transformed encrypted query vector. and encryption key vector The corresponding calculation formula is as follows:
[0084]
[0085] After transformation, we get , Combined with the untransformed encrypted value vector These three components together constitute the encrypted intermediate result corresponding to the self-attention layer. All the above operations are performed on encrypted data. The first processor can only read the ciphertext and cannot obtain the plaintext information of the query, key, and value vectors. While undertaking large-scale linear computation, it ensures the data privacy and security of the computation process.
[0086] When the first network layer is a multilayer perceptron layer, the first processor performs matrix multiplication with the gate layer weight matrix and the upprojection layer weight matrix respectively based on the encrypted input data of the first network layer to obtain the encrypted gate vector and the encrypted upprojection vector, and generates the encrypted intermediate result corresponding to the multilayer perceptron layer.
[0087] Specifically, for a Multi-Layer Perceptron (MLP) layer, let the encrypted input data of this layer be... The encrypted input data is also obtained by superimposing plaintext feature vectors with corresponding random masks for encryption, and its encryption method is consistent with the element-by-element addition encryption method of the initial encrypted input data. The first processor encrypts the input data... Compared with the pre-trained gate layer weight matrix Weight matrix of upper projection layer Perform matrix multiplication to calculate the encrypted gate vector. Encrypted projection vector The corresponding calculation formula is as follows:
[0088]
[0089] in, This is the encrypted gating vector after a linear weight transformation. This is the encrypted upprojection vector after a weighted linear transformation.
[0090] Unlike self-attention layers, the computational process of a multilayer perceptron layer does not involve position rotation encoding transformation operations; therefore, the resulting encrypted gating vector... With encrypted projection vector These directly constitute the encrypted intermediate results corresponding to the multilayer perceptron layer.
[0091] It should be noted that all the above operations are performed directly on the encrypted data. The first processor can only read the ciphertext data and cannot restore the corresponding plaintext feature information. While undertaking the task of accelerating linear calculations, it ensures the data privacy and security of this layer of calculation process.
[0092] This invention, through configuring corresponding encrypted linear operation processes for the self-attention layer and the multilayer perceptron layer respectively, adapts to the differences in the operation structure of the two core sub-layers in the large language model decoder. While ensuring the consistency of the self-attention layer position rotation encoding transformation and offline mask pre-computation operation, and ensuring that the encrypted intermediate results can be accurately decrypted, it fully leverages the large-scale parallel computing capabilities of the first processor to carry all high-computing linear operations, effectively reducing the overall inference latency. At the same time, all linear operations are completed in encrypted state, avoiding the leakage of plaintext feature data on the coprocessor side, thus balancing privacy protection and security with inference execution efficiency.
[0093] As an extension and refinement of the above embodiments, the decryption process of S203 (using the second processor to decrypt the encrypted intermediate result based on the auxiliary mask data to obtain plaintext intermediate data) in the above embodiments needs to match the type of the current first network layer. For the encrypted intermediate results output by different network layers, the corresponding auxiliary mask is retrieved to perform element-by-element decryption operations. The specific implementation is as follows: When the first network layer is a self-attention layer, the second processor obtains the corresponding query mask, key mask, and value mask from the auxiliary mask data. The encrypted query vector, encrypted key vector, and encrypted value vector are subtracted element by element from the corresponding mask to recover the plaintext query vector, plaintext key vector, and plaintext value vector, which are used as the plaintext intermediate data corresponding to the self-attention layer.
[0094] Specifically, based on the calculations in the aforementioned embodiments, the transformed encrypted query vector is: The transformed encryption key vector is The encrypted value vector is The corresponding auxiliary masks are the query mask and the query mask, respectively. , key mask Value mask The decryption process satisfies the following operational relationships:
[0095]
[0096]
[0097] Where Q is the plaintext query vector recovered through decryption, K is the plaintext key vector recovered through decryption, and V is the plaintext value vector recovered through decryption. Since the auxiliary mask and the mask components of the online encrypted linear operation are homologous and perfectly matched, element-wise subtraction can accurately cancel mask perturbations and restore unbiased plaintext intermediate data; moreover, all decryption operations are completed within a trusted execution environment, and plaintext feature data will not be leaked externally.
[0098] When the first network layer is a multilayer perceptron layer, the second processor obtains the corresponding gating mask and upprojection mask from the auxiliary mask data, and subtracts the encrypted gating vector and encrypted upprojection vector from the corresponding mask element by element to recover the plaintext gating vector and plaintext upprojection vector, which are used as the plaintext intermediate data corresponding to the multilayer perceptron layer.
[0099] Specifically, based on the calculations in the aforementioned embodiments, the encryption gate vector is: The encrypted projection vector is The corresponding auxiliary masks are the gate masks. Upper projection mask The decryption process satisfies the following operational relationships:
[0100]
[0101] Where G is the plaintext gate vector obtained by decryption and recovery, and U is the plaintext projection vector obtained by decryption and recovery.
[0102] Since the auxiliary mask and the mask components of the online dense linear operation are homologous and perfectly matched, the mask perturbation can be accurately canceled after element-by-element subtraction, and the unbiased plaintext intermediate data can be restored; moreover, all decryption operations are completed within a trusted execution environment, and the plaintext feature data will not be leaked to the outside.
[0103] This invention adapts to the differences in the operational structures of the two core sub-layers in a large language model decoder by matching corresponding auxiliary masks for the self-attention layer and the multilayer perceptron layer respectively and performing element-wise subtraction decryption operations. This ensures that the offline pre-computed mask is accurately aligned with the mask components of the online encrypted intermediate result, allowing for unbiased reconstruction of the plaintext intermediate data. At the same time, the decryption operation has low computational complexity, does not add extra computational burden to the trusted execution environment, and is completed entirely within the second processor, ensuring that the plaintext feature data does not leak out of the trusted domain. This balances decryption accuracy and inference execution efficiency while guaranteeing data privacy and security.
[0104] As an extension and refinement of the above embodiments, the decryption process of S203 (performing nonlinear operator operations on the plaintext intermediate data inside the second processor to obtain the plaintext calculation result) in the above embodiments needs to match the type of the current first network layer. For the encrypted intermediate results output by different network layers, the corresponding auxiliary mask is retrieved to perform element-by-element decryption operations. The specific implementation is as follows: When the first network layer is a self-attention layer, the second processor calculates the scaled dot product attention result based on the plaintext query vector, plaintext key vector and plaintext value vector obtained by decryption, and performs Softmax normalization operation on the scaled dot product attention result to obtain the plaintext calculation result corresponding to the self-attention layer.
[0105] Specifically, let the decrypted plaintext query vector be Q, the plaintext key vector be K, and the plaintext value vector be V. The nonlinear operation process of the self-attention layer satisfies the following formula:
[0106] in, To query the feature dimensions of the vector and key vector, The scaled dot product attention score is used; the Softmax operation is used to normalize the attention score into semantic probability weights, and finally, the plaintext calculation result of the self-attention layer is obtained by weighted summation of the weights into a vector. .
[0107] Since Softmax normalization is a non-linear operation, it cannot be directly completed in the ciphertext state by relying on the linear properties of the mask. Therefore, this step is executed in plaintext form within the trusted execution environment of the second processor, and the plaintext feature data does not flow out of the trusted domain throughout the process.
[0108] When the first network layer is a multilayer perceptron layer, the second processor performs SiLU activation function operation on the decrypted plaintext gate vector, and multiplies the activation result element-wise with the decrypted plaintext projection vector to obtain the plaintext calculation result corresponding to the multilayer perceptron layer.
[0109] Specifically, let the plaintext gating vector obtained from decryption be G, and the plaintext projection vector be U. The nonlinear operation process of the multilayer perceptron layer satisfies the following formula step by step:
[0110]
[0111] in, , Use the Sigmoid activation function; This is the intermediate result after the gated vector is activated by SiLU. This indicates element-wise multiplication. This represents the intermediate plaintext calculation results for the multilayer perceptron layer.
[0112] Since SiLU activation involves Sigmoid nonlinear transformation and element-wise multiplication, it does not satisfy the linear homomorphic property and cannot be directly computed in the encrypted state. Therefore, this step is completed entirely within the trusted execution environment of the second processor, which is consistent with the trusted computing logic of the self-attention layer, thus ensuring the privacy and security of feature data from the computational level.
[0113] This invention addresses the technical problem that nonlinear operators lack linear homomorphic properties and cannot be directly computed in encrypted form by placing both the Softmax normalization operation of the self-attention layer and the SiLU activation operation of the multilayer perceptron layer within the trusted execution environment of the second processor. This adapts to the computational characteristics of the two core sub-layers in the large language model decoder, ensures that plaintext feature data does not leak out of the trusted domain throughout the nonlinear computation, and avoids leakage of privacy data during the computation process. At the same time, it forms a division of computational power with the architecture where the first processor undertakes linear operator operations, maintaining the operational efficiency of model inference while ensuring data privacy and security.
[0114] As an extension and refinement of the above embodiments, refer to Figure 3 As shown, in the above embodiment, S204 (the plaintext calculation result is re-encrypted by the second processor using an output mask to obtain the encrypted layer output data) specifically includes the following steps: S301. The second processor obtains the output mask corresponding to the plaintext calculation result of the current layer from the auxiliary mask data.
[0115] This step can be understood as the pre-mask matching step in the re-encryption process, and it is executed entirely by a second processor running in a trusted execution environment.
[0116] The output masks retrieved in this step are all derived from the auxiliary mask dataset that was pre-computed and generated and stored in a trusted, sealed manner during the offline phase. After the online inference process starts, the second processor first performs a desealing operation on the full set of sealed auxiliary mask data to restore the plaintext mask set. Then, based on the current network layer type and current computation stage, it precisely matches the output mask from the mask set that completely corresponds to the dimension of the current plaintext computation result and has the same derivation relationship.
[0117] Since the entire mask retrieval and temporary storage process is completed within a trusted execution environment, the plaintext mask will not leak out of the trusted domain, ensuring the security of the entire masking system from the data acquisition stage. The objects retrieved in this step differ for different types of network layers: self-attention layers only need to retrieve a single layer output mask for re-encryption of the final self-attention calculation result; multilayer perceptron layers need to match both intermediate feature masks and the final layer output mask separately, adapting to the two different re-encryption stages: the return of intermediate calculation results for linear operations and the final layer output.
[0118] S302. The plaintext calculation result is added to the output mask element by element to obtain the encryption layer output data corresponding to the first network layer.
[0119] In this step, the element-wise additive mask encryption rule, which is exactly the same as the initial encryption on the user end, is adopted. The plaintext calculation result of the current stage is superimposed on the corresponding output mask in the same dimension element by element. The plaintext feature data is perturbed by a random mask to generate the encryption layer output data of the corresponding stage.
[0120] By adopting encryption rules that are the same as those used in the front-end encryption, the encrypted data after re-encryption is guaranteed to have completely consistent cryptographic characteristics with the initial encrypted data. It can be directly handed over to the first processor to perform subsequent linear operations such as weight multiplication and residual connection without additional format conversion or decryption preprocessing. This effectively reduces the additional performance overhead caused by encryption and decryption operations, while taking into account both privacy protection and inference efficiency.
[0121] It should be noted that the mask and execution logic for re-encryption operations differ for different types of network layers, as detailed below: When the first network layer is a self-attention layer, after the second processor completes Softmax normalization and obtains the plaintext self-attention calculation result, it retrieves the self-attention layer output mask that matches the current layer from the desealed auxiliary mask data; then, it adds the plaintext calculation result to the output mask element by element to obtain the encryption layer output data corresponding to the self-attention layer.
[0122] Specifically, the plaintext calculation results of the self-attention layer obtained in the aforementioned embodiments , recorded as The corresponding output mask is The re-encryption process satisfies the following operational relationship:
[0123] in, This is the output data of the encryption layer for the self-attention layer. This output data can directly participate in subsequent linear operations such as residual connection and layer normalization, and serves as the encryption input data for the multilayer perceptron layer, fully compatible with the encrypted computation process of the first processor.
[0124] It is important to note that residual connection and root mean square normalization are standard transition operations within the decoder layer. Both are affine operations with linear homomorphic properties, and therefore are executed directly on the ciphertext data by the first processor without needing to be passed to a trusted execution environment for decryption, further reducing cross-processor data transmission overhead. Specifically, residual connection is an element-wise addition operation of feature vectors, and root mean square normalization is a linear scaling operation of feature dimensions. Both satisfy the homomorphic property of mask addition: directly performing linear operations on ciphertext data is equivalent to performing operations on plaintext data and then superimposing the corresponding mask; the operation process does not destroy the perturbation effect of the mask. Therefore, after the encrypted output of the attention sublayer is returned to the first processor, the first processor directly performs element-wise addition of residual connection with the original encrypted input of that layer, and then completes the root mean square normalization operation. The resulting ciphertext can be directly used as the encrypted input of the multilayer perceptron sublayer.
[0125] When the first network layer is a multilayer perceptron layer, the re-encryption operation is divided into two stages: intermediate result re-encryption and final layer output re-encryption. Specifically, the intermediate plaintext result obtained after SiLU activation and element-wise multiplication is first re-encrypted using an intermediate feature mask and then sent back to the first processor for down-projection linear operation. After the down-projection operation is completed and the result is returned to the trusted execution environment for decryption, the second processor retrieves the final output mask of the multilayer perceptron layer to obtain the final encrypted layer output data.
[0126] Specifically, the final plaintext output of the multilayer perceptron layer obtained in the aforementioned embodiments is H, denoted as H. The corresponding layer output mask is The final re-encryption process satisfies the following operational relationship:
[0127] in, The data output from the encryption layer of the multilayer perceptron can be directly used as the encryption input for the next decoder layer and enter the next round of inference loop.
[0128] It should be noted that all re-encryption operations are completed within the trusted execution environment of the second processor. The plaintext calculation results exist only within the trusted domain. All data flowing out of the trusted execution environment is encrypted data after overlay masking. From the perspective of data transmission and cross-processor interaction, the data privacy and security of the entire inference chain are guaranteed.
[0129] This invention employs a two-step operation of precise retrieval of the output mask and element-wise re-encryption. It uses encryption rules derived from the front-end input encryption to complete the encrypted transformation of the plaintext calculation result. This ensures the consistency of the entire encryption system, allowing the re-encrypted ciphertext data to be directly adapted to subsequent linear operations and inter-layer transfers without additional preprocessing. It also ensures that all data flowing out of the trusted execution environment remains encrypted, forming a complete trusted computing closed loop with the pre-decryption and nonlinear calculation steps. At the same time, the lightweight element-wise operation does not increase the computing power overhead of the trusted domain, maintaining the running efficiency of model inference while ensuring the privacy and security of data throughout the entire chain.
[0130] In conjunction with the above embodiments, the self-attention sub-layer operation and the multilayer perceptron sub-layer operation are executed sequentially within a single decoder network layer. Both sub-layers follow the computing power division architecture and privacy protection rules of "linear operator operations are executed by the first processor and nonlinear operator operations are completed by the second processor in a trusted execution environment". All inference operations of a single network layer are completed by the method of ciphertext data flowing across processors and plaintext calculation within the trusted domain.
[0131] First, the computation of the self-attention sublayer is performed. That is, after receiving the encrypted input data, the first processor completes all linear operations such as querying, key-value vector weight mapping, etc., generating the corresponding encrypted intermediate results and transmitting them to the second processor. The second processor performs element-by-element decryption within a trusted execution environment, then performs non-linear operations such as Softmax normalization. After obtaining the plaintext computation result of the self-attention sublayer, it uses the corresponding output mask to perform re-encryption, generating the encrypted output of the self-attention sublayer. The data is then transmitted back to the first processor. After performing linear operations such as residual connection and layer normalization based on the ciphertext data, the first processor uses the processed ciphertext data as the encrypted input to the sublayer of the multilayer perceptron.
[0132] Subsequently, the computation of the multilayer perceptron sublayer is performed. Specifically, the first processor performs a linear operation of upward projection weight mapping based on the input ciphertext data, generating an encrypted gated vector and an upward projection vector, which are then transmitted to the second processor. The second processor decrypts the plaintext vector within a trusted execution environment, performs SiLU activation and element-wise multiplication nonlinear operations to obtain an intermediate plaintext result, and then uses an intermediate feature mask to perform the first re-encryption. The encrypted intermediate result is then transmitted back to the first processor to perform a linear operation of downward projection weight mapping. After the downward projection operation is completed, the encrypted result is again transmitted back to the second processor, which performs decryption and re-encryption of the final layer output, generating the encrypted output of the multilayer perceptron sublayer. .
[0133] Because the multilayer perceptron sublayer is located at the end of the computation link of a single decoder network layer, this encrypted output... This is the final encryption layer output data corresponding to the first network layer. This output can be directly used as the encryption input for the next decoder network layer, repeatedly executing the complete computation process of the self-attention sublayer and the multilayer perceptron sublayer. Through a layer-by-layer iterative loop, the inference operation of all decoder layers of the target inference model is completed, realizing privacy-preserving inference with full-link encrypted flow.
[0134] In some embodiments, for large language models fine-tuned using low-rank adaptation, this method can be extended to support privacy protection of fine-tuning parameters. While protecting user input, inference intermediate states and output results, it avoids leakage of fine-tuning weight parameters and adapts to inference scenarios of personalized fine-tuning models.
[0135] Specifically, LoRA fine-tuning achieves efficient parameter fine-tuning by adding a low-rank matrix increment next to the original basic weights. The low-rank matrix parameters are sensitive privacy data and are deployed entirely within the trusted execution environment of the second processor, without being exposed to the outside world. The basic weight matrix is still calculated in a secret state by the first processor, and the incremental part is calculated by the second processor and then sent back to the first processor in the form of a secret state increment, which is then merged with the basic ciphertext result to ensure that the fine-tuning parameters do not flow out of the trusted domain throughout the entire process.
[0136] Furthermore, in the offline phase, the second processor seals and stores the low-rank parameters of LoRA in a trusted execution environment, completing the trusted deployment of fine-tuning parameters; and combines the basic weights and the low-rank weights of LoRA to uniformly derive the complete masks corresponding to the attention layer and the multilayer perceptron layer. After sealing, the masks are added to the model-level mask set to ensure that the mask and the mask components of the final calculation result are completely matched, ensuring that the subsequent decryption operation is without deviation.
[0137] During the online phase, the second processor decrypts the LoRA low-rank parameters and corresponding masks, calculates the feature increment of the LoRA part in the trusted domain, and performs mask encryption on the increment result to generate encrypted incremental data, which is then sent to the first processor. The first processor performs linear operations on the basic weights on the encrypted input to obtain the basic ciphertext result, and then performs element-wise addition with the encrypted increment passed in by the second processor to obtain the fused complete ciphertext feature. Subsequent processes such as position rotation encoding transformation, nonlinear operation decryption, and result re-encryption are completely consistent with the basic model, ensuring the consistency of the inference architecture between the basic model and the fine-tuning model.
[0138] Furthermore, it achieves full lifecycle privacy protection for fine-tuning parameters, while fully reusing the heterogeneous collaborative computing architecture of the basic model without significantly altering the inference process, thus balancing security, scalability, and inference efficiency.
[0139] Figure 4 This is a schematic diagram of a privacy-preserving inference device for a model provided in an embodiment of the present invention, as shown below. Figure 4As shown, the privacy-preserving inference device 400 of the model includes: The acquisition unit 41 is used to acquire initial encrypted input data and auxiliary mask data; the initial encrypted input data is the data obtained by encrypting the embedding vector of the user's question text using a first random mask on the user terminal; the auxiliary mask data is used to decrypt the intermediate encryption result calculated on the first processor; the first processor is a coprocessor. The first computing unit 42 is used to take the initial encrypted input data as the encrypted input data of the first layer of the target inference model, and to perform linear operator operations on the encrypted input data of the first layer of the network layer by the first processor to obtain the encrypted intermediate result. The second computing unit 43 is used to decrypt the encrypted intermediate result based on the auxiliary mask data through the second processor to obtain plaintext intermediate data, and to perform nonlinear operator operations on the plaintext intermediate data within the second processor to obtain the plaintext calculation result corresponding to the first network layer; the second processor is a processor in a trusted execution environment. The return unit 44 is used to re-encrypt the plaintext calculation result by the second processor using an output mask to obtain the encrypted output data corresponding to the first network layer, and return the encrypted output data back to the first processor; Processing unit 45 is used to use the encrypted output data as the encrypted input data of the next network layer to obtain the encrypted output data of the next network layer, until the inference of all network layers of the target inference model is completed, and to obtain the target encrypted inference result.
[0140] Thus, in this embodiment, through a heterogeneous collaborative architecture between the coprocessor and the trusted execution environment, computational tasks are split according to operator characteristics: large-scale linear operators are offloaded to the coprocessor for dense execution, while only plaintext-dependent nonlinear operators are confined to the trusted execution environment. This fully leverages the parallel computing power of the coprocessor, overcomes the performance bottleneck of the trusted execution environment, and effectively improves inference efficiency; it also ensures end-to-end encryption of user input, model intermediate states, and inter-layer data transmission, achieving privacy protection throughout the entire inference chain.
[0141] Meanwhile, by pre-compiling and sealing the auxiliary masks at each layer offline, the mask transformation calculations related to fixed parameters are performed in advance, significantly reducing the online computational burden and latency overhead of the trusted execution environment. The entire mask system is derived from the user's first random mask, and the final result can be decrypted by the user. The server never touches the plaintext, achieving end-to-end privacy and security. In addition, this solution is compatible with low-rank adaptation fine-tuning models while protecting user data and fine-tuning parameters, making it more adaptable to various scenarios.
[0142] The present invention also provides an electronic device, Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention, as shown below. Figure 5 As shown, the electronic device includes a processor 501, a memory 502, a bus 503, and a computer program stored in the memory 502 and executable on the processor 501. The processor 501 includes one or more processing cores. The memory 502 is connected to the processor 501 via the bus 503. The memory 502 is used to store program instructions. When the processor executes the computer program, it implements the steps in the above-described method embodiment of Embodiment 1 of the present invention.
[0143] Furthermore, as an executable solution, the electronic device can be a computer unit, which can be a desktop computer, laptop, handheld computer, cloud server, or other computing device. The computer unit may include, but is not limited to, a processor and memory. Those skilled in the art will understand that the above-described structure of the computer unit is merely an example and does not constitute a limitation on the computer unit. It may include more or fewer components, or combine certain components, or use different components. For example, the computer unit may also include input / output devices, network access devices, buses, etc., and this embodiment of the invention does not limit this.
[0144] Furthermore, as an executable solution, the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor, etc. The processor is the control center of the computer unit, connecting various parts of the entire computer unit via various interfaces and lines.
[0145] The memory can be used to store the computer programs and / or modules. The processor implements various functions of the computer unit by running or executing the computer programs and / or modules stored in the memory and by calling data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system and at least one application program required for a function; the data storage area may store data created based on the use of the mobile phone, etc. In addition, the memory may include high-speed random access memory and may also include non-volatile memory, such as hard disk, RAM, plug-in hard disk, smart media card (SMC), secure digital card (SD), flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0146] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the method described in the embodiments of the present invention.
[0147] If the modules / units integrated in the computer unit are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction.
[0148] Although the invention has been specifically shown and described in conjunction with preferred embodiments, those skilled in the art should understand that various changes in form and detail may be made to the invention without departing from the spirit and scope of the invention as defined in the appended claims, all of which shall be within the scope of protection of the invention.
Claims
1. A method for privacy-preserving inference in large models through collaboration between a coprocessor and a trusted execution environment, characterized in that, include: Obtain the initial encrypted input data and auxiliary mask data; The initial encrypted input data is the data obtained by encrypting the embedding vector of the user's query text using a first random mask on the user's end; the auxiliary mask data is used to decrypt the intermediate encrypted results calculated on the first processor; the first processor is a coprocessor; The initial encrypted input data is used as the encrypted input data of the first layer of the target inference model. The first processor performs linear operator operations on the encrypted input data of the first layer of the network to obtain the encrypted intermediate result. The second processor decrypts the encrypted intermediate result based on the auxiliary mask data to obtain plaintext intermediate data, and performs nonlinear operator operations on the plaintext intermediate data within the second processor to obtain the plaintext calculation result corresponding to the first network layer; the second processor is a processor in a trusted execution environment; The second processor re-encrypts the plaintext calculation result using an output mask to obtain the encrypted output data corresponding to the first network layer, and then sends the encrypted output data back to the first processor. The encrypted output data is used as the encrypted input data of the next network layer to obtain the encrypted output data of the next network layer, until the inference of all network layers of the target inference model is completed, and the target encrypted inference result is obtained.
2. The method according to claim 1, characterized in that, After completing the inference of all network layers of the target inference model and obtaining the target encryption inference result, the method further includes: The target encrypted reasoning result is returned to the user terminal, so that the user terminal can decrypt the target encrypted reasoning result using the corresponding output mask to obtain the plaintext reasoning result and convert it into natural language output; the output mask is derived from the first random mask.
3. The method according to claim 1, characterized in that, Obtain auxiliary mask data, including: In the offline stage before online inference, the model parameters of the target inference model are obtained through the second processor. Based on the model parameters and the first random mask, the mask data corresponding to each network layer is pre-calculated, and the mask data of each layer is sealed and stored through a trusted sealing mechanism to obtain the auxiliary mask data.
4. The method according to claim 1, characterized in that, The step of performing linear operator operations on the encrypted input data of the first network layer through the first processor to obtain the intermediate encryption result includes: When the first network layer is a self-attention layer, the first processor performs matrix multiplication with the query weight matrix, key weight matrix, and value weight matrix respectively based on the encrypted input data of the first network layer to obtain the encrypted query vector, encrypted key vector, and encrypted value vector, and performs position rotation encoding transformation on the encrypted query vector and the encrypted key vector to obtain the encrypted intermediate result corresponding to the self-attention layer. When the first network layer is a multilayer perceptron layer, the first processor performs matrix multiplication with the gate layer weight matrix and the upprojection layer weight matrix respectively based on the encrypted input data of the first network layer to obtain the encrypted gate vector and the encrypted upprojection vector, and generates the encrypted intermediate result corresponding to the multilayer perceptron layer.
5. The method according to claim 1, characterized in that, The step of decrypting the encrypted intermediate result based on the auxiliary mask data using the second processor to obtain plaintext intermediate data includes: When the first network layer is a self-attention layer, the second processor obtains the corresponding query mask, key mask and value mask in the auxiliary mask data, and subtracts the encrypted query vector, encrypted key vector and encrypted value vector from the corresponding mask element by element to recover the plaintext query vector, plaintext key vector and plaintext value vector, which are used as the plaintext intermediate data corresponding to the self-attention layer. When the first network layer is a multilayer perceptron layer, the second processor obtains the corresponding gating mask and upprojection mask from the auxiliary mask data, and subtracts the encrypted gating vector and encrypted upprojection vector from the corresponding mask element by element to recover the plaintext gating vector and plaintext upprojection vector, which are used as the plaintext intermediate data corresponding to the multilayer perceptron layer.
6. The method according to claim 1, characterized in that, The step of performing nonlinear operator operations on the plaintext intermediate data within the second processor to obtain the plaintext calculation result includes: When the first network layer is a self-attention layer, the second processor calculates the scaled dot product attention result based on the plaintext query vector, plaintext key vector and plaintext value vector obtained by decryption, and performs Softmax normalization operation on the scaled dot product attention result to obtain the plaintext calculation result corresponding to the self-attention layer. When the first network layer is a multilayer perceptron layer, the second processor performs SiLU activation function operation on the decrypted plaintext gate vector, and multiplies the activation result element-wise with the decrypted plaintext projection vector to obtain the plaintext calculation result corresponding to the multilayer perceptron layer.
7. The method according to claim 1, characterized in that, The step of re-encrypting the plaintext calculation result using the output mask by the second processor to obtain the encrypted layer output data includes: The second processor obtains the output mask corresponding to the plaintext calculation result of the current layer from the auxiliary mask data; The plaintext calculation result is added element by element to the output mask to obtain the encryption layer output data corresponding to the first network layer.
8. A large-scale privacy inference method apparatus for co-processor and trusted execution environment collaboration, characterized in that, include: The acquisition unit is used to acquire the initial encrypted input data and auxiliary mask data; The initial encrypted input data is the data obtained by encrypting the embedding vector of the user's query text using a first random mask on the user's end; the auxiliary mask data is used to decrypt the intermediate encrypted results calculated on the first processor; the first processor is a coprocessor; The first computing unit is used to take the initial encrypted input data as the encrypted input data of the first layer of the target inference model, and to perform linear operator operations on the encrypted input data of the first layer of the network layer through the first processor to obtain the encrypted intermediate result. The second computing unit is used to decrypt the encrypted intermediate result based on the auxiliary mask data through the second processor to obtain plaintext intermediate data, and to perform nonlinear operator operations on the plaintext intermediate data within the second processor to obtain the plaintext calculation result corresponding to the first network layer; the second processor is a processor in a trusted execution environment. The return unit is used to re-encrypt the plaintext calculation result by the second processor using an output mask to obtain the encrypted output data corresponding to the first network layer, and return the encrypted output data to the first processor. The processing unit is used to use the encrypted output data as the encrypted input data of the next network layer to obtain the encrypted output data of the next network layer, until the inference of all network layers of the target inference model is completed, and the target encrypted inference result is obtained.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the large model privacy inference method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the large model privacy inference method as described in any one of claims 1 to 7.
