Benchmark metrics statistics,generate benchmark result
(
benchmark_duration: float,
result_file: str,
selected_percentiles: list[float],
selected_percentile_metrics: list[str],
goodput_config_dict: dict[str, float],
)
| 829 | |
| 830 | |
| 831 | def benchmark_metrics( |
| 832 | benchmark_duration: float, |
| 833 | result_file: str, |
| 834 | selected_percentiles: list[float], |
| 835 | selected_percentile_metrics: list[str], |
| 836 | goodput_config_dict: dict[str, float], |
| 837 | ): |
| 838 | """Benchmark metrics statistics,generate benchmark result""" |
| 839 | outputs = [] |
| 840 | with open(result_file) as f: |
| 841 | for line in f.readlines(): |
| 842 | if "RequestFuncOutput" in line: |
| 843 | start = line.find("RequestFuncOutput") |
| 844 | end = line.rfind(")") |
| 845 | para_str = line[start : end + 1] |
| 846 | |
| 847 | output = eval(para_str) |
| 848 | outputs.append(output) |
| 849 | |
| 850 | input_requests = [[]] * len(outputs) |
| 851 | goodput_config_dict = check_goodput_args(args) |
| 852 | |
| 853 | metrics, actual_output_lens = calculate_metrics( |
| 854 | # input_requests=input_requests, |
| 855 | outputs=outputs, |
| 856 | dur_s=benchmark_duration, |
| 857 | selected_percentiles=selected_percentiles, |
| 858 | goodput_config_dict=goodput_config_dict, |
| 859 | ) |
| 860 | |
| 861 | print("{s:{c}^{n}}".format(s=" Serving Benchmark Result ", n=50, c="=")) |
| 862 | print("{:<40} {:<10}".format("Successful requests:", metrics.completed)) |
| 863 | print("{:<40} {:<10.2f}".format("Benchmark duration (s):", benchmark_duration)) |
| 864 | print("{:<40} {:<10}".format("Total input tokens:", metrics.total_input)) |
| 865 | print("{:<40} {:<10}".format("Total generated tokens:", metrics.total_output)) |
| 866 | print("{:<40} {:<10.2f}".format("Request throughput (req/s):", metrics.request_throughput)) |
| 867 | if goodput_config_dict: |
| 868 | print("{:<40} {:<10.2f}".format("Request goodput (req/s):", metrics.request_goodput)) |
| 869 | print("{:<40} {:<10.2f}".format("Output token throughput (tok/s):", metrics.output_throughput)) |
| 870 | print("{:<40} {:<10.2f}".format("Total Token throughput (tok/s):", metrics.total_token_throughput)) |
| 871 | |
| 872 | result = { |
| 873 | "duration": benchmark_duration, |
| 874 | "completed": metrics.completed, |
| 875 | "total_input_tokens": metrics.total_input, |
| 876 | "total_output_tokens": metrics.total_output, |
| 877 | "request_throughput": metrics.request_throughput, |
| 878 | "request_goodput:": (metrics.request_goodput if goodput_config_dict else None), |
| 879 | "output_throughput": metrics.output_throughput, |
| 880 | "total_token_throughput": metrics.total_token_throughput, |
| 881 | "input_lens": [output.prompt_len for output in outputs], |
| 882 | "output_lens": actual_output_lens, |
| 883 | "ttfts": [output.ttft for output in outputs], |
| 884 | "itls": [output.itl for output in outputs], |
| 885 | "input_texts": ["" for input in input_requests], |
| 886 | "generated_texts": [output.generated_text for output in outputs], |
| 887 | "errors": [output.error for output in outputs], |
| 888 | } |
nothing calls this directly
no test coverage detected