TEACH, a method that tutors LLMs to solve competitive programming
by combining critical hints with structured Chains of Thought (CoT).
- Python >=3.10
- Java: JDK1.8
Create a new Python environment using conda:
conda create -n teach python=3.10
conda activate teach
Use pip to install the required Python packages:
pip install -r requirements.txt
Install the project as a package:
pip install -e .
If you want run the expriments with Java languages, you need to download Java packages as follow.
animal-sniffer-annotations-1.17.jar
checker-qual-2.5.2.jar
commons-io-2.11.0.jar
commons-lang3-3.12.0.jar
error_prone_annotations-2.2.0.jar
failureaccess-1.0.1.jar
fastjson2-2.0.45.jar
fastjson-1.2.83.jar
gjf.jar
google-java-format-1.7.jar
guava-27.0.1-jre.jar
j2objc-annotations-1.1.jar
javac-shaded-9+181-r4173-1.jar
jsr305-3.0.2.jar
kotlin-stdlib-1.6.20.jar
lc-sdk-v0.0.1.jar
listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
okhttp-4.12.0.jar
okhttp-urlconnection-4.12.0.jar
okio-jvm-3.6.0.jar
searchableOptions.jar
All experiments were conducted on machines equipped with an Intel(R) Xeon(R) 2.10GHz CPU and a 24GB NVIDIA RTX 4090 GPU, running on the Ubuntu 20.04 platform.
You could use a server or computer with a 4090 GPU to run this inference.
- Install the required packages:
conda activate teach
cd src/ft
pip install -r requirements.txt
- Start the sever with the fine-tuned model:
cd src/ft/script
sh api.sh
- Run the following command to generate hints for leetcode questions:
cd src/ft/hint/infer
python batch_gen_leetcode.py
If you want to generate code and submit to leetcode, get the leetcode account cookie and openai api key, then you can run the following command:
- run the bash script:
cd src/infer/script
sh run_apps.sh
or 2. run the python:
python src/infer/analysis/ht_chainleetcode_submit_sh.py \
--reuse \
--cookie-user 'leetcode-cookie' \
--qtype 'easy' \
--difficulty 1 \
--top-p 1.0 \
--temperature 1.0 \
--left 3000 \
--right 3005 \
--syn-type 'hint_ft_each_chain'
--repeat 1 \
--time 1 \
--lang 'java' \
--model 'gpt-3.5-turbo-1106' \
--dir-path 'data/leetcode/full_info/hint_3000-3235_r20/' \
--api-key 'sk-xxx'
Arguments:
reuse
: whether to reuse the generated codecookie-user
: leetcode cookieqtype
: question type, [easy, medium, hard, or all]difficulty
: question difficulty, a list , could be the subset of [1, 2, 3]top-p
: top-p valuetemperature
: temperature valueleft
: left index of the question, the minimum value is 3000right
: right index of the question, the maximum value is 3235syn-type
: hint type, [origin, template, hint_ft_each, hint_ft_each_chain]repeat
: repeat timestime
: timelang
: language, [python, java]model
: modeldir-path
: directory path of the question and hintsapi-key
: openai api key
Construct the instruction data for the fine-tuning model.
The data is stored in the data/leetcode
directory. The data is constructed as follows:
python src/ft/hint/data_construct/leetcode_ft.py
CUDA_VISIBLE_DEVICES=0 llamafactory-cli train examples/lora_single_gpu/llama3_lora_sft.yaml
The model saves the checkpoints in the src/ft/saves
directory.