AI开发平台MODELARTS-推理精度测试:使用Lm-eval精度测评工具
时间:2025-04-09 09:16:27
使用Lm-eval精度测评工具
使用lm-eval工具暂不支持qwen-7b、qwen-14b、qwen-72b、chatglm2-6b、chatglm3-6b模型。
- 精度评测可以在原先conda环境,进入到一个固定目录下,执行如下命令。
rm -rf lm-evaluation-harness/ git clone https://github.com/EleutherAI/lm-evaluation-harness.git cd lm-evaluation-harness git checkout 383bbd54bc621086e05aa1b030d8d4d5635b25e6 pip install -e . pip install aiohttp==3.9.3
- 执行如下精度测试命令,可以根据参数说明修改参数。
lm_eval --model vllm --model_args pretrained=${vllm_path},dtype=auto,tensor_parallel_size=${tensor_parallel_size},gpu_memory_utilization=${gpu_memory_utilization},add_bos_token=True,max_model_len=${max_model_len},quantization=${quantization},distributed_executor_backend='ray' \ --tasks ${task} --batch_size ${batch_size} --log_samples --cache_requests true --trust_remote_code --output_path ${output_path}
参数说明:- model_args:标志向模型构造函数提供额外参数,比如指定运行模型的数据类型;
- vllm_path是模型权重路径;
- max_model_len 是最大模型长度,默认设置为4096;
- gpu_memory_utilization是gpu利用率,如果模型出现oom报错,调小参数;
- tensor_parallel_size是使用的卡数;
- quantization是量化参数,使用非量化权重,去掉quantization参数;如果使用awq、smoothquant或者gptq加载的量化权重,根据量化方式选择对应参数,可选awq,smoothquant,gptq。
- distributed_executor_backend是开启多进程服务方式,选择ray开启。
- model:模型启动模式,可选vllm,openai或hf,hf代表huggingface。
- tasks:评测数据集任务,比如openllm。
- batch_size:输入的batch_size大小,不影响精度,只影响得到结果速度,默认使用auto,代表自动选择batch大小。
- output_path:结果保存路径。
使用lm-eval,比如加载非量化或者awq量化,llama3.2-1b模型的权重,参考命令:lm_eval --model vllm --model_args pretrained="/data/nfs/benchmark/tokenizer/Llama-3.2-1B-Instruct/",dtype=auto,tensor_parallel_size=1,gpu_memory_utilization=0.7,add_bos_token=True,max_model_len=4096,distributed_executor_backend='ray' \ --tasks openllm --batch_size auto --log_samples --cache_requests true --trust_remote_code --output_path ./
使用lm-eval,比如smoothquant量化,llama3.1-70b模型的权重,参考命令:lm_eval --model vllm --model_args pretrained="/data/nfs/benchmark/tokenizer_w8a8/llama3.1-70b/",dtype=auto,tensor_parallel_size=4,gpu_memory_utilization=0.7,add_bos_token=True,max_model_len=4096,quantization="smoothquant",distributed_executor_backend='ray' \ --tasks openllm --batch_size auto --log_samples --cache_requests true --trust_remote_code --output_path ./
- model_args:标志向模型构造函数提供额外参数,比如指定运行模型的数据类型;
support.huaweicloud.com/bestpractice-modelarts/modelarts_llm_infer_91108.html