Skip to content

sdc17/SwiReasoning

Repository files navigation

SwiReasoning: Switch-Thinking in Latent and Explicit for Pareto-Superior Reasoning LLMs

ArXiv Website

πŸ‘€ TL;DR

SwiReasoning is a training-free method for Pareto-superior reasoning LLMs that dynamically switches between explicit and latent thinking, with a switch count control mechanism to suppress overthinking.

swir

demo.mp4

Comparison of solving the same question with the same reasoning LLM (6s vs. 1min).

βš™οΈ Getting Started

Clone the project

git clone https://github.com/sdc17/SwiReasoning.git
cd SwiReasoning

Environment setup

conda create -n swir python=3.12
conda activate swir
pip install -r requirements.txt

πŸ’» Interactive Chat

python run_chat.py --model_name Qwen/Qwen3-8B --method swir --max_switch_count 2
  • Modify --model_name to try different reasoning LLMs.
  • Increase --max_switch_count to allow more thinking rounds (default: 2).
Commands:
  exit or q -> [Exit]
  switch <N|none> -> [Set] swir max_switch_count = N (integer >= 1) or None (disabled)
  method <swir|cot|cot_greedy> -> [Set] generation method

πŸ“ˆ Evaluation

# Evaluate without switch count control
torchrun --nproc_per_node 1 --nnodes 1 --node_rank 0 --master_port $((RANDOM + 20000)) run.py --model_name Qwen/Qwen3-1.7B \
    --dataset_name gsm8k --batch_size 512 --max_new_tokens 32768 --method swir --alpha 0.6
python merge.py --model_name Qwen/Qwen3-1.7B --dataset_name gsm8k --max_new_tokens 32768 --method swir

# Evaluate with switch count control
torchrun --nproc_per_node 1 --nnodes 1 --node_rank 0 --master_port $((RANDOM + 20000)) run.py --model_name Qwen/Qwen3-8B \
    --dataset_name gsm8k --batch_size 256 --max_new_tokens 32768 --method swir --alpha 0.5 --max_switch_count 2
python merge.py --model_name Qwen/Qwen3-8B --dataset_name gsm8k --max_new_tokens 32768 --method swir
  • Increase --nproc_per_node to enable faster evaluation on multiple GPUs.
  • Modify --model_name and --dataset_name for evaluation with different models and datasets.
  • Please check run.sh for more examples.

πŸ’¬ Acknowledgments

We thank the contributors of open-source projects Transformers, Qwen3, and Soft-Thinking.

✨ BibTeX

@misc{shi2025swireasoningswitchthinkinglatentexplicit,
      title={SwiReasoning: Switch-Thinking in Latent and Explicit for Pareto-Superior Reasoning LLMs}, 
      author={Dachuan Shi and Abedelkadir Asi and Keying Li and Xiangchi Yuan and Leyan Pan and Wenke Lee and Wen Xiao},
      year={2025},
      eprint={2510.05069},
      archivePrefix={arXiv},
      primaryClass={cs.CL},
      url={https://arxiv.org/abs/2510.05069}, 
}

About

SwiReasoning: Switch-Thinking in Latent and Explicit for Pareto-Superior Reasoning LLMs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published