Views
No views yet
DeBERTaV3-base that predicts the optimal thinking mode for an LLM to use when answering a given question. The goal is to dynamically balance reasoning accuracy and computational efficiency.1git clone https://github.com/DL-Levi/DynamicMind
2cd DynamicMind
3pip install transformers==4.47.11import os
2import yaml
3from transformers import pipeline
4from modes.mode import ThinkingMode
5
6def load_config(file_path):
7 if not os.path.exists(file_path):
8 raise FileNotFoundError(f"config file '{file_path}' not found")
9 with open(file_path, 'r') as file:
10 return yaml.safe_load(file)
11
12def DynamicMind(prompt, llm_thinker, mind_router):
13 # Use the Mind Router to select the optimal thinking mode
14 router_pipeline = pipeline("text-classification", model=mind_router, trust_remote_code=True)(prompt)
15 thinking_mode = router_pipeline['label']
16 print(f"Mind Router selected: {thinking_mode} Mode")
17 mode_config = load_config(f"../config/{thinking_mode}_mode_config.yaml")
18
19 system_prompt = mode_config['mode']["system_prompt"]
20 format_prompt = mode_config['mode']['format_prompt'].format(answer_format='42')
21
22 # Generate a response with the LLM Thinker
23 messages = [
24 {"role": "system", "content": system_prompt},
25 {"role": "user", "content": prompt + format_prompt},
26 ]
27 thinker_pipeline = pipeline("text-generation", model=llm_thinker, **mode_config['generation'])(messages)
28 response = thinker_pipeline[0]['generated_text'][-1]['content']
29
30 return response
31
32# --- Example Usage ---
33prompt = "Please answer the following question: It is approximately 1955 kilometers from San Diego, California to New York City, New York. If Bernice drove 325 kilometers for 4 days, how many kilometers will she still need to drive?"
34llm_thinker = "meta-llama/Meta-Llama-3.1-8B-Instruct"
35mind_router = "0xWei/MR-Llama-3.1-8B-Instruct"
36
37response = DynamicMind(prompt, llm_thinker, mind_router)
38print(response)1@article{li2025dynamicmind,
2 title={DynamicMind: A Tri-Mode Thinking System for Large Language Models},
3 author={Li, Wei and Wei, Yanbin and Huang, Qiushi and Yan, Jiangyue and Chen, Yang and Kwok, James T and Zhang, Yu},
4 journal={arXiv preprint arXiv:2506.05936},
5 year={2025}
6}