MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / process_pd_metrics

Function process_pd_metrics

benchmarks/benchmark_serving.py:711–757  ·  view source on GitHub ↗
(model_outputs, metric_key, is_time=True)

Source from the content-addressed store, hash-verified

709 result[f"p{p_word}_{metric_attribute_name}_ms"] = value
710
711 def process_pd_metrics(model_outputs, metric_key, is_time=True):
712 # 收集所有该 metric 的数值
713 values = []
714 percentiles = []
715 for p in args.metric_percentiles.split(","):
716 p = p.strip()
717 if p:
718 percentiles.append(float(p))
719 for item in model_outputs:
720 metrics = item.metrics
721 if metrics.get(metric_key, None) is not None:
722 values.append(metrics[metric_key])
723
724 if not values:
725 print(f"[WARN] metric_key '{metric_key}' not found in outputs.")
726 return
727
728 if is_time:
729 arr = np.array(values) * 1000 # 秒 -> 毫秒
730 suffix = "(ms)"
731 else:
732 arr = np.array(values)
733 suffix = ""
734
735 print("{s:{c}^{n}}".format(s=metric_key, n=50, c="-"))
736 print(
737 "{:<40} {:<10.2f}".format(
738 f"Mean {metric_key} {suffix}:",
739 np.mean(arr),
740 )
741 )
742 print(
743 "{:<40} {:<10.2f}".format(
744 f"Median {metric_key} {suffix}:",
745 np.median(arr),
746 )
747 )
748 for p in percentiles:
749 v = np.percentile(arr, p)
750 print("{:<40} {:<10.2f}".format(f"P{str(int(p)) if int(p) == p else str(p)} {metric_key} {suffix}:", v))
751 # print(f"P{str(int(p)) if int(p) == p else str(p)} {metric_key} (ms): {v:10.2f}")
752 print(
753 "{:<40} {:<10.2f}".format(
754 f"Successful {metric_key}:",
755 len(arr),
756 )
757 )
758
759 def process_one_length(
760 # E.g., "ttft"

Callers 1

benchmarkFunction · 0.85

Calls 4

printFunction · 0.85
splitMethod · 0.80
getMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected