Model inference method, apparatus, and electronic device

By assessing the importance of historical data in a trusted execution environment and storing it in hot and cold partitions, combined with cross-domain collaborative computing, the problems of memory constraints and high latency in large model computing are solved, achieving an efficient and secure computing process.

CN123159552APending Publication Date: 2026-11-24INSPUR (SHANDONG) COMPUTER TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611654068.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-26
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

Existing large-scale model computation methods based on trusted execution environments suffer from problems such as limited secure memory capacity, excessive key-value cache usage, frequent secure paging, and significant inference latency, making it difficult to improve computational efficiency while ensuring the security of confidential computation.

Method used

The importance of historical data is assessed based on attention-related scoring and time decay mechanisms. Highly important data is stored within a trusted execution environment, while less important data is encrypted and stored in an external environment. The data is then unified, normalized, and integrated through a cross-domain collaborative computing mechanism to ensure the security and efficiency of the computation process.

Benefits of technology

It enables efficient and secure cross-domain collaborative execution in a confidential computing environment, reduces the secure memory footprint and secure paging operation frequency in the trusted execution environment, lowers inference latency, and improves computational efficiency and security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123159552A_ABST
    Figure CN123159552A_ABST
Patent Text Reader

Abstract

This disclosure provides a model inference method, apparatus, and electronic device, applied in the field of artificial intelligence secure computing technology. The method includes determining the importance weight corresponding to each historical data; determining multiple first historical data based on the importance weight corresponding to each historical data, storing the multiple first historical data within a trusted execution environment, and storing second historical data other than the multiple first historical data outside the trusted execution environment; and performing target model inference based on the multiple first historical data stored within the trusted execution environment, the second historical data stored outside the trusted execution environment, and a query vector. This reduces the use of secure memory in the trusted execution environment, controls the scale of data entering the trusted execution environment, reduces the frequency of secure paging operations, and thus reduces inference latency caused by frequent paging.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of secure computing technology for artificial intelligence, and in particular to a model reasoning method, apparatus, and electronic device. Background Technology

[0002] With the widespread application of Large Language Models (LLMs) in sensitive business scenarios such as healthcare, finance, government affairs, energy, and the industrial internet, the model inference process often involves high-value information such as user privacy data, industry-sensitive data, model parameters, and intermediate calculation results. How to achieve efficient inference of large models while ensuring data privacy, model security, and computational reliability has become a crucial technical problem that urgently needs to be solved in the field of secure computing in artificial intelligence.

[0003] Confidential computing technology protects data in its "in use" state through a Trusted Execution Environment (TEE), ensuring that user input, model parameters, and intermediate computation data are not accessed by the operating system, cloud service administrators, or other unauthorized entities during execution. Therefore, deploying large model inference processes within a TEE can significantly improve the security of model computation tasks in sensitive scenarios.

[0004] However, existing large-model computation methods based on trusted execution environments (TEEs) still have significant shortcomings. First, the secure memory capacity of a TEE is typically limited, while large models continuously generate a large amount of key-value cache and intermediate activation data during long-context inference. As the key-value cache grows, the TEE struggles to fully accommodate all historical data. Second, when the computational data exceeds the secure memory capacity of the TEE, the system triggers frequent secure paging and memory swapping operations, leading to a significant increase in inference latency and severely impacting the inference efficiency of large models. Existing solutions typically employ two extreme approaches: one is to place all data and computation within the TEE, which, while offering high security, causes severe memory pressure and performance degradation; the other is to externalize a large amount of data for processing in an untrusted environment, which, while improving computational efficiency, struggles to meet the data security and computational trustworthiness requirements of sensitive business scenarios.

[0005] Therefore, how to reduce the dependence of large model inference processes on the secure memory of trusted execution environments, reduce secure paging overhead, and make full use of external high-performance computing resources to achieve a balance between security and computational efficiency while ensuring the security of confidential computing has become a key technical problem that urgently needs to be solved in the field of confidential computing of large models. Summary of the Invention

[0006] This disclosure provides a model reasoning method, apparatus, and electronic device to at least solve the above-mentioned technical problems existing in the prior art.

[0007] According to a first aspect of this disclosure, a model reasoning method is provided, comprising: Based on the query vector corresponding to the first moment, the key vector of each historical data corresponding to the first moment, and the historical moment corresponding to each historical data, the importance weight of each historical data is determined; the importance weight represents the degree of correlation between the historical data and the query vector. Based on the importance weight corresponding to each historical data, multiple first historical data are determined, and the multiple first historical data are stored inside the trusted execution environment. Second historical data other than the multiple first historical data are stored outside the trusted execution environment. Target model inference is achieved based on multiple first historical data stored inside the trusted execution environment, second historical data stored outside the trusted execution environment, and query vectors.

[0008] In the above scheme, determining the importance weight of each historical data point based on the query vector corresponding to the first time point, the key vector of each historical data point corresponding to the first time point, and the historical time corresponding to each historical data point includes: Based on the query vector and the key vector of each historical data point, determine the attention relevance score between each historical data point and the query vector; Based on the historical moment corresponding to each historical data point, determine the time decay factor corresponding to each historical moment. Based on the attention relevance score between each historical data point and the query vector, and the time decay factor corresponding to each historical moment, the importance weight corresponding to each historical data point is determined.

[0009] In the above scheme, determining the attention relevance score between each historical data point and the query vector based on the query vector and the key vector of each historical data point includes performing the following operations on each historical data point: The result of the inner product operation between the query vector and the key vector of historical data is determined as the attention relevance score between the historical data and the query vector.

[0010] In the above scheme, determining the importance weight of each historical data point based on the attention relevance score between each historical data point and the query vector, and the time decay factor corresponding to each historical moment, includes: Normalize all attention relevance scores to determine the attention weight for each historical data point. The attention weights of the corresponding historical data are processed based on the time decay factor corresponding to each historical data point to obtain the importance weights of each historical data point.

[0011] In the above scheme, determining multiple first historical data based on the importance weight corresponding to each historical data includes: The first historical data is determined by prioritizing a set threshold of importance weights. The preset threshold is determined based on any of the following: The available secure memory capacity of the trusted execution environment is determined; wherein, the larger the available secure memory capacity of the trusted execution environment, the higher the preset threshold, and the smaller the available secure memory capacity of the trusted execution environment, the lower the preset threshold. The importance weight and preset importance coverage threshold are determined based on the importance weight corresponding to each historical data point; The preset threshold is determined based on at least one of the following: inference latency, available safe memory utilization, and page count, according to the target model; wherein, the higher the inference latency, the lower the preset threshold; the higher the available safe memory utilization, the lower the preset threshold; and the higher the page count, the lower the preset threshold.

[0012] In the above scheme, the preset threshold is determined based on the available secure memory capacity of the trusted execution environment, including: Based on available safe memory capacity, reserved safe memory capacity, and the average storage cost of historical data, a preset threshold is determined; specifically including: The effective memory capacity for storing historical data is determined based on the difference between the available safe memory capacity and the reserved safe memory capacity. A preset threshold is determined based on the quotient of the effective memory capacity and the average storage overhead.

[0013] In the above scheme, the preset threshold is determined based on the importance weight corresponding to each historical data point and the preset importance coverage threshold, including: The importance weights of multiple historical data points are summed in descending order to obtain the summation result. When the summation result is greater than or equal to a preset importance coverage threshold, the minimum number of historical data participating in the summation operation is the preset threshold.

[0014] In the above scheme, storing the second historical data, other than the plurality of first historical data, outside the trusted execution environment includes: Based on the data encryption key, the unique random number corresponding to the second historical data, the associated authentication data, the key vector corresponding to the second historical data, and the value vector corresponding to the second historical data are encrypted to obtain the ciphertext data of the second historical data and the integrity authentication tag of the second historical data. The encrypted data of the second historical data and the integrity authentication tag of the second historical data are stored outside the trusted execution environment.

[0015] The method in the above scheme further includes: Based on the query vector corresponding to the second time step, determine the importance weight of each historical data point; If the importance weight of the first historical data stored inside the trusted execution environment is less than the first threshold, then the first historical data is stored outside the trusted execution environment. If the importance weight of the second historical data stored outside the trusted execution environment is greater than the second threshold, then the second historical data will be stored inside the trusted execution environment. Among them, the first threshold is greater than or equal to the second threshold.

[0016] In the above scheme, before storing the second historical data within the trusted execution environment, the method further includes: Integrity verification is performed based on the integrity authentication tag corresponding to the second historical data, and the verification result is determined. Decryption and verification are performed based on the ciphertext data corresponding to the second historical data, and the verification result is determined. If both the verification result and the validation result indicate that the data passed, the second historical data is stored inside the Trusted Execution Environment (TEE), and the encrypted data and integrity authentication tag of the second historical data stored outside the TEE are deleted.

[0017] In the above scheme, the step of implementing target model inference based on multiple first historical data stored within the trusted execution environment, second historical data stored outside the trusted execution environment, and query vectors includes: Determine the first correlation data between all first historical data stored within the trusted execution environment and the query vector; Determine the second correlation data between all second historical data stored outside the trusted execution environment and the query vector; Based on the first and second relevance data, determine the context data corresponding to the query vector.

[0018] In the above scheme, determining the first correlation data between multiple first historical data stored within the trusted execution environment and the query vector includes: Based on the query vector and the key vector of each first historical data point, determine the attention relevance score between each first historical data point and the query vector; Based on the attention relevance score between all first historical data and the query vector, and the value vector of all first historical data, the first relevance data between all first historical data and the query vector is determined.

[0019] In the above scheme, determining the context data corresponding to the query vector based on the first relevance data and the second relevance data includes: The normalization factor is determined based on the attention relevance score between each first historical data point and the query vector, and the attention relevance score between each second historical data point and the query vector. Based on the first relevance data, the second relevance data, and the normalization factor, the context data corresponding to the query vector is determined.

[0020] According to a second aspect of this disclosure, a model inference apparatus is provided, the apparatus comprising: The importance determination unit is used to determine the importance weight of each historical data based on the query vector corresponding to the first time point, the key vector of each historical data corresponding to the first time point, and the historical time corresponding to each historical data; the importance weight represents the degree of correlation between the historical data and the query vector; A storage unit is used to determine multiple first historical data based on the importance weight corresponding to each historical data, store the multiple first historical data inside the trusted execution environment, and store second historical data other than the multiple first historical data outside the trusted execution environment. The inference unit is used to perform target model inference based on multiple first historical data stored inside the trusted execution environment, second historical data stored outside the trusted execution environment, and query vectors.

[0021] According to a third aspect of this disclosure, an electronic device is provided, comprising: At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor to enable the at least one processor to perform the methods of this disclosure.

[0022] According to a fourth aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions for causing the computer to perform the methods described in this disclosure.

[0023] The model inference method disclosed herein determines the importance weight of each historical data point based on the query vector corresponding to a first time step, the key vector of each historical data point corresponding to the first time step, and the historical time corresponding to each historical data point. The importance weight characterizes the degree of correlation between the historical data and the query vector. Multiple first historical data points are determined based on the importance weight of each historical data point, and these multiple first historical data points are stored within a trusted execution environment (TEX). Second historical data points, excluding the multiple first historical data points, are stored outside the TEX. Target model inference is achieved based on the multiple first historical data points stored within the TEX, the second historical data points stored outside the TEX, and the query vector. In this way, storing high-importance historical data within the TEX and low-importance historical data outside the TEX reduces the use of secure memory within the TEX. It also controls the scale of data entering the TEX, reduces the frequency of secure paging operations, and thus reduces inference latency caused by frequent paging.

[0024] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0025] The above and other objects, features, and advantages of this disclosure will become readily apparent from the following detailed description of exemplary embodiments, taken in conjunction with the accompanying drawings. Several embodiments of this disclosure are illustrated in the drawings by way of example and not limitation, in which: In the accompanying drawings, the same or corresponding reference numerals indicate the same or corresponding parts.

[0026] Figure 1 A schematic diagram of a first optional process of the model inference method provided in this disclosure embodiment is shown; Figure 2 A schematic diagram of a second optional process for the model inference method provided in this disclosure embodiment is shown; Figure 3 A schematic diagram of a third optional process for the model inference method provided in this disclosure embodiment is shown; Figure 4 A schematic diagram of a fourth optional process for the model inference method provided in this disclosure embodiment is shown; Figure 5 A schematic diagram of a fifth optional process for the model inference method provided in this disclosure is shown; Figure 6 A schematic diagram of an optional structure of the model inference apparatus provided in an embodiment of this disclosure is shown; Figure 7A schematic diagram of the composition structure of an electronic device according to an embodiment of the present disclosure is shown. Detailed Implementation

[0027] To make the objectives, features, and advantages of this disclosure more apparent and understandable, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without creative effort are within the scope of protection of this disclosure.

[0028] In the following description, references are made to “some embodiments,” which describe a subset of all possible embodiments. However, it is understood that “some embodiments” may be the same subset or different subsets of all possible embodiments and may be combined with each other without conflict.

[0029] In the following description, the terms "first" and "second" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first" and "second" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this disclosure described herein can be implemented in an order other than that illustrated or described herein.

[0030] Unless otherwise defined, all technical and scientific terms used in this disclosure have the same meaning as commonly understood by one of ordinary skill in the art to which this disclosure belongs. The terminology used in this disclosure is for the purpose of describing embodiments of this disclosure only and is not intended to be limiting of this disclosure.

[0031] It should be understood that in the various embodiments of this disclosure, the sequence number of each implementation process does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this disclosure.

[0032] The purpose of this disclosure is to provide a model inference method to address the problems of existing large model computation methods based on trusted execution environments, such as limited secure memory, excessive key-value cache usage, frequent secure paging, large inference latency, and insufficient external computation security.

[0033] Specifically, this disclosure first assesses the importance of historical key-value caches and related intermediate data generated during the target model computation process based on attention relevance scoring and time decay mechanisms. High-importance historical data is then retained within the TEE (Time-Based Environment), while low-importance historical data is encrypted and stored externally to the TEE. Furthermore, this disclosure constructs a cross-domain collaborative computation mechanism to uniformly normalize and merge results from both internal and external computation units within the TEE, ensuring consistency throughout the overall computation process. Simultaneously, encryption protection and integrity verification mechanisms safeguard the security of external data during storage and computation. In addition, this disclosure designs a dynamic update strategy to adjust the division between internal and external data within the TEE in real time based on changes in data importance during computation, thereby adapting to the computational needs of target models of different scales and contexts.

[0034] Through the above method, this disclosure achieves efficient and secure collaborative execution of target model computation tasks in a confidential computing environment.

[0035] Figure 1 A schematic diagram of a first optional process for the model inference method provided in this disclosure is shown, and the steps will be described accordingly.

[0036] Step S101: Based on the query vector corresponding to the first time point, the key vector of each historical data corresponding to the first time point, and the historical time corresponding to each historical data, determine the importance weight corresponding to each historical data.

[0037] In some embodiments, the carrier implementing the model inference method (hereinafter referred to as the carrier) determines the historical time window corresponding to the first moment, and then determines the historical data of different historical moments within the historical time window. The historical time window is a time window prior to the first moment. Sampling is performed within the historical time window at a preset frequency to obtain multiple historical moments within the historical time window, and the historical data corresponding to each historical moment is determined. The historical data includes the key-value cache generated by the target model in step a of inference at the corresponding historical moment, including key vectors and value vectors, and at least one of the intermediate activation data, historical state data, and context data corresponding to step a. 'a' is a positive integer representing the inference step of the target model corresponding to the historical moment. The target model can be a large language model (large model).

[0038] In some embodiments, the importance weight corresponding to historical data represents the degree of attention relevance (or content matching degree, semantic relevance degree) between historical data and the query vector at the first moment, as well as the comprehensive evaluation result of the temporal proximity between historical moments and the first moment.

[0039] Specifically, the higher the semantic relevance (i.e., the more similar the semantics), the higher the content matching degree, and the higher the attention relevance between historical data and query vector, the higher the importance weight of historical data under the same time proximity. Conversely, the lower the semantic relevance, the lower the content matching degree, and the lower the attention relevance between historical data and query vector, the lower the importance weight of historical data under the same time proximity. The greater the time proximity between historical moments and the first moment, the lower the importance weight of historical data under the same attention relevance. Conversely, the closer the time proximity between historical moments and the first moment, the higher the importance weight of historical data under the same attention relevance.

[0040] In some embodiments, the query vector corresponding to the first time point and the key vector of each historical data point corresponding to the first time point are used to determine the attention relevance score between each historical data point and the query vector; the historical time point corresponding to each historical data point is used to determine the time decay factor; the attention relevance of the corresponding historical data is processed by the time decay factor to obtain the importance weight of the query vector corresponding to each historical data point. The attention relevance score represents the degree of attention relevance; that is, the higher the degree of attention relevance, the higher the attention relevance score, indicating that the key vector of the historical data is more similar to the query vector.

[0041] The carrier can be computer programs, electronic circuits, databases, mobile applications, electronic devices, cloud computing platforms, distributed systems, artificial intelligence frameworks, mathematical models, automation tools, and microcontrollers, etc., which are software or hardware capable of implementing algorithms and methods.

[0042] Step S102: Based on the importance weight corresponding to each historical data, determine multiple first historical data, store the multiple first historical data inside the trusted execution environment, and store the second historical data other than the multiple first historical data outside the trusted execution environment.

[0043] In some embodiments, the carrier sorts multiple historical data in descending order of importance weight, determines the historical data with a preset threshold as the first historical data, stores the first historical data inside the trusted execution environment, and stores the second historical data other than the first historical data outside the trusted execution environment.

[0044] The Trusted Execution Environment (TEE) refers to a hardware-isolated secure area defined by the central processing unit (CPU). Within the TEE, the operating system, hypervisor, cloud administrator, and external programs cannot directly read or tamper with the memory data. This area typically handles hot data storage, generates and stores encryption keys, performs core secure computations, performs encryption and decryption, and implements integrity verification. The area outside the TEE includes the server's operating system memory, disk, and general-purpose graphics processing unit (GPU) storage space. This environment is untrusted; if the external operating system, virtual machine, or administrator is compromised, the external TEE could be compromised through memory access and data tampering.

[0045] In some embodiments, the preset threshold can be determined based on the available safe memory capacity of the trusted execution environment; or, based on the importance weight corresponding to each historical data and a preset importance coverage threshold; or, based on at least one of the inference latency, available safe memory occupancy rate, and page count of the target model; the specific determination method will be described later. Wherein, the larger the available safe memory capacity of the trusted execution environment, the higher the preset threshold; the smaller the available safe memory capacity of the trusted execution environment, the lower the preset threshold; wherein, the higher the inference latency, the lower the preset threshold; the higher the available safe memory occupancy rate, the lower the preset threshold; the higher the page count, the lower the preset threshold.

[0046] Step S103: Target model inference is performed based on multiple first historical data stored inside the trusted execution environment, second historical data stored outside the trusted execution environment, and query vectors.

[0047] In some embodiments, the carrier may perform target model inference based solely on multiple first historical data and query vectors stored within a trusted execution environment. Specifically, multiple first historical data stored within a trusted execution environment serve as the inference context for the target model.

[0048] In practice, the output vector of the attention module in the target model is determined based on multiple first historical data stored inside the trusted execution environment, multiple second historical data stored outside the trusted execution environment, and the query vector. Subsequently, it enters the neural network layer (feedforward network, the next transformer layer) of the target model for further computation. After multiple layers of computation, the word is output, completing one step of inference. At the same time, the key vector and value vector corresponding to the output word are added to the key-value (KV) cache as new historical data and enter the next round of hot and cold partitioning process.

[0049] Thus, the model inference method provided in this embodiment stores high-importance historical data inside the trusted execution environment and low-importance historical data outside the trusted execution environment, reducing the occupation of secure memory in the trusted execution environment. It can also control the scale of data entering the trusted execution environment, reduce the frequency of secure paging operations, and thereby reduce inference latency caused by frequent paging.

[0050] Figure 2 A second alternative flowchart of the model reasoning method provided in this disclosure embodiment is shown, and will be described according to each step.

[0051] Figure 2 The diagram shows the specific steps in step S101 to determine the importance weight of each historical data point based on the query vector corresponding to the first time point, the key vector of each historical data point corresponding to the first time point, and the historical time corresponding to each historical data point.

[0052] Steps S201 to S203 are used to evaluate the importance of historical key-value cache and related intermediate data generated during the inference process of the target model, and to adaptively partition the data according to the evaluation results to determine the range of data to be retained within the trusted execution environment and the range of data to be migrated to the external computing environment.

[0053] Step S201: Based on the query vector and the key vector of each historical data, determine the attention relevance score between each historical data and the query vector.

[0054] In some embodiments, during the target model inference process, the carrier first acquires the query vector at a first time point and the historical data generated at each historical time point within the corresponding historical time window. The historical data includes key-value data (i.e., key vectors and value vectors), and the key-value data includes key-value cache data in the attention mechanism, intermediate activation information, and historical state data related to the context inference process. Let the first time point be... The current query vector is Historical data The corresponding key vector is The value vector is The length of the historical time window is That is, the historical time window includes Each historical moment corresponds to a historical data point, and the corresponding historical data... The value is That is, historical data 1, historical data 2, ..., historical data The carrier evaluates the contribution (i.e. importance) of each historical data point in the current inference computation based on the correlation between the query vector and the key vectors of historical data.

[0055] During the importance assessment process, the carrier first utilizes the query vector from the first time step. key vectors of each historical data The inner product between them is used to calculate the attention relevance score. To reflect the degree of attention the current calculation process pays to historical data at different historical moments, the attention relevance score is calculated using the following formula: (1) in, Representing historical data Attention relevance score of the key vector relative to the query vector at the first time step; symbol " " indicates the vector dot product operation. The larger the value, the more historical data the current reasoning process has been used for. The higher the level of attention, the better.

[0056] In some embodiments, the carrier may further perform exponential normalization on the attention relevance score to obtain the contribution weight of each historical data point to the current calculation result. The formula for calculating the attention weight is as follows: (2) in, Representing historical data The degree of attention contributed to the current reasoning result is also based on historical data. Attention weights; Represents an exponential function; Representing historical data The corresponding attention relevance score, The value is ; This represents the total amount of historical data that can currently be used in the calculation. Through exponential normalization, the attention relevance scores of different historical data can be converted into comparable weights, and the sum of the attention weights of all historical data is made to 1.

[0057] Step S202: Based on the historical time corresponding to each historical data point, determine the time decay factor corresponding to each historical time point.

[0058] In some embodiments, to avoid older historical data occupying resources within the trusted execution environment for extended periods, and to further reflect the changing impact of historical data on the current inference task over time, a time decay factor is introduced to attenuate the weight of historical data that is far removed from the current moment. The corresponding time decay factor is calculated as follows: (3) in, Representing historical data Attention weights; This represents the time decay coefficient, used to adjust the rate at which the importance weight of historical data decays with increasing time distance; Representing historical data The corresponding historical moment, Representing historical data The time distance between the corresponding historical moment and the first moment. When the value is large, the importance weight of historical data decays faster, and the importance weight of historical data farther from the first time point decreases faster than that of historical data closer to the first time point; when When the value is small, the importance of historical data decays more slowly. This metric avoids allowing some historical data to remain in the trusted execution environment for extended periods due to relying solely on attention weights, while also improving the adaptability of hot and cold data partitioning to long-context reasoning scenarios. It is usually a positive integer, and can be set according to actual needs or experimental results.

[0059] Step S203: Based on the attention relevance score between each historical data point and the query vector, and the time decay factor corresponding to each historical moment, determine the importance weight corresponding to each historical data point.

[0060] In some embodiments, the carrier multiplies the attention weights of corresponding historical data based on the time decay factor corresponding to each historical data to obtain the importance weight corresponding to each historical data, specifically including: (4) in, Representing historical data Importance weights.

[0061] Thus, by combining the attention relevance of historical data with a time decay factor to calculate the importance weight of historical data, on the one hand, attention weights are obtained through the inner product of the query vector and the key vector and normalization, accurately reflecting the semantic dependence of the current inference on each historical data; on the other hand, a time decay factor is introduced to impose a weight penalty on historical data that is far removed from the current time. Multiplying the two results in the importance weight, which allows the evaluation to take into account both semantic relevance and temporal proximity, avoiding the problem of old historical data occupying the limited safe memory within the trusted execution environment for a long time due to relying solely on attention weights. This adapts to long-context inference scenarios and provides a reliable quantitative evaluation basis for subsequent adaptive partitioning of hot and cold data.

[0062] Figure 3A third optional flowchart of the model inference method provided in this disclosure embodiment is shown, and will be described according to each step.

[0063] Figure 3 The specific steps in step S102 for determining multiple first historical data based on the importance weight corresponding to each historical data include: Step S301: Determine the preset threshold.

[0064] In some embodiments, the preset threshold is not a fixed constant, but is determined based on at least one of the importance weights of historical data, the available safe memory of the trusted execution environment, and a preset importance coverage threshold. Furthermore, the preset threshold can be periodically updated during the target model inference process to meet the inference needs of the target model in real time. In this embodiment of the disclosure, the preset threshold... In different determination methods, it can be represented as or .

[0065] In some embodiments, the carrier can determine a preset threshold based on the available safe memory capacity, the reserved safe memory capacity, and the average storage overhead of historical data; specifically, the carrier determines the effective memory capacity for storing historical data based on the difference between the available safe memory capacity and the reserved safe memory capacity; the preset threshold is determined based on the quotient of the effective memory capacity and the average storage overhead, calculated as follows: (5) in, Available safe memory capacity represents the safe memory capacity that can be used to store key-value cache. To reserve safe memory capacity, The average storage cost for historical data. The preset threshold; This is for rounding down. The available safe memory capacity is not the total physical safe memory of all TEEs, but rather a memory pool allocated to the key-value cache business domain to store the key and value vectors of data. However, within this business memory pool, it is still necessary to allocate... This space is reserved within the business domain for caching metadata, managing structures, and temporary working caches; it cannot be used entirely to store historical data. The effective memory capacity obtained is the memory capacity used to store historical data.

[0066] In other embodiments, the carrier can be determined based on the importance weight corresponding to each historical data and a preset importance coverage threshold. Specifically, the importance weights corresponding to multiple historical data are summed in descending order to obtain a summation result. When the summation result is greater than or equal to the preset importance coverage threshold, the minimum number of historical data participating in the summation operation is the preset threshold.

[0067] In practice, the importance coverage threshold is: , of which 0 The importance weights of historical data are sorted from highest to lowest and denoted as follows: The minimum number of data points required to satisfy the importance coverage requirement can be expressed as: (6) In this case, determine the preset threshold. for .

[0068] If fixed settings Setting a fixed value, for example, always retaining the 100 historical data points with the highest importance weight, presents two problems: First, the importance of historical data varies across different input scenarios, so a fixed value would be problematic. This could lead to the loss of important information; on the other hand, when TEE resources are sufficient, a smaller fixed amount... Alternatively, it may not be possible to fully utilize storage space. Therefore, an importance coverage threshold was introduced. The importance coverage threshold represents the proportion of importance contribution that the historical data to be retained (i.e., the first historical data) should cover for all historical data.

[0069] For example, setting the importance coverage threshold to 90% means that although the retained historical data only constitutes a portion of all historical data, the sum of the importance contributions of these data should reach 90% or more of the importance weight of all historical data. It should be noted that "90%" here does not mean retaining 90% of the data, but rather that the retained data contains 90% of the valid information. This setting takes into account that directly fixing the K value is impractical, but can fix the proportion of valid information that should be retained in the hot data to ensure that the hot data can cover a certain amount of key information.

[0070] Specifically, let's assume the sum of the importance weights of all historical data corresponding to the first moment is: (7) Furthermore, when selecting a preset threshold... When considering historical data, the importance weight is as follows: The cumulative importance contribution ratio of each historical data point is: (8) The carrier gradually increases The value, until The minimum obtained at this time The value is the preset threshold.

[0071] For example, given 1000 historical data entries, sorted by importance weight from highest to lowest, the top 50 entries contribute 70% of the importance weight; the top 100 contribute 85%; and the top 150 contribute 92%. If the carrier has a preset importance coverage threshold... If the importance weights of the first 100 historical data points are 90%, then the sum of their importance weights does not meet the preset importance coverage threshold. However, the sum of their importance weights of the first 150 historical data points does meet the preset importance coverage threshold. =150, meaning that the carrier only needs to store 150 historical data entries with the top 150 importance weights in the TEE to cover more than 90% of the important information.

[0072] In some embodiments, the carrier can also dynamically adjust the preset threshold based on the running state of the target model during inference. When it detects an increase in the secure memory usage of the trusted execution environment, an increase in the number of page breaks, or an inference latency exceeding at least one of the preset thresholds, the carrier can appropriately lower the preset threshold, adjusting some less important first historical data from hot data to cold data. When it detects increased current context dependencies, a more dispersed attention distribution, or a decrease in model output stability, the carrier system can raise the preset threshold to retain more critical historical data within the trusted execution environment. This achieves adaptive data partitioning for different context lengths, different input distributions, and different trusted execution environment resource states.

[0073] Step S302: Determine the first historical data as the multiple historical data with the highest importance weight and a preset threshold.

[0074] In some embodiments, the carrier determines a plurality of historical data with a priority weight of a preset threshold as first historical data, stores the plurality of first historical data inside a trusted execution environment, and stores second historical data other than the plurality of first historical data outside the trusted execution environment.

[0075] The model inference method provided in this disclosure can perform hot and cold partitioning management of historical data during the target model inference process based on attention relevance scores, importance weights, time decay factors, preset importance coverage thresholds, and trusted execution environment memory constraints. While ensuring that critical context information remains within the protected scope of the trusted execution environment, it reduces the secure memory footprint of the trusted execution environment, lowers secure paging overhead, and lays the foundation for subsequent secure data storage, dynamic cross-domain management, and cross-trusted domain collaborative computing.

[0076] Figure 4 A fourth optional flowchart of the model inference method provided in this disclosure embodiment is shown, and will be described according to each step.

[0077] Figure 4 The diagram shows the specific steps in step S102 of storing the second historical data, other than the plurality of first historical data, outside the trusted execution environment.

[0078] Step S401: Based on the data encryption key, the unique random number corresponding to the second historical data, the associated authentication data, the key vector corresponding to the second historical data, and the value vector corresponding to the second historical data are encrypted to obtain the ciphertext data of the second historical data and the integrity authentication tag of the second historical data.

[0079] In some embodiments, a plurality of historical data with an importance weight ranking first by a preset threshold are designated as first historical data, or hot data, and a second historical data with an importance weight ranking after the preset threshold is designated as cold data.

[0080] In some embodiments, to achieve secure storage and integrity protection, the second historical data is not stored directly outside the trusted execution environment in plaintext. Instead, the key vector and value vector pairs corresponding to the second historical data are first authenticated and encrypted, and then the encrypted second historical data is migrated to external storage of the trusted execution environment or external computing environment for storage. This prevents unauthorized entities from obtaining sensitive intermediate data and reduces the risk of data leakage and tampering in the external storage environment.

[0081] In some embodiments, the second historical data is encrypted using the AES-GCM authentication encryption algorithm. The AES-GCM algorithm generates an integrity authentication tag while generating ciphertext data, thus providing both confidentiality and integrity protection for the second historical data. For the second historical data... The authentication process can be represented as follows: (9) in, Indicates the second historical data The corresponding encrypted data; This indicates the integrity authentication tag corresponding to the encrypted data; This represents the AES-GCM authentication encryption function; This refers to the data encryption key generated, stored, or derived by a trusted execution environment; Indicates the second historical data A unique random number (which can also be a counting initialization vector) is used to avoid security risks caused by repeated encryption under the same key; Indicates the second historical data The associated authentication data is used to bind the second historical data. Context identity, access constraints, and version status.

[0082] In some embodiments, through the above-described authentication encryption process, even if the second historical data is stored in an untrusted external environment (i.e., outside the trusted execution environment), external systems, administrators, or attackers cannot directly obtain the key vectors, value vectors, and related intermediate state information contained therein. Simultaneously, integrity authentication tags... It can be used to verify whether the second historical data has been tampered with during transmission, storage and retrieval, thereby ensuring the security and trustworthiness of the second historical data outside the trusted execution environment.

[0083] Step S402: Store the encrypted data of the second historical data and the integrity authentication tag of the second historical data outside the trusted execution environment.

[0084] In some embodiments, the carrier determines the encrypted data of historical data. After integrity certification label ciphertext data After integrity certification label Store outside the trusted execution environment.

[0085] In some alternative embodiments, the method may further include: Step S403: Update the storage location of historical data based on the importance weight of all historical data.

[0086] In some embodiments, the historical time window corresponding to the first moment may include a time window from the moment the current problem is received to the first moment; it may also include a time window from the moment the target model is started to the first moment. The historical time window may also include a time window of fixed length, the duration of which is less than the runtime of the target model or the processing time for the current problem.

[0087] In some embodiments, the carrier determines the importance weights of historical data corresponding to all historical moments within a historical time window. If the length of the historical time window is the same as the runtime of the target model, the target model may process multiple problems. If the correlation between multiple problems is small, the historical data of some problems will have a lower importance weight to other problems. Therefore, the carrier determines the importance weights of all historical data within the historical time window relative to the query vector at the first moment, and migrates the first historical data that was once judged as hot data but has a low importance weight to the query vector from inside the trusted execution environment to outside the trusted execution environment; and migrates the second historical data that was once judged as cold data but has a high importance weight to the query vector from outside the trusted execution environment to inside the trusted execution environment.

[0088] Specifically, the carrier can set a first threshold for historical data inside the trusted execution environment and a second threshold for historical data outside the trusted execution environment. It can determine whether the importance weight of each first historical data inside the trusted execution environment is less than the first threshold. If the importance weight of any first historical data is less than the first threshold, the first historical data is stored outside the trusted execution environment. It can also determine whether the importance weight of each second historical data outside the trusted execution environment is greater than the second threshold. If the importance weight of any second historical data is greater than the second threshold, the second historical data is stored inside the trusted execution environment.

[0089] Specifically, set historical data The importance weight at the current moment is The first threshold for hot data migration is The second threshold for cold data migration is To avoid frequent back-and-forth migration of hot and cold data around the threshold, this disclosure embodiment sets up a dual threshold mechanism, wherein... Used to migrate second historical data from outside the trusted execution environment into the trusted execution environment. Used to migrate the first historical data from inside the trusted execution environment to outside the trusted execution environment, and satisfying the following conditions: ≥ Hot data refers to historical data stored within the trusted execution environment, i.e., the first historical data; cold data refers to historical data stored outside the trusted execution environment, i.e., the second historical data.

[0090] In some embodiments, the carrier determines that first historical data with an importance weight less than a first threshold is converted from hot data to cold data, and migrates the first historical data outside the trusted execution environment. Before migration, the key vector and value vector corresponding to the first historical data are encrypted based on the method described in step S401 to obtain ciphertext data of the first historical data and integrity authentication tags of the historical data, and the ciphertext data and integrity authentication tags of the first historical data are stored outside the trusted execution environment.

[0091] In practice, when the importance weight of any first historical data decreases and the following conditions are met, it is migrated from inside the trusted execution environment to outside the trusted execution environment: (10) in, Characterizes the first historical dataset (hot dataset). China's first historical data The importance weight is determined; at this point, the carrier re-marks the hot data as cold data and performs AES-GCM authentication encryption on it.

[0092] In some embodiments, for second historical data with an importance weight greater than a second threshold, the carrier performs integrity verification based on the integrity authentication tag corresponding to the second historical data and determines the verification result; performs decryption verification based on the ciphertext data corresponding to the second historical data and determines the verification result; in response to both the verification result and the verification result indicating that they have passed, the second historical data is stored inside the trusted execution environment, and the ciphertext data and integrity authentication tag of the second historical data stored outside the trusted execution environment are deleted.

[0093] In practice, when the importance weight of any second historical data increases and the following conditions are met, it will be migrated from outside the trusted execution environment back into the trusted execution environment: (11) in, Characterizing the second historical dataset (cold data set) Second historical data The importance weight. At this point, the trusted execution environment first considers the second historical data. Perform integrity verification and authentication decryption verification. Once the verification is successful, reload it into the trusted execution environment as hot data to participate in subsequent core calculations.

[0094] Thus, through the aforementioned data security storage and dynamic cross-domain management mechanism, it is possible to achieve controlled data flow between the trusted execution environment and the external environment while ensuring the confidentiality, integrity, and context binding of external cold data. This reduces the secure memory footprint of the trusted execution environment, decreases secure paging overhead, and improves the operational efficiency of confidential computation processes for large models.

[0095] Figure 5 A fifth optional flowchart of the model reasoning method provided in this disclosure embodiment is shown, and the steps will be described accordingly.

[0096] Figure 5 The diagram shows the specific steps in step S103 for implementing target model inference based on multiple first historical data stored inside the trusted execution environment, second historical data stored outside the trusted execution environment, and query vectors.

[0097] Step S501: Determine the first correlation data between all first historical data stored within the trusted execution environment and the query vector.

[0098] In some embodiments, the carrier determines the attention relevance score between each first historical data and the query vector based on equation (1); based on the attention relevance scores between all first historical data and the query vector, and the value vector of all first historical data, it determines the first relevance data between all first historical data and the query vector, specifically including: (12) in, Characterizing the primary correlation data, The first historical data set includes all first historical data stored within the trusted execution environment; First historical data The value vector; First historical data Attention relevance score.

[0099] Step S502: Determine the second correlation data between all second historical data stored outside the trusted execution environment and the query vector.

[0100] In some embodiments, the carrier determines the attention relevance score between each second historical data point and the query vector based on equation (1); and determines the second relevance data between all second historical data points and the query vector based on the attention relevance scores between all second historical data points and the query vector, and the value vector of all second historical data points, specifically including: (13) in, Characterizing the second correlation data, The second historical data set includes all second historical data stored outside the trusted execution environment; Second historical data The value vector; Second historical data Attention relevance score.

[0101] Step S503: Based on the first relevance data and the second relevance data, determine the context data corresponding to the query vector.

[0102] In some embodiments, the carrier determines a normalization factor based on the attention relevance score between each first historical data point and the query vector, and the attention relevance score between each second historical data point and the query vector, specifically including: (14) In some embodiments, the carrier determines the context data corresponding to the query vector based on the first relevance data, the second relevance data, and the normalization factor, specifically including: Weighted results of the heat data Weighted results with cold data Summation and use the normalization factor Normalization is performed to obtain the context data: (15) Among them, context data Contextual input used for subsequent model inference.

[0103] In some embodiments, due to thermal data sets and cold data sets Together, they constitute a complete historical data set, and the two sets do not overlap. Therefore, the above-mentioned domain-based calculation and normalization fusion process is equivalent to the complete attention calculation process without hot and cold data partitioning. In other words, this embodiment can offload the auxiliary calculations corresponding to some low-importance data from the trusted execution environment to an external computing environment while maintaining the consistency of model calculation results. This reduces the secure memory footprint of the trusted execution environment, reduces secure paging overhead, and improves the inference efficiency of large models.

[0104] Through the above implementation methods, this disclosure achieves hierarchical management, secure storage, dynamic migration, and collaborative computation of target model inference data between a trusted execution environment and an external computing environment. On the one hand, highly important hot data and core computation processes are retained within the trusted execution environment, ensuring the security of critical context information and core intermediate results. On the other hand, less important cold data is stored in the external environment after authentication and encryption, and participates in auxiliary computation under controlled conditions, effectively reducing the resource consumption of the trusted execution environment and the overhead of secure paging. Therefore, this invention can improve the computational efficiency, scalability, and operational stability of large-model, long-context inference tasks while ensuring the security of confidential computation.

[0105] Thus, the model inference method provided in this disclosure, through a data importance evaluation mechanism based on attention contribution, context contribution, and time decay, retains only highly important hot data within the trusted execution environment, reducing secure memory consumption and lowering the resource consumption of the trusted execution environment. Secondly, since the scale of data entering the trusted execution environment is effectively controlled, the frequency of secure paging operations can be reduced, thereby reducing inference latency caused by frequent paging and lowering paging overhead. Then, this disclosure offloads some computational tasks corresponding to cold data to an external high-performance computing environment for execution, achieving collaborative allocation of computational load between the trusted and untrusted domains, improving the throughput of large model inference. Thirdly, this disclosure reduces the risk of cold data being leaked, tampered with, or illegally accessed in the external environment through encrypted storage, integrity verification, and dynamic verification mechanisms, ensuring the security of external data. Finally, this disclosure can dynamically adjust the hot and cold data partitioning strategy according to data importance, context changes, and system resource status during inference, improving the stability, accuracy, and scalability of the system under different input scenarios, achieving dynamic adaptive optimization.

[0106] Figure 6 A schematic diagram of an optional structure of the model inference apparatus provided in an embodiment of this disclosure is shown, and the steps will be described accordingly.

[0107] In some embodiments, the model reasoning apparatus includes an importance determination unit, a storage unit, and a reasoning unit.

[0108] The importance determination unit is used to determine the importance weight of each historical data based on the query vector corresponding to the first time point, the key vector of each historical data corresponding to the first time point, and the historical time corresponding to each historical data; the importance weight represents the degree of correlation between the historical data and the query vector; The storage unit is used to determine multiple first historical data based on the importance weight corresponding to each historical data, and store the multiple first historical data inside the trusted execution environment, and store the second historical data other than the multiple first historical data outside the trusted execution environment. The inference unit is used to perform target model inference based on multiple first historical data stored inside the trusted execution environment, second historical data stored outside the trusted execution environment, and query vectors.

[0109] In some embodiments, the importance determination unit is specifically used to determine the attention relevance score between each historical data and the query vector based on the query vector and the key vector of each historical data. Based on the historical moment corresponding to each historical data point, determine the time decay factor corresponding to each historical moment. Based on the attention relevance score between each historical data point and the query vector, and the time decay factor corresponding to each historical moment, the importance weight corresponding to each historical data point is determined.

[0110] In some embodiments, the importance determination unit is specifically configured to perform the following operations on each piece of historical data: The result of the inner product operation between the query vector and the key vector of historical data is determined as the attention relevance score between the historical data and the query vector.

[0111] In some embodiments, the importance determination unit is specifically used to normalize all attention relevance scores and determine the attention weight corresponding to each historical data point. The attention weights of the corresponding historical data are processed based on the time decay factor corresponding to each historical data point to obtain the importance weights of each historical data point.

[0112] The storage unit is specifically used to determine multiple historical data points with a priority weight ranking above a preset threshold as the first historical data. The preset threshold is determined based on any of the following: The available secure memory capacity of the trusted execution environment is determined; wherein, the larger the available secure memory capacity of the trusted execution environment, the higher the preset threshold, and the smaller the available secure memory capacity of the trusted execution environment, the lower the preset threshold. The importance weight and preset importance coverage threshold are determined based on the importance weight corresponding to each historical data point; The preset threshold is determined based on at least one of the following: inference latency, available safe memory utilization, and page count, according to the target model; wherein, the higher the inference latency, the lower the preset threshold; the higher the available safe memory utilization, the lower the preset threshold; and the higher the page count, the lower the preset threshold.

[0113] The storage unit is specifically used to determine a preset threshold based on the available safe memory capacity, the reserved safe memory capacity, and the average storage overhead of historical data; specifically including: The effective memory capacity for storing historical data is determined based on the difference between the available safe memory capacity and the reserved safe memory capacity. A preset threshold is determined based on the quotient of the effective memory capacity and the average storage overhead.

[0114] The storage unit is specifically used to sum the importance weights corresponding to multiple historical data in descending order to obtain the summation result; When the summation result is greater than or equal to a preset importance coverage threshold, the minimum number of historical data participating in the summation operation is the preset threshold.

[0115] The storage unit is specifically used to encrypt the unique random number, associated authentication data, key vector, and value vector corresponding to the second historical data based on the data encryption key, so as to obtain the ciphertext data of the second historical data and the integrity authentication tag of the second historical data. The encrypted data of the second historical data and the integrity authentication tag of the second historical data are stored outside the trusted execution environment.

[0116] The importance determination unit is further configured to determine the importance weight of each historical data point based on the query vector corresponding to the second time step. The second time step is after the first time step.

[0117] The storage unit is also used for If the importance weight of the first historical data stored inside the trusted execution environment is less than the first threshold, then the first historical data is stored outside the trusted execution environment. If the importance weight of the second historical data stored outside the trusted execution environment is greater than the second threshold, then the second historical data will be stored inside the trusted execution environment. Among them, the first threshold is greater than or equal to the second threshold.

[0118] Before storing the second historical data into the trusted execution environment, the storage unit is also used to perform integrity verification based on the integrity authentication tag corresponding to the second historical data and determine the verification result. Decryption and verification are performed based on the ciphertext data corresponding to the second historical data, and the verification result is determined. If both the verification result and the validation result indicate that the data passed, the second historical data is stored inside the Trusted Execution Environment (TEE), and the encrypted data and integrity authentication tag of the second historical data stored outside the TEE are deleted.

[0119] The reasoning unit is specifically used to determine the first correlation data between all the first historical data stored in the trusted execution environment and the query vector; Determine the second correlation data between all second historical data stored outside the trusted execution environment and the query vector; Based on the first and second relevance data, determine the context data corresponding to the query vector.

[0120] The inference unit is specifically used to determine the attention relevance score between each first historical data and the query vector based on the query vector and the key vector of each first historical data. Based on the attention relevance score between all first historical data and the query vector, and the value vector of all first historical data, the first relevance data between all first historical data and the query vector is determined.

[0121] The reasoning unit is specifically used to determine a normalization factor based on the attention relevance score between each first historical data and the query vector, and the attention relevance score between each second historical data and the query vector. Based on the first relevance data, the second relevance data, and the normalization factor, the context data corresponding to the query vector is determined.

[0122] According to embodiments of this disclosure, this disclosure also provides an electronic device and a readable storage medium.

[0123] Figure 7 A schematic block diagram of an example electronic device 800 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown in this disclosure, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure as described and / or claimed herein.

[0124] like Figure 7As shown, the electronic device 800 includes a computing unit 801, which can perform various appropriate actions and processes based on a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. The RAM 803 may also store various programs and data required for the operation of the electronic device 800. The computing unit 801, ROM 802, and RAM 803 are interconnected via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0125] Multiple components in electronic device 800 are connected to I / O interface 805, including: input unit 806, such as keyboard, mouse, etc.; output unit 807, such as various types of displays, speakers, etc.; storage unit 808, such as disk, optical disk, etc.; and communication unit 809, such as network card, modem, wireless transceiver, etc. Communication unit 809 allows electronic device 800 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0126] The computing unit 801 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 801 performs the various methods and processes described above, such as model inference methods. For example, in some embodiments, the model inference method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 808. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 800 via ROM 802 and / or communication unit 809. When the computer program is loaded into RAM 803 and executed by the computing unit 801, one or more steps of the model inference method described above may be performed. Alternatively, in other embodiments, the computing unit 801 may be configured to perform model inference methods by any other suitable means (e.g., by means of firmware).

[0127] Various embodiments of the systems and techniques described above in this disclosure can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0128] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0129] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0130] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0131] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0132] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.

[0133] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this disclosure can be achieved, and this disclosure does not impose any limitations herein.

[0134] The above description is merely a specific embodiment of this disclosure, but the scope of protection of this disclosure is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this disclosure should be included within the scope of protection of this disclosure. Therefore, the scope of protection of this disclosure should be determined by the scope of the claims.

Claims

1. A model reasoning method, characterized in that, The method includes: Based on the query vector corresponding to the first moment, the key vector of each historical data corresponding to the first moment, and the historical moment corresponding to each historical data, the importance weight of each historical data is determined; the importance weight represents the degree of correlation between the historical data and the query vector. Based on the importance weight corresponding to each historical data, multiple first historical data are determined, and the multiple first historical data are stored inside the trusted execution environment. Second historical data other than the multiple first historical data are stored outside the trusted execution environment. Target model inference is achieved based on multiple first historical data stored inside the trusted execution environment, second historical data stored outside the trusted execution environment, and query vectors.

2. The method according to claim 1, characterized in that, The determination of the importance weight for each historical data point based on the query vector corresponding to the first time point, the key vector of each historical data point corresponding to the first time point, and the historical time corresponding to each historical data point includes: Based on the query vector and the key vector of each historical data point, determine the attention relevance score between each historical data point and the query vector; Based on the historical moment corresponding to each historical data point, determine the time decay factor corresponding to each historical moment. Based on the attention relevance score between each historical data point and the query vector, and the time decay factor corresponding to each historical moment, the importance weight corresponding to each historical data point is determined.

3. The method according to claim 2, characterized in that, The process of determining the attention relevance score between each historical data point and the query vector, based on the query vector and the key vector of each historical data point, includes performing the following operations on each historical data point: The result of the inner product operation between the query vector and the key vector of historical data is determined as the attention relevance score between the historical data and the query vector.

4. The method according to claim 2, characterized in that, The determination of the importance weight for each historical data point, based on the attention relevance score between each historical data point and the query vector, and the time decay factor corresponding to each historical moment, includes: Normalize all attention relevance scores to determine the attention weight for each historical data point. The attention weights of the corresponding historical data are processed based on the time decay factor corresponding to each historical data point to obtain the importance weights of each historical data point.

5. The method according to claim 1, characterized in that, The determination of multiple first historical data based on the importance weight corresponding to each historical data includes: The first historical data is determined by prioritizing a set threshold of importance weights. The preset threshold is determined based on any of the following: The available secure memory capacity of the trusted execution environment is determined; wherein, the larger the available secure memory capacity of the trusted execution environment, the higher the preset threshold, and the smaller the available secure memory capacity of the trusted execution environment, the lower the preset threshold. The importance weight and preset importance coverage threshold are determined based on the importance weight corresponding to each historical data point; The preset threshold is determined based on at least one of the following: inference latency, available safe memory utilization, and page count, according to the target model; wherein, the higher the inference latency, the lower the preset threshold; the higher the available safe memory utilization, the lower the preset threshold; and the higher the page count, the lower the preset threshold.

6. The method according to claim 5, characterized in that, Determining a preset threshold based on the available secure memory capacity of a trusted execution environment includes: Based on available safe memory capacity, reserved safe memory capacity, and the average storage cost of historical data, a preset threshold is determined; specifically including: The effective memory capacity for storing historical data is determined based on the difference between the available safe memory capacity and the reserved safe memory capacity. A preset threshold is determined based on the quotient of the effective memory capacity and the average storage overhead.

7. The method according to claim 5, characterized in that, The preset threshold is determined based on the importance weight corresponding to each historical data point and the preset importance coverage threshold, including: The importance weights of multiple historical data points are summed in descending order to obtain the summation result. When the summation result is greater than or equal to a preset importance coverage threshold, the minimum number of historical data participating in the summation operation is the preset threshold.

8. The method according to claim 1, characterized in that, The step of storing the second historical data, excluding the plurality of first historical data, outside the trusted execution environment includes: Based on the data encryption key, the unique random number corresponding to the second historical data, the associated authentication data, the key vector corresponding to the second historical data, and the value vector corresponding to the second historical data are encrypted to obtain the ciphertext data of the second historical data and the integrity authentication tag of the second historical data. The encrypted data of the second historical data and the integrity authentication tag of the second historical data are stored outside the trusted execution environment.

9. The method according to claim 8, characterized in that, The method further includes: Based on the query vector corresponding to the second time step, determine the importance weight of each historical data point; If the importance weight of the first historical data stored inside the trusted execution environment is less than the first threshold, then the first historical data is stored outside the trusted execution environment. If the importance weight of the second historical data stored outside the trusted execution environment is greater than the second threshold, then the second historical data will be stored inside the trusted execution environment. Among them, the first threshold is greater than or equal to the second threshold.

10. The method according to claim 9, characterized in that, Before storing the second historical data within the trusted execution environment, the method further includes: Integrity verification is performed based on the integrity authentication tag corresponding to the second historical data, and the verification result is determined. Decryption and verification are performed based on the ciphertext data corresponding to the second historical data, and the verification result is determined. If both the verification result and the validation result indicate that the data passed, the second historical data is stored inside the Trusted Execution Environment (TEE), and the encrypted data and integrity authentication tag of the second historical data stored outside the TEE are deleted.

11. The method according to claim 1, characterized in that, The method of implementing target model inference based on multiple first historical data stored within the trusted execution environment, second historical data stored outside the trusted execution environment, and query vectors includes: Determine the first correlation data between all first historical data stored within the trusted execution environment and the query vector; Determine the second correlation data between all second historical data stored outside the trusted execution environment and the query vector; Based on the first and second relevance data, determine the context data corresponding to the query vector.

12. The method according to claim 11, characterized in that, The determination of the first correlation data between multiple first historical data stored within the trusted execution environment and the query vector includes: Based on the query vector and the key vector of each first historical data point, determine the attention relevance score between each first historical data point and the query vector; Based on the attention relevance score between all first historical data and the query vector, and the value vector of all first historical data, the first relevance data between all first historical data and the query vector is determined.

13. The method according to claim 11, characterized in that, The step of determining the context data corresponding to the query vector based on the first relevance data and the second relevance data includes: The normalization factor is determined based on the attention relevance score between each first historical data point and the query vector, and the attention relevance score between each second historical data point and the query vector. Based on the first relevance data, the second relevance data, and the normalization factor, the context data corresponding to the query vector is determined.

14. A model reasoning device, characterized in that, The device includes: The importance determination unit is used to determine the importance weight of each historical data based on the query vector corresponding to the first time point, the key vector of each historical data corresponding to the first time point, and the historical time corresponding to each historical data; the importance weight represents the degree of correlation between the historical data and the query vector; A storage unit is used to determine multiple first historical data based on the importance weight corresponding to each historical data, store the multiple first historical data inside the trusted execution environment, and store second historical data other than the multiple first historical data outside the trusted execution environment. The inference unit is used to perform target model inference based on multiple first historical data stored inside the trusted execution environment, second historical data stored outside the trusted execution environment, and query vectors.

15. An electronic device, characterized in that, include: At least one processor; And a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-13.