🔗9.3.6 Q*

During the autoregressive generation process, LLMs can have hallucinations and inconsistent statements when performing multi-step reasoning. Researchers from Skywork AI and Nanyang Technological University proposed the Q* framework, a general and flexible framework that improves the multi-step reasoning ability of LLMs by treating multi-step reasoning as a heuristic search problem.
By leveraging deliberate planning, Q* framework formalizes the multi-step reasoning process of LLMs as a Markov Decision Process (MDP) and uses the A* search algorithm and Q-value modeling to guide the model in selecting the most promising reasoning steps, thereby enhancing multi-step reasoning performance.
Extensive experiments on GSM8K, MATH, and MBPP demonstrate the effectiveness of this approach, helping to improve the reasoning abilities of existing open-source large language models.

Background

Problems Faced by LLMs in Reasoning:
  • Errors and Inconsistency: Although LLMs perform well in many natural language tasks, during the autoregressive generation process in multi-step reasoning tasks, as reasoning steps increase, errors, hallucinations, and inconsistent statements easily occur.
  • Lack of Deep Thinking: Current improvement methods mainly focus on enhancing LLMs’ “System 1” ability (i.e., fast, instinctive, but not very accurate thinking mode). Examples include:
    • Using extensive domain knowledge to construct complex prompts
    • Finetuning LLMs with large task-specific datasets
    • Training reward models to rank candidate responses
  • Limited Method Generalization: However, solving complex reasoning problems requires more advanced “System 2” thinking (i.e., deeper, deliberate, and logical reasoning steps), where LLMs fall short. Prior attempts to enhance “System 2” ability include asic tree search algorithms (BFS, DFS), MCTS (See Section 9.3.4 and Section 9.3.5), A*, etc. However, the utility functions these methods use typically require carefully designed domain knowledge for each specific task, making it difficult to generalize to new scenarios. Moreover, applying MCTS for deliberative planning in problems with many reasoning steps requires massive amounts of simulations.

Preliminary

📌
Representing LLM multi-step reasoning as a Markov Decision Process (MDP, see Section 3.2.2 Markov Process):
  • Given a question as input, the answer generation process of LLMs can be decomposed into multiple reasoning steps. The final answer sequence can be regarded as the concatenation of reasoning steps . Each step can be an entire line of output from the LLM or a fixed number of tokens. Thus, the multi-step reasoning process of LLMs can be formalized as an MDP process , where:
    • State : represents the concatenation of the input question and the reasoning trajectory generated up to time step , i.e.
    • Action : represents the next reasoning step generated by the LLM given the current state .
    • State transition : deterministic transition, i.e. is directly achieved by concatenating .
    • Reward function : usually based on the final outcome:
    • Discount factor .
  • The policy of an LLM, , can be expressed as:
  • Given the MDP and the LLM’s policy, we can define the state-action value function (Q-function) and the optimal strategy’s corresponding Q-function:
📌

A* Search Algorithm:

The A* algorithm is a commonly used heuristic search algorithm for pathfinding and graph traversal. It is used to find the shortest path from a source to a target . The A* algorithm calculates the priority of each node using the following function:
  • : the overall priority of a node. When selecting the next node to expand, the algorithm always chooses the node with the highest priority (smallest value).
  • : the accumulated cost from the start node to the current node.
  • : the estimated cost from the current node to the target node, also known as the heuristic function of A*.
For grid-based graphs, the following heuristic functions can be used:
  • If movement is only allowed up, down, left, and right, use Manhattan distance.
  • If movement is allowed in eight directions, use the Diagonal distance.
  • If movement is allowed in any direction, use Euclidean distance.
The A* algorithm uses two sets to represent nodes that are waiting to be expanded and nodes that have already been expanded: open_set and close_set. The algorithm flow is as follows:

Method - Q*: A General, Versatile, and Agile Deliberation Framework for LLMs

This study treats the search for the most appropriate reasoning sequence for the problem as a heuristic search process. The utility function for each state in the search is defined as:
where represents the aggregated utility from the initial state to the current state:
Each state uses the process reward function for the reasoning step, and then the aggregation function combines them in different methods. For example, indicates taking the reward of only the final state as . The process reward function can be obtained from a PRM trained on preference data, or it can be a rule-based model, ground truth, or the logits of the model’s reasoning steps (reflecting the model’s confidence).
The heuristic term in this paper directly uses the optimal Q-value function as the heuristic function. At the same time, since the action space of reasoning steps is too large, this paper directly restricts the action space to the top-K candidate steps returned by the LLM. Therefore, the final utility function is:

Estimation of the Optimal Q-value:

This study learns a proxy Q-value model to approximate the optimal Q-function. Specifically, it is learned from a dataset of LLM-sampled trajectories:
The objective is:
where:
  • is a trajectory sampled from the LLM (containing multiple actions, and means one action in this trajectory)
  • is the partial reasoning trace
  • is the label for the state-action value .
This paper proposes three methods to construct these labels:
  • Offline RL Method: Given an offline dataset , Fitted Q-iteration algorithm is used to iteratively learn the Q-value model. For each iteration , the label is constructed as follows:
    • After obtaining the labels for the current iteration, it can optimize to get the Q-value function of this iteration, and then proceed to obtain the labels for the next iteration. This process is repeated until convergence or until reaching the specified number of iterations.
  • Learning from rollout: Use the current LLM to perform random rollout or MCTS rollout, collecting a large number of rollout trajectories to form a trajectory pool . Then, from the subsequent trajectories, compute the label for the current state using the trajectory with the maximum cumulative reward:
  • Learning from stronger LLMs: Directly use trajectories generated by a stronger model, such as GPT-4 to compute labels:
    • where
(a): the deliberation process of Q*. Each state is associated with an value which is the weighted sum of the aggregated utility and the heuristic value. (b-d): estimating optimal Q-value with fitted-Q-iteration, rollout, and completion with stronger LLMs.
(a): the deliberation process of Q*. Each state is associated with an value which is the weighted sum of the aggregated utility and the heuristic value. (b-d): estimating optimal Q-value with fitted-Q-iteration, rollout, and completion with stronger LLMs.

Deliberative Planning with A*

Once the proxy Q-value model is obtained, it can be used to calculate the value of each state, and then A* search is applied to perform optimal priority search.
Specifically, this study maintains a set to store unexplored state candidates, denoted as the unvisited set, which initially contains only the input problem . There is also a visited set to record the states that have already been explored. At each step, the algorithm selects the state with the largest value from the unvisited set, and then uses the LLM to generate top-K reasoning steps to expand this state into new candidates. This process is repeated until a terminal state is reached (i.e., a complete trajectory is obtained). The answer part of the terminal state is then returned as the final result.
notion image

Experiment

🔬

Experimental Setup

  • Datasets: Evaluations are conducted on three datasets: GSM8K, MATH, and MBPP (entry-level Python Programming dataset).
  • Implementation details:
    • Q-value estimation: The experiments in this paper show that Learning from rollout gives the best results for estimating Q-values.
    • Utility aggregation (Agg):
      • For GSM8K, a process reward model (PRM) trained on PRM800K is used to model , with min as the Agg function.
      • For MATH, to ensure fairness, all states in each trajectory are set to , because PRM800K contains samples constructed from the MATH test set, which poses a potential data leakage risk.
      • For MBPP, Agg is set to [-1].
    • A* planning:
      • For GSM8K and MATH, one line of reasoning is treated as one reasoning step.
      • For MBPP, a 24-token code snippet is treated as one reasoning step.

Experimental Results

  • GSM8K dataset: Using Llama-2-7b as the base model, combined with the Process Reward Model (PRM) and the Q-value model (QVM), the Q* method achieved an accuracy of 80.8%, outperforming other methods based on the same LLM, and even surpassing the closed-source ChatGPT-turbo.
    • notion image
  • MATH dataset: Using Llama-2-7b fine-tuned on synthetic data and DeepSeek-Math-7b as base models, the Q* method achieved further improvements compared to the Best-of-N method. With DeepSeek-Math-7b, the enhanced performance even surpassed closed-source models such as Gemini Ultra, reaching an accuracy of 55.4%.
    • notion image
  • MBPP dataset: Using CodeQwen1.5-7b-Chat as the base model, the Q* method performed excellently in code generation, achieving an accuracy of 77.0%, outperforming the Best-of-N method.
    • notion image

Conclusion

Q* is a general, versatile, and agile framework designed to improve the multi-step reasoning ability of LLMs through careful and deliberate planning.
  • Q* formalizes multi-step reasoning as an MDP and uses A* search with a Q-value model, which effectively guides LLMs in selecting the most promising next step during multi-step reasoning tasks. This avoids the need to fine-tune the LLM for each task, reducing computational overhead and the risk of performance reduction.
  • The framework is general, flexible, and easy to implement, relying only on value models trained on real data. Moreover, it considers only single-step reasoning at each stage, making it more efficient than traditional approaches. Experimental results demonstrate the superiority of Q* in mathematical reasoning and code generation tasks.
 
Prev
CivitAI’s Payment Issue
Next
Awesome-AI-Tutorials
Loading...
Article List
LLM Learning Roadmap
✨ Awesome-Anything
🖼️ Digital Image Processing
🍃 LLM Components
🌱 LLM Pre-training
☘️ LLM Post-Training
🍀 LLM Popular Models
🪴 LLM Applications
🌿 LLM Optimization
🌾 LLM Compression
🌵 LLM Hands-on Practice
🌴 LLM Must-read Papers
🌳 LLM Q&A
🐝 VLM Image Encoders
📝 MISC.