mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2026-04-23 00:17:25 +08:00
[benchmark] update tools (#7211)
This commit is contained in:
@@ -269,6 +269,15 @@ async def async_request_eb_openai_chat_completions(
|
|||||||
if request_func_input.response_format:
|
if request_func_input.response_format:
|
||||||
payload["response_format"] = request_func_input.response_format
|
payload["response_format"] = request_func_input.response_format
|
||||||
|
|
||||||
|
# 随机输入开关
|
||||||
|
if request_func_input.random_flag:
|
||||||
|
payload["max_tokens"] = request_func_input.output_len
|
||||||
|
payload["min_tokens"] = request_func_input.output_len
|
||||||
|
# 随机token_ids场景
|
||||||
|
if isinstance(request_func_input.prompt, list):
|
||||||
|
request_func_input.prompt_token_ids = request_func_input.prompt
|
||||||
|
request_func_input.prompt = ""
|
||||||
|
|
||||||
# 支持传入prompt_token_ids
|
# 支持传入prompt_token_ids
|
||||||
if request_func_input.prompt_token_ids:
|
if request_func_input.prompt_token_ids:
|
||||||
# 不走messages
|
# 不走messages
|
||||||
|
|||||||
@@ -818,3 +818,61 @@ class RandomTextDataset(BenchmarkDataset):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
return samples
|
return samples
|
||||||
|
|
||||||
|
|
||||||
|
class RandomTokenDataset(BenchmarkDataset):
|
||||||
|
"""
|
||||||
|
Generates random English words for pure text benchmarking.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
|
def sample(
|
||||||
|
self,
|
||||||
|
num_requests: int,
|
||||||
|
lora_path: Optional[str] = None,
|
||||||
|
max_loras: Optional[int] = None,
|
||||||
|
random_input_len: Optional[int] = None,
|
||||||
|
random_output_len: Optional[int] = None,
|
||||||
|
random_range_ratio: Optional[float] = None,
|
||||||
|
enable_multimodal_chat: bool = False,
|
||||||
|
**kwargs,
|
||||||
|
) -> list:
|
||||||
|
samples = []
|
||||||
|
|
||||||
|
def sample_len(base_len: int, ratio: float) -> int:
|
||||||
|
if base_len is None:
|
||||||
|
return None
|
||||||
|
if ratio is None or ratio <= 0:
|
||||||
|
return base_len
|
||||||
|
lo = max(1, int(base_len * (1 - ratio)))
|
||||||
|
hi = int(base_len * (1 + ratio))
|
||||||
|
return random.randint(lo, hi)
|
||||||
|
|
||||||
|
for i in range(1, num_requests + 1):
|
||||||
|
# [length * (1 - range_ratio), length * (1 + range_ratio)]
|
||||||
|
sampled_input_len = sample_len(random_input_len, random_range_ratio)
|
||||||
|
sampled_output_len = sample_len(random_output_len, random_range_ratio)
|
||||||
|
|
||||||
|
random.seed(21)
|
||||||
|
token_ids = [random.randint(2000, 10000) for _ in range(sampled_input_len)]
|
||||||
|
# prompt_text = " ".join(words)
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"messages": [{"role": "user", "content": [{"type": "text", "text": ""}]}],
|
||||||
|
"prompt_token_ids": token_ids,
|
||||||
|
}
|
||||||
|
|
||||||
|
samples.append(
|
||||||
|
SampleRequest(
|
||||||
|
no=i,
|
||||||
|
json_data=data,
|
||||||
|
prompt=token_ids,
|
||||||
|
prompt_len=sampled_input_len,
|
||||||
|
history_QA=data["messages"],
|
||||||
|
expected_output_len=sampled_output_len,
|
||||||
|
random_flag=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return samples
|
||||||
|
|||||||
@@ -39,7 +39,13 @@ from backend_request_func import (
|
|||||||
RequestFuncInput,
|
RequestFuncInput,
|
||||||
RequestFuncOutput,
|
RequestFuncOutput,
|
||||||
)
|
)
|
||||||
from benchmark_dataset import EBChatDataset, EBDataset, RandomTextDataset, SampleRequest
|
from benchmark_dataset import (
|
||||||
|
EBChatDataset,
|
||||||
|
EBDataset,
|
||||||
|
RandomTextDataset,
|
||||||
|
RandomTokenDataset,
|
||||||
|
SampleRequest,
|
||||||
|
)
|
||||||
from benchmark_utils import convert_to_pytorch_benchmark_format, write_to_json
|
from benchmark_utils import convert_to_pytorch_benchmark_format, write_to_json
|
||||||
from tqdm.asyncio import tqdm
|
from tqdm.asyncio import tqdm
|
||||||
|
|
||||||
@@ -1156,6 +1162,12 @@ def main(args: argparse.Namespace):
|
|||||||
random_output_len=args.random_output_len,
|
random_output_len=args.random_output_len,
|
||||||
random_range_ratio=args.random_range_ratio,
|
random_range_ratio=args.random_range_ratio,
|
||||||
),
|
),
|
||||||
|
"random_token_ids": lambda: RandomTokenDataset().sample(
|
||||||
|
num_requests=args.num_prompts,
|
||||||
|
random_input_len=args.random_input_len,
|
||||||
|
random_output_len=args.random_output_len,
|
||||||
|
random_range_ratio=args.random_range_ratio,
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -1338,6 +1350,7 @@ if __name__ == "__main__":
|
|||||||
"EB",
|
"EB",
|
||||||
"EBChat",
|
"EBChat",
|
||||||
"random",
|
"random",
|
||||||
|
"random_token_ids",
|
||||||
],
|
],
|
||||||
help="Name of the dataset to benchmark on.",
|
help="Name of the dataset to benchmark on.",
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user