大模型压力测试 evalscope

大模型压力测试 evalscope
  1. / 性能 /

快速入门

专注于大型语言模型的压力测试工具,可定制支持多种数据集格式和不同的API协议格式。

用法

命令行   evalscope perf --help usage: evalscope <command> [<args>] perf [-h] --model MODEL [--url URL] [--connect-timeout CONNECT_TIMEOUT] [--read-timeout READ_TIMEOUT] [-n NUMBER] [--parallel PARALLEL] [--rate RATE] [--log-every-n-query LOG_EVERY_N_QUERY] [--headers KEY1=VALUE1 [KEY1=VALUE1 ...]] [--wandb-api-key WANDB_API_KEY] [--name NAME] [--debug] [--tokenizer-path TOKENIZER_PATH] [--api API] [--max-prompt-length MAX_PROMPT_LENGTH] [--min-prompt-length MIN_PROMPT_LENGTH] [--prompt PROMPT] [--query-template QUERY_TEMPLATE] [--dataset DATASET] [--dataset-path DATASET_PATH] [--frequency-penalty FREQUENCY_PENALTY] [--logprobs] [--max-tokens MAX_TOKENS] [--n-choices N_CHOICES] [--seed SEED] [--stop STOP] [--stream] [--temperature TEMPERATURE] [--top-p TOP_P] options: -h, --help            show this help message and exit --model MODEL         The test model name. --url URL --connect-timeout CONNECT_TIMEOUT The network connection timeout --read-timeout READ_TIMEOUT The network read timeout -n NUMBER, --number NUMBER How many requests to be made, if None, will will send request base dataset or prompt. --parallel PARALLEL   Set number of concurrency request, default 1 --rate RATE           Number of requests per second. default None, if it set to -1,then all the requests are sent at time 0. Otherwise, we use Poisson process to synthesize the request arrival times. Mutual exclusion with parallel --log-every-n-query LOG_EVERY_N_QUERY Logging every n query. --headers KEY1=VALUE1 [KEY1=VALUE1 ...] Extra http headers accepts by key1=value1 key2=value2. The headers will be use for each query.You can use this parameter to specify http authorization and other header. --wandb-api-key WANDB_API_KEY The wandb api key, if set the metric will be saved to wandb. --name NAME           The wandb db result name and result db name, default: {model_name}_{current_time} --debug               Debug request send. --tokenizer-path TOKENIZER_PATH Specify the tokenizer weight path, used to calculate the number of input and output tokens,usually in the same directory as the model weight. --api API             Specify the service api, current support [openai|dashscope]you can define your custom parser with python, and specify the python file path, reference api_plugin_base.py, --max-prompt-length MAX_PROMPT_LENGTH Maximum input prompt length --min-prompt-length MIN_PROMPT_LENGTH Minimum input prompt length. --prompt PROMPT       Specified the request prompt, all the query will use this prompt, You can specify local file via @file_path, the prompt will be the file content. --query-template QUERY_TEMPLATE Specify the query template, should be a json string, or local file,with local file, specified with @local_file_path,will will replace model and prompt in the template. --dataset DATASET     Specify the dataset [openqa|longalpaca|line_by_line]you can define your custom dataset parser with python, and specify the python file path, reference dataset_plugin_base.py, --dataset-path DATASET_PATH Path to the dataset file, Used in conjunction with dataset. If dataset is None, each line defaults to a prompt. --frequency-penalty FREQUENCY_PENALTY The frequency_penalty value. --logprobs            The logprobs. --max-tokens MAX_TOKENS The maximum number of tokens can be generated. --n-choices N_CHOICES How may chmpletion choices to generate. --seed SEED           The random seed. --stop STOP           The stop generating tokens. --stop-token-ids      Set the stop token ids. --stream              Stream output with SSE. --temperature TEMPERATURE The sample temperature. --top-p TOP_P         Sampling top p.

结果:    Total requests: 10 Succeed requests: 10 Failed requests: 0 Average QPS: 0.256 Average latency: 3.859 Throughput(average output tokens per second): 23.317 Average time to first token: 0.007 Average input tokens per request: 21.800 Average output tokens per request: 91.100 Average time per output token: 0.04289 Average package per request: 93.100 Average package latency: 0.042 Percentile of time to first token: p50: 0.0021 p66: 0.0023 p75: 0.0025 p80: 0.0030 p90: 0.0526 p95: 0.0526 p98: 0.0526 p99: 0.0526 Percentile of request latency: p50: 3.9317 p66: 3.9828 p75: 4.0153 p80: 7.2801 p90: 7.7003 p95: 7.7003 p98: 7.7003 p99: 7.7003

请求参数

您可以在查询模板中设置请求参数,并使用(--stop、--stream、--temperature 等),参数将替换或添加到请求中。

带参数的请求

示例请求 llama3 vllm openai 兼容接口。  evalscope perf --url 'http://127.0.0.1:8000/v1/chat/completions' --parallel 128 --model 'qwen' --log-every-n-query 10 --read-timeout=120 --dataset-path './datasets/open_qa.jsonl' -n 1 --max-prompt-length 128000 --api openai --stream --stop '<|im_end|>' --dataset openqa --debug

evalscope perf '  ' --parallel 128 --model 'qwen' --log-every-n-query 10 --read-timeout=120 -n 10000 --max-prompt-length 128000 --tokenizer-path "THE_PATH_TO_TOKENIZER/Qwen1.5-32B/" --api openai --query-template '{"model": "%m", "messages": [{"role": "user","content": "%p"}], "stream": true,"skip_special_tokens": false,"stop": ["<|im_end|>"]}' --dataset openqa --dataset-path 'THE_PATH_TO_DATASETS/open_qa.jsonl'

查询模板的使用。

当需要处理更复杂的请求时,可以使用模板来简化命令行。如果模板和参数同时存在,则以参数中的值为准。查询模板示例:  evalscope perf --url 'http://127.0.0.1:8000/v1/chat/completions' --parallel 12 --model 'llama3' --log-every-n-query 10 --read-timeout=120 -n 1 --max-prompt-length 128000 --api openai --query-template '{"model": "%m", "messages": [], "stream": true, "stream_options":{"include_usage": true},"n": 3, "stop_token_ids": [128001, 128009]}' --dataset openqa --dataset-path './datasets/open_qa.jsonl'

对于消息,数据集处理器消息将替换查询模板中的消息。

启动客户端   # test openai service evalscope perf --url 'https://api.openai.com/v1/chat/completions' --parallel 1 --headers 'Authorization=Bearer YOUR_OPENAI_API_KEY' --model 'gpt-4o' --dataset-path 'THE_DATA_TO/open_qa.jsonl'  --log-every-n-query 10 --read-timeout=120  -n 100 --max-prompt-length 128000 --api openai --stream --dataset openqa    ##### open qa dataset and #### dataset address: https://huggingface.co/datasets/Hello-SimpleAI/HC3-Chinese/blob/main/open_qa.jsonl evalscope perf --url 'http://IP:PORT/v1/chat/completions' --parallel 1 --model 'qwen' --log-every-n-query 1 --read-timeout=120 -n 1000 --max-prompt-length 128000 --tokenizer-path "THE_PATH_TO_TOKENIZER/Qwen1.5-32B/" --api openai --query-template '{"model": "%m", "messages": [{"role": "user","content": "%p"}], "stream": true,"skip_special_tokens": false,"stop": ["<|im_end|>"]}' --dataset openqa --dataset-path 'THE_PATH_TO_DATASETS/open_qa.jsonl'
如何将指标记录到 wandb

--wandb-api-key'你的_wandb_api_key'--name'wandb_and_result_db 的名称'

如何调试

--debug 使用--debug选项,我们将输出请求和响应。

如何分析结果。

该工具会将测试过程中的所有数据,包括请求和响应保存到sqlite3数据库中,测试结束后可以对测试数据进行分析。  import sqlite3 import base64 import pickle import json result_db_path = 'db_name.db' con = sqlite3.connect(result_db_path) query_sql = "SELECT request, response_messages, prompt_tokens, completion_tokens \ FROM result WHERE success='True'" # how to save base64.b64encode(pickle.dumps(benchmark_data["request"])).decode("ascii"), with con: rows = con.execute(query_sql).fetchall() if len(rows) > 0: for row in rows: request = row[0] responses = row[1] request = base64.b64decode(request) request = pickle.loads(request) responses = base64.b64decode(responses) responses = pickle.loads(responses) response_content = '' for response in responses: response = json.loads(response) response_content += response['choices'][0]['delta']['content'] print('prompt: %s, tokens: %s, completion: %s, tokens: %s' % (request['messages'][0]['content'], row[2], response_content, row[3]))

支持 API

目前支持 openai、dashscope、zhipu API 请求。您可以使用 --api 指定 api。您可以使用 --query-template 自定义您的请求,您可以指定一个 json 字符串:'{"model": "%m", "messages": [{"role": "user","content": "%p"}], "stream": true,"skip_special_tokens": false,"stop": ["<|im_end|>"]}' 或使用 @to_query_template_path 指定本地文件。我们将 %m 替换为 model,%p 替换为 prompt。

如何扩展API

要扩展 api,您可以创建 的子类ApiPluginBase,使用 @register_api("name_of_api") 注释,并通过模型、提示和查询模板使用 build_request 构建请求。您可以参考 opanai_api.py parse_responses 返回 number_of_prompt_tokens 和 number_of_completion_tokens。  class ApiPluginBase: def __init__(self, model_path: str) -> None: self.model_path = model_path @abstractmethod def build_request(self, messages: List[Dict], param: QueryParameters)->Dict: """Build a api request body. Args: messages (List[Dict]): The messages generated by dataset. param (QueryParameters): The query parameters. Raises: NotImplementedError: Not implemented. Returns: Dict: The api request body. """ raise NotImplementedError @abstractmethod def parse_responses(self, responses: List, request: Any=None, **kwargs:Any) -> Tuple[int, int]: """Parser responses and return number of request and response tokens. Args: responses (List[bytes]): List of http response body, for stream output, there are multiple responses, each is bytes, for general only one. request (Any): The request body. Returns: Tuple: (Number of prompt_tokens and number of completion_tokens). """ raise NotImplementedError

支持的数据集

目前支持逐行,longalpaca 和 openqa 数据集。逐行,每行作为提示。longalpaca 将获取 item['instruction'] 作为提示。openqa 将获取 item['question'] 作为提示。

如何扩展数据集。

要扩展 api,您可以创建 的子类DatasetPluginBase,用 @register_dataset('name_of_dataset') 注释,实现 build_prompt api 返回提示。  class DatasetPluginBase: def __init__(self, query_parameters: QueryParameters): """Build data set plugin Args: dataset_path (str, optional): The input dataset path. Defaults to None. """ self.query_parameters = query_parameters def __next__(self): for item in self.build_messages(): yield item raise StopIteration def __iter__(self): return self.build_messages() @abstractmethod def build_messages(self)->Iterator[List[Dict]]: """Build the request. Raises: NotImplementedError: The request is not impletion. Yields: Iterator[List[Dict]]: Yield request messages. """ raise NotImplementedError def dataset_line_by_line(self, dataset: str)->Iterator[str]: """Get content line by line of dataset. Args: dataset (str): The dataset path. Yields: Iterator[str]: Each line of file. """ with open(dataset, 'r', encoding='utf-8') as f: for line in f: yield line def dataset_json_list(self, dataset: str)->Iterator[Dict]: """Read data from file which is list of requests. Sample: https://huggingface.co/datasets/Yukang/LongAlpaca-12k Args: dataset (str): The dataset path. Yields: Iterator[Dict]: The each request object. """ with open(dataset, 'r', encoding='utf-8') as f: content = f.read() data = json.loads(content) for item in data: yield item

Read more

60个“特征工程”计算函数(Python代码)

60个“特征工程”计算函数(Python代码)

转自:coggle数据科学 近期一些朋友询问我关于如何做特征工程的问题,有没有什么适合初学者的有效操作。 特征工程的问题往往需要具体问题具体分析,当然也有一些暴力的策略,可以在竞赛初赛前期可以带来较大提升,而很多竞赛往往依赖这些信息就可以拿到非常好的效果,剩余的则需要结合业务逻辑以及很多其他的技巧,此处我们将平时用得最多的聚合操作罗列在下方。 最近刚好看到一篇文章汇总了非常多的聚合函数,就摘录在下方,供许多初入竞赛的朋友参考。 聚合特征汇总 pandas自带的聚合函数 * 其它重要聚合函数 其它重要聚合函数&分类分别如下。 def median(x):     return np.median(x) def variation_coefficient(x):     mean = np.mean(x)     if mean != 0:         return np.std(x) / mean     else:         return np.nan def variance(x):     return

By Ne0inhk
90w,确实可以封神了!

90w,确实可以封神了!

要说24年一定最热的技术,还得是AIGC! 前段时间阿里旗下的开源项目,登上GitHub热榜! AI大热,如今ChatGPT的优异表现,必然会出现各种细分场景应用的工具软件,和大量岗位项目! 山雨欲来风满楼,强人工智能的出现,所有科技公司已经开始巨量扩招此领域的人才。算法的岗位,近三个月已经增长68%!这件事在HR届也是相当震撼的。 目前各行各业都不景气的市场,人工智能岗位却一直保持常青!甚至同属AI边缘岗都比其他岗薪资高40%! 与此同时,AI算法岗上岸也不简单,竞争激烈,好公司核心岗位不用说,谁都想去。 所以事实就是,想要上岸,门槛也逐渐变高,项目经历、实习经历都很重要,越早明白这个道理就越能提前建立起自己的优势。 但我在b站逛知识区的时候,经常看到有些同学,因为一些客观原因导致无法参加实习,这种情况下,如果你想提升背景,增加项目经历的话,可以试试这个《CV/NLP 算法工程师培养计划》。 目前已经有上千位同学通过该计划拿到offer了,最新一期学员就业薪资最高能拿到78K!年薪94w! 优势就是有BAT大厂讲师带领,手把手带做AI真实企业项目(包含CV、NLP等

By Ne0inhk
再见nohup!试试这个神器,Python Supervisor!

再见nohup!试试这个神器,Python Supervisor!

👇我的小册 45章教程:() ,原价299,限时特价2杯咖啡,满100人涨10元。 作者丨Ais137 https://juejin.cn/post/7354406980784373798 1. 概述 Supervisor 是一个 C/S 架构的进程监控与管理工具,本文主要介绍其基本用法和部分高级特性,用于解决部署持久化进程的稳定性问题。 2. 问题场景 在实际的工作中,往往会有部署持久化进程的需求,比如接口服务进程,又或者是消费者进程等。这类进程通常是作为后台进程持久化运行的。 一般的部署方法是通过 nohup cmd & 命令来部署。但是这种方式有个弊端是在某些情况下无法保证目标进程的稳定性运行,有的时候 nohup 运行的后台任务会因为未知原因中断,从而导致服务或者消费中断,进而影响项目的正常运行。 为了解决上述问题,通过引入 Supervisor 来部署持久化进程,提高系统运行的稳定性。 3. Supervisor 简介 Supervisor is a client/

By Ne0inhk
第一本给程序员看的AI Agent图书上市了!

第一本给程序员看的AI Agent图书上市了!

AI Agent火爆到什么程度? OpenAI创始人奥特曼预测,未来各行各业,每一个人都可以拥有一个AI Agent;比尔·盖茨在2023年层预言:AI Agent将彻底改变人机交互方式,并颠覆整个软件行业;吴恩达教授在AI Ascent 2024演讲中高赞:AI Agent是一个令人兴奋的趋势,所有从事AI开发的人都应该关注。而国内的各科技巨头也纷纷布局AI Agent平台,如:钉钉的AI PaaS、百度智能云千帆大模型平台等等。 Agent 是未来最重要的智能化工具。对于程序员来说,是时候将目光转向大模型的应用开发了,率先抢占AI的下一个风口AI Agent。 小异带来一本新书《大模型应用开发 动手做 AI Agent》,这本书由《GPT图解》的作者黄佳老师创作,从0到1手把手教你做AI Agent。现在下单享受5折特惠! ▼点击下方,即可5折起购书 有这样一本秘籍在手,程序员们这下放心了吧,让我们先来揭开 Agent 的神秘面纱。 AI Agent 面面观

By Ne0inhk