This is the official repository for DynTS.


The following steps outline how to train the importance predictor using deepseek-ai/DeepSeek-R1-Distill-Llama-8B on MATH500, and subsequently run inference on AIME24 using DynTS.
Datasets should be downloaded manually and put into datas/dataset/${DATASET_NAME}. ${DATASET_NAME} must be one of aime24, aime25, amc23, gaokao2023en, gpqa_d, math500.
# 1. Install python environment
conda env create -f environment
conda activate dynts
# 2. Generate training data for the importance predictor
bash ./recipes/sft_data_prepare/compute_sft_is.sh
# 3. Train the importance predictor
bash ./recipes/sft/sft_deepseek_llama.sh
# 4. Run inference on AIME24 using DynTS
bash ./recipes/inference/dynts_deepseek_llama.sh
Evaluation results for AIME24 will be saved in outputs/inference/dynts-llama.
To fine-tune LRMs (Large Reasoning Models) with an importance predictor, first run the data preparation script. This script utilizes vLLM to generate importance scores for each token on a specific dataset.
bash ./recipes/sft_data_prepare/compute_sft_is.sh
math500 as the training dataset, but this can be adapted to other datasets.datas/train/${MODEL_NAME}_{$DATA_NAME}_is.jsonl.After generating the importance scores, use the following scripts to fine-tune the models:
bash recipes/sft/sft_deepseek_{llama|qwen}.sh
The checkpoint of the fine-tuned model (integrated with the importance predictor) will be located at outputs/models/${MODEL_NAME}_ip/checkpoints/global_step_405. This path can be directly passed to the --model_name_and_path argument in the inference scripts.
Inference scripts are located in recipes/inference. For example, to run inference with DeepSeek-R1-Llama-8B using DynTS:
bash ./recipes/inference/dynts_deepseek_llama.sh
You can run any of the following benchmarks by setting the DATA_NAME variable in the script:
aime24aime25amc23gaokao2023engpqa_dmath500We currently implement eight KV cache pruning strategies:
After execution, the results will be saved in SAVE_DIR with the following structure:
metrics.jsonl: A comprehensive summary of metrics, including PASS@5, MAJOR@5, PASS@1, Throughput, Latency, and Peak KV Cache Usage.files/: Contains the model's raw answers for each question (useful for debugging).statistics/: Contains detailed metrics for each decoding step.Scripts for reproducing our ablation study results can be found in recipes/ablation:
budget_{MODEL}: Analyzes the influence of the KV cache budget.local_ratio_{MODEL}: Analyzes the influence of the local window size and ratio.wolocal_{MODEL}: Runs DynTS without the local window.select_{MODEL}: Runs DynTS using diverse token selection strategies (e.g., w/o question tokens, w/o thinking tokens, random thinking tokens, bottom thinking tokens).1 commits
Python
94.1%
Shell
4.4%
ANTLR
1.5%
This is the official repository for DynTS.


The following steps outline how to train the importance predictor using deepseek-ai/DeepSeek-R1-Distill-Llama-8B on MATH500, and subsequently run inference on AIME24 using DynTS.
Datasets should be downloaded manually and put into datas/dataset/${DATASET_NAME}. ${DATASET_NAME} must be one of aime24, aime25, amc23, gaokao2023en, gpqa_d, math500.
# 1. Install python environment
conda env create -f environment
conda activate dynts
# 2. Generate training data for the importance predictor
bash ./recipes/sft_data_prepare/compute_sft_is.sh
# 3. Train the importance predictor
bash ./recipes/sft/sft_deepseek_llama.sh
# 4. Run inference on AIME24 using DynTS
bash ./recipes/inference/dynts_deepseek_llama.sh
Evaluation results for AIME24 will be saved in outputs/inference/dynts-llama.
To fine-tune LRMs (Large Reasoning Models) with an importance predictor, first run the data preparation script. This script utilizes vLLM to generate importance scores for each token on a specific dataset.
bash ./recipes/sft_data_prepare/compute_sft_is.sh
math500 as the training dataset, but this can be adapted to other datasets.datas/train/${MODEL_NAME}_{$DATA_NAME}_is.jsonl.After generating the importance scores, use the following scripts to fine-tune the models:
bash recipes/sft/sft_deepseek_{llama|qwen}.sh
The checkpoint of the fine-tuned model (integrated with the importance predictor) will be located at outputs/models/${MODEL_NAME}_ip/checkpoints/global_step_405. This path can be directly passed to the --model_name_and_path argument in the inference scripts.
Inference scripts are located in recipes/inference. For example, to run inference with DeepSeek-R1-Llama-8B using DynTS:
bash ./recipes/inference/dynts_deepseek_llama.sh
You can run any of the following benchmarks by setting the DATA_NAME variable in the script:
aime24aime25amc23gaokao2023engpqa_dmath500We currently implement eight KV cache pruning strategies:
After execution, the results will be saved in SAVE_DIR with the following structure:
metrics.jsonl: A comprehensive summary of metrics, including PASS@5, MAJOR@5, PASS@1, Throughput, Latency, and Peak KV Cache Usage.files/: Contains the model's raw answers for each question (useful for debugging).statistics/: Contains detailed metrics for each decoding step.Scripts for reproducing our ablation study results can be found in recipes/ablation:
budget_{MODEL}: Analyzes the influence of the KV cache budget.local_ratio_{MODEL}: Analyzes the influence of the local window size and ratio.wolocal_{MODEL}: Runs DynTS without the local window.select_{MODEL}: Runs DynTS using diverse token selection strategies (e.g., w/o question tokens, w/o thinking tokens, random thinking tokens, bottom thinking tokens).1 commits
Python
94.1%
Shell
4.4%
ANTLR
1.5%