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])
| 801 | |
| 802 | |
| 803 | def 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). |
no test coverage detected