Language model inference method and apparatus
By using the same attention mask and block table in both the main model and the speculative model, streaming is achieved, which solves the performance bottleneck caused by CPU synchronization and improves the computational efficiency and throughput of the language model.
Patent Information
- Application Number
- CN202511144242.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Priority Date
- 2025-05-21
- Filing Date
- 2025-08-14
- Publication Date
- 2026-11-24
AI Technical Summary
In large model inference, the communication latency and inefficient pipeline utilization caused by CPU interrupted synchronization limit the concurrency and efficiency of speculative inference systems, forming a performance bottleneck.
By using the same attention mask and block table between the main model and the speculative model, control logic switching during parameter updates is avoided, enabling streaming transmission and improving the computing efficiency and throughput of the computing device cluster.
It effectively improves the computational efficiency and throughput of the language model's decoding stage, reduces the generation latency of individual lexical units, and solves the performance bottleneck problem caused by CPU synchronization.
Smart Images

Figure CN123159508A_ABST
Abstract
Description
[0001] This application claims priority to Chinese Patent Application No. 202510662048.7, filed on May 21, 2025, entitled "Language Model Reasoning Method and Apparatus", the entire contents of which are incorporated herein by reference. Technical Field
[0002] This application relates to the field of natural language processing, and more specifically, to a language model reasoning method and apparatus. Background Technology
[0003] In the field of large-scale model inference optimization, speculative inference improves computational density by introducing a smaller model (called a speculative model or draft model) to predict the output of a larger model (called the main model). This, in turn, reduces token generation latency and increases inference throughput. Specifically, the speculative model generates one or more speculative tokens as drafts for the main model. The main model then uses both the drafts from the speculative model and its own generated tokens as input for its next inference step, outputting the result and validating the drafts from the speculative model. This collaborative inference mechanism, through parallelizing the generation and verification processes, significantly improves inference efficiency while maintaining generation quality. This allows large models to be deployed in high-concurrency scenarios such as real-time interaction and long text generation, while simultaneously reducing computational resource consumption.
[0004] In speculative inference, CPU-interrupted synchronization (referred to as synchronous transfer) refers to the CPU actively intervening in the execution flow of the Neural Processing Unit (NPU) to complete data verification, synchronization, and updates between the main model and the speculative model. This method frequently interrupts the NPU flow, resulting in high communication latency and inefficient pipeline utilization. Uninterrupted streaming communication (referred to as streaming transfer), on the other hand, avoids CPU intervention as much as possible, achieving efficient and continuous data transfer between models and maintaining the high concurrency and throughput of the NPU. Synchronous transfer requires multiple interruptions of the NPU process by the CPU to complete inter-model communication, introducing additional latency in each inference round. As the number of rounds increases, this latency accumulates significantly, causing the overall inference speed improvement to be far less than expected and limiting concurrency and efficiency, thus forming a performance bottleneck. This method fails to fully utilize the hardware's potential and becomes a major obstacle to inference acceleration. Summary of the Invention
[0005] This application provides a language model inference method and apparatus. Language model inference refers to the process by which a pre-trained language model predicts the most likely subsequent content or answer based on the input text, thereby understanding and generating natural language text. The technical solution of this application can improve the computational efficiency and throughput of the decoding stage of the language model and reduce the latency of generating individual tokens.
[0006] In a first aspect, a language model inference method is provided, applied to a computing device cluster running a subject model and a speculative model. The method includes: the subject model acquiring natural language text and determining a first introductory term based on the natural language text; the subject model determining a first subject term and first contextual information based on the first introductory term; the speculative model determining a second introductory term based on the first contextual information, the first introductory term, and the first subject term; the speculative model determining a first draft term based on the first contextual information and the second introductory term; the subject model determining a second subject term and second contextual information based on a portion of information in the first contextual information corresponding to the first subject term and the first draft term; and the speculative model determining a second draft term based on a portion of information in the second contextual information corresponding to the first draft term and the second subject term, or a portion of information in the second contextual information corresponding to the first subject term and the second subject term, wherein the second subject term is used as the first subject term, the second draft term is used as the first draft term, and the second contextual information is used as the first contextual information.
[0007] In common speculative inference systems, the speculative model determines the second draft lexicon based on a portion of the second context information corresponding to the second subject lexicon. Simultaneously, the subject model determines the second subject lexicon and the second context information based on a portion of the first context information corresponding to both the first subject lexicon and the first draft lexicon. The different ways the speculative and subject models utilize context information lead to differences in their computational processes. This difference forces them to use different attention masks and key-value caching strategies (typically represented by block tables), frequently triggering parameter reconfiguration. Since the NPU cannot autonomously handle this type of control logic switching, each parameter update requires CPU intervention for synchronization, interrupting the NPU's continuous computational flow. This dynamic parameter adjustment caused by differences in model behavior can cause speculative inference systems to reach performance bottlenecks, resulting in overall inference speed improvements falling short of expectations.
[0008] In this embodiment, the subject model and the speculative model complete the corresponding calculations based on two sets of lexical units. They can use the same attention mask and block table in the context information to obtain the required information. There is no need to switch control logic when updating parameters, so there will be no calculation pauses or pipeline bubbles caused by waiting for the CPU to complete parameter configuration, thereby improving the overall computing efficiency and throughput.
[0009] In some implementations of the first aspect, the computing device cluster includes at least one computing device, which includes Q first accelerated computing units and R second accelerated computing units; the main model operates in a pre-filling and decoding separation manner, wherein A of the Q first accelerated computing units perform the pre-filling function of the main model, and B of the R second accelerated computing units perform the decoding function of the main model; QA of the Q first accelerated computing units perform the pre-filling function of the speculative model, and RB of the R second accelerated computing units perform the decoding function of the speculative model, where Q, R, A, and B are positive integers; the pre-filling function of the main model includes Based on the first control parameter and the first guiding word, determine the first main word and the first context information; the pre-filling function of the speculative model includes: based on the first control parameter and the first context information and the second guiding word, determine the first draft word; the decoding function of the main model includes: based on the second control parameter and a portion of the information in the first context information corresponding to the first main word and the first draft word, determine the second main word and the second context information; the decoding function of the speculative model includes: based on the second control parameter and a portion of the information in the second context information corresponding to the first draft word and the second main word, or a portion of the information in the second context information corresponding to the first main word and the second main word, determine the second draft word.
[0010] In some implementations of the first aspect, the first control parameter or the second control parameter includes at least one of the following: position encoding, block table, and sequence length.
[0011] In common speculative inference systems, inconsistencies in control parameters such as position encoding, block table, and sequence length between the principal and speculative models necessitate readjustment of computational parameters during transitions from the pre-filling stage of the principal model to the pre-filling stage of the speculative model, and vice versa. This leads to frequent CPU synchronization operations. These parameter adjustments interrupt the continuous computation of the acceleration unit, forcing it to wait for the CPU to complete parameter configuration and data transfer. This causes the speculative inference system to hit a performance bottleneck, resulting in a lower-than-expected overall inference speed improvement.
[0012] In this implementation, the control parameters of the main model can be directly used as the control parameters of the speculative model. The first accelerated computing unit can stream key-value cache and first context information to the second accelerated computing unit, and the second accelerated computing unit can stream key-value cache and second context information to the second accelerated computing unit. This avoids computational pauses and pipeline bubbles caused by waiting for the CPU to complete parameter configuration, thereby improving overall computing efficiency and throughput.
[0013] In some implementations of the first aspect, the speculative model is a multi-term prediction (MTP) layer, and the control parameters of the speculative model are the control parameters of the attention operator of the MTP layer.
[0014] In some implementations of the first aspect, the number of first introductory lexical units is equal to the number of second introductory lexical units.
[0015] In common speculative inference systems, the second introductory term is typically a direct concatenation of the first introductory term and the first main term, and the number of the first introductory term is not equal to the number of the second introductory term. Therefore, transitioning from the pre-filling stage of the main model to the pre-filling stage of the speculative model requires realigning positional encodings, dynamically reconstructing the key-value cache and block table, and updating the attention mask. These adjustments force the CPU to frequently intervene in parameter synchronization, interrupting the continuous computation of the first accelerated computing unit. These synchronization operations caused by cross-model parameter differences can cause speculative inference systems to reach a performance bottleneck, resulting in a lower-than-expected improvement in overall inference speed.
[0016] In this implementation, the speculative model can directly reuse parameters such as position encoding, attention mask, key-value cache, block table, and sequence length of the main model, without causing computational pauses and pipeline bubbles due to waiting for the CPU to complete parameter synchronization, thereby improving overall computational efficiency and throughput.
[0017] In some implementations of the first aspect, the number of first draft lexical units is the same as the number of second draft lexical units, and the shape of the input tensor of the static graph of the main model is the same as the shape of the input tensor of the static graph of the speculative model.
[0018] In common speculative inference systems, to handle concurrent requests, the input tensor of the static graph of the principal model typically has a shape of [dynamic_batch_size, n+1] during the determination of the second principal lexicon and the second context information. `dynamic_batch_size` is related to the number of concurrent requests, and `n` is the number of first draft lexicons. During the determination of the second draft lexicon, the input tensor of the static graph of the speculative model typically has a shape of [dynamic_batch_size, 1]. The principal model and the speculative model need to construct the graph batch parameters and static graph cache for the static graph, respectively.
[0019] In this implementation, the shape of the input tensor of the static graph of the main model is the same as the shape of the input tensor of the static graph of the speculative model. The speculative model can reuse the graph batch parameters and static graph cache of the main model, thereby improving the overall computational efficiency and throughput.
[0020] In some implementations of the first aspect, the type of the first context information is the last layer of the hidden state of the main model.
[0021] Secondly, a language model inference apparatus is provided, the apparatus being applied to a computing device cluster, the computing device cluster running a subject model and a speculative model; the apparatus includes: an acquisition module for acquiring natural language text; and a processing module for: instructing the subject model to determine a first introductory word based on the natural language text; instructing the subject model to determine a first subject word and first contextual information based on the first introductory word; instructing the speculative model to determine a second introductory word based on the first contextual information, the first introductory word, and the first subject word; instructing the speculative model to determine a first draft word based on the first contextual information and the second introductory word; instructing the subject model to determine a second subject word and second contextual information based on a portion of information in the first contextual information corresponding to the first subject word and the first draft word; and instructing the speculative model to determine a second draft word based on a portion of information in the second contextual information corresponding to the first draft word and the second subject word, or a portion of information in the second contextual information corresponding to the first subject word and the second subject word, wherein the second subject word is used as the first subject word, the second draft word is used as the first draft word, and the second contextual information is used as the first contextual information.
[0022] In some implementations of the second aspect, the computing device cluster includes at least one computing device, which includes Q first accelerated computing units and R second accelerated computing units; the main model operates in a pre-filling and decoding separation manner, wherein A of the Q first accelerated computing units perform the pre-filling function of the main model, and B of the R second accelerated computing units perform the decoding function of the main model; QA of the Q first accelerated computing units perform the pre-filling function of the speculative model, and RB of the R second accelerated computing units perform the decoding function of the speculative model, where Q, R, A, and B are positive integers; the pre-filling function of the main model includes Based on the first control parameter and the first guiding word, determine the first main word and the first context information; the pre-filling function of the speculative model includes: based on the first control parameter and the first context information and the second guiding word, determine the first draft word; the decoding function of the main model includes: based on the second control parameter and a portion of the information in the first context information corresponding to the first main word and the first draft word, determine the second main word and the second context information; the decoding function of the speculative model includes: based on the second control parameter and a portion of the information in the second context information corresponding to the first draft word and the second main word, or a portion of the information in the second context information corresponding to the first main word and the second main word, determine the second draft word.
[0023] In some implementations of the second aspect, the first control parameter or the second control parameter includes at least one of the following: position encoding, block table, and sequence length.
[0024] In some implementations of the second aspect, the speculative model is a multi-term prediction (MTP) layer, and the control parameters of the speculative model are the control parameters of the attention operator of the MTP layer.
[0025] In some implementations of the second aspect, the number of first introductory lexical units is equal to the number of second introductory lexical units.
[0026] In some implementations of the second aspect, the number of first draft lexical units is the same as the number of second draft lexical units, and the shape of the input tensor of the static graph of the main model is the same as the shape of the input tensor of the static graph of the speculative model.
[0027] In some implementations of the second aspect, the type of the first context information is the last layer of the hidden state of the main model.
[0028] Thirdly, a computing device cluster is provided, comprising at least one computing device, the at least one computing device including Q first neural processing units, R second neural processing units, and at least one central processing unit, wherein: the at least one central processing unit is configured to: acquire natural language text and determine a first introductory word based on the natural language text; the Q first neural processing units are configured to: determine a first subject word and first contextual information based on the first introductory word; determine a first subject word and first contextual information based on the first introductory word; determine a first draft word based on the first contextual information and a second introductory word; the R second neural processing units are configured to: determine a second subject word and second contextual information based on a portion of information in the first contextual information corresponding to the first subject word and the first draft word; determine a second draft word based on a portion of information in the second contextual information corresponding to the first draft word and the second subject word, or a portion of information in the second contextual information corresponding to the first subject word and the second subject word, wherein the second subject word is used as the first subject word, the second draft word is used as the first draft word, and the second contextual information is used as the first contextual information.
[0029] In some implementations of the third aspect, A of the Q first neural processing units are used to determine a first subject word and first context information based on a first control parameter and a first guiding word word; QA of the Q first accelerated computing units are used to determine a first draft word based on the first control parameter and the first context information and a second guiding word word; B of the R second accelerated computing units are used to determine a second subject word and second context information based on a portion of the first context information corresponding to the first subject word and the first draft word word; and RB of the R second accelerated computing units are used to determine a second draft word based on a portion of the second context information corresponding to the first draft word and the second subject word word, or a portion of the second context information corresponding to the first subject word and the second subject word word.
[0030] In some implementations of the third aspect, the number of first introductory lexical units is equal to the number of second introductory lexical units.
[0031] Fourthly, a computer program product containing instructions is provided, which, when run by a cluster of computing devices, cause the cluster of computing devices to perform the method described in the first aspect.
[0032] Fifthly, a computer-readable storage medium is provided, including computer program instructions that, when executed by a cluster of computing devices, perform the method as described in the first aspect. Attached Figure Description
[0033] Figure 1 This is a schematic block diagram of a speculative reasoning system provided in an embodiment of this application.
[0034] Figure 2 This is a flowchart illustrating a language model reasoning method provided in an embodiment of this application.
[0035] Figure 3 This is a flowchart illustrating a language model reasoning method provided in an embodiment of this application.
[0036] Figure 4 This is a schematic block diagram of a pipeline for a language model reasoning method provided in an embodiment of this application.
[0037] Figure 5 This is a schematic block diagram of a language model inference device provided in an embodiment of this application.
[0038] Figure 6 This is a schematic block diagram of a computing device provided in an embodiment of this application.
[0039] Figure 7 This is a schematic block diagram of a computing device cluster provided in an embodiment of this application.
[0040] Figure 8 This is a schematic block diagram of a computing device cluster provided in an embodiment of this application. Detailed Implementation
[0041] The technical solutions in this application will now be described with reference to the accompanying drawings.
[0042] Language model inference refers to the process by which a pre-trained language model predicts the most likely subsequent content or answer based on the input text, thereby understanding and generating natural language text.
[0043] A neural processing unit (NPU) is an application-specific integrated circuit (ASIC) specifically designed to accelerate machine learning and deep learning tasks. The main goal of an NPU is to efficiently perform computational tasks related to neural networks, such as convolution and activation function calculations, which may be inefficient or energy-intensive when performed on traditional graphics processing units (GPUs).
[0044] Both graphics processing units and neural processing units belong to either acceleration computing units (ACUs) or parallel computing units (PCUs). In the embodiments of this application, the NPU can also be a GPU, or collectively referred to as an ACU. This application does not limit this.
[0045] In the field of large model inference optimization, speculative inference, as a highly promising technical approach, generates inference drafts for large models by introducing lightweight models or external knowledge data. During the decoding phase, it infers multiple tokens at once, improving computational density. Taking the DeepSeek V3 / R1 model as an example, it innovatively introduces a speculative (multi-tokenprediction, MTP) layer, effectively realizing the implementation of speculative inference technology.
[0046] Speculative inference systems improve computational density by introducing a smaller model (called the speculative model or draft model) to predict the output of a larger model (called the main model), thereby reducing token generation latency and increasing inference throughput. Specifically, the speculative model generates one or more speculative tokens as drafts input to the main model; the main model uses both the drafts from the speculative model and its own generated tokens as input for its next inference step, outputting the result and validating the speculative model's draft. This collaborative inference mechanism, through parallelizing the generation and verification processes, significantly improves inference efficiency while ensuring generation quality. This allows large models to be deployed in high-concurrency scenarios such as real-time interaction and long text generation, while simultaneously reducing computational resource consumption.
[0047] In speculative inference, the consistency between the draft generated by the speculative model and the output of the main model is a key factor affecting overall performance. Simply using an unaligned small model for speculative generation often fails to achieve a satisfactory acceptance rate and may even lead to a decrease in system throughput due to frequent rejections. To address this issue, some efficient speculative architectures incorporate the hidden state of the main model as input in their design, thereby achieving more accurate alignment.
[0048] Hidden states are intermediate representations generated by a neural network when processing an input sequence; they encode the model's understanding of the current context. In speculative inference, the final layer of the main model's hidden states contains the most complete semantic information, which is then passed to the speculative model as the basis for generating a draft. By reusing the main model's hidden states, the speculative model can avoid redundant computation and make predictions directly based on high-quality contextual representations, thereby improving the accuracy and efficiency of draft generation.
[0049] The multi-token prediction (MTP) layer, or simply the speculative layer, is a core component of the principal model in speculative inference. It is specifically designed for parallel verification of draft sequences generated by the speculative model. This layer expands the model's output space, enabling the principal model to simultaneously calculate the acceptance probability of each token in the draft sequence during a single forward propagation. This transforms the serial verification of traditional autoregressive models into parallel processing. This design significantly improves computational density; when the draft quality is high, 3-5 tokens can be verified in a single inference run, with a theoretical throughput increase of nearly linear growth. It is a key technological support for accelerating speculative inference.
[0050] In speculative inference, CPU-interrupted synchronization (referred to as synchronous transfer) refers to the CPU actively intervening in the execution flow of the Neural Processing Unit (NPU) to complete data verification, synchronization, and updates between the main model and the speculative model. This method frequently interrupts the NPU flow, resulting in high communication latency and inefficient pipeline utilization. Uninterrupted streaming communication (referred to as streaming transfer), on the other hand, avoids CPU intervention as much as possible, achieving efficient and continuous data transfer between models and maintaining the high concurrency and throughput of the NPU. Synchronous transfer requires multiple interruptions of the NPU process by the CPU to complete inter-model communication, introducing additional latency in each inference round. As the number of rounds increases, this latency accumulates significantly, causing the overall inference speed improvement to be far less than expected and limiting concurrency and efficiency, thus forming a performance bottleneck. This method fails to fully utilize the hardware's potential and becomes a major obstacle to inference acceleration.
[0051] This application provides a language model inference method. In the speculative inference system of this application embodiment, the subject model and the speculative model can use the same attention mask and block table in the context information to obtain the required information. There is no need to switch control logic when updating parameters, so it will not cause computational pauses and pipeline bubbles caused by waiting for the CPU to complete parameter configuration, thereby improving the overall computational efficiency and throughput.
[0052] For ease of explanation, the tokens generated by the speculative model will be referred to as draft tokens, draft words, or speculative tokens; the tokens generated by the main model will be referred to as main tokens or main words. Nouns related to tokens, such as first main token, second main token, and draft token, can refer to multiple tokens.
[0053] The following is combined Figure 1 The schematic block diagram of the speculative reasoning system shown illustrates the speculative reasoning system of the main embodiment of this application.
[0054] The speculative inference system of this application operates on a computing device cluster, which includes at least one computing device. Each computing device includes Q first accelerated computing units (NPUs#1), R second accelerated computing units (NPUs#2), and at least one central processing unit (CPU). Solid lines connecting different modules indicate communication lines between them, while dashed lines indicate data transmission between them. The Q NPUs#1 can be an NPU cluster or an NPU interconnect array, and the R NPUs#2 can also be an NPU cluster or an NPU interconnect array. NPUs#1 and NPUs#2 can be located on a single computing device or on different computing devices; this application does not impose any limitations on this.
[0055] In some embodiments, the main model operates in a pre-filling and decoding separation manner, wherein A of the Q first accelerated computing units perform the pre-filling function of the main model, and B of the R second accelerated computing units perform the decoding function of the main model; QA of the Q first accelerated computing units perform the pre-filling function of the speculative model, and RB of the R second accelerated computing units perform the decoding function of the speculative model, where Q, R, A, and B are positive integers.
[0056] In Large Language Model (LLM) inference, key-value (KV) caching is a crucial memory optimization mechanism used to store pre-computed key and value vectors from the self-attention layer. This avoids repeatedly calculating the context information of historical tokens during the decoding phase. During the prefill phase, the model processes all input tokens in parallel, generating and caching the KV vectors for the entire sequence. In the decoding phase, the model only needs to compute the KV vector for the newly generated token and incrementally append it to the cache, while reusing previously cached KV vectors for self-attention computation. This significantly reduces computational overhead and improves inference efficiency.
[0057] Prefill-decode (PD) separation is an optimized architecture for language model inference, improving hardware efficiency by strictly dividing the computational stages across different computing nodes. In the prefill stage, the model processes all prompts in parallel at once, completing attention score calculation and KV cache filling, maximizing the parallel capabilities of the NPU tensor cores. This stage initializes the KV cache, calculates the attention key and value for each position, and writes them into the KV cache, forming the initial cache state. Due to the need to process the entire input sequence, this stage is computationally intensive but offers the advantage of parallel processing. In the decode stage, the model outputs token-by-token in a purely autoregressive manner, incrementally updating the KV cache based on the already constructed one, optimizing GPU memory bandwidth utilization, thereby ensuring the coherence and correctness of the generated text. The core difference between these two stages is that the prefill stage is responsible for initializing the KV cache, while the decode stage continuously maintains and updates the cache content.
[0058] This hardware architecture fully considers the computational characteristics of different stages. The node responsible for prefill computation uses a computationally intensive NPU, which possesses powerful parallel computing capabilities and large-capacity GPU memory, specifically designed for efficiently processing attention computations on long input sequences. The node responsible for decode computation uses a high-bandwidth, low-latency NPU, whose extremely high GPU memory bandwidth and fast memory access mechanism optimize the pipeline efficiency for single-token autoregressive generation. This separation design relies on the temporal purity of stage execution, requiring prefill to be fully executed before decoding, while the decoding stage only allows single-token iteration operations.
[0059] In some speculative inference systems, the main model is allocated to dedicated NPUs for prefill (A NPUs #1) and dedicated NPUs for decoding (B NPUs #2) according to the PD separation principle. To further improve hardware efficiency, the prefill phase of the speculative model runs on the remaining QA NPUs #1, and the decoding phase of the speculative model runs on the remaining RB NPUs #2. This architecture can be called a heterogeneous speculative inference system.
[0060] In one possible implementation, the decoding function of the main model operates in a hybrid parallelism mode of data parallelism and expert parallelism across B first-acceleration computing units. Specifically, in language model inference, the hybrid parallelism mode of data parallelism (DP) and expert parallelism (EP) is referred to as the DP×EP parallel mode. Its core is to achieve efficient training / inference of large-scale models through the combination of two parallel strategies. Data parallelism shards the input data and processes the same model copies in parallel across multiple devices; expert parallelism distributes the expert modules in the model to different devices and dynamically routes computations as needed.
[0061] exist Figure 1 In the speculative inference system shown, on the one hand, the post-decoupling of the speculative model decouples the PD separation system from the speculative framework, effectively reducing data transmission between nodes. On the other hand, by pre-positioning the main model and concatenating the process, the input preparation in a single-step speculative inference is reduced from two steps to one, and the pipeline is not interrupted by CPU synchronization between the main model and the speculative model. This compresses the framework latency between the main model and the speculative model within a single step of inference, making the overall framework latency of speculative inference consistent with that of non-speculative scenarios. This improves the computational efficiency and throughput of the language model in the decoding stage and reduces the latency of individual word generation.
[0062] The following is combined with Figure 2 and Figure 3 The flowchart shown illustrates the language model reasoning method and explains how the method of this application is applied to a speculative reasoning system.
[0063] S210, the main model acquires natural language text and determines the first guiding word lexical based on the natural language text.
[0064] In typical cases, this step is performed by the CPU. In some embodiments, the subject model obtains natural language text (i.e., prompt) from user input, then tokenizes and embeds it to generate an initially generated token sequence (i.e., the first prompt lexical units), metadata such as the positional encoding of these tokens, and contextual information. For example, if the natural language text is "What is the capital of China?", a token sequence ["<begin_of_sentence> The system generates metadata such as the location code (0-5) for each token, including the information of the Chinese capital, the location ...
[0065] For ease of explanation, in the following embodiments, it is assumed that the ideal output of the speculative reasoning system is ["China", "capital", "is", "Beijing", "."].
[0066] S220, the main model determines the first main lexicon and the first context information based on the first guiding lexicon.
[0067] In typical cases, this step is performed during the prefill phase of the main model. In some embodiments, the main model also initializes a key-value cache based on first context information.
[0068] In one possible implementation, the hidden states of the last layer of the main model are concatenated with the embedding vectors of its tokens, serving as input to the speculative model, which is then fine-tuned and trained. Another possible implementation, similar to DeepSeek V3, integrates an MTP-like structure during the pre-training phase to further improve the matching between the generated draft and the main model's output. These designs, which enhance alignment to improve acceptance rates, significantly reduce inference latency while maintaining quality, making them an important technical path for achieving low-latency generation.
[0069] For ease of explanation, in subsequent embodiments, the type of the first context information is the last layer of the hidden state of the main model.
[0070] In one possible implementation, the main model generates a token (i.e., the first main term), such as "China". Then, the KV cache is initialized based on the last layer of the hidden state.
[0071] S230, the speculative model determines the second introductory word based on the first contextual information, the first introductory word, and the first main word.
[0072] In general, this step is performed during the prefill phase of the main model. In some embodiments, the number of first introductory lexical units is equal to the number of second introductory lexical units.
[0073] In one possible implementation, the speculative model first determines the combined lexical sequence of the first introductory lexical and the first subject lexical [“<begin_of_sentence> Remove the first token from ["China", "Capital", "Is", "Where", "?", "China"] to obtain the second guiding token ["China", "Capital", "Is", "Where", "?", "China"]. Reuse the positional encoding (e.g., 0-5) and other metadata used by the main model, and use the complete hidden state generated in the prefill stage of the main model as input.
[0074] In common speculative reasoning systems, the second introductory word is usually a direct concatenation of the first introductory word and the first subject word, for example, [“<begin_of_sentence> “, “China”, “capital”, “is”, “where”, “?”, “China”).
[0075] In common speculative inference systems, the second introductory term is typically a direct concatenation of the first introductory term and the first main term, and the number of the first introductory term is not equal to the number of the second introductory term. Therefore, transitioning from the pre-filling stage of the main model to the pre-filling stage of the speculative model requires realigning positional encodings, dynamically reconstructing the key-value cache and block table, and updating the attention mask. These adjustments force the CPU to frequently intervene in parameter synchronization, interrupting the continuous computation of the first accelerated computing unit. These synchronization operations caused by cross-model parameter differences can cause speculative inference systems to reach a performance bottleneck, resulting in a lower-than-expected improvement in overall inference speed.
[0076] In this implementation, the speculative model can directly reuse parameters such as position encoding, attention mask, key-value cache, block table, and sequence length of the main model, without causing computational pauses and pipeline bubbles due to waiting for the CPU to complete parameter synchronization, thereby improving overall computational efficiency and throughput.
[0077] In some embodiments, the control parameters of the subject model are used as the control parameters of the speculative model, and the first subject lexical and the first contextual information are determined based on the same control parameters as the second introductory lexical. When the speculative model is an MTP layer, the control parameters of the speculative model are the control parameters of the attention operator of the MTP layer.
[0078] In large language models, some language model control parameters can be used as control parameters for attention operators to support efficient key-value cache management and computation. Positions and their corresponding positional codes identify the specific location of the currently processed token in the sequence, ensuring that positional information is correctly incorporated during attention computation. The block table is a structure indicating which memory blocks are used in the complete KV cache for the current request, allowing the attention operator to access only the relevant cache blocks, thereby improving computational efficiency and reducing memory bandwidth consumption. The sequence length (seq lens) represents the total length of the current request sequence, including the input prompt and the number of generated tokens. This parameter helps the attention operator determine the range of valid tokens and correctly mask padding, avoiding invalid computation. These parameters work together to ensure that the attention mechanism remains efficient and accurate when handling long sequences and batch inference.
[0079] In common speculative inference systems, inconsistencies in control parameters such as position encoding, block table, and sequence length between the principal and speculative models necessitate readjustment of computational parameters during the transition from the principal model's pre-filling stage to the speculative model's pre-filling stage, leading to frequent CPU synchronization operations. These parameter adjustments interrupt the continuous computation of the first accelerated computing unit, forcing it to wait for the CPU to complete parameter configuration and data transfer, causing the speculative inference system to hit a performance bottleneck, resulting in a lower-than-expected overall inference speed improvement.
[0080] In some embodiments, the control parameters of the main model are used as the control parameters of the attention operator of the speculative model. Specifically, mainstream large language models, such as DeepSeek V3 / R1, employ Rotated Position Encoding (RoPE). When using the speculative model for prediction, position encoding is performed according to the actual number of tokens in the inference. However, for the MTP layer, the input token with index 0 is ignored during computation. Therefore, the MTP layer is treated as part of the main model, the input token with index 0 is discarded, the remaining tokens are shifted forward, and the control parameters of the main model are reused. RoPE ensures that the attention score remains unchanged after shifting all tokens. This guarantees the correct computation of the MTP layer, saves preparation time on the CPU in the inference pipeline, and simplifies block management of the entire system.
[0081] In this embodiment, the control parameters of the main model can be directly used as the control parameters of the speculative model. The first accelerated computing unit can stream key-value cache and first context information to the second accelerated computing unit, which will not cause computational pauses and pipeline bubbles caused by waiting for the CPU to complete parameter configuration, thereby improving the overall computing efficiency and throughput.
[0082] In some embodiments, the principal model can determine that all tokens have been generated and output, thus ending the entire speculative reasoning process. This step is typically executed by the CPU.
[0083] S240, the speculative model determines the first draft lexicon based on the first contextual information and the second guiding lexicon.
[0084] In general, this step is performed during the prefill phase of the main model. In one possible implementation, the speculative model may output "capital" or "Beijing". It should be understood that the number of first draft tokens can also be multiple. For example, the speculative model may output ["capital", "is"] or ["Beijing", "."]. For ease of explanation, subsequent embodiments of this application will illustrate the speculative model outputting one first draft token at a time.
[0085] S250, the main model determines the second main lexical unit and the second contextual information based on a portion of the information in the first contextual information that corresponds to the first main lexical unit and the first draft lexical unit.
[0086] In typical cases, this step is performed during the decoding phase of the main model. In some embodiments, the main model also updates the key-value cache based on the second context information.
[0087] In one possible implementation, the subject model takes a first subject token ("China") and a first draft token ("capital" or "Beijing") as input and generates corresponding positional codes (e.g., 6, 7) and other metadata. Then, the subject model calculates the hidden states corresponding to these two tokens (i.e., a portion of the information in the first context corresponding to the first subject token and the first draft token) and the generation probabilities of their corresponding positions. The generation probabilities of these two token positions are then used to determine whether to accept the first draft token.
[0088] If accepted (the first draft token is "capital"), the subject model generates another subject token after the first draft token, for example, "is" after "capital", and the output second subject token is ["capital", "is"]. If rejected (the first draft token is "Beijing"), the subject model generates another subject token after the first subject token, and the output second subject token is ["capital"].
[0089] S260, the speculative model determines the second draft word based on a portion of the information in the second context information corresponding to the first draft word and the second main word, or a portion of the information in the second context information corresponding to the first main word and the second main word, wherein the second main word is used as the first main word, the second draft word is used as the first draft word, and the second context information is used as the first context information.
[0090] Typically, this step is performed during the decoding phase of the speculative model. In one possible implementation, given that the main model receives a first draft token, the speculative model combines the first draft token (“capital”) and the second main token (“is”) as input. Then, the speculative model generates a second draft token (e.g., “Beijing”) from the hidden states corresponding to these two tokens (i.e., a portion of the second context information corresponding to the first draft token and the second main token).
[0091] In one possible implementation, if the subject model rejects the first draft token, the speculative model takes the first subject token (“China”) and the second subject token (“capital”) as input. Then, the speculative model generates a second draft token (e.g., “is”) from the hidden states corresponding to these two tokens (i.e., a portion of the information in the second context corresponding to the first and second subject tokens).
[0092] In common speculative reasoning systems, the speculative model takes the second subject token (“is”) as input. Then, the speculative model generates a second draft token (e.g., “Beijing”) from the hidden state corresponding to this token (i.e., a portion of the information in the second context corresponding to the second subject token).
[0093] In common speculative inference systems, the speculative model determines the second draft lexicon based on a portion of the second context information corresponding to the second subject lexicon. Simultaneously, the subject model determines the second subject lexicon and the second context information based on a portion of the first context information corresponding to both the first subject lexicon and the first draft lexicon. The different ways the speculative and subject models utilize context information lead to differences in their computational processes. This difference forces them to use different attention masks and key-value caching strategies (typically represented by block tables), frequently triggering parameter reconfiguration. Since the NPU cannot autonomously handle this type of control logic switching, each parameter update requires CPU intervention for synchronization, interrupting the NPU's continuous computational flow. This dynamic parameter adjustment caused by differences in model behavior can cause speculative inference systems to reach performance bottlenecks, resulting in overall inference speed improvements falling short of expectations.
[0094] In this embodiment, the subject model and the speculative model complete the corresponding calculations based on two sets of lexical units. They can use the same attention mask and block table in the context information to obtain the required information. There is no need to switch control logic when updating parameters, so there will be no calculation pauses or pipeline bubbles caused by waiting for the CPU to complete parameter configuration, thereby improving the overall computing efficiency and throughput.
[0095] In some embodiments, the control parameters of the subject model are used as the control parameters of the speculative model, and the second subject lexical and the second contextual information are determined based on the same control parameters as the second draft lexical.
[0096] In common speculative inference systems, inconsistencies in control parameters such as position encoding, block tables, and sequence lengths between the principal and speculative models necessitate readjustment of computational parameters during the transition from the speculative model's decoding phase to the principal model's decoding phase. This leads to frequent CPU synchronization operations. These parameter adjustments interrupt the continuous computation of the second acceleration unit, forcing it to wait for the CPU to complete parameter configuration and data transfer. This causes the speculative inference system to hit a performance bottleneck, resulting in a lower-than-expected overall inference speed improvement.
[0097] In this embodiment, the control parameters of the main model can be directly used as the control parameters of the speculative model. The second acceleration computing unit can stream key-value cache and second context information to the second acceleration computing unit, which will not cause computing pauses and pipeline bubbles caused by waiting for the CPU to complete parameter configuration, thereby improving the overall computing efficiency and throughput.
[0098] In language model inference scenarios, dynamic batch size is an optimization technique that dynamically adjusts the batch size based on the number of real-time requests and computing resources during inference, aiming to balance throughput and latency. The number of concurrent requests directly affects the dynamic batch size adjustment strategy: the system typically adjusts the dynamic batch size in real time based on the current number of concurrent requests, the input and output lengths of the requests, and hardware resources to maximize throughput or meet latency requirements. When the number of concurrent requests increases, the dynamic batch size may increase to utilize the parallel computing capabilities of the NPU; conversely, under low concurrency, the dynamic batch size may decrease to reduce latency, or requests of different lengths may be merged using padding or bucketing strategies to optimize efficiency.
[0099] In static graph inference of language models, the shape of the static graph mainly refers to the pre-allocated dimensions of key tensors (such as input tensors, attention weights, KV cache, etc.). When processing a set of concurrent requests, the dynamic batch size directly affects the actual effective shape of these tensors. For example, the [dynamic_batch_size, seq_len] dimension of the input tensor may need to be expanded or truncated due to dynamic changes in the number of requests.
[0100] Graph batching is a technique used in static graph inference frameworks to improve hardware utilization and optimize throughput by dynamically merging multiple input requests into a single batch for parallel computation. This technique typically involves dynamic padding (such as zero-padding for short sequences) and masking to conceal invalid computations. Static graph caching refers to pre-allocated and reused memory space during static graph inference, primarily used to store intermediate computation results (such as key-value caches) to reduce the overhead of redundant computations and dynamic memory allocation. The two are usually used in conjunction: graph batching handles multiple requests efficiently, while static graph caching optimizes the computational efficiency of generating long sequences, jointly improving inference performance.
[0101] In some embodiments, the number of first draft terms is the same as the number of second draft terms, and the shape of the input tensor of the static graph of the main model is the same as the shape of the input tensor of the static graph of the speculative model.
[0102] In common speculative inference systems, to handle concurrent requests, the input tensor of the static graph of the principal model typically has a shape of [dynamic_batch_size, n+1] during the determination of the second principal lexicon and the second context information. `dynamic_batch_size` is related to the number of concurrent requests, and `n` is the number of first draft lexicons. During the determination of the second draft lexicon, the input tensor of the static graph of the speculative model typically has a shape of [dynamic_batch_size, 1]. The principal model and the speculative model need to construct the graph batch parameters and static graph cache for the static graph, respectively.
[0103] In this implementation, the shape of the input tensor of the static graph of the main model is the same as the shape of the input tensor of the static graph of the speculative model. The speculative model can reuse the graph batch parameters and static graph cache of the main model, thereby improving the overall computational efficiency and throughput.
[0104] In some embodiments, the main model can determine that all tokens have been generated and output, ending the entire speculative reasoning process. If output has not yet been completed, the second main terminology is used as the first main terminology, the second draft terminology as the first draft terminology, and the second context information as the first context information. S250 and S260 are executed iteratively until all tokens have been generated and output. This step is typically performed by the CPU.
[0105] In some embodiments, Figure 4 A schematic block diagram of a pipeline for a language model reasoning method is shown. Specifically, Figure 4 (a) shows the workflow of different processing units in a common speculative reasoning system. Figure 4(b) illustrates the workflow of different processing units in the speculative reasoning system of this application. Clearly, the speculative reasoning system of this application can improve the computational efficiency and throughput of speculative reasoning systems.
[0106] The foregoing mainly describes the solutions provided by the embodiments of this application from a methodological perspective. To achieve the above functions, the embodiments of this application also include hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0107] like Figure 5 As shown, this application also provides a computing device, which may also be referred to as a language model reasoning device, the device comprising:
[0108] The acquisition module is used to acquire natural language text.
[0109] The processing module is used to instruct the subject model to determine a first guiding word element based on natural language text; to instruct the subject model to determine a first subject word element and first contextual information based on the first guiding word element; to instruct the speculative model to determine a second guiding word element based on the first contextual information, the first guiding word element, and the first subject word element; to instruct the speculative model to determine a first draft word element based on the first contextual information and the second guiding word element; to instruct the subject model to determine a second subject word element and second contextual information based on a portion of the information in the first contextual information corresponding to the first subject word element and the first draft word element; and to instruct the speculative model to determine a second draft word element based on a portion of the information in the second contextual information corresponding to the first draft word element and the second subject word element, or a portion of the information in the second contextual information corresponding to the first subject word element and the second subject word element, wherein the second subject word element is used as the first subject word element, the second draft word element is used as the first draft word element, and the second contextual information is used as the first contextual information.
[0110] As an example of a software functional unit, any of the aforementioned modules may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, or a container. Furthermore, the aforementioned computing instance may be one or more. For example, a processing module may include code running on multiple hosts / virtual machines / containers.
[0111] As an example of a hardware functional unit, any of the aforementioned modules may include at least one computing device, such as a server. Alternatively, the module may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The aforementioned PLD may be implemented using a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), generic array logic (GAL), or any combination thereof.
[0112] For example, the implementation of each module in the device will be described below, taking the processing module as an example.
[0113] As an example of a software functional unit, a processing module may include code running on a compute instance. A compute instance may include at least one of a physical host (computing device), a virtual machine, or a container. Furthermore, the aforementioned compute instance may be one or more. For example, a processing module may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed within the same region or in different regions. Further, the multiple hosts / virtual machines / containers used to run the code may be distributed within the same availability zone (AZ) or in different AZs, each AZ comprising one or more geographically proximate data centers. Typically, a region may include multiple AZs.
[0114] Furthermore, the multiple hosts / virtual machines / containers used to run this code can be distributed within the same Virtual Private Cloud (VPC) or across multiple VPCs. Typically, a VPC is set up within a region. Communication between two VPCs within the same region, as well as between VPCs in different regions, requires a communication gateway to be set up within each VPC to achieve interconnection between VPCs.
[0115] As an example of a hardware functional unit, a processing module may include at least one computing device, such as a server. Alternatively, the processing module may also be a device implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD can be implemented using a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), generic array logic (GAL), or any combination thereof.
[0116] Furthermore, the processing module includes multiple computing devices that can be distributed within the same region or in different regions. Similarly, the processing module includes multiple computing devices that can be distributed within the same Availability Zone (AZ) or in different AZs. Likewise, the processing module includes multiple computing devices that can be distributed within the same Virtual Private Cloud (VPC) or in multiple VPCs. These multiple computing devices can be any combination of computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.
[0117] like Figure 6 As shown, this application also provides a computing device 1200. The computing device 1200 includes a bus 1202, a processor 1204, a memory 1206, and a communication interface 1208. The processor 1204, the memory 1206, and the communication interface 1208 communicate with each other via the bus 1202. The computing device 1200 can be a server or a terminal device. It should be understood that this application does not limit the number of processors and memories in the computing device 1200.
[0118] In one possible implementation, bus 1202 can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of representation, Figure 6 The bus 1202 may be represented by a single line, but this does not mean that there is only one bus or one type of bus. The bus 1202 may include a path for transmitting information between various components of the computing device 1200 (e.g., memory 1206, processor 1204, communication interface 1208).
[0119] In one possible implementation, the processor 1204 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0120] In one possible implementation, memory 1206 may include volatile memory, such as random access memory (RAM). Processor 1204 may also include non-volatile memory, such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD).
[0121] In one possible implementation, the memory 1206 stores executable program code, which the processor 1204 executes to implement the functions of the aforementioned processing module and acquisition module, thereby realizing the language model inference method. That is, the memory 1206 stores instructions for executing this method.
[0122] In one possible implementation, the communication interface 1208 uses a transceiver module, such as, but not limited to, a network interface card or transceiver, to enable communication between the computing device 1200 and other devices or communication networks.
[0123] This application also provides a computing device cluster. The computing device cluster includes at least one computing device. The computing device can be a server, such as a central server, an edge server, or a local server in a local data center. In some embodiments, the computing device can also be a terminal device such as a desktop computer, a laptop computer, or a smartphone.
[0124] like Figure 7As shown, the computing device cluster includes at least one computing device 1200. The memory 1206 of one or more computing devices 1200 in the computing device cluster may store the same instructions for executing language model inference methods; alternatively, the memory 1206 of one or more computing devices 1200 in the computing device cluster may each store partial instructions for executing language model inference methods. In other words, a combination of one or more computing devices 1200 can jointly execute the instructions for executing language model inference methods.
[0125] It should be understood that the memory 1206 in different computing devices 1200 within the computing device cluster can store different instructions, each used to execute a portion of the functions of the language model inference device. In other words, the instructions stored in the memory 1206 of different computing devices 1200 can implement some or all of the functions of the aforementioned processing module and acquisition module.
[0126] like Figure 8 As shown, one or more computing devices in a computing device cluster can be connected via a network. This network can be a wide area network (WAN) or a local area network (LAN), etc. Specifically, two computing devices, 1200A and 1200B, are connected via a network, for example, through the communication interfaces of each computing device.
[0127] It should be understood that Figure 8 The functions of the computing device 1200A shown can also be performed by multiple computing devices 1200. Similarly, the functions of the computing device 1200B can also be performed by multiple computing devices 1200.
[0128] This application also provides a computer program product containing instructions. The computer program product may be a software or program product containing instructions, capable of running on a computing device or stored on any usable medium. When the computer program product is run on at least one computing device, it causes the at least one computing device to execute a language model inference method.
[0129] This application also provides a computer-readable storage medium. The computer-readable storage medium can be any available medium that a computing device can store, or a data storage device such as a data center containing one or more available media. The available medium can 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). The computer-readable storage medium includes instructions that instruct the computing device to execute a language model inference method.
[0130] 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 conceived 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.
Claims
1. A language model reasoning method, characterized in that, The method is applied to a cluster of computing devices, which runs a principal model and a speculative model. The method includes: The main model acquires natural language text and determines the first guiding word lexical unit based on the natural language text; The main model determines the first main lexical unit and the first contextual information based on the first guiding lexical unit; The speculative model determines the second guiding word based on the first context information, the first guiding word, and the first main word; The speculative model determines the first draft word based on the first context information and the second guiding word; The main model determines the second main lexical and the second contextual information based on a portion of the information in the first contextual information that corresponds to the first main lexical and the first draft lexical. The speculative model determines the second draft word based on a portion of the information in the second context information corresponding to the first draft word and the second main word, or a portion of the information in the second context information corresponding to the first main word and the second main word, wherein the second main word is used as the first main word, the second draft word is used as the first draft word, and the second context information is used as the first context information.
2. The method according to claim 1, characterized in that, The computing device cluster includes at least one computing device, which includes Q first accelerated computing units and R second accelerated computing units. The main model operates in a pre-filling and decoding separation manner, wherein A of the Q first accelerated computing units perform the pre-filling function of the main model, and B of the R second accelerated computing units perform the decoding function of the main model; QA of the Q first accelerated computing units perform the pre-filling function of the speculative model, and RB of the R second accelerated computing units perform the decoding function of the speculative model, where Q, R, A, and B are positive integers. The pre-filling function of the main model includes: determining the first main lexical unit and the first context information based on the first control parameter and the first guiding lexical unit; The pre-filling function of the speculative model includes: determining the first draft lexical based on the first control parameter, the first context information, and the second guiding lexical; The decoding function of the main model includes: based on the second control parameter, determining the second main word and the second context information according to a portion of the information in the first context information corresponding to the first main word and the first draft word; The decoding function of the speculative model includes: determining the second draft word based on the second control parameter, according to a portion of the information in the second context information corresponding to the first draft word and the second main word, or a portion of the information in the second context information corresponding to the first main word and the second main word.
3. The method according to claim 2, characterized in that, The first control parameter or the second control parameter includes at least one of the following: position encoding, block table, and sequence length.
4. The method according to claim 2 or 3, characterized in that, The speculative model is a multi-term prediction MTP layer, and the control parameters of the speculative model are the control parameters of the attention operator of the MTP layer.
5. The method according to any one of claims 1 to 4, characterized in that, The number of the first introductory word elements is equal to the number of the second introductory word elements.
6. The method according to any one of claims 1 to 5, characterized in that, The number of terms in the first draft is the same as the number of terms in the second draft, and the shape of the input tensor of the static graph of the main model is the same as the shape of the input tensor of the static graph of the speculative model.
7. The method according to any one of claims 1 to 6, characterized in that, The type of the first context information is the last layer of the hidden state of the main model.
8. A language model reasoning device, characterized in that, The apparatus is applied to a computing device cluster, which runs a principal model and a speculative model; the apparatus includes: The acquisition module is used to acquire natural language text; Processing module, used for: The main model is instructed to determine the first guiding word lexical based on the natural language text; The main model is instructed to determine the first main lexical unit and the first contextual information based on the first guiding lexical unit; The speculative model is instructed to determine the second introductory word based on the first context information, the first introductory word, and the first main word; The speculative model is instructed to determine the first draft word based on the first context information and the second guiding word; The main model is instructed to determine the second main lexical and the second contextual information based on a portion of the information in the first contextual information that corresponds to the first main lexical and the first draft lexical. The speculative model is instructed to determine the second draft word based on a portion of the information in the second context information corresponding to the first draft word and the second main word, or a portion of the information in the second context information corresponding to the first main word and the second main word, wherein the second main word is used as the first main word, the second draft word is used as the first draft word, and the second context information is used as the first context information.
9. The apparatus according to claim 8, characterized in that, The computing device cluster includes at least one computing device, which includes Q first accelerated computing units and R second accelerated computing units. The main model operates in a pre-filling and decoding separation manner, wherein A of the Q first accelerated computing units perform the pre-filling function of the main model, and B of the R second accelerated computing units perform the decoding function of the main model; QA of the Q first accelerated computing units perform the pre-filling function of the speculative model, and RB of the R second accelerated computing units perform the decoding function of the speculative model, where Q, R, A, and B are positive integers. The pre-filling function of the main model includes: determining the first main lexical unit and the first context information based on the first control parameter and the first guiding lexical unit; The pre-filling function of the speculative model includes: determining the first draft word based on the first control parameter, according to the first context information and the second guiding word word; The decoding function of the main model includes: based on the second control parameter, determining the second main word and the second context information according to a portion of the information in the first context information corresponding to the first main word and the first draft word; The decoding function of the speculative model includes: determining the second draft word based on the second control parameter, according to a portion of the information in the second context information corresponding to the first draft word and the second main word, or a portion of the information in the second context information corresponding to the first main word and the second main word.
10. The apparatus according to claim 9, characterized in that, The first control parameter or the second control parameter includes at least one of the following: position encoding, block table, and sequence length.
11. The apparatus according to claim 9 or 10, characterized in that, The speculative model is a multi-term prediction MTP layer, and the control parameters of the speculative model are the control parameters of the attention operator of the MTP layer.
12. The apparatus according to any one of claims 8 to 11, characterized in that, The number of the first introductory word elements is equal to the number of the second introductory word elements.
13. The apparatus according to any one of claims 8 to 12, characterized in that, The number of terms in the first draft is the same as the number of terms in the second draft, and the shape of the input tensor of the static graph of the main model is the same as the shape of the input tensor of the static graph of the speculative model.
14. The apparatus according to any one of claims 8 to 13, characterized in that, The type of the first context information is the last layer of the hidden state of the main model.
15. A computing device cluster, characterized in that, It includes at least one computing device, said at least one computing device comprising Q first neural processing units, R second neural processing units, and at least one central processing unit, wherein: The at least one central processing unit is used to acquire natural language text and determine a first introductory word based on the natural language text; The Q first neural processing units are used for: Based on the first introductory word element, determine the first main word element and the first contextual information; Based on the first guiding word element, determine the first subject word element and the first context information; Based on the first context information and the second guiding word element, the first draft word element is determined; The R second neural processing units are used for: Based on a portion of the information in the first context information corresponding to the first main word and the first draft word, determine the second main word and the second context information; The second draft word is determined based on a portion of the information in the second context information corresponding to the first draft word and the second main word, or a portion of the information in the second context information corresponding to the first main word and the second main word, wherein the second main word is used as the first main word, the second draft word is used as the first draft word, and the second context information is used as the first context information.
16. The computing device cluster according to claim 15, characterized in that: A of the Q first neural processing units are used to determine the first subject word and the first context information based on the first control parameter and the first guiding word word. The QA first acceleration computing units among the Q first acceleration computing units are used to determine the first draft word based on the first control parameters, the first context information, and the second guiding word word; B of the R second acceleration computing units are used to determine the second main word and the second context information based on the second control parameters and according to a portion of the information in the first context information corresponding to the first main word and the first draft word. The R second acceleration computing units among the R second acceleration computing units are used to determine the second draft word based on the second control parameters and according to a portion of the information in the second context information corresponding to the first draft word and the second main word, or a portion of the information in the second context information corresponding to the first main word and the second main word.
17. The computing device cluster according to claim 15 or 16, characterized in that, The number of the first introductory word elements is equal to the number of the second introductory word elements.
18. A computer program product containing instructions, characterized in that, When the instruction is executed by the computing device cluster, the computing device cluster performs the method as described in any one of claims 1 to 7.
19. A computer-readable storage medium, characterized in that, It includes computer program instructions, which, when executed by a cluster of computing devices, perform the method as described in any one of claims 1 to 7.
