Train Policy Models for SciGLM
mainSciGLM-6B, use the default repository from SciGLM.repository·main·Indexed 20 days ago
https://github.com/thudm/rest-mctsA reinforced self-training approach that integrates process reward guidance with MCTS* tree search to collect high-quality reasoning traces and per-step values. It supports policy and reward model training without manual per-step annotations, with implementations for Llama3-8B-Instruct, Mistral-7B, and SciGLM-6B. The framework includes tools for MCTS* search, benchmark evaluation, and self-training via CoT and DPO datasets.
SciGLM-6B, use the default repository from SciGLM.Llama3-8B-Instruct and Mistral-7B: MetaMATH, use the default repository from MAmmoTH.ReST-MCTS requires different environments depending on whether you are running Mistral/Llama models or SciGLM models due to transformers dependency variations. Use Miniconda to manage these environments.
Install the required packages using the provided requirements files.
# For running Mistral (or Llama)
pip install -r requirements_mistral.txt
# For running SciGLM
pip install -r requirements_sciglm.txtPolicy data is used for training and comparing policy models across different iterations and self-training methods.
Data Characteristics:
Datasets are available on Hugging Face for the following backbones:
Llama3-8b-InstructMistral: MetaMATH-7bSciGLM-6BEach backbone has data for the 1st and 2nd iterations, categorized by self-training method: ReST-EM (CoT), Self-Rewarding (DPO), and ReST-MCTS.
Process Reward Model (PRM) data, containing both positive and negative samples, is available for training the 1st reward model (specifically for Llama3-8b-Instruct).
Dataset Link: ReST-MCTS-Llama3-8b-Instruct-PRM-1st
To run MCTS* search, you must implement a policy model and a process reward model (value model). You can configure these by editing models/model.py with the following keys:
INFERENCE_MODEL_DIR: Local path to the policy model (e.g., Llama3-8B-Instruct, Mistral-7B: MetaMATH, or SciGLM-6B).VALUE_BASE_MODEL_DIR: Local path to the value model backbone.VALUE_MODEL_STATE_DICT: The state dict for the value model.LOCAL_INFERENCE_IDX: The index corresponding to your implemented policy model.LOCAL_VALUE_IDX: The index corresponding to your implemented value model.Supported implementations in models/model.py include llama, glm, and mistral for policies, and glm and mistral for value models.
You can use the MCTS_Task interface in MCTS/task.py to run a search for a specific question. The lang parameter specifies the language (e.g., 'en').
from MCTS.task import *
question = "Calculate the sum of the first 10 prime numbers."
task = MCTS_Task(question, 'llama', 'local', lang='en')
output = task.run()
print(output['solution'])Before running MCTS* search for evaluation or generation, ensure your target question dataset is a JSON file where each item follows this format:
content (Required): The question text.answer (Optional): The ground truth answer, used for evaluation.{
"content": "Calculate the sum of the first 10 prime numbers.",
"answer": "129"
}The MCTS* algorithm is controlled via several key parameters that govern search behavior, exploration/exploitation balance, and simulation strategies. Use these arguments to tune the tree search process:
temperature: Search temperature; determines the degrees of freedom for generating responses.time_limit: The upper limit of the search time in milliseconds (ms).iteration_limit: The maximum number of search rounds allowed for exploration.use_case_prompt: Boolean flag to enable sample output prompt assisted generation.use_reflection: Boolean flag to enable the reflection mechanism.exploration_constant: The constant used in the UCT (Upper Confidence Bound applied to Trees) formula to balance exploration and exploitation.branch: The number of branches to create during node expansion.inf: The base value assigned to an unvisited node.alpha: The value update weight used for Monte Carlo simulation.end_gate: The lowest value threshold used to determine when the search should end.roll_policy: The strategy for Monte Carlo simulation. Supported values are random or greedy.roll_forward_steps: The number of forward steps to take during the simulation process.roll_branch: The number of branches to sample during simulation.low: The lower bound of the node value.high: The upper bound of the node value.visualize: Boolean flag to determine whether search results are rendered in a tree diagram.To evaluate MCTS* performance on benchmarks, use the evaluate.py script with --mode "mcts".
Key arguments:
--task_name: The name of the benchmark task.--file: The specific file or subset to evaluate.--propose_method: The method used for proposing solutions (e.g., gpt).--value_method: The method used for value estimation (e.g., local).--mode: Set to mcts for MCTS* evaluation.--evaluate: The benchmark name.--iteration_limit: Maximum iterations.--use_reflection: Reflection strategy (e.g., simple).--branch: Branching factor for search.python evaluate.py \
--task_name "scibench" \
--file "thermo" \
--propose_method "gpt" \
--value_method "local" \
--mode "mcts" \
--evaluate "scibench" \
--iteration_limit 50 \
--use_reflection "simple" \
--branch 3The self-rewarding baseline is implemented in the following script:
./self_train/self_train_dpo.pyfigures/plot_math_self_training.py.figures/plot_math_self_training.py