Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to benchmark multiple models concurrently #850

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Re-sample requests for each model
  • Loading branch information
liu-cong committed Oct 18, 2024
commit 69b139fdbf5d90f1bbb41b052fef929c935949d4
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,18 @@ async def send_request(
async def benchmark(
args: argparse.Namespace,
api_url: str,
input_requests: List[Tuple[str, int, int]],
tokenizer: PreTrainedTokenizerBase,
model: str,
) -> Tuple[List[Tuple[int, int, float]], Dict[str, int]]:
"""Runs benchmark with asynchronous requests."""
input_requests = sample_requests(
args.dataset,
args.num_prompts,
args.max_input_length,
args.max_output_length,
tokenizer,
args.use_dummy_text,
)
benchmark_start_time = time.time()
tasks: List[asyncio.Task] = []
async for request in get_request(input_requests, args.request_rate):
Expand Down Expand Up @@ -586,19 +593,12 @@ async def main(args: argparse.Namespace):
tokenizer = AutoTokenizer.from_pretrained(
args.tokenizer, trust_remote_code=args.trust_remote_code
)
input_requests = sample_requests(
args.dataset,
args.num_prompts,
args.max_input_length,
args.max_output_length,
tokenizer,
args.use_dummy_text,
)

benchmark_start_time = time.time()
args.start_datetime = datetime.fromtimestamp(benchmark_start_time)

results = await asyncio.gather(
*[benchmark(args, api_url, input_requests, tokenizer, model) for model in models]
*[benchmark(args, api_url, tokenizer, model) for model in models]
)

# Summarize results
Expand All @@ -618,7 +618,7 @@ async def main(args: argparse.Namespace):

benchmark_duration_all_models = time.time() - benchmark_start_time
if args.save_aggregated_result:
print_and_save_result(args, benchmark_duration_all_models, len(models)*len(input_requests), f"ALL-{len(models)}-MODELS", combined_latencies, combined_errors)
print_and_save_result(args, benchmark_duration_all_models, len(models)*args.num_prompts, f"ALL-{len(models)}-MODELS", combined_latencies, combined_errors)

if __name__ == "__main__":
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -709,7 +709,7 @@ async def main(args: argparse.Namespace):
"the request arrival times."
),
)
parser.add_argument("--seed", type=int, default=0)
parser.add_argument("--seed", type=int, default=int(time.time()))
parser.add_argument(
"--trust-remote-code",
action="store_true",
Expand Down