Large language model inference method and device based on multi-path parallel inference
Patent Information
- Application Number
- CN202610754466.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-28
- Publication Date
- 2026-08-18
AI Technical Summary
[0003]然而,现有大语言模型大多采用串行推理方式,即模型按照单一路径逐步生成后续推理内容
[0022] This invention provides a method and apparatus for reasoning a large language model based on multi-path parallel reasoning. The method involves acquiring the task text of a target task; inputting the task text into a large language model for parallel reasoning to generate path reasoning results corresponding to multiple reasoning paths; and inputting the multiple reasoning paths and their corresponding path reasoning results into the large language model to generate a model reasoning result corresponding to the target task. By performing multi-path parallel reasoning on the target task and combining the path reasoning results from multiple reasoning paths to generate the model reasoning result, the accuracy, stability, and efficiency of reasoning for complex tasks using a large language model are improved.
Smart Images

Figure CN122596244A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of large language model technology, and in particular to a large language model reasoning method and apparatus based on multi-path parallel reasoning. Background Technology
[0002] With the development of artificial intelligence technology, Large Language Models (LLMs) have been widely applied in scenarios such as mathematical reasoning, code generation, intelligent question answering, task planning, and complex logic analysis. Existing LLMs are typically based on autoregressive generation mechanisms, predicting each token of the input text to progressively generate the corresponding reasoning process and output results. In complex task processing, LLMs often rely on the Chain of Thought (CoT) approach, extending the reasoning steps to improve problem-solving capabilities.
[0003] However, most existing large language models employ a sequential reasoning approach, where the model generates subsequent reasoning content step-by-step along a single path. In this process, the reasoning steps generated early in the model continuously influence the direction of subsequent reasoning. When the initial reasoning direction deviates, subsequent reasoning processes are prone to extending in the wrong direction, making it difficult for the model to escape the current reasoning path. This results in erroneous reasoning results, low reasoning stability, and insufficient ability to solve complex tasks. Furthermore, as the length of sequential reasoning increases, the model's reasoning latency and computational resource consumption also increase significantly, making it difficult to meet the application requirements of real-time reasoning scenarios.
[0004] Meanwhile, some existing methods attempt to improve the quality of model output by means of repeated sampling, multiple generation, or result voting. However, such methods usually only filter the final result, lack the synergistic use of different reasoning processes, are difficult to effectively integrate multiple reasoning ideas, and are prone to causing redundant computing resources.
[0005] Therefore, how to improve the reasoning accuracy, reasoning stability, and reasoning efficiency of large language models in complex tasks has become an urgent technical problem to be solved in the field of large language model reasoning technology. Summary of the Invention
[0006] This invention provides a method and apparatus for reasoning large language models based on multi-path parallel reasoning. By performing multi-path parallel reasoning on the target task and combining the path reasoning results corresponding to multiple reasoning paths to generate model reasoning results, the accuracy, stability and reasoning efficiency of reasoning for complex tasks of large language models are improved.
[0007] In a first aspect, the present invention provides a large language model reasoning method based on multi-path parallel reasoning, comprising the following steps: Obtain the task text of the target task; The task text is input into a large language model for parallel reasoning, generating path reasoning results corresponding to multiple reasoning paths. Multiple inference paths and the inference results corresponding to each inference path are input into the large language model to generate model inference results corresponding to the target task.
[0008] Preferably, according to the large language model reasoning method based on multi-path parallel reasoning provided by the present invention, the step of inputting the task text into the large language model for parallel reasoning to generate path reasoning results corresponding to multiple reasoning paths includes: Based on the task text, generate multiple path input sequences; Insert corresponding path control tokens into each of the path input sequences so that the large language model generates path reasoning content with different reasoning directions based on different path control tokens; Assign corresponding path identification information to each of the path input sequences, and generate corresponding path location codes based on the path identification information; Multiple path input sequences carrying corresponding path location codes are input into the large language model for parallel decoding, and path inference results corresponding to multiple inference paths are generated based on multiple token sequences generated during the parallel decoding process.
[0009] Preferably, according to the large language model reasoning method based on multi-path parallel reasoning provided by the present invention, generating multiple path input sequences based on the task text includes: Construct an initial input sequence based on the task text; The initial input sequence is copied according to a preset number of paths to generate multiple path input sequences.
[0010] Preferably, in the large language model reasoning method based on multi-path parallel reasoning provided by the present invention, the step of inserting corresponding path control tokens into each of the path input sequences includes: Insert path control tokens with different identifier values for different path input sequences, so that different path control tokens with different identifier values correspond to different inference modes; The reasoning mode includes at least one of the following: Formula derivation mode, logic verification mode, boundary condition analysis mode, counterexample search mode, enumeration reasoning mode, code planning mode.
[0011] Preferably, according to the large language model reasoning method based on multi-path parallel reasoning provided by the present invention, the step of assigning corresponding path identification information to each of the path input sequences and generating corresponding path location codes based on the path identification information includes: Obtain the basic position code corresponding to the token in each path input sequence, and obtain the path identifier code corresponding to each path input sequence; A fusion operation is performed on the basic location code and the path identifier code to generate the path location code corresponding to each path input sequence; The path location encoding is used as the location input of the large language model to distinguish the token source in different inference paths.
[0012] Preferably, according to the large language model reasoning method based on multi-path parallel reasoning provided by the present invention, the step of inputting multiple path input sequences carrying corresponding path position codes into the large language model for parallel decoding, and generating path reasoning results corresponding to multiple reasoning paths based on multiple token sequences generated during the parallel decoding process, includes: Identify a common prefix token sequence shared among multiple path input sequences; Perform unified attention computation on the common prefix token sequence and cache the corresponding key vector and value vector; After content forks occur in multiple path input sequences, incremental attention calculation is performed on the forked path input sequences based on the cached Key vector and Value vector to obtain the incremental attention calculation result; Based on the incremental attention calculation results, token prediction is performed synchronously on multiple path input sequences to obtain the token prediction results corresponding to each path input sequence. Update the corresponding path input sequence based on the token prediction result corresponding to each path input sequence; Based on the updated input sequences of each path, generate path inference results corresponding to multiple inference paths.
[0013] Preferably, according to the large language model reasoning method based on multi-path parallel reasoning provided by the present invention, after content bifurcation occurs in multiple path input sequences, incremental attention calculation is performed on the bifurcation path input sequences based on the cached Key vector and Value vector to obtain the incremental attention calculation result, including: Determine the path fork positions corresponding to each path input sequence; The corresponding cache sharing range is determined based on the path fork location; For the common prefix token sequence before the path fork position, reuse the cached Key vector and Value vector; For the fork token sequence after the path fork position, re-perform attention calculation; Based on the reused Key vector, Value vector, and attention calculation data obtained by re-performing attention calculation, a corresponding incremental attention calculation result is generated.
[0014] Preferably, according to the large language model reasoning method based on multi-path parallel reasoning provided by the present invention, the step of simultaneously performing token prediction on multiple path input sequences based on the incremental attention calculation result to obtain the token prediction result corresponding to each path input sequence includes: Multiple path input sequences are arranged according to a preset path dimension to construct a corresponding batch processing input matrix; Based on the batch input matrix and the incremental attention calculation results, token probability calculation is performed synchronously on multiple path input sequences to obtain the token probability distribution corresponding to each path input sequence. Determine the corresponding target token based on the token probability distribution corresponding to each path input sequence; Each target token is appended to the end of its corresponding path input sequence to generate the token prediction result for each path input sequence.
[0015] Preferably, according to the large language model reasoning method based on multi-path parallel reasoning provided by the present invention, the step of inputting multiple reasoning paths and the path reasoning results corresponding to each reasoning path into the large language model to generate a model reasoning result corresponding to the target task includes: Based on the path reasoning results corresponding to each reasoning path, logical consistency detection, constraint satisfaction detection, and reasoning integrity detection are performed on the corresponding reasoning paths to obtain the corresponding detection results. Based on the detection results corresponding to each inference path, a path quality score is generated for the corresponding inference path. The target reasoning path is determined based on the quality scores of each path. The target reasoning path and the path reasoning result corresponding to the target reasoning path are input into the large language model to generate the model reasoning result corresponding to the target task.
[0016] Preferably, according to the large language model reasoning method based on multi-path parallel reasoning provided by the present invention, the step of performing logical consistency detection, constraint satisfaction detection, and reasoning integrity detection on the corresponding reasoning paths based on the path reasoning results of each reasoning path to obtain the corresponding detection results includes: Obtain the sequence of reasoning steps from the path reasoning results corresponding to each reasoning path; Based on the sequence of inference steps, the logical relationship between adjacent inference steps in the corresponding inference path is detected, and the logical consistency detection result of the corresponding inference path is obtained. Based on the task constraints corresponding to the target task, the constraint satisfaction status in the path reasoning results of each reasoning path is detected, and the constraint satisfaction detection results of the corresponding reasoning path are obtained. Based on the step coverage in the path reasoning results corresponding to each reasoning path, the missing reasoning steps in the corresponding reasoning path are detected, and the reasoning integrity detection result of the corresponding reasoning path is obtained. Based on the logical consistency detection result, constraint satisfaction detection result, and reasoning integrity detection result of the corresponding reasoning path, the detection result of the corresponding reasoning path is generated.
[0017] Preferably, in the large language model reasoning method based on multi-path parallel reasoning provided by the present invention, the step of generating a path quality score for each reasoning path based on the detection results corresponding to each reasoning path includes: Extract the logical consistency index, constraint satisfaction index, and reasoning integrity index from the detection results corresponding to each reasoning path; Based on preset scoring weights, the logical consistency index, constraint satisfaction index, and reasoning integrity index corresponding to each reasoning path are weighted and calculated to generate a path quality score for the corresponding reasoning path. Rank the path quality scores corresponding to multiple inference paths; Based on the ranking results, the inference path with the highest path quality score is determined as the target inference path.
[0018] Secondly, the present invention also provides a large language model reasoning device based on multi-path parallel reasoning, comprising the following modules: The acquisition module is used to acquire the task text of the target task; The parallel reasoning module is used to input the task text into a large language model for parallel reasoning and generate path reasoning results corresponding to multiple reasoning paths. The generation module is used to input multiple inference paths and the path inference results corresponding to each inference path into the large language model to generate model inference results corresponding to the target task.
[0019] Thirdly, the present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the large language model reasoning method based on multi-path parallel reasoning as described above.
[0020] Fourthly, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the large language model reasoning method based on multi-path parallel reasoning as described above.
[0021] Fifthly, the present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the large language model reasoning method based on multi-path parallel reasoning as described above.
[0022] This invention provides a method and apparatus for reasoning a large language model based on multi-path parallel reasoning. The method involves acquiring the task text of a target task; inputting the task text into a large language model for parallel reasoning to generate path reasoning results corresponding to multiple reasoning paths; and inputting the multiple reasoning paths and their corresponding path reasoning results into the large language model to generate a model reasoning result corresponding to the target task. By performing multi-path parallel reasoning on the target task and combining the path reasoning results from multiple reasoning paths to generate the model reasoning result, the accuracy, stability, and efficiency of reasoning for complex tasks using a large language model are improved. Attached Figure Description
[0023] To more clearly illustrate the technical solutions in this invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0024] Figure 1 This is one of the flowcharts of the large language model reasoning method based on multi-path parallel reasoning provided by the present invention.
[0025] Figure 2 This is a schematic diagram of the structure of the large language model reasoning device based on multi-path parallel reasoning provided by the present invention.
[0026] Figure 3 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0027] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0028] First, let's analyze some of the terms used in this invention: Large Language Model (LLM): Based on the Transformer architecture, this neural network model is pre-trained on massive amounts of text and can autoregressively generate text sequences. In this embodiment, DeepSeek-R1 series distillation models, Qwen2.5 series models, etc., can be selected.
[0029] Task text: Natural language input describing the task to be solved, such as a math problem, a code requirement, or a logic reasoning problem.
[0030] Reasoning path: The complete sequence of intermediate reasoning steps generated by the large language model from the start of the question to the provision of the answer reflects a specific problem-solving approach.
[0031] Token: The basic unit of text processing in large language models. It can be a word, a subword, or a character. The model understands and generates text in the form of token sequences.
[0032] Path control token: A special-purpose learnable token used to trigger large language models to generate reasoning paths with specific reasoning tendencies or patterns.
[0033] Path location encoding: A location encoding that incorporates path identity information, used to distinguish the source of tokens in different inference paths during parallel decoding.
[0034] Parallel decoding: In the same inference step, the large language model generates tokens for multiple inference paths simultaneously, rather than generating them one by one.
[0035] Key and Value Vectors: Intermediate representations in the Transformer self-attention mechanism. The model caches the key and value vectors of the generated tokens for reuse when subsequent tokens are focused on, avoiding redundant calculations.
[0036] KV cache: A high-speed cache that stores key vectors and value vectors, located in GPU memory, used to accelerate the autoregressive generation process.
[0037] Attention calculation: The core operation of the Transformer model, which obtains the attention score by dot product of the query vector and the key vector, and then weights and sums the value vectors to integrate contextual information.
[0038] All actions involving the acquisition of signal information or data in this invention are carried out in compliance with the relevant data protection laws and policies of the country where the device is located, and with the authorization granted by the owner of the device.
[0039] The following is combined with Figures 1-3The present invention describes a large language model reasoning method and apparatus based on multi-path parallel reasoning. By performing multi-path parallel reasoning on the target task and combining the path reasoning results corresponding to multiple reasoning paths to generate model reasoning results, the accuracy, stability and reasoning efficiency of large language model reasoning for complex tasks are improved.
[0040] Figure 1 This is one of the flowcharts illustrating a large language model reasoning method based on multi-path parallel reasoning provided by the present invention, such as... Figure 1 As shown, the method may include, but is not limited to, steps S100 to S300: S100, retrieve the task text of the target task; S200, the task text is input into a large language model for parallel reasoning, generating path reasoning results corresponding to multiple reasoning paths; S300, input multiple reasoning paths and the path reasoning results corresponding to each reasoning path into the large language model to generate model reasoning results corresponding to the target task.
[0041] In step S100 of some embodiments, the task text of the target task is obtained.
[0042] Understandably, the first step is to obtain the task text of the target task. The target task can be any task that requires a large language model to perform multi-step thinking, such as mathematical reasoning, code generation, logical judgment, or agent decision-making. The task text is a complete natural language description of the task.
[0043] For example, in a probability calculation scenario, the task text could be: "Four different numbers are randomly selected from the set {1,2,3,…,10} as the winning numbers. A person also randomly selects four numbers. If her numbers match the winning numbers, she wins the grand prize. It is known that she has won one prize. Find the probability that she wins the grand prize, expressed in the simplest fraction m / n, and calculate m+n." In step S200 of some embodiments, the task text is input into a large language model for parallel reasoning to generate path reasoning results corresponding to multiple reasoning paths.
[0044] Understandably, the task text mentioned above is input into a large language model for parallel reasoning, generating path reasoning results corresponding to multiple reasoning paths. Here, "parallel reasoning" means that the model initiates multiple thought processes in parallel within the same reasoning stage, rather than generating a long chain sequentially.
[0045] Each reasoning path contains a complete token sequence from problem understanding to intermediate deductions and then to a local conclusion. For example, for this probability problem, the model may generate three paths in parallel: the first uses the strategy of "enumerating all winning combinations", the second uses the strategy of "deriving the conditional probability formula", and the third uses the strategy of "eliminating counterexamples". Each path will output its complete reasoning process and the preliminary answer under that path.
[0046] In step S300 of some embodiments, multiple inference paths and the path inference results corresponding to each inference path are input into the large language model to generate model inference results corresponding to the target task.
[0047] Understandably, all the generated inference paths (i.e., the complete inference token sequence for each path) and the path inference results corresponding to each path are input into the large language model for information synthesis to generate the final model inference result corresponding to the target task.
[0048] In this step, the model acts like an expert reviewer, reading all the "problem-solving drafts," comprehensively analyzing the rationale and omissions of different reasoning paths, and ultimately refining a high-quality, unified answer. This process fully preserves the intermediate steps of each path, thus overcoming the deficiency of majority voting methods in losing reasoning details. The entire method achieves a paradigm shift from single-path deep thinking to multi-path broad thinking, effectively breaking through the "tunnel vision" bottleneck.
[0049] In some embodiments of the present invention, the step of inputting the task text into a large language model for parallel inference to generate path inference results corresponding to multiple inference paths includes: Based on the task text, generate multiple path input sequences; Insert corresponding path control tokens into each of the path input sequences so that the large language model generates path reasoning content with different reasoning directions based on different path control tokens; Assign corresponding path identification information to each of the path input sequences, and generate corresponding path location codes based on the path identification information; Multiple path input sequences carrying corresponding path location codes are input into the large language model for parallel decoding, and path inference results corresponding to multiple inference paths are generated based on multiple token sequences generated during the parallel decoding process.
[0050] Understandably, the first step involves generating multiple path input sequences based on the task text. This step prepares the input foundation for multiple parallel processing steps. The task text can be segmented to obtain an initial token sequence. Then, based on a preset number of paths (e.g., 4, 8, or 16), this initial sequence can be copied multiple times to obtain a set of path input sequences that initially contain identical content.
[0051] The second step is to insert the corresponding path control token into each path input sequence. A path control token is a special token with learnable parameters, typically represented as "".<think_i> The symbol "i" represents the path identifier. By inserting control tokens with different identifier values at specific positions in the input sequence of each path (generally after the task text and before the start of inference), the large language model can be guided to activate different inference modes during subsequent decoding, thereby generating path-based inference content with different inference directions. For example, path 1 inserts...<think_1> Insert path 2<think_2> ,etc.
[0052] The third step involves assigning corresponding path identifier information to each input sequence and generating a corresponding path position code based on this identifier. Here, the "path identifier information" is a learnable embedding vector that uniquely identifies each path, while the "path position code" is a composite position representation obtained by fusing traditional position codes with the path identifier information. Specifically, for a token at position t in path j, in addition to calculating its basic position code to represent its relative position in the sequence, an embedding vector bound to path j is superimposed on the token's key and value vectors. The resulting path position code carries dual information: "I am the t-th token of path j," enabling subsequent attention calculations to accurately distinguish source tokens from different paths, effectively solving the position ambiguity problem in parallel multi-path scenarios.
[0053] The fourth step involves inputting multiple path input sequences, each carrying the corresponding path position encoding, into a large language model for parallel decoding. Based on the multiple token sequences generated during parallel decoding, path inference results corresponding to multiple inference paths are generated. Parallel decoding means that at each time step, the model simultaneously performs autoregressive generation on multiple paths and predicts the next lexical unit for each path. The token sequences gradually accumulated for each path constitute the complete path inference result for that path. This parallel processing significantly improves the utilization of GPU computing resources and memory bandwidth.
[0054] In some embodiments of the present invention, generating multiple path input sequences based on the task text includes: Construct an initial input sequence based on the task text; The initial input sequence is copied according to a preset number of paths to generate multiple path input sequences.
[0055] It is understandable that, first, the task text obtained is converted into a list of token identifiers using the tokenizer配套 with the large language model, and this list is the initial input sequence. For example, the task text "Calculate 1+1" may be segmented into the identifiers corresponding to the four tokens ['Calculate', '1', '+', '1']. Then, according to the preset number of paths P, a copy operation is performed on this initial input sequence to generate P path input sequences with exactly the same content. The preset number of paths P can be dynamically set according to the complexity of the task, the available GPU video memory size, or the user's requirement for response time. For example, for relatively simple tasks, P can be set to 4, and for high-difficulty competition-level math problems, P can be set to 8 or 16. The copy operation ensures that all inference paths start from exactly the same "problem understanding" starting point, and the subsequent thinking differences they generate only come from the guidance of different control tokens and random sampling during their respective decoding processes, thus stimulating thinking diversity on a fair basis.
[0056] In some embodiments of the present invention, inserting the corresponding path control tokens into each of the path input sequences includes: Inserting path control tokens with different identification values for different path input sequences so that the path control tokens with different identification values correspond to different inference modes; Among them, the inference mode includes at least one of the following: Formula derivation mode, logical verification mode, boundary condition analysis mode, counterexample search mode, enumeration inference mode, code planning mode.
[0057] It is understandable that for different path input sequences, path control tokens with different identification values are inserted at the end of their sequences (i.e., after the task text content). These identification values can be consecutive digital numbers, such as 1, 2, 3..., and each token is a special reserved word element in the model vocabulary, and has acquired the ability to trigger a specific inference mode through gradient descent during the training phase.
[0058] After insertion, the path control tokens with different identification values will correspond to different inference modes, and these inference modes include but are not limited to at least one of the formula derivation mode, logical verification mode, boundary condition analysis mode, counterexample search mode, enumeration inference mode, and code planning mode.
[0059] For example, in formula derivation mode, the model prioritizes listing relevant theorems and performing symbolic derivations; in logic verification mode, it examines the logical implications between reasoning steps sentence by sentence; in boundary condition analysis mode, it tends to examine extreme value cases first; in counterexample search mode, it actively seeks cases that refute the current hypothesis; in enumeration reasoning mode, it tends to classify and enumerate the solution space; and in code planning mode, it emphasizes architectural design before filling in details in coding tasks. By assigning different modes to different paths, the model can jointly attack the same problem from multiple cognitive perspectives, effectively ensuring the diversity of thinking among parallel paths and avoiding the risk of the singularity of "tunnel vision" from the source.
[0060] In some embodiments of the present invention, the step of assigning corresponding path identification information to each of the path input sequences and generating corresponding path location codes based on the path identification information includes: Obtain the basic position code corresponding to the token in each path input sequence, and obtain the path identifier code corresponding to each path input sequence; A fusion operation is performed on the basic location code and the path identifier code to generate the path location code corresponding to each path input sequence; The path location encoding is used as the location input of the large language model to distinguish the token source in different inference paths.
[0061] Understandably, the first step is to obtain the basic positional encoding for each token in the input sequence of each path. The basic positional encoding is used to represent the relative or absolute position of the token within its respective sequence. For example, rotational position embedding is a commonly used basic positional encoding scheme, which encodes positional information by applying rotational transformations to the query vector and key vector of the token.
[0062] Secondly, obtain the path identifier code corresponding to each path input sequence. The path identifier code is a learnable embedding vector that uniquely corresponds to the path number j, and its dimension is the same as the hidden layer dimension of the model.
[0063] For example, for four paths, there are four independent embedding vectors T(1), T(2), T(3), and T(4). Then, a fusion operation is performed on the basic positional encoding and the path identifier encoding. Specifically, for a token at position t in path j, before applying the rotated positional embedding, the path identifier encoding T(j) is first superimposed onto the original key vector k of the token, and then rotated using the rotation matrix Rt corresponding to position t to obtain the fused key vector; simultaneously, T(j) is also superimposed onto the value vector v of the token to obtain the fused value vector. The resulting path positional encoding contains both the sequence position information of the token itself and embeds the path identity information.
[0064] In the subsequent self-attention calculation, the dot product of the query vector and the key vector generates two items: one is the traditional "content-content" attention, and the other is "content-path identity" attention. The latter allows the model to directly perceive which inference path the currently focused lexical comes from, thereby completely eliminating positional ambiguity caused by lexicals in the same position in multiple paths, ensuring the clarity and accuracy of subsequent information synthesis.
[0065] In some embodiments of the present invention, the step of inputting multiple path input sequences carrying corresponding path position codes into the large language model for parallel decoding, and generating path inference results corresponding to multiple inference paths based on multiple token sequences generated during the parallel decoding process, includes: Identify a common prefix token sequence shared among multiple path input sequences; Perform unified attention computation on the common prefix token sequence and cache the corresponding key vector and value vector; After content forks occur in multiple path input sequences, incremental attention calculation is performed on the forked path input sequences based on the cached Key vector and Value vector to obtain the incremental attention calculation result; Based on the incremental attention calculation results, token prediction is performed synchronously on multiple path input sequences to obtain the token prediction results corresponding to each path input sequence. Update the corresponding path input sequence based on the token prediction result corresponding to each path input sequence; Based on the updated input sequences of each path, generate path inference results corresponding to multiple inference paths.
[0066] Understandably, the system first identifies a common prefix token sequence shared among multiple path input sequences. Since all path input sequences are copies of the same initial input sequence, the portion before the control token is inserted is identical; this portion constitutes the common prefix. For example, the common prefix might be the token string corresponding to the task text.
[0067] Next, the large language model performs a unified forward attention computation on this common prefix token sequence and writes the key vectors and value vectors of all layers generated by the computation into the KV cache. This cache is stored in GPU memory and can be quickly read by all subsequent paths.
[0068] Then, after the input sequences of multiple paths branch off, the branching point is usually located at the starting position of the control token insertion for different paths. That is, the decoding of each path will rely on the cached key vectors and value vectors for incremental attention calculation. Specifically, for the common prefix portion before the branching point, each path does not recalculate the key and value, but directly reuses them from the KV cache; only for the newly generated unique token sequences after the branching point are new key vectors and value vectors created and appended to their respective incremental caches. In this way, each path only needs to process its own unique part of the calculation, avoiding the repeated calculation of the same prefix by each of the P paths.
[0069] Based on the incremental attention calculation results, the model synchronously performs token prediction on multiple path input sequences. At each decoding time step, all paths share a batch for forward propagation to obtain the probability distribution of their next token. The target token is determined by sampling or greedy selection based on the probability distribution, and appended to the end of the corresponding path sequence, completing one update. This process is repeated until each path generates an end token or reaches its maximum length. The final accumulated complete token sequence for each path is the path inference result. This mechanism significantly reduces the computational overhead of parallel multiple paths through common prefix cache reuse and batch synchronous prediction, making the increase in inference latency far less than the linear increase in the number of paths.
[0070] In some embodiments of the present invention, after content forking occurs in multiple path input sequences, incremental attention calculation is performed on the forked path input sequences based on the cached Key vector and Value vector to obtain the incremental attention calculation result, including: Determine the path fork positions corresponding to each path input sequence; The corresponding cache sharing range is determined based on the path fork location; For the common prefix token sequence before the path fork position, reuse the cached Key vector and Value vector; For the fork token sequence after the path fork position, re-perform attention calculation; Based on the reused Key vector, Value vector, and attention calculation data obtained by re-performing attention calculation, a corresponding incremental attention calculation result is generated.
[0071] Understandably, the first step is to determine the path fork positions corresponding to each path input sequence. This position refers to the token index where the first difference occurs in the sequence, typically corresponding to the insertion point of the path control token. For example, path 1 inserts at position 100.<think_1> Path 2 inserts at the same position<think_2> Then the part after position 100 is the bifurcation segment.
[0072] Then, the corresponding cache sharing range is determined based on the path fork position. All token sequences before the fork position belong to the shared range, and the key and value vectors at these positions are already stored in the public KV cache. For token sequences after the fork position, they belong to the private segment of each path. In subsequent decoding, for the public prefix token sequence before the path fork position, the attention layer of each path directly reads the corresponding key and value vectors from the public KV cache without any recalculation. For the forked token sequence after the path fork position, new key and value vectors are calculated token by token in a standard manner, and these newly generated key-value pairs are stored in the path's independent incremental KV cache.
[0073] Finally, the data reused from the public cache and the newly computed incremental attention data are combined to form a complete attention context representation for each path, i.e., the incremental attention computation result. This strategy of "shared prefix reuse + unique suffix new computation" eliminates redundant computations in parallel multi-path scenarios to the greatest extent and significantly improves inference efficiency in long sequence scenarios.
[0074] In some embodiments of the present invention, the step of simultaneously performing token prediction on multiple path input sequences based on the incremental attention calculation result to obtain the token prediction result corresponding to each path input sequence includes: Multiple path input sequences are arranged according to a preset path dimension to construct a corresponding batch processing input matrix; Based on the batch input matrix and the incremental attention calculation results, token probability calculation is performed synchronously on multiple path input sequences to obtain the token probability distribution corresponding to each path input sequence. Determine the corresponding target token based on the token probability distribution corresponding to each path input sequence; Each target token is appended to the end of its corresponding path input sequence to generate the token prediction result for each path input sequence.
[0075] Understandably, at each time step of parallel decoding, the current input sequences of multiple paths are first arranged and organized according to a preset path dimension (i.e., the number of paths P) to construct a batch input matrix. This matrix is a three-dimensional tensor of shape [P, L, d], where P is the number of paths (batch size), L is the length of each path's sequence after padding and alignment, and d is the hidden layer dimension of the model. This matrixing operation allows the input of all paths to be processed simultaneously by the parallel computing units of the GPU.
[0076] Subsequently, based on the batch input matrix and the previously calculated incremental attention results, the large language model synchronously performs token probability calculations on all P paths.
[0077] Specifically, the output of the final layer of the model undergoes a linear transformation and Softmax normalization to obtain the probability distribution of the next token for each path across the entire vocabulary, forming a probability distribution matrix of [P, V] (where V is the vocabulary size). For each path's probability distribution, the system selects a target token based on a preset sampling strategy (such as temperature sampling, Top-p sampling, etc.). For example, it can select the token with the highest probability or randomly sample from the distribution to maintain diversity. The selected target token is appended to the end of the corresponding path's input sequence, thus completing the token prediction and sequence update for that time step. Through this batch processing synchronous computation, the originally P independent predictions are integrated into a single parallel matrix operation, greatly leveraging the parallel computing power of the GPU and enabling parallel multi-path inference to perform excellently in terms of latency metrics.
[0078] In some embodiments of the present invention, the step of inputting multiple inference paths and the path inference results corresponding to each inference path into the large language model to generate model inference results corresponding to the target task includes: Based on the path reasoning results corresponding to each reasoning path, logical consistency detection, constraint satisfaction detection, and reasoning integrity detection are performed on the corresponding reasoning paths to obtain the corresponding detection results. Based on the detection results corresponding to each inference path, a path quality score is generated for the corresponding inference path. The target reasoning path is determined based on the quality scores of each path. The target reasoning path and the path reasoning result corresponding to the target reasoning path are input into the large language model to generate the model reasoning result corresponding to the target task.
[0079] Understandably, this embodiment introduces an intelligent path quality screening mechanism to further improve the reliability of the final answer.
[0080] After obtaining all reasoning paths and their results, instead of immediately feeding all paths into the aggregation model, a quality assessment is first performed. First, based on the reasoning results for each path, three automatic checks are executed on each path: logical consistency check, constraint satisfaction check, and reasoning completeness check, yielding the results for each path. Logical consistency check primarily determines whether there are contradictions between reasoning steps; constraint satisfaction check verifies whether the path results meet the explicit or implicit constraints given in the problem (e.g., the answer must be a positive integer); and reasoning completeness check checks whether any necessary reasoning steps have been omitted.
[0081] Then, based on the detection results of each inference path, a corresponding path quality score is generated. The scoring process transforms logical consistency, constraint satisfaction, and reasoning completeness into quantitative indicators, and calculates a comprehensive score through weighted summation and other methods. Next, the target inference path is determined from all paths based on the path quality score, typically selecting the one or more paths with the highest scores as "elite paths".
[0082] Finally, only the selected target reasoning paths and their results are input into the large language model for final aggregation, generating model reasoning results corresponding to the target task. This mechanism of "evaluating and filtering first, then aggregating and synthesizing" can effectively filter out low-quality paths with chaotic logic or violations, making the input information in the aggregation stage of higher quality, thereby directly improving the accuracy of the final answer.
[0083] In some embodiments of the present invention, the step of performing logical consistency detection, constraint satisfaction detection, and reasoning integrity detection on the corresponding reasoning paths based on the path reasoning results of each reasoning path, and obtaining the corresponding detection results, includes: Obtain the sequence of reasoning steps from the path reasoning results corresponding to each reasoning path; Based on the sequence of inference steps, the logical relationship between adjacent inference steps in the corresponding inference path is detected, and the logical consistency detection result of the corresponding inference path is obtained. Based on the task constraints corresponding to the target task, the constraint satisfaction status in the path reasoning results of each reasoning path is detected, and the constraint satisfaction detection results of the corresponding reasoning path are obtained. Based on the step coverage in the path reasoning results corresponding to each reasoning path, the missing reasoning steps in the corresponding reasoning path are detected, and the reasoning integrity detection result of the corresponding reasoning path is obtained. Based on the logical consistency detection result, constraint satisfaction detection result, and reasoning integrity detection result of the corresponding reasoning path, the detection result of the corresponding reasoning path is generated.
[0084] Understandably, the first step is to extract the sequence of reasoning steps from the results of each reasoning path. These reasoning steps can usually be obtained through step identifiers in the text (such as "first step", "second step", "first", "then") or through automatic segmentation via semantic analysis, forming an ordered linked list of steps.
[0085] Subsequently, logical consistency is checked based on the sequence of reasoning steps: the connection between premises and conclusions between adjacent steps is analyzed one by one, checking whether the output of the previous step constitutes a valid input for the next step, and whether there are any substitutions of concepts or self-contradictions in between, generating logical consistency detection results. Simultaneously, constraint satisfaction is checked based on the task constraints corresponding to the target task: task constraints can be automatically extracted from the task text or preset by the system, such as "the denominator cannot be zero" or "the result must be a prime number," etc.; each intermediate step and final conclusion of the reasoning path is checked to see if it violates these constraints, yielding constraint satisfaction detection results. Furthermore, by comparing the standard reasoning steps required for the task (which can be generated by the teacher model or a strong baseline model) with the steps actually covered by the current path, missing reasoning steps are detected, obtaining reasoning completeness detection results.
[0086] Finally, the results of the logical consistency test, constraint satisfaction test, and reasoning integrity test are summarized and integrated to form a complete test result for the reasoning path, providing a structured basis for subsequent scoring. This three-dimensional automatic evaluation does not rely on external validators, but is purely based on the reasoning content itself, and has good versatility.
[0087] In some embodiments of the present invention, generating a path quality score for each inference path based on the detection results corresponding to each inference path includes: Extract the logical consistency index, constraint satisfaction index, and reasoning integrity index from the detection results corresponding to each reasoning path; Based on preset scoring weights, the logical consistency index, constraint satisfaction index, and reasoning integrity index corresponding to each reasoning path are weighted and calculated to generate a path quality score for the corresponding reasoning path. Rank the path quality scores corresponding to multiple inference paths; Based on the ranking results, the inference path with the highest path quality score is determined as the target inference path.
[0088] Understandably, the first step is to extract three quantitative indicators from the detection results of each reasoning path: logical consistency indicator (e.g., subtracting the proportion of logically contradictory steps from the total number of steps by 1), constraint satisfaction indicator (the ratio of satisfied constraints to the total number of constraints), and reasoning integrity indicator (the ratio of covered steps to the total number of required steps). Each indicator is mapped to a value between 0 and 1.
[0089] The second step involves performing a weighted calculation on the three indicators mentioned above for each reasoning path, based on preset scoring weights, to generate a corresponding path quality score. The weights can be pre-configured according to the task type; for example, mathematical proof problems might be given higher weight for logical consistency, while application problems might be given higher weight for constraint satisfaction. After the weighted calculation, each path receives a numerical score.
[0090] The third step is to rank the path quality scores of all paths. The fourth step is to determine the reasoning path with the highest quality score as the target reasoning path based on the ranking results; for example, selecting the K highest-scoring paths (K≥1) for the subsequent summarization stage. This objective and quantitative evaluation and selection mechanism ensures that only paths with satisfactory reasoning quality will influence the final answer, significantly improving the overall output quality.
[0091] In some embodiments of the present invention, the step of performing weighted calculations on the logical consistency index, constraint satisfaction index, and reasoning integrity index corresponding to each reasoning path based on preset scoring weights to generate a path quality score for the corresponding reasoning path includes: obtaining the logical consistency weight corresponding to the logical consistency index, the constraint satisfaction weight corresponding to the constraint satisfaction index, and the reasoning integrity weight corresponding to the reasoning integrity index; performing weighted calculations on the logical consistency index based on the logical consistency weights to obtain a logical consistency score; performing weighted calculations on the constraint satisfaction index based on the constraint satisfaction weights to obtain a constraint satisfaction score; performing weighted calculations on the reasoning integrity index based on the reasoning integrity weights to obtain a reasoning integrity score; and performing aggregate calculations on the logical consistency score, the constraint satisfaction score, and the reasoning integrity score to generate a corresponding path quality score.
[0092] Understandably, after obtaining the logical consistency index, constraint satisfaction index, and reasoning integrity index, the system obtains the pre-defined weights for logical consistency, constraint satisfaction, and reasoning integrity for each of these three dimensions. The sum of the three weights can be normalized to 1, or any scale can be used, as long as the relative magnitudes are maintained.
[0093] Next, the logical consistency index is weighted based on the logical consistency weight to obtain the logical consistency score; the constraint satisfaction index is weighted based on the constraint satisfaction weight to obtain the constraint satisfaction score; and the reasoning integrity index is weighted based on the reasoning integrity weight to obtain the reasoning integrity score.
[0094] Finally, these three scores are aggregated, such as by direct summation or weighted summation, to generate the final path quality score for the reasoning path. For example, if a path has a logical consistency score of 0.9, a constraint satisfaction score of 1.0, and a reasoning integrity score of 0.8, and the weights for logical consistency, constraint satisfaction, and reasoning integrity are 0.5, 0.3, and 0.2, then the final score is 0.9 × 0.5 + 1.0 × 0.3 + 0.8 × 0.2 = 0.88. This fine-grained weighting method allows the scoring system to flexibly adapt to different task scenarios with varying emphases on reasoning quality, further improving the targeting and accuracy of the selection process.
[0095] In some embodiments of the present invention, to enable the large language model to possess the parallel reasoning capabilities described in the above embodiments, the present invention also includes a supporting large language model training method. The training process first requires constructing a large-scale parallel reasoning training dataset. Using a stronger teacher model (such as the full version of DeepSeek-R1 or a reasoning model with larger parameters), the text for each training task is sampled multiple times to generate multiple initial reasoning paths with different reasoning processes. These paths, along with the standard answer, are then used to construct training samples according to a specified format. A typical training sample structure is:<think_1> All reasoning text for Path 1< / think_1><think_2> All reasoning text for path 2< / think_2> … <summary> Standard Answer< / summary> ".
[0096] During the supervised fine-tuning phase, a dynamic control token sampling strategy is employed to train the generalization triggering capability of the control tokens. Specifically, a predefined set of control tokens with a capacity of P (e.g., containing...) is used.<think_1> arrive<think_8> There are a total of 8 control tokens, but a single training sample may actually contain only 4 inference paths, P1. Each time a training batch is processed, the system randomly samples 4 tokens from the entire set of 8 control tokens and randomly matches them with the 4 inference paths in the sample. Thus, in different training iterations, the same control token...<think_i> These paths are associated with completely different reasoning content, forcing the model to learn the ability to "autonomously generate a unique reasoning path upon seeing token i," rather than simply memorizing specific paths. After large-scale training, the model not only learns how to synthesize the correct answer given multiple paths, but also learns to autonomously generate diverse reasoning paths under arbitrary control token triggering. Furthermore, since the size P of the complete set of control tokens is larger than the actual number of sample paths P1 during training, the model can be required to generate up to P paths during inference, achieving extrapolation of the number of parallel paths. This feature is crucial for flexibly scaling computational capabilities.
[0097] Through the above training method, the final large language model can perfectly execute the large language model reasoning method based on multi-path parallel reasoning described in the previous embodiment during the reasoning stage, thereby achieving performance that surpasses traditional single-path reasoning on complex tasks.
[0098] The large language model reasoning method based on multi-path parallel reasoning provided by this invention generates multiple reasoning paths in parallel, each carrying path identity information and guided by diverse control tokens. It then reuses a KV cache with a common prefix for efficient synchronous decoding. Finally, it performs a comprehensive summary after filtering based on path quality assessment. This fundamentally breaks through the "tunnel vision" bottleneck of single-path reasoning, fully preserving intermediate reasoning information and significantly improving the accuracy of solving complex tasks. Simultaneously, the batch parallel decoding and cache reuse mechanism smooths the increase in reasoning latency and maximizes computational resource utilization, making it highly suitable for applications requiring real-time performance, such as agent decision-making and real-time question answering. Experimental data shows that in the AIME 2024 math competition benchmark test, using a 1.5B parameter model with 8 parallel paths, the accuracy reaches 48.1%, far exceeding the 27.4% of single-path reasoning with equivalent models, fully demonstrating the advanced nature and practical value of this invention.
[0099] The following describes the large language model reasoning device based on multi-path parallel reasoning provided by the present invention. The large language model reasoning device based on multi-path parallel reasoning described below and the large language model reasoning method based on multi-path parallel reasoning described above can be referred to in correspondence.
[0100] like Figure 2 The diagram shown is a structural schematic of a large language model reasoning device based on multi-path parallel reasoning provided by the present invention. The large language model reasoning device based on multi-path parallel reasoning includes the following modules: Module 210 is used to obtain the task text of the target task; Parallel inference module 220 is used to input the task text into a large language model for parallel inference and generate path inference results corresponding to multiple inference paths; The generation module 230 is used to input multiple inference paths and the path inference results corresponding to each inference path into the large language model to generate model inference results corresponding to the target task.
[0101] Preferably, the large language model reasoning device based on multi-path parallel reasoning provided by the present invention is specifically used for inputting the task text into the large language model for parallel reasoning and generating path reasoning results corresponding to multiple reasoning paths, including: Based on the task text, generate multiple path input sequences; Insert corresponding path control tokens into each of the path input sequences so that the large language model generates path reasoning content with different reasoning directions based on different path control tokens; Assign corresponding path identification information to each of the path input sequences, and generate corresponding path location codes based on the path identification information; Multiple path input sequences carrying corresponding path location codes are input into the large language model for parallel decoding, and path inference results corresponding to multiple inference paths are generated based on multiple token sequences generated during the parallel decoding process.
[0102] Preferably, the large language model reasoning device based on multi-path parallel reasoning provided by the present invention is specifically used to construct an initial input sequence based on the task text; The initial input sequence is copied according to a preset number of paths to generate multiple path input sequences.
[0103] Preferably, the large language model reasoning device based on multi-path parallel reasoning provided by the present invention is specifically used to insert path control tokens with different identifier values for different path input sequences, so that path control tokens with different identifier values correspond to different reasoning modes. The reasoning mode includes at least one of the following: Formula derivation mode, logic verification mode, boundary condition analysis mode, counterexample search mode, enumeration reasoning mode, code planning mode.
[0104] Preferably, the large language model reasoning device based on multi-path parallel reasoning provided by the present invention is specifically used to obtain the basic position code corresponding to the token in each path input sequence, and to obtain the path identifier code corresponding to each path input sequence; A fusion operation is performed on the basic location code and the path identifier code to generate the path location code corresponding to each path input sequence; The path location encoding is used as the location input of the large language model to distinguish the token source in different inference paths.
[0105] Preferably, the large language model reasoning device based on multi-path parallel reasoning provided by the present invention is specifically used to identify a common prefix token sequence shared among multiple path input sequences; Perform unified attention computation on the common prefix token sequence and cache the corresponding key vector and value vector; After content forks occur in multiple path input sequences, incremental attention calculation is performed on the forked path input sequences based on the cached Key vector and Value vector to obtain the incremental attention calculation result; Based on the incremental attention calculation results, token prediction is performed synchronously on multiple path input sequences to obtain the token prediction results corresponding to each path input sequence. Update the corresponding path input sequence based on the token prediction result corresponding to each path input sequence; Based on the updated input sequences of each path, generate path inference results corresponding to multiple inference paths.
[0106] Preferably, the large language model reasoning device based on multi-path parallel reasoning provided by the present invention is specifically used to determine the path fork position corresponding to each path input sequence. The corresponding cache sharing range is determined based on the path fork location; For the common prefix token sequence before the path fork position, reuse the cached Key vector and Value vector; For the fork token sequence after the path fork position, re-perform attention calculation; Based on the reused Key vector, Value vector, and attention calculation data obtained by re-performing attention calculation, a corresponding incremental attention calculation result is generated.
[0107] Preferably, the large language model reasoning device based on multi-path parallel reasoning provided by the present invention is specifically used to arrange multiple path input sequences according to a preset path dimension to construct a corresponding batch processing input matrix; Based on the batch input matrix and the incremental attention calculation results, token probability calculation is performed synchronously on multiple path input sequences to obtain the token probability distribution corresponding to each path input sequence. Determine the corresponding target token based on the token probability distribution corresponding to each path input sequence; Each target token is appended to the end of its corresponding path input sequence to generate the token prediction result for each path input sequence.
[0108] Preferably, the large language model reasoning device based on multi-path parallel reasoning provided by the present invention is specifically used to perform logical consistency detection, constraint satisfaction detection and reasoning integrity detection on the corresponding reasoning path based on the path reasoning results corresponding to each reasoning path, and obtain the corresponding detection results. Based on the detection results corresponding to each inference path, a path quality score is generated for the corresponding inference path. The target reasoning path is determined based on the quality scores of each path. The target reasoning path and the path reasoning result corresponding to the target reasoning path are input into the large language model to generate the model reasoning result corresponding to the target task.
[0109] Preferably, the large language model reasoning device based on multi-path parallel reasoning provided by the present invention is specifically used to obtain the sequence of reasoning steps in the path reasoning results corresponding to each reasoning path; Based on the sequence of inference steps, the logical relationship between adjacent inference steps in the corresponding inference path is detected, and the logical consistency detection result of the corresponding inference path is obtained. Based on the task constraints corresponding to the target task, the constraint satisfaction status in the path reasoning results of each reasoning path is detected, and the constraint satisfaction detection results of the corresponding reasoning path are obtained. Based on the step coverage in the path reasoning results corresponding to each reasoning path, the missing reasoning steps in the corresponding reasoning path are detected, and the reasoning integrity detection result of the corresponding reasoning path is obtained. Based on the logical consistency detection result, constraint satisfaction detection result, and reasoning integrity detection result of the corresponding reasoning path, the detection result of the corresponding reasoning path is generated.
[0110] Preferably, the large language model reasoning device based on multi-path parallel reasoning provided by the present invention is specifically used to extract the logical consistency index, constraint satisfaction index and reasoning integrity index from the detection results corresponding to each reasoning path. Based on preset scoring weights, the logical consistency index, constraint satisfaction index, and reasoning integrity index corresponding to each reasoning path are weighted and calculated to generate a path quality score for the corresponding reasoning path. Rank the path quality scores corresponding to multiple inference paths; Based on the ranking results, the inference path with the highest path quality score is determined as the target inference path.
[0111] Figure 3 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 3 As shown, the electronic device may include a processor 310, a communications interface 320, a memory 330, and a communication bus 340, wherein the processor 310, communications interface 320, and memory 330 communicate with each other via the communication bus 340. The processor 310 can call logical instructions in the memory 330 to execute a large language model reasoning method based on multi-path parallel reasoning. This method includes: acquiring the task text of the target task; inputting the task text into the large language model for parallel reasoning to generate path reasoning results corresponding to multiple reasoning paths; and inputting the multiple reasoning paths and the path reasoning results corresponding to each reasoning path into the large language model to generate a model reasoning result corresponding to the target task.
[0112] Furthermore, the logical instructions in the aforementioned memory 330 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, essentially, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0113] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the large language model reasoning method based on multi-path parallel reasoning provided by the above methods. The method includes: obtaining the task text of the target task; inputting the task text into the large language model for parallel reasoning to generate path reasoning results corresponding to multiple reasoning paths; and inputting the multiple reasoning paths and the path reasoning results corresponding to each reasoning path into the large language model to generate a model reasoning result corresponding to the target task.
[0114] In another aspect, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements a large language model reasoning method based on multi-path parallel reasoning provided by the above methods. The method includes: acquiring task text of a target task; inputting the task text into a large language model for parallel reasoning to generate path reasoning results corresponding to multiple reasoning paths; and inputting the multiple reasoning paths and the path reasoning results corresponding to each reasoning path into the large language model to generate a model reasoning result corresponding to the target task.
[0115] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0116] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0117] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A large language model reasoning method based on multi-path parallel reasoning, characterized in that, include: Obtain the task text of the target task; The task text is input into a large language model for parallel reasoning, generating path reasoning results corresponding to multiple reasoning paths. Multiple inference paths and the inference results corresponding to each inference path are input into the large language model to generate model inference results corresponding to the target task.
2. The large language model reasoning method based on multi-path parallel reasoning according to claim 1, characterized in that, The step of inputting the task text into a large language model for parallel inference to generate path inference results corresponding to multiple inference paths includes: Based on the task text, generate multiple path input sequences; Insert corresponding path control tokens into each of the path input sequences so that the large language model generates path reasoning content with different reasoning directions based on different path control tokens; Assign corresponding path identification information to each of the path input sequences, and generate corresponding path location codes based on the path identification information; Multiple path input sequences carrying corresponding path location codes are input into the large language model for parallel decoding, and path inference results corresponding to multiple inference paths are generated based on multiple token sequences generated during the parallel decoding process.
3. The large language model reasoning method based on multi-path parallel reasoning according to claim 1, characterized in that, The process of generating multiple path input sequences based on the task text includes: Construct an initial input sequence based on the task text; The initial input sequence is copied according to a preset number of paths to generate multiple path input sequences.
4. The large language model reasoning method based on multi-path parallel reasoning according to claim 2, characterized in that, The step of inserting the corresponding path control token into each of the path input sequences includes: Insert path control tokens with different identifier values for different path input sequences, so that different path control tokens with different identifier values correspond to different inference modes; The reasoning mode includes at least one of the following: Formula derivation mode, logic verification mode, boundary condition analysis mode, counterexample search mode, enumeration reasoning mode, code planning mode.
5. The large language model reasoning method based on multi-path parallel reasoning according to claim 2, characterized in that, The step of assigning corresponding path identifier information to each of the path input sequences and generating corresponding path location codes based on the path identifier information includes: Obtain the basic position code corresponding to the token in each path input sequence, and obtain the path identifier code corresponding to each path input sequence; A fusion operation is performed on the basic location code and the path identifier code to generate the path location code corresponding to each path input sequence; The path location encoding is used as the location input of the large language model to distinguish the token source in different inference paths.
6. The large language model reasoning method based on multi-path parallel reasoning according to claim 2, characterized in that, The process involves inputting multiple path input sequences carrying corresponding path location codes into the large language model for parallel decoding, and generating path inference results corresponding to multiple inference paths based on multiple token sequences generated during the parallel decoding process, including: Identify a common prefix token sequence shared among multiple path input sequences; Perform unified attention computation on the common prefix token sequence and cache the corresponding key vector and value vector; After content forks occur in multiple path input sequences, incremental attention calculation is performed on the forked path input sequences based on the cached Key vector and Value vector to obtain the incremental attention calculation result; Based on the incremental attention calculation results, token prediction is performed synchronously on multiple path input sequences to obtain the token prediction results corresponding to each path input sequence. Update the corresponding path input sequence based on the token prediction result corresponding to each path input sequence; Based on the updated input sequences of each path, generate path inference results corresponding to multiple inference paths.
7. The large language model reasoning method based on multi-path parallel reasoning according to claim 6, characterized in that, After content forking occurs in multiple path input sequences, incremental attention calculation is performed on the forked path input sequences based on the cached Key vector and Value vector, yielding the incremental attention calculation result, including: Determine the path fork positions corresponding to each path input sequence; The corresponding cache sharing range is determined based on the path fork location; For the common prefix token sequence before the path fork position, reuse the cached Key vector and Value vector; For the fork token sequence after the path fork position, re-perform attention calculation; Based on the reused Key vector, Value vector, and attention calculation data obtained by re-performing attention calculation, a corresponding incremental attention calculation result is generated.
8. The large language model reasoning method based on multi-path parallel reasoning according to claim 7, characterized in that, Based on the incremental attention calculation result, token prediction is simultaneously performed on multiple path input sequences to obtain the token prediction result corresponding to each path input sequence, including: Multiple path input sequences are arranged according to a preset path dimension to construct a corresponding batch processing input matrix; Based on the batch input matrix and the incremental attention calculation results, token probability calculation is performed synchronously on multiple path input sequences to obtain the token probability distribution corresponding to each path input sequence. Determine the corresponding target token based on the token probability distribution corresponding to each path input sequence; Each target token is appended to the end of its corresponding path input sequence to generate the token prediction result for each path input sequence.
9. The large language model reasoning method based on multi-path parallel reasoning according to claim 1, characterized in that, The step of inputting multiple inference paths and the path inference results corresponding to each inference path into the large language model to generate model inference results corresponding to the target task includes: Based on the path reasoning results corresponding to each reasoning path, logical consistency detection, constraint satisfaction detection, and reasoning integrity detection are performed on the corresponding reasoning paths to obtain the corresponding detection results. Based on the detection results corresponding to each inference path, a path quality score is generated for the corresponding inference path. The target reasoning path is determined based on the quality scores of each path. The target reasoning path and the path reasoning result corresponding to the target reasoning path are input into the large language model to generate the model reasoning result corresponding to the target task.
10. A large language model reasoning device based on multi-path parallel reasoning, characterized in that, include: The acquisition module is used to acquire the task text of the target task; The parallel reasoning module is used to input the task text into a large language model for parallel reasoning and generate path reasoning results corresponding to multiple reasoning paths. The generation module is used to input multiple inference paths and the path inference results corresponding to each inference path into the large language model to generate model inference results corresponding to the target task.