Figure: CodeSteer on guiding LLM code/text generation to integrate symbolic computing. At each interaction with TaskLLM, it reviews current and previous answers, then provides guidance for the next round.
Inspirations
s
Figure: The cases that GPT-4o makes simple mistakes by direct textual reasoning but can reliably solve the problem with prompted to use code.
Performance
We compare GPT-4o + CodeSteer with OpenAI o1 and DeepSeek R1 on SymBench, with 28 seen tasks and 9 unseen tasks. GPT-4o + CodeSteer surpasses o1 (82.7), R1 (76.8), and o1-preview (74.8), highlighting the importance of integrating symbolic computing into LLMs.
s
The cost of tokens and runtimes for each method are as follows. GPT-4o + CodeSteer costs less tokens and runtimes than o1 and R1.
s
Environment_Setup
The fine-tuning and inference of CodeSteerLLM are based on Llama-factory with some modules modified by us.
Add this .env file to your .gitignore to prevent accidentally committing it:
echo ".env" >> .gitignore
Train_and_Test_Models
Create_test_samples
The synthesized test samples for 37 tasks of SymBench are in dataset_gather dictionary. You can also synthezise the samples by yourself with tunable complexities with scripts in create_dataset.
Run inference without GPU, test close LLM as CodeSteerLLM
We can directly use unfinetuned model like GPT-4o as CodeSteerLLM, in this case directly run
python benchmark_test_baseline.py
Run inference with GPU, test finetuned CodeSteerLLM
We can infer Llama-3.1-8B with own GPUs (default setting is in infer_CodeSteer.sh using 4*H100 of Harvard Cluster, please modify freely with your own cluster settings). You can also download the Model Weights in your local and change the path in llama3_8B_CodeSteer.yaml.
bash
1bash infer_CodeSteer.sh
2# default config file is ./llama3_8B_CodeSteer.yaml using the model uploaded on Huggingface.
Finetuning CodeSteerLLM with synthesized data
Both our synthesized datasets of SFT and DPO finetuning are in Finetune Datasets.
We use Llama-factory and DeepSpeed for fintuning processes. First install Llama-factory with:
git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git
cd LLaMA-Factory
pip install -e ".[torch,metrics]"
cd ..
Then we run the code with (default setting is in train_llama3-8B-CodeSteer.sh using 4*H100 of Harvard Cluster, please modify freely with your own cluster settings):
bash train_llama3-8B-CodeSteer.sh
Assistance
We appreciate all feedback! Feel free to raise an issue for bugs, questions, or suggestions. Contacting Yongchao Chen and Chuchu Fan for any questions and discussion.
Citation
md
1@misc{chen2025codesteersymbolicaugmentedlanguagemodels,
2 title={CodeSteer: Symbolic-Augmented Language Models via Code/Text Guidance},
3 author={Yongchao Chen and Yilun Hao and Yueying Liu and Yang Zhang and Chuchu Fan},
4 year={2025},
5 eprint={2502.04350},
6 archivePrefix={arXiv},
7 primaryClass={cs.CL},
8 url={https://arxiv.org/abs/2502.04350},
9}
md
1@article{chen2024steering,
2 title={Steering Large Language Models between Code Execution and Textual Reasoning},
3 author={Chen, Yongchao and Jhamtani, Harsh and Sharma, Srinagesh and Fan, Chuchu and Wang, Chi},
4 journal={arXiv preprint arXiv:2410.03524},
5 year={2024}
6}