MCPcopy
hub / github.com/huggingface/transformers / metrics_format

Function metrics_format

src/transformers/trainer_pt_utils.py:803–826  ·  view source on GitHub ↗

Reformat Trainer metrics values to a human-readable format. Args: metrics (`dict[str, float]`): The metrics returned from train/evaluate/predict Returns: metrics (`dict[str, float]`): The reformatted metrics

(metrics: dict[str, float])

Source from the content-addressed store, hash-verified

801
802
803def metrics_format(metrics: dict[str, float]) -> dict[str, float]:
804 """
805 Reformat Trainer metrics values to a human-readable format.
806
807 Args:
808 metrics (`dict[str, float]`):
809 The metrics returned from train/evaluate/predict
810
811 Returns:
812 metrics (`dict[str, float]`): The reformatted metrics
813 """
814
815 metrics_copy = metrics.copy()
816 for k, v in metrics_copy.items():
817 if "_mem_" in k:
818 metrics_copy[k] = f"{v >> 20}MB"
819 elif "_runtime" in k:
820 metrics_copy[k] = _secs2timedelta(v)
821 elif k == "total_flos":
822 metrics_copy[k] = f"{int(v) >> 30}GF"
823 elif isinstance(metrics_copy[k], float):
824 metrics_copy[k] = round(v, 4)
825
826 return metrics_copy
827
828
829# Trainer helper method: imported into the Trainer class and used as a method (takes `self` as first argument).

Callers 1

log_metricsFunction · 0.85

Calls 2

_secs2timedeltaFunction · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected