DEER 项目最佳实践教程
1. 项目介绍
DEER(Dynamic Early Exit in Reasoning Models)是一个为大型推理语言模型设计的动态早期退出方法。此方法通过在潜在的推理转换点监控模型行为,当模型对一个尝试性答案表现出高度自信时,动态终止后续推理链的生成。根据官方描述,该方法在11个系列和大小各异的前沿推理LLM模型上均表现出一致性效果,平均减少了19.1% - 80.1%的CoT序列长度,同时提高了0.3% - 5.0%的准确性。
2. 项目快速启动
安装
首先,需要克隆项目仓库:
git clone https://github.com/iie-ycx/DEER.git
cd DEER
接着,安装项目所需的依赖:
pip install -r requirements.txt
运行 DEER
对于基于vLLM框架的模型,推荐以下命令进行结果复现:
CUDA_VISIBLE_DEVICES=1 python ../vllm-deer.py \
--model_name_or_path "./DeepSeek-R1-Distill-Qwen-14B" \
--dataset_dir "./data/" \
--output_path "./outputs" \
--dataset "math" \
--threshold 0.95 \
--max_generated_tokens 16000 \
--think_ratio 0.6 \
--batch_size 2000 \
--policy avg1 \
--dtype bfloat16 \
--gpu-memory-utilization 0.9
对于Qwen3系列模型,由于它们在置信度预测上往往过于自信,官方进行了一些实现上的调整。以下是对Qwen3模型的运行命令:
CUDA_VISIBLE_DEVICES=1 python ../vllm-deer-qwen3.py \
--model_name_or_path "./Qwen3-4B" \
--dataset_dir "./data/" \
--output_path "./outputs" \
--dataset "math" \
--threshold 0.95 \
--max_generated_tokens 16000 \
--think_ratio 0.8 \
--batch_size 2000 \
--dtype bfloat16 \
--policy avg2 \
--gpu-memory-utilization 0.9
如果使用HuggingFace Transformers而不使用vLLM,可以运行以下脚本:
bash ./bashes/bash-vanilla-deer.sh
3. 应用案例和最佳实践
评估
DEER支持在7个推理基准上进行评估。评估基于来自LIMO项目的代码实现。以下是一个评估示例:
python ../check.py \
--model_name_or_path "./DeepSeek-R1-Distill-Qwen-14B" \
--data_name "math" \
--generation_path "your_output.jsonl"
或者运行脚本:
bash ./bashes/bash-check-correct.sh
引用
如果您的研
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考