A hierarchical memory sparse replay pre-training method of a long context model and related equipment
By constructing memory hierarchical objects and introducing a sparse replay strategy, the problems of high computational overhead and low memory utilization efficiency in long context scenarios are solved, achieving efficient selection and scheduling of long context information and improving the model's adaptability and computational efficiency.
Patent Information
- Application Number
- CN202611646006.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-23
- Publication Date
- 2026-11-20
AI Technical Summary
Existing technologies lack effective selection and scheduling of historical information at different levels in long-context scenarios, resulting in high computational overhead and low memory utilization efficiency, making it difficult to form stable and interpretable long-term memory capabilities.
By constructing a memory hierarchy object, including an active window, a summary chain, and a cold memory candidate set, and introducing a memory retrieval routing mechanism based on query state and a sparse replay strategy during pre-training, the model can make targeted selections and scheduling among information at different time scales.
It significantly reduces computational resource consumption, improves training efficiency and memory utilization efficiency, and enhances the model's adaptability and stability in long context processing tasks.
Smart Images

Figure CN123140261A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a hierarchical memory sparse replay pre-training method and related equipment for long context models. Background Technology
[0002] With the development of artificial intelligence technology, especially the continuous evolution of natural language processing technology represented by large language models, the application of models in scenarios such as multi-turn dialogues, complex task reasoning, and tool invocation is becoming increasingly widespread. In these application scenarios, models often need to process contextual information spanning a long time span, including historical dialogue content, task execution process, tool invocation results, and environmental feedback data, thus forming the so-called long context processing requirements. To improve the model's ability to process long sequence data, existing technologies typically extend the context window length, introduce sliding window attention mechanisms, block attention mechanisms, or combine external retrieval and summarization techniques to enable the model to obtain the required information from longer input sequences.
[0003] However, in long-context scenarios, existing technologies generally lack the ability to effectively select and schedule historical information at different levels. They often adopt the method of directly incorporating a large amount of historical content into the current context for unified processing, which leads to a significant increase in computational overhead and resource consumption. When summarizing or retrieving mechanisms are introduced, due to the lack of modeling of memory selection strategies during the training phase, the model has difficulty in autonomously determining what memory information should be read based on the current task state. Especially in long-historical scenarios, the lack of effective screening mechanisms based on factors such as importance, relevance, and time sequence position can easily lead to problems such as loading invalid information, over-replay, or missing key historical information, making it difficult to form stable and interpretable long-term memory capabilities. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this application provides a hierarchical memory sparse replay pre-training method and related equipment for long-context models, which at least solves the problem in existing technologies that models in long-context scenarios have difficulty effectively selecting and scheduling historical information according to the current task state, resulting in high computational overhead and low memory utilization efficiency.
[0005] To achieve the above objectives and other advantages, some embodiments of this application provide the following aspects: In a first aspect, some embodiments of this application provide a hierarchical memory sparse replay pre-training method for a long context model, including: A memory hierarchy object is constructed based on long-context training data. The memory hierarchy object includes an active window, a summary chain, and a cold memory candidate set. The active window is formed by segmenting the long-context training data. The summary chain is generated based on the active window. The cold memory candidate set is obtained by filtering from the long-context training data. The query state of the long context model in the current training step is obtained, and the memory retrieval route for training is determined based on the query state and the memory hierarchy object, so as to guide the model to select the route for memory retrieval among the active window, the summary chain and the cold memory candidate set. When the memory read routing method indicates that history playback is triggered, at least a portion of the historical fragments are selected from the cold memory candidate set for sparse playback. The long context model is pre-trained based on the memory hierarchical object, the memory retrieval routing method, and the sparse replay.
[0006] Secondly, some embodiments of this application also provide an electronic device, the electronic device comprising: One or more processors; and a memory storing computer program instructions that, when executed, cause the processors to perform a hierarchical memory sparse replay pre-training method for long context models as described above.
[0007] Thirdly, some embodiments of this application also provide a computer-readable storage medium having a computer program and / or instructions stored thereon, wherein the computer program and / or instructions, when executed by a processor, implement the hierarchical memory sparse replay pre-training method for long context models as described above.
[0008] Fourthly, some embodiments of this application also provide a computer program product, including a computer program and / or instructions, which, when executed by a processor, implement the hierarchical memory sparse replay pre-training method for long context models as described above.
[0009] Compared to existing technologies, the solution provided in this application constructs long-context training data into a hierarchical memory object including an active window, a summary chain, and a cold memory candidate set. During pre-training, a memory retrieval routing mechanism based on query state and a controlled sparse replay strategy are introduced, enabling the model to selectively select and schedule information across different time scales. Compared to existing methods that input all historical information into the model as a uniform long sequence, this application significantly reduces the reliance on intensive full-scale historical data retrieval through hierarchical modeling, effectively reducing computational resource consumption and GPU memory usage, and improving training efficiency. Simultaneously, by guiding the model to learn memory retrieval paths among the active window, summary chain, and cold memory candidate set during pre-training, the model possesses transferable memory routing capabilities, avoiding reliance solely on heuristic rules from the deployment phase for memory access, thus enhancing the model's adaptability and stability in long-context processing tasks. Therefore, this solution achieves efficient utilization of key information without intensively expanding all historical information, thereby improving memory utilization efficiency and long-term inference capabilities. Attached Figure Description
[0010] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other implementation methods can be obtained based on these drawings without creative effort.
[0011] Figure 1 This is a flowchart illustrating a hierarchical memory sparse replay pre-training method for a long context model provided in an embodiment of this application. Figure 2 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0012] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.
[0013] The following terms are used in this document.
[0014] An intelligent agent, typically referring to an AI intelligent agent, is an autonomous software entity implemented based on artificial intelligence technology. It can perceive its environment by receiving input information and, based on this information, perform semantic understanding, decision-making, planning, and behavioral execution to complete pre-defined task objectives. Intelligent agents are usually based on large language models or other intelligent models, possessing a certain degree of autonomy and task execution capabilities. They can invoke external tools, access remote services, or interact with other intelligent agents, thus forming a continuous, task-oriented execution process.
[0015] Large Language Model (LLM) is a natural language processing model based on deep learning. It learns the semantic relationships and expression rules in language by pre-training on large-scale text data, thereby possessing the ability to understand text, generate text, make semantic inferences, and perform multi-turn interactions.
[0016] Some embodiments of this application relate to a hierarchical memory sparse replay pre-training method for long-context models. Long-context models can be built upon large language models, which, by extending context processing capabilities beyond the language understanding and generation capabilities of large language models, enable the model to handle longer input sequences. Compared to traditional large language models, long-context models can consider a wider range of contextual information during a single input or multi-turn interaction, such as hundreds of thousands or millions of tokens, thereby achieving continuous understanding and reasoning of long texts, multi-turn dialogues, or multi-stage tasks.
[0017] This method can be applied to intelligent agent systems, dialogue systems, automated task execution systems, or model training scenarios that require processing long-term temporal contextual data, all based on large language models. In these scenarios, models typically need to process long-term contextual data, including multi-turn interaction records, task execution trajectories, tool invocation processes, and environmental feedback information, to achieve cross-stage information understanding and continuous decision-making. Long-term contextual data can be in text form or serializable, including both natural language text content and structured or semi-structured information associated with the text content, organized sequentially over time to form a long-term contextual data sequence.
[0018] In one specific embodiment, long context data can originate from the interaction and execution data generated by a long context agent during the execution of multi-step tasks. For example, in an automated task execution scenario, a long context agent can perform multiple rounds of inference and execution based on user-inputted task instructions, generating intermediate inference results during execution and calling external tools (such as search interfaces, database interfaces, or code execution environments) to obtain auxiliary information. It then continuously updates the task status based on the returned results, thus forming a long context data sequence unfolding chronologically. This type of sequence typically spans multiple processing stages, containing not only near-field information related to the current task but also intermediate state information formed in historical stages and key event information from distant history. Near-field information refers to context information located within the current activity window and directly related to the current task processing, including the input content of the current round, recent interaction records, and intermediate processing results related to the current task steps. Because long context data is characterized by its long sequence length, diverse structure, and strong cross-stage correlation, directly inputting it into the model in a uniform long sequence format can easily lead to high computational resource consumption and inefficient utilization of key information. Therefore, it is necessary to perform hierarchical modeling and selective reading processing of long context data to improve the efficiency and effectiveness of long context training and inference processes. Reference Figure 1 As shown, the method may include the following steps: Step S1: Construct a memory hierarchy object based on long context training data. The memory hierarchy object includes: an active window, a summary chain, and a cold memory candidate set. Specifically, the active window is formed by segmenting the long context training data; the summary chain is generated based on the active window; and the cold memory candidate set is obtained by filtering from the long context training data.
[0019] In one specific embodiment, during the offline data preparation phase prior to model pre-training, a server or training data processing system acquires long-context training data and processes it to construct a memory hierarchy object for subsequent training. Long-context training data can be sequential data organized chronologically to characterize multi-round interaction processes or multi-step task execution processes. It can include interaction data generated in historical stages, as well as intermediate data continuously generated during task execution, such as user input, model responses, task inference processes, tool call records, tool return results, and environmental feedback information. Long-context training data can be obtained by acquiring historical data from existing datasets or system operation logs, collecting interaction and execution trajectory data in real time during the operation of the intelligent agent system, or constructing it through simulation generation and data concatenation.
[0020] In one specific embodiment, long-context training data organized chronologically is acquired, and the data is segmented based on a preset segmentation strategy to form multiple consecutive active windows. The segmentation strategy may include one or more of the following: window length constraints based on the number of tokens, segmentation rules based on task stage boundaries, and event-triggered segmentation rules. Specifically, in the token-based segmentation method, the long-context training data can be slidably or segmented according to a preset upper limit for window length. For example, when the length of the current sequence reaches a preset token threshold, that segment of data is divided into an active window, and subsequent data is processed as a new window. In the task stage boundary-based segmentation method, data can be segmented according to stage changes during task execution. For example, when the task is detected to switch from the "information retrieval stage" to the "result analysis stage," the data from the previous stage is divided into an independent active window. In the event-triggered segmentation method, tool calls, key state changes, or environmental feedback events can also be used as segmentation boundaries to divide relevant data into independent windows.
[0021] For example, in a scenario where an agent performs a multi-step task, the system can divide a long context sequence of approximately 2M tokens into multiple activity windows, where each activity window corresponds to a stage in the task execution process or a data segment of fixed length. An activity window may contain user-initiated query requests, intermediate analysis results generated by the model, and one or more tool call records; when the window ends, the system divides subsequent data into new activity windows for further processing.
[0022] Through the above segmentation process, the original long-context training data is converted into multiple activity windows arranged in chronological order. Each activity window carries contextual information that can be directly read within the current time frame. The activity window can include user input, model response, task inference process, tool call requests and their return results, and corresponding state change information within that time frame. The state change information includes at least one of task state changes, execution state changes, or environment state changes, reflecting contextual state updates caused by model inference or tool calls during task execution.
[0023] In a preferred embodiment, step S1, generating a summary chain based on the active window, specifically includes: When the current active window is closed or a phase switching condition is triggered, obtain the summary status of the previous moment, the window content of the current active window, the execution trajectory within the active window, and the target prediction result corresponding to the active window; Semantic fusion and feature compression are performed on the summary status, window content, execution trajectory and target prediction results of the previous moment to obtain the summary entries of the current moment; The current summary entry is attached to the summary chain in a chained recursive manner.
[0024] Specifically, when the current active window is detected to have reached a preset end condition (e.g., the number of tokens within the window reaches a preset limit, task execution enters a new stage, or a key event is triggered), the current active window is considered closed or a stage switching condition is triggered. At this time, the summary state of the previous moment, the window content of the current active window, the execution trajectory within the active window, and the target prediction result corresponding to the active window are retrieved from the cache or intermediate state. Among them, the summary state of the previous moment can be the previous summary entry in the summary chain or the cumulative summary representation, used to represent the historical key information up to the previous window; the window content can include user input, model response, and contextual text within the window; the execution trajectory can include tool call records, call parameters and return results, key decision paths, etc.; the target prediction result can include the stage output result or training label information corresponding to the window.
[0025] After acquiring the aforementioned multi-source information, semantic fusion and feature compression are performed using a preset summary generation operator to generate the summary entry for the current time. In a specific implementation, the summary chain generation process can be modeled using a recursive update method. For the summary entry formed after the k-th active window closes, it can be represented as: in, This represents the k-th summary entry; Indicates the summary state at the previous moment; This indicates the content of the currently active window; This indicates the action or tool call trajectory within the currently active window; Indicates the important output results or monitoring targets corresponding to the currently active window; function This represents a summary generation operator used to achieve multi-source information fusion and feature compression.
[0026] In the specific implementation, the function By extracting key information from the window content, such as identifying task objectives, core entities, key conclusions, and anomalies, and combining this with tool call results and state change information in the execution trajectory, key decision nodes in the task execution process can be structurally encoded. Furthermore, by incorporating the previous summary state, semantic fusion is performed on cross-window continuity information, thereby generating summary entries that include key task states, core semantic information, and interim results. Through this recursive update mechanism, the current summary entry not only contains the key information of the current window but also inherits important semantic content from historical summary states.
[0027] After generating the current summary entry, the summary entry will be... The information is attached to the summary chain in a chain-like recursive manner. Multiple summary entries are associated according to time sequence and task progression relationship to form a summary chain. Unlike single summaries, the summary chain is used to carry compressed historical information across windows and stages, so that the key threads in long contexts can be continuously transmitted without retaining the entire original text, thereby providing stable mid-level semantic support for subsequent memory retrieval routing decisions.
[0028] A cold memory candidate set refers to a collection of historical data fragments selected from long-context training data. These fragments are stored outside the current active window but may be referenced again in subsequent processing. Data fragments in the cold memory candidate set can originate from closed active windows or historical portions of long-context training data preceding the current active window. They can include intermediate results generated in the early stages of a task, key tool call records, anomaly information, important decision paths, and historical context information related to the task objective. Historical data marked as cold memory refers to data accessed less frequently than data in the current active window, but still possessing significant reference value under specific circumstances. For example, in a scenario where an agent performs a multi-step task, error logs, key interface descriptions, complex query results, or failed attempt records generated in the early stages can be evaluated as candidate historical fragments. When these historical fragments are determined to have high informational value and are not fully expressed in the current active window and summary chain, they can be included in the cold memory candidate set for storage. Historical fragments meeting the criteria are organized into a set to form the cold memory candidate set. Each candidate historical fragment in the cold memory candidate set can be associated with and stored with corresponding identification information (such as time index, window number, or semantic label) so that it can be matched and selected based on the query status during subsequent memory retrieval routing. In this way, the cold memory candidate set can serve as a candidate source of distant historical information, providing support for subsequent sparse replay without increasing the burden on the current context.
[0029] In a preferred embodiment, after constructing the active window, summary chain, and cold memory candidate set, the memory information at different levels can be uniformly organized into a structured memory object. Specifically, the memory hierarchy object can be described using the field structure shown in the table below.
[0030] The field composition and meaning of a table memory hierarchical object Through the aforementioned structured field design, the active window, summary chain, and cold memory candidate set can be represented using a unified data structure. This allows the memory retrieval routing decision in subsequent step S2 to directly utilize fields such as memory layer identifier, window pointer, route label, cold memory reference, and replay budget to determine the memory retrieval path. It also enables sparse replay in step S3 to filter candidate segments based on fields such as cold memory reference set, importance score, recentity score, and replay budget. Furthermore, when transmitting memory objects across modules, sub-agents, or execution nodes, structured memory objects carrying fields such as memory layer identifier, window pointer, summary content, chained references, cold memory reference set, and replay budget can be transmitted, instead of just transmitting ordinary free text. Therefore, the same memory object structure can be reused in the training, runtime, and evaluation processes, thereby improving the consistency, traceability, and reusability of hierarchical memory data across different processing stages.
[0031] Step S2: Obtain the query status of the long context model in the current training step, and determine the memory retrieval routing method for training based on the query status and memory hierarchical objects, so as to guide the model to select the route for memory retrieval among the active window, the summary chain and the cold memory candidate set.
[0032] In a preferred embodiment, in step S2, to enable the model to perform unified modeling and selection across different memory levels, the active window, summary chain, and cold memory candidate set can first be uniformly represented. In a specific implementation, the hierarchical memory state at time t can be defined as: in, This indicates the overall memory state of the current training step; It indicates the memory state corresponding to the active window, which is used to represent the context information that can be directly accessed at present; This represents a summary chain entry, used to characterize compressed semantic information passed across windows; This represents the cold memory candidate set, used to characterize candidate historical data fragments located outside the current active window.
[0033] The unified representation method described above enables the model to perceive information at different time scales simultaneously. The active window corresponds to near-field information, the summary chain corresponds to mid-field compression information, and the cold memory candidate set corresponds to far-historical candidate information, thus providing a unified input basis for subsequent memory retrieval routing decisions.
[0034] Based on this, the query state of the current training step is obtained, and the state is remembered hierarchically. Extract the corresponding hierarchical memory features to use as input for the subsequent routing decision network.
[0035] In a preferred embodiment, step S2 specifically includes: Step S201: Obtain the query status of the current training step and the hierarchical memory features corresponding to the hierarchical objects.
[0036] In this step, the query state can be either the input context representation of the model in the current training step or the hidden state representation within the model. For example, it could be a context vector representation obtained by encoding the input data in the current active window, used to characterize the model's semantic understanding and task processing state at the current moment. Hierarchical memory features can be extracted from the active window, the summary chain, and the cold memory candidate set, respectively. Examples include the original context representation corresponding to the active window, the compressed semantic representation corresponding to the summary chain, and the feature representations of each candidate historical segment in the cold memory candidate set. In a specific implementation, memory data at different levels can be uniformly encoded to obtain hierarchical memory feature representations with consistent dimensions, thus providing a foundation for subsequent fusion processing.
[0037] Step S202: The query status and hierarchical memory features are fused and input into a preset routing decision network for linear mapping and normalization processing to output the selection probability distribution for each candidate memory reading action.
[0038] In this step, the query state and hierarchical memory features are fused, and a selection probability distribution for each candidate memory retrieval action is generated based on the fusion result to achieve learnable selection of different memory sources. Specifically, the query state and hierarchical memory features from the active window, summary chain, and cold memory candidate set are encoded to convert them into dimensionally consistent or alignable representations, enabling joint modeling of information from different sources in a unified representation space. Based on this, the query state and hierarchical memory features are fused to obtain the fused comprehensive representation. In a specific implementation, the fusion and routing decision process can be modeled as follows: in, This represents the probability distribution of the selection of each candidate memory retrieval action at the current training step; Indicates the query status; This represents a hierarchical memory feature composed of an active window, a summary chain, and a cold memory candidate set. and This is a parameter matrix used for linear mapping of query status and hierarchical memory features; This is the bias term; the Softmax function is used to normalize the scores corresponding to each candidate action so that the output results satisfy the probability distribution constraints.
[0039] Through the aforementioned linear mapping and normalization processes, the query state and hierarchical memory features are uniformly mapped into the action space, thereby obtaining the selection probability distribution for the full-text reading action of the active window, the summary reading action of the summary chain, and the sparse replay action of the cold memory candidate set. Based on this probability distribution, the model can reflect the selection tendency of different memory sources in the current state and provide a basis for determining subsequent target routing actions, thus realizing learnable modeling of memory retrieval strategies.
[0040] Step S203: Based on the selection probability distribution, determine the target routing action in the preset action space as the memory reading routing method; wherein, the action space includes at least: full text reading action for the active window, summary reading action for the summary chain, and sparse replay action for the cold memory candidate set.
[0041] In this step, the selection probability distribution corresponding to the current training step is obtained. Each component of this probability distribution corresponds to a candidate memory retrieval action in the action space. In a specific implementation, a maximum probability selection strategy can be used to select the action with the highest probability value from the selection probability distribution as the target routing action, thereby enabling the model to prioritize accessing the most relevant memory source in the current query state.
[0042] After determining the target routing action, the corresponding memory retrieval operation is performed according to the target routing action. When the target routing action is a full-text retrieval action for the active window, the complete context information is read from the current active window; when the target routing action is a summary retrieval action for the summary chain, the corresponding summary entries or summary sequences are read from the summary chain to obtain compressed semantic information across windows; when the target routing action is a sparse replay action for the cold memory candidate set, at least some historical data fragments are selected from the cold memory candidate set for replay, thereby introducing historical information located outside the current active window.
[0043] In this way, the model can dynamically select the most suitable memory retrieval method among different memory levels based on the current query state in each training step, thereby achieving adaptive scheduling of the active window, summary chain, and cold memory candidate set.
[0044] Step S204: During the pre-training process, the routing decision network updates its parameters by optimizing the routing decision loss, so as to model the memory reading and routing selection in the action space as a learnable classification task or policy task.
[0045] A routing decision loss function is constructed based on the output of the routing decision network. The routing decision loss function takes the selection probability distribution obtained in step S202 as the prediction result input and the target routing action as the supervision signal to measure the difference between the output of the routing decision network and the target routing action.
[0046] In one implementation, memory retrieval routing can be modeled as a multi-class classification task, where each candidate memory retrieval action in the action space corresponds to a class label. A cross-entropy loss is constructed based on the selection probability distribution and the target routing action to obtain the routing decision loss value. The routing decision loss function directly affects the output of the routing decision network, and its gradient with respect to the network parameters is calculated using backpropagation.
[0047] In another implementation, routing decisions can be modeled as a policy learning problem, where a probability distribution is chosen to characterize the policy function, and the target routing action corresponds to the policy execution result. Feedback signals can be constructed based on task performance, the accuracy of prediction results, or the benefits of sparse replay, and a policy optimization objective can be defined based on these feedback signals, thus forming the corresponding routing decision loss function.
[0048] During training, the parameters of the routing decision network are updated based on the routing decision loss. Specifically, the optimized result of the loss function is applied to the routing decision network through backpropagation, adjusting its parameters along the direction of loss descent. This gradually establishes a mapping relationship between the query state and the optimal memory retrieval action. Through continuous parameter updates, the routing decision network can transform the memory retrieval strategy, which originally relied on manually set or heuristic rules, into a data-driven, learnable strategy. This improves the adaptability and decision-making efficiency of the long-context model in processing long-context training data.
[0049] In the solution provided in this embodiment, through steps S201 to S204, a routing decision mechanism based on query state and hierarchical memory features is introduced during the model pre-training process. This enables the model to perform unified modeling and joint decision-making among the active window, summary chain, and cold memory candidate set. The routing decision network outputs the selection probability distribution of each candidate memory retrieval action, thereby establishing a mapping relationship between query state and memory retrieval method. Furthermore, by combining probability distribution-based target routing action determination and reverse optimization of routing decision loss, the memory retrieval strategy is learned and solidified into a generalizable model capability during the training phase. Therefore, when processing long-context training data, the model can adaptively select the most suitable memory source according to the current task semantics, achieving dynamic scheduling of information at different levels. This not only improves the targeting and effectiveness of memory utilization and reduces ineffective access to redundant historical information, but also enhances overall computational efficiency while ensuring information representation capabilities.
[0050] Step S3: When the memory read routing method indicates that history playback is triggered, select at least some historical fragments from the cold memory candidate set for sparse playback.
[0051] Step S3 is used to select a small number of historical segments with high utilization value from the cold memory candidate set for playback when the memory reading routing method indicates that access to distant historical information is required, so as to avoid reloading all historical data into the model. Specifically, when the target routing action determined in step S2 corresponds to a sparse playback action for the cold memory candidate set, the system enters the history playback processing flow; if the target routing action corresponds to full-text reading of the active window or summary chain reading, cold memory playback can be avoided, thereby reducing unnecessary historical access overhead.
[0052] In a preferred embodiment, step S3 specifically includes: Step S301: Calculate the priority score of each candidate historical fragment in the cold memory candidate set for the query status. The priority score is determined based on a weighted combination of multiple factors, including: relevance factor, importance factor, timeliness factor, and cost factor.
[0053] In this step, a priority score is calculated for each candidate historical segment in the cold memory candidate set. For each candidate historical segment, a comprehensive evaluation can be performed from multiple dimensions, including relevance, importance, timeliness, and cost, in conjunction with the query state of the current training step. Specifically, the relevance factor characterizes the semantic matching degree between the candidate historical segment and the current query state; the importance factor characterizes the strength of the candidate historical segment's support for the task objective or prediction objective, such as whether it contains key evidence, key state changes, or core tool return results; the timeliness factor characterizes the relationship between the candidate historical segment's temporal position in the long-context training data and the current training step, reflecting its temporal reference value for the current training step; and the cost factor characterizes the computational overhead, context occupancy, or read / write resource overhead required to reload the candidate historical segment.
[0054] In a specific implementation, the priority score of candidate historical segments can be determined by a multi-factor weighted method, for example, as follows: in, Indicates the first Priority scoring for each candidate historical segment; This indicates the query status of the current training step; Indicates the first One candidate historical segment; This indicates the relevance between candidate historical fragments and the current query status; Indicates the importance of candidate historical segments; Indicates the timeliness of candidate historical segments; This indicates the cost of reloading candidate history segments; , , and This represents the weight coefficient of the corresponding factor.
[0055] In a specific implementation, before weighting and combining the relevance factor, importance factor, timeliness factor, and cost factor, each factor can be dimensionless to ensure its value falls within the range of 0 to 1. Specifically, the relevance factor can be determined based on the semantic similarity between the current query state and candidate historical segments, for example, mapping cosine similarity to the range of 0 to 1; the importance factor can be obtained by normalizing the importance score corresponding to the candidate historical segment; and the timeliness factor can be determined based on the window number interval between the historical window to which the candidate historical segment belongs and the current active window, and converted into a dimensionless value through a preset decay mapping method, so that the larger the window number interval, the smaller the corresponding timeliness factor.
[0056] Specifically, for the first The timeliness factor of a candidate historical segment can be calculated as follows: in, Indicates the current active window and the first The window number interval between the history windows to which each candidate history segment belongs; This represents the preset reference window interval, and is greater than 0.
[0057] Regarding the cost factor, in one specific implementation, the number of tokens required to reload candidate history segments can be used as the evaluation criterion for resource overhead. Specifically, based on the token span corresponding to the candidate history segment in the long-context training data, the number of tokens contained in the candidate history segment is determined, and this is compared with the maximum replay token budget preset for the current training step to obtain the normalized cost factor. Its calculation method can be expressed as: in, Indicates reloading the first... The number of tokens required for each candidate historical segment; This indicates the maximum number of replay tokens allowed in the current training step, and is greater than 0. This represents the normalized cost factor. When the number of tokens for a candidate historical segment reaches or exceeds the maximum replay token budget for the current training step, the cost factor is set to 1; when the number of tokens for a candidate historical segment is less than the budget, the cost factor is determined based on the ratio between the two.
[0058] Through the above processing, relevance factors, importance factors, timeliness factors, and cost factors are all converted into dimensionless scoring values, and each weight coefficient is a dimensionless coefficient. This allows for weighted combination according to the aforementioned priority scoring formula, avoiding unreasonable influences on priority scoring results due to differences in the original dimensions and numerical ranges of different evaluation factors. This scoring method prioritizes the identification of historical segments that are highly relevant to the current query, have high information value, still have temporal reference value, and have low loading costs.
[0059] Step S302: Sort all candidate historical segments in descending order according to priority scores, and select the top K candidate historical segments with total cost within the replay budget constraint as target replay segments for replay, based on the replay budget constraint preset in the current training step.
[0060] In this step, candidate historical segments in the cold memory candidate set are sorted in descending order according to their priority scores, and target replay segments are selected based on the replay budget constraint of the current training step. The replay budget constraint may include the maximum number of segments allowed to be replayed in the current training step, the maximum number of tokens, the maximum computational cost, or the maximum I / O cost, etc. Selection can begin with candidate historical segments with higher scores, and stops when the number of selected segments reaches a preset number K, and the cumulative cost of the selected segments reaches the replay budget constraint. The resulting target replay segments cover the most valuable historical information for the current training step without causing context bloat or excessive computational cost due to replaying too much historical content.
[0061] After identifying the target replay segment, it can be provided as sparse replay content to the subsequent pre-training process. For example, the target replay segment can participate in subsequent memory fusion along with the current active window and summary chain. Alternatively, the identifier, source window number, time index, or semantic tag of the target replay segment can be transmitted together so that subsequent training steps can record cold memory hits. In this way, this embodiment does not indiscriminately replay all historical segments in the cold memory candidate set, but selectively replays them based on the current query state and resource budget. This restores access to key far-historical information within a limited context budget, improves the efficiency of historical information utilization, and reduces resource consumption caused by invalid and excessive replays.
[0062] In the solution provided in this embodiment, through steps S301 to S302, historical fragments in the cold memory candidate set are quantitatively evaluated based on multiple dimensions such as relevance, importance, timeliness, and cost. This transforms the selection process of historical information from a coarse-grained or rule-driven approach into a refined multi-factor scoring mechanism. Furthermore, by ranking the candidate historical fragments according to their priority scores and combining this with replay budget constraints, only a small number of historical fragments that provide strong semantic support for the current query state and offer high cost-effectiveness are selected for the replay set. This not only avoids indiscriminate loading of all historical data, reducing contextual redundancy and computational resource consumption, but also prioritizes the retention of key historical information within a limited replay budget, improving the utilization efficiency of distant historical information.
[0063] In a preferred embodiment, in step S3, during the step of selecting at least a portion of historical fragments from the cold memory candidate set for sparse replay, a regularization constraint mechanism is applied to the sparse replay, the regularization constraint mechanism including at least one of the following constraints: Minimum trigger interval constraint is used to limit the minimum interval between two adjacent historical playbacks; Replay budget constraints are used to limit the number of times historical replays can be performed within a preset time frame or to set a maximum resource consumption limit. Replay suppression constraints are used to reduce the probability of triggering historical replay when the current query requirement has been met in the active window or summary chain.
[0064] Specifically, when the memory retrieval routing method indicates that historical playback is triggered, a regularization constraint mechanism can be applied to sparse playback before the historical segment selection is performed, so as to control the triggering frequency, resource overhead and necessity of historical playback, thereby avoiding the model's excessive reliance on cold memory.
[0065] Regularization constraints can include at least one of the following constraints: The minimum trigger interval constraint is used to limit the minimum interval between two adjacent history replays. In a specific implementation, the training step or time position of the most recent trigger of history replay can be recorded. When the interval between the current training step and the most recent replay is less than a preset threshold, the triggering of this history replay is suppressed, thereby avoiding increased resource consumption caused by continuous or high-frequency replays.
[0066] Replay budget constraints are used to limit the number of times historical replays can be performed or to set a resource overhead limit within a preset time frame. In a specific implementation, a maximum number of replays, a maximum number of tokens loaded, or a maximum computational overhead can be allocated to each training phase or each sample. When the cumulative replay overhead reaches the budget limit, the trigger probability of subsequent historical replays is paused or reduced.
[0067] Replay suppression constraints are used to reduce the probability of triggering historical replay when the active window or summary chain can already satisfy the current query requirements. In a specific implementation, when the semantic matching degree between the current query state and the active window or summary chain reaches a preset threshold, it can be considered that there is no need to access cold memory, thereby suppressing the triggering of sparse replay.
[0068] Only when the regularization constraint mechanism is satisfied will the process proceed to step S301, where priority scoring is performed on the candidate historical segments in the cold memory candidate set, and the target playback segment is selected based on the scoring results.
[0069] Step S4: Pre-train the long context model based on memory hierarchical objects, memory retrieval routing methods, and sparse replay.
[0070] Step S4 is used to integrate the memory hierarchical objects, memory retrieval routing methods, and sparse replay results into the model pre-training process, so that the model can not only complete the prediction task in each training step, but also continuously update and pass on its internal memory state.
[0071] In a preferred embodiment, step S4 specifically includes: Step S401: Construct corresponding memory representations based on the active window, summary chain, and sparse replay respectively, and perform fusion processing on the memory representations to obtain the state representation of the current training step.
[0072] In this step, memory representations are constructed based on the active window, the summary chain, and sparse replay, respectively, and these memory representations are fused to obtain the state representation of the current training step. Specifically, the memory representation corresponding to the active window is used to represent the original context information of the current training step, the memory representation corresponding to the summary chain is used to represent the compressed semantic information transmitted across windows, and the memory representation corresponding to sparse replay is used to represent the long-term key information carried by the historical fragments selected from the cold memory candidate set. In a specific implementation, the fusion process of the above multi-source memory information can be modeled as follows: in, This represents the state of the current training step; This represents the memory representation corresponding to the active window; This represents the memory representation corresponding to the digest chain; This represents the memory representation corresponding to the sparse replay history fragments after filtering; Fuse(·) represents the function used to fuse multi-source memory information. In specific implementations, the fusion function can be implemented through vector concatenation, weighted fusion, or attention-based mechanisms, thereby integrating current window information, compressed summary information, and far-historical information in a unified representation space to form a unified state representation for the current training step.
[0073] Step S402: Update the memory hierarchical object based on the state representation, and synchronously update the stage state of the current training step.
[0074] In this step, for the active window, a sliding update or truncation update can be performed based on the window length constraint and the current state representation to retain the tail information of the active window related to subsequent training steps. For the summary chain, new summary entries can be generated or existing summary entries can be modified based on the current state representation, enabling the summary chain to integrate replay information and semantic updates introduced in the current training step. For the cold memory candidate set, the historical segments that were replayed and their hit status can be recorded to update the usage status of cold memories. The stage state is used to characterize the processing stage or memory scheduling state of the current training step, such as whether a replay has occurred, the replay scale, or the memory fusion state.
[0075] Step S403: Extract incremental propagation information based on the updated memory hierarchy object. The incremental propagation information includes: the tail information of the active window, the updated summary chain status, and the identification information of the corresponding sparse replay.
[0076] In this step, incremental propagation information is extracted based on the updated memory hierarchy object to avoid repeatedly loading the complete historical context in subsequent training steps. Specifically, the incremental propagation information may include: the tail information of the active window, the updated summary chain state, and the identification information of the corresponding sparse replay. The tail information of the active window is used to retain the most recently occurring context content; the summary chain state is used to carry cross-window compressed semantic information; and the sparse replay identification information may include the identifier of the replayed historical segment, the source window number, or the time index, used to track the usage of historical segments in subsequent training steps.
[0077] Step S404: Use the incremental transfer information as the input state for subsequent training steps to achieve memory state transfer across training steps.
[0078] Specifically, when moving to the next training step, the system does not need to reload the complete historical context. Instead, it constructs a new input state based on incremental information transfer, so that the memory fusion results formed in the previous training step can be directly inherited and utilized, thereby forming a continuously evolving memory state link.
[0079] In the solution provided in this embodiment, through steps S401 to S404, the model can uniformly fuse and model the different levels of information corresponding to the active window, summary chain, and sparse replay in each training step, and synchronously update the memory hierarchical objects based on the fused state representation. This makes the memory information no longer a static input, but can dynamically evolve with the training process. Furthermore, by extracting incremental transmission information containing only the tail information of the active window, the state of the summary chain, and the replay identifier information, and using it as the input state for subsequent training steps, the full reconstruction of the historical context is effectively avoided. Thus, not only is the computational overhead and input redundancy significantly reduced while ensuring the continuous transmission of key information across training steps, but the model can also gradually learn to fuse, update, and utilize memory information at different levels during the training process.
[0080] In a preferred embodiment, step S4 involves pre-training the long context model, specifically including: Based on the prediction output of the long context model at the current training step, the decision result of the memory retrieval route method, the update result of the summary chain, and the execution result of sparse replay, a joint training loss function is constructed, which includes language modeling loss, memory retrieval route loss, summary loss, and sparse replay effectiveness loss. Based on preset weight coefficients, the language modeling loss, memory retrieval routing loss, summarization loss, and sparse replay effectiveness loss in the joint training loss function are weighted and summed to obtain the total pre-training loss. The long context model is trained by backpropagation using the total pre-training loss to simultaneously optimize the long context model’s generation capability and scheduling capability for memory hierarchical objects.
[0081] Specifically, after completing the forward computation of the current training step, the system obtains the prediction output of the long context model for the current training step, the decision result of the memory retrieval routing method, the update result of the summary chain, and the execution result of sparse replay. The prediction output can be a token sequence or probability distribution generated by the model based on the current input; the decision result of the memory retrieval routing method can be the target routing action selected among the active window, the summary chain, and the cold memory candidate set; the update result of the summary chain can be the summary entries generated or corrected in the current training step; and the execution result of sparse replay can be the selected target historical fragments that participate in the fusion and their corresponding usage feedback.
[0082] Based on this, a joint training loss function is constructed to uniformly constrain the learning objectives of the aforementioned multiple sub-tasks. In a specific implementation, the joint training loss function can be expressed as: in, This represents the total pre-training loss; This represents the language modeling loss, used to measure the difference between the model's predicted output and the true target. This represents the memory retrieval routing loss, used to measure the deviation between the selection probability distribution output by the routing decision network and the target routing action; This represents the summary loss, used to measure the consistency between the currently generated summary entry and the reference summary or the original semantics; This represents the sparse playback effectiveness loss, used to assess the contribution or benefit of the selected playback segment to the current prediction task. , and These are the weighting coefficients for the corresponding loss terms, used to adjust the degree of influence of different subtasks on the overall training process.
[0083] The above losses are weighted and summed based on preset weight coefficients to obtain the total pre-training loss. In a specific implementation, the weights of each loss term can be dynamically adjusted according to different training stages or task requirements, thereby strengthening language modeling capabilities in the early stages of model training and gradually enhancing memory scheduling capabilities in later stages. The total pre-training loss is used to train the long context model through backpropagation, and the model parameters are updated using the gradient descent algorithm. This allows the model to optimize its generation capabilities while gradually learning to rationally schedule between the active window, summary chain, and cold memory candidate set. Through the above joint training mechanism, the model can simultaneously learn the ability to "generate answers" and "how to obtain the memory required for answers" within a unified framework, thereby significantly improving its overall performance in long context tasks.
[0084] In a preferred embodiment, to ensure consistency in the processing of long-context training data during offline preparation, sample construction, model training, and validation export, a pre-training state machine can be defined for unified scheduling and state control. The pre-training state machine includes multiple processing states, as well as the triggering conditions, core actions, and output results corresponding to each processing state. Through the pre-training state machine, the system can uniformly schedule the long-context training data from access, segmentation, summary generation, cold memory pooling, route annotation, sample assembly, model training, performance validation, to model export, thereby ensuring that hierarchical memory construction, memory retrieval route learning, sparse replay, and joint pre-training in steps S1 to S4 are executed under consistent flow control.
[0085] Specifically, when receiving extremely long corpora, agent task trajectories, or multi-turn interaction records, the pre-trained state machine enters the data access state. In this state, it reads the raw data and registers metadata such as sample identifiers, trajectory identifiers, data sources, and time ranges to form samples to be segmented. When the sequence length exceeds the window budget, or an event boundary or stage boundary is detected, the pre-trained state machine enters the segmentation state. It segments the long context training data according to the number of tokens, event boundaries, or task stage boundaries to form a set of active windows. Subsequently, when the active windows close or the task stage switches, the pre-trained state machine enters the summary generation state. Based on the current active window and the previous summary state, it generates or updates summary entries, forming a summary chain state.
[0086] When a closed historical window meets the preset pooling conditions, the pre-trained state machine enters the cold memory pooling state. It evaluates factors such as the importance, relevance, and cost of the historical window or fragment, and writes the qualifying historical fragments into the cold memory candidate set, forming a cold memory index. When supporting evidence, teacher strategies, or attribution information are available, the pre-trained state machine enters the annotation state, constructing routing labels to indicate full-text reading, summary reading, or historical playback, thus forming a supervision signal for memory reading routes. Once the sample budget or playback budget is determined, the pre-trained state machine enters the sample assembly state, assembling the active window, summary chain, and selected playback fragments into training samples, while retaining the corresponding routing labels, playback budget, and memory object identifiers.
[0087] Once the batch data is ready, the pre-trained state machine enters the training state, performing forward computation, loss construction, and parameter updates based on the training samples to complete multi-objective pre-training of the long context model. When the preset evaluation interval is reached, the pre-trained state machine enters the validation state, evaluating memory retrieval routing accuracy, summary fidelity, replay effectiveness, and task execution performance to form validation conclusions. When the validation metrics meet the deployment conditions, the pre-trained state machine enters the export state, exporting model checkpoints and memory configurations consistent with the runtime phase, such as active window parameters, summary chain update rules, cold memory replay strategies, and replay budget configurations, thus completing the pre-training closed loop.
[0088] Through the aforementioned pre-trained state machine, this embodiment can incorporate the processes of slicing, compressing, pooling, labeling, assembling, training, and validating long-context training data into a unified process control, so that there are clear triggering conditions and state transition relationships between each processing stage, avoiding inconsistent data processing rules used by different modules.
[0089] In an optional embodiment, after completing the hierarchical memory sparse replay pre-training of the long context model based on steps S1 to S4, the memory retrieval routing method, summary chain update rules, and cold memory sparse replay strategy obtained in the pre-training stage can be deployed to the agent execution platform based on the long context model. When executing actual tasks, the agent execution platform can adopt the same memory hierarchical object structure as in the pre-training stage to manage the active window, maintain the summary chain, and manage the cold memory candidate set for the context data during operation, thereby enabling the hierarchical memory scheduling capability learned by the long context model in the pre-training stage to be directly transferred to the real task environment.
[0090] In its implementation, the intelligent agent execution platform continuously receives user input, model inference results, tool call requests and returns, and environmental feedback when performing multi-step tasks. This data is organized chronologically to form long contextual data. Simultaneously, based on a segmentation strategy consistent with the pre-training phase, the platform divides the long contextual data into active windows and performs summary chain updates when windows close or phases switch. Furthermore, when the current task state requires access to distant historical information, the platform can trigger sparse replay of cold memories using a memory retrieval routing method, selecting target historical fragments from the cold memory candidate set to participate in the current inference process.
[0091] Furthermore, during runtime, the agent execution platform can record memory scheduling behavior to form behavioral trajectory data. For example, it can record the current query status, the corresponding memory retrieval route action, the actual active window, summary entry, or cold memory fragment hit, replay budget consumption, summary chain update results, and task execution results. Simultaneously, it can also record evaluation metrics related to task completion, such as whether the task was successfully completed, whether the output meets preset requirements, whether the replay fragment effectively contributes to the result, and the corresponding computational resource overhead.
[0092] In one specific implementation, the aforementioned behavioral trajectory data can be written into a long-term trajectory ledger to store behavioral trajectory data related to memory routing, summary generation, and replay scheduling. Based on the long-term trajectory ledger, new training samples or optimization targets can be constructed to continuously optimize the memory retrieval routing strategy, summary generation strategy, and replay budget allocation strategy. For example, the accuracy of memory routing decisions can be improved based on routing selection records; the quality of summary generation can be optimized based on summary chain update records and summary distortion; and the replay budget allocation strategy can be optimized based on the relationship between replay hit rate and task rewards and resource costs.
[0093] By employing the above methods, the hierarchical memory scheduling capability developed during the pre-training phase can be directly reused during the deployment phase and continuously iterated and optimized using feedback data during operation. This reduces behavioral deviations between the training phase and actual applications, while enhancing the model's continuous learning and adaptive capabilities in complex long-context tasks, and providing a stable data foundation for subsequent reinforcement learning, policy distillation, or self-supervised optimization.
[0094] In summary, the hierarchical memory sparse replay pre-training method for long-context models provided in this application constructs long-context training data into a hierarchical memory object including an active window, a summary chain, and a cold memory candidate set. During pre-training, a memory retrieval routing mechanism based on query state and a controlled sparse replay strategy are introduced, enabling the model to selectively select and schedule information across different time scales. Compared to existing methods that input all historical information into the model as a uniform long sequence, this application significantly reduces the reliance on intensive full-scale historical data retrieval through hierarchical modeling, effectively reducing computational resource consumption and GPU memory usage, and improving training efficiency. Simultaneously, by guiding the model to learn memory retrieval path selection among the active window, summary chain, and cold memory candidate set during the pre-training phase, the model possesses transferable memory routing capabilities, avoiding reliance solely on heuristic rules from the deployment phase for memory access, and enhancing the model's adaptability and stability in long-context processing tasks. Therefore, this solution achieves efficient utilization of key information without intensively expanding all historical information, thereby improving memory utilization efficiency and long-term inference capabilities.
[0095] The steps of the various methods described above are only for clarity. In practice, they can be combined into one step or some steps can be split into multiple steps. As long as they include the same logical relationship, they are all within the scope of protection of this application. Adding insignificant modifications or introducing insignificant designs to the algorithm or process, but without changing the core design of the algorithm and process, are also within the scope of protection of this application.
[0096] Furthermore, some embodiments of this application also provide an electronic device. The electronic device can be various forms of digital computer, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, etc. The electronic device can also be various forms of mobile devices, such as cellular phones, smartphones, wearable devices, and other similar computing devices.
[0097] The electronic device includes: one or more processors; and a memory storing computer program instructions that, when executed, cause the processor to perform a hierarchical memory sparse replay pre-training method for a long context model as provided in any one or more of the above embodiments. Figure 2An exemplary structural diagram of the electronic device is disclosed. The electronic device includes one or more processors 1101, a memory 1102, and interfaces for connecting the components, including high-speed interfaces and low-speed interfaces. The components are interconnected via different buses and can be mounted on a common motherboard or otherwise installed as needed. The processors can process instructions executed within the electronic device, including instructions stored in or on memory to display graphical information of a GUI on an external input / output device (such as a display device coupled to the interface). In some other embodiments, multiple processors and / or multiple buses can be used with multiple memories and multiple memory modules, if desired. Similarly, multiple electronic devices can be connected, each providing some of the necessary operations. The components, their connections and relationships, and their functions shown herein are merely examples and are not intended to limit the implementation of the present application described and / or claimed herein.
[0098] The electronic device may further include an input device 1103 and an output device 1104. The processor 1101, memory 1102, input device 1103, and output device 1104 may be connected via a bus or other means. Figure 2 Taking the example of a connection between China and Israel via a bus.
[0099] Input device 1103 can receive input numerical or character information, and generate key signal inputs related to user settings and function control of the electronic device, such as a touch screen, keypad, mouse, trackpad, touchpad, joystick, one or more mouse buttons, trackball, joystick, etc. Output device 1104 may include a display device, auxiliary lighting device (e.g., LED), and haptic feedback device (e.g., vibration motor). The display device may include, but is not limited to, a liquid crystal display, a light-emitting diode display, and a plasma display. In some embodiments, the display device may be a touch screen.
[0100] To provide interaction with the user, the electronic device can be a computer. The computer has: a display device (e.g., a cathode ray tube or LCD monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse) 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); and input from the user can be received in any form (e.g., voice input or tactile input).
[0101] In this embodiment, a computer-readable medium stores a computer program / instruction, which, when executed by a processor, implements a hierarchical memory sparse replay pre-training method for a long context model provided in any one or more of the above embodiments. This computer-readable medium may be included in the electronic device described in the above embodiments; or it may exist independently and not assembled into that device. The aforementioned computer-readable medium carries one or more computer-readable instructions.
[0102] The memory 1102 can serve as a non-transitory computer-readable storage medium, used to store non-transitory software programs, non-transitory computer-executable programs, and modules. The processor 1101 executes various functional applications and data processing of the server by running the non-transitory software programs, instructions, and modules stored in the memory 1102, thereby implementing the program instructions / modules corresponding to the methods provided in any one or more of the embodiments described above in this application.
[0103] The memory 1102 may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created based on the use of the electronic device. Furthermore, the memory 1102 may include high-speed random access memory and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory 1102 may optionally include memory remotely located relative to the processor 1101, and these remote memories can be connected to the electronic device via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0104] It should be noted that the computer-readable medium described in this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. Computer-readable media can be, for example, but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to, electrical connections having one or more wires, portable computer disks, hard disks, random access memory, read-only memory, erasable programmable read-only memory, optical fibers, portable compact disk read-only memory, optical storage devices, magnetic storage devices, or any suitable combination thereof. In this application, a computer-readable medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0105] Computer-readable media include permanent and non-permanent, removable and non-removable media, which can store information by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory, static random access memory, dynamic random access memory, other types of random access memory, read-only memory, electrically erasable programmable read-only memory, flash memory or other memory technologies, read-only optical discs, digital versatile optical discs or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transfer medium that can be used to store information accessible by a computing device.
[0106] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including local area networks (LANs) or wide area networks (WANs), or it can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0107] In the above embodiments, all or part of the implementation can be achieved through software, hardware, firmware, or any combination thereof. For example, it can be implemented using an application-specific integrated circuit (ASIC), a general-purpose computer, or any other similar hardware device. In some embodiments, the software program of this application can be executed by a processor to implement the above steps or functions. Similarly, the software program of this application (including related data structures) can be stored in a computer-readable recording medium, such as RAM memory, magnetic or optical drives, floppy disks, and similar devices. In addition, some steps or functions of this application can be implemented in hardware, for example, as circuitry that cooperates with a processor to perform the various steps or functions.
[0108] The computer program product provided in this application includes one or more computer programs / instructions. When executed by a processor, these computer programs / instructions generate, in whole or in part, the processes or functions described in this application. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium may be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium may be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid-state drive), etc.
[0109] The flowcharts or block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of devices, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-specific system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0110] The scope of this application is defined by the appended claims rather than the foregoing description, and is therefore intended to encompass all variations falling within the meaning and scope of equivalents of the claims. No reference numerals in the claims should be construed as limiting the scope of the claims. Furthermore, it is clear that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. Terms such as "first," "second," etc., are used only to distinguish descriptions and do not indicate any particular order, nor should they be construed as indicating or implying relative importance.
[0111] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily made by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims, and the above embodiments should be regarded as exemplary and non-limiting.
Claims
1. A hierarchical memory sparse replay pre-training method for long context models, characterized in that, include: A memory hierarchy object is constructed based on long-context training data. The memory hierarchy object includes an active window, a summary chain, and a cold memory candidate set. The active window is formed by segmenting the long-context training data. The summary chain is generated based on the active window. The cold memory candidate set is obtained by filtering from the long-context training data. Obtain the query status of the long context model in the current training step, and determine the memory retrieval routing method for training based on the query status and the memory hierarchy object, so as to guide the model to select the route for memory retrieval among the active window, the summary chain and the cold memory candidate set; When the memory read routing method indicates that history playback is triggered, at least a portion of the historical fragments are selected from the cold memory candidate set for sparse playback. The long context model is pre-trained based on the memory hierarchical object, the memory retrieval routing method, and the sparse replay.
2. The hierarchical memory sparse replay pre-training method for long context models according to claim 1, characterized in that, The step of obtaining the query state of the long context model in the current training step, and determining the memory retrieval routing method for training based on the query state and the memory hierarchy object, to guide the model in selecting a route for memory retrieval among the active window, the summary chain, and the cold memory candidate set, includes: Obtain the query status of the current training step and the hierarchical memory features corresponding to the memory hierarchical object; The query status is fused with the hierarchical memory features and input into a preset routing decision network for linear mapping and normalization processing to output the selection probability distribution for each candidate memory reading action; Based on the selection probability distribution, a target routing action is determined in a preset action space to serve as the memory retrieval routing method; wherein, the action space includes: a full-text retrieval action for the active window, a summary retrieval action for the summary chain, and a sparse replay action for the cold memory candidate set; The routing decision network updates its parameters by optimizing the routing decision loss during pre-training, so as to model the memory retrieval routing selection in the action space as a learnable classification task or policy task.
3. The hierarchical memory sparse replay pre-training method for long context models according to claim 1, characterized in that, The step of selecting at least a portion of historical fragments from the cold memory candidate set for sparse replay includes: Calculate the priority score of each candidate historical fragment in the cold memory candidate set for the query state. The priority score is determined based on a weighted combination of multiple factors, including: relevance factor, importance factor, timeliness factor, and cost factor. All candidate historical segments are sorted in descending order according to the priority score, and the top K candidate historical segments with total cost within the replay budget constraint are selected as target replay segments for replay, taking into account the replay budget constraint preset for the current training step.
4. The hierarchical memory sparse replay pre-training method for long context models according to claim 1, characterized in that, The step of pre-training the long context model based on the memory hierarchy object, the memory retrieval routing method, and the sparse replay includes: Based on the activity window, the summary chain, and the sparse replay, corresponding memory representations are constructed respectively, and the memory representations are fused to obtain the state representation of the current training step. The memory hierarchy object is updated based on the state representation, and the stage state of the current training step is updated synchronously. Incremental transfer information is extracted based on the updated memory hierarchy object. The incremental transfer information includes: tail information of the active window, updated summary chain status, and corresponding sparse playback identification information. The incremental information is used as the input state for subsequent training steps to achieve the transfer of memory states across training steps.
5. The hierarchical memory sparse replay pre-training method for long context models according to claim 1, characterized in that, The step of pre-training the long context model includes: Based on the prediction output of the long context model at the current training step, the decision result of the memory retrieval routing method, the update result of the summary chain, and the execution result of the sparse replay, a joint training loss function is constructed, including language modeling loss, memory retrieval routing loss, summary loss, and sparse replay effectiveness loss. Based on preset weight coefficients, the language modeling loss, memory retrieval routing loss, summarization loss, and sparse replay effectiveness loss in the joint training loss function are weighted and summed to obtain the total pre-training loss. The long context model is trained by backpropagation using the total pre-training loss to simultaneously optimize the generation capability of the long context model and the scheduling capability for the memory hierarchical object.
6. The hierarchical memory sparse replay pre-training method for long context models according to claim 1, characterized in that, The step of generating the digest chain based on the active window includes: When the current active window is closed or a phase switching condition is triggered, obtain the summary status of the previous moment, the window content of the current active window, the execution trajectory within the active window, and the target prediction result corresponding to the active window; Semantic fusion and feature compression are performed on the previous time-state summary, the window content, the execution trajectory, and the target prediction result to obtain the current time-state summary entry. The current summary entry is attached to the summary chain in a chained recursive manner.
7. The hierarchical memory sparse replay pre-training method for long context models according to claim 1, characterized in that, In the step of selecting at least a portion of historical fragments from the cold memory candidate set for sparse replay, a regularization constraint mechanism is applied to the sparse replay, the regularization constraint mechanism including at least one of the following constraints: Minimum trigger interval constraint is used to limit the minimum interval between two adjacent historical playbacks; Replay budget constraints are used to limit the number of times historical replays can be performed within a preset time frame or to set a maximum resource consumption limit. A replay suppression constraint is used to reduce the probability of triggering historical replay when the current query requirement has been met in the active window or the summary chain.
8. An electronic device, characterized in that, The electronic device includes: One or more processors; and a memory storing computer program instructions that, when executed, cause the processors to perform the hierarchical memory sparse replay pre-training method for a long context model as described in any one of claims 1-7.
9. A computer-readable storage medium having a computer program and / or instructions stored thereon, characterized in that, When the computer program and / or instructions are executed by the processor, they implement the hierarchical memory sparse replay pre-training method for long context models as described in any one of claims 1-7.
10. A computer program product comprising a computer program and / or instructions, characterized in that, When the computer program and / or instructions are executed by the processor, they implement the hierarchical memory sparse replay pre-training method for long context models as described in any one of claims 1-7.
